{"name":"ast-query","version":"0.3.0","description":"Declarative JavaScript AST modification façade","main":"lib/tree.js","author":{"name":"Simon Boudrias","email":"admin@simonboudrias.com"},"license":"MIT","keywords":["AST","source","traversal","syntax","tree"],"scripts":{"test":"grunt"},"repository":{"type":"git","url":"git@github.com:SBoudrias/AST-query.git"},"dependencies":{"esprima":"~1.1.1","escodegen":"~1.3.1","lodash":"~2.4.1","traverse":"~0.6.6","class-extend":"~0.1.1"},"devDependencies":{"grunt":"~0.4.1","grunt-cli":"~0.1.9","grunt-contrib-jshint":"~0.10.0","grunt-simple-mocha":"~0.4.0","grunt-release":"~0.7.0"},"gitHead":"eeeb541111fc8cbc4cbc0b394bb4cc79f6963497","bugs":{"url":"https://github.com/SBoudrias/AST-query/issues"},"homepage":"https://github.com/SBoudrias/AST-query","_id":"ast-query@0.3.0","_shasum":"ca0ae981e81da016ec4d3ce0c0abab9f86b54535","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"maintainers":[{"name":"sboudrias","email":"admin@simonboudrias.com"}],"dist":{"shasum":"ca0ae981e81da016ec4d3ce0c0abab9f86b54535","tarball":"http://registry-npm.ywwl.com/ast-query/download/ast-query-0.3.0.tgz","integrity":"sha512-MJGENYT3Kp9xgYV2O5sZpzEpOiwrIElukl9WPewbjljrzMLdMAuzVzA9VIX6El61A4QclMsnfd+e0Oc8drvYYA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDyeAKlkg4dgAJ9md6PTrefJ/riQKJQ07x5+jvbBGuSCwIhAK4N+vNrSagJ/ZfxUL4LjJ3ok3F6yledI1mu8P63u2cQ"}],"size":9327,"noattachment":false,"key":"/ast-query/-/ast-query-0.3.0.tgz"},"directories":{},"readme":"AST Query\n================\n\n[![npm](https://badge.fury.io/js/ast-query.svg)](http://badge.fury.io/js/ast-query) [![tests](https://travis-ci.org/SBoudrias/AST-query.svg?branch=master)](http://travis-ci.org/SBoudrias/AST-query) [![dependencies](https://david-dm.org/SBoudrias/AST-query.svg?theme=shields.io)](https://david-dm.org/SBoudrias/AST-query)\n\n\nThis project is a tentative to create a simple JavaScript AST modification library.\n\nIf you've ever worked with AST trying to edit source code, you'll know it is a bad time. AST syntax is terse and forces you to loop a tree and use conditional structure a lot. AST Query hide these complexities behind a declarative façade.\n\nMaking the simplicity choice means AST Query won't try to cover the full AST API. Rather we strive to answer commons needs.\n\n\nGetting Started\n================\n\nInstall: `npm install --save ast-query`\n\nFirst, you need to pass a program code into AST query:\n\n``` javascript\nvar program = require(\"ast-query\");\nvar tree = program(\"var a = 'foo'\");\n```\n\nThis function returns a wrapped AST tree you can query and modify.\n\nOnce you've modified the AST, get the source code back by calling the `toString` method on the tree.\n\n``` javascript\n// ...\ntree.var(\"a\").value(\"'bar'\");\n\nconsole.log( tree.toString() );\n// LOG: var a = 'bar';\n```\n\nRemember that you are editing source code. This mean you provide raw source code strings. This mean you need to double wrap strings (e.g.: `\"'foo'\"`). If that's not done, AST-query assume you're referencing a variable called `foo`.\n\n\nAPI\n================\n\nProgram\n----------------\n\n### `var tree = program( sourceCode, escodegenOptions, esprimaOptions )`\n- **sourceCode** (String) - The source code to edit.\n- **escodegenOptions** (Object) _optional_ - [escodegen](https://github.com/Constellation/escodegen) option object\n- **acornOptions** (Object) _optional_ - [acorn](https://github.com/ternjs/acorn) option object\n\nReturns an AST tree you can then query as explained below:\n\n### `tree.var( name )`\n- **name** (String) - The variable name\n\nFind and returns a [`Variable` node](#variable-node).\n\nGiven this code\n\n``` js\nvar bar = 23;\n```\n\nYou'd call `tree.var('bar')` to get the Variable node.\n\n### `tree.callExpression( name )`\n- **name** (String) - The name of the function or method being called.\n\nFind a function or method call and return a [`CallExpression` node](#callexpression-node)\n\nGiven this code\n\n```js\ngrunt.initConfig({});\n```\n\nYou'd call `tree.callExpression('grunt.initConfig')` to get the CallExpression node.\n\n### `tree.assignment( assignedTo )`\n- **assignedTo** (String) - The name (name or object) a value is assigned to\n\nFind and return an [`AssignmentExpression` node](#assignmentexpression-node).\n\nYou'd call `tree.assignment('module.exports')` to query the code below:\n\n```js\nmodule.exports = function () {\n  // code\n};\n```\n### `tree.body`\n\nProperty representing the program body in a [`Body` node](#body-node).\n\n### `tree.verbatim( body )`\n- **body** (String) - The source code to inline verbatim\n\nAdds body and return a token assigment.\n\n```js\ntree.body.append('var a = 1;' + tree.verbatim('ANYTHING'));\n```\n\nVariable node\n-----------------\n\n### `.value( value )`\n- **value** (String) _optionnal_ - A string containing the new variable value.\n\nIt returns the current or new value wrapped in AST query interface.\n\n### `.rename( name )`\n- **name** (String) - Change the variable name\n\nCallExpression node\n--------------------\n\n### `.filter( iterator )`\n- **iterator** (Function) - Function receiving each node as arguments and returning true to keep the current node in the returned set.\n\nReturn a new CallExpression nodes collection with nodes passing the iterator test.\n\n### `.arguments`\n\nA property pointing to an [`ArrayExpression` node](#arrayexpression-node) referencing the called function arguments.\n\nAssignmentExpression node\n--------------------\n\n### `.value( value )`\n\nReplace the assignment value with a new value or return the current value wrapped in an AST query interface.\n\nLiteral node\n--------------------\n\nA Literal node represent a raw JavaScript value as a String, a Number or a Boolean.\n\n### `.value( value )`\n\nGet or update the value.\n\nFunctionExpression node\n-------------------\n\nNode representing a function declaration (e.g. `function () {}`).\n\n### `.body`\n\nProperty pointing to a [`Body` node](#body-node) representing the function expression body.\n\nObjectExpression node\n-------------------\n\n### `.key( name )`\n- **name** (String) - Key name\nGet a key value object or create a blank placeholder\n\n### `value( value )`\n\nReplace current node with a new value. Returns the new value wrapped.\n\nArrayExpression node\n-------------------\n\n### `.push( value )`\n- **value** (String) - value to push in the array\n\n### `.unshift( value )`\n- **value** (String) - value to unshift in the array\n\n### `.at( index )`\n- **index** (Number) - Index of the value to fetch\n\nReturns a value wrapped in an AST query interface.\n\n### `value( value )`\n\nReplace current node with a new value. Returns the new value wrapped.\n\nBody node\n-------------------\n\n### `.prepend( code )`\n\nPreprend the given code lines in the body. If a `\"use strict\";` statement is present, it always stay first.\n\n### `.append( code )`\n\nAppend the given code lines in the body.\n\nContributing\n=====================\n\n**Style Guide**: Please base yourself on [Idiomatic.js](https://github.com/rwldrn/idiomatic.js)\nstyle guide with two space indent\n**Unit test**: Unit test are wrote in Mocha. Please add a unit test for every new feature\nor bug fix. `npm test` to run the test suite.\n**Documentation**: Add documentation for every API change. Feel free to send corrections\nor better docs!\n**Pull Requests**: Send _fixes_ PR on the `master` branch. Any new features should be send\non the `wip`branch.\n\n\nLicense\n=====================\n\nCopyright (c) 2013 Simon Boudrias (twitter: @vaxilart)\nLicensed under the MIT license.\n","publish_time":1411108332883,"_cnpm_publish_time":1411108332883,"dist-tags":{"latest":"2.0.0"}}