{"name":"oxc-parser","version":"0.30.5","keywords":["Parser"],"author":{"name":"Boshen and oxc contributors"},"license":"MIT","_id":"oxc-parser@0.30.5","maintainers":[{"name":"boshen","email":"boshenc@gmail.com"}],"homepage":"https://oxc.rs","bugs":{"url":"https://github.com/oxc-project/oxc/issues"},"dist":{"shasum":"d85149e16f7e625786666f6ed96a7e86732caa3f","tarball":"http://registry-npm.ywwl.com/oxc-parser/download/oxc-parser-0.30.5.tgz","fileCount":5,"integrity":"sha512-ilcJ7SJrept5Yqr6y+MTGCVlXCQ8woxr2h+TWaHP/7yE6GnYXNP0+1oVIwr2rCoH0E9mSMyLJCfyiWwMcohp/g==","signatures":[{"sig":"MEQCIEmQusmCRalHuCUzDQs5lD3pQntOQCwVdgmVEAX16hQRAiAhjAgwrbC9dRDlzxDQs5nh5aLNdZBAMvn1W/9V/fw/sQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/oxc-parser@0.30.5","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":15416,"size":3925,"noattachment":false,"key":"/oxc-parser/-/oxc-parser-0.30.5.tgz"},"main":"index.js","_from":"file:oxc-parser-0.30.5.tgz","types":"./index.d.ts","funding":{"url":"https://github.com/sponsors/Boshen"},"_npmUser":{"name":"boshen","email":"boshenc@gmail.com"},"_resolved":"/tmp/b0947b30f40bb8c1ca03a0c79990e568/oxc-parser-0.30.5.tgz","_integrity":"sha512-ilcJ7SJrept5Yqr6y+MTGCVlXCQ8woxr2h+TWaHP/7yE6GnYXNP0+1oVIwr2rCoH0E9mSMyLJCfyiWwMcohp/g==","repository":{"url":"git+https://github.com/oxc-project/oxc.git","type":"git","directory":"npm/oxc-parser"},"_npmVersion":"10.8.2","description":"Oxc Parser Node API","directories":{},"_nodeVersion":"22.7.0","_hasShrinkwrap":false,"optionalDependencies":{"@oxc-parser/binding-darwin-x64":"0.30.5","@oxc-parser/binding-darwin-arm64":"0.30.5","@oxc-parser/binding-linux-x64-gnu":"0.30.5","@oxc-parser/binding-linux-x64-musl":"0.30.5","@oxc-parser/binding-win32-x64-msvc":"0.30.5","@oxc-parser/binding-linux-arm64-gnu":"0.30.5","@oxc-parser/binding-linux-arm64-musl":"0.30.5","@oxc-parser/binding-win32-arm64-msvc":"0.30.5"},"_npmOperationalInternal":{"tmp":"tmp/oxc-parser_0.30.5_1727595339890_0.6682807486876865","host":"s3://npm-registry-packages"},"readme":"# Oxc Parser\n\nSee [usage instructions](https://oxc.rs/docs/guide/usage/parser).\n\n## Features\n\n### Supports WASM\n\nSee https://stackblitz.com/edit/oxc-parser for usage example.\n\n### ESTree\n\nWhen parsing JS or JSX files, the AST returned is fully conformant with the\n[ESTree standard](https://github.com/estree/estree), the same as produced by\n[Acorn](https://npmx.dev/package/acorn).\n\nWhen parsing TypeScript, the AST conforms to [@typescript-eslint/typescript-estree](https://npmx.dev/package/@typescript-eslint/typescript-estree)'s TS-ESTree format.\n\nIf you need all ASTs in the same with-TS-properties format, use the `astType: 'ts'` option.\n\nThe only differences between Oxc's AST and ESTree / TS-ESTree are:\n\n- Support for Stage 3 [decorators](https://github.com/tc39/proposal-decorators).\n- Support for Stage 3 ECMA features [`import defer`](https://github.com/tc39/proposal-defer-import-eval)\n  and [`import source`](https://github.com/tc39/proposal-source-phase-imports).\n- In TS-ESTree AST, `import.defer(...)` and `import.source(...)` are represented as an `ImportExpression`\n  with `'defer'` or `'source'` in `phase` field (as in ESTree spec), where TS-ESLint represents these\n  as a `CallExpression` with `MetaProperty` as its `callee`.\n- Addition of a non-standard `hashbang` field to `Program`.\n\nThat aside, the AST should completely align with Acorn's ESTree AST or TS-ESLint's TS-ESTree.\nAny deviation would be considered a bug.\n\n### AST Types\n\n[@oxc-project/types](https://npmx.dev/package/@oxc-project/types) can be used. For example:\n\n```typescript\nimport { Statement } from \"@oxc-project/types\";\n```\n\n### Visitor\n\nAn AST visitor is provided. See example below.\n\nThis package also exports visitor keys which can be used with any other ESTree walker.\n\n```js\nimport { visitorKeys } from \"oxc-parser\";\n```\n\n### Fast Mode\n\nBy default, Oxc parser does not produce semantic errors where symbols and scopes are needed.\n\nTo enable semantic errors, apply the option `showSemanticErrors: true`.\n\nFor example,\n\n```js\nlet foo;\nlet foo;\n```\n\nDoes not produce any errors when `showSemanticErrors` is `false`, which is the default behavior.\n\nFast mode is best suited for parser plugins, where other parts of your build pipeline has already checked for errors.\n\nPlease note that turning off fast mode ​incurs​ a small performance overhead.\n\n### Returns ESM information.\n\nIt is likely that you are writing a parser plugin that requires ESM information.\n\nTo avoid walking the AST again, Oxc Parser returns ESM information directly.\n\nThis information can be used to rewrite import and exports with the help of [`magic-string`](https://npmx.dev/package/magic-string),\nwithout any AST manipulations.\n\n```ts\nexport interface EcmaScriptModule {\n  /**\n   * Has ESM syntax.\n   *\n   * i.e. `import` and `export` statements, and `import.meta`.\n   *\n   * Dynamic imports `import('foo')` are ignored since they can be used in non-ESM files.\n   */\n  hasModuleSyntax: boolean;\n  /** Import statements */\n  staticImports: Array<StaticImport>;\n  /** Export statements */\n  staticExports: Array<StaticExport>;\n  /** Dynamic import expressions */\n  dynamicImports: Array<DynamicImport>;\n  /** Span positions of `import.meta` */\n  importMetas: Array<Span>;\n}\n```\n\n## API\n\n### Functions\n\n```typescript\n// Synchronous parsing\nparseSync(filename: string, sourceText: string, options?: ParserOptions): ParseResult\n\n// Asynchronous parsing\nparse(filename: string, sourceText: string, options?: ParserOptions): Promise<ParseResult>\n```\n\nUse `parseSync` for synchronous parsing. Use `parse` for asynchronous parsing, which can be beneficial in I/O-bound or concurrent scenarios, though it adds async overhead.\n\n### Example\n\n```javascript\nimport { parseSync, Visitor } from \"oxc-parser\";\n\nconst code = \"const url: String = /* 🤨 */ import.meta.url;\";\n\n// File extension is used to determine which dialect to parse source as.\nconst filename = \"test.tsx\";\n\nconst result = parseSync(filename, code);\n// Or use async version: const result = await parse(filename, code);\n\n// An array of errors, if any.\nconsole.log(result.errors);\n\n// AST and comments.\nconsole.log(result.program, result.comments);\n\n// ESM information - imports, exports, `import.meta`s.\nconsole.log(result.module);\n\n// Visit the AST\nconst visitations = [];\n\nconst visitor = new Visitor({\n  VariableDeclaration(decl) {\n    visitations.push(`enter ${decl.kind}`);\n  },\n  \"VariableDeclaration:exit\"(decl) {\n    visitations.push(`exit ${decl.kind}`);\n  },\n  Identifier(ident) {\n    visitations.push(ident.name);\n  },\n});\n\nvisitor.visit(result.program);\n\n// Logs: [ 'enter const', 'url', 'String', 'import', 'meta', 'url', 'exit const' ]\nconsole.log(visitations);\n```\n\n### Options\n\nAll options are optional.\n\n- `lang`: `'js'` | `'jsx'` | `'ts'` | `'tsx'`. Set language of source. If omitted, language is deduced from file extension.\n- `sourceType`: `'script'` | `'module'` | `'unambiguous'`. Set source type. Defaults to `'module'`.\n- `astType`: `'js'` | `'ts'`. Set to `'ts'` if you want ASTs of plain JS/JSX files to contain TypeScript-specific properties.\n- `range`: `true` | `false`. If `true`, AST nodes contain a `range` field. Defaults to `false`.\n- `preserveParens`: `true` | `false`. If `true`, parenthesized expressions are represented by (non-standard) `ParenthesizedExpression` and `TSParenthesizedType` AST nodes. Defaults to `true`.\n- `showSemanticErrors`: `true` | `false`. If `true`, check file for semantic errors which parser does not otherwise emit e.g. `let x; let x;`. Has a small performance cost. Defaults to `false`.\n","publish_time":1727595340134,"_cnpm_publish_time":1727595340134,"dist-tags":{"latest":"0.159.0"}}