Skip to content

Commit

Permalink
fix(paresr): do not report missing initializer error in ambient conte…
Browse files Browse the repository at this point in the history
…xt (#6020)

closes #5958
  • Loading branch information
Boshen committed Sep 24, 2024
1 parent 0c9dee1 commit 0658576
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
7 changes: 5 additions & 2 deletions crates/oxc_parser/src/js/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,17 @@ impl<'a> ParserImpl<'a> {
let init =
self.eat(Kind::Eq).then(|| self.parse_assignment_expression_or_higher()).transpose()?;

if init.is_none() && decl_ctx.parent == VariableDeclarationParent::Statement {
if init.is_none()
&& !self.ctx.has_ambient()
&& decl_ctx.parent == VariableDeclarationParent::Statement
{
// LexicalBinding[In, Yield, Await] :
// BindingIdentifier[?Yield, ?Await] Initializer[?In, ?Yield, ?Await] opt
// BindingPattern[?Yield, ?Await] Initializer[?In, ?Yield, ?Await]
// the grammar forbids `let []`, `let {}`
if !matches!(id.kind, BindingPatternKind::BindingIdentifier(_)) {
self.error(diagnostics::invalid_destrucuring_declaration(id.span()));
} else if kind == VariableDeclarationKind::Const && !self.ctx.has_ambient() {
} else if kind == VariableDeclarationKind::Const {
// It is a Syntax Error if Initializer is not present and IsConstantDeclaration of the LexicalDeclaration containing this LexicalBinding is true.
self.error(diagnostics::missinginitializer_in_const(id.span()));
}
Expand Down
20 changes: 1 addition & 19 deletions tasks/coverage/snapshots/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: a709f989

parser_typescript Summary:
AST Parsed : 6469/6479 (99.85%)
Positive Passed: 6456/6479 (99.65%)
Positive Passed: 6458/6479 (99.68%)
Negative Passed: 1226/5715 (21.45%)
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ClassDeclaration10.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ClassDeclaration11.ts
Expand Down Expand Up @@ -4519,15 +4519,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/elidedEmbeddedSt
· ────
24 │ const enum H {}
╰────
Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/moduleAugmentationNoNewNames.ts

× Missing initializer in destructuring declaration
╭─[typescript/tests/cases/compiler/moduleAugmentationNoNewNames.ts:11:9]
10 │ let y: number, z: string;
11 │ let {a: x, b: x1}: {a: number, b: number};
· ─────────────────────────────────────
12 │ module Z {}
╰────
Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/moduleResolutionWithExtensions_unexpected2.ts

× Expected a semicolon or an implicit semicolon after a statement, but found none
Expand All @@ -4554,15 +4545,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/moduleResolution
· ▲
╰────
help: Try insert a semicolon here
Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/newNamesInGlobalAugmentations1.ts

× Missing initializer in destructuring declaration
╭─[typescript/tests/cases/compiler/newNamesInGlobalAugmentations1.ts:11:9]
10 │ class Cls {x}
11 │ let [a, b]: number[];
· ────────────────
12 │ export import X = M.M1.x;
╰────
Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationDecorators.ts

× Unexpected token
Expand Down
8 changes: 2 additions & 6 deletions tasks/coverage/snapshots/semantic_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: a709f989

semantic_typescript Summary:
AST Parsed : 6479/6479 (100.00%)
Positive Passed: 2671/6479 (41.23%)
Positive Passed: 2672/6479 (41.24%)
tasks/coverage/typescript/tests/cases/compiler/2dArrays.ts
semantic error: Symbol reference IDs mismatch:
after transform: SymbolId(0): [ReferenceId(1)]
Expand Down Expand Up @@ -23132,8 +23132,7 @@ after transform: ScopeId(0): ["Observable", "x"]
rebuilt : ScopeId(0): ["x"]

tasks/coverage/typescript/tests/cases/compiler/moduleAugmentationNoNewNames.ts
semantic error: Missing initializer in destructuring declaration
Bindings mismatch:
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["./observable", "Observable"]
rebuilt : ScopeId(0): ["Observable"]
Scope children mismatch:
Expand Down Expand Up @@ -24951,9 +24950,6 @@ Unresolved references mismatch:
after transform: ["a"]
rebuilt : []

tasks/coverage/typescript/tests/cases/compiler/newNamesInGlobalAugmentations1.ts
semantic error: Missing initializer in destructuring declaration

tasks/coverage/typescript/tests/cases/compiler/noAsConstNameLookup.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "Cleaner", "FeatureRunner", "Store"]
Expand Down

0 comments on commit 0658576

Please sign in to comment.