docs(napi): simplify + reformat README (#6834)

In particular:

* the long comment was scrolling off side of screen on
[npm.com](https://www.npmjs.com/package/oxc-parser).
* the example is ESM, so can simplify it by using top level await.
This commit is contained in:
overlookmotel 2024-10-24 01:34:46 +01:00 committed by GitHub
parent dcddbeb689
commit d48e008e47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,29 +1,22 @@
# The JavaScript Oxidation Compiler # The JavaScript Oxidation Compiler
See index.d.ts for `parseSync` and `parseAsync` API. See `index.d.ts` for `parseSync` and `parseAsync` API.
## ESM
```javascript ```javascript
import assert from 'assert'; import assert from 'assert';
import oxc from 'oxc-parser'; import oxc from 'oxc-parser';
const sourceText = "let foo: Foo = 'foo';";
// Filename extension is used to determine which
// dialect to parse source as
const options = { sourceFilename: 'text.tsx' };
test(oxc.parseSync(sourceText, options));
test(await oxc.parseAsync(sourceText, options));
function test(ret) { function test(ret) {
const program = JSON.parse(ret.program); const program = JSON.parse(ret.program);
assert(program.body.length == 1); assert(program.body.length == 1);
assert(ret.errors.length == 0); assert(ret.errors.length == 0);
} }
const sourceText = "let foo: Foo = 'foo';";
const options = {
sourceFilename: 'text.tsx', // the extension is used to determine which dialect to parse
};
test(oxc.parseSync(sourceText, options));
async function main() {
test(await oxc.parseAsync(sourceText, options));
}
main();
``` ```