Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat: refactor to split AST specification out as its own module#2911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions.eslintignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions.eslintrc.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions.vscode/settings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletionpackage.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletionspackages/ast-spec/LICENSE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
| Copyright (c) 2019 TypeScript ESLint and other contributors | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
24 changes: 24 additions & 0 deletionspackages/ast-spec/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <h1 align="center">TypeScript-ESTree AST Specification</h1> | ||
| <p align="center"> | ||
| <img src="https://github.com/typescript-eslint/typescript-eslint/workflows/CI/badge.svg" alt="CI" /> | ||
| <a href="https://www.npmjs.com/package/@typescript-eslint/ast-spec"><img src="https://img.shields.io/npm/v/@typescript-eslint/ast-spec.svg?style=flat-square" alt="NPM Version" /></a> | ||
| <a href="https://www.npmjs.com/package/@typescript-eslint/ast-spec"><img src="https://img.shields.io/npm/dm/@typescript-eslint/ast-spec.svg?style=flat-square" alt="NPM Downloads" /></a> | ||
| </p> | ||
| This is the complete specification for the TypeScript-ESTree AST. | ||
| It includes: | ||
| - Node definitions as TypeScript types (the specification) | ||
| - Logic for converting from the TypeScript AST to the TypeScript-ESTree AST. | ||
| - Tests/Fixtures/Examples for each Node | ||
| **You probably don't want to use it directly.** | ||
| If you're building an ESLint plugin, consider using [`@typescript-eslint/experimental-utils`](../experimental-utils). | ||
| If you're parsing TypeScript code, consider using [`@typescript-eslint/typescript-estree`](../typescript-estree). | ||
| ## Contributing | ||
| [See the contributing guide here](../../CONTRIBUTING.md) |
31 changes: 31 additions & 0 deletionspackages/ast-spec/api-extractor.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts", | ||
| "apiReport": { | ||
| "enabled": false | ||
| }, | ||
| "docModel": { | ||
| "enabled": false | ||
| }, | ||
| "dtsRollup": { | ||
| "enabled": true, | ||
| "untrimmedFilePath": "<projectFolder>/dist/ast-spec.ts" | ||
| }, | ||
| "tsdocMetadata": { | ||
| "enabled": false | ||
| }, | ||
| "messages": { | ||
| "extractorMessageReporting": { | ||
| "default": { | ||
| "logLevel": "none" | ||
| }, | ||
| "ae-forgotten-export": { | ||
| "logLevel": "none" | ||
| } | ||
| }, | ||
| "tsdocMessageReporting": { | ||
| "default": { | ||
| "logLevel": "none" | ||
| } | ||
| } | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletionspackages/ast-spec/jest.config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| 'use strict'; | ||
| // @ts-check | ||
| /** @type {import('@jest/types').Config.InitialOptions} */ | ||
| module.exports = { | ||
| globals: { | ||
| 'ts-jest': { | ||
| isolatedModules: true, | ||
| }, | ||
| }, | ||
| testEnvironment: 'node', | ||
| transform: { | ||
| ['^.+\\.tsx?$']: 'ts-jest', | ||
| }, | ||
| testRegex: ['./tests/.+\\.test\\.ts$'], | ||
| collectCoverage: false, | ||
| collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], | ||
| moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
| coverageReporters: ['text-summary', 'lcov'], | ||
| }; |
46 changes: 46 additions & 0 deletionspackages/ast-spec/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| { | ||
| "name": "@typescript-eslint/ast-spec", | ||
| "version": "4.20.0", | ||
| "description": "TypeScript-ESTree AST spec", | ||
| "private": true, | ||
| "keywords": [ | ||
| "eslint", | ||
| "typescript", | ||
| "estree" | ||
| ], | ||
| "engines": { | ||
| "node": "^8.10.0 || ^10.13.0 || >=11.10.1" | ||
| }, | ||
| "files": [ | ||
| "dist", | ||
| "package.json", | ||
| "README.md", | ||
| "LICENSE" | ||
| ], | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/typescript-eslint/typescript-eslint.git", | ||
| "directory": "packages/ast-spec" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/typescript-eslint/typescript-eslint/issues" | ||
| }, | ||
| "license": "MIT", | ||
| "main": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "scripts": { | ||
| "build": "tsc -b tsconfig.build.json && api-extractor run --local", | ||
| "clean": "tsc -b tsconfig.build.json --clean", | ||
| "postclean": "rimraf dist && rimraf _ts3.4 && rimraf .rollup.cache && rimraf coverage", | ||
| "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", | ||
| "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", | ||
| "typecheck": "tsc -p tsconfig.json --noEmit" | ||
| }, | ||
| "funding": { | ||
| "type": "opencollective", | ||
| "url": "https://opencollective.com/typescript-eslint" | ||
| }, | ||
| "devDependencies": { | ||
| "@microsoft/api-extractor": "^7.13.2" | ||
| } | ||
| } |
22 changes: 1 addition & 21 deletionspackages/types/src/ast-node-types.ts → packages/ast-spec/src/ast-node-types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletionspackages/types/src/ast-token-types.ts → packages/ast-spec/src/ast-token-types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionspackages/ast-spec/src/base/Accessibility.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export type Accessibility = 'private' | 'protected' | 'public'; |
22 changes: 22 additions & 0 deletionspackages/ast-spec/src/base/BaseNode.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // import type { Node } from '../unions/Node'; | ||
| import type { Range } from './Range'; | ||
| import type { SourceLocation } from './SourceLocation'; | ||
| export interface BaseNode { | ||
| /** | ||
| * The source location information of the node. | ||
| * @see {SourceLocation} | ||
| */ | ||
| loc: SourceLocation; | ||
| /** | ||
| * @see {Range} | ||
| */ | ||
| range: Range; | ||
| /** | ||
| * The parent node of the current node | ||
| */ | ||
| // parent?: Node; | ||
| // every node *will* have a type, but let the nodes define their own exact string | ||
| // type: string; | ||
| } |
8 changes: 8 additions & 0 deletionspackages/ast-spec/src/base/BaseToken.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import type { BaseNode } from './BaseNode'; | ||
| /* | ||
| * Token and Comment are pseudo-nodes to represent pieces of source code | ||
| */ | ||
| export interface BaseToken extends BaseNode { | ||
| value: string; | ||
| } |
8 changes: 8 additions & 0 deletionspackages/ast-spec/src/base/BinaryExpressionBase.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import type { Expression } from '../unions/Expression'; | ||
| import type { BaseNode } from './BaseNode'; | ||
| export interface BinaryExpressionBase extends BaseNode { | ||
| operator: string; | ||
| left: Expression; | ||
| right: Expression; | ||
| } |
20 changes: 20 additions & 0 deletionspackages/ast-spec/src/base/ClassDeclarationBase.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import type { Identifier } from '../expression/Identifier/spec'; | ||
| import type { ClassBody } from '../special/ClassBody/spec'; | ||
| import type { Decorator } from '../special/Decorator/spec'; | ||
| import type { TSClassImplements } from '../special/TSClassImplements/spec'; | ||
| import type { TSTypeParameterDeclaration } from '../special/TSTypeParameterDeclaration/spec'; | ||
| import type { TSTypeParameterInstantiation } from '../special/TSTypeParameterInstantiation/spec'; | ||
| import type { LeftHandSideExpression } from '../unions/LeftHandSideExpression'; | ||
| import type { BaseNode } from './BaseNode'; | ||
| export interface ClassDeclarationBase extends BaseNode { | ||
| typeParameters?: TSTypeParameterDeclaration; | ||
| superTypeParameters?: TSTypeParameterInstantiation; | ||
| id: Identifier | null; | ||
| body: ClassBody; | ||
| superClass: LeftHandSideExpression | null; | ||
| implements?: TSClassImplements[]; | ||
| abstract?: boolean; | ||
| declare?: boolean; | ||
| decorators?: Decorator[]; | ||
| } |
34 changes: 34 additions & 0 deletionspackages/ast-spec/src/base/ClassPropertyBase.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { Decorator } from '../special/Decorator/spec'; | ||
| import type { TSTypeAnnotation } from '../special/TSTypeAnnotation/spec'; | ||
| import type { Expression } from '../unions/Expression'; | ||
| import type { | ||
| PropertyName, | ||
| PropertyNameComputed, | ||
| PropertyNameNonComputed, | ||
| } from '../unions/PropertyName'; | ||
| import type { Accessibility } from './Accessibility'; | ||
| import type { BaseNode } from './BaseNode'; | ||
| interface ClassPropertyBase extends BaseNode { | ||
| key: PropertyName; | ||
| value: Expression | null; | ||
| computed: boolean; | ||
| static: boolean; | ||
| declare: boolean; | ||
| readonly?: boolean; | ||
| decorators?: Decorator[]; | ||
| accessibility?: Accessibility; | ||
| optional?: boolean; | ||
| definite?: boolean; | ||
| typeAnnotation?: TSTypeAnnotation; | ||
| } | ||
| export interface ClassPropertyComputedNameBase extends ClassPropertyBase { | ||
| key: PropertyNameComputed; | ||
| computed: true; | ||
| } | ||
| export interface ClassPropertyNonComputedNameBase extends ClassPropertyBase { | ||
| key: PropertyNameNonComputed; | ||
| computed: false; | ||
| } |
18 changes: 18 additions & 0 deletionspackages/ast-spec/src/base/FunctionDeclarationBase.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import type { Identifier } from '../expression/Identifier/spec'; | ||
| import type { TSTypeAnnotation } from '../special/TSTypeAnnotation/spec'; | ||
| import type { TSTypeParameterDeclaration } from '../special/TSTypeParameterDeclaration/spec'; | ||
| import type { BlockStatement } from '../statement/BlockStatement/spec'; | ||
| import type { Parameter } from '../unions/Parameter'; | ||
| import type { BaseNode } from './BaseNode'; | ||
| export interface FunctionDeclarationBase extends BaseNode { | ||
| id: Identifier | null; | ||
| generator: boolean; | ||
| expression: boolean; | ||
| async: boolean; | ||
| params: Parameter[]; | ||
| body?: BlockStatement | null; | ||
| returnType?: TSTypeAnnotation; | ||
| typeParameters?: TSTypeParameterDeclaration; | ||
| declare?: boolean; | ||
| } |
10 changes: 10 additions & 0 deletionspackages/ast-spec/src/base/LineAndColumnData.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export interface LineAndColumnData { | ||
| /** | ||
| * Line number (1-indexed) | ||
| */ | ||
| line: number; | ||
| /** | ||
| * Column number on the line (0-indexed) | ||
| */ | ||
| column: number; | ||
| } |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.