{"id":22710586,"url":"https://github.com/smallhelm/estree-builder","last_synced_at":"2025-08-07T15:31:21.748Z","repository":{"id":57230636,"uuid":"60360225","full_name":"smallhelm/estree-builder","owner":"smallhelm","description":"Handy functions for building estree nodes","archived":false,"fork":false,"pushed_at":"2020-03-16T15:58:10.000Z","size":76,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-12T01:18:20.733Z","etag":null,"topics":["estree"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smallhelm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-03T15:58:18.000Z","updated_at":"2020-03-16T15:58:12.000Z","dependencies_parsed_at":"2022-09-10T07:22:04.150Z","dependency_job_id":null,"html_url":"https://github.com/smallhelm/estree-builder","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallhelm%2Festree-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallhelm%2Festree-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallhelm%2Festree-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallhelm%2Festree-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smallhelm","download_url":"https://codeload.github.com/smallhelm/estree-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229057638,"owners_count":18013289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["estree"],"created_at":"2024-12-10T12:10:41.146Z","updated_at":"2024-12-10T12:10:41.641Z","avatar_url":"https://github.com/smallhelm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# estree-builder\n\n[![build status](https://secure.travis-ci.org/smallhelm/estree-builder.svg)](https://travis-ci.org/smallhelm/estree-builder)\n[![dependency status](https://david-dm.org/smallhelm/estree-builder.svg)](https://david-dm.org/smallhelm/estree-builder)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\nHandy functions for building [estree](https://github.com/estree/estree/blob/master/spec.md) nodes\n\n## Example\n\n```js\nvar e = require('estree-builder')\n\nvar estree = e.number(1)\n// -\u003e { type: 'Literal', value: 1 }\n\n//let's use astring to convert the estree into js code\nvar astring = require('astring').generate\n\nastring(estree)\n// -\u003e '1'\n\nestree = e.fn(['a', 'b'], [\n  e('return', e('+', e.id('a'), e.id('b')))\n], 'add')\n\nastring(estree)\n// -\u003e 'function add(a, b) {return a + b}'\n```\n\n## Usage\nThere are 3 ways to call a builder\n```js\ne.number(1)\ne['number'](1)\ne('number', 1)\n```\nAll builders can take a `location` object as the last argument. (i.e. for generating source maps)\n```js\nvar loc = {\n  source: \"some-file.js\"\n  start: { line: 1, column: 0 },\n  end: { line: 1, column: 1 }\n}\n\ne('number', 1, loc)\n```\n\n## List of builders\n\n[//]: # (GEN-DOCS-BEGIN)\n\n### building block values\n\n```js\ne('number', val) //aliases: 'num', 'float'\ne('string', val) //aliases: 'str'\ne('true')\ne('false')\ne('null')\ne('undefined') //aliases: 'nil'\ne('array', elements) //aliases: 'arr'\ne('object-raw', pairs) //aliases: 'obj-raw'\ne('object-property', key, value) //aliases: 'obj-prop'\ne('object', obj) //aliases: 'obj'\n```\n\n### given some json object, build the tree\n\n```js\ne('json', val)\n```\n\n### variables\n\n```js\ne('var', id, val)\ne('let', id, val)\ne('const', id, val)\ne('identifier', name) //aliases: 'id'\n```\n\n### control flow\n\n```js\ne('if', test, consequent, alternate)\ne('ternary', test, consequent, alternate) //aliases: '?'\ne('switch', discriminant, cases)\ne('case', test, consequent)\ne('default', consequent)\ne('while', test, body)\ne('for', init, test, update, body)\ne('for-in', left, right, body)\ne('for-of', left, right, body)\ne('break')\ne('continue')\ne('return', arg)\ne('throw', arg)\ne('try', body, catchVar, catchStmt, finallyStmt)\n```\n\n### functions\n\n```js\ne('function', args, body, id) //aliases: 'fn', 'lambda'\ne('call', callee, args)\ne('arrow', args, body)\n```\n\n### property access\n\n```js\ne('.', obj, prop)\ne('get', obj, prop)\ne('get-in', obj, path) //aliases: '..'\n```\n\n### language stuff\n\n```js\ne('arguments') //aliases: 'args'\ne('this')\ne('statement', expr) //aliases: ';'\ne('block', body)\ne('new', callee, args)\n```\n\n### infix operators\n\n```js\ne('==', left, right)\ne('!=', left, right)\ne('===', left, right)\ne('!==', left, right)\ne('\u003c', left, right)\ne('\u003c=', left, right)\ne('\u003e', left, right)\ne('\u003e=', left, right)\ne('\u003c\u003c', left, right)\ne('\u003e\u003e', left, right)\ne('\u003e\u003e\u003e', left, right)\ne('*', left, right)\ne('/', left, right)\ne('%', left, right)\ne('|', left, right)\ne('^', left, right)\ne('\u0026', left, right)\ne('in', left, right)\ne('instanceof', left, right)\ne('\u0026\u0026', left, right)\ne('||', left, right)\ne('+', a, b)\ne('-', a, b)\n```\n\n### unary operators\n\n```js\ne('!', arg)\ne('~', arg)\ne('typeof', arg)\ne('void', arg)\ne('delete', arg)\ne('++', arg)\ne('--', arg)\n```\n\n### assignments\n\n```js\ne('=', left, right)\ne('+=', left, right)\ne('-=', left, right)\ne('*=', left, right)\ne('/=', left, right)\ne('%=', left, right)\ne('\u003c\u003c=', left, right)\ne('\u003e\u003e=', left, right)\ne('\u003e\u003e\u003e=', left, right)\ne('|=', left, right)\ne('^=', left, right)\ne('\u0026=', left, right)\n```\n\n### destructuring\n\n```js\ne('assign', left, right)\ne('assign-property', key, value) //aliases: 'assign-prop'\ne('obj-pattern', properties)\ne('arr-pattern', elements)\n```\n\n### generator functions\n\n```js\ne('genfn', args, body, id)\ne('yield', arg, delegate)\n```\n\n### classes\n\n```js\ne('class', name, superClass, methods)\ne('method', key, value, kind, computed, isStatic)\n```\n\n[//]: # (GEN-DOCS-END)\n\n## Contributing\n\nAdd tests to tests.js, run them like this:\n```sh\n$ npm test\n```\nor to automatically re-run them whenever you make a change\n```sh\n$ npm start\n```\n\nRe-generate the docs (README.md between the GEN-DOCS-BEGIN|END comments)\n```sh\n$ npm run build\n```\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallhelm%2Festree-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmallhelm%2Festree-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallhelm%2Festree-builder/lists"}