Skip to content

Commit

Permalink
fix(es/parser): Fix parsing of await using (#8101)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8096
  • Loading branch information
kdy1 authored Oct 11, 2023
1 parent 17fe7b2 commit e1043fa
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
20 changes: 20 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8096/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true
},
"target": "es2022",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}
1 change: 1 addition & 0 deletions crates/swc/tests/fixture/issues-8xxx/8096/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
await using(true);
1 change: 1 addition & 0 deletions crates/swc/tests/fixture/issues-8xxx/8096/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
await using(true);
13 changes: 9 additions & 4 deletions crates/swc_ecma_parser/src/parser/expr/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl<I: Tokens> Parser<I> {
}

if is!(self, "await") {
return self.parse_await_expr();
return self.parse_await_expr(None);
}

// UpdateExpression
Expand Down Expand Up @@ -361,10 +361,15 @@ impl<I: Tokens> Parser<I> {
Ok(expr)
}

pub(crate) fn parse_await_expr(&mut self) -> PResult<Box<Expr>> {
let start = cur_pos!(self);
pub(crate) fn parse_await_expr(
&mut self,
start_of_await_token: Option<BytePos>,
) -> PResult<Box<Expr>> {
let start = start_of_await_token.unwrap_or_else(|| cur_pos!(self));

assert_and_bump!(self, "await");
if start_of_await_token.is_none() {
assert_and_bump!(self, "await");
}

if is!(self, '*') {
syntax_error!(self, SyntaxError::AwaitStar);
Expand Down
4 changes: 3 additions & 1 deletion crates/swc_ecma_parser/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ impl<'a, I: Tokens> Parser<I> {
self.emit_err(self.input.cur_span(), SyntaxError::TopLevelAwaitInScript);
}

let mut eaten_await = None;
if peeked_is!(self, "using") {
eaten_await = Some(self.input.cur_pos());
assert_and_bump!(self, "await");

let v = self.parse_using_decl(start, true)?;
Expand All @@ -135,7 +137,7 @@ impl<'a, I: Tokens> Parser<I> {
}
}

let expr = self.parse_await_expr()?;
let expr = self.parse_await_expr(eaten_await)?;
let expr = self
.include_in_expr(true)
.parse_bin_op_recursively(expr, 0)?;
Expand Down

1 comment on commit e1043fa

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: e1043fa Previous: 226b17f Ratio
es/full/bugs-1 288955 ns/iter (± 5526) 290989 ns/iter (± 6364) 0.99
es/full/minify/libraries/antd 1394116231 ns/iter (± 26558988) 1400668650 ns/iter (± 18008284) 1.00
es/full/minify/libraries/d3 292383982 ns/iter (± 2936402) 296455682 ns/iter (± 2476883) 0.99
es/full/minify/libraries/echarts 1141694049 ns/iter (± 13432346) 1111940309 ns/iter (± 13001085) 1.03
es/full/minify/libraries/jquery 88643929 ns/iter (± 372087) 89504899 ns/iter (± 249366) 0.99
es/full/minify/libraries/lodash 103916758 ns/iter (± 402967) 104087178 ns/iter (± 512471) 1.00
es/full/minify/libraries/moment 52416733 ns/iter (± 327568) 52546168 ns/iter (± 158595) 1.00
es/full/minify/libraries/react 18849633 ns/iter (± 51141) 18931698 ns/iter (± 183137) 1.00
es/full/minify/libraries/terser 232314284 ns/iter (± 2596996) 233574287 ns/iter (± 1679175) 0.99
es/full/minify/libraries/three 408384625 ns/iter (± 2630249) 410502521 ns/iter (± 1949728) 0.99
es/full/minify/libraries/typescript 2816402782 ns/iter (± 11054970) 2823716939 ns/iter (± 13765090) 1.00
es/full/minify/libraries/victory 598947446 ns/iter (± 7751231) 615478141 ns/iter (± 6622097) 0.97
es/full/minify/libraries/vue 126476197 ns/iter (± 349776) 127998820 ns/iter (± 394593) 0.99
es/full/codegen/es3 33384 ns/iter (± 172) 34646 ns/iter (± 106) 0.96
es/full/codegen/es5 33471 ns/iter (± 82) 34556 ns/iter (± 72) 0.97
es/full/codegen/es2015 33184 ns/iter (± 117) 34536 ns/iter (± 102) 0.96
es/full/codegen/es2016 33227 ns/iter (± 100) 34552 ns/iter (± 59) 0.96
es/full/codegen/es2017 33241 ns/iter (± 107) 34543 ns/iter (± 109) 0.96
es/full/codegen/es2018 33231 ns/iter (± 101) 34530 ns/iter (± 98) 0.96
es/full/codegen/es2019 33166 ns/iter (± 87) 34679 ns/iter (± 93) 0.96
es/full/codegen/es2020 33315 ns/iter (± 96) 34611 ns/iter (± 121) 0.96
es/full/all/es3 176630922 ns/iter (± 1643550) 178130922 ns/iter (± 1809872) 0.99
es/full/all/es5 170591331 ns/iter (± 923941) 170872027 ns/iter (± 1165954) 1.00
es/full/all/es2015 128685132 ns/iter (± 1425368) 128046220 ns/iter (± 1371919) 1.00
es/full/all/es2016 129382324 ns/iter (± 1329967) 127949876 ns/iter (± 934745) 1.01
es/full/all/es2017 128318171 ns/iter (± 1568732) 126865752 ns/iter (± 937093) 1.01
es/full/all/es2018 125086385 ns/iter (± 1896512) 125524473 ns/iter (± 1625123) 1.00
es/full/all/es2019 124625454 ns/iter (± 1175732) 124743025 ns/iter (± 947084) 1.00
es/full/all/es2020 121543638 ns/iter (± 1001834) 120611511 ns/iter (± 786003) 1.01
es/full/parser 567758 ns/iter (± 2293) 556954 ns/iter (± 3034) 1.02
es/full/base/fixer 21468 ns/iter (± 198) 17594 ns/iter (± 59) 1.22
es/full/base/resolver_and_hygiene 86589 ns/iter (± 256) 83788 ns/iter (± 215) 1.03

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.