{"name":"@phenomnomnominal/tsquery","version":"4.2.0","description":"Query TypeScript ASTs with the esquery API!","main":"dist/src/index.js","typings":"dist/src/index.d.ts","author":{"name":"Craig Spence","email":"craigspence0@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/phenomnomnominal/tsquery.git"},"license":"MIT","scripts":{"build":"npm run clean && npm run compile && npm run lint && npm run test","clean":"rimraf dist","compile":"tsc","lint":"npm run lint:src && npm run lint:test","lint:src":"tslint --project ./tsconfig.json -c ./tslint.json 'src/**/*.ts'","lint:test":"tslint --project ./tsconfig.json -c ./tslint.json 'test/**/*.ts'","lint:fix":"npm run lint:src:fix && npm run lint:test","lint:src:fix":"tslint -c tslint.json 'src/**/*.ts' --fix","lint:test:fix":"tslint -c tslint.json 'test/**/*.ts' --fix","test":"jest","test:debug":"node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand","prepublishOnly":"npm run build"},"dependencies":{"esquery":"^1.0.1"},"peerDependencies":{"typescript":"^3 || ^4"},"devDependencies":{"@types/chai":"^4.2.3","@types/jasmine":"^3.4.4","@types/minimist":"^1.2.0","@types/node":"^12.11.1","chai":"^4.2.0","jest":"^24.9.0","rimraf":"^2.6.3","ts-jest":"^24.1.0","ts-node":"^8.4.1","tslint":"^5.20.0","typescript":"^3.6.4","webpack":"^4.41.2","webpack-cli":"^3.3.9"},"jest":{"globals":{"__TS_CONFIG__":"tsconfig.json"},"moduleFileExtensions":["ts","js"],"collectCoverage":true,"collectCoverageFrom":["<rootDir>/src/**"],"coverageDirectory":"<rootDir>/reports/coverage","transform":{"\\.(ts)$":"ts-jest"},"testRegex":"/test/.*\\.spec\\.ts$"},"gitHead":"9d69685f53efa49d20710b58f9eaeebc38c5175c","bugs":{"url":"https://github.com/phenomnomnominal/tsquery/issues"},"homepage":"https://github.com/phenomnomnominal/tsquery#readme","_id":"@phenomnomnominal/tsquery@4.2.0","_nodeVersion":"14.18.1","_npmVersion":"6.14.15","dist":{"integrity":"sha512-hR2U3uVcrrdkuG30ItQ+uFDs4ncZAybxWG0OjTE8ptPzVoU7GVeXpy+vMU8zX9EbmjGeITPw/su5HjYQyAH8bA==","shasum":"7742ff4af12ce673b0b601ba5515c934f1876b14","tarball":"http://registry-npm.ywwl.com/@phenomnomnominal/tsquery/download/@phenomnomnominal/tsquery-4.2.0.tgz","fileCount":78,"unpackedSize":60963,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh6JP2CRA9TVsSAnZWagAA0WgP/0p/vq1api6NYDXoOSf5\naeFgNtPgn4GuiqPXurPFFJCWt4hig+HGaujKzGHKsKW2esixYSQ0doruPuBR\nr5rFOSVHTh2OCcUOzpTLxTQCHSgk8N2TN/xmN2+SqCv28SKqX7n0/Mb6EQzT\nTikL+NzpmZJpv9+eUvH+dpw9tgMA4IDUeNfy3Pf6mi45JwemrMuHg9+jWKET\nt4pCb+f9hXjq+eH4r5M3QOI4qJEwYr3Hg6/Xf6BFsYToPjJz7x92miMF9MYM\n1VkjW3g6/+KP26saGUznf+lItf8VtrzFQRDPmY1EModply7dBP+63nfsJtQh\n1xlAUaR4drGKJ2XZwt5qTVtQsQZl9Q061qXkFFZInN7BFXBkY/4N42jYauuT\nCIdREgb1QlgGlc6+y7wlin1G01thQ/vroCcH5Ymz5nLvIf+Spkm9n5xnvJ1y\nMkLA5wpQt8Ce/Im3Ug4eTCUPwV0AAiOR+tozhQkwe0xFAPBzZr2UJxmsTZFs\nWvBQNngfCc9UUuCYWX5Hw8EpTnFGgzNDopVoZJOz72TJCPueML/PmtqtJLvC\n7VCs6OL1AqObVkH0Sm5ByTk9zrIke0yjLq2ez+0sbCmMYeRBjvo+sPHxzqqM\n3KiIttS7dla+0cRAcaLJFLTT3EAClDg4CMas6WHJN+UXPCascWjz8ShZbhRx\n/dxo\r\n=rBJR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAsEJVQ3AzvK40rGwMb9gU+g+HUAH9sFzWzL/TfI5K81AiBLl3TWYfisG899HLtHyq9C7Ip/1txwOebT1Nks2uFHOA=="}],"size":16381,"noattachment":false,"key":"/@phenomnomnominal/tsquery/-/@phenomnomnominal/tsquery-4.2.0.tgz"},"_npmUser":{"name":"phenomnomnominal","email":"craigspence0@gmail.com"},"directories":{},"maintainers":[{"name":"phenomnomnominal","email":"craigspence0@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tsquery_4.2.0_1642632182190_0.5453849313534878"},"_hasShrinkwrap":false,"readme":"# TSQuery\n\n[![npm version](https://img.shields.io/npm/v/@phenomnomnominal/tsquery.svg)](https://img.shields.io/npm/v/@phenomnomnominal/tsquery.svg)\n\nTSQuery is a port of the ESQuery API for TypeScript! TSQuery allows you to query a TypeScript AST for patterns of syntax using a CSS style selector system. \n\n## Demos:\n\n[ESQuery demo](https://estools.github.io/esquery/) - note that the demo requires JavaScript code, not TypeScript\n[TSQuery demo](https://tsquery-playground.firebaseapp.com) by [Uri Shaked](https://github.com/urish)\n\n## Installation\n\n```sh\nnpm install @phenomnomnominal/tsquery --save-dev\n```\n\n## Examples\n\nSay we want to select all instances of an identifier with name \"Animal\", e.g. the identifier in the `class` declaration, and the identifier in the `extends` declaration.\n\nWe would do something like the following:\n\n```ts\nimport { ast, query } from '@phenomnomnominal/tsquery';\n\nconst typescript = `\n\nclass Animal {\n    constructor(public name: string) { }\n    move(distanceInMeters: number = 0) {\n        console.log(\\`\\${this.name} moved \\${distanceInMeters}m.\\`);\n    }\n}\n\nclass Snake extends Animal {\n    constructor(name: string) { super(name); }\n    move(distanceInMeters = 5) {\n        console.log(\"Slithering...\");\n        super.move(distanceInMeters);\n    }\n}\n\n`;\n\nconst ast = ast(typescript);\nconst nodes = query(ast, 'Identifier[name=\"Animal\"]');\nconsole.log(nodes.length); // 2\n```\n\n### Selectors\n\nThe following selectors are supported:\n\n* AST node type: `ForStatement` (see [common node types](#common-ast-node-types))\n* [wildcard](http://dev.w3.org/csswg/selectors4/#universal-selector): `*`\n* [attribute existence](http://dev.w3.org/csswg/selectors4/#attribute-selectors): `[attr]`\n* [attribute value](http://dev.w3.org/csswg/selectors4/#attribute-selectors): `[attr=\"foo\"]` or `[attr=123]`\n* attribute regex: `[attr=/foo.*/]`\n* attribute conditions: `[attr!=\"foo\"]`, `[attr>2]`, `[attr<3]`, `[attr>=2]`, or `[attr<=3]`\n* nested attribute: `[attr.level2=\"foo\"]`\n* field: `FunctionDeclaration > Identifier.id`\n* [First](http://dev.w3.org/csswg/selectors4/#the-first-child-pseudo) or [last](http://dev.w3.org/csswg/selectors4/#the-last-child-pseudo) child: `:first-child` or `:last-child`\n* [nth-child](http://dev.w3.org/csswg/selectors4/#the-nth-child-pseudo) (no ax+b support): `:nth-child(2)`\n* [nth-last-child](http://dev.w3.org/csswg/selectors4/#the-nth-last-child-pseudo) (no ax+b support): `:nth-last-child(1)`\n* [descendant](http://dev.w3.org/csswg/selectors4/#descendant-combinators): `ancestor descendant`\n* [child](http://dev.w3.org/csswg/selectors4/#child-combinators): `parent > child`\n* [following sibling](http://dev.w3.org/csswg/selectors4/#general-sibling-combinators): `node ~ sibling`\n* [adjacent sibling](http://dev.w3.org/csswg/selectors4/#adjacent-sibling-combinators): `node + adjacent`\n* [negation](http://dev.w3.org/csswg/selectors4/#negation-pseudo): `:not(ForStatement)`\n* [matches-any](http://dev.w3.org/csswg/selectors4/#matches): `:matches([attr] > :first-child, :last-child)`\n* [has](https://drafts.csswg.org/selectors-4/#has-pseudo): `IfStatement:has([name=\"foo\"])`\n* class of AST node: `:statement`, `:expression`, `:declaration`, `:function`, or `:pattern`\n\n### Common AST node types\n\n* `Identifier` - any identifier (name of a function, class, variable, etc)\n* `IfStatement`, `ForStatement`, `WhileStatement`, `DoStatement` - control flow\n* `FunctionDeclaration`, `ClassDeclaration`, `ArrowFunction` - declarations\n* `VariableStatement` - var, const, let.\n* `ImportDeclaration` - any `import` statement\n* `StringLiteral` - any string\n* `TrueKeyword`, `FalseKeyword`, `NullKeyword`, `AnyKeyword` - various keywords\n* `CallExpression` - function call\n* `NumericLiteral` - any numeric constant\n* `NoSubstitutionTemplateLiteral`, `TemplateExpression` - template strings and expressions\n\n## API:\n\n### `ast`:\n\nParse a string of code into an Abstract Syntax Tree which can then be queried with TSQuery Selectors.\n\n```typescript\nimport { ast } from '@phenomnomnominal/tsquery';\n\nconst sourceFile = ast('const x = 1;');\n```\n\n### `includes`:\n\nCheck for `Nodes` within a given `string` of code or AST `Node` matching a `Selector`.\n\n```typescript\nimport { includes } from '@phenomnomnominal/tsquery';\n\nconst hasIdentifier = includes('const x = 1;', 'Identifier');\n```\n\n### `map`:\n\nTransform AST `Nodes` within a given `Node` matching a `Selector`. Can be used to do `Node`-based replacement or removal of parts of the input AST.\n\n```typescript\nimport { factory } from 'typescript';\nimport { map } from '@phenomnomnominal/tsquery';\n\nconst tree = ast('const x = 1;')\nconst updatedTree = map(tree, 'Identifier', () => factory.createIdentifier('y'));\n```\n\n### `match`:\n\nFind AST `Nodes` within a given AST `Node` matching a `Selector`.\n\n```typescript\nimport { ast, match } from '@phenomnomnominal/tsquery';\n\nconst tree = ast('const x = 1;')\nconst [xNode] = match(tree, 'Identifier');\n```\n\n### `parse`:\n\nParse a `string` into an [ESQuery](https://github.com/estools/esquery) `Selector`.\n\n```typescript\nimport { parse } from '@phenomnomnominal/tsquery';\n\nconst selector = parse(':matches([attr] > :first-child, :last-child)');\n```\n\n### `print`:\n\nPrint a given `Node` or `SourceFile` to a string, using the default TypeScript printer.\n\n```typescript\nimport { print } from '@phenomnomnominal/tsquery';\nimport { factory } from 'typescript';\n\n  // create synthetic node:\nconst node = factory.createArrowFunction(\n  // ...\n);\nconst code = print(node);\n```\n\n### `project`:\n\nGet all the `SourceFiles` included in a the TypeScript project described by a given config file.\n\n```typescript\nimport { project } from '@phenomnomnominal/tsquery';\n\nconst files = project('./tsconfig.json');\n```\n\n### `files`:\n\nGet all the file paths included ina the TypeScript project described by a given config file.\n\n```typescript\nimport { files } from '@phenomnomnominal/tsquery';\n\nconst filePaths = files('./tsconfig.json');\n```\n\n### `match`:\n\nFind AST `Nodes` within a given `string` of code or AST `Node` matching a `Selector`.\n\n```typescript\nimport {query } from '@phenomnomnominal/tsquery';\n\nconst [xNode] = query('const x = 1;', 'Identifier');\n```\n\n### `replace`:\n\nTransform AST `Nodes` within a given `Node` matching a `Selector`. Can be used to do string-based replacement or removal of parts of the input AST. The updated code will be printed with the TypeScript [`Printer`](https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#creating-and-printing-a-typescript-ast), so you may need to run your own formatter on any output code.\n\n```typescript\nimport { replace } from '@phenomnomnominal/tsquery';\n\nconst updatedCode = replace('const x = 1;', 'Identifier', () => 'y'));\n```\n","publish_time":1642632182356,"_cnpm_publish_time":1642632182356,"dist-tags":{"latest":"6.2.0"}}