{"name":"yuku-parser","version":"0.6.1","keywords":["acorn","ast","babel","compiler","ecmascript","espree","fast","javascript","js","jsx","lexer","napi","oxc","parser","rust","swc","tokenizer","ts","tsx","typescript"],"license":"MIT","_id":"yuku-parser@0.6.1","maintainers":[{"name":"arshadyaseen","email":"arshadpyaseen@gmail.com"}],"homepage":"https://github.com/yuku-toolchain/yuku#readme","bugs":{"url":"https://github.com/yuku-toolchain/yuku/issues"},"dist":{"shasum":"02db66bb4f7f4003cf548b1ef49a3cb5419fd8c1","tarball":"http://registry-npm.ywwl.com/yuku-parser/download/yuku-parser-0.6.1.tgz","fileCount":7,"integrity":"sha512-dPE3/+H2VBw9LhjoIVeW/axKidYGd+XzNtrwGGseZ0325cQFl0Dpwyh0R74XWe/WqQn4M8CR5YApsv2KF2zN1A==","signatures":[{"sig":"MEUCIAZMmYOG0lOWfYINvCwwUqDBIHYmQJIEpJktk41PpgWuAiEA9ridrHj5Cgg1SJPoMAPSISkAR1FJ6Lfcn80xRU+gDcc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/yuku-parser@0.6.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":67478,"size":16226,"noattachment":false,"key":"/yuku-parser/-/yuku-parser-0.6.1.tgz"},"main":"index.js","type":"module","_from":"file:yuku-parser-0.6.1.tgz","types":"index.d.ts","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:8017ba33-3756-4ee3-b8f1-8abb63744a15"}},"_resolved":"/home/runner/work/yuku/yuku/npm/yuku-parser/yuku-parser-0.6.1.tgz","_integrity":"sha512-dPE3/+H2VBw9LhjoIVeW/axKidYGd+XzNtrwGGseZ0325cQFl0Dpwyh0R74XWe/WqQn4M8CR5YApsv2KF2zN1A==","repository":{"url":"git+https://github.com/yuku-toolchain/yuku.git","type":"git"},"_npmVersion":"11.18.0","description":"High-performance JavaScript/TypeScript parser","directories":{},"_nodeVersion":"24.18.0","dependencies":{"@yuku-toolchain/types":"0.5.43"},"_hasShrinkwrap":false,"optionalDependencies":{"@yuku-parser/binding-win32-x64":"0.6.1","@yuku-parser/binding-darwin-x64":"0.6.1","@yuku-parser/binding-freebsd-x64":"0.6.1","@yuku-parser/binding-win32-arm64":"0.6.1","@yuku-parser/binding-darwin-arm64":"0.6.1","@yuku-parser/binding-linux-arm-gnu":"0.6.1","@yuku-parser/binding-linux-x64-gnu":"0.6.1","@yuku-parser/binding-linux-arm-musl":"0.6.1","@yuku-parser/binding-linux-x64-musl":"0.6.1","@yuku-parser/binding-linux-arm64-gnu":"0.6.1","@yuku-parser/binding-linux-arm64-musl":"0.6.1"},"_npmOperationalInternal":{"tmp":"tmp/yuku-parser_0.6.1_1783868075394_0.16367451314200188","host":"s3://npm-registry-packages-npm-production"},"readme":"# yuku-parser\n\nA fast, spec-compliant JavaScript and TypeScript parser, part of [Yuku](https://yuku.fyi).\n\n- [Install](#install)\n- [Usage](#usage)\n- [The AST](#the-ast)\n- [Options](#options)\n- [Result](#result)\n- [Diagnostics](#diagnostics)\n- [Comments](#comments)\n- [Tokens](#tokens)\n\n## Install\n\n```bash\nnpm install yuku-parser\n```\n\nIt runs on Yuku's native core, installed for your platform. In browsers and edge runtimes, load the WebAssembly core from [`@yuku-core/wasm`](https://www.npmjs.com/package/@yuku-core/wasm) and pass it in as `core`.\n\n## Usage\n\n```js\nimport { parse } from \"yuku-parser\";\n\nconst { program, comments, diagnostics } = parse(\"const x = 1 + 2;\");\n```\n\n## The AST\n\n[ESTree](https://github.com/estree/estree) for JavaScript and JSX, identical to [Acorn](https://www.npmjs.com/package/acorn), and [TypeScript-ESTree](https://www.npmjs.com/package/@typescript-eslint/typescript-estree) for TypeScript, matching [Oxc](https://oxc.rs) for both. On top of the specs, it carries stage 3 [decorators](https://github.com/tc39/proposal-decorators), [import defer](https://github.com/tc39/proposal-defer-import-eval) and [import source](https://github.com/tc39/proposal-source-phase-imports) as `phase` on imports and `ImportExpression`, and the `hashbang` of `Program`.\n\nEvery node type is exported, listed in the [type definitions](https://github.com/yuku-toolchain/yuku/blob/main/npm/yuku-types/index.d.ts).\n\n```ts\nimport type { Expression, Identifier, Node, Statement } from \"yuku-parser\";\n```\n\nTo walk, build, and check nodes, use [`yuku-ast`](https://www.npmjs.com/package/yuku-ast). For scopes and bindings, use [`yuku-analyzer`](https://www.npmjs.com/package/yuku-analyzer).\n\n## Options\n\n```js\nparse(source, { path: \"src/app.tsx\" });\n```\n\n| Option           | Values                                    | Default    | Description                                                                                        |\n| ---------------- | ----------------------------------------- | ---------- | -------------------------------------------------------------------------------------------------- |\n| `path`           | a file path                               | none       | Names the file in diagnostics. `lang` and `sourceType` default from its extension.                 |\n| `lang`           | `\"js\"`, `\"jsx\"`, `\"ts\"`, `\"tsx\"`, `\"dts\"` | `\"js\"`     | The syntax to parse. `.d.ts`, `.tsx`, `.ts`, and `.jsx` paths select their own.                    |\n| `sourceType`     | `\"module\"`, `\"script\"`, `\"commonjs\"`      | `\"module\"` | `\"commonjs\"` allows top-level `return`, and `.cjs` and `.cts` paths select it.                     |\n| `preserveParens` | `true`, `false`                           | `true`     | Keep `ParenthesizedExpression` nodes.                                                              |\n| `semanticErrors` | `true`, `false`                           | `false`    | Also report the early errors that need scopes, such as redeclarations and `break` outside a loop.  |\n| `attachComments` | `true`, `false`                           | `false`    | Also attach each comment to its node. See [Comments](#comments).                                   |\n| `tokens`         | `true`, `false`                           | `false`    | Keep every token. See [Tokens](#tokens).                                                           |\n| `core`           | a loaded core                             | native     | The core that parses, see [`@yuku-core/wasm`](https://www.npmjs.com/package/@yuku-core/wasm).      |\n\nAn unknown `lang` or `sourceType` throws a `TypeError`. `langFromPath(path)` and `sourceTypeFromPath(path)` return the values a path implies.\n\n## Result\n\n```ts\ninterface ParseResult {\n  program: Program;\n  comments: Comment[];\n  tokens?: TokenList; // with tokens: true\n  diagnostics: Diagnostic[];\n}\n```\n\nThe parser recovers from errors, so a result with diagnostics still holds a tree of everything it could read.\n\n## Diagnostics\n\nEvery Yuku package reports diagnostics in one shape.\n\n```ts\ninterface Diagnostic {\n  severity: \"error\" | \"warning\" | \"hint\" | \"info\";\n  message: string;\n  path: string | null; // the path option\n  start: number;       // UTF-16 offsets, like nodes\n  end: number;\n  labels: { start: number; end: number; message: string }[];\n  help: string | null;\n}\n```\n\n## Comments\n\n```js\nconst { comments } = parse(`// a line comment\\nconst x = 1; /* a block comment */`);\n// [\n//   { type: \"Line\", value: \" a line comment\", start: 0, end: 17 },\n//   { type: \"Block\", value: \" a block comment \", start: 31, end: 52 },\n// ]\n```\n\n`attachComments: true` also hangs each comment on the node it sits next to, which [`yuku-codegen`](https://www.npmjs.com/package/yuku-codegen#comments) prints from, so comments move with their nodes.\n\n```js\nconst { program } = parse(`// header\\nfunction foo() {} // trailing`, { attachComments: true });\n\nprogram.body[0].comments;\n// [\n//   { type: \"Line\", position: \"before\", sameLine: false, value: \" header\" },\n//   { type: \"Line\", position: \"after\", sameLine: true, value: \" trailing\" },\n// ]\n```\n\n`position` is `\"before\"`, `\"after\"`, or `\"inside\"` an otherwise empty node, such as `function f() { /* hi */ }`.\n\n## Tokens\n\n`tokens: true` keeps every token in a `TokenList`, a view over the parser's token table where a token is an index.\n\n```js\nimport { parse, TokenKind } from \"yuku-parser\";\n\nconst { tokens } = parse(source, { tokens: true });\n\nfor (let i = 0; i < tokens.length; i++) {\n  if (tokens.kind(i) === TokenKind.Arrow) console.log(tokens.start(i), tokens.text(i));\n}\n```\n\n```js\ntokens.kind(i)                      // one of TokenKind\ntokens.text(i)                      // its source text\ntokens.start(i)                     // UTF-16 offsets\ntokens.end(i)\n\ntokens.isKeyword(i)\ntokens.isReserved(i)                // reserved unconditionally or in strict mode\ntokens.isUnconditionallyReserved(i)\ntokens.isStrictModeReserved(i)\ntokens.isIdentifierLike(i)          // an identifier or any keyword\ntokens.isNumericLiteral(i)\ntokens.isBinaryOperator(i)\ntokens.isLogicalOperator(i)\ntokens.isUnaryOperator(i)\ntokens.isAssignmentOperator(i)\ntokens.precedence(i)                // operator precedence, 0 when none\n\ntokens.newlineBefore(i)             // what ASI reads\ntokens.escaped(i)\ntokens.invalidEscape(i)             // a template chunk whose cooked value is undefined\ntokens.loneSurrogate(i)\n\ntokens.range(node)                  // [from, to) of the tokens inside a node\ntokens.first(node)\ntokens.last(node)\ntokens.before(nodeOrOffset)         // the last token ending at or before it\ntokens.after(nodeOrOffset)          // the first token starting at or after it\ntokens.at(offset)                   // the token containing an offset\n```\n\nThe queries answer with an index, or `-1` when there is none. Tokens are as the parser resolved them, so a regex is one `RegexLiteral`, and comments are not tokens. The kinds are listed in [tokens.d.ts](https://github.com/yuku-toolchain/yuku/blob/main/npm/yuku-types/tokens.d.ts).\n\n## License\n\nMIT\n","publish_time":1783868075526,"_cnpm_publish_time":1783868075526,"dist-tags":{"beta":"0.5.0-beta.2","latest":"0.19.0"}}