{"id":14155537,"url":"https://github.com/fraxken/Node-Estree","last_synced_at":"2025-08-06T01:31:41.249Z","repository":{"id":41869710,"uuid":"218143338","full_name":"fraxken/Node-Estree","owner":"fraxken","description":"Complete and compliant ESTree spec implementation in TypeScript","archived":false,"fork":false,"pushed_at":"2024-10-28T22:23:59.000Z","size":1166,"stargazers_count":11,"open_issues_count":9,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-01T14:36:15.430Z","etag":null,"topics":["ast","code-generation","ecmascript","estree","javascript","node","nodejs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/fraxken.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-28T20:53:54.000Z","updated_at":"2024-08-11T19:34:07.000Z","dependencies_parsed_at":"2024-10-27T15:28:31.323Z","dependency_job_id":null,"html_url":"https://github.com/fraxken/Node-Estree","commit_stats":null,"previous_names":["fraxken/astree"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraxken%2FNode-Estree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraxken%2FNode-Estree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraxken%2FNode-Estree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraxken%2FNode-Estree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fraxken","download_url":"https://codeload.github.com/fraxken/Node-Estree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228821405,"owners_count":17977166,"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":["ast","code-generation","ecmascript","estree","javascript","node","nodejs","typescript"],"created_at":"2024-08-17T08:03:48.582Z","updated_at":"2024-12-09T02:31:26.051Z","avatar_url":"https://github.com/fraxken.png","language":"TypeScript","funding_links":[],"categories":["typescript"],"sub_categories":[],"readme":"# Node.js ESTree\r\n![version](https://img.shields.io/badge/dynamic/json.svg?url=https://raw.githubusercontent.com/fraxken/Node-Estree/master/package.json\u0026query=$.version\u0026label=Version)\r\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/fraxken/Node-Estree/commit-activity)\r\n![MIT](https://img.shields.io/github/license/mashape/apistatus.svg)\r\n![size](https://img.shields.io/bundlephobia/min/node-estree)\r\n![dep](https://img.shields.io/david/fraxken/Node-Estree)\r\n\r\nComplete and compliant [ESTree](https://github.com/estree/estree) spec implementation in TypeScript (for Node.js and the Browser). This project includes types definitions, variant functions and some helpers aside to help generating code.\r\n\r\n## Getting Started\r\n\r\nThis package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).\r\n\r\n```bash\r\n$ npm install node-estree\r\n# or\r\n$ yarn add node-estree\r\n```\r\n\r\n## Usage example\r\n\r\nFollowing example require the [astring](https://github.com/davidbonnet/astring#readmes) package to generate a JavaScript code with the EStree compliant AST.\r\n\r\n```js\r\n\"use strict\";\r\nconst { ESTree, Helpers, VarDeclaration, Switch } = require(\"node-estree\");\r\nconst astring = require(\"astring\");\r\n\r\nconst logNative = (body) =\u003e ESTree.CallExpression(Helpers.AutoChain(\"console\", \"log\"), body);\r\nconst log = (message) =\u003e logNative([ESTree.Literal(message)]);\r\n\r\n// Note: i use a generator function because I find it easier to read\r\nfunction* program() {\r\n    yield ESTree.ExpressionStatement(log(\"hello world!\"));\r\n    {\r\n        const objExpr = Helpers.PlainObject({\r\n            yoo: \"foo\", test: Helpers.Symbol(\"bar\"), lol: true\r\n        });\r\n\r\n        yield ESTree.BlockStatement([\r\n            VarDeclaration.let(\"myObject\", objExpr),\r\n            ESTree.ExpressionStatement(logNative([ESTree.Identifier(\"myObject\")]))\r\n        ]);\r\n    }\r\n\r\n    yield ESTree.ExpressionStatement(Helpers.AutoChainStr(\"a.b.?hello().c.d()\", {\r\n        hello: [ESTree.Literal(true)]\r\n    }));\r\n\r\n    yield VarDeclaration.const(\"myArray\", Helpers.LiteralArray(1, 2, true, \"boo\"));\r\n\r\n    yield new VarDeclaration({ kind: \"var\" })\r\n        .declare(\"a\", ESTree.Literal(1))\r\n        .declareEx(\"b\", 2)\r\n        .toJSON();\r\n\r\n    yield new Switch(ESTree.Identifier(\"a\"), { autoBreak: true })\r\n        .case(1, [log(\"foo\")])\r\n        .case(2, [log(\"bar\")])\r\n        .toJSON();\r\n}\r\n\r\nconst prog = ESTree.Program(\"module\", [...program()]);\r\nconsole.log(\"\\n\");\r\nconsole.log(astring.generate(prog));\r\n```\r\n\r\nThe astring lib will generate the following JavaScript code:\r\n```js\r\nconsole.log(\"hello world!\");\r\n{\r\n  let myObject = {\r\n    yoo: \"foo\",\r\n    test: Symbol(\"bar\"),\r\n    lol: true\r\n  };\r\n  console.log(myObject);\r\n}\r\na.b.hello(true).c.d();\r\nconst myArray = [1, 2, true, \"boo\"];\r\nvar a = 1, b = 2;\r\nswitch (a) {\r\n  case 1:\r\n    console.log(\"foo\")\r\n    break;\r\n  case 2:\r\n    console.log(\"bar\")\r\n    break;\r\n}\r\n```\r\n\r\nWhen you want to generate a given code I recommend you to use [astexplorer](https://astexplorer.net/). You can observe how the tree is built and reproduce the same thing with my lib.\r\n\r\n## API\r\n\r\n### ESTree\r\nThe ESTree object exports all members for all versions of ECMAScript (the current implementation doesn't work by version.. everything to ES2020 has been implemented). Variant names are exactly the same as the Specification. Everything has been done to be as close to the specification as possible.\r\n\r\nTechnical notes:\r\n- MethodDefinition use the property **isStatic** instead of **static** (because static is a reserved keyword).\r\n- Some Variant with to much properties (like FunctionDeclarations etc) use an options payload.\r\n\r\n```js\r\nFunctionDeclaration(Identifier(\"functionName\"), { body:[], params: [], async: true, generator: false, });\r\n```\r\n\r\n--- \r\n\r\nAvailable Variant\r\n```ts\r\ntype Variant =\r\n    \"Program\" |\r\n    \"Identifier\" |\r\n    \"Literal\" |\r\n    \"RegExpLiteral\" |\r\n    \"ExpressionStatement\" |\r\n    \"BlockStatement\" |\r\n    \"EmptyStatement\" |\r\n    \"DebuggerStatement\" |\r\n    \"WithStatement\" |\r\n    \"ReturnStatement\" |\r\n    \"LabeledStatement\" |\r\n    \"BreakStatement\" |\r\n    \"ContinueStatement\" |\r\n    \"IfStatement\" |\r\n    \"SwitchStatement\" |\r\n    \"SwitchCase\" |\r\n    \"ThrowStatement\" |\r\n    \"TryStatement\" |\r\n    \"CatchClause\" |\r\n    \"WhileStatement\" |\r\n    \"DoWhileStatement\" |\r\n    \"ForStatement\" |\r\n    \"ForInStatement\" |\r\n    \"FunctionDeclaration\" |\r\n    \"VariableDeclaration\" |\r\n    \"VariableDeclarator\" |\r\n    \"ThisExpression\" |\r\n    \"ArrayExpression\" |\r\n    \"ObjectExpression\" |\r\n    \"Property\" |\r\n    \"FunctionExpression\" |\r\n    \"UnaryExpression\" |\r\n    \"UpdateExpression\" |\r\n    \"BinaryExpression\" |\r\n    \"AssignmentExpression\" |\r\n    \"LogicalExpression\" |\r\n    \"MemberExpression\" |\r\n    \"ConditionalExpression\" |\r\n    \"CallExpression\" |\r\n    \"NewExpression\" |\r\n    \"SequenceExpression\" |\r\n    \"ForOfStatement\" |\r\n    \"Super\" |\r\n    \"SpreadElement\" |\r\n    \"ArrowFunctionExpression\" |\r\n    \"YieldExpression\" |\r\n    \"TemplateLiteral\" |\r\n    \"TaggedTemplateExpression\" |\r\n    \"TemplateElement\" |\r\n    \"ObjectPattern\" |\r\n    \"ArrayPattern\" |\r\n    \"RestElement\" |\r\n    \"AssignmentPattern\" |\r\n    \"ClassBody\" |\r\n    \"MethodDefinition\" |\r\n    \"ClassDeclaration\" |\r\n    \"ClassExpression\" |\r\n    \"MetaProperty\" |\r\n    \"ImportDeclaration\" |\r\n    \"ImportExpression\" |\r\n    \"ImportSpecifier\" |\r\n    \"ImportDefaultSpecifier\" |\r\n    \"ImportNamespaceSpecifier\" |\r\n    \"ExportNamedDeclaration\" |\r\n    \"ExportSpecifier\" |\r\n    \"ExportDefaultDeclaration\" |\r\n    \"ExportAllDeclaration\" |\r\n    \"AwaitExpression\" |\r\n    \"ChainExpression\" |\r\n    \"BigIntLiteral\";\r\n```\r\n\r\n### Others\r\n\r\nThose implementation are experimental and may change in future (they are not related to the ESTree spec in any way). Please also feel free to feedback or PR new things!\r\n\r\n- [Helpers API](./docs/Helpers.md)\r\n- [VarDeclaration](./docs/VarDeclaration.md)\r\n- [Switch (stand for SwitchStatement)](./docs/Switch.md)\r\n\r\n## License\r\nMIT\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffraxken%2FNode-Estree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffraxken%2FNode-Estree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffraxken%2FNode-Estree/lists"}