{"id":19504020,"url":"https://github.com/mysticatea/eslint-ast","last_synced_at":"2025-04-26T00:33:22.525Z","repository":{"id":57227609,"uuid":"257422121","full_name":"mysticatea/eslint-ast","owner":"mysticatea","description":"The Extensible Type Definition of ESLint AST","archived":false,"fork":false,"pushed_at":"2021-05-06T10:42:40.000Z","size":216,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-16T19:38:28.732Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mysticatea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["mysticatea"]}},"created_at":"2020-04-20T22:50:09.000Z","updated_at":"2023-03-04T05:01:21.000Z","dependencies_parsed_at":"2022-09-12T16:52:19.004Z","dependency_job_id":null,"html_url":"https://github.com/mysticatea/eslint-ast","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticatea%2Feslint-ast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticatea%2Feslint-ast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticatea%2Feslint-ast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticatea%2Feslint-ast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mysticatea","download_url":"https://codeload.github.com/mysticatea/eslint-ast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250917284,"owners_count":21507561,"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":[],"created_at":"2024-11-10T22:23:58.099Z","updated_at":"2025-04-26T00:33:22.250Z","avatar_url":"https://github.com/mysticatea.png","language":"TypeScript","funding_links":["https://github.com/sponsors/mysticatea"],"categories":[],"sub_categories":[],"readme":"# TypeScript Types for ESLint AST\n\n[![npm version](https://img.shields.io/npm/v/eslint-ast.svg)](https://www.npmjs.com/package/eslint-ast)\n[![Downloads/month](https://img.shields.io/npm/dm/eslint-ast.svg)](http://www.npmtrends.com/eslint-ast)\n[![Build Status](https://github.com/mysticatea/eslint-ast/workflows/CI/badge.svg)](https://github.com/mysticatea/eslint-ast/actions)\n[![Dependency Status](https://david-dm.org/mysticatea/eslint-ast.svg)](https://david-dm.org/mysticatea/eslint-ast)\n\nThis package provides TypeScript types for ESLint AST and the utilities to extend the AST types.\n\n## 💿 Installation\n\nUse [npm](https://www.npmjs.com/) or a compatible tool.\n\n```\n$ npm install eslint-ast\n```\n\n## 📖 Usage\n\n### ■ Using types\n\nThere are several type definition files. Those files exports [AST node](https://github.com/estree/estree) types.\n\n```ts\n// The latest snapshot. Currently this is ES2021.\nimport * as latest from \"eslint-ast\" // or `eslint-ast/latest`\n\n// The living standard, contains the proposals that have arrived at Stage 4.\n// This types will be updated in minor releases.\nimport * as esNext from \"eslint-ast/esnext\"\n\n// It contains the proposals that have arrived at Stage 3.\n// This types will be updated in minor releases.\nimport * as experimental from \"eslint-ast/experimental\"\n\n// The specific snapshots.\nimport * as es2021 from \"eslint-ast/es2021\"\nimport * as es2020 from \"eslint-ast/es2020\"\nimport * as es2019 from \"eslint-ast/es2019\"\nimport * as es2018 from \"eslint-ast/es2018\"\nimport * as es2017 from \"eslint-ast/es2017\"\nimport * as es2016 from \"eslint-ast/es2016\"\nimport * as es2015 from \"eslint-ast/es2015\"\nimport * as es5 from \"eslint-ast/es5\"\n```\n\n### ■ Defining your own AST\n\nThis package provides the utilities to define your own AST types.\n\n1. Declare the AST definition.\n1. Convert the AST definition to the AST types.\n\n```ts\nimport { AST, NodeRef } from \"eslint-ast/util\"\n\n// Declare the AST definition.\n// This has three properties: `nodes`, `aliases`, and `commonProperties`.\ninterface MyDefinition {\n    // Each node's definition.\n    nodes: {\n        Program: {\n            // `NodeRef\u003c node-name-or-alias \u003e` will be replaced by actual node type later.\n            expression: NodeRef\u003c\"Expression\"\u003e\n        }\n        ConstantValue: {\n            value: number\n        }\n        BinaryExpression: {\n            operator: \"+\" | \"-\" | \"*\" | \"/\"\n            left: NodeRef\u003c\"Expression\"\u003e\n            right: NodeRef\u003c\"Expression\"\u003e\n        }\n    }\n\n    // Alias definitions to use `NodeRef`.\n    aliases: {\n        Expression: \"ConstantValue\" | \"BinaryExpression\"\n    }\n\n    // You can define common properties for every node.\n    // The `parent` and `type` properties are automatically defined.\n    commonProperties: {\n        range: readonly [number, number]\n    }\n}\n\n// Convert the AST definition to AST types.\ntype MyAST = AST\u003cMyDefinition\u003e\n\n// Every types is in the properties of `MyAST`.\ntype Program = MyAST[\"Program\"] //= { type: \"Program\"\n                                //    parent: null | undefined\n                                //    expression: MyAST[\"Expression\"]\n                                //    range: readonly [number, number] }\n\ntype ConstantValue = MyAST[\"ConstantValue\"] //= { type: \"ConstantValue\"\n                                            //    parent: MyAST[\"Program\"] | MyAST[\"BinaryExpression\"]\n                                            //    value: number\n                                            //    range: readonly [number, number] }\n\ntype BinaryExpression = MyAST[\"BinaryExpression\"] //= { type: \"BinaryExpression\"\n                                                  //    parent: MyAST[\"Program\"] | MyAST[\"BinaryExpression\"]\n                                                  //    operator: \"+\" | \"-\" | \"*\" | \"/\"\n                                                  //    left: MyAST[\"Expression\"]\n                                                  //    right: MyAST[\"Expression\"]\n                                                  //    range: readonly [number, number] }\n\ntype Expression = MyAST[\"Expression\"] //= MyAST[\"ConstantValue\"] | MyAST[\"BinaryExpression\"]\n```\n\n- [./es5-definition.ts](./es5-definition.ts) is an example for AST definitions.\n- [./es5.ts](./es5.ts) is an example for converting to AST.\n\n### ■ Extending existing AST\n\nThis package provides the utilities to define your own AST types as extended from other existing AST definition.\n\n1. Declare the differential of AST definition.\n1. Merge the differential and an existing AST definition.\n1. Convert the AST definition to the AST types.\n\n```ts\nimport { Definition as ES2019Definition } from \"eslint-ast/es2019-definition\"\nimport { AST, Extends, NodeRef } from \"eslint-ast/util\"\n\n// Declare the differential of AST definition.\ninterface BigInt {\n    nodes: {\n        // Adding a new property into existing node types.\n        BooleanLiteral: {\n            bigint: undefined\n        }\n        NullLiteral: {\n            bigint: undefined\n        }\n        NumberLiteral: {\n            bigint: undefined\n        }\n        RegExpLiteral: {\n            bigint: undefined\n        }\n        StringLiteral: {\n            bigint: undefined\n        }\n\n        // Adding a new node.\n        BigIntLiteral: {\n            type: \"Literal\"\n            value: bigint | null\n            bigint: string\n            regex: undefined\n            raw: string\n        }\n    }\n\n    aliases: {\n        // Adding the new node into existing aliases.\n        Expression: \"BigIntLiteral\"\n        StaticPropertyKey: \"BigIntLiteral\"\n    }\n}\n\n// Merge the differential and an existing AST definition.\n// I'd like to recommend to use `interface` for readability in VSCode popups.\ninterface MyDefinition extends Extends\u003cES2019Definition, BigInt\u003e {}\n\n// Convert the AST definition to the AST types.\ntype MyAST = AST\u003cMyDefinition\u003e\n```\n\n- [./es2015-definition.ts](./es2015-definition.ts) is an example for extending.\n- [./es2016-definition.ts](./es2016-definition.ts) is an example for extending.\n- [./es2017-definition.ts](./es2017-definition.ts) is an example for extending.\n- [./es2018-definition.ts](./es2018-definition.ts) is an example for extending.\n- [./es2019-definition.ts](./es2019-definition.ts) is an example for extending.\n- [./es2020-definition.ts](./es2020-definition.ts) is an example for extending.\n- [./es2021-definition.ts](./es2021-definition.ts) is an example for extending.\n\n## 📰 Release Notes\n\nSee [GitHub releases](https://github.com/mysticatea/eslint-ast/releases).\n\n## 🚥 Semantic Versioning Policy\n\nIf the type of libraries is updated, it causes compile errors in userland in most cases. Therefore, this package declare semantic versioning policy.\n\n### Major\n\nThe major version bump allows any breaking changes. For example, the following things can happen:\n\n- Changes exposed files.\n- Changes existing types.\n- Changes the API of `eslint-ast/util`.\n- Changes the minimum supported TypeScript version.\n- etc...\n\nIn particular, changing `eslint-ast/latest` requires a major bump.\n\n### Minor\n\nThe minor version bump allows any breaking changes only in `eslint-ast/esnext`, `eslint-ast/esnext-definition`, `eslint-ast/experimental`, `eslint-ast/experimental-definition`, and `eslint-ast/lib/`. It doesn't change the types in the other files.\n\nIt happens when new proposals arrived at Stage 4 and ESTree was updated.\n\n### Patch\n\nThe minor version bump allows any breaking changes only in `eslint-ast/esnext`, `eslint-ast/esnext-definition`, `eslint-ast/experimental`, `eslint-ast/experimental-definition`, and `eslint-ast/lib/`. It doesn't change the types in the other files.\n\nIt happens when bugs found in new types.\n\n## ❤️ Contributing\n\nContributing is welcome. Use GitHub issues and pull requests.\n\n### Development tools\n\n- `npm test` runs tests.\n- `npm run build` compiles codebase and makes `dist/` directory.\n- `npm run update-ast` updates `es*.ts` files by the content of `es*-definition.ts` files.\n- `npm version \u003cmajor|minor|patch\u003e` bump a new version and releases it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmysticatea%2Feslint-ast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmysticatea%2Feslint-ast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmysticatea%2Feslint-ast/lists"}