Skip to content

Commit 19abbe0

Browse files
kaicataldobradzacher
authored andcommitted
fix(typescript-estree): parsing error for await in non-async func (typescript-eslint#988)
1 parent c3c8b86 commit 19abbe0

File tree

6 files changed

+885
-1
lines changed

6 files changed

+885
-1
lines changed

packages/parser/tests/lib/__snapshots__/typescript.ts.snap

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,272 @@ Object {
19671967
}
19681968
`;
19691969

1970+
exports[`typescript fixtures/basics/await-without-async-function.src 1`] = `
1971+
Object {
1972+
"$id": 8,
1973+
"block": Object {
1974+
"range": Array [
1975+
0,
1976+
64,
1977+
],
1978+
"type": "Program",
1979+
},
1980+
"childScopes": Array [
1981+
Object {
1982+
"$id": 7,
1983+
"block": Object {
1984+
"range": Array [
1985+
0,
1986+
64,
1987+
],
1988+
"type": "Program",
1989+
},
1990+
"childScopes": Array [
1991+
Object {
1992+
"$id": 6,
1993+
"block": Object {
1994+
"range": Array [
1995+
0,
1996+
63,
1997+
],
1998+
"type": "FunctionDeclaration",
1999+
},
2000+
"childScopes": Array [],
2001+
"functionExpressionScope": false,
2002+
"isStrict": true,
2003+
"references": Array [
2004+
Object {
2005+
"$id": 3,
2006+
"from": Object {
2007+
"$ref": 6,
2008+
},
2009+
"identifier": Object {
2010+
"name": "bar",
2011+
"range": Array [
2012+
25,
2013+
28,
2014+
],
2015+
"type": "Identifier",
2016+
},
2017+
"kind": "w",
2018+
"resolved": Object {
2019+
"$ref": 2,
2020+
},
2021+
"writeExpr": Object {
2022+
"range": Array [
2023+
31,
2024+
42,
2025+
],
2026+
"type": "AwaitExpression",
2027+
},
2028+
},
2029+
Object {
2030+
"$id": 4,
2031+
"from": Object {
2032+
"$ref": 6,
2033+
},
2034+
"identifier": Object {
2035+
"name": "baz",
2036+
"range": Array [
2037+
37,
2038+
40,
2039+
],
2040+
"type": "Identifier",
2041+
},
2042+
"kind": "r",
2043+
"resolved": null,
2044+
"writeExpr": undefined,
2045+
},
2046+
Object {
2047+
"$id": 5,
2048+
"from": Object {
2049+
"$ref": 6,
2050+
},
2051+
"identifier": Object {
2052+
"name": "bar",
2053+
"range": Array [
2054+
53,
2055+
56,
2056+
],
2057+
"type": "Identifier",
2058+
},
2059+
"kind": "r",
2060+
"resolved": Object {
2061+
"$ref": 2,
2062+
},
2063+
"writeExpr": undefined,
2064+
},
2065+
],
2066+
"throughReferences": Array [
2067+
Object {
2068+
"$ref": 4,
2069+
},
2070+
],
2071+
"type": "function",
2072+
"upperScope": Object {
2073+
"$ref": 7,
2074+
},
2075+
"variableMap": Object {
2076+
"arguments": Object {
2077+
"$ref": 1,
2078+
},
2079+
"bar": Object {
2080+
"$ref": 2,
2081+
},
2082+
},
2083+
"variableScope": Object {
2084+
"$ref": 6,
2085+
},
2086+
"variables": Array [
2087+
Object {
2088+
"$id": 1,
2089+
"defs": Array [],
2090+
"eslintUsed": undefined,
2091+
"identifiers": Array [],
2092+
"name": "arguments",
2093+
"references": Array [],
2094+
"scope": Object {
2095+
"$ref": 6,
2096+
},
2097+
},
2098+
Object {
2099+
"$id": 2,
2100+
"defs": Array [
2101+
Object {
2102+
"name": Object {
2103+
"name": "bar",
2104+
"range": Array [
2105+
25,
2106+
28,
2107+
],
2108+
"type": "Identifier",
2109+
},
2110+
"node": Object {
2111+
"range": Array [
2112+
25,
2113+
42,
2114+
],
2115+
"type": "VariableDeclarator",
2116+
},
2117+
"parent": Object {
2118+
"range": Array [
2119+
19,
2120+
43,
2121+
],
2122+
"type": "VariableDeclaration",
2123+
},
2124+
"type": "Variable",
2125+
},
2126+
],
2127+
"eslintUsed": undefined,
2128+
"identifiers": Array [
2129+
Object {
2130+
"name": "bar",
2131+
"range": Array [
2132+
25,
2133+
28,
2134+
],
2135+
"type": "Identifier",
2136+
},
2137+
],
2138+
"name": "bar",
2139+
"references": Array [
2140+
Object {
2141+
"$ref": 3,
2142+
},
2143+
Object {
2144+
"$ref": 5,
2145+
},
2146+
],
2147+
"scope": Object {
2148+
"$ref": 6,
2149+
},
2150+
},
2151+
],
2152+
},
2153+
],
2154+
"functionExpressionScope": false,
2155+
"isStrict": true,
2156+
"references": Array [],
2157+
"throughReferences": Array [
2158+
Object {
2159+
"$ref": 4,
2160+
},
2161+
],
2162+
"type": "module",
2163+
"upperScope": Object {
2164+
"$ref": 8,
2165+
},
2166+
"variableMap": Object {
2167+
"foo": Object {
2168+
"$ref": 0,
2169+
},
2170+
},
2171+
"variableScope": Object {
2172+
"$ref": 7,
2173+
},
2174+
"variables": Array [
2175+
Object {
2176+
"$id": 0,
2177+
"defs": Array [
2178+
Object {
2179+
"name": Object {
2180+
"name": "foo",
2181+
"range": Array [
2182+
9,
2183+
12,
2184+
],
2185+
"type": "Identifier",
2186+
},
2187+
"node": Object {
2188+
"range": Array [
2189+
0,
2190+
63,
2191+
],
2192+
"type": "FunctionDeclaration",
2193+
},
2194+
"parent": null,
2195+
"type": "FunctionName",
2196+
},
2197+
],
2198+
"eslintUsed": undefined,
2199+
"identifiers": Array [
2200+
Object {
2201+
"name": "foo",
2202+
"range": Array [
2203+
9,
2204+
12,
2205+
],
2206+
"type": "Identifier",
2207+
},
2208+
],
2209+
"name": "foo",
2210+
"references": Array [],
2211+
"scope": Object {
2212+
"$ref": 7,
2213+
},
2214+
},
2215+
],
2216+
},
2217+
],
2218+
"functionExpressionScope": false,
2219+
"isStrict": false,
2220+
"references": Array [],
2221+
"throughReferences": Array [
2222+
Object {
2223+
"$ref": 4,
2224+
},
2225+
],
2226+
"type": "global",
2227+
"upperScope": null,
2228+
"variableMap": Object {},
2229+
"variableScope": Object {
2230+
"$ref": 8,
2231+
},
2232+
"variables": Array [],
2233+
}
2234+
`;
2235+
19702236
exports[`typescript fixtures/basics/call-signatures.src 1`] = `
19712237
Object {
19722238
"$id": 1,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function foo() {
2+
const bar = await baz();
3+
return bar.qux;
4+
}

packages/typescript-estree/src/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { astConverter } from './ast-converter';
77
import { convertError } from './convert';
88
import { firstDefined } from './node-utils';
99
import { Extra, TSESTreeOptions, ParserServices } from './parser-options';
10-
import { getFirstSemanticOrSyntacticError } from './semantic-errors';
10+
import { getFirstSemanticOrSyntacticError } from './semantic-or-syntactic-errors';
1111
import { TSESTree } from './ts-estree';
1212
import {
1313
calculateProjectParserOptions,

packages/typescript-estree/src/semantic-errors.ts renamed to packages/typescript-estree/src/semantic-or-syntactic-errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function whitelistSupportedDiagnostics(
8686
case 1242: // ts 3.2 "'abstract' modifier can only appear on a class, method, or property declaration."
8787
case 1246: // ts 3.2 "An interface property cannot have an initializer."
8888
case 1255: // ts 3.2 "A definite assignment assertion '!' is not permitted in this context."
89+
case 1308: // ts 3.2 "'await' expression is only allowed within an async function."
8990
case 2364: // ts 3.2 "The left-hand side of an assignment expression must be a variable or a property access."
9091
case 2369: // ts 3.2 "A parameter property is only allowed in a constructor implementation."
9192
case 2462: // ts 3.2 "A rest element must be last in a destructuring pattern."

packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,15 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e
16691669

16701670
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"`;
16711671

1672+
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/await-without-async-function.src 1`] = `
1673+
Object {
1674+
"column": 14,
1675+
"index": 31,
1676+
"lineNumber": 2,
1677+
"message": "'await' expression is only allowed within an async function.",
1678+
}
1679+
`;
1680+
16721681
exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/call-signatures.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
16731682

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy