oxc/npm/oxc-transform
2024-11-26 14:38:47 +08:00
..
scripts chore(doc): replace main/master to tag/commit to make the url always accessible (#7298) 2024-11-16 21:00:30 +08:00
CHANGELOG.md release(crates): v0.30.4 (#6134) 2024-09-28 13:08:44 +08:00
package.json release(crates): v0.38.0 (#7490) 2024-11-26 14:38:47 +08:00
README.md docs(transformer): fix formatting of README (#6111) 2024-09-27 14:27:21 +01:00

Oxc Transform

This is alpha software and may yield incorrect results, feel free to submit a bug report.

TypeScript and React JSX Transform

import assert from 'assert';
import oxc from 'oxc-transform';

const { code, declaration, errors } = oxc.transform(
  'test.ts',
  'class A<T> {}',
  {
    typescript: {
      declaration: true, // With isolated declarations in a single step.
    },
  },
);

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 --isolated-declaration .d.ts emit.

Usage

import assert from 'assert';
import oxc from 'oxc-transform';

const { map, code, errors } = oxc.isolatedDeclaration('test.ts', 'class A {}');

assert.equal(code, 'declare class A {}\n');
assert(errors.length == 0);

API

See index.d.ts.

export declare function transform(
  filename: string,
  sourceText: string,
  options?: TransformOptions,
): TransformResult;

export function isolatedDeclaration(
  filename: string,
  sourceText: string,
  options?: IsolatedDeclarationsOptions,
): IsolatedDeclarationsResult;