New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect parsing for contextual keyword async
#678
Comments
According to astexplorer that isn't what comes out? This is the result of the parse (yes, ASTExplorer is on This is the output of parsing against master (without location info), which is against `v1.11.0`{
"body": [
{
"source": {
"raw": "'@angular/core/testing'",
"type": "Literal",
"value": "@angular/core/testing",
},
"specifiers": [
{
"imported": {
"name": "TestBed",
"type": "Identifier",
},
"local": {
"name": "TestBed",
"type": "Identifier",
},
"type": "ImportSpecifier",
},
//////////////////////////////////
{
"imported": {
"name": "async",
"type": "Identifier",
},
"local": {
"name": "async",
"type": "Identifier",
},
"type": "ImportSpecifier",
},
//////////////////////////////////
],
"type": "ImportDeclaration",
},
],
"sourceType": "module",
"tokens": [
{
"type": "Keyword",
"value": "import",
},
{
"type": "Punctuator",
"value": "{",
},
{
"type": "Identifier",
"value": "TestBed",
},
{
"type": "Punctuator",
"value": ",",
},
{
"type": "Keyword",
"value": "async",
},
{
"type": "Punctuator",
"value": "}",
},
{
"type": "Identifier",
"value": "from",
},
{
"type": "String",
"value": "'@angular/core/testing'",
},
{
"type": "Punctuator",
"value": ";",
},
],
"type": "Program",
} As you can see, in both cases |
@bradzacher Thank you for quick response! The parser used for easy integration between TypeScript & JavaScript ecosystems. So I expect identical results with identical strings of code. // @ts-check
const tsParser = require('@typescript-eslint/typescript-estree');
const esParser = require('esprima')
const esParser2 = require('espree')
const code = `import { TestBed, async } from '@angular/core/testing';`;
const { tokens: tsTokens } = tsParser.parse(code, {
tokens: true,
});
const esTokens = esParser.tokenize(code)
const esTokens2 = esParser2.tokenize(code, {ecmaVersion: 2019, sourceType: 'module'})
console.log(tsTokens.map(({ type, value }) => ({ type, value })))
console.log('---')
console.log(esTokens.map(({ type, value }) => ({ type, value })))
console.log('---')
console.log(esTokens2.map(({ type, value }) => ({ type, value }))) Result is different:
Consistent results will help to use the available ESLint plugins for TypeScript code |
I see - you should have included that in your initial issue! Looking again at the example, yes - the tokens array does classify the However looking at the linked issue, and the source code of the plugin, it never inspects that array, and gathers tokens via In practice it looks like it all works as expected?
|
Note that I have raised #681 to fix the incorrect typing of the token. |
@bradzacher Result: test is OK :)
Plugin works as expected |
What code were you trying to parse?
What did you expect to happen?
token type
Identifier
with valueasync
What actually happened?
token type
Keyword
with valueasync
Versions
@typescript-eslint/typescript-estree
1.11.0
TypeScript
3.4.5
node
10.14.2
npm
6.4.1
The text was updated successfully, but these errors were encountered: