{"name":"esast-util-from-js","version":"2.0.1","description":"estree (and esast) utility to parse from JavaScript","license":"MIT","keywords":["unist","estree","estree-util","esast","esast-util","util","utility","js","parse","tokenize","acorn"],"repository":{"type":"git","url":"git+https://github.com/syntax-tree/esast-util-from-js.git"},"bugs":{"url":"https://github.com/syntax-tree/esast-util-from-js/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","exports":"./index.js","dependencies":{"@types/estree-jsx":"^1.0.0","acorn":"^8.0.0","esast-util-from-estree":"^2.0.0","vfile-message":"^4.0.0"},"devDependencies":{"@types/node":"^20.0.0","acorn-stage3":"^4.0.0","c8":"^8.0.0","prettier":"^3.0.0","remark-cli":"^11.0.0","remark-preset-wooorm":"^9.0.0","type-coverage":"^2.0.0","typescript":"^5.0.0","xo":"^0.55.0"},"scripts":{"prepack":"npm run build && npm run format","build":"tsc --build --clean && tsc --build && type-coverage","format":"remark . -qfo && prettier . -w --log-level warn && xo --fix","test-api":"node --conditions development test/index.js","test-coverage":"c8 --100 --reporter lcov npm run test-api","test":"npm run build && npm run format && npm run test-coverage"},"prettier":{"bracketSpacing":false,"semi":false,"singleQuote":true,"tabWidth":2,"trailingComma":"none","useTabs":false},"remarkConfig":{"plugins":["remark-preset-wooorm"]},"typeCoverage":{"atLeast":100,"detail":true,"ignoreCatch":true,"strict":true},"xo":{"ignore":["test/fixtures/"],"prettier":true,"rules":{"no-await-in-loop":"off"}},"gitHead":"57b7fb7d3697cec0445d2dbae8f73d98fdbc70f9","types":"./index.d.ts","homepage":"https://github.com/syntax-tree/esast-util-from-js#readme","_id":"esast-util-from-js@2.0.1","_nodeVersion":"20.0.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-8Ja+rNJ0Lt56Pcf3TAmpBZjmx8ZcK5Ts4cAzIOjsjevg9oSXJnl6SUQ2EevU8tv3h6ZLWmoKL5H4fgWvdvfETw==","shasum":"5147bec34cc9da44accf52f87f239a40ac3e8225","tarball":"http://registry-npm.ywwl.com/esast-util-from-js/download/esast-util-from-js-2.0.1.tgz","fileCount":7,"unpackedSize":19018,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGrnisS0gERlNYfd4MQu0fQ6rMunW8oU3m64R3wZkPoQAiA7GyW0I91I7Gux1RaixGPbsmOaxcomqTFRO6T+dHbCWA=="}],"size":6039,"noattachment":false,"key":"/esast-util-from-js/-/esast-util-from-js-2.0.1.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/esast-util-from-js_2.0.1_1690792906727_0.1244021427814972"},"_hasShrinkwrap":false,"readme":"# esast-util-from-js\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[esast][] (and [estree][]) utility to parse trees from JavaScript.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`fromJs(value[, options])`](#fromjsvalue-options)\n    *   [`Options`](#options)\n    *   [`Plugin`](#plugin)\n    *   [`Value`](#value)\n    *   [`Version`](#version-1)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a utility that turns a string of JavaScript into an esast\n(estree with some extra cleanliness) syntax tree.\n\n## When should I use this?\n\nYou can use this utility when you want to deal with ASTs of JavaScript\ncombined with other [unist][] and [`vfile`][vfile] things.\nYou can use [`acorn`][acorn] itself if you don’t care about unified.\n\nThe utility [`estree-util-to-js`][estree-util-to-js] does the inverse of this\nutility.\nIt turns the tree into a string of JavaScript.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install esast-util-from-js\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {fromJs} from 'https://esm.sh/esast-util-from-js@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {fromJs} from 'https://esm.sh/esast-util-from-js@2?bundle'\n</script>\n```\n\n## Use\n\n```js\nimport fs from 'node:fs/promises'\nimport {fromJs} from 'esast-util-from-js'\n\nconst tree = fromJs(await fs.readFile('example.js'), {module: true})\n\nconsole.log(tree)\n```\n\nYields:\n\n```js\n{\n  type: 'Program',\n  body: [\n    {\n      type: 'ImportDeclaration',\n      specifiers: [Array],\n      source: [Object],\n      position: [Object]\n    },\n    {\n      type: 'ImportDeclaration',\n      specifiers: [Array],\n      source: [Object],\n      position: [Object]\n    },\n    {\n      type: 'VariableDeclaration',\n      declarations: [Array],\n      kind: 'const',\n      position: [Object]\n    },\n    {\n      type: 'ExpressionStatement',\n      expression: [Object],\n      position: [Object]\n    }\n  ],\n  sourceType: 'module',\n  comments: [],\n  position: {\n    start: {line: 1, column: 1, offset: 0},\n    end: {line: 7, column: 1, offset: 157}\n  }\n}\n```\n\n## API\n\nThis package exports the identifier [`fromJs`][api-from-js].\nThere is no default export.\n\n### `fromJs(value[, options])`\n\nParse JavaScript to an esast.\n\n###### Parameters\n\n*   `value` ([`Value`][api-value])\n    — serialized JavaScript to parse\n*   `options` ([`Options`][api-options], optional)\n    — configuration\n\n###### Returns\n\nTree ([`Node`][node]).\n\n###### Throws\n\nWhen the JavaScript cannot be parsed with `acorn`, a\n[`VFileMessage`][vfile-message] is thrown.\n\nThis can for example happen when passing modern syntax (you could maybe use a\nnewer `version`, or it might be that the syntax is not yet supported), or just\notherwise invalid JavaScript (you might need a plugin).\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n##### Fields\n\n###### `version`\n\nJavaScript version ([`Version`][api-version], default: `'latest'`).\n\nWhen a number, must be a year in the range `2015` and `2023` (both including).\n`'latest'` is the same as passing the latest supported year.\n\n> ☢️ **Danger**: `'latest'` is a sliding thing, you could consider it as\n> breaking semver.\n> Pass an actual year to lock that down.\n\n###### `module`\n\nWhether this is a module (ESM) or a script (`boolean`, default: `false`).\n\n###### `allowReturnOutsideFunction`\n\nWhether a return statement is allowed in the top scope (`boolean`, default:\n`false`).\n\n###### `allowImportExportEverywhere`\n\nWhether import/export statements are allowed in the every scope (`boolean`,\ndefault: `false`).\n\n###### `allowAwaitOutsideFunction`\n\nWhether `await` is allowed in the top scope (`boolean`, default: depends).\nDefaults to `version >= 2022`.\n\n###### `allowSuperOutsideMethod`\n\nWhether `super` is allowed outside methods (`boolean`, default: `false`).\n\n###### `allowHashBang`\n\nWhether a shell hasbang is allowed (`boolean`, default: `false`).\n\n###### `plugins`\n\nList of acorn plugins ([`Array<Plugin>`][api-plugin], default: `[]`).\nExamples are [`acorn-jsx`][acorn-jsx] and [`acorn-stage3`][acorn-stage3].\n\n### `Plugin`\n\nAcorn plugin (TypeScript type).\n\n###### Type\n\n```ts\ntype Plugin = (Parser: ParserClass) => ParserClass\n```\n\n### `Value`\n\nInput value (TypeScript type).\n\nWhen a typed array, must be UTF-8.\n\n###### Type\n\n```ts\ntype Value = Uint8Array | string\n```\n\n### `Version`\n\nJavaScript version (TypeScript type).\n\n`'latest'` is equivalent to the latest supported year.\n\n###### Type\n\n```ts\ntype Version = 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 'latest'\n```\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Options`][api-options],\n[`Plugin`][api-plugin],\n[`Value`][api-value], and\n[`Version`][api-version].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `esast-util-from-js@^2`,\ncompatible with Node.js 16.\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/syntax-tree/esast-util-from-js/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/esast-util-from-js/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/esast-util-from-js.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/esast-util-from-js\n\n[downloads-badge]: https://img.shields.io/npm/dm/esast-util-from-js.svg\n\n[downloads]: https://www.npmjs.com/package/esast-util-from-js\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=esast-util-from-js\n\n[size]: https://bundlejs.com/?q=esast-util-from-js\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[esast]: https://github.com/syntax-tree/esast\n\n[node]: https://github.com/syntax-tree/esast#node\n\n[estree]: https://github.com/estree/estree\n\n[unist]: https://github.com/syntax-tree/unist\n\n[vfile]: https://github.com/vfile/vfile\n\n[acorn]: https://github.com/acornjs/acorn\n\n[acorn-jsx]: https://github.com/acornjs/acorn-jsx\n\n[acorn-stage3]: https://github.com/acornjs/acorn-stage3\n\n[estree-util-to-js]: https://github.com/syntax-tree/estree-util-to-js\n\n[vfile-message]: https://github.com/vfile/vfile-message\n\n[api-from-js]: #fromjsvalue-options\n\n[api-options]: #options\n\n[api-plugin]: #plugin\n\n[api-value]: #value\n\n[api-version]: #version-1\n","publish_time":1690792906875,"_cnpm_publish_time":1690792906875,"dist-tags":{"latest":"2.0.1"}}