diff --git a/npm/parser-wasm/README.md b/npm/parser-wasm/README.md index df79941349ba7..742ea1dd1c596 100644 --- a/npm/parser-wasm/README.md +++ b/npm/parser-wasm/README.md @@ -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: diff --git a/wasm/parser/README.md b/wasm/parser/README.md index df79941349ba7..742ea1dd1c596 100644 --- a/wasm/parser/README.md +++ b/wasm/parser/README.md @@ -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: