Skip to content

Commit 68d015f

Browse files
committed
fix(parser): trailing comma is not allowed in ParenthesizedExpression
1 parent 24979c9 commit 68d015f

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

crates/oxc_parser/src/js/list.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,27 @@ impl<'a> SeparatedList<'a> for SequenceExpressionList<'a> {
215215
// read everything as expression and map to it to either
216216
// ParenthesizedExpression or ArrowFormalParameters later
217217
fn parse_element(&mut self, p: &mut ParserImpl<'a>) -> Result<()> {
218-
let element = p.parse_assignment_expression_or_higher()?;
219-
self.elements.push(element);
218+
let element = p.parse_assignment_expression_or_higher();
219+
self.elements.push(element?);
220+
Ok(())
221+
}
222+
223+
fn parse_list(&mut self, p: &mut ParserImpl<'a>) -> Result<()> {
224+
p.expect(self.open())?;
225+
226+
let mut first = true;
227+
228+
while !p.at(self.close()) && !p.at(Kind::Eof) {
229+
if first {
230+
first = false;
231+
} else {
232+
p.expect(self.separator())?;
233+
}
234+
235+
self.parse_element(p)?;
236+
}
237+
238+
p.expect(self.close())?;
220239
Ok(())
221240
}
222241
}

tasks/coverage/parser_babel.snap

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ commit: 12619ffe
33
parser_babel Summary:
44
AST Parsed : 2095/2101 (99.71%)
55
Positive Passed: 2087/2101 (99.33%)
6-
Negative Passed: 1364/1501 (90.87%)
6+
Negative Passed: 1365/1501 (90.94%)
77
Expect Syntax Error: "annex-b/disabled/1.1-html-comments-close/input.js"
88
Expect Syntax Error: "annex-b/disabled/3.1-sloppy-labeled-functions/input.js"
99
Expect Syntax Error: "annex-b/disabled/3.1-sloppy-labeled-functions-if-body/input.js"
@@ -27,7 +27,6 @@ Expect Syntax Error: "es2015/uncategorised/297/input.js"
2727
Expect Syntax Error: "es2015/uncategorised/335/input.js"
2828
Expect Syntax Error: "es2017/async-functions/async-await-as-arrow-binding-identifier/input.js"
2929
Expect Syntax Error: "es2017/async-functions/await-binding-inside-arrow-params-inside-async-arrow-params/input.js"
30-
Expect Syntax Error: "es2017/trailing-function-commas/7/input.js"
3130
Expect Syntax Error: "es2018/object-rest-spread/24/input.js"
3231
Expect Syntax Error: "es2018/object-rest-spread/comma-after-rest/input.js"
3332
Expect Syntax Error: "es2018/object-rest-spread/comma-after-spread-for-in/input.js"
@@ -5154,6 +5153,12 @@ Expect to Parse: "typescript/types/const-type-parameters-babel-7/input.ts"
51545153
· ─
51555154
╰────
51565155

5156+
× Unexpected token
5157+
╭─[es2017/trailing-function-commas/7/input.js:1:8]
5158+
1 │ ('foo',)
5159+
· ─
5160+
╰────
5161+
51575162
× Expected `(` but found `await`
51585163
╭─[es2018/async-generators/for-await-async-context/input.js:2:7]
51595164
1 │ function f() {

tasks/coverage/parser_typescript.snap

+9-10
Original file line numberDiff line numberDiff line change
@@ -15431,11 +15431,11 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
1543115431
╰────
1543215432

1543315433
× Unexpected token
15434-
╭─[conformance/expressions/commaOperator/commaOperatorWithoutOperand.ts:16:2]
15435-
15 │ // Missing the first operand
15436-
16 │ (, ANY);
15437-
· ─
15438-
17 │ (, BOOLEAN);
15434+
╭─[conformance/expressions/commaOperator/commaOperatorWithoutOperand.ts:9:7]
15435+
8 │ // Missing the second operand
15436+
9 │ (ANY, );
15437+
·
15438+
10 │ (BOOLEAN, );
1543915439
╰────
1544015440

1544115441
× 'with' statements are not allowed
@@ -15952,13 +15952,12 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
1595215952
· ─
1595315953
╰────
1595415954

15955-
× Expected `>` but found `,`
15956-
╭─[conformance/externalModules/topLevelAwaitErrors.1.ts:5:14]
15955+
× Unexpected token
15956+
╭─[conformance/externalModules/topLevelAwaitErrors.1.ts:4:10]
15957+
3 │ // reparse call as invalid await should error
1595715958
4 │ await (1,);
15959+
· ─
1595815960
5 │ await <number, string>(1);
15959-
· ┬
15960-
· ╰── `>` expected
15961-
6 │
1596215961
╰────
1596315962

1596415963
× Cannot use `await` as an identifier in an async context

0 commit comments

Comments
 (0)