diff --git a/crates/oxc_parser/src/diagnostics.rs b/crates/oxc_parser/src/diagnostics.rs index cf1cc42d7..cf938ae9a 100644 --- a/crates/oxc_parser/src/diagnostics.rs +++ b/crates/oxc_parser/src/diagnostics.rs @@ -130,7 +130,7 @@ pub struct ClassDeclaration(#[label] pub Span); #[derive(Debug, Error, Diagnostic)] #[error("Rest element must be last element")] #[diagnostic()] -pub struct RestElement(#[label] pub Span); +pub struct RestElementLast(#[label] pub Span); #[derive(Debug, Error, Diagnostic)] #[error("Spread must be last element")] diff --git a/crates/oxc_parser/src/js/binding.rs b/crates/oxc_parser/src/js/binding.rs index de4614e92..715ef20f9 100644 --- a/crates/oxc_parser/src/js/binding.rs +++ b/crates/oxc_parser/src/js/binding.rs @@ -56,8 +56,8 @@ impl<'a> Parser<'a> { if self.at(Kind::Comma) { if self.peek_at(Kind::RBrack) { self.error(diagnostics::RestElementTrailingComma(self.cur_token().span())); - } else { - self.error(diagnostics::RestElement(span)); + } else if !self.ctx.has_ambient() { + self.error(diagnostics::RestElementLast(span)); } } diff --git a/tasks/coverage/babel.snap b/tasks/coverage/babel.snap index 645d184cc..af146f469 100644 --- a/tasks/coverage/babel.snap +++ b/tasks/coverage/babel.snap @@ -1,6 +1,6 @@ Babel Summary: AST Parsed : 2065/2071 (99.71%) -Positive Passed: 2057/2071 (99.32%) +Positive Passed: 2058/2071 (99.37%) Negative Passed: 1332/1502 (88.68%) Expect Syntax Error: "annex-b/disabled/1.1-html-comments-close/input.js" Expect Syntax Error: "annex-b/disabled/3.1-sloppy-labeled-functions-if-body/input.js" @@ -240,13 +240,6 @@ Expect to Parse: "typescript/class/constructor-with-modifier-names/input.ts" · ╰── it cannot be redeclared here 4 │ } ╰──── -Expect to Parse: "typescript/declare/function-rest-trailing-comma/input.ts" - - × Rest element must be last element - ╭─[typescript/declare/function-rest-trailing-comma/input.ts:1:1] - 1 │ declare function foo(...args: any[], ) - · ────────────── - ╰──── Expect to Parse: "typescript/dts/no-initializer/input.ts" × Missing initializer in const declaration diff --git a/tasks/coverage/typescript.snap b/tasks/coverage/typescript.snap index 784b96898..548fd2967 100644 --- a/tasks/coverage/typescript.snap +++ b/tasks/coverage/typescript.snap @@ -7241,14 +7241,6 @@ Expect to Parse: "salsa/privateIdentifierExpando.ts" 8 │ ╰──── - × Rest element must be last element - ╭─[es7/trailingCommasInFunctionParametersAndArguments.ts:9:1] - 9 │ // Allowed for ambient declarations - 10 │ declare function f25(...args,): void; - · ─────── - 11 │ - ╰──── - × Unexpected token ╭─[es7/trailingCommasInGetter.ts:1:1] 1 │ class X {