Skip to content

Missing init on destructuring not flagged as syntax error when inside for loop #8220

@marvinhagemeister

Description

@marvinhagemeister

This code should be a syntax error, but is parsed successfully in OXC. Other parsers like Babel and SWC throw a syntax error as expected.

for (let { x };;);

Interestingly, OXC seems to be able to detect the missing initializer properly when it's outside of the for loop:

// throws: Error: Missing initializer in destructuring declaration
let { x }

Babel:

Missing initializer in destructuring declaration. (1:14)

> 1 | for (let { x };;);
    |               ^

SWC:

  x Destructuring bindings require initializers
   ,-[input.tsx:1:1]
 1 | for (let { x };;);
   :          ^^^^^
   `----

Metadata

Metadata

Assignees

Labels

C-bugCategory - Bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions