From add63826bdc6e4417a3a0fa522806b7177edc92f Mon Sep 17 00:00:00 2001 From: kdy1 Date: Sat, 8 Feb 2020 01:49:00 +0000 Subject: [PATCH] Allow await expression at other than expression statement (#636) Fixes #635 --- ecmascript/parser/src/parser/expr/ops.rs | 2 +- tests/projects.rs | 9 +++++++++ tests/projects/await-expression-2/.swcrc | 9 +++++++++ tests/projects/await-expression-2/input.js | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/projects/await-expression-2/.swcrc create mode 100644 tests/projects/await-expression-2/input.js diff --git a/ecmascript/parser/src/parser/expr/ops.rs b/ecmascript/parser/src/parser/expr/ops.rs index bba3609283bf..dc67269d5489 100644 --- a/ecmascript/parser/src/parser/expr/ops.rs +++ b/ecmascript/parser/src/parser/expr/ops.rs @@ -305,7 +305,7 @@ impl<'a, I: Tokens> Parser<'a, I> { }))); } - if self.ctx().in_async && is!("await") { + if (self.ctx().in_async || self.syntax().top_level_await()) && is!("await") { return self.parse_await_expr(); } diff --git a/tests/projects.rs b/tests/projects.rs index d25d8a0a65d3..628e15c06ca8 100644 --- a/tests/projects.rs +++ b/tests/projects.rs @@ -361,3 +361,12 @@ fn await_expr() { assert!(f.contains("await")); assert!(f.contains("test")); } + +#[test] +fn await_expr_2() { + let f = file("tests/projects/await-expression-2/input.js").unwrap(); + println!("{}", f); + + assert!(f.contains("await")); + assert!(f.contains("test")); +} diff --git a/tests/projects/await-expression-2/.swcrc b/tests/projects/await-expression-2/.swcrc new file mode 100644 index 000000000000..feb0370102fd --- /dev/null +++ b/tests/projects/await-expression-2/.swcrc @@ -0,0 +1,9 @@ +{ + "jsc": { + "target": "es2017", + "parser": { + "syntax": "ecmascript", + "topLevelAwait": true + } + } +} \ No newline at end of file diff --git a/tests/projects/await-expression-2/input.js b/tests/projects/await-expression-2/input.js new file mode 100644 index 000000000000..78319c00d0a8 --- /dev/null +++ b/tests/projects/await-expression-2/input.js @@ -0,0 +1 @@ +const foo = await test;