Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions crates/oxc_parser/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ pub fn expect_token(x0: &str, x1: &str, span: Span) -> OxcDiagnostic {
.with_label(span.label(format!("`{x0}` expected")))
}

#[cold]
pub fn unexpected_trailing_comma(name: &'static str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::error(format!("{name} may not have a trailing comma."))
.with_label(span)
.with_help("Remove the trailing comma here")
}

#[cold]
pub fn invalid_escape_sequence(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Invalid escape sequence").with_label(span)
Expand Down Expand Up @@ -236,9 +243,7 @@ pub fn spread_last_element(span: Span) -> OxcDiagnostic {

#[cold]
pub fn rest_element_trailing_comma(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("A rest parameter or binding pattern may not have a trailing comma.")
.with_label(span)
.with_help("Remove the trailing comma here")
unexpected_trailing_comma("A rest parameter or binding pattern", span)
}

#[cold]
Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_parser/src/js/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ impl<'a> ParserImpl<'a> {
});

if let Some(comma_span) = comma_span {
let error = diagnostics::expect_token(")", ",", self.end_span(comma_span));
let error = diagnostics::unexpected_trailing_comma(
"Parenthesized expressions",
self.end_span(comma_span),
);
return self.fatal_error(error);
}

Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_parser/src/ts/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,10 @@ impl<'a> ParserImpl<'a> {
Self::parse_ts_index_signature_name,
);
if let Some(comma_span) = comma_span {
self.error(diagnostics::expect_token("]", ",", self.end_span(comma_span)));
self.error(diagnostics::unexpected_trailing_comma(
"Index signature declarations",
self.end_span(comma_span),
));
}
self.expect(Kind::RBrack);
if params.len() != 1 {
Expand Down
6 changes: 3 additions & 3 deletions tasks/coverage/snapshots/parser_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5912,12 +5912,12 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
· ─
╰────

× Expected `)` but found `,`
× Parenthesized expressions may not have a trailing comma.
╭─[babel/packages/babel-parser/test/fixtures/es2017/trailing-function-commas/7/input.js:1:7]
1 │ ('foo',)
· ┬
· ╰── `)` expected
· ─
╰────
help: Remove the trailing comma here

× `await` is only allowed within async functions and at the top levels of modules
╭─[babel/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-async-context/input.js:2:7]
Expand Down
24 changes: 12 additions & 12 deletions tasks/coverage/snapshots/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8738,32 +8738,32 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
3 │ }
╰────

× Expected `]` but found `,`
× Index signature declarations may not have a trailing comma.
╭─[typescript/tests/cases/compiler/indexSignatureWithTrailingComma.ts:2:17]
1 │ type A = {
2 │ [key: string,]: string;
· ┬
· ╰── `]` expected
· ─
3 │ };
╰────
help: Remove the trailing comma here

× Expected `]` but found `,`
× Index signature declarations may not have a trailing comma.
╭─[typescript/tests/cases/compiler/indexSignatureWithTrailingComma.ts:6:17]
5 │ interface B {
6 │ [key: string,]: string;
· ┬
· ╰── `]` expected
· ─
7 │ }
╰────
help: Remove the trailing comma here

× Expected `]` but found `,`
× Index signature declarations may not have a trailing comma.
╭─[typescript/tests/cases/compiler/indexSignatureWithTrailingComma.ts:10:17]
9 │ class C {
10 │ [key: string,]: null;
· ┬
· ╰── `]` expected
· ─
11 │ }
╰────
help: Remove the trailing comma here

× TS(1021): An index signature must have a type annotation.
╭─[typescript/tests/cases/compiler/indexSignatureWithoutTypeAnnotation1.ts:2:3]
Expand Down Expand Up @@ -20386,14 +20386,14 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
8 │ this += value;
╰────

× Expected `)` but found `,`
× Parenthesized expressions may not have a trailing comma.
╭─[typescript/tests/cases/conformance/expressions/commaOperator/commaOperatorWithoutOperand.ts:9:5]
8 │ // Missing the second operand
9 │ (ANY, );
· ┬
· ╰── `)` expected
· ─
10 │ (BOOLEAN, );
╰────
help: Remove the trailing comma here

× 'with' statements are not allowed
╭─[typescript/tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts:2:1]
Expand Down
2 changes: 1 addition & 1 deletion tasks/track_memory_allocations/allocs_parser.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ File | File size || Sys allocs | Sys reallocs |
-------------------------------------------------------------------------------------------------------------------------------------------
checker.ts | 2.92 MB || 10165 | 21 || 268665 | 23341

cal.com.tsx | 1.06 MB || 2209 | 61 || 138188 | 13712
cal.com.tsx | 1.06 MB || 2210 | 62 || 138188 | 13712

RadixUIAdoptionSection.jsx | 2.52 kB || 1 | 0 || 365 | 66

Expand Down
Loading