Remove empty expression in expression statement with top level await (#630)

Eats the semi-colon.

This doesn't compile (edit: doesn't compile the code in the tests) though because the target of that folder is ES2015. Also, this is kind of strange for me to put the tests in the "typescript" folder. Should we create something more general?

You can take over this PR if you'd like!
This commit is contained in:
dsherret 2020-02-07 05:33:26 +00:00
parent 26eb4e3206
commit 55c0258017
5 changed files with 21 additions and 1 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "swc_ecma_parser" name = "swc_ecma_parser"
version = "0.18.0" version = "0.18.1"
authors = ["강동윤 <kdy1997.dev@gmail.com>"] authors = ["강동윤 <kdy1997.dev@gmail.com>"]
license = "Apache-2.0/MIT" license = "Apache-2.0/MIT"
repository = "https://github.com/swc-project/swc.git" repository = "https://github.com/swc-project/swc.git"

View File

@ -100,6 +100,7 @@ impl<'a, I: Tokens> Parser<'a, I> {
} }
let expr = self.parse_await_expr()?; let expr = self.parse_await_expr()?;
eat!(';');
let span = span!(start); let span = span!(start);
return Ok(Stmt::Expr(ExprStmt { span, expr })); return Ok(Stmt::Expr(ExprStmt { span, expr }));

View File

@ -352,3 +352,12 @@ fn issue_605() {
assert!(f.contains("Object.keys(_c)")); assert!(f.contains("Object.keys(_c)"));
} }
#[test]
fn await_expr() {
let f = file("tests/projects/await-expression/input.js").unwrap();
println!("{}", f);
assert!(f.contains("await"));
assert!(f.contains("test"));
}

View File

@ -0,0 +1,9 @@
{
"jsc": {
"target": "es2017",
"parser": {
"syntax": "ecmascript",
"topLevelAwait": true
}
}
}

View File

@ -0,0 +1 @@
await test ;