{"name":"esast-util-from-js","version":"1.0.0","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","main":"index.js","types":"index.d.ts","dependencies":{"@types/estree-jsx":"^0.0.1","acorn":"^8.0.0","esast-util-from-estree":"^1.0.0","vfile-message":"^3.0.0"},"devDependencies":{"@types/tape":"^4.0.0","acorn-stage3":"^4.0.0","c8":"^7.0.0","prettier":"^2.0.0","remark-cli":"^10.0.0","remark-preset-wooorm":"^9.0.0","rimraf":"^3.0.0","tape":"^5.0.0","type-coverage":"^2.0.0","typescript":"^4.0.0","xo":"^0.49.0"},"scripts":{"prepack":"npm run build && npm run format","build":"rimraf \"{lib,test}/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage","format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node --conditions development test/index.js","test-coverage":"c8 --check-coverage --100 --reporter lcov npm run test-api","test":"npm run build && npm run format && npm run test-coverage"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true,"rules":{"no-await-in-loop":"off"},"ignore":["test/fixtures/"]},"remarkConfig":{"plugins":["preset-wooorm"]},"typeCoverage":{"atLeast":100,"detail":true,"strict":true,"ignoreFiles":["lib/types.d.ts"]},"gitHead":"41ec60d64641bbc706b5beb41ebfa6382fef6502","homepage":"https://github.com/syntax-tree/esast-util-from-js#readme","_id":"esast-util-from-js@1.0.0","_nodeVersion":"18.2.0","_npmVersion":"8.9.0","dist":{"integrity":"sha512-jqK8mokE7Gvij+UDeRpU8P+Rgris7B9lkHyez7uqAG5ID/h0joG9ps9DCHKOZzKCHooQdGYIClTCgmlPk6P35Q==","shasum":"3ceb25419d861128799c8c848c346c20bbf4f8ab","tarball":"http://registry-npm.ywwl.com/esast-util-from-js/download/esast-util-from-js-1.0.0.tgz","fileCount":7,"unpackedSize":15580,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDweiWAWGRBm3/YZwkozrVJBkoXOO1aq6j+YkcYosB7LgIhAPzdT/SSl/Vtl+pH7FbvKZdtYL8Wpek0tftsODp9PSG/"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJilQYbACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpyJQ//XfRnNba24gPg7/j2+FygNa2uHdqKz74qpwExflqeM02mMoOk\r\nHCsqBrcURbAP7G2wpJYd2J3IJG4bh1kLPB2tq3P2ZSobKjt4X1rB3lp8eHIv\r\nOu4iWKDE5mLkj7nZ2vz/oSeHMT5r1HGuI5i6qk5hWZnAYPMuIKv8GStNNwNK\r\n+f3UdSncsSH1tp1xK8Pt7/GCNqduMItng2vFwvCHnS/Yl8rbJTsDmxO835Jd\r\nrFajtcynqKQUqohQ7DRNtZ/nVpOD//z3Wh4Wm1AnqyRqeJrmouWC2iSq/TXh\r\nAEPYNlhBg+WE8RedHuGrZiaqGrmxlOJIPSrLaS5m+lb5fk6zgK1GfO6IbfLg\r\n/1lHE6f6zstIv1T9pAaEV+/tGzQtFYQOwW2R7Rl8xGNIR0ex5qe7rFrpShIj\r\nYwEU6U3Sf/iRy+IB2EwJadOuADXbzZ7v+MNdBEEEmVYhPSg5IUIFDeHOGTHn\r\nCK3C/DYOYlOErCghA6ekSgaPIfMe2/FW3vItxwcRbF6uvCFBmk3b630fGxoS\r\njOCkO+V0v2d6BCA5ejwVyx69StE5gOfQs4bAD1i0Xo+drTKsZRutU6MlpulB\r\nSVlkVHJXwC+DS+wXKjYSHWF01fGPuGdPBdJKs54twrz0GF8KuJhxjkq80IF1\r\nVr3LzQxz3mCre9UfgpJ2WbFT+gYKJmOHLOs=\r\n=aDF8\r\n-----END PGP SIGNATURE-----\r\n","size":5425,"noattachment":false,"key":"/esast-util-from-js/-/esast-util-from-js-1.0.0.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/esast-util-from-js_1.0.0_1653933595283_0.6368768968170446"},"_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":1653933595406,"_cnpm_publish_time":1653933595406,"dist-tags":{"latest":"2.0.1"}}