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:
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)
usingdeclarations are not allowed at the top level withsourceType: script, which is correct behavior as stated in ES2026.However, in the case of CommonJS, top-level
usingmay be allowed.In fact, if you run the following code in Node.js v24.2.0 it will work correctly:
run:
output:
In order to parse this code, I would like
acornto add theallowTopLevelUsingDeclarationoption so that it always allows top-levelusingdeclarations.Related to #1373 (comment)