Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions npm/parser-wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,43 @@ And exports the files as
"types": "./node/oxc_parser_wasm.d.ts",
```

Checkout [oxc-parser](https://www.npmjs.com/package/oxc-parser) for usage in node.js via napi bindings.
Check out [oxc-parser](https://www.npmjs.com/package/oxc-parser) for an alternative in Node.js
which performs the same function, but using native code via NAPI bindings (slightly faster).

Source code: https://github.com/oxc-project/oxc/tree/main/wasm/parser

## Usage

### Node.js

```js
import initWasm, { parseSync } from '@oxc-parser/wasm';
import { parseSync } from '@oxc-parser/wasm';

const code = 'let foo';
const result = parseSync(code, { sourceFilename: 'test.ts' });
console.log(result.program);
```

async function main() {
await initWasm();
### Browser

const code = 'let foo';
const result = parseSync(code, { sourceFilename: 'test.ts' });
console.log(result);
}
```js
import { initSync, parseSync } from '@oxc-parser/wasm';

main();
initSync();

const code = 'let foo';
const result = parseSync(code, { sourceFilename: 'test.ts' });
console.log(result.program);
```

## Notes

The AST returned conforms to the [ESTree](https://github.com/estree/estree) spec for JS syntax.

For TypeScript code, the AST is broadly aligned with
[typescript-eslint](https://typescript-eslint.io/packages/parser/)'s format, though there may be some
differences.

### UTF8 vs UTF16 byte offsets

The `span` value returned from the ASTs and diagnostics is in UTF8 byte offsets. Converting to UTF16 byte offsets:
Expand Down
33 changes: 24 additions & 9 deletions wasm/parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,43 @@ And exports the files as
"types": "./node/oxc_parser_wasm.d.ts",
```

Checkout [oxc-parser](https://www.npmjs.com/package/oxc-parser) for usage in node.js via napi bindings.
Check out [oxc-parser](https://www.npmjs.com/package/oxc-parser) for an alternative in Node.js
which performs the same function, but using native code via NAPI bindings (slightly faster).

Source code: https://github.com/oxc-project/oxc/tree/main/wasm/parser

## Usage

### Node.js

```js
import initWasm, { parseSync } from '@oxc-parser/wasm';
import { parseSync } from '@oxc-parser/wasm';

const code = 'let foo';
const result = parseSync(code, { sourceFilename: 'test.ts' });
console.log(result.program);
```

async function main() {
await initWasm();
### Browser

const code = 'let foo';
const result = parseSync(code, { sourceFilename: 'test.ts' });
console.log(result);
}
```js
import { initSync, parseSync } from '@oxc-parser/wasm';

main();
initSync();

const code = 'let foo';
const result = parseSync(code, { sourceFilename: 'test.ts' });
console.log(result.program);
```

## Notes

The AST returned conforms to the [ESTree](https://github.com/estree/estree) spec for JS syntax.

For TypeScript code, the AST is broadly aligned with
[typescript-eslint](https://typescript-eslint.io/packages/parser/)'s format, though there may be some
differences.

### UTF8 vs UTF16 byte offsets

The `span` value returned from the ASTs and diagnostics is in UTF8 byte offsets. Converting to UTF16 byte offsets:
Expand Down