fix(parser): false postive for "Missing initializer in const declaration" in declare + namespace (#1724)

closes #1723
This commit is contained in:
Boshen 2023-12-18 17:03:42 +08:00 committed by GitHub
parent 621a9438a8
commit 19e77b0af3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 16 deletions

View file

@ -89,6 +89,11 @@ impl Context {
self.union_if(Self::Await, include)
}
#[inline]
pub(crate) fn union_ambient_if(self, include: bool) -> Self {
self.union_if(Self::Ambient, include)
}
#[inline]
pub(crate) fn union_yield_if(self, include: bool) -> Self {
self.union_if(Self::Yield, include)

View file

@ -294,14 +294,9 @@ impl<'a> Parser<'a> {
start_span: Span,
) -> Result<Statement<'a>> {
let reserved_ctx = self.ctx;
let (flags, modifiers) = self.eat_modifiers_before_declaration();
let declare = flags.declare();
let r#async = flags.r#async();
self.ctx = self.ctx.and_ambient(declare).and_await(r#async);
self.ctx = self.ctx.union_ambient_if(flags.declare()).and_await(flags.r#async());
let result = self.parse_declaration(start_span, modifiers);
self.ctx = reserved_ctx;
result.map(Statement::Declaration)
}

View file

@ -1,6 +1,6 @@
parser_babel Summary:
AST Parsed : 2090/2096 (99.71%)
Positive Passed: 2087/2096 (99.57%)
Positive Passed: 2088/2096 (99.62%)
Negative Passed: 1350/1499 (90.06%)
Expect Syntax Error: "annex-b/disabled/1.1-html-comments-close/input.js"
Expect Syntax Error: "annex-b/disabled/3.1-sloppy-labeled-functions/input.js"
@ -197,15 +197,6 @@ Expect to Parse: "typescript/interface/get-set-properties/input.ts"
3 │ set bar: string;
╰────
Expect to Parse: "typescript/module-namespace/body-nested-declare/input.ts"
× Missing initializer in const declaration
╭─[typescript/module-namespace/body-nested-declare/input.ts:2:1]
2 │ namespace B {
3 │ const x: number;
· ─
4 │ }
╰────
Expect to Parse: "typescript/regression/nested-extends-in-arrow-type-param/input.ts"
× Expected `,` but found `extends`
╭─[typescript/regression/nested-extends-in-arrow-type-param/input.ts:1:1]