fix(parser): allow non-last rest element in ambient contexts

This commit is contained in:
Boshen 2023-04-02 15:57:13 +08:00
parent be9b3f9acc
commit 7db1643425
4 changed files with 4 additions and 19 deletions

View file

@ -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")]

View file

@ -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));
}
}

View file

@ -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

View file

@ -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 {