Files
oxc-project__oxc/napi/parser/test-browser/parse.test.ts
Boshen 66b8c022ab feat(parser): implement unambiguous module parsing for JS/TS files (#18124)
## Summary

- Implements speculative/unambiguous parsing for `.js`, `.jsx`, `.ts`, and `.tsx` files
- Instead of assuming module or script upfront, parses with `ModuleKind::Unambiguous` and upgrades to module mode when ESM syntax is detected
- ESM indicators: `import`, `export`, `import.meta` (NOT top-level await alone)
- Defers top-level await errors until module type is resolved
- Vue loader upgrades unambiguous scripts to module mode
- Updates linter tests to use explicit ESM extensions (`.mjs`/`.mts`) where needed

## Test plan

- [x] All parser tests pass
- [x] All linter tests pass
- [x] All semantic tests pass
- [x] Coverage conformance tests updated

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-01-17 13:40:28 +00:00

55 lines
1.1 KiB
TypeScript

import { expect, test } from "vitest";
import { parse, parseSync } from "../src-js/wasm.js";
test("parseSync", () => {
const result = parseSync("test.mjs", "ok");
expect(result.program).toMatchInlineSnapshot(`
{
"body": [
{
"end": 2,
"expression": {
"end": 2,
"name": "ok",
"start": 0,
"type": "Identifier",
},
"start": 0,
"type": "ExpressionStatement",
},
],
"end": 2,
"hashbang": null,
"sourceType": "module",
"start": 0,
"type": "Program",
}
`);
});
test("parse", async () => {
const result = await parse("test.mjs", "ok");
expect(result.program).toMatchInlineSnapshot(`
{
"body": [
{
"end": 2,
"expression": {
"end": 2,
"name": "ok",
"start": 0,
"type": "Identifier",
},
"start": 0,
"type": "ExpressionStatement",
},
],
"end": 2,
"hashbang": null,
"sourceType": "module",
"start": 0,
"type": "Program",
}
`);
});