mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
66b8c022ab
## 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)
55 lines
1.1 KiB
TypeScript
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",
|
|
}
|
|
`);
|
|
});
|