Skip to content

Commit

Permalink
Allow await expression at other than expression statement (swc-projec…
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Feb 8, 2020
1 parent 55c0258 commit add6382
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ecmascript/parser/src/parser/expr/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
9 changes: 9 additions & 0 deletions tests/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
9 changes: 9 additions & 0 deletions tests/projects/await-expression-2/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"jsc": {
"target": "es2017",
"parser": {
"syntax": "ecmascript",
"topLevelAwait": true
}
}
}
1 change: 1 addition & 0 deletions tests/projects/await-expression-2/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const foo = await test;

0 comments on commit add6382

Please sign in to comment.