Skip to content

Commit

Permalink
fix(typescript-estree): parsing error for await in non-async func (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo authored and bradzacher committed Sep 19, 2019
1 parent c3c8b86 commit 19abbe0
Show file tree
Hide file tree
Showing 6 changed files with 885 additions and 1 deletion.
266 changes: 266 additions & 0 deletions packages/parser/tests/lib/__snapshots__/typescript.ts.snap
Expand Up @@ -1967,6 +1967,272 @@ Object {
}
`;

exports[`typescript fixtures/basics/await-without-async-function.src 1`] = `
Object {
"$id": 8,
"block": Object {
"range": Array [
0,
64,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 7,
"block": Object {
"range": Array [
0,
64,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 6,
"block": Object {
"range": Array [
0,
63,
],
"type": "FunctionDeclaration",
},
"childScopes": Array [],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [
Object {
"$id": 3,
"from": Object {
"$ref": 6,
},
"identifier": Object {
"name": "bar",
"range": Array [
25,
28,
],
"type": "Identifier",
},
"kind": "w",
"resolved": Object {
"$ref": 2,
},
"writeExpr": Object {
"range": Array [
31,
42,
],
"type": "AwaitExpression",
},
},
Object {
"$id": 4,
"from": Object {
"$ref": 6,
},
"identifier": Object {
"name": "baz",
"range": Array [
37,
40,
],
"type": "Identifier",
},
"kind": "r",
"resolved": null,
"writeExpr": undefined,
},
Object {
"$id": 5,
"from": Object {
"$ref": 6,
},
"identifier": Object {
"name": "bar",
"range": Array [
53,
56,
],
"type": "Identifier",
},
"kind": "r",
"resolved": Object {
"$ref": 2,
},
"writeExpr": undefined,
},
],
"throughReferences": Array [
Object {
"$ref": 4,
},
],
"type": "function",
"upperScope": Object {
"$ref": 7,
},
"variableMap": Object {
"arguments": Object {
"$ref": 1,
},
"bar": Object {
"$ref": 2,
},
},
"variableScope": Object {
"$ref": 6,
},
"variables": Array [
Object {
"$id": 1,
"defs": Array [],
"eslintUsed": undefined,
"identifiers": Array [],
"name": "arguments",
"references": Array [],
"scope": Object {
"$ref": 6,
},
},
Object {
"$id": 2,
"defs": Array [
Object {
"name": Object {
"name": "bar",
"range": Array [
25,
28,
],
"type": "Identifier",
},
"node": Object {
"range": Array [
25,
42,
],
"type": "VariableDeclarator",
},
"parent": Object {
"range": Array [
19,
43,
],
"type": "VariableDeclaration",
},
"type": "Variable",
},
],
"eslintUsed": undefined,
"identifiers": Array [
Object {
"name": "bar",
"range": Array [
25,
28,
],
"type": "Identifier",
},
],
"name": "bar",
"references": Array [
Object {
"$ref": 3,
},
Object {
"$ref": 5,
},
],
"scope": Object {
"$ref": 6,
},
},
],
},
],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [],
"throughReferences": Array [
Object {
"$ref": 4,
},
],
"type": "module",
"upperScope": Object {
"$ref": 8,
},
"variableMap": Object {
"foo": Object {
"$ref": 0,
},
},
"variableScope": Object {
"$ref": 7,
},
"variables": Array [
Object {
"$id": 0,
"defs": Array [
Object {
"name": Object {
"name": "foo",
"range": Array [
9,
12,
],
"type": "Identifier",
},
"node": Object {
"range": Array [
0,
63,
],
"type": "FunctionDeclaration",
},
"parent": null,
"type": "FunctionName",
},
],
"eslintUsed": undefined,
"identifiers": Array [
Object {
"name": "foo",
"range": Array [
9,
12,
],
"type": "Identifier",
},
],
"name": "foo",
"references": Array [],
"scope": Object {
"$ref": 7,
},
},
],
},
],
"functionExpressionScope": false,
"isStrict": false,
"references": Array [],
"throughReferences": Array [
Object {
"$ref": 4,
},
],
"type": "global",
"upperScope": null,
"variableMap": Object {},
"variableScope": Object {
"$ref": 8,
},
"variables": Array [],
}
`;

exports[`typescript fixtures/basics/call-signatures.src 1`] = `
Object {
"$id": 1,
Expand Down
@@ -0,0 +1,4 @@
function foo() {
const bar = await baz();
return bar.qux;
}
2 changes: 1 addition & 1 deletion packages/typescript-estree/src/parser.ts
Expand Up @@ -7,7 +7,7 @@ import { astConverter } from './ast-converter';
import { convertError } from './convert';
import { firstDefined } from './node-utils';
import { Extra, TSESTreeOptions, ParserServices } from './parser-options';
import { getFirstSemanticOrSyntacticError } from './semantic-errors';
import { getFirstSemanticOrSyntacticError } from './semantic-or-syntactic-errors';
import { TSESTree } from './ts-estree';
import {
calculateProjectParserOptions,
Expand Down
Expand Up @@ -86,6 +86,7 @@ function whitelistSupportedDiagnostics(
case 1242: // ts 3.2 "'abstract' modifier can only appear on a class, method, or property declaration."
case 1246: // ts 3.2 "An interface property cannot have an initializer."
case 1255: // ts 3.2 "A definite assignment assertion '!' is not permitted in this context."
case 1308: // ts 3.2 "'await' expression is only allowed within an async function."
case 2364: // ts 3.2 "The left-hand side of an assignment expression must be a variable or a property access."
case 2369: // ts 3.2 "A parameter property is only allowed in a constructor implementation."
case 2462: // ts 3.2 "A rest element must be last in a destructuring pattern."
Expand Down
Expand Up @@ -1669,6 +1669,15 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/async-function-with-var-declaration.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/await-without-async-function.src 1`] = `
Object {
"column": 14,
"index": 31,
"lineNumber": 2,
"message": "'await' expression is only allowed within an async function.",
}
`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/call-signatures.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/call-signatures-with-generics.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down

0 comments on commit 19abbe0

Please sign in to comment.