mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
e4cea255b7
Hi, This PR simply updates the documentation example in `napi/transform/README.md` to use the `node:` namespace when importing a Node.js built-in module. As far as I know, the `node:` namespace prefix for built-in modules was introduced in Node.js `14.18.0` and `16.0.0`, so it should work with the current Node.js supported version range. https://github.com/oxc-project/oxc/blob/6245c5629f2ca3bbbfbaffd1400fad06cc23d659/napi/transform/package.json#L87-L89 Also, it appears that the other source files already use it when importing Node.js built-in modules. https://github.com/oxc-project/oxc/blob/6245c5629f2ca3bbbfbaffd1400fad06cc23d659/napi/transform/scripts/patch.js#L1-L2 https://github.com/oxc-project/oxc/blob/6245c5629f2ca3bbbfbaffd1400fad06cc23d659/napi/transform/webcontainer-fallback.cjs#L1-L2 Please let me know if there's anything wrong with this change!
2.1 KiB
2.1 KiB
Oxc Transform
See usage instructions.
TypeScript and React JSX Transform
import assert from "node:assert";
import { transformSync } from "oxc-transform";
const { code, declaration, errors } = transformSync("test.ts", "class A<T> {}", {
typescript: {
declaration: true, // With isolated declarations in a single step.
},
});
// or `await transform(filename, code, options)`
assert.equal(code, "class A {}\n");
assert.equal(declaration, "declare class A<T> {}\n");
assert(errors.length == 0);
Isolated Declarations for Standalone DTS Emit
Conforms to TypeScript compiler's --isolatedDeclarations .d.ts emit.
Usage
import assert from "node:assert";
import { isolatedDeclarationSync } from "oxc-transform";
const { map, code, errors } = isolatedDeclarationSync("test.ts", "class A {}");
// or `await isolatedDeclaration(filename, code, options)`
assert.equal(code, "declare class A {}\n");
assert(errors.length == 0);
API
Transform Functions
// Synchronous transform
transformSync(
filename: string,
sourceText: string,
options?: TransformOptions,
): TransformResult
// Asynchronous transform
transform(
filename: string,
sourceText: string,
options?: TransformOptions,
): Promise<TransformResult>
Isolated Declaration Functions
// Synchronous isolated declaration
isolatedDeclarationSync(
filename: string,
sourceText: string,
options?: IsolatedDeclarationsOptions,
): IsolatedDeclarationsResult
// Asynchronous isolated declaration
isolatedDeclaration(
filename: string,
sourceText: string,
options?: IsolatedDeclarationsOptions,
): Promise<IsolatedDeclarationsResult>
Use the Sync versions for synchronous operations. Use async versions for asynchronous operations, which can be beneficial in I/O-bound or concurrent scenarios, though they add async overhead.
See index.d.ts for complete type definitions.
Supports WASM
See https://stackblitz.com/edit/oxc-transform for usage example.