mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
docs(oxc-transform): update README
This commit is contained in:
parent
fd6798ffbc
commit
26a273a462
1 changed files with 33 additions and 21 deletions
|
|
@ -1,10 +1,31 @@
|
|||
# Oxc Transform
|
||||
|
||||
This is alpha software and may yield incorrect results, feel free to [submit a bug report](https://github.com/oxc-project/oxc/issues/new?assignees=&labels=C-bug&projects=&template=bug_report.md).
|
||||
|
||||
## TypeScript and React JSX Transform
|
||||
|
||||
```javascript
|
||||
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](https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-beta/#isolated-declarations)
|
||||
|
||||
Based on Oxc and conforms to TypeScript Compiler's `--isolated-declaration` `.d.ts` emit.
|
||||
|
||||
This is still in alpha and may yield incorrect results, feel free to [submit a bug report](https://github.com/oxc-project/oxc/issues/new?assignees=&labels=C-bug&projects=&template=bug_report.md&title=isolated-declarations:).
|
||||
Conforms to TypeScript Compiler's `--isolated-declaration` `.d.ts` emit.
|
||||
|
||||
### Usage
|
||||
|
||||
|
|
@ -12,35 +33,26 @@ This is still in alpha and may yield incorrect results, feel free to [submit a b
|
|||
import assert from 'assert';
|
||||
import oxc from 'oxc-transform';
|
||||
|
||||
const { map, code, errors } = oxc.isolatedDeclaration('test.ts', 'class A {}', { sourcemap: true });
|
||||
const { map, code, errors } = oxc.isolatedDeclaration('test.ts', 'class A {}');
|
||||
|
||||
assert.equal(code, 'declare class A {}\n');
|
||||
assert.deepEqual(map, {
|
||||
mappings: 'AAAA,cAAM,EAAE,CAAE',
|
||||
names: [],
|
||||
sources: ['test.ts'],
|
||||
sourcesContent: ['class A {}'],
|
||||
});
|
||||
assert(errors.length == 0);
|
||||
```
|
||||
|
||||
### API
|
||||
|
||||
See `index.d.ts`.
|
||||
|
||||
```typescript
|
||||
export declare function transform(
|
||||
filename: string,
|
||||
sourceText: string,
|
||||
options?: TransformOptions
|
||||
): TransformResult;
|
||||
|
||||
export function isolatedDeclaration(
|
||||
filename: string,
|
||||
sourceText: string,
|
||||
options?: IsolatedDeclarationsOptions,
|
||||
): IsolatedDeclarationsResult;
|
||||
|
||||
export interface IsolatedDeclarationsOptions {
|
||||
stripInternal?: boolean;
|
||||
sourcemap?: boolean;
|
||||
}
|
||||
|
||||
export interface IsolatedDeclarationsResult {
|
||||
code: string;
|
||||
map?: SourceMap;
|
||||
errors: Array<string>;
|
||||
}
|
||||
```
|
||||
|
|
|
|||
Loading…
Reference in a new issue