Skip to content

feat: add source type and extension selects - #488

Merged
Dunqing merged 1 commit into
mainfrom
claude/awesome-kilby-84e92a
Nov 16, 2026
Merged

Dunqing merged 1 commit into
mainfrom
claude/awesome-kilby-84e92a

Conversation

@Dunqing

@Dunqing Dunqing commented Nov 16, 2026

Copy link
Copy Markdown
Member

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 sourceType using oxc_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.

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
Dunqing marked this pull request as ready for review November 16, 2026 03:25
@Dunqing
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.
@github-actions

Copy link
Copy Markdown
Contributor

@Dunqing
Dunqing merged commit e7e086a into main Nov 16, 2026
6 of 7 checks passed
@Dunqing
Dunqing deleted the claude/awesome-kilby-84e92a branch November 16, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant