mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-16 06:28:12 -05:00
fix(49483): throw error on await inside non-async function (#49496)
This commit is contained in:
@@ -954,6 +954,7 @@ namespace ts {
|
||||
Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations.code,
|
||||
Diagnostics.Class_constructor_may_not_be_a_generator.code,
|
||||
Diagnostics.Class_constructor_may_not_be_an_accessor.code,
|
||||
Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
|
||||
]);
|
||||
|
||||
/**
|
||||
|
||||
13
tests/baselines/reference/plainJSGrammarErrors3.errors.txt
Normal file
13
tests/baselines/reference/plainJSGrammarErrors3.errors.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
/a.js(2,5): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
|
||||
|
||||
|
||||
==== tests/cases/conformance/salsa/plainJSGrammarErrors3.js (0 errors) ====
|
||||
|
||||
==== /a.js (1 errors) ====
|
||||
function foo() {
|
||||
await new Promise(undefined);
|
||||
~~~~~
|
||||
!!! error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
|
||||
!!! related TS1356 /a.js:1:10: Did you mean to mark this function as 'async'?
|
||||
}
|
||||
|
||||
15
tests/baselines/reference/plainJSGrammarErrors3.js
Normal file
15
tests/baselines/reference/plainJSGrammarErrors3.js
Normal file
@@ -0,0 +1,15 @@
|
||||
//// [tests/cases/conformance/salsa/plainJSGrammarErrors3.ts] ////
|
||||
|
||||
//// [plainJSGrammarErrors3.js]
|
||||
|
||||
//// [a.js]
|
||||
function foo() {
|
||||
await new Promise(undefined);
|
||||
}
|
||||
|
||||
|
||||
//// [plainJSGrammarErrors3.js]
|
||||
//// [a.js]
|
||||
function foo() {
|
||||
await new Promise(undefined);
|
||||
}
|
||||
11
tests/baselines/reference/plainJSGrammarErrors3.symbols
Normal file
11
tests/baselines/reference/plainJSGrammarErrors3.symbols
Normal file
@@ -0,0 +1,11 @@
|
||||
=== tests/cases/conformance/salsa/plainJSGrammarErrors3.js ===
|
||||
|
||||
No type information for this code.=== /a.js ===
|
||||
function foo() {
|
||||
>foo : Symbol(foo, Decl(a.js, 0, 0))
|
||||
|
||||
await new Promise(undefined);
|
||||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
|
||||
>undefined : Symbol(undefined)
|
||||
}
|
||||
|
||||
13
tests/baselines/reference/plainJSGrammarErrors3.types
Normal file
13
tests/baselines/reference/plainJSGrammarErrors3.types
Normal file
@@ -0,0 +1,13 @@
|
||||
=== tests/cases/conformance/salsa/plainJSGrammarErrors3.js ===
|
||||
|
||||
No type information for this code.=== /a.js ===
|
||||
function foo() {
|
||||
>foo : () => void
|
||||
|
||||
await new Promise(undefined);
|
||||
>await new Promise(undefined) : any
|
||||
>new Promise(undefined) : Promise<any>
|
||||
>Promise : PromiseConstructor
|
||||
>undefined : undefined
|
||||
}
|
||||
|
||||
10
tests/cases/conformance/salsa/plainJSGrammarErrors3.ts
Normal file
10
tests/cases/conformance/salsa/plainJSGrammarErrors3.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
// @outdir: out/
|
||||
// @target: esnext
|
||||
// @module: esnext
|
||||
// @allowJs: true
|
||||
// @filename: plainJSGrammarErrors3.js
|
||||
|
||||
// @filename: /a.js
|
||||
function foo() {
|
||||
await new Promise(undefined);
|
||||
}
|
||||
Reference in New Issue
Block a user