Skip to content

Feature Request: Add option to parse CommonJS #1376

@ota-meshi

Description

@ota-meshi

using declarations are not allowed at the top level with sourceType: script, which is correct behavior as stated in ES2026.

However, in the case of CommonJS, top-level using may be allowed.
In fact, if you run the following code in Node.js v24.2.0 it will work correctly:

// test.cjs
using x = {
    [Symbol.dispose]() {
        console.log('dispose')
    }
};
console.log(x);

run:

node -v
node test.cjs

output:

v24.2.0
{ Symbol(Symbol.dispose): [Function: [Symbol.dispose]] }
dispose

In order to parse this code, I would like acorn to add the allowTopLevelUsingDeclaration option so that it always allows top-level using declarations.


Related to #1373 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions