Repository navigation
feat: add source type and extension selects - #488
Merged
Merged
Conversation
Default new inputs to module semantics so transformed runtime helpers use ESM imports without requiring import or export syntax. Expose the parser's four source-type modes and preserve older shared URLs' behavior. Replace the extension text field with supported choices, including TypeScript declaration files, and use the TypeScript parser for their Prettier comparison.
Dunqing
marked this pull request as ready for review
November 16, 2026 03:25
Dunqing
enabled auto-merge (squash)
November 16, 2026 03:26
Dunqing
added a commit
to oxc-project/oxc
that referenced
this pull request
Nov 16, 2026
The playground binding cannot override source type, so TSX without import/export syntax emits `require()` helpers. Its public declarations also lack `sourceType`, blocking type-checking in [oxc-project/playground#488](oxc-project/playground#488). Expose the parser's `script`, `module`, `commonjs`, and `unambiguous` modes through `oxc_napi::get_source_type`. Preserve extension-based language selection and inference when the option is omitted. Copy the generated WASI declarations to the public `index.d.ts` during binding patching. ### Example Input ([playground for this input and configuration](https://playground.oxc.rs/?t=codegen&options=%7B%22run%22%3A%7B%22lint%22%3Afalse%2C%22formatter%22%3Afalse%2C%22transform%22%3Atrue%2C%22isolatedDeclarations%22%3Afalse%2C%22whitespace%22%3Afalse%2C%22compress%22%3Afalse%2C%22mangle%22%3Afalse%2C%22scope%22%3Afalse%2C%22symbol%22%3Afalse%2C%22cfg%22%3Afalse%7D%2C%22parser%22%3A%7B%22extension%22%3A%22tsx%22%2C%22sourceType%22%3A%22module%22%2C%22allowReturnOutsideFunction%22%3Afalse%2C%22preserveParens%22%3Atrue%2C%22allowV8Intrinsics%22%3Afalse%2C%22semanticErrors%22%3Atrue%7D%2C%22transformer%22%3A%7B%22target%22%3A%22es2015%22%2C%22useDefineForClassFields%22%3Atrue%2C%22experimentalDecorators%22%3Afalse%2C%22emitDecoratorMetadata%22%3Afalse%2C%22optimizeEnums%22%3Atrue%2C%22optimizeConstEnums%22%3Atrue%7D%7D&code=class+A+%7B+%23a+%3D+0%3B+%7D)): ```js class A { #a = 0; } ``` Both binding builds use `extension: "tsx"`, `sourceType: "module"`, and transformer target `es2015`, with npm runtime helpers. The playground link contains the same run, parser, and transformer options; the deployed binding cannot demonstrate the new `sourceType` option until updated. Before output (parent `e4703b1848`): ```js var _classPrivateFieldInitSpec = require("@oxc-project/runtime/helpers/classPrivateFieldInitSpec"); var _a = /* @__PURE__ */ new WeakMap(); class A { constructor() { _classPrivateFieldInitSpec(this, _a, 0); } } ``` After output: ```js import _classPrivateFieldInitSpec from "@oxc-project/runtime/helpers/classPrivateFieldInitSpec"; var _a = /* @__PURE__ */ new WeakMap(); class A { constructor() { _classPrivateFieldInitSpec(this, _a, 0); } } ``` The explicit Module mode now emits an ESM helper import. Both runs have no diagnostics and produce identical serialized source maps. Verified the WASM development build on Rust 1.100.0; temporary Node/WASI assertions for all four modes, omitted-option inference, CommonJS top-level return, JavaScript strictness, TSX parsing, and source-map content; `just lint -p oxc_playground_napi`; Rust/script formatting and script lint. Playground `vue-tsc` reproduces exactly four `sourceType` errors with the parent's declarations and passes with the newly generated declarations. No persistent playground tests added. AI assistance: implementation and verification were prepared with an AI coding assistant.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Inputs without import/export syntax currently emit CommonJS runtime helpers. Default new playground inputs to Module and expose the parser's Module, Script, CommonJS, and Unambiguous modes. Preserve older shared URLs' extension-based behavior.
Replace the extension text field with supported choices, including TypeScript declaration files, and use Prettier's TypeScript parser for declaration files. Both selects follow the refreshed settings UI on main.
Verified formatting, type checks/lint, generated linter rules, production build, and browser selection/URL behavior against the locally patched WASM binding. No tests added. The browser preview logs Monaco service-initialization errors that also reproduce on unchanged main at
9eb4a21.Draft dependency: the companion Oxc playground binding change must expose
sourceTypeusingoxc_napi::get_source_type. That change is local and unpublished. CI's Build job is expected to fail until it lands because CI builds the Oxc binding from main.