Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
docs(ast-spec): add script to generates code strings for the doc files#3248
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
Closed
Uh oh!
There was an error while loading.Please reload this page.
Closed
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
17 changes: 17 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: 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
1 change: 1 addition & 0 deletionspackage.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) |
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'], | ||
| }; |
55 changes: 55 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,55 @@ | ||
| { | ||
| "name": "@typescript-eslint/ast-spec", | ||
| "version": "4.20.0", | ||
| "description": "Types for the TypeScript-ESTree AST spec", | ||
| "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", | ||
| "postbuild": "downlevel-dts dist _ts3.4/dist", | ||
| "clean": "tsc -b tsconfig.build.json --clean", | ||
| "postclean": "rimraf dist && rimraf _ts3.4 && 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" | ||
| }, | ||
| "devDependencies": { | ||
| "@typescript-eslint/typescript-estree": "4.20.0", | ||
| "globby": "*", | ||
| "typescript": "*" | ||
| }, | ||
| "funding": { | ||
| "type": "opencollective", | ||
| "url": "https://opencollective.com/typescript-eslint" | ||
| }, | ||
| "typesVersions": { | ||
| "<3.8": { | ||
| "*": [ | ||
| "_ts3.4/*" | ||
| ] | ||
| } | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletionspackages/ast-spec/src/__tests__/ast-node-types.test.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,16 @@ | ||
| import type { AST_NODE_TYPES } from '../ast-node-types'; | ||
| import type { Node } from '../unions/Node'; | ||
| type GetKeys<T extends AST_NODE_TYPES> = keyof Extract<Node, { type: T }>; | ||
| type AllKeys = { | ||
| readonly [T in AST_NODE_TYPES]: GetKeys<T>; | ||
| }; | ||
| type TakesString<T extends Record<string, string>> = T; | ||
| // @ts-expect-error: purposely unused | ||
| type _Test = | ||
| // forcing the test onto a new line so it isn't covered by the expect error | ||
| // If there are any enum members that don't have a corresponding TSESTree.Node, then this line will error with "Type 'string | number | symbol' is not assignable to type 'string'." | ||
| TakesString<AllKeys> | void; |
166 changes: 166 additions & 0 deletionspackages/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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| export enum AST_NODE_TYPES { | ||
| ArrayExpression = 'ArrayExpression', | ||
| ArrayPattern = 'ArrayPattern', | ||
| ArrowFunctionExpression = 'ArrowFunctionExpression', | ||
| AssignmentExpression = 'AssignmentExpression', | ||
| AssignmentPattern = 'AssignmentPattern', | ||
| AwaitExpression = 'AwaitExpression', | ||
| BinaryExpression = 'BinaryExpression', | ||
| BlockStatement = 'BlockStatement', | ||
| BreakStatement = 'BreakStatement', | ||
| CallExpression = 'CallExpression', | ||
| CatchClause = 'CatchClause', | ||
| ChainExpression = 'ChainExpression', | ||
| ClassBody = 'ClassBody', | ||
| ClassDeclaration = 'ClassDeclaration', | ||
| ClassExpression = 'ClassExpression', | ||
| ClassProperty = 'ClassProperty', | ||
| ConditionalExpression = 'ConditionalExpression', | ||
| ContinueStatement = 'ContinueStatement', | ||
| DebuggerStatement = 'DebuggerStatement', | ||
| Decorator = 'Decorator', | ||
| DoWhileStatement = 'DoWhileStatement', | ||
| EmptyStatement = 'EmptyStatement', | ||
| ExportAllDeclaration = 'ExportAllDeclaration', | ||
| ExportDefaultDeclaration = 'ExportDefaultDeclaration', | ||
| ExportNamedDeclaration = 'ExportNamedDeclaration', | ||
| ExportSpecifier = 'ExportSpecifier', | ||
| ExpressionStatement = 'ExpressionStatement', | ||
| ForInStatement = 'ForInStatement', | ||
| ForOfStatement = 'ForOfStatement', | ||
| ForStatement = 'ForStatement', | ||
| FunctionDeclaration = 'FunctionDeclaration', | ||
| FunctionExpression = 'FunctionExpression', | ||
| Identifier = 'Identifier', | ||
| IfStatement = 'IfStatement', | ||
| ImportDeclaration = 'ImportDeclaration', | ||
| ImportDefaultSpecifier = 'ImportDefaultSpecifier', | ||
| ImportExpression = 'ImportExpression', | ||
| ImportNamespaceSpecifier = 'ImportNamespaceSpecifier', | ||
| ImportSpecifier = 'ImportSpecifier', | ||
| JSXAttribute = 'JSXAttribute', | ||
| JSXClosingElement = 'JSXClosingElement', | ||
| JSXClosingFragment = 'JSXClosingFragment', | ||
| JSXElement = 'JSXElement', | ||
| JSXEmptyExpression = 'JSXEmptyExpression', | ||
| JSXExpressionContainer = 'JSXExpressionContainer', | ||
| JSXFragment = 'JSXFragment', | ||
| JSXIdentifier = 'JSXIdentifier', | ||
| JSXMemberExpression = 'JSXMemberExpression', | ||
| JSXNamespacedName = 'JSXNamespacedName', | ||
| JSXOpeningElement = 'JSXOpeningElement', | ||
| JSXOpeningFragment = 'JSXOpeningFragment', | ||
| JSXSpreadAttribute = 'JSXSpreadAttribute', | ||
| JSXSpreadChild = 'JSXSpreadChild', | ||
| JSXText = 'JSXText', | ||
| LabeledStatement = 'LabeledStatement', | ||
| Literal = 'Literal', | ||
| LogicalExpression = 'LogicalExpression', | ||
| MemberExpression = 'MemberExpression', | ||
| MetaProperty = 'MetaProperty', | ||
| MethodDefinition = 'MethodDefinition', | ||
| NewExpression = 'NewExpression', | ||
| ObjectExpression = 'ObjectExpression', | ||
| ObjectPattern = 'ObjectPattern', | ||
| Program = 'Program', | ||
| Property = 'Property', | ||
| RestElement = 'RestElement', | ||
| ReturnStatement = 'ReturnStatement', | ||
| SequenceExpression = 'SequenceExpression', | ||
| SpreadElement = 'SpreadElement', | ||
| Super = 'Super', | ||
| SwitchCase = 'SwitchCase', | ||
| SwitchStatement = 'SwitchStatement', | ||
| TaggedTemplateExpression = 'TaggedTemplateExpression', | ||
| TemplateElement = 'TemplateElement', | ||
| TemplateLiteral = 'TemplateLiteral', | ||
| ThisExpression = 'ThisExpression', | ||
| ThrowStatement = 'ThrowStatement', | ||
| TryStatement = 'TryStatement', | ||
| UnaryExpression = 'UnaryExpression', | ||
| UpdateExpression = 'UpdateExpression', | ||
| VariableDeclaration = 'VariableDeclaration', | ||
| VariableDeclarator = 'VariableDeclarator', | ||
| WhileStatement = 'WhileStatement', | ||
| WithStatement = 'WithStatement', | ||
| YieldExpression = 'YieldExpression', | ||
| /** | ||
| * TS-prefixed nodes | ||
| */ | ||
| TSAbstractClassProperty = 'TSAbstractClassProperty', | ||
| TSAbstractKeyword = 'TSAbstractKeyword', | ||
| TSAbstractMethodDefinition = 'TSAbstractMethodDefinition', | ||
| TSAnyKeyword = 'TSAnyKeyword', | ||
| TSArrayType = 'TSArrayType', | ||
| TSAsExpression = 'TSAsExpression', | ||
| TSAsyncKeyword = 'TSAsyncKeyword', | ||
| TSBigIntKeyword = 'TSBigIntKeyword', | ||
| TSBooleanKeyword = 'TSBooleanKeyword', | ||
| TSCallSignatureDeclaration = 'TSCallSignatureDeclaration', | ||
| TSClassImplements = 'TSClassImplements', | ||
| TSConditionalType = 'TSConditionalType', | ||
| TSConstructorType = 'TSConstructorType', | ||
| TSConstructSignatureDeclaration = 'TSConstructSignatureDeclaration', | ||
| TSDeclareFunction = 'TSDeclareFunction', | ||
| TSDeclareKeyword = 'TSDeclareKeyword', | ||
| TSEmptyBodyFunctionExpression = 'TSEmptyBodyFunctionExpression', | ||
| TSEnumDeclaration = 'TSEnumDeclaration', | ||
| TSEnumMember = 'TSEnumMember', | ||
| TSExportAssignment = 'TSExportAssignment', | ||
| TSExportKeyword = 'TSExportKeyword', | ||
| TSExternalModuleReference = 'TSExternalModuleReference', | ||
| TSFunctionType = 'TSFunctionType', | ||
| TSImportEqualsDeclaration = 'TSImportEqualsDeclaration', | ||
| TSImportType = 'TSImportType', | ||
| TSIndexedAccessType = 'TSIndexedAccessType', | ||
| TSIndexSignature = 'TSIndexSignature', | ||
| TSInferType = 'TSInferType', | ||
| TSInterfaceBody = 'TSInterfaceBody', | ||
| TSInterfaceDeclaration = 'TSInterfaceDeclaration', | ||
| TSInterfaceHeritage = 'TSInterfaceHeritage', | ||
| TSIntersectionType = 'TSIntersectionType', | ||
| TSIntrinsicKeyword = 'TSIntrinsicKeyword', | ||
| TSLiteralType = 'TSLiteralType', | ||
| TSMappedType = 'TSMappedType', | ||
| TSMethodSignature = 'TSMethodSignature', | ||
| TSModuleBlock = 'TSModuleBlock', | ||
| TSModuleDeclaration = 'TSModuleDeclaration', | ||
| TSNamedTupleMember = 'TSNamedTupleMember', | ||
| TSNamespaceExportDeclaration = 'TSNamespaceExportDeclaration', | ||
| TSNeverKeyword = 'TSNeverKeyword', | ||
| TSNonNullExpression = 'TSNonNullExpression', | ||
| TSNullKeyword = 'TSNullKeyword', | ||
| TSNumberKeyword = 'TSNumberKeyword', | ||
| TSObjectKeyword = 'TSObjectKeyword', | ||
| TSOptionalType = 'TSOptionalType', | ||
| TSParameterProperty = 'TSParameterProperty', | ||
| TSParenthesizedType = 'TSParenthesizedType', | ||
| TSPrivateKeyword = 'TSPrivateKeyword', | ||
| TSPropertySignature = 'TSPropertySignature', | ||
| TSProtectedKeyword = 'TSProtectedKeyword', | ||
| TSPublicKeyword = 'TSPublicKeyword', | ||
| TSQualifiedName = 'TSQualifiedName', | ||
| TSReadonlyKeyword = 'TSReadonlyKeyword', | ||
| TSRestType = 'TSRestType', | ||
| TSStaticKeyword = 'TSStaticKeyword', | ||
| TSStringKeyword = 'TSStringKeyword', | ||
| TSSymbolKeyword = 'TSSymbolKeyword', | ||
| TSTemplateLiteralType = 'TSTemplateLiteralType', | ||
| TSThisType = 'TSThisType', | ||
| TSTupleType = 'TSTupleType', | ||
| TSTypeAliasDeclaration = 'TSTypeAliasDeclaration', | ||
| TSTypeAnnotation = 'TSTypeAnnotation', | ||
| TSTypeAssertion = 'TSTypeAssertion', | ||
| TSTypeLiteral = 'TSTypeLiteral', | ||
| TSTypeOperator = 'TSTypeOperator', | ||
| TSTypeParameter = 'TSTypeParameter', | ||
| TSTypeParameterDeclaration = 'TSTypeParameterDeclaration', | ||
| TSTypeParameterInstantiation = 'TSTypeParameterInstantiation', | ||
| TSTypePredicate = 'TSTypePredicate', | ||
| TSTypeQuery = 'TSTypeQuery', | ||
| TSTypeReference = 'TSTypeReference', | ||
| TSUndefinedKeyword = 'TSUndefinedKeyword', | ||
| TSUnionType = 'TSUnionType', | ||
| TSUnknownKeyword = 'TSUnknownKeyword', | ||
| TSVoidKeyword = 'TSVoidKeyword', | ||
| } |
17 changes: 17 additions & 0 deletionspackages/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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| export enum AST_TOKEN_TYPES { | ||
| Boolean = 'Boolean', | ||
| Identifier = 'Identifier', | ||
| JSXIdentifier = 'JSXIdentifier', | ||
| JSXText = 'JSXText', | ||
| Keyword = 'Keyword', | ||
| Null = 'Null', | ||
| Numeric = 'Numeric', | ||
| Punctuator = 'Punctuator', | ||
| RegularExpression = 'RegularExpression', | ||
| String = 'String', | ||
| Template = 'Template', | ||
| // comment types | ||
| Block = 'Block', | ||
| Line = 'Line', | ||
| } |
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; | ||
| } |
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.