Files
oxc-project__oxc/tasks/coverage/misc/pass/oxc-22158.js
Boshen b284045af2 fix(parser): switch to module goal eagerly on export (#22684)
## Summary

In unambiguous (`.js` auto-detect) sources, `export var x = await + 1;` reported a spurious `Duplicated export 'x'` error. The parser first parsed the statement with `await` as an identifier, then re-parsed it under `Context::Await` to patch the AST — but the second pass re-invoked `visit_export_named_declaration`, recording the binding `x` a second time in the module record.

`export` is unambiguously module syntax per ECMA-262 §16.2.3 (`ExportDeclaration` is only a `ModuleItem`, never a Script production). So commit to the Module goal — enable `Context::Await` — as soon as the next top-level token is `Kind::Export`. The statement then parses correctly on the first attempt; no reparse and no duplicate record.

`Kind::Import` is intentionally **not** eager-switched. TypeScript's `import name = ns.path` is a script-compatible namespace alias (see `topLevelAwait.2.ts`), so treating `import` as a module starter would break that case.

The only TS snapshot churn is +16 lines of additional error messages for already-failing tests (`topLevelAwaitErrors.5.ts`, `topLevelAwaitErrors.6.ts` — `export ... await`). Summary counts unchanged.

Closes #22520
Fixes #22158
2026-05-23 06:00:04 +00:00

7 lines
268 B
JavaScript

// https://github.com/oxc-project/oxc/issues/22158
// `await` in initializer of an `export var` declaration must not be
// reported as a duplicated export when parsed with unambiguous `.js`.
export var a = await + 1;
export var b = await(1);
export var c = await + 0;