diff --git a/.eslintrc.js b/.eslintrc.js index 1c18917bbcbe..1d9d4d70f7c0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -7,6 +7,7 @@ module.exports = { 'import', 'eslint-comments', '@typescript-eslint/internal', + 'simple-import-sort', ], env: { es6: true, @@ -251,5 +252,21 @@ module.exports = { '@typescript-eslint/internal/prefer-ast-types-enum': 'off', }, }, + // ast spec specific standardization + { + files: ['packages/ast-spec/src/**/*.ts'], + rules: { + '@typescript-eslint/consistent-type-imports': [ + 'error', + { prefer: 'type-imports', disallowTypeAnnotations: true }, + ], + '@typescript-eslint/no-unused-vars': 'error', + '@typescript-eslint/sort-type-union-intersection-members': 'error', + 'import/first': 'error', + 'import/newline-after-import': 'error', + 'import/no-duplicates': 'error', + 'simple-import-sort/imports': 'error', + }, + }, ], }; diff --git a/.vscode/settings.json b/.vscode/settings.json index 20830a2fa0b8..f0677068d037 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,8 +13,8 @@ // typescript auto-format settings "typescript.tsdk": "node_modules/typescript/lib", - "javascript.preferences.importModuleSpecifier": "auto", - "typescript.preferences.importModuleSpecifier": "auto", + "javascript.preferences.importModuleSpecifier": "project-relative", + "typescript.preferences.importModuleSpecifier": "project-relative", "javascript.preferences.quoteStyle": "single", "typescript.preferences.quoteStyle": "single", "editor.defaultFormatter": "esbenp.prettier-vscode", diff --git a/package.json b/package.json index 98fed783eb40..57f1f90a76e0 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "eslint-plugin-eslint-plugin": "^2.3.0", "eslint-plugin-import": "^2.22.0", "eslint-plugin-jest": "^23.20.0", + "eslint-plugin-simple-import-sort": "^7.0.0", "glob": "^7.1.6", "husky": "^4.2.5", "isomorphic-fetch": "^2.2.1", diff --git a/packages/ast-spec/LICENSE b/packages/ast-spec/LICENSE new file mode 100644 index 000000000000..7e7370143b26 --- /dev/null +++ b/packages/ast-spec/LICENSE @@ -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. diff --git a/packages/ast-spec/README.md b/packages/ast-spec/README.md new file mode 100644 index 000000000000..7c954398395b --- /dev/null +++ b/packages/ast-spec/README.md @@ -0,0 +1,24 @@ +

TypeScript-ESTree AST Specification

+ +

+ CI + NPM Version + NPM Downloads +

+ +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) diff --git a/packages/ast-spec/jest.config.js b/packages/ast-spec/jest.config.js new file mode 100644 index 000000000000..c23ca67fbc68 --- /dev/null +++ b/packages/ast-spec/jest.config.js @@ -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'], +}; diff --git a/packages/ast-spec/package.json b/packages/ast-spec/package.json new file mode 100644 index 000000000000..2aa6734e0674 --- /dev/null +++ b/packages/ast-spec/package.json @@ -0,0 +1,51 @@ +{ + "name": "@typescript-eslint/ast-spec", + "version": "4.11.1", + "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", + "generate:lib": "../../node_modules/.bin/ts-node --files --transpile-only ../scope-manager/tools/generate-lib.ts", + "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", + "typecheck": "tsc -p tsconfig.json --noEmit" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "typesVersions": { + "<3.8": { + "*": [ + "_ts3.4/*" + ] + } + } +} diff --git a/packages/ast-spec/src/__tests__/ast-node-types.test.ts b/packages/ast-spec/src/__tests__/ast-node-types.test.ts new file mode 100644 index 000000000000..eb0a0894b6ed --- /dev/null +++ b/packages/ast-spec/src/__tests__/ast-node-types.test.ts @@ -0,0 +1,16 @@ +import type { AST_NODE_TYPES } from '../ast-node-types'; +import type { Node } from '../unions/Node'; + +type GetKeys = keyof Extract; + +type AllKeys = { + readonly [T in AST_NODE_TYPES]: GetKeys; +}; + +type TakesString> = 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 | void; diff --git a/packages/ast-spec/src/ast-node-types.ts b/packages/ast-spec/src/ast-node-types.ts new file mode 100644 index 000000000000..c91a1017de08 --- /dev/null +++ b/packages/ast-spec/src/ast-node-types.ts @@ -0,0 +1,164 @@ +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', + 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', + 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', +} diff --git a/packages/ast-spec/src/ast-token-types.ts b/packages/ast-spec/src/ast-token-types.ts new file mode 100644 index 000000000000..f839d8dfae59 --- /dev/null +++ b/packages/ast-spec/src/ast-token-types.ts @@ -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', +} diff --git a/packages/ast-spec/src/base/Accessibility.ts b/packages/ast-spec/src/base/Accessibility.ts new file mode 100644 index 000000000000..d52942f43ab2 --- /dev/null +++ b/packages/ast-spec/src/base/Accessibility.ts @@ -0,0 +1 @@ +export type Accessibility = 'private' | 'protected' | 'public'; diff --git a/packages/ast-spec/src/base/BaseNode.ts b/packages/ast-spec/src/base/BaseNode.ts new file mode 100644 index 000000000000..362f156832b4 --- /dev/null +++ b/packages/ast-spec/src/base/BaseNode.ts @@ -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; +} diff --git a/packages/ast-spec/src/base/BaseToken.ts b/packages/ast-spec/src/base/BaseToken.ts new file mode 100644 index 000000000000..cdf0d1286438 --- /dev/null +++ b/packages/ast-spec/src/base/BaseToken.ts @@ -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; +} diff --git a/packages/ast-spec/src/base/BinaryExpressionBase.ts b/packages/ast-spec/src/base/BinaryExpressionBase.ts new file mode 100644 index 000000000000..926491d49855 --- /dev/null +++ b/packages/ast-spec/src/base/BinaryExpressionBase.ts @@ -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; +} diff --git a/packages/ast-spec/src/base/ClassDeclarationBase.ts b/packages/ast-spec/src/base/ClassDeclarationBase.ts new file mode 100644 index 000000000000..f104b739b517 --- /dev/null +++ b/packages/ast-spec/src/base/ClassDeclarationBase.ts @@ -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[]; +} diff --git a/packages/ast-spec/src/base/ClassPropertyBase.ts b/packages/ast-spec/src/base/ClassPropertyBase.ts new file mode 100644 index 000000000000..8ac19b05fa55 --- /dev/null +++ b/packages/ast-spec/src/base/ClassPropertyBase.ts @@ -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; +} diff --git a/packages/ast-spec/src/base/FunctionDeclarationBase.ts b/packages/ast-spec/src/base/FunctionDeclarationBase.ts new file mode 100644 index 000000000000..50b7aa97bf2f --- /dev/null +++ b/packages/ast-spec/src/base/FunctionDeclarationBase.ts @@ -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; +} diff --git a/packages/ast-spec/src/base/LineAndColumnData.ts b/packages/ast-spec/src/base/LineAndColumnData.ts new file mode 100644 index 000000000000..740ebe6fa467 --- /dev/null +++ b/packages/ast-spec/src/base/LineAndColumnData.ts @@ -0,0 +1,10 @@ +export interface LineAndColumnData { + /** + * Line number (1-indexed) + */ + line: number; + /** + * Column number on the line (0-indexed) + */ + column: number; +} diff --git a/packages/ast-spec/src/base/LiteralBase.ts b/packages/ast-spec/src/base/LiteralBase.ts new file mode 100644 index 000000000000..4944ce7fc9fe --- /dev/null +++ b/packages/ast-spec/src/base/LiteralBase.ts @@ -0,0 +1,6 @@ +import type { BaseNode } from './BaseNode'; + +export interface LiteralBase extends BaseNode { + raw: string; + value: RegExp | bigint | boolean | null | number | string; +} diff --git a/packages/ast-spec/src/base/MethodDefinitionBase.ts b/packages/ast-spec/src/base/MethodDefinitionBase.ts new file mode 100644 index 000000000000..fe8846062106 --- /dev/null +++ b/packages/ast-spec/src/base/MethodDefinitionBase.ts @@ -0,0 +1,35 @@ +import type { FunctionExpression } from '../expression/FunctionExpression/spec'; +import type { TSEmptyBodyFunctionExpression } from '../expression/TSEmptyBodyFunctionExpression/spec'; +import type { Decorator } from '../special/Decorator/spec'; +import type { TSTypeParameterDeclaration } from '../special/TSTypeParameterDeclaration/spec'; +import type { + PropertyName, + PropertyNameComputed, + PropertyNameNonComputed, +} from '../unions/PropertyName'; +import type { Accessibility } from './Accessibility'; +import type { BaseNode } from './BaseNode'; + +/** this should not be directly used - instead use MethodDefinitionComputedNameBase or MethodDefinitionNonComputedNameBase */ +interface MethodDefinitionBase extends BaseNode { + key: PropertyName; + value: FunctionExpression | TSEmptyBodyFunctionExpression; + computed: boolean; + static: boolean; + kind: 'constructor' | 'get' | 'method' | 'set'; + optional?: boolean; + decorators?: Decorator[]; + accessibility?: Accessibility; + typeParameters?: TSTypeParameterDeclaration; +} + +export interface MethodDefinitionComputedNameBase extends MethodDefinitionBase { + key: PropertyNameComputed; + computed: true; +} + +export interface MethodDefinitionNonComputedNameBase + extends MethodDefinitionBase { + key: PropertyNameNonComputed; + computed: false; +} diff --git a/packages/ast-spec/src/base/OptionalRangeAndLoc.ts b/packages/ast-spec/src/base/OptionalRangeAndLoc.ts new file mode 100644 index 000000000000..d9b8cc9f874d --- /dev/null +++ b/packages/ast-spec/src/base/OptionalRangeAndLoc.ts @@ -0,0 +1,11 @@ +import type { Range } from './Range'; +import type { SourceLocation } from './SourceLocation'; + +// TODO - breaking change move this into `typescript-estree` +export type OptionalRangeAndLoc = Pick< + T, + Exclude +> & { + range?: Range; + loc?: SourceLocation; +}; diff --git a/packages/ast-spec/src/base/Range.ts b/packages/ast-spec/src/base/Range.ts new file mode 100644 index 000000000000..e78f71e3f747 --- /dev/null +++ b/packages/ast-spec/src/base/Range.ts @@ -0,0 +1,6 @@ +/** + * An array of two numbers. + * Both numbers are a 0-based index which is the position in the array of source code characters. + * The first is the start position of the node, the second is the end position of the node. + */ +export type Range = [number, number]; diff --git a/packages/ast-spec/src/base/SourceLocation.ts b/packages/ast-spec/src/base/SourceLocation.ts new file mode 100644 index 000000000000..e1a8e272a6fc --- /dev/null +++ b/packages/ast-spec/src/base/SourceLocation.ts @@ -0,0 +1,12 @@ +import type { LineAndColumnData } from './LineAndColumnData'; + +export interface SourceLocation { + /** + * The position of the first character of the parsed source region + */ + start: LineAndColumnData; + /** + * The position of the first character after the parsed source region + */ + end: LineAndColumnData; +} diff --git a/packages/ast-spec/src/base/TSFunctionSignatureBase.ts b/packages/ast-spec/src/base/TSFunctionSignatureBase.ts new file mode 100644 index 000000000000..0da1e7b414d6 --- /dev/null +++ b/packages/ast-spec/src/base/TSFunctionSignatureBase.ts @@ -0,0 +1,10 @@ +import type { TSTypeAnnotation } from '../special/TSTypeAnnotation/spec'; +import type { TSTypeParameterDeclaration } from '../special/TSTypeParameterDeclaration/spec'; +import type { Parameter } from '../unions/Parameter'; +import type { BaseNode } from './BaseNode'; + +export interface TSFunctionSignatureBase extends BaseNode { + params: Parameter[]; + returnType?: TSTypeAnnotation; + typeParameters?: TSTypeParameterDeclaration; +} diff --git a/packages/ast-spec/src/base/TSHeritageBase.ts b/packages/ast-spec/src/base/TSHeritageBase.ts new file mode 100644 index 000000000000..b3ed1770b674 --- /dev/null +++ b/packages/ast-spec/src/base/TSHeritageBase.ts @@ -0,0 +1,8 @@ +import type { TSTypeParameterInstantiation } from '../special/TSTypeParameterInstantiation/spec'; +import type { Expression } from '../unions/Expression'; +import type { BaseNode } from './BaseNode'; + +export interface TSHeritageBase extends BaseNode { + expression: Expression; + typeParameters?: TSTypeParameterInstantiation; +} diff --git a/packages/ast-spec/src/base/UnaryExpressionBase.ts b/packages/ast-spec/src/base/UnaryExpressionBase.ts new file mode 100644 index 000000000000..feb681ccbc3c --- /dev/null +++ b/packages/ast-spec/src/base/UnaryExpressionBase.ts @@ -0,0 +1,10 @@ +import type { UnaryExpression } from '../expression/UnaryExpression/spec'; +import type { LeftHandSideExpression } from '../unions/LeftHandSideExpression'; +import type { Literal } from '../unions/Literal'; +import type { BaseNode } from './BaseNode'; + +export interface UnaryExpressionBase extends BaseNode { + operator: string; + prefix: boolean; + argument: LeftHandSideExpression | Literal | UnaryExpression; +} diff --git a/packages/ast-spec/src/convert.ts b/packages/ast-spec/src/convert.ts new file mode 100644 index 000000000000..dbfa5b311edf --- /dev/null +++ b/packages/ast-spec/src/convert.ts @@ -0,0 +1 @@ +export const Convert = 1; diff --git a/packages/ast-spec/src/element/ClassProperty/spec.ts b/packages/ast-spec/src/element/ClassProperty/spec.ts new file mode 100644 index 000000000000..29fe75aa84e6 --- /dev/null +++ b/packages/ast-spec/src/element/ClassProperty/spec.ts @@ -0,0 +1,19 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { + ClassPropertyComputedNameBase, + ClassPropertyNonComputedNameBase, +} from '../../base/ClassPropertyBase'; + +export interface ClassPropertyComputedName + extends ClassPropertyComputedNameBase { + type: AST_NODE_TYPES.ClassProperty; +} + +export interface ClassPropertyNonComputedName + extends ClassPropertyNonComputedNameBase { + type: AST_NODE_TYPES.ClassProperty; +} + +export type ClassProperty = + | ClassPropertyComputedName + | ClassPropertyNonComputedName; diff --git a/packages/ast-spec/src/element/MethodDefinition/spec.ts b/packages/ast-spec/src/element/MethodDefinition/spec.ts new file mode 100644 index 000000000000..f097f9f8e854 --- /dev/null +++ b/packages/ast-spec/src/element/MethodDefinition/spec.ts @@ -0,0 +1,19 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { + MethodDefinitionComputedNameBase, + MethodDefinitionNonComputedNameBase, +} from '../../base/MethodDefinitionBase'; + +export interface MethodDefinitionComputedName + extends MethodDefinitionComputedNameBase { + type: AST_NODE_TYPES.MethodDefinition; +} + +export interface MethodDefinitionNonComputedName + extends MethodDefinitionNonComputedNameBase { + type: AST_NODE_TYPES.MethodDefinition; +} + +export type MethodDefinition = + | MethodDefinitionComputedName + | MethodDefinitionNonComputedName; diff --git a/packages/ast-spec/src/element/Property/spec.ts b/packages/ast-spec/src/element/Property/spec.ts new file mode 100644 index 000000000000..c96a7a26e371 --- /dev/null +++ b/packages/ast-spec/src/element/Property/spec.ts @@ -0,0 +1,37 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSEmptyBodyFunctionExpression } from '../../expression/TSEmptyBodyFunctionExpression/spec'; +import type { AssignmentPattern } from '../../parameter/AssignmentPattern/spec'; +import type { BindingName } from '../../unions/BindingName'; +import type { Expression } from '../../unions/Expression'; +import type { + PropertyName, + PropertyNameComputed, + PropertyNameNonComputed, +} from '../../unions/PropertyName'; + +interface PropertyBase extends BaseNode { + type: AST_NODE_TYPES.Property; + key: PropertyName; + value: + | AssignmentPattern + | BindingName + | Expression + | TSEmptyBodyFunctionExpression; + computed: boolean; + method: boolean; + shorthand: boolean; + optional?: boolean; + kind: 'get' | 'init' | 'set'; +} + +export interface PropertyComputedName extends PropertyBase { + key: PropertyNameComputed; + computed: true; +} +export interface PropertyNonComputedName extends PropertyBase { + key: PropertyNameNonComputed; + computed: false; +} + +export type Property = PropertyComputedName | PropertyNonComputedName; diff --git a/packages/ast-spec/src/element/SpreadElement/spec.ts b/packages/ast-spec/src/element/SpreadElement/spec.ts new file mode 100644 index 000000000000..13a691901710 --- /dev/null +++ b/packages/ast-spec/src/element/SpreadElement/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; + +export interface SpreadElement extends BaseNode { + type: AST_NODE_TYPES.SpreadElement; + argument: Expression; +} diff --git a/packages/ast-spec/src/element/TSAbstractClassProperty/spec.ts b/packages/ast-spec/src/element/TSAbstractClassProperty/spec.ts new file mode 100644 index 000000000000..0d845a893290 --- /dev/null +++ b/packages/ast-spec/src/element/TSAbstractClassProperty/spec.ts @@ -0,0 +1,19 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { + ClassPropertyComputedNameBase, + ClassPropertyNonComputedNameBase, +} from '../../base/ClassPropertyBase'; + +export interface TSAbstractClassPropertyComputedName + extends ClassPropertyComputedNameBase { + type: AST_NODE_TYPES.TSAbstractClassProperty; +} + +export interface TSAbstractClassPropertyNonComputedName + extends ClassPropertyNonComputedNameBase { + type: AST_NODE_TYPES.TSAbstractClassProperty; +} + +export type TSAbstractClassProperty = + | TSAbstractClassPropertyComputedName + | TSAbstractClassPropertyNonComputedName; diff --git a/packages/ast-spec/src/element/TSAbstractMethodDefinition/spec.ts b/packages/ast-spec/src/element/TSAbstractMethodDefinition/spec.ts new file mode 100644 index 000000000000..a8f5a05c50ab --- /dev/null +++ b/packages/ast-spec/src/element/TSAbstractMethodDefinition/spec.ts @@ -0,0 +1,19 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { + MethodDefinitionComputedNameBase, + MethodDefinitionNonComputedNameBase, +} from '../../base/MethodDefinitionBase'; + +export interface TSAbstractMethodDefinitionComputedName + extends MethodDefinitionComputedNameBase { + type: AST_NODE_TYPES.TSAbstractMethodDefinition; +} + +export interface TSAbstractMethodDefinitionNonComputedName + extends MethodDefinitionNonComputedNameBase { + type: AST_NODE_TYPES.TSAbstractMethodDefinition; +} + +export type TSAbstractMethodDefinition = + | TSAbstractMethodDefinitionComputedName + | TSAbstractMethodDefinitionNonComputedName; diff --git a/packages/ast-spec/src/element/TSCallSignatureDeclaration/spec.ts b/packages/ast-spec/src/element/TSCallSignatureDeclaration/spec.ts new file mode 100644 index 000000000000..8ba015661ccb --- /dev/null +++ b/packages/ast-spec/src/element/TSCallSignatureDeclaration/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { TSFunctionSignatureBase } from '../../base/TSFunctionSignatureBase'; + +export interface TSCallSignatureDeclaration extends TSFunctionSignatureBase { + type: AST_NODE_TYPES.TSCallSignatureDeclaration; +} diff --git a/packages/ast-spec/src/element/TSConstructSignatureDeclaration/spec.ts b/packages/ast-spec/src/element/TSConstructSignatureDeclaration/spec.ts new file mode 100644 index 000000000000..21feddb824d1 --- /dev/null +++ b/packages/ast-spec/src/element/TSConstructSignatureDeclaration/spec.ts @@ -0,0 +1,7 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { TSFunctionSignatureBase } from '../../base/TSFunctionSignatureBase'; + +export interface TSConstructSignatureDeclaration + extends TSFunctionSignatureBase { + type: AST_NODE_TYPES.TSConstructSignatureDeclaration; +} diff --git a/packages/ast-spec/src/element/TSEnumMember/spec.ts b/packages/ast-spec/src/element/TSEnumMember/spec.ts new file mode 100644 index 000000000000..97d8e49fcd94 --- /dev/null +++ b/packages/ast-spec/src/element/TSEnumMember/spec.ts @@ -0,0 +1,41 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { + PropertyNameComputed, + PropertyNameNonComputed, +} from '../../unions/PropertyName'; + +interface TSEnumMemberBase extends BaseNode { + type: AST_NODE_TYPES.TSEnumMember; + id: + | PropertyNameComputed // this should only happen in semantically invalid code (ts error 1164) + | PropertyNameNonComputed; + initializer?: Expression; + computed?: boolean; +} + +/** + * this should only really happen in semantically invalid code (errors 1164 and 2452) + * + * VALID: + * enum Foo { ['a'] } + * + * INVALID: + * const x = 'a'; + * enum Foo { [x] } + * enum Bar { ['a' + 'b'] } + */ +export interface TSEnumMemberComputedName extends TSEnumMemberBase { + id: PropertyNameComputed; + computed: true; +} + +export interface TSEnumMemberNonComputedName extends TSEnumMemberBase { + id: PropertyNameNonComputed; + computed?: false; +} + +export type TSEnumMember = + | TSEnumMemberComputedName + | TSEnumMemberNonComputedName; diff --git a/packages/ast-spec/src/element/TSIndexSignature/spec.ts b/packages/ast-spec/src/element/TSIndexSignature/spec.ts new file mode 100644 index 000000000000..38002bec2951 --- /dev/null +++ b/packages/ast-spec/src/element/TSIndexSignature/spec.ts @@ -0,0 +1,15 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { Accessibility } from '../../base/Accessibility'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; +import type { Parameter } from '../../unions/Parameter'; + +export interface TSIndexSignature extends BaseNode { + type: AST_NODE_TYPES.TSIndexSignature; + parameters: Parameter[]; + typeAnnotation?: TSTypeAnnotation; + readonly?: boolean; + accessibility?: Accessibility; + export?: boolean; + static?: boolean; +} diff --git a/packages/ast-spec/src/element/TSMethodSignature/spec.ts b/packages/ast-spec/src/element/TSMethodSignature/spec.ts new file mode 100644 index 000000000000..76b2e71ab3ad --- /dev/null +++ b/packages/ast-spec/src/element/TSMethodSignature/spec.ts @@ -0,0 +1,39 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { Accessibility } from '../../base/Accessibility'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; +import type { TSTypeParameterDeclaration } from '../../special/TSTypeParameterDeclaration/spec'; +import type { Parameter } from '../../unions/Parameter'; +import type { + PropertyName, + PropertyNameComputed, + PropertyNameNonComputed, +} from '../../unions/PropertyName'; + +interface TSMethodSignatureBase extends BaseNode { + type: AST_NODE_TYPES.TSMethodSignature; + key: PropertyName; + computed: boolean; + params: Parameter[]; + optional?: boolean; + returnType?: TSTypeAnnotation; + readonly?: boolean; + typeParameters?: TSTypeParameterDeclaration; + accessibility?: Accessibility; + export?: boolean; + static?: boolean; +} + +export interface TSMethodSignatureComputedName extends TSMethodSignatureBase { + key: PropertyNameComputed; + computed: true; +} +export interface TSMethodSignatureNonComputedName + extends TSMethodSignatureBase { + key: PropertyNameNonComputed; + computed: false; +} + +export type TSMethodSignature = + | TSMethodSignatureComputedName + | TSMethodSignatureNonComputedName; diff --git a/packages/ast-spec/src/element/TSPropertySignature/spec.ts b/packages/ast-spec/src/element/TSPropertySignature/spec.ts new file mode 100644 index 000000000000..a3f91ac26807 --- /dev/null +++ b/packages/ast-spec/src/element/TSPropertySignature/spec.ts @@ -0,0 +1,39 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { Accessibility } from '../../base/Accessibility'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; +import type { Expression } from '../../unions/Expression'; +import type { + PropertyName, + PropertyNameComputed, + PropertyNameNonComputed, +} from '../../unions/PropertyName'; + +interface TSPropertySignatureBase extends BaseNode { + type: AST_NODE_TYPES.TSPropertySignature; + key: PropertyName; + optional?: boolean; + computed: boolean; + typeAnnotation?: TSTypeAnnotation; + initializer?: Expression; + readonly?: boolean; + static?: boolean; + export?: boolean; + accessibility?: Accessibility; +} + +export interface TSPropertySignatureComputedName + extends TSPropertySignatureBase { + key: PropertyNameComputed; + computed: true; +} + +export interface TSPropertySignatureNonComputedName + extends TSPropertySignatureBase { + key: PropertyNameNonComputed; + computed: false; +} + +export type TSPropertySignature = + | TSPropertySignatureComputedName + | TSPropertySignatureNonComputedName; diff --git a/packages/ast-spec/src/element/spec.ts b/packages/ast-spec/src/element/spec.ts new file mode 100644 index 000000000000..5ee18d914024 --- /dev/null +++ b/packages/ast-spec/src/element/spec.ts @@ -0,0 +1,12 @@ +export * from './ClassProperty/spec'; +export * from './MethodDefinition/spec'; +export * from './Property/spec'; +export * from './SpreadElement/spec'; +export * from './TSAbstractClassProperty/spec'; +export * from './TSAbstractMethodDefinition/spec'; +export * from './TSCallSignatureDeclaration/spec'; +export * from './TSConstructSignatureDeclaration/spec'; +export * from './TSEnumMember/spec'; +export * from './TSIndexSignature/spec'; +export * from './TSMethodSignature/spec'; +export * from './TSPropertySignature/spec'; diff --git a/packages/ast-spec/src/expression/ArrayExpression/spec.ts b/packages/ast-spec/src/expression/ArrayExpression/spec.ts new file mode 100644 index 000000000000..7da330e231a4 --- /dev/null +++ b/packages/ast-spec/src/expression/ArrayExpression/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; + +export interface ArrayExpression extends BaseNode { + type: AST_NODE_TYPES.ArrayExpression; + elements: Expression[]; +} diff --git a/packages/ast-spec/src/expression/ArrowFunctionExpression/spec.ts b/packages/ast-spec/src/expression/ArrowFunctionExpression/spec.ts new file mode 100644 index 000000000000..347ee8541371 --- /dev/null +++ b/packages/ast-spec/src/expression/ArrowFunctionExpression/spec.ts @@ -0,0 +1,19 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; +import type { TSTypeParameterDeclaration } from '../../special/TSTypeParameterDeclaration/spec'; +import type { BlockStatement } from '../../statement/BlockStatement/spec'; +import type { Expression } from '../../unions/Expression'; +import type { Parameter } from '../../unions/Parameter'; + +export interface ArrowFunctionExpression extends BaseNode { + type: AST_NODE_TYPES.ArrowFunctionExpression; + generator: boolean; + id: null; + params: Parameter[]; + body: BlockStatement | Expression; + async: boolean; + expression: boolean; + returnType?: TSTypeAnnotation; + typeParameters?: TSTypeParameterDeclaration; +} diff --git a/packages/ast-spec/src/expression/AssignmentExpression/spec.ts b/packages/ast-spec/src/expression/AssignmentExpression/spec.ts new file mode 100644 index 000000000000..8d76be21bdcc --- /dev/null +++ b/packages/ast-spec/src/expression/AssignmentExpression/spec.ts @@ -0,0 +1,23 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase'; + +export interface AssignmentExpression extends BinaryExpressionBase { + type: AST_NODE_TYPES.AssignmentExpression; + operator: + | '-=' + | '??=' + | '**=' + | '*=' + | '/=' + | '&&=' + | '&=' + | '%=' + | '^=' + | '+=' + | '<<=' + | '=' + | '>>=' + | '>>>=' + | '|=' + | '||='; +} diff --git a/packages/ast-spec/src/expression/AwaitExpression/spec.ts b/packages/ast-spec/src/expression/AwaitExpression/spec.ts new file mode 100644 index 000000000000..248e371e871b --- /dev/null +++ b/packages/ast-spec/src/expression/AwaitExpression/spec.ts @@ -0,0 +1,16 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { LeftHandSideExpression } from '../../unions/LeftHandSideExpression'; +import type { TSTypeAssertion } from '../TSTypeAssertion/spec'; +import type { UnaryExpression } from '../UnaryExpression/spec'; +import type { UpdateExpression } from '../UpdateExpression/spec'; + +export interface AwaitExpression extends BaseNode { + type: AST_NODE_TYPES.AwaitExpression; + argument: + | AwaitExpression + | LeftHandSideExpression + | TSTypeAssertion + | UnaryExpression + | UpdateExpression; +} diff --git a/packages/ast-spec/src/expression/BinaryExpression/spec.ts b/packages/ast-spec/src/expression/BinaryExpression/spec.ts new file mode 100644 index 000000000000..5df33cc3e16a --- /dev/null +++ b/packages/ast-spec/src/expression/BinaryExpression/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase'; + +export interface BinaryExpression extends BinaryExpressionBase { + type: AST_NODE_TYPES.BinaryExpression; +} diff --git a/packages/ast-spec/src/expression/CallExpression/spec.ts b/packages/ast-spec/src/expression/CallExpression/spec.ts new file mode 100644 index 000000000000..9a1c9ea7c47c --- /dev/null +++ b/packages/ast-spec/src/expression/CallExpression/spec.ts @@ -0,0 +1,13 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeParameterInstantiation } from '../../special/TSTypeParameterInstantiation/spec'; +import type { Expression } from '../../unions/Expression'; +import type { LeftHandSideExpression } from '../../unions/LeftHandSideExpression'; + +export interface CallExpression extends BaseNode { + type: AST_NODE_TYPES.CallExpression; + callee: LeftHandSideExpression; + arguments: Expression[]; + typeParameters?: TSTypeParameterInstantiation; + optional: boolean; +} diff --git a/packages/ast-spec/src/expression/ChainExpression/spec.ts b/packages/ast-spec/src/expression/ChainExpression/spec.ts new file mode 100644 index 000000000000..dfad50f3580f --- /dev/null +++ b/packages/ast-spec/src/expression/ChainExpression/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { ChainElement } from '../../unions/ChainElement'; + +export interface ChainExpression extends BaseNode { + type: AST_NODE_TYPES.ChainExpression; + expression: ChainElement; +} diff --git a/packages/ast-spec/src/expression/ClassExpression/spec.ts b/packages/ast-spec/src/expression/ClassExpression/spec.ts new file mode 100644 index 000000000000..15215c31f1b6 --- /dev/null +++ b/packages/ast-spec/src/expression/ClassExpression/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { ClassDeclarationBase } from '../../base/ClassDeclarationBase'; + +export interface ClassExpression extends ClassDeclarationBase { + type: AST_NODE_TYPES.ClassExpression; +} diff --git a/packages/ast-spec/src/expression/ConditionalExpression/spec.ts b/packages/ast-spec/src/expression/ConditionalExpression/spec.ts new file mode 100644 index 000000000000..545fc9497b77 --- /dev/null +++ b/packages/ast-spec/src/expression/ConditionalExpression/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; + +export interface ConditionalExpression extends BaseNode { + type: AST_NODE_TYPES.ConditionalExpression; + test: Expression; + consequent: Expression; + alternate: Expression; +} diff --git a/packages/ast-spec/src/expression/FunctionExpression/spec.ts b/packages/ast-spec/src/expression/FunctionExpression/spec.ts new file mode 100644 index 000000000000..111be168b024 --- /dev/null +++ b/packages/ast-spec/src/expression/FunctionExpression/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { FunctionDeclarationBase } from '../../base/FunctionDeclarationBase'; +import type { BlockStatement } from '../../statement/BlockStatement/spec'; + +export interface FunctionExpression extends FunctionDeclarationBase { + type: AST_NODE_TYPES.FunctionExpression; + body: BlockStatement; +} diff --git a/packages/ast-spec/src/expression/Identifier/spec.ts b/packages/ast-spec/src/expression/Identifier/spec.ts new file mode 100644 index 000000000000..384922a061a1 --- /dev/null +++ b/packages/ast-spec/src/expression/Identifier/spec.ts @@ -0,0 +1,12 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Decorator } from '../../special/Decorator/spec'; +import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; + +export interface Identifier extends BaseNode { + type: AST_NODE_TYPES.Identifier; + name: string; + typeAnnotation?: TSTypeAnnotation; + optional?: boolean; + decorators?: Decorator[]; +} diff --git a/packages/ast-spec/src/expression/ImportExpression/spec.ts b/packages/ast-spec/src/expression/ImportExpression/spec.ts new file mode 100644 index 000000000000..c381802571a6 --- /dev/null +++ b/packages/ast-spec/src/expression/ImportExpression/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; + +export interface ImportExpression extends BaseNode { + type: AST_NODE_TYPES.ImportExpression; + source: Expression; +} diff --git a/packages/ast-spec/src/expression/JSXElement/spec.ts b/packages/ast-spec/src/expression/JSXElement/spec.ts new file mode 100644 index 000000000000..111a9cdbfbd4 --- /dev/null +++ b/packages/ast-spec/src/expression/JSXElement/spec.ts @@ -0,0 +1,12 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { JSXClosingElement } from '../../special/JSXClosingElement/spec'; +import type { JSXOpeningElement } from '../../special/JSXOpeningElement/spec'; +import type { JSXChild } from '../../unions/JSXChild'; + +export interface JSXElement extends BaseNode { + type: AST_NODE_TYPES.JSXElement; + openingElement: JSXOpeningElement; + closingElement: JSXClosingElement | null; + children: JSXChild[]; +} diff --git a/packages/ast-spec/src/expression/JSXFragment/spec.ts b/packages/ast-spec/src/expression/JSXFragment/spec.ts new file mode 100644 index 000000000000..c70749c6b74d --- /dev/null +++ b/packages/ast-spec/src/expression/JSXFragment/spec.ts @@ -0,0 +1,12 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { JSXClosingFragment } from '../../special/JSXClosingFragment/spec'; +import type { JSXOpeningFragment } from '../../special/JSXOpeningFragment/spec'; +import type { JSXChild } from '../../unions/JSXChild'; + +export interface JSXFragment extends BaseNode { + type: AST_NODE_TYPES.JSXFragment; + openingFragment: JSXOpeningFragment; + closingFragment: JSXClosingFragment; + children: JSXChild[]; +} diff --git a/packages/ast-spec/src/expression/LogicalExpression/spec.ts b/packages/ast-spec/src/expression/LogicalExpression/spec.ts new file mode 100644 index 000000000000..a9bd50e1dfe1 --- /dev/null +++ b/packages/ast-spec/src/expression/LogicalExpression/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BinaryExpressionBase } from '../../base/BinaryExpressionBase'; + +export interface LogicalExpression extends BinaryExpressionBase { + type: AST_NODE_TYPES.LogicalExpression; +} diff --git a/packages/ast-spec/src/expression/MemberExpression/spec.ts b/packages/ast-spec/src/expression/MemberExpression/spec.ts new file mode 100644 index 000000000000..92bad8cf3dc3 --- /dev/null +++ b/packages/ast-spec/src/expression/MemberExpression/spec.ts @@ -0,0 +1,28 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { LeftHandSideExpression } from '../../unions/LeftHandSideExpression'; +import type { Identifier } from '../Identifier/spec'; + +interface MemberExpressionBase extends BaseNode { + object: LeftHandSideExpression; + property: Expression | Identifier; + computed: boolean; + optional: boolean; +} + +export interface MemberExpressionComputedName extends MemberExpressionBase { + type: AST_NODE_TYPES.MemberExpression; + property: Expression; + computed: true; +} + +export interface MemberExpressionNonComputedName extends MemberExpressionBase { + type: AST_NODE_TYPES.MemberExpression; + property: Identifier; + computed: false; +} + +export type MemberExpression = + | MemberExpressionComputedName + | MemberExpressionNonComputedName; diff --git a/packages/ast-spec/src/expression/MetaProperty/spec.ts b/packages/ast-spec/src/expression/MetaProperty/spec.ts new file mode 100644 index 000000000000..5bc9afb81113 --- /dev/null +++ b/packages/ast-spec/src/expression/MetaProperty/spec.ts @@ -0,0 +1,9 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../Identifier/spec'; + +export interface MetaProperty extends BaseNode { + type: AST_NODE_TYPES.MetaProperty; + meta: Identifier; + property: Identifier; +} diff --git a/packages/ast-spec/src/expression/NewExpression/spec.ts b/packages/ast-spec/src/expression/NewExpression/spec.ts new file mode 100644 index 000000000000..bb75ae3f4b8f --- /dev/null +++ b/packages/ast-spec/src/expression/NewExpression/spec.ts @@ -0,0 +1,12 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeParameterInstantiation } from '../../special/TSTypeParameterInstantiation/spec'; +import type { Expression } from '../../unions/Expression'; +import type { LeftHandSideExpression } from '../../unions/LeftHandSideExpression'; + +export interface NewExpression extends BaseNode { + type: AST_NODE_TYPES.NewExpression; + callee: LeftHandSideExpression; + arguments: Expression[]; + typeParameters?: TSTypeParameterInstantiation; +} diff --git a/packages/ast-spec/src/expression/ObjectExpression/spec.ts b/packages/ast-spec/src/expression/ObjectExpression/spec.ts new file mode 100644 index 000000000000..0573a2a76faf --- /dev/null +++ b/packages/ast-spec/src/expression/ObjectExpression/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { ObjectLiteralElement } from '../../unions/ObjectLiteralElement'; + +export interface ObjectExpression extends BaseNode { + type: AST_NODE_TYPES.ObjectExpression; + properties: ObjectLiteralElement[]; +} diff --git a/packages/ast-spec/src/expression/SequenceExpression/spec.ts b/packages/ast-spec/src/expression/SequenceExpression/spec.ts new file mode 100644 index 000000000000..fa571adb4f08 --- /dev/null +++ b/packages/ast-spec/src/expression/SequenceExpression/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; + +export interface SequenceExpression extends BaseNode { + type: AST_NODE_TYPES.SequenceExpression; + expressions: Expression[]; +} diff --git a/packages/ast-spec/src/expression/Super/spec.ts b/packages/ast-spec/src/expression/Super/spec.ts new file mode 100644 index 000000000000..eb310620d8ed --- /dev/null +++ b/packages/ast-spec/src/expression/Super/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface Super extends BaseNode { + type: AST_NODE_TYPES.Super; +} diff --git a/packages/ast-spec/src/expression/TSAsExpression/spec.ts b/packages/ast-spec/src/expression/TSAsExpression/spec.ts new file mode 100644 index 000000000000..b90925a53ca7 --- /dev/null +++ b/packages/ast-spec/src/expression/TSAsExpression/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSAsExpression extends BaseNode { + type: AST_NODE_TYPES.TSAsExpression; + expression: Expression; + typeAnnotation: TypeNode; +} diff --git a/packages/ast-spec/src/expression/TSEmptyBodyFunctionExpression/spec.ts b/packages/ast-spec/src/expression/TSEmptyBodyFunctionExpression/spec.ts new file mode 100644 index 000000000000..2cc413c01095 --- /dev/null +++ b/packages/ast-spec/src/expression/TSEmptyBodyFunctionExpression/spec.ts @@ -0,0 +1,7 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { FunctionDeclarationBase } from '../../base/FunctionDeclarationBase'; + +export interface TSEmptyBodyFunctionExpression extends FunctionDeclarationBase { + type: AST_NODE_TYPES.TSEmptyBodyFunctionExpression; + body: null; +} diff --git a/packages/ast-spec/src/expression/TSNonNullExpression/spec.ts b/packages/ast-spec/src/expression/TSNonNullExpression/spec.ts new file mode 100644 index 000000000000..fd25d33d372f --- /dev/null +++ b/packages/ast-spec/src/expression/TSNonNullExpression/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; + +export interface TSNonNullExpression extends BaseNode { + type: AST_NODE_TYPES.TSNonNullExpression; + expression: Expression; +} diff --git a/packages/ast-spec/src/expression/TSTypeAssertion/spec.ts b/packages/ast-spec/src/expression/TSTypeAssertion/spec.ts new file mode 100644 index 000000000000..d820f8fcc378 --- /dev/null +++ b/packages/ast-spec/src/expression/TSTypeAssertion/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSTypeAssertion extends BaseNode { + type: AST_NODE_TYPES.TSTypeAssertion; + typeAnnotation: TypeNode; + expression: Expression; +} diff --git a/packages/ast-spec/src/expression/TaggedTemplateExpression/spec.ts b/packages/ast-spec/src/expression/TaggedTemplateExpression/spec.ts new file mode 100644 index 000000000000..e3438484d9dd --- /dev/null +++ b/packages/ast-spec/src/expression/TaggedTemplateExpression/spec.ts @@ -0,0 +1,12 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeParameterInstantiation } from '../../special/TSTypeParameterInstantiation/spec'; +import type { LeftHandSideExpression } from '../../unions/LeftHandSideExpression'; +import type { TemplateLiteral } from '../TemplateLiteral/spec'; + +export interface TaggedTemplateExpression extends BaseNode { + type: AST_NODE_TYPES.TaggedTemplateExpression; + typeParameters?: TSTypeParameterInstantiation; + tag: LeftHandSideExpression; + quasi: TemplateLiteral; +} diff --git a/packages/ast-spec/src/expression/TemplateLiteral/spec.ts b/packages/ast-spec/src/expression/TemplateLiteral/spec.ts new file mode 100644 index 000000000000..4d92ef79176d --- /dev/null +++ b/packages/ast-spec/src/expression/TemplateLiteral/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TemplateElement } from '../../special/TemplateElement/spec'; +import type { Expression } from '../../unions/Expression'; + +export interface TemplateLiteral extends BaseNode { + type: AST_NODE_TYPES.TemplateLiteral; + quasis: TemplateElement[]; + expressions: Expression[]; +} diff --git a/packages/ast-spec/src/expression/ThisExpression/spec.ts b/packages/ast-spec/src/expression/ThisExpression/spec.ts new file mode 100644 index 000000000000..63b5a213a883 --- /dev/null +++ b/packages/ast-spec/src/expression/ThisExpression/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface ThisExpression extends BaseNode { + type: AST_NODE_TYPES.ThisExpression; +} diff --git a/packages/ast-spec/src/expression/UnaryExpression/spec.ts b/packages/ast-spec/src/expression/UnaryExpression/spec.ts new file mode 100644 index 000000000000..26ec8a0e9cdf --- /dev/null +++ b/packages/ast-spec/src/expression/UnaryExpression/spec.ts @@ -0,0 +1,7 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { UnaryExpressionBase } from '../../base/UnaryExpressionBase'; + +export interface UnaryExpression extends UnaryExpressionBase { + type: AST_NODE_TYPES.UnaryExpression; + operator: '-' | '!' | '+' | '~' | 'delete' | 'typeof' | 'void'; +} diff --git a/packages/ast-spec/src/expression/UpdateExpression/spec.ts b/packages/ast-spec/src/expression/UpdateExpression/spec.ts new file mode 100644 index 000000000000..909815fdabf3 --- /dev/null +++ b/packages/ast-spec/src/expression/UpdateExpression/spec.ts @@ -0,0 +1,7 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { UnaryExpressionBase } from '../../base/UnaryExpressionBase'; + +export interface UpdateExpression extends UnaryExpressionBase { + type: AST_NODE_TYPES.UpdateExpression; + operator: '--' | '++'; +} diff --git a/packages/ast-spec/src/expression/YieldExpression/spec.ts b/packages/ast-spec/src/expression/YieldExpression/spec.ts new file mode 100644 index 000000000000..1f07e4f78e32 --- /dev/null +++ b/packages/ast-spec/src/expression/YieldExpression/spec.ts @@ -0,0 +1,9 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; + +export interface YieldExpression extends BaseNode { + type: AST_NODE_TYPES.YieldExpression; + delegate: boolean; + argument?: Expression; +} diff --git a/packages/ast-spec/src/expression/literal/BigIntLiteral/spec.ts b/packages/ast-spec/src/expression/literal/BigIntLiteral/spec.ts new file mode 100644 index 000000000000..c27a85543ff8 --- /dev/null +++ b/packages/ast-spec/src/expression/literal/BigIntLiteral/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../../ast-node-types'; +import type { LiteralBase } from '../../../base/LiteralBase'; + +export interface BigIntLiteral extends LiteralBase { + type: AST_NODE_TYPES.Literal; + value: bigint | null; + bigint: string; +} diff --git a/packages/ast-spec/src/expression/literal/BooleanLiteral/spec.ts b/packages/ast-spec/src/expression/literal/BooleanLiteral/spec.ts new file mode 100644 index 000000000000..a2310a698d02 --- /dev/null +++ b/packages/ast-spec/src/expression/literal/BooleanLiteral/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../../ast-node-types'; +import type { LiteralBase } from '../../../base/LiteralBase'; + +export interface BooleanLiteral extends LiteralBase { + type: AST_NODE_TYPES.Literal; + value: boolean; + raw: 'false' | 'true'; +} diff --git a/packages/ast-spec/src/expression/literal/NullLiteral/spec.ts b/packages/ast-spec/src/expression/literal/NullLiteral/spec.ts new file mode 100644 index 000000000000..f520b7b3d454 --- /dev/null +++ b/packages/ast-spec/src/expression/literal/NullLiteral/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../../ast-node-types'; +import type { LiteralBase } from '../../../base/LiteralBase'; + +export interface NullLiteral extends LiteralBase { + type: AST_NODE_TYPES.Literal; + value: null; + raw: 'null'; +} diff --git a/packages/ast-spec/src/expression/literal/NumberLiteral/spec.ts b/packages/ast-spec/src/expression/literal/NumberLiteral/spec.ts new file mode 100644 index 000000000000..8155bb45cafc --- /dev/null +++ b/packages/ast-spec/src/expression/literal/NumberLiteral/spec.ts @@ -0,0 +1,7 @@ +import type { AST_NODE_TYPES } from '../../../ast-node-types'; +import type { LiteralBase } from '../../../base/LiteralBase'; + +export interface NumberLiteral extends LiteralBase { + type: AST_NODE_TYPES.Literal; + value: number; +} diff --git a/packages/ast-spec/src/expression/literal/RegExpLiteral/spec.ts b/packages/ast-spec/src/expression/literal/RegExpLiteral/spec.ts new file mode 100644 index 000000000000..ab45f651b768 --- /dev/null +++ b/packages/ast-spec/src/expression/literal/RegExpLiteral/spec.ts @@ -0,0 +1,11 @@ +import type { AST_NODE_TYPES } from '../../../ast-node-types'; +import type { LiteralBase } from '../../../base/LiteralBase'; + +export interface RegExpLiteral extends LiteralBase { + type: AST_NODE_TYPES.Literal; + value: RegExp | null; + regex: { + pattern: string; + flags: string; + }; +} diff --git a/packages/ast-spec/src/expression/literal/StringLiteral/spec.ts b/packages/ast-spec/src/expression/literal/StringLiteral/spec.ts new file mode 100644 index 000000000000..de83d9d20e1d --- /dev/null +++ b/packages/ast-spec/src/expression/literal/StringLiteral/spec.ts @@ -0,0 +1,7 @@ +import type { AST_NODE_TYPES } from '../../../ast-node-types'; +import type { LiteralBase } from '../../../base/LiteralBase'; + +export interface StringLiteral extends LiteralBase { + type: AST_NODE_TYPES.Literal; + value: string; +} diff --git a/packages/ast-spec/src/expression/literal/spec.ts b/packages/ast-spec/src/expression/literal/spec.ts new file mode 100644 index 000000000000..d40804b424e1 --- /dev/null +++ b/packages/ast-spec/src/expression/literal/spec.ts @@ -0,0 +1,6 @@ +export * from './BigIntLiteral/spec'; +export * from './BooleanLiteral/spec'; +export * from './NullLiteral/spec'; +export * from './NumberLiteral/spec'; +export * from './RegExpLiteral/spec'; +export * from './StringLiteral/spec'; diff --git a/packages/ast-spec/src/expression/spec.ts b/packages/ast-spec/src/expression/spec.ts new file mode 100644 index 000000000000..9ea054546202 --- /dev/null +++ b/packages/ast-spec/src/expression/spec.ts @@ -0,0 +1,33 @@ +export * from './ArrayExpression/spec'; +export * from './ArrowFunctionExpression/spec'; +export * from './AssignmentExpression/spec'; +export * from './AwaitExpression/spec'; +export * from './BinaryExpression/spec'; +export * from './CallExpression/spec'; +export * from './ChainExpression/spec'; +export * from './ClassExpression/spec'; +export * from './ConditionalExpression/spec'; +export * from './FunctionExpression/spec'; +export * from './Identifier/spec'; +export * from './ImportExpression/spec'; +export * from './JSXElement/spec'; +export * from './JSXFragment/spec'; +export * from './LogicalExpression/spec'; +export * from './MemberExpression/spec'; +export * from './MetaProperty/spec'; +export * from './NewExpression/spec'; +export * from './ObjectExpression/spec'; +export * from './SequenceExpression/spec'; +export * from './Super/spec'; +export * from './TSAsExpression/spec'; +export * from './TSEmptyBodyFunctionExpression/spec'; +export * from './TSNonNullExpression/spec'; +export * from './TSTypeAssertion/spec'; +export * from './TaggedTemplateExpression/spec'; +export * from './TemplateLiteral/spec'; +export * from './ThisExpression/spec'; +export * from './UnaryExpression/spec'; +export * from './UpdateExpression/spec'; +export * from './YieldExpression/spec'; + +export * from './literal/spec'; diff --git a/packages/ast-spec/src/index.ts b/packages/ast-spec/src/index.ts new file mode 100644 index 000000000000..0a3875673023 --- /dev/null +++ b/packages/ast-spec/src/index.ts @@ -0,0 +1,4 @@ +export * as TSESTree from './spec'; +export * as convert from './convert'; +export * from './ast-node-types'; +export * from './ast-token-types'; diff --git a/packages/ast-spec/src/parameter/ArrayPattern/spec.ts b/packages/ast-spec/src/parameter/ArrayPattern/spec.ts new file mode 100644 index 000000000000..420a93278731 --- /dev/null +++ b/packages/ast-spec/src/parameter/ArrayPattern/spec.ts @@ -0,0 +1,13 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Decorator } from '../../special/Decorator/spec'; +import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; +import type { DestructuringPattern } from '../../unions/DestructuringPattern'; + +export interface ArrayPattern extends BaseNode { + type: AST_NODE_TYPES.ArrayPattern; + elements: (DestructuringPattern | null)[]; + typeAnnotation?: TSTypeAnnotation; + optional?: boolean; + decorators?: Decorator[]; +} diff --git a/packages/ast-spec/src/parameter/AssignmentPattern/spec.ts b/packages/ast-spec/src/parameter/AssignmentPattern/spec.ts new file mode 100644 index 000000000000..ee558c2167c2 --- /dev/null +++ b/packages/ast-spec/src/parameter/AssignmentPattern/spec.ts @@ -0,0 +1,15 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Decorator } from '../../special/Decorator/spec'; +import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; +import type { BindingName } from '../../unions/BindingName'; +import type { Expression } from '../../unions/Expression'; + +export interface AssignmentPattern extends BaseNode { + type: AST_NODE_TYPES.AssignmentPattern; + left: BindingName; + right: Expression; + typeAnnotation?: TSTypeAnnotation; + optional?: boolean; + decorators?: Decorator[]; +} diff --git a/packages/ast-spec/src/parameter/ObjectPattern/spec.ts b/packages/ast-spec/src/parameter/ObjectPattern/spec.ts new file mode 100644 index 000000000000..12c89878794e --- /dev/null +++ b/packages/ast-spec/src/parameter/ObjectPattern/spec.ts @@ -0,0 +1,14 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Property } from '../../element/Property/spec'; +import type { Decorator } from '../../special/Decorator/spec'; +import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; +import type { RestElement } from '../RestElement/spec'; + +export interface ObjectPattern extends BaseNode { + type: AST_NODE_TYPES.ObjectPattern; + properties: (Property | RestElement)[]; + typeAnnotation?: TSTypeAnnotation; + optional?: boolean; + decorators?: Decorator[]; +} diff --git a/packages/ast-spec/src/parameter/RestElement/spec.ts b/packages/ast-spec/src/parameter/RestElement/spec.ts new file mode 100644 index 000000000000..006f5e48ba3b --- /dev/null +++ b/packages/ast-spec/src/parameter/RestElement/spec.ts @@ -0,0 +1,15 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Decorator } from '../../special/Decorator/spec'; +import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; +import type { DestructuringPattern } from '../../unions/DestructuringPattern'; +import type { AssignmentPattern } from '../AssignmentPattern/spec'; + +export interface RestElement extends BaseNode { + type: AST_NODE_TYPES.RestElement; + argument: DestructuringPattern; + typeAnnotation?: TSTypeAnnotation; + optional?: boolean; + value?: AssignmentPattern; + decorators?: Decorator[]; +} diff --git a/packages/ast-spec/src/parameter/TSParameterProperty/spec.ts b/packages/ast-spec/src/parameter/TSParameterProperty/spec.ts new file mode 100644 index 000000000000..d04e49fd98b8 --- /dev/null +++ b/packages/ast-spec/src/parameter/TSParameterProperty/spec.ts @@ -0,0 +1,17 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { Accessibility } from '../../base/Accessibility'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Decorator } from '../../special/Decorator/spec'; +import type { BindingName } from '../../unions/BindingName'; +import type { AssignmentPattern } from '../AssignmentPattern/spec'; +import type { RestElement } from '../RestElement/spec'; + +export interface TSParameterProperty extends BaseNode { + type: AST_NODE_TYPES.TSParameterProperty; + accessibility?: Accessibility; + readonly?: boolean; + static?: boolean; + export?: boolean; + parameter: AssignmentPattern | BindingName | RestElement; + decorators?: Decorator[]; +} diff --git a/packages/ast-spec/src/parameter/spec.ts b/packages/ast-spec/src/parameter/spec.ts new file mode 100644 index 000000000000..b006664a36ae --- /dev/null +++ b/packages/ast-spec/src/parameter/spec.ts @@ -0,0 +1,5 @@ +export * from './ArrayPattern/spec'; +export * from './AssignmentPattern/spec'; +export * from './ObjectPattern/spec'; +export * from './RestElement/spec'; +export * from './TSParameterProperty/spec'; diff --git a/packages/ast-spec/src/spec.ts b/packages/ast-spec/src/spec.ts new file mode 100644 index 000000000000..160d70ed4741 --- /dev/null +++ b/packages/ast-spec/src/spec.ts @@ -0,0 +1,46 @@ +export * from './base/Accessibility'; +export * from './base/BaseNode'; // this is exported so that the `types` package can merge the decl and add the `parent` property +export * from './base/OptionalRangeAndLoc'; +export * from './base/LineAndColumnData'; +export * from './base/Range'; +export * from './base/SourceLocation'; + +export * from './unions/BindingName'; +export * from './unions/BindingPattern'; +export * from './unions/ChainElement'; +export * from './unions/ClassElement'; +export * from './unions/Comment'; +export * from './unions/DeclarationStatement'; +export * from './unions/DestructuringPattern'; +export * from './unions/EntityName'; +export * from './unions/ExportDeclaration'; +export * from './unions/Expression'; +export * from './unions/ForInitialiser'; +export * from './unions/FunctionLike'; +export * from './unions/ImportClause'; +export * from './unions/IterationStatement'; +export * from './unions/JSXChild'; +export * from './unions/JSXExpression'; +export * from './unions/JSXTagNameExpression'; +export * from './unions/LeftHandSideExpression'; +export * from './unions/Literal'; +export * from './unions/LiteralExpression'; +export * from './unions/Modifier'; +export * from './unions/Node'; +export * from './unions/ObjectLiteralElement'; +export * from './unions/Parameter'; +export * from './unions/PrimaryExpression'; +export * from './unions/PropertyName'; +export * from './unions/Statement'; +export * from './unions/TSUnaryExpression'; +export * from './unions/Token'; +export * from './unions/TypeElement'; +export * from './unions/TypeNode'; + +export * from './element/spec'; +export * from './expression/spec'; +export * from './parameter/spec'; +export * from './special/spec'; +export * from './statement/spec'; +export * from './token/spec'; +export * from './type/spec'; diff --git a/packages/ast-spec/src/special/CatchClause/spec.ts b/packages/ast-spec/src/special/CatchClause/spec.ts new file mode 100644 index 000000000000..dea8168acda0 --- /dev/null +++ b/packages/ast-spec/src/special/CatchClause/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { BlockStatement } from '../../statement/BlockStatement/spec'; +import type { BindingName } from '../../unions/BindingName'; + +export interface CatchClause extends BaseNode { + type: AST_NODE_TYPES.CatchClause; + param: BindingName | null; + body: BlockStatement; +} diff --git a/packages/ast-spec/src/special/ClassBody/spec.ts b/packages/ast-spec/src/special/ClassBody/spec.ts new file mode 100644 index 000000000000..11c93d540fb3 --- /dev/null +++ b/packages/ast-spec/src/special/ClassBody/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { ClassElement } from '../../unions/ClassElement'; + +export interface ClassBody extends BaseNode { + type: AST_NODE_TYPES.ClassBody; + body: ClassElement[]; +} diff --git a/packages/ast-spec/src/special/Decorator/spec.ts b/packages/ast-spec/src/special/Decorator/spec.ts new file mode 100644 index 000000000000..3c8d1e819042 --- /dev/null +++ b/packages/ast-spec/src/special/Decorator/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { LeftHandSideExpression } from '../../unions/LeftHandSideExpression'; + +export interface Decorator extends BaseNode { + type: AST_NODE_TYPES.Decorator; + expression: LeftHandSideExpression; +} diff --git a/packages/ast-spec/src/special/EmptyStatement/spec.ts b/packages/ast-spec/src/special/EmptyStatement/spec.ts new file mode 100644 index 000000000000..530283d3bdc1 --- /dev/null +++ b/packages/ast-spec/src/special/EmptyStatement/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface EmptyStatement extends BaseNode { + type: AST_NODE_TYPES.EmptyStatement; +} diff --git a/packages/ast-spec/src/special/ExportSpecifier/spec.ts b/packages/ast-spec/src/special/ExportSpecifier/spec.ts new file mode 100644 index 000000000000..8fd038e92be6 --- /dev/null +++ b/packages/ast-spec/src/special/ExportSpecifier/spec.ts @@ -0,0 +1,9 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; + +export interface ExportSpecifier extends BaseNode { + type: AST_NODE_TYPES.ExportSpecifier; + local: Identifier; + exported: Identifier; +} diff --git a/packages/ast-spec/src/special/ImportDefaultSpecifier/spec.ts b/packages/ast-spec/src/special/ImportDefaultSpecifier/spec.ts new file mode 100644 index 000000000000..c4ad22f20340 --- /dev/null +++ b/packages/ast-spec/src/special/ImportDefaultSpecifier/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; + +export interface ImportDefaultSpecifier extends BaseNode { + type: AST_NODE_TYPES.ImportDefaultSpecifier; + local: Identifier; +} diff --git a/packages/ast-spec/src/special/ImportNamespaceSpecifier/spec.ts b/packages/ast-spec/src/special/ImportNamespaceSpecifier/spec.ts new file mode 100644 index 000000000000..eec79636f1fc --- /dev/null +++ b/packages/ast-spec/src/special/ImportNamespaceSpecifier/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; + +export interface ImportNamespaceSpecifier extends BaseNode { + type: AST_NODE_TYPES.ImportNamespaceSpecifier; + local: Identifier; +} diff --git a/packages/ast-spec/src/special/ImportSpecifier/spec.ts b/packages/ast-spec/src/special/ImportSpecifier/spec.ts new file mode 100644 index 000000000000..326df7db6b65 --- /dev/null +++ b/packages/ast-spec/src/special/ImportSpecifier/spec.ts @@ -0,0 +1,9 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; + +export interface ImportSpecifier extends BaseNode { + type: AST_NODE_TYPES.ImportSpecifier; + local: Identifier; + imported: Identifier; +} diff --git a/packages/ast-spec/src/special/JSXAttribute/spec.ts b/packages/ast-spec/src/special/JSXAttribute/spec.ts new file mode 100644 index 000000000000..43c023a416bd --- /dev/null +++ b/packages/ast-spec/src/special/JSXAttribute/spec.ts @@ -0,0 +1,11 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { JSXExpression } from '../../unions/JSXExpression'; +import type { Literal } from '../../unions/Literal'; +import type { JSXIdentifier } from '../JSXIdentifier/spec'; + +export interface JSXAttribute extends BaseNode { + type: AST_NODE_TYPES.JSXAttribute; + name: JSXIdentifier; + value: JSXExpression | Literal | null; +} diff --git a/packages/ast-spec/src/special/JSXClosingElement/spec.ts b/packages/ast-spec/src/special/JSXClosingElement/spec.ts new file mode 100644 index 000000000000..ea698d6059ed --- /dev/null +++ b/packages/ast-spec/src/special/JSXClosingElement/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { JSXTagNameExpression } from '../../unions/JSXTagNameExpression'; + +export interface JSXClosingElement extends BaseNode { + type: AST_NODE_TYPES.JSXClosingElement; + name: JSXTagNameExpression; +} diff --git a/packages/ast-spec/src/special/JSXClosingFragment/spec.ts b/packages/ast-spec/src/special/JSXClosingFragment/spec.ts new file mode 100644 index 000000000000..8edd7c4e958f --- /dev/null +++ b/packages/ast-spec/src/special/JSXClosingFragment/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface JSXClosingFragment extends BaseNode { + type: AST_NODE_TYPES.JSXClosingFragment; +} diff --git a/packages/ast-spec/src/special/JSXEmptyExpression/spec.ts b/packages/ast-spec/src/special/JSXEmptyExpression/spec.ts new file mode 100644 index 000000000000..36e3c16069c4 --- /dev/null +++ b/packages/ast-spec/src/special/JSXEmptyExpression/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface JSXEmptyExpression extends BaseNode { + type: AST_NODE_TYPES.JSXEmptyExpression; +} diff --git a/packages/ast-spec/src/special/JSXExpressionContainer/spec.ts b/packages/ast-spec/src/special/JSXExpressionContainer/spec.ts new file mode 100644 index 000000000000..1a0673e6fd15 --- /dev/null +++ b/packages/ast-spec/src/special/JSXExpressionContainer/spec.ts @@ -0,0 +1,9 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { JSXEmptyExpression } from '../JSXEmptyExpression/spec'; + +export interface JSXExpressionContainer extends BaseNode { + type: AST_NODE_TYPES.JSXExpressionContainer; + expression: Expression | JSXEmptyExpression; +} diff --git a/packages/ast-spec/src/special/JSXIdentifier/spec.ts b/packages/ast-spec/src/special/JSXIdentifier/spec.ts new file mode 100644 index 000000000000..1d7b71d67ab0 --- /dev/null +++ b/packages/ast-spec/src/special/JSXIdentifier/spec.ts @@ -0,0 +1,7 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface JSXIdentifier extends BaseNode { + type: AST_NODE_TYPES.JSXIdentifier; + name: string; +} diff --git a/packages/ast-spec/src/special/JSXMemberExpression/spec.ts b/packages/ast-spec/src/special/JSXMemberExpression/spec.ts new file mode 100644 index 000000000000..e0cda9c16ee4 --- /dev/null +++ b/packages/ast-spec/src/special/JSXMemberExpression/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { JSXTagNameExpression } from '../../unions/JSXTagNameExpression'; +import type { JSXIdentifier } from '../JSXIdentifier/spec'; + +export interface JSXMemberExpression extends BaseNode { + type: AST_NODE_TYPES.JSXMemberExpression; + object: JSXTagNameExpression; + property: JSXIdentifier; +} diff --git a/packages/ast-spec/src/special/JSXOpeningElement/spec.ts b/packages/ast-spec/src/special/JSXOpeningElement/spec.ts new file mode 100644 index 000000000000..ed933418b351 --- /dev/null +++ b/packages/ast-spec/src/special/JSXOpeningElement/spec.ts @@ -0,0 +1,13 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { JSXTagNameExpression } from '../../unions/JSXTagNameExpression'; +import type { JSXAttribute } from '../JSXAttribute/spec'; +import type { TSTypeParameterInstantiation } from '../TSTypeParameterInstantiation/spec'; + +export interface JSXOpeningElement extends BaseNode { + type: AST_NODE_TYPES.JSXOpeningElement; + typeParameters?: TSTypeParameterInstantiation; + selfClosing: boolean; + name: JSXTagNameExpression; + attributes: JSXAttribute[]; +} diff --git a/packages/ast-spec/src/special/JSXOpeningFragment/spec.ts b/packages/ast-spec/src/special/JSXOpeningFragment/spec.ts new file mode 100644 index 000000000000..9b972a237f22 --- /dev/null +++ b/packages/ast-spec/src/special/JSXOpeningFragment/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface JSXOpeningFragment extends BaseNode { + type: AST_NODE_TYPES.JSXOpeningFragment; +} diff --git a/packages/ast-spec/src/special/JSXSpreadAttribute/spec.ts b/packages/ast-spec/src/special/JSXSpreadAttribute/spec.ts new file mode 100644 index 000000000000..db6e6fc1d1bc --- /dev/null +++ b/packages/ast-spec/src/special/JSXSpreadAttribute/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; + +export interface JSXSpreadAttribute extends BaseNode { + type: AST_NODE_TYPES.JSXSpreadAttribute; + argument: Expression; +} diff --git a/packages/ast-spec/src/special/JSXSpreadChild/spec.ts b/packages/ast-spec/src/special/JSXSpreadChild/spec.ts new file mode 100644 index 000000000000..53fe53555c30 --- /dev/null +++ b/packages/ast-spec/src/special/JSXSpreadChild/spec.ts @@ -0,0 +1,9 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { JSXEmptyExpression } from '../JSXEmptyExpression/spec'; + +export interface JSXSpreadChild extends BaseNode { + type: AST_NODE_TYPES.JSXSpreadChild; + expression: Expression | JSXEmptyExpression; +} diff --git a/packages/ast-spec/src/special/JSXText/spec.ts b/packages/ast-spec/src/special/JSXText/spec.ts new file mode 100644 index 000000000000..a323493fba90 --- /dev/null +++ b/packages/ast-spec/src/special/JSXText/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface JSXText extends BaseNode { + type: AST_NODE_TYPES.JSXText; + value: string; + raw: string; +} diff --git a/packages/ast-spec/src/special/Program/spec.ts b/packages/ast-spec/src/special/Program/spec.ts new file mode 100644 index 000000000000..81d69e1e604d --- /dev/null +++ b/packages/ast-spec/src/special/Program/spec.ts @@ -0,0 +1,13 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Comment } from '../../unions/Comment'; +import type { ProgramStatement } from '../../unions/Statement'; +import type { Token } from '../../unions/Token'; + +export interface Program extends BaseNode { + type: AST_NODE_TYPES.Program; + body: ProgramStatement[]; + sourceType: 'module' | 'script'; + comments?: Comment[]; + tokens?: Token[]; +} diff --git a/packages/ast-spec/src/special/SwitchCase/spec.ts b/packages/ast-spec/src/special/SwitchCase/spec.ts new file mode 100644 index 000000000000..f48f323536a4 --- /dev/null +++ b/packages/ast-spec/src/special/SwitchCase/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { Statement } from '../../unions/Statement'; + +export interface SwitchCase extends BaseNode { + type: AST_NODE_TYPES.SwitchCase; + test: Expression | null; + consequent: Statement[]; +} diff --git a/packages/ast-spec/src/special/TSClassImplements/spec.ts b/packages/ast-spec/src/special/TSClassImplements/spec.ts new file mode 100644 index 000000000000..98213713edc4 --- /dev/null +++ b/packages/ast-spec/src/special/TSClassImplements/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { TSHeritageBase } from '../../base/TSHeritageBase'; + +export interface TSClassImplements extends TSHeritageBase { + type: AST_NODE_TYPES.TSClassImplements; +} diff --git a/packages/ast-spec/src/special/TSExternalModuleReference/spec.ts b/packages/ast-spec/src/special/TSExternalModuleReference/spec.ts new file mode 100644 index 000000000000..e634d4d0d6e9 --- /dev/null +++ b/packages/ast-spec/src/special/TSExternalModuleReference/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; + +export interface TSExternalModuleReference extends BaseNode { + type: AST_NODE_TYPES.TSExternalModuleReference; + expression: Expression; +} diff --git a/packages/ast-spec/src/special/TSInterfaceBody/spec.ts b/packages/ast-spec/src/special/TSInterfaceBody/spec.ts new file mode 100644 index 000000000000..1ee1c901c14d --- /dev/null +++ b/packages/ast-spec/src/special/TSInterfaceBody/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeElement } from '../../unions/TypeElement'; + +export interface TSInterfaceBody extends BaseNode { + type: AST_NODE_TYPES.TSInterfaceBody; + body: TypeElement[]; +} diff --git a/packages/ast-spec/src/special/TSInterfaceHeritage/spec.ts b/packages/ast-spec/src/special/TSInterfaceHeritage/spec.ts new file mode 100644 index 000000000000..29382acd5460 --- /dev/null +++ b/packages/ast-spec/src/special/TSInterfaceHeritage/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { TSHeritageBase } from '../../base/TSHeritageBase'; + +export interface TSInterfaceHeritage extends TSHeritageBase { + type: AST_NODE_TYPES.TSInterfaceHeritage; +} diff --git a/packages/ast-spec/src/special/TSModuleBlock/spec.ts b/packages/ast-spec/src/special/TSModuleBlock/spec.ts new file mode 100644 index 000000000000..9fed19af3b80 --- /dev/null +++ b/packages/ast-spec/src/special/TSModuleBlock/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { ProgramStatement } from '../../unions/Statement'; + +export interface TSModuleBlock extends BaseNode { + type: AST_NODE_TYPES.TSModuleBlock; + body: ProgramStatement[]; +} diff --git a/packages/ast-spec/src/special/TSTypeAnnotation/spec.ts b/packages/ast-spec/src/special/TSTypeAnnotation/spec.ts new file mode 100644 index 000000000000..bb9272353cbc --- /dev/null +++ b/packages/ast-spec/src/special/TSTypeAnnotation/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSTypeAnnotation extends BaseNode { + type: AST_NODE_TYPES.TSTypeAnnotation; + typeAnnotation: TypeNode; +} diff --git a/packages/ast-spec/src/special/TSTypeParameter/spec.ts b/packages/ast-spec/src/special/TSTypeParameter/spec.ts new file mode 100644 index 000000000000..61d75a6a29ed --- /dev/null +++ b/packages/ast-spec/src/special/TSTypeParameter/spec.ts @@ -0,0 +1,11 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSTypeParameter extends BaseNode { + type: AST_NODE_TYPES.TSTypeParameter; + name: Identifier; + constraint?: TypeNode; + default?: TypeNode; +} diff --git a/packages/ast-spec/src/special/TSTypeParameterDeclaration/spec.ts b/packages/ast-spec/src/special/TSTypeParameterDeclaration/spec.ts new file mode 100644 index 000000000000..ac8971e38a0c --- /dev/null +++ b/packages/ast-spec/src/special/TSTypeParameterDeclaration/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeParameter } from '../TSTypeParameter/spec'; + +export interface TSTypeParameterDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSTypeParameterDeclaration; + params: TSTypeParameter[]; +} diff --git a/packages/ast-spec/src/special/TSTypeParameterInstantiation/spec.ts b/packages/ast-spec/src/special/TSTypeParameterInstantiation/spec.ts new file mode 100644 index 000000000000..e5122c2f6a5c --- /dev/null +++ b/packages/ast-spec/src/special/TSTypeParameterInstantiation/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSTypeParameterInstantiation extends BaseNode { + type: AST_NODE_TYPES.TSTypeParameterInstantiation; + params: TypeNode[]; +} diff --git a/packages/ast-spec/src/special/TemplateElement/spec.ts b/packages/ast-spec/src/special/TemplateElement/spec.ts new file mode 100644 index 000000000000..abf4dc910457 --- /dev/null +++ b/packages/ast-spec/src/special/TemplateElement/spec.ts @@ -0,0 +1,11 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TemplateElement extends BaseNode { + type: AST_NODE_TYPES.TemplateElement; + value: { + raw: string; + cooked: string; + }; + tail: boolean; +} diff --git a/packages/ast-spec/src/special/VariableDeclarator/spec.ts b/packages/ast-spec/src/special/VariableDeclarator/spec.ts new file mode 100644 index 000000000000..619c6a57d5dc --- /dev/null +++ b/packages/ast-spec/src/special/VariableDeclarator/spec.ts @@ -0,0 +1,11 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { BindingName } from '../../unions/BindingName'; +import type { Expression } from '../../unions/Expression'; + +export interface VariableDeclarator extends BaseNode { + type: AST_NODE_TYPES.VariableDeclarator; + id: BindingName; + init: Expression | null; + definite?: boolean; +} diff --git a/packages/ast-spec/src/special/spec.ts b/packages/ast-spec/src/special/spec.ts new file mode 100644 index 000000000000..94c9c3dec069 --- /dev/null +++ b/packages/ast-spec/src/special/spec.ts @@ -0,0 +1,33 @@ +export * from './CatchClause/spec'; +export * from './ClassBody/spec'; +export * from './Decorator/spec'; +export * from './EmptyStatement/spec'; +export * from './ExportSpecifier/spec'; +export * from './ImportDefaultSpecifier/spec'; +export * from './ImportNamespaceSpecifier/spec'; +export * from './ImportSpecifier/spec'; +export * from './JSXAttribute/spec'; +export * from './JSXClosingElement/spec'; +export * from './JSXClosingFragment/spec'; +export * from './JSXEmptyExpression/spec'; +export * from './JSXExpressionContainer/spec'; +export * from './JSXIdentifier/spec'; +export * from './JSXMemberExpression/spec'; +export * from './JSXOpeningElement/spec'; +export * from './JSXOpeningFragment/spec'; +export * from './JSXSpreadAttribute/spec'; +export * from './JSXSpreadChild/spec'; +export * from './JSXText/spec'; +export * from './Program/spec'; +export * from './SwitchCase/spec'; +export * from './TSClassImplements/spec'; +export * from './TSExternalModuleReference/spec'; +export * from './TSInterfaceBody/spec'; +export * from './TSInterfaceHeritage/spec'; +export * from './TSModuleBlock/spec'; +export * from './TSTypeAnnotation/spec'; +export * from './TSTypeParameter/spec'; +export * from './TSTypeParameterDeclaration/spec'; +export * from './TSTypeParameterInstantiation/spec'; +export * from './TemplateElement/spec'; +export * from './VariableDeclarator/spec'; diff --git a/packages/ast-spec/src/statement/BlockStatement/spec.ts b/packages/ast-spec/src/statement/BlockStatement/spec.ts new file mode 100644 index 000000000000..298a962e5161 --- /dev/null +++ b/packages/ast-spec/src/statement/BlockStatement/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Statement } from '../../unions/Statement'; + +export interface BlockStatement extends BaseNode { + type: AST_NODE_TYPES.BlockStatement; + body: Statement[]; +} diff --git a/packages/ast-spec/src/statement/BreakStatement/spec.ts b/packages/ast-spec/src/statement/BreakStatement/spec.ts new file mode 100644 index 000000000000..0441c298d365 --- /dev/null +++ b/packages/ast-spec/src/statement/BreakStatement/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; + +export interface BreakStatement extends BaseNode { + type: AST_NODE_TYPES.BreakStatement; + label: Identifier | null; +} diff --git a/packages/ast-spec/src/statement/ClassDeclaration/spec.ts b/packages/ast-spec/src/statement/ClassDeclaration/spec.ts new file mode 100644 index 000000000000..2154b8863a02 --- /dev/null +++ b/packages/ast-spec/src/statement/ClassDeclaration/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { ClassDeclarationBase } from '../../base/ClassDeclarationBase'; + +export interface ClassDeclaration extends ClassDeclarationBase { + type: AST_NODE_TYPES.ClassDeclaration; +} diff --git a/packages/ast-spec/src/statement/ContinueStatement/spec.ts b/packages/ast-spec/src/statement/ContinueStatement/spec.ts new file mode 100644 index 000000000000..70f2373dc217 --- /dev/null +++ b/packages/ast-spec/src/statement/ContinueStatement/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; + +export interface ContinueStatement extends BaseNode { + type: AST_NODE_TYPES.ContinueStatement; + label: Identifier | null; +} diff --git a/packages/ast-spec/src/statement/DebuggerStatement/spec.ts b/packages/ast-spec/src/statement/DebuggerStatement/spec.ts new file mode 100644 index 000000000000..f28b7fc41b72 --- /dev/null +++ b/packages/ast-spec/src/statement/DebuggerStatement/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface DebuggerStatement extends BaseNode { + type: AST_NODE_TYPES.DebuggerStatement; +} diff --git a/packages/ast-spec/src/statement/DoWhileStatement/spec.ts b/packages/ast-spec/src/statement/DoWhileStatement/spec.ts new file mode 100644 index 000000000000..933ce61b2c4c --- /dev/null +++ b/packages/ast-spec/src/statement/DoWhileStatement/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { Statement } from '../../unions/Statement'; + +export interface DoWhileStatement extends BaseNode { + type: AST_NODE_TYPES.DoWhileStatement; + test: Expression; + body: Statement; +} diff --git a/packages/ast-spec/src/statement/ExportAllDeclaration/spec.ts b/packages/ast-spec/src/statement/ExportAllDeclaration/spec.ts new file mode 100644 index 000000000000..e9657a7536fa --- /dev/null +++ b/packages/ast-spec/src/statement/ExportAllDeclaration/spec.ts @@ -0,0 +1,11 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; +import type { Expression } from '../../unions/Expression'; + +export interface ExportAllDeclaration extends BaseNode { + type: AST_NODE_TYPES.ExportAllDeclaration; + source: Expression | null; + exportKind: 'type' | 'value'; + exported: Identifier | null; +} diff --git a/packages/ast-spec/src/statement/ExportDefaultDeclaration/spec.ts b/packages/ast-spec/src/statement/ExportDefaultDeclaration/spec.ts new file mode 100644 index 000000000000..f34b6e44668f --- /dev/null +++ b/packages/ast-spec/src/statement/ExportDefaultDeclaration/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { ExportDeclaration } from '../../unions/ExportDeclaration'; +import type { Expression } from '../../unions/Expression'; + +export interface ExportDefaultDeclaration extends BaseNode { + type: AST_NODE_TYPES.ExportDefaultDeclaration; + declaration: ExportDeclaration | Expression; + exportKind: 'type' | 'value'; +} diff --git a/packages/ast-spec/src/statement/ExportNamedDeclaration/spec.ts b/packages/ast-spec/src/statement/ExportNamedDeclaration/spec.ts new file mode 100644 index 000000000000..021fea1c6330 --- /dev/null +++ b/packages/ast-spec/src/statement/ExportNamedDeclaration/spec.ts @@ -0,0 +1,13 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { ExportSpecifier } from '../../special/ExportSpecifier/spec'; +import type { ExportDeclaration } from '../../unions/ExportDeclaration'; +import type { Expression } from '../../unions/Expression'; + +export interface ExportNamedDeclaration extends BaseNode { + type: AST_NODE_TYPES.ExportNamedDeclaration; + declaration: ExportDeclaration | null; + specifiers: ExportSpecifier[]; + source: Expression | null; + exportKind: 'type' | 'value'; +} diff --git a/packages/ast-spec/src/statement/ExpressionStatement/spec.ts b/packages/ast-spec/src/statement/ExpressionStatement/spec.ts new file mode 100644 index 000000000000..f5fd336a9604 --- /dev/null +++ b/packages/ast-spec/src/statement/ExpressionStatement/spec.ts @@ -0,0 +1,9 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; + +export interface ExpressionStatement extends BaseNode { + type: AST_NODE_TYPES.ExpressionStatement; + expression: Expression; + directive?: string; +} diff --git a/packages/ast-spec/src/statement/ForInStatement/spec.ts b/packages/ast-spec/src/statement/ForInStatement/spec.ts new file mode 100644 index 000000000000..7abe3b2f5fad --- /dev/null +++ b/packages/ast-spec/src/statement/ForInStatement/spec.ts @@ -0,0 +1,12 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { ForInitialiser } from '../../unions/ForInitialiser'; +import type { Statement } from '../../unions/Statement'; + +export interface ForInStatement extends BaseNode { + type: AST_NODE_TYPES.ForInStatement; + left: ForInitialiser; + right: Expression; + body: Statement; +} diff --git a/packages/ast-spec/src/statement/ForOfStatement/spec.ts b/packages/ast-spec/src/statement/ForOfStatement/spec.ts new file mode 100644 index 000000000000..963261eaaac8 --- /dev/null +++ b/packages/ast-spec/src/statement/ForOfStatement/spec.ts @@ -0,0 +1,13 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { ForInitialiser } from '../../unions/ForInitialiser'; +import type { Statement } from '../../unions/Statement'; + +export interface ForOfStatement extends BaseNode { + type: AST_NODE_TYPES.ForOfStatement; + left: ForInitialiser; + right: Expression; + body: Statement; + await: boolean; +} diff --git a/packages/ast-spec/src/statement/ForStatement/spec.ts b/packages/ast-spec/src/statement/ForStatement/spec.ts new file mode 100644 index 000000000000..1b56756b3a50 --- /dev/null +++ b/packages/ast-spec/src/statement/ForStatement/spec.ts @@ -0,0 +1,13 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { ForInitialiser } from '../../unions/ForInitialiser'; +import type { Statement } from '../../unions/Statement'; + +export interface ForStatement extends BaseNode { + type: AST_NODE_TYPES.ForStatement; + init: Expression | ForInitialiser | null; + test: Expression | null; + update: Expression | null; + body: Statement; +} diff --git a/packages/ast-spec/src/statement/FunctionDeclaration/spec.ts b/packages/ast-spec/src/statement/FunctionDeclaration/spec.ts new file mode 100644 index 000000000000..40cf76f389c4 --- /dev/null +++ b/packages/ast-spec/src/statement/FunctionDeclaration/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { FunctionDeclarationBase } from '../../base/FunctionDeclarationBase'; +import type { BlockStatement } from '../BlockStatement/spec'; + +export interface FunctionDeclaration extends FunctionDeclarationBase { + type: AST_NODE_TYPES.FunctionDeclaration; + body: BlockStatement; +} diff --git a/packages/ast-spec/src/statement/IfStatement/spec.ts b/packages/ast-spec/src/statement/IfStatement/spec.ts new file mode 100644 index 000000000000..f9081923e64a --- /dev/null +++ b/packages/ast-spec/src/statement/IfStatement/spec.ts @@ -0,0 +1,11 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { Statement } from '../../unions/Statement'; + +export interface IfStatement extends BaseNode { + type: AST_NODE_TYPES.IfStatement; + test: Expression; + consequent: Statement; + alternate: Statement | null; +} diff --git a/packages/ast-spec/src/statement/ImportDeclaration/spec.ts b/packages/ast-spec/src/statement/ImportDeclaration/spec.ts new file mode 100644 index 000000000000..eaaad5f53e32 --- /dev/null +++ b/packages/ast-spec/src/statement/ImportDeclaration/spec.ts @@ -0,0 +1,11 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { ImportClause } from '../../unions/ImportClause'; +import type { Literal } from '../../unions/Literal'; + +export interface ImportDeclaration extends BaseNode { + type: AST_NODE_TYPES.ImportDeclaration; + source: Literal; + specifiers: ImportClause[]; + importKind: 'type' | 'value'; +} diff --git a/packages/ast-spec/src/statement/LabeledStatement/spec.ts b/packages/ast-spec/src/statement/LabeledStatement/spec.ts new file mode 100644 index 000000000000..d007008d3a4b --- /dev/null +++ b/packages/ast-spec/src/statement/LabeledStatement/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; +import type { Statement } from '../../unions/Statement'; + +export interface LabeledStatement extends BaseNode { + type: AST_NODE_TYPES.LabeledStatement; + label: Identifier; + body: Statement; +} diff --git a/packages/ast-spec/src/statement/ReturnStatement/spec.ts b/packages/ast-spec/src/statement/ReturnStatement/spec.ts new file mode 100644 index 000000000000..d7758715c8dd --- /dev/null +++ b/packages/ast-spec/src/statement/ReturnStatement/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; + +export interface ReturnStatement extends BaseNode { + type: AST_NODE_TYPES.ReturnStatement; + argument: Expression | null; +} diff --git a/packages/ast-spec/src/statement/SwitchStatement/spec.ts b/packages/ast-spec/src/statement/SwitchStatement/spec.ts new file mode 100644 index 000000000000..9c76f81455c8 --- /dev/null +++ b/packages/ast-spec/src/statement/SwitchStatement/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { SwitchCase } from '../../special/SwitchCase/spec'; +import type { Expression } from '../../unions/Expression'; + +export interface SwitchStatement extends BaseNode { + type: AST_NODE_TYPES.SwitchStatement; + discriminant: Expression; + cases: SwitchCase[]; +} diff --git a/packages/ast-spec/src/statement/TSDeclareFunction/spec.ts b/packages/ast-spec/src/statement/TSDeclareFunction/spec.ts new file mode 100644 index 000000000000..88bd4aff2f21 --- /dev/null +++ b/packages/ast-spec/src/statement/TSDeclareFunction/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { FunctionDeclarationBase } from '../../base/FunctionDeclarationBase'; + +export interface TSDeclareFunction extends FunctionDeclarationBase { + type: AST_NODE_TYPES.TSDeclareFunction; +} diff --git a/packages/ast-spec/src/statement/TSEnumDeclaration/spec.ts b/packages/ast-spec/src/statement/TSEnumDeclaration/spec.ts new file mode 100644 index 000000000000..1c1530d501ff --- /dev/null +++ b/packages/ast-spec/src/statement/TSEnumDeclaration/spec.ts @@ -0,0 +1,14 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSEnumMember } from '../../element/TSEnumMember/spec'; +import type { Identifier } from '../../expression/Identifier/spec'; +import type { Modifier } from '../../unions/Modifier'; + +export interface TSEnumDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSEnumDeclaration; + id: Identifier; + members: TSEnumMember[]; + const?: boolean; + declare?: boolean; + modifiers?: Modifier[]; +} diff --git a/packages/ast-spec/src/statement/TSExportAssignment/spec.ts b/packages/ast-spec/src/statement/TSExportAssignment/spec.ts new file mode 100644 index 000000000000..3792bc5012b1 --- /dev/null +++ b/packages/ast-spec/src/statement/TSExportAssignment/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; + +export interface TSExportAssignment extends BaseNode { + type: AST_NODE_TYPES.TSExportAssignment; + expression: Expression; +} diff --git a/packages/ast-spec/src/statement/TSImportEqualsDeclaration/spec.ts b/packages/ast-spec/src/statement/TSImportEqualsDeclaration/spec.ts new file mode 100644 index 000000000000..38bf8563bf3a --- /dev/null +++ b/packages/ast-spec/src/statement/TSImportEqualsDeclaration/spec.ts @@ -0,0 +1,12 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; +import type { TSExternalModuleReference } from '../../special/TSExternalModuleReference/spec'; +import type { EntityName } from '../../unions/EntityName'; + +export interface TSImportEqualsDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSImportEqualsDeclaration; + id: Identifier; + moduleReference: EntityName | TSExternalModuleReference; + isExport: boolean; +} diff --git a/packages/ast-spec/src/statement/TSInterfaceDeclaration/spec.ts b/packages/ast-spec/src/statement/TSInterfaceDeclaration/spec.ts new file mode 100644 index 000000000000..1e95380c3cbb --- /dev/null +++ b/packages/ast-spec/src/statement/TSInterfaceDeclaration/spec.ts @@ -0,0 +1,17 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; +import type { TSInterfaceBody } from '../../special/TSInterfaceBody/spec'; +import type { TSInterfaceHeritage } from '../../special/TSInterfaceHeritage/spec'; +import type { TSTypeParameterDeclaration } from '../../special/TSTypeParameterDeclaration/spec'; + +export interface TSInterfaceDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSInterfaceDeclaration; + body: TSInterfaceBody; + id: Identifier; + typeParameters?: TSTypeParameterDeclaration; + extends?: TSInterfaceHeritage[]; + implements?: TSInterfaceHeritage[]; + abstract?: boolean; + declare?: boolean; +} diff --git a/packages/ast-spec/src/statement/TSModuleDeclaration/spec.ts b/packages/ast-spec/src/statement/TSModuleDeclaration/spec.ts new file mode 100644 index 000000000000..cfadd9ba4ddc --- /dev/null +++ b/packages/ast-spec/src/statement/TSModuleDeclaration/spec.ts @@ -0,0 +1,15 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; +import type { TSModuleBlock } from '../../special/TSModuleBlock/spec'; +import type { Literal } from '../../unions/Literal'; +import type { Modifier } from '../../unions/Modifier'; + +export interface TSModuleDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSModuleDeclaration; + id: Identifier | Literal; + body?: TSModuleBlock; + global?: boolean; + declare?: boolean; + modifiers?: Modifier[]; +} diff --git a/packages/ast-spec/src/statement/TSNamespaceExportDeclaration/spec.ts b/packages/ast-spec/src/statement/TSNamespaceExportDeclaration/spec.ts new file mode 100644 index 000000000000..6853d4a28544 --- /dev/null +++ b/packages/ast-spec/src/statement/TSNamespaceExportDeclaration/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; + +export interface TSNamespaceExportDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSNamespaceExportDeclaration; + id: Identifier; +} diff --git a/packages/ast-spec/src/statement/TSTypeAliasDeclaration/spec.ts b/packages/ast-spec/src/statement/TSTypeAliasDeclaration/spec.ts new file mode 100644 index 000000000000..61ce986c2a23 --- /dev/null +++ b/packages/ast-spec/src/statement/TSTypeAliasDeclaration/spec.ts @@ -0,0 +1,13 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; +import type { TSTypeParameterDeclaration } from '../../special/TSTypeParameterDeclaration/spec'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSTypeAliasDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSTypeAliasDeclaration; + id: Identifier; + typeAnnotation: TypeNode; + declare?: boolean; + typeParameters?: TSTypeParameterDeclaration; +} diff --git a/packages/ast-spec/src/statement/ThrowStatement/spec.ts b/packages/ast-spec/src/statement/ThrowStatement/spec.ts new file mode 100644 index 000000000000..ac47bd98778c --- /dev/null +++ b/packages/ast-spec/src/statement/ThrowStatement/spec.ts @@ -0,0 +1,9 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSAsExpression } from '../../expression/TSAsExpression/spec'; +import type { Statement } from '../../unions/Statement'; + +export interface ThrowStatement extends BaseNode { + type: AST_NODE_TYPES.ThrowStatement; + argument: Statement | TSAsExpression | null; +} diff --git a/packages/ast-spec/src/statement/TryStatement/spec.ts b/packages/ast-spec/src/statement/TryStatement/spec.ts new file mode 100644 index 000000000000..0435fbeb2100 --- /dev/null +++ b/packages/ast-spec/src/statement/TryStatement/spec.ts @@ -0,0 +1,11 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { CatchClause } from '../../special/CatchClause/spec'; +import type { BlockStatement } from '../BlockStatement/spec'; + +export interface TryStatement extends BaseNode { + type: AST_NODE_TYPES.TryStatement; + block: BlockStatement; + handler: CatchClause | null; + finalizer: BlockStatement | null; +} diff --git a/packages/ast-spec/src/statement/VariableDeclaration/spec.ts b/packages/ast-spec/src/statement/VariableDeclaration/spec.ts new file mode 100644 index 000000000000..418a51eb735b --- /dev/null +++ b/packages/ast-spec/src/statement/VariableDeclaration/spec.ts @@ -0,0 +1,11 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { VariableDeclarator } from '../../special/VariableDeclarator/spec'; + +export interface VariableDeclaration extends BaseNode { + type: AST_NODE_TYPES.VariableDeclaration; + // NOTE - this is not guaranteed to have any elements in it. i.e. `const;` + declarations: VariableDeclarator[]; + kind: 'const' | 'let' | 'var'; + declare?: boolean; +} diff --git a/packages/ast-spec/src/statement/WhileStatement/spec.ts b/packages/ast-spec/src/statement/WhileStatement/spec.ts new file mode 100644 index 000000000000..1c9492c77140 --- /dev/null +++ b/packages/ast-spec/src/statement/WhileStatement/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { Statement } from '../../unions/Statement'; + +export interface WhileStatement extends BaseNode { + type: AST_NODE_TYPES.WhileStatement; + test: Expression; + body: Statement; +} diff --git a/packages/ast-spec/src/statement/WithStatement/spec.ts b/packages/ast-spec/src/statement/WithStatement/spec.ts new file mode 100644 index 000000000000..c661a5175b9a --- /dev/null +++ b/packages/ast-spec/src/statement/WithStatement/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Expression } from '../../unions/Expression'; +import type { Statement } from '../../unions/Statement'; + +export interface WithStatement extends BaseNode { + type: AST_NODE_TYPES.WithStatement; + object: Expression; + body: Statement; +} diff --git a/packages/ast-spec/src/statement/spec.ts b/packages/ast-spec/src/statement/spec.ts new file mode 100644 index 000000000000..4c967f828a45 --- /dev/null +++ b/packages/ast-spec/src/statement/spec.ts @@ -0,0 +1,32 @@ +export * from './BlockStatement/spec'; +export * from './BreakStatement/spec'; +export * from './ClassDeclaration/spec'; +export * from './ContinueStatement/spec'; +export * from './DebuggerStatement/spec'; +export * from './DoWhileStatement/spec'; +export * from './ExportAllDeclaration/spec'; +export * from './ExportDefaultDeclaration/spec'; +export * from './ExportNamedDeclaration/spec'; +export * from './ExpressionStatement/spec'; +export * from './ForInStatement/spec'; +export * from './ForOfStatement/spec'; +export * from './ForStatement/spec'; +export * from './FunctionDeclaration/spec'; +export * from './IfStatement/spec'; +export * from './ImportDeclaration/spec'; +export * from './LabeledStatement/spec'; +export * from './ReturnStatement/spec'; +export * from './SwitchStatement/spec'; +export * from './TSDeclareFunction/spec'; +export * from './TSEnumDeclaration/spec'; +export * from './TSExportAssignment/spec'; +export * from './TSImportEqualsDeclaration/spec'; +export * from './TSInterfaceDeclaration/spec'; +export * from './TSModuleDeclaration/spec'; +export * from './TSNamespaceExportDeclaration/spec'; +export * from './TSTypeAliasDeclaration/spec'; +export * from './ThrowStatement/spec'; +export * from './TryStatement/spec'; +export * from './VariableDeclaration/spec'; +export * from './WhileStatement/spec'; +export * from './WithStatement/spec'; diff --git a/packages/ast-spec/src/token/BlockComment/spec.ts b/packages/ast-spec/src/token/BlockComment/spec.ts new file mode 100644 index 000000000000..c2c7db298a4f --- /dev/null +++ b/packages/ast-spec/src/token/BlockComment/spec.ts @@ -0,0 +1,6 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface BlockComment extends BaseToken { + type: AST_TOKEN_TYPES.Block; +} diff --git a/packages/ast-spec/src/token/BooleanToken/spec.ts b/packages/ast-spec/src/token/BooleanToken/spec.ts new file mode 100644 index 000000000000..eeace18c8cd9 --- /dev/null +++ b/packages/ast-spec/src/token/BooleanToken/spec.ts @@ -0,0 +1,6 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface BooleanToken extends BaseToken { + type: AST_TOKEN_TYPES.Boolean; +} diff --git a/packages/ast-spec/src/token/IdentifierToken/spec.ts b/packages/ast-spec/src/token/IdentifierToken/spec.ts new file mode 100644 index 000000000000..9df6e14c3c99 --- /dev/null +++ b/packages/ast-spec/src/token/IdentifierToken/spec.ts @@ -0,0 +1,6 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface IdentifierToken extends BaseToken { + type: AST_TOKEN_TYPES.Identifier; +} diff --git a/packages/ast-spec/src/token/JSXIdentifierToken/spec.ts b/packages/ast-spec/src/token/JSXIdentifierToken/spec.ts new file mode 100644 index 000000000000..858775073735 --- /dev/null +++ b/packages/ast-spec/src/token/JSXIdentifierToken/spec.ts @@ -0,0 +1,6 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface JSXIdentifierToken extends BaseToken { + type: AST_TOKEN_TYPES.JSXIdentifier; +} diff --git a/packages/ast-spec/src/token/JSXTextToken/spec.ts b/packages/ast-spec/src/token/JSXTextToken/spec.ts new file mode 100644 index 000000000000..6a8d3aa5d50d --- /dev/null +++ b/packages/ast-spec/src/token/JSXTextToken/spec.ts @@ -0,0 +1,6 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface JSXTextToken extends BaseToken { + type: AST_TOKEN_TYPES.JSXText; +} diff --git a/packages/ast-spec/src/token/KeywordToken/spec.ts b/packages/ast-spec/src/token/KeywordToken/spec.ts new file mode 100644 index 000000000000..b7e9c058f692 --- /dev/null +++ b/packages/ast-spec/src/token/KeywordToken/spec.ts @@ -0,0 +1,6 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface KeywordToken extends BaseToken { + type: AST_TOKEN_TYPES.Keyword; +} diff --git a/packages/ast-spec/src/token/LineComment/spec.ts b/packages/ast-spec/src/token/LineComment/spec.ts new file mode 100644 index 000000000000..82db26f07442 --- /dev/null +++ b/packages/ast-spec/src/token/LineComment/spec.ts @@ -0,0 +1,6 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface LineComment extends BaseToken { + type: AST_TOKEN_TYPES.Line; +} diff --git a/packages/ast-spec/src/token/NullToken/spec.ts b/packages/ast-spec/src/token/NullToken/spec.ts new file mode 100644 index 000000000000..d5ae492de83a --- /dev/null +++ b/packages/ast-spec/src/token/NullToken/spec.ts @@ -0,0 +1,6 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface NullToken extends BaseToken { + type: AST_TOKEN_TYPES.Null; +} diff --git a/packages/ast-spec/src/token/NumericToken/spec.ts b/packages/ast-spec/src/token/NumericToken/spec.ts new file mode 100644 index 000000000000..a00fd383df75 --- /dev/null +++ b/packages/ast-spec/src/token/NumericToken/spec.ts @@ -0,0 +1,6 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface NumericToken extends BaseToken { + type: AST_TOKEN_TYPES.Numeric; +} diff --git a/packages/ast-spec/src/token/PunctuatorToken/spec.ts b/packages/ast-spec/src/token/PunctuatorToken/spec.ts new file mode 100644 index 000000000000..39b9507348c2 --- /dev/null +++ b/packages/ast-spec/src/token/PunctuatorToken/spec.ts @@ -0,0 +1,6 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface PunctuatorToken extends BaseToken { + type: AST_TOKEN_TYPES.Punctuator; +} diff --git a/packages/ast-spec/src/token/RegularExpressionToken/spec.ts b/packages/ast-spec/src/token/RegularExpressionToken/spec.ts new file mode 100644 index 000000000000..7b0bb09d5262 --- /dev/null +++ b/packages/ast-spec/src/token/RegularExpressionToken/spec.ts @@ -0,0 +1,10 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface RegularExpressionToken extends BaseToken { + type: AST_TOKEN_TYPES.RegularExpression; + regex: { + pattern: string; + flags: string; + }; +} diff --git a/packages/ast-spec/src/token/StringToken/spec.ts b/packages/ast-spec/src/token/StringToken/spec.ts new file mode 100644 index 000000000000..6b6535c6208d --- /dev/null +++ b/packages/ast-spec/src/token/StringToken/spec.ts @@ -0,0 +1,6 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface StringToken extends BaseToken { + type: AST_TOKEN_TYPES.String; +} diff --git a/packages/ast-spec/src/token/TSAbstractKeyword/spec.ts b/packages/ast-spec/src/token/TSAbstractKeyword/spec.ts new file mode 100644 index 000000000000..d15a55443c57 --- /dev/null +++ b/packages/ast-spec/src/token/TSAbstractKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSAbstractKeyword extends BaseNode { + type: AST_NODE_TYPES.TSAbstractKeyword; +} diff --git a/packages/ast-spec/src/token/TSAsyncKeyword/spec.ts b/packages/ast-spec/src/token/TSAsyncKeyword/spec.ts new file mode 100644 index 000000000000..26baddf7ad64 --- /dev/null +++ b/packages/ast-spec/src/token/TSAsyncKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSAsyncKeyword extends BaseNode { + type: AST_NODE_TYPES.TSAsyncKeyword; +} diff --git a/packages/ast-spec/src/token/TSDeclareKeyword/spec.ts b/packages/ast-spec/src/token/TSDeclareKeyword/spec.ts new file mode 100644 index 000000000000..8b6e6606b3e8 --- /dev/null +++ b/packages/ast-spec/src/token/TSDeclareKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSDeclareKeyword extends BaseNode { + type: AST_NODE_TYPES.TSDeclareKeyword; +} diff --git a/packages/ast-spec/src/token/TSExportKeyword/spec.ts b/packages/ast-spec/src/token/TSExportKeyword/spec.ts new file mode 100644 index 000000000000..016664d11b03 --- /dev/null +++ b/packages/ast-spec/src/token/TSExportKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSExportKeyword extends BaseNode { + type: AST_NODE_TYPES.TSExportKeyword; +} diff --git a/packages/ast-spec/src/token/TSPrivateKeyword/spec.ts b/packages/ast-spec/src/token/TSPrivateKeyword/spec.ts new file mode 100644 index 000000000000..ae57db0a066c --- /dev/null +++ b/packages/ast-spec/src/token/TSPrivateKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSPrivateKeyword extends BaseNode { + type: AST_NODE_TYPES.TSPrivateKeyword; +} diff --git a/packages/ast-spec/src/token/TSProtectedKeyword/spec.ts b/packages/ast-spec/src/token/TSProtectedKeyword/spec.ts new file mode 100644 index 000000000000..815b28a1c2c1 --- /dev/null +++ b/packages/ast-spec/src/token/TSProtectedKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSProtectedKeyword extends BaseNode { + type: AST_NODE_TYPES.TSProtectedKeyword; +} diff --git a/packages/ast-spec/src/token/TSPublicKeyword/spec.ts b/packages/ast-spec/src/token/TSPublicKeyword/spec.ts new file mode 100644 index 000000000000..3409fc6d689a --- /dev/null +++ b/packages/ast-spec/src/token/TSPublicKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSPublicKeyword extends BaseNode { + type: AST_NODE_TYPES.TSPublicKeyword; +} diff --git a/packages/ast-spec/src/token/TSReadonlyKeyword/spec.ts b/packages/ast-spec/src/token/TSReadonlyKeyword/spec.ts new file mode 100644 index 000000000000..462849972785 --- /dev/null +++ b/packages/ast-spec/src/token/TSReadonlyKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSReadonlyKeyword extends BaseNode { + type: AST_NODE_TYPES.TSReadonlyKeyword; +} diff --git a/packages/ast-spec/src/token/TSStaticKeyword/spec.ts b/packages/ast-spec/src/token/TSStaticKeyword/spec.ts new file mode 100644 index 000000000000..1c2417eeb589 --- /dev/null +++ b/packages/ast-spec/src/token/TSStaticKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSStaticKeyword extends BaseNode { + type: AST_NODE_TYPES.TSStaticKeyword; +} diff --git a/packages/ast-spec/src/token/TemplateToken/spec.ts b/packages/ast-spec/src/token/TemplateToken/spec.ts new file mode 100644 index 000000000000..da64ef0b6e98 --- /dev/null +++ b/packages/ast-spec/src/token/TemplateToken/spec.ts @@ -0,0 +1,6 @@ +import type { AST_TOKEN_TYPES } from '../../ast-token-types'; +import type { BaseToken } from '../../base/BaseToken'; + +export interface TemplateToken extends BaseToken { + type: AST_TOKEN_TYPES.Template; +} diff --git a/packages/ast-spec/src/token/spec.ts b/packages/ast-spec/src/token/spec.ts new file mode 100644 index 000000000000..45df05189eb2 --- /dev/null +++ b/packages/ast-spec/src/token/spec.ts @@ -0,0 +1,22 @@ +export * from './BlockComment/spec'; +export * from './BooleanToken/spec'; +export * from './IdentifierToken/spec'; +export * from './JSXIdentifierToken/spec'; +export * from './JSXTextToken/spec'; +export * from './KeywordToken/spec'; +export * from './LineComment/spec'; +export * from './NullToken/spec'; +export * from './NumericToken/spec'; +export * from './PunctuatorToken/spec'; +export * from './RegularExpressionToken/spec'; +export * from './StringToken/spec'; +export * from './TSAbstractKeyword/spec'; +export * from './TSAsyncKeyword/spec'; +export * from './TSDeclareKeyword/spec'; +export * from './TSExportKeyword/spec'; +export * from './TSPrivateKeyword/spec'; +export * from './TSProtectedKeyword/spec'; +export * from './TSPublicKeyword/spec'; +export * from './TSReadonlyKeyword/spec'; +export * from './TSStaticKeyword/spec'; +export * from './TemplateToken/spec'; diff --git a/packages/ast-spec/src/type/TSAnyKeyword/spec.ts b/packages/ast-spec/src/type/TSAnyKeyword/spec.ts new file mode 100644 index 000000000000..a9e2ba977f1d --- /dev/null +++ b/packages/ast-spec/src/type/TSAnyKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSAnyKeyword extends BaseNode { + type: AST_NODE_TYPES.TSAnyKeyword; +} diff --git a/packages/ast-spec/src/type/TSArrayType/spec.ts b/packages/ast-spec/src/type/TSArrayType/spec.ts new file mode 100644 index 000000000000..f7aa4f16a596 --- /dev/null +++ b/packages/ast-spec/src/type/TSArrayType/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSArrayType extends BaseNode { + type: AST_NODE_TYPES.TSArrayType; + elementType: TypeNode; +} diff --git a/packages/ast-spec/src/type/TSBigIntKeyword/spec.ts b/packages/ast-spec/src/type/TSBigIntKeyword/spec.ts new file mode 100644 index 000000000000..fc18a9519dee --- /dev/null +++ b/packages/ast-spec/src/type/TSBigIntKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSBigIntKeyword extends BaseNode { + type: AST_NODE_TYPES.TSBigIntKeyword; +} diff --git a/packages/ast-spec/src/type/TSBooleanKeyword/spec.ts b/packages/ast-spec/src/type/TSBooleanKeyword/spec.ts new file mode 100644 index 000000000000..89438151de1f --- /dev/null +++ b/packages/ast-spec/src/type/TSBooleanKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSBooleanKeyword extends BaseNode { + type: AST_NODE_TYPES.TSBooleanKeyword; +} diff --git a/packages/ast-spec/src/type/TSConditionalType/spec.ts b/packages/ast-spec/src/type/TSConditionalType/spec.ts new file mode 100644 index 000000000000..979fcb3e6026 --- /dev/null +++ b/packages/ast-spec/src/type/TSConditionalType/spec.ts @@ -0,0 +1,11 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSConditionalType extends BaseNode { + type: AST_NODE_TYPES.TSConditionalType; + checkType: TypeNode; + extendsType: TypeNode; + trueType: TypeNode; + falseType: TypeNode; +} diff --git a/packages/ast-spec/src/type/TSConstructorType/spec.ts b/packages/ast-spec/src/type/TSConstructorType/spec.ts new file mode 100644 index 000000000000..6fa013938064 --- /dev/null +++ b/packages/ast-spec/src/type/TSConstructorType/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { TSFunctionSignatureBase } from '../../base/TSFunctionSignatureBase'; + +export interface TSConstructorType extends TSFunctionSignatureBase { + type: AST_NODE_TYPES.TSConstructorType; +} diff --git a/packages/ast-spec/src/type/TSFunctionType/spec.ts b/packages/ast-spec/src/type/TSFunctionType/spec.ts new file mode 100644 index 000000000000..4388b097efd5 --- /dev/null +++ b/packages/ast-spec/src/type/TSFunctionType/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { TSFunctionSignatureBase } from '../../base/TSFunctionSignatureBase'; + +export interface TSFunctionType extends TSFunctionSignatureBase { + type: AST_NODE_TYPES.TSFunctionType; +} diff --git a/packages/ast-spec/src/type/TSImportType/spec.ts b/packages/ast-spec/src/type/TSImportType/spec.ts new file mode 100644 index 000000000000..b2eea1a78e01 --- /dev/null +++ b/packages/ast-spec/src/type/TSImportType/spec.ts @@ -0,0 +1,13 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeParameterInstantiation } from '../../special/TSTypeParameterInstantiation/spec'; +import type { EntityName } from '../../unions/EntityName'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSImportType extends BaseNode { + type: AST_NODE_TYPES.TSImportType; + isTypeOf: boolean; + parameter: TypeNode; + qualifier: EntityName | null; + typeParameters: TSTypeParameterInstantiation | null; +} diff --git a/packages/ast-spec/src/type/TSIndexedAccessType/spec.ts b/packages/ast-spec/src/type/TSIndexedAccessType/spec.ts new file mode 100644 index 000000000000..86a22e22a16e --- /dev/null +++ b/packages/ast-spec/src/type/TSIndexedAccessType/spec.ts @@ -0,0 +1,9 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSIndexedAccessType extends BaseNode { + type: AST_NODE_TYPES.TSIndexedAccessType; + objectType: TypeNode; + indexType: TypeNode; +} diff --git a/packages/ast-spec/src/type/TSInferType/spec.ts b/packages/ast-spec/src/type/TSInferType/spec.ts new file mode 100644 index 000000000000..11cdacb25d20 --- /dev/null +++ b/packages/ast-spec/src/type/TSInferType/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeParameter } from '../../special/TSTypeParameter/spec'; + +export interface TSInferType extends BaseNode { + type: AST_NODE_TYPES.TSInferType; + typeParameter: TSTypeParameter; +} diff --git a/packages/ast-spec/src/type/TSIntersectionType/spec.ts b/packages/ast-spec/src/type/TSIntersectionType/spec.ts new file mode 100644 index 000000000000..b84834143a0e --- /dev/null +++ b/packages/ast-spec/src/type/TSIntersectionType/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSIntersectionType extends BaseNode { + type: AST_NODE_TYPES.TSIntersectionType; + types: TypeNode[]; +} diff --git a/packages/ast-spec/src/type/TSLiteralType/spec.ts b/packages/ast-spec/src/type/TSLiteralType/spec.ts new file mode 100644 index 000000000000..39f6ae0d2961 --- /dev/null +++ b/packages/ast-spec/src/type/TSLiteralType/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { UnaryExpression } from '../../expression/UnaryExpression/spec'; +import type { UpdateExpression } from '../../expression/UpdateExpression/spec'; +import type { LiteralExpression } from '../../unions/LiteralExpression'; + +export interface TSLiteralType extends BaseNode { + type: AST_NODE_TYPES.TSLiteralType; + literal: LiteralExpression | UnaryExpression | UpdateExpression; +} diff --git a/packages/ast-spec/src/type/TSMappedType/spec.ts b/packages/ast-spec/src/type/TSMappedType/spec.ts new file mode 100644 index 000000000000..db5abd4063a1 --- /dev/null +++ b/packages/ast-spec/src/type/TSMappedType/spec.ts @@ -0,0 +1,13 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeParameter } from '../../special/TSTypeParameter/spec'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSMappedType extends BaseNode { + type: AST_NODE_TYPES.TSMappedType; + typeParameter: TSTypeParameter; + readonly?: boolean | '-' | '+'; + optional?: boolean | '-' | '+'; + typeAnnotation?: TypeNode; + nameType: TypeNode | null; +} diff --git a/packages/ast-spec/src/type/TSNamedTupleMember/spec.ts b/packages/ast-spec/src/type/TSNamedTupleMember/spec.ts new file mode 100644 index 000000000000..540d8bf19db5 --- /dev/null +++ b/packages/ast-spec/src/type/TSNamedTupleMember/spec.ts @@ -0,0 +1,11 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSNamedTupleMember extends BaseNode { + type: AST_NODE_TYPES.TSNamedTupleMember; + elementType: TypeNode; + label: Identifier; + optional: boolean; +} diff --git a/packages/ast-spec/src/type/TSNeverKeyword/spec.ts b/packages/ast-spec/src/type/TSNeverKeyword/spec.ts new file mode 100644 index 000000000000..59fe839e3473 --- /dev/null +++ b/packages/ast-spec/src/type/TSNeverKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSNeverKeyword extends BaseNode { + type: AST_NODE_TYPES.TSNeverKeyword; +} diff --git a/packages/ast-spec/src/type/TSNullKeyword/spec.ts b/packages/ast-spec/src/type/TSNullKeyword/spec.ts new file mode 100644 index 000000000000..254d5cc592d5 --- /dev/null +++ b/packages/ast-spec/src/type/TSNullKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSNullKeyword extends BaseNode { + type: AST_NODE_TYPES.TSNullKeyword; +} diff --git a/packages/ast-spec/src/type/TSNumberKeyword/spec.ts b/packages/ast-spec/src/type/TSNumberKeyword/spec.ts new file mode 100644 index 000000000000..768742a425dc --- /dev/null +++ b/packages/ast-spec/src/type/TSNumberKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSNumberKeyword extends BaseNode { + type: AST_NODE_TYPES.TSNumberKeyword; +} diff --git a/packages/ast-spec/src/type/TSObjectKeyword/spec.ts b/packages/ast-spec/src/type/TSObjectKeyword/spec.ts new file mode 100644 index 000000000000..3472bc9191ff --- /dev/null +++ b/packages/ast-spec/src/type/TSObjectKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSObjectKeyword extends BaseNode { + type: AST_NODE_TYPES.TSObjectKeyword; +} diff --git a/packages/ast-spec/src/type/TSOptionalType/spec.ts b/packages/ast-spec/src/type/TSOptionalType/spec.ts new file mode 100644 index 000000000000..9cdb0f636d32 --- /dev/null +++ b/packages/ast-spec/src/type/TSOptionalType/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSOptionalType extends BaseNode { + type: AST_NODE_TYPES.TSOptionalType; + typeAnnotation: TypeNode; +} diff --git a/packages/ast-spec/src/type/TSParenthesizedType/spec.ts b/packages/ast-spec/src/type/TSParenthesizedType/spec.ts new file mode 100644 index 000000000000..2d20d5d2f2bc --- /dev/null +++ b/packages/ast-spec/src/type/TSParenthesizedType/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSParenthesizedType extends BaseNode { + type: AST_NODE_TYPES.TSParenthesizedType; + typeAnnotation: TypeNode; +} diff --git a/packages/ast-spec/src/type/TSQualifiedName/spec.ts b/packages/ast-spec/src/type/TSQualifiedName/spec.ts new file mode 100644 index 000000000000..cdd6feeee0ef --- /dev/null +++ b/packages/ast-spec/src/type/TSQualifiedName/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; +import type { EntityName } from '../../unions/EntityName'; + +export interface TSQualifiedName extends BaseNode { + type: AST_NODE_TYPES.TSQualifiedName; + left: EntityName; + right: Identifier; +} diff --git a/packages/ast-spec/src/type/TSRestType/spec.ts b/packages/ast-spec/src/type/TSRestType/spec.ts new file mode 100644 index 000000000000..f1b4f2ecfa85 --- /dev/null +++ b/packages/ast-spec/src/type/TSRestType/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSRestType extends BaseNode { + type: AST_NODE_TYPES.TSRestType; + typeAnnotation: TypeNode; +} diff --git a/packages/ast-spec/src/type/TSStringKeyword/spec.ts b/packages/ast-spec/src/type/TSStringKeyword/spec.ts new file mode 100644 index 000000000000..35721dd44137 --- /dev/null +++ b/packages/ast-spec/src/type/TSStringKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSStringKeyword extends BaseNode { + type: AST_NODE_TYPES.TSStringKeyword; +} diff --git a/packages/ast-spec/src/type/TSSymbolKeyword/spec.ts b/packages/ast-spec/src/type/TSSymbolKeyword/spec.ts new file mode 100644 index 000000000000..6b8b949dd0b8 --- /dev/null +++ b/packages/ast-spec/src/type/TSSymbolKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSSymbolKeyword extends BaseNode { + type: AST_NODE_TYPES.TSSymbolKeyword; +} diff --git a/packages/ast-spec/src/type/TSTemplateLiteralType/spec.ts b/packages/ast-spec/src/type/TSTemplateLiteralType/spec.ts new file mode 100644 index 000000000000..c2e8783da873 --- /dev/null +++ b/packages/ast-spec/src/type/TSTemplateLiteralType/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TemplateElement } from '../../special/TemplateElement/spec'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSTemplateLiteralType extends BaseNode { + type: AST_NODE_TYPES.TSTemplateLiteralType; + quasis: TemplateElement[]; + types: TypeNode[]; +} diff --git a/packages/ast-spec/src/type/TSThisType/spec.ts b/packages/ast-spec/src/type/TSThisType/spec.ts new file mode 100644 index 000000000000..319e82460f67 --- /dev/null +++ b/packages/ast-spec/src/type/TSThisType/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSThisType extends BaseNode { + type: AST_NODE_TYPES.TSThisType; +} diff --git a/packages/ast-spec/src/type/TSTupleType/spec.ts b/packages/ast-spec/src/type/TSTupleType/spec.ts new file mode 100644 index 000000000000..641a0c15b4c6 --- /dev/null +++ b/packages/ast-spec/src/type/TSTupleType/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSTupleType extends BaseNode { + type: AST_NODE_TYPES.TSTupleType; + elementTypes: TypeNode[]; +} diff --git a/packages/ast-spec/src/type/TSTypeLiteral/spec.ts b/packages/ast-spec/src/type/TSTypeLiteral/spec.ts new file mode 100644 index 000000000000..243179d23d9f --- /dev/null +++ b/packages/ast-spec/src/type/TSTypeLiteral/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeElement } from '../../unions/TypeElement'; + +export interface TSTypeLiteral extends BaseNode { + type: AST_NODE_TYPES.TSTypeLiteral; + members: TypeElement[]; +} diff --git a/packages/ast-spec/src/type/TSTypeOperator/spec.ts b/packages/ast-spec/src/type/TSTypeOperator/spec.ts new file mode 100644 index 000000000000..c83b8721eed9 --- /dev/null +++ b/packages/ast-spec/src/type/TSTypeOperator/spec.ts @@ -0,0 +1,9 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSTypeOperator extends BaseNode { + type: AST_NODE_TYPES.TSTypeOperator; + operator: 'keyof' | 'readonly' | 'unique'; + typeAnnotation?: TypeNode; +} diff --git a/packages/ast-spec/src/type/TSTypePredicate/spec.ts b/packages/ast-spec/src/type/TSTypePredicate/spec.ts new file mode 100644 index 000000000000..cd34a31bcaf0 --- /dev/null +++ b/packages/ast-spec/src/type/TSTypePredicate/spec.ts @@ -0,0 +1,12 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Identifier } from '../../expression/Identifier/spec'; +import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; +import type { TSThisType } from '../TSThisType/spec'; + +export interface TSTypePredicate extends BaseNode { + type: AST_NODE_TYPES.TSTypePredicate; + asserts: boolean; + parameterName: Identifier | TSThisType; + typeAnnotation: TSTypeAnnotation | null; +} diff --git a/packages/ast-spec/src/type/TSTypeQuery/spec.ts b/packages/ast-spec/src/type/TSTypeQuery/spec.ts new file mode 100644 index 000000000000..bf1cd3e192df --- /dev/null +++ b/packages/ast-spec/src/type/TSTypeQuery/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { EntityName } from '../../unions/EntityName'; + +export interface TSTypeQuery extends BaseNode { + type: AST_NODE_TYPES.TSTypeQuery; + exprName: EntityName; +} diff --git a/packages/ast-spec/src/type/TSTypeReference/spec.ts b/packages/ast-spec/src/type/TSTypeReference/spec.ts new file mode 100644 index 000000000000..9d88fe7f6b4f --- /dev/null +++ b/packages/ast-spec/src/type/TSTypeReference/spec.ts @@ -0,0 +1,10 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeParameterInstantiation } from '../../special/TSTypeParameterInstantiation/spec'; +import type { EntityName } from '../../unions/EntityName'; + +export interface TSTypeReference extends BaseNode { + type: AST_NODE_TYPES.TSTypeReference; + typeName: EntityName; + typeParameters?: TSTypeParameterInstantiation; +} diff --git a/packages/ast-spec/src/type/TSUndefinedKeyword/spec.ts b/packages/ast-spec/src/type/TSUndefinedKeyword/spec.ts new file mode 100644 index 000000000000..0aa062c84212 --- /dev/null +++ b/packages/ast-spec/src/type/TSUndefinedKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSUndefinedKeyword extends BaseNode { + type: AST_NODE_TYPES.TSUndefinedKeyword; +} diff --git a/packages/ast-spec/src/type/TSUnionType/spec.ts b/packages/ast-spec/src/type/TSUnionType/spec.ts new file mode 100644 index 000000000000..a286f796a23d --- /dev/null +++ b/packages/ast-spec/src/type/TSUnionType/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { TypeNode } from '../../unions/TypeNode'; + +export interface TSUnionType extends BaseNode { + type: AST_NODE_TYPES.TSUnionType; + types: TypeNode[]; +} diff --git a/packages/ast-spec/src/type/TSUnknownKeyword/spec.ts b/packages/ast-spec/src/type/TSUnknownKeyword/spec.ts new file mode 100644 index 000000000000..c8c1f9340c6e --- /dev/null +++ b/packages/ast-spec/src/type/TSUnknownKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSUnknownKeyword extends BaseNode { + type: AST_NODE_TYPES.TSUnknownKeyword; +} diff --git a/packages/ast-spec/src/type/TSVoidKeyword/spec.ts b/packages/ast-spec/src/type/TSVoidKeyword/spec.ts new file mode 100644 index 000000000000..abf0c14c5ab3 --- /dev/null +++ b/packages/ast-spec/src/type/TSVoidKeyword/spec.ts @@ -0,0 +1,6 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface TSVoidKeyword extends BaseNode { + type: AST_NODE_TYPES.TSVoidKeyword; +} diff --git a/packages/ast-spec/src/type/spec.ts b/packages/ast-spec/src/type/spec.ts new file mode 100644 index 000000000000..bbbea76cbd8e --- /dev/null +++ b/packages/ast-spec/src/type/spec.ts @@ -0,0 +1,36 @@ +export * from './TSAnyKeyword/spec'; +export * from './TSArrayType/spec'; +export * from './TSBigIntKeyword/spec'; +export * from './TSBooleanKeyword/spec'; +export * from './TSConditionalType/spec'; +export * from './TSConstructorType/spec'; +export * from './TSFunctionType/spec'; +export * from './TSImportType/spec'; +export * from './TSIndexedAccessType/spec'; +export * from './TSInferType/spec'; +export * from './TSIntersectionType/spec'; +export * from './TSLiteralType/spec'; +export * from './TSMappedType/spec'; +export * from './TSNamedTupleMember/spec'; +export * from './TSNeverKeyword/spec'; +export * from './TSNullKeyword/spec'; +export * from './TSNumberKeyword/spec'; +export * from './TSObjectKeyword/spec'; +export * from './TSOptionalType/spec'; +export * from './TSParenthesizedType/spec'; +export * from './TSQualifiedName/spec'; +export * from './TSRestType/spec'; +export * from './TSStringKeyword/spec'; +export * from './TSSymbolKeyword/spec'; +export * from './TSTemplateLiteralType/spec'; +export * from './TSThisType/spec'; +export * from './TSTupleType/spec'; +export * from './TSTypeLiteral/spec'; +export * from './TSTypeOperator/spec'; +export * from './TSTypePredicate/spec'; +export * from './TSTypeQuery/spec'; +export * from './TSTypeReference/spec'; +export * from './TSUndefinedKeyword/spec'; +export * from './TSUnionType/spec'; +export * from './TSUnknownKeyword/spec'; +export * from './TSVoidKeyword/spec'; diff --git a/packages/ast-spec/src/unions/BindingName.ts b/packages/ast-spec/src/unions/BindingName.ts new file mode 100644 index 000000000000..2da273d80476 --- /dev/null +++ b/packages/ast-spec/src/unions/BindingName.ts @@ -0,0 +1,4 @@ +import type { Identifier } from '../expression/Identifier/spec'; +import type { BindingPattern } from './BindingPattern'; + +export type BindingName = BindingPattern | Identifier; diff --git a/packages/ast-spec/src/unions/BindingPattern.ts b/packages/ast-spec/src/unions/BindingPattern.ts new file mode 100644 index 000000000000..ef39d0af1126 --- /dev/null +++ b/packages/ast-spec/src/unions/BindingPattern.ts @@ -0,0 +1,4 @@ +import type { ArrayPattern } from '../parameter/ArrayPattern/spec'; +import type { ObjectPattern } from '../parameter/ObjectPattern/spec'; + +export type BindingPattern = ArrayPattern | ObjectPattern; diff --git a/packages/ast-spec/src/unions/ChainElement.ts b/packages/ast-spec/src/unions/ChainElement.ts new file mode 100644 index 000000000000..fccde99ed8c6 --- /dev/null +++ b/packages/ast-spec/src/unions/ChainElement.ts @@ -0,0 +1,8 @@ +import type { CallExpression } from '../expression/CallExpression/spec'; +import type { MemberExpression } from '../expression/MemberExpression/spec'; +import type { TSNonNullExpression } from '../expression/TSNonNullExpression/spec'; + +export type ChainElement = + | CallExpression + | MemberExpression + | TSNonNullExpression; diff --git a/packages/ast-spec/src/unions/ClassElement.ts b/packages/ast-spec/src/unions/ClassElement.ts new file mode 100644 index 000000000000..a4d986d09c73 --- /dev/null +++ b/packages/ast-spec/src/unions/ClassElement.ts @@ -0,0 +1,12 @@ +import type { ClassProperty } from '../element/ClassProperty/spec'; +import type { MethodDefinition } from '../element/MethodDefinition/spec'; +import type { TSAbstractClassProperty } from '../element/TSAbstractClassProperty/spec'; +import type { TSAbstractMethodDefinition } from '../element/TSAbstractMethodDefinition/spec'; +import type { TSIndexSignature } from '../element/TSIndexSignature/spec'; + +export type ClassElement = + | ClassProperty + | MethodDefinition + | TSAbstractClassProperty + | TSAbstractMethodDefinition + | TSIndexSignature; diff --git a/packages/ast-spec/src/unions/Comment.ts b/packages/ast-spec/src/unions/Comment.ts new file mode 100644 index 000000000000..d5cdca042476 --- /dev/null +++ b/packages/ast-spec/src/unions/Comment.ts @@ -0,0 +1,4 @@ +import type { BlockComment } from '../token/BlockComment/spec'; +import type { LineComment } from '../token/LineComment/spec'; + +export type Comment = BlockComment | LineComment; diff --git a/packages/ast-spec/src/unions/DeclarationStatement.ts b/packages/ast-spec/src/unions/DeclarationStatement.ts new file mode 100644 index 000000000000..3899075ec6eb --- /dev/null +++ b/packages/ast-spec/src/unions/DeclarationStatement.ts @@ -0,0 +1,29 @@ +import type { ClassExpression } from '../expression/ClassExpression/spec'; +import type { ClassDeclaration } from '../statement/ClassDeclaration/spec'; +import type { ExportAllDeclaration } from '../statement/ExportAllDeclaration/spec'; +import type { ExportDefaultDeclaration } from '../statement/ExportDefaultDeclaration/spec'; +import type { ExportNamedDeclaration } from '../statement/ExportNamedDeclaration/spec'; +import type { FunctionDeclaration } from '../statement/FunctionDeclaration/spec'; +import type { TSDeclareFunction } from '../statement/TSDeclareFunction/spec'; +import type { TSEnumDeclaration } from '../statement/TSEnumDeclaration/spec'; +import type { TSImportEqualsDeclaration } from '../statement/TSImportEqualsDeclaration/spec'; +import type { TSInterfaceDeclaration } from '../statement/TSInterfaceDeclaration/spec'; +import type { TSModuleDeclaration } from '../statement/TSModuleDeclaration/spec'; +import type { TSNamespaceExportDeclaration } from '../statement/TSNamespaceExportDeclaration/spec'; +import type { TSTypeAliasDeclaration } from '../statement/TSTypeAliasDeclaration/spec'; + +// TODO - breaking change remove this +export type DeclarationStatement = + | ClassDeclaration + | ClassExpression + | ExportAllDeclaration + | ExportDefaultDeclaration + | ExportNamedDeclaration + | FunctionDeclaration + | TSDeclareFunction + | TSEnumDeclaration + | TSImportEqualsDeclaration + | TSInterfaceDeclaration + | TSModuleDeclaration + | TSNamespaceExportDeclaration + | TSTypeAliasDeclaration; diff --git a/packages/ast-spec/src/unions/DestructuringPattern.ts b/packages/ast-spec/src/unions/DestructuringPattern.ts new file mode 100644 index 000000000000..40d07009651c --- /dev/null +++ b/packages/ast-spec/src/unions/DestructuringPattern.ts @@ -0,0 +1,14 @@ +import type { Identifier } from '../expression/Identifier/spec'; +import type { MemberExpression } from '../expression/MemberExpression/spec'; +import type { ArrayPattern } from '../parameter/ArrayPattern/spec'; +import type { AssignmentPattern } from '../parameter/AssignmentPattern/spec'; +import type { ObjectPattern } from '../parameter/ObjectPattern/spec'; +import type { RestElement } from '../parameter/RestElement/spec'; + +export type DestructuringPattern = + | ArrayPattern + | AssignmentPattern + | Identifier + | MemberExpression + | ObjectPattern + | RestElement; diff --git a/packages/ast-spec/src/unions/EntityName.ts b/packages/ast-spec/src/unions/EntityName.ts new file mode 100644 index 000000000000..82f7b1c9b0ca --- /dev/null +++ b/packages/ast-spec/src/unions/EntityName.ts @@ -0,0 +1,4 @@ +import type { Identifier } from '../expression/Identifier/spec'; +import type { TSQualifiedName } from '../type/TSQualifiedName/spec'; + +export type EntityName = Identifier | TSQualifiedName; diff --git a/packages/ast-spec/src/unions/ExportDeclaration.ts b/packages/ast-spec/src/unions/ExportDeclaration.ts new file mode 100644 index 000000000000..7ddfdd0ad508 --- /dev/null +++ b/packages/ast-spec/src/unions/ExportDeclaration.ts @@ -0,0 +1,20 @@ +import type { ClassExpression } from '../expression/ClassExpression/spec'; +import type { ClassDeclaration } from '../statement/ClassDeclaration/spec'; +import type { FunctionDeclaration } from '../statement/FunctionDeclaration/spec'; +import type { TSDeclareFunction } from '../statement/TSDeclareFunction/spec'; +import type { TSEnumDeclaration } from '../statement/TSEnumDeclaration/spec'; +import type { TSInterfaceDeclaration } from '../statement/TSInterfaceDeclaration/spec'; +import type { TSModuleDeclaration } from '../statement/TSModuleDeclaration/spec'; +import type { TSTypeAliasDeclaration } from '../statement/TSTypeAliasDeclaration/spec'; +import type { VariableDeclaration } from '../statement/VariableDeclaration/spec'; + +export type ExportDeclaration = + | ClassDeclaration + | ClassExpression + | FunctionDeclaration + | TSDeclareFunction + | TSEnumDeclaration + | TSInterfaceDeclaration + | TSModuleDeclaration + | TSTypeAliasDeclaration + | VariableDeclaration; diff --git a/packages/ast-spec/src/unions/Expression.ts b/packages/ast-spec/src/unions/Expression.ts new file mode 100644 index 000000000000..fd1a14b114e2 --- /dev/null +++ b/packages/ast-spec/src/unions/Expression.ts @@ -0,0 +1,78 @@ +import type { ArrayExpression } from '../expression/ArrayExpression/spec'; +import type { ArrowFunctionExpression } from '../expression/ArrowFunctionExpression/spec'; +import type { AssignmentExpression } from '../expression/AssignmentExpression/spec'; +import type { AwaitExpression } from '../expression/AwaitExpression/spec'; +import type { BinaryExpression } from '../expression/BinaryExpression/spec'; +import type { CallExpression } from '../expression/CallExpression/spec'; +import type { ChainExpression } from '../expression/ChainExpression/spec'; +import type { ClassExpression } from '../expression/ClassExpression/spec'; +import type { ConditionalExpression } from '../expression/ConditionalExpression/spec'; +import type { FunctionExpression } from '../expression/FunctionExpression/spec'; +import type { Identifier } from '../expression/Identifier/spec'; +import type { ImportExpression } from '../expression/ImportExpression/spec'; +import type { JSXElement } from '../expression/JSXElement/spec'; +import type { JSXFragment } from '../expression/JSXFragment/spec'; +import type { LogicalExpression } from '../expression/LogicalExpression/spec'; +import type { MemberExpression } from '../expression/MemberExpression/spec'; +import type { MetaProperty } from '../expression/MetaProperty/spec'; +import type { NewExpression } from '../expression/NewExpression/spec'; +import type { ObjectExpression } from '../expression/ObjectExpression/spec'; +import type { SequenceExpression } from '../expression/SequenceExpression/spec'; +import type { Super } from '../expression/Super/spec'; +import type { TaggedTemplateExpression } from '../expression/TaggedTemplateExpression/spec'; +import type { TemplateLiteral } from '../expression/TemplateLiteral/spec'; +import type { ThisExpression } from '../expression/ThisExpression/spec'; +import type { TSAsExpression } from '../expression/TSAsExpression/spec'; +import type { TSNonNullExpression } from '../expression/TSNonNullExpression/spec'; +import type { TSTypeAssertion } from '../expression/TSTypeAssertion/spec'; +import type { UnaryExpression } from '../expression/UnaryExpression/spec'; +import type { UpdateExpression } from '../expression/UpdateExpression/spec'; +import type { YieldExpression } from '../expression/YieldExpression/spec'; +import type { ArrayPattern } from '../parameter/ArrayPattern/spec'; +import type { ObjectPattern } from '../parameter/ObjectPattern/spec'; +import type { LiteralExpression } from './LiteralExpression'; + +/* +This isn't technically correct, as it includes ArrayPattern and ObjectPattern - which are only valid +in a LeftHandSideExpression, and not in a general expression location. + +However most of the time that this type is used, the intention will be to assign a LeftHandSideExpression to this type. +So excluding the Pattern types just makes it a pain, as people have to write Expression | LeftHandSideExpression everywhere. +*/ + +export type Expression = + | ArrayExpression + | ArrayPattern + | ArrowFunctionExpression + | AssignmentExpression + | AwaitExpression + | BinaryExpression + | CallExpression + | ChainExpression + | ClassExpression + | ClassExpression + | ConditionalExpression + | FunctionExpression + | FunctionExpression + | Identifier + | ImportExpression + | JSXElement + | JSXFragment + | LiteralExpression + | LogicalExpression + | MemberExpression + | MetaProperty + | NewExpression + | ObjectExpression + | ObjectPattern + | SequenceExpression + | Super + | TaggedTemplateExpression + | TemplateLiteral + | ThisExpression + | TSAsExpression + | TSNonNullExpression + | TSTypeAssertion + | UnaryExpression + | UpdateExpression + | YieldExpression; diff --git a/packages/ast-spec/src/unions/ForInitialiser.ts b/packages/ast-spec/src/unions/ForInitialiser.ts new file mode 100644 index 000000000000..ab5e0a5f59b9 --- /dev/null +++ b/packages/ast-spec/src/unions/ForInitialiser.ts @@ -0,0 +1,4 @@ +import type { VariableDeclaration } from '../statement/VariableDeclaration/spec'; +import type { Expression } from './Expression'; + +export type ForInitialiser = Expression | VariableDeclaration; diff --git a/packages/ast-spec/src/unions/FunctionLike.ts b/packages/ast-spec/src/unions/FunctionLike.ts new file mode 100644 index 000000000000..a9b49d292aaa --- /dev/null +++ b/packages/ast-spec/src/unions/FunctionLike.ts @@ -0,0 +1,12 @@ +import type { ArrowFunctionExpression } from '../expression/ArrowFunctionExpression/spec'; +import type { FunctionExpression } from '../expression/FunctionExpression/spec'; +import type { TSEmptyBodyFunctionExpression } from '../expression/TSEmptyBodyFunctionExpression/spec'; +import type { FunctionDeclaration } from '../statement/FunctionDeclaration/spec'; +import type { TSDeclareFunction } from '../statement/TSDeclareFunction/spec'; + +export type FunctionLike = + | ArrowFunctionExpression + | FunctionDeclaration + | FunctionExpression + | TSDeclareFunction + | TSEmptyBodyFunctionExpression; diff --git a/packages/ast-spec/src/unions/ImportClause.ts b/packages/ast-spec/src/unions/ImportClause.ts new file mode 100644 index 000000000000..80b40826ff6d --- /dev/null +++ b/packages/ast-spec/src/unions/ImportClause.ts @@ -0,0 +1,8 @@ +import type { ImportDefaultSpecifier } from '../special/ImportDefaultSpecifier/spec'; +import type { ImportNamespaceSpecifier } from '../special/ImportNamespaceSpecifier/spec'; +import type { ImportSpecifier } from '../special/ImportSpecifier/spec'; + +export type ImportClause = + | ImportDefaultSpecifier + | ImportNamespaceSpecifier + | ImportSpecifier; diff --git a/packages/ast-spec/src/unions/IterationStatement.ts b/packages/ast-spec/src/unions/IterationStatement.ts new file mode 100644 index 000000000000..6a611431ca05 --- /dev/null +++ b/packages/ast-spec/src/unions/IterationStatement.ts @@ -0,0 +1,12 @@ +import type { DoWhileStatement } from '../statement/DoWhileStatement/spec'; +import type { ForInStatement } from '../statement/ForInStatement/spec'; +import type { ForOfStatement } from '../statement/ForOfStatement/spec'; +import type { ForStatement } from '../statement/ForStatement/spec'; +import type { WhileStatement } from '../statement/WhileStatement/spec'; + +export type IterationStatement = + | DoWhileStatement + | ForInStatement + | ForOfStatement + | ForStatement + | WhileStatement; diff --git a/packages/ast-spec/src/unions/JSXChild.ts b/packages/ast-spec/src/unions/JSXChild.ts new file mode 100644 index 000000000000..3bec0fa37f5d --- /dev/null +++ b/packages/ast-spec/src/unions/JSXChild.ts @@ -0,0 +1,6 @@ +import type { JSXElement } from '../expression/JSXElement/spec'; +import type { JSXFragment } from '../expression/JSXFragment/spec'; +import type { JSXText } from '../special/JSXText/spec'; +import type { JSXExpression } from './JSXExpression'; + +export type JSXChild = JSXElement | JSXExpression | JSXFragment | JSXText; diff --git a/packages/ast-spec/src/unions/JSXExpression.ts b/packages/ast-spec/src/unions/JSXExpression.ts new file mode 100644 index 000000000000..f106a05e5c62 --- /dev/null +++ b/packages/ast-spec/src/unions/JSXExpression.ts @@ -0,0 +1,8 @@ +import type { JSXEmptyExpression } from '../special/JSXEmptyExpression/spec'; +import type { JSXExpressionContainer } from '../special/JSXExpressionContainer/spec'; +import type { JSXSpreadChild } from '../special/JSXSpreadChild/spec'; + +export type JSXExpression = + | JSXEmptyExpression + | JSXExpressionContainer + | JSXSpreadChild; diff --git a/packages/ast-spec/src/unions/JSXTagNameExpression.ts b/packages/ast-spec/src/unions/JSXTagNameExpression.ts new file mode 100644 index 000000000000..d0f9b3c2a50b --- /dev/null +++ b/packages/ast-spec/src/unions/JSXTagNameExpression.ts @@ -0,0 +1,4 @@ +import type { JSXIdentifier } from '../special/JSXIdentifier/spec'; +import type { JSXMemberExpression } from '../special/JSXMemberExpression/spec'; + +export type JSXTagNameExpression = JSXIdentifier | JSXMemberExpression; diff --git a/packages/ast-spec/src/unions/LeftHandSideExpression.ts b/packages/ast-spec/src/unions/LeftHandSideExpression.ts new file mode 100644 index 000000000000..a8a24bb08d2d --- /dev/null +++ b/packages/ast-spec/src/unions/LeftHandSideExpression.ts @@ -0,0 +1,44 @@ +import type { ArrayExpression } from '../expression/ArrayExpression/spec'; +import type { ArrowFunctionExpression } from '../expression/ArrowFunctionExpression/spec'; +import type { CallExpression } from '../expression/CallExpression/spec'; +import type { ClassExpression } from '../expression/ClassExpression/spec'; +import type { FunctionExpression } from '../expression/FunctionExpression/spec'; +import type { Identifier } from '../expression/Identifier/spec'; +import type { JSXElement } from '../expression/JSXElement/spec'; +import type { JSXFragment } from '../expression/JSXFragment/spec'; +import type { MemberExpression } from '../expression/MemberExpression/spec'; +import type { MetaProperty } from '../expression/MetaProperty/spec'; +import type { ObjectExpression } from '../expression/ObjectExpression/spec'; +import type { Super } from '../expression/Super/spec'; +import type { TaggedTemplateExpression } from '../expression/TaggedTemplateExpression/spec'; +import type { TemplateLiteral } from '../expression/TemplateLiteral/spec'; +import type { ThisExpression } from '../expression/ThisExpression/spec'; +import type { TSAsExpression } from '../expression/TSAsExpression/spec'; +import type { TSNonNullExpression } from '../expression/TSNonNullExpression/spec'; +import type { TSTypeAssertion } from '../expression/TSTypeAssertion/spec'; +import type { ArrayPattern } from '../parameter/ArrayPattern/spec'; +import type { ObjectPattern } from '../parameter/ObjectPattern/spec'; +import type { LiteralExpression } from './LiteralExpression'; + +export type LeftHandSideExpression = + | ArrayExpression + | ArrayPattern + | ArrowFunctionExpression + | CallExpression + | ClassExpression + | FunctionExpression + | Identifier + | JSXElement + | JSXFragment + | LiteralExpression + | MemberExpression + | MetaProperty + | ObjectExpression + | ObjectPattern + | Super + | TaggedTemplateExpression + | TemplateLiteral + | ThisExpression + | TSAsExpression + | TSNonNullExpression + | TSTypeAssertion; diff --git a/packages/ast-spec/src/unions/Literal.ts b/packages/ast-spec/src/unions/Literal.ts new file mode 100644 index 000000000000..4da361d88423 --- /dev/null +++ b/packages/ast-spec/src/unions/Literal.ts @@ -0,0 +1,14 @@ +import type { BigIntLiteral } from '../expression/literal/BigIntLiteral/spec'; +import type { BooleanLiteral } from '../expression/literal/BooleanLiteral/spec'; +import type { NullLiteral } from '../expression/literal/NullLiteral/spec'; +import type { NumberLiteral } from '../expression/literal/NumberLiteral/spec'; +import type { RegExpLiteral } from '../expression/literal/RegExpLiteral/spec'; +import type { StringLiteral } from '../expression/literal/StringLiteral/spec'; + +export type Literal = + | BigIntLiteral + | BooleanLiteral + | NullLiteral + | NumberLiteral + | RegExpLiteral + | StringLiteral; diff --git a/packages/ast-spec/src/unions/LiteralExpression.ts b/packages/ast-spec/src/unions/LiteralExpression.ts new file mode 100644 index 000000000000..e29ddeec7ee5 --- /dev/null +++ b/packages/ast-spec/src/unions/LiteralExpression.ts @@ -0,0 +1,4 @@ +import type { TemplateLiteral } from '../expression/TemplateLiteral/spec'; +import type { Literal } from './Literal'; + +export type LiteralExpression = Literal | TemplateLiteral; diff --git a/packages/ast-spec/src/unions/Modifier.ts b/packages/ast-spec/src/unions/Modifier.ts new file mode 100644 index 000000000000..bb5ddfb429b4 --- /dev/null +++ b/packages/ast-spec/src/unions/Modifier.ts @@ -0,0 +1,20 @@ +import type { TSAbstractKeyword } from '../token/TSAbstractKeyword/spec'; +import type { TSAsyncKeyword } from '../token/TSAsyncKeyword/spec'; +import type { TSDeclareKeyword } from '../token/TSDeclareKeyword/spec'; +import type { TSExportKeyword } from '../token/TSExportKeyword/spec'; +import type { TSPrivateKeyword } from '../token/TSPrivateKeyword/spec'; +import type { TSProtectedKeyword } from '../token/TSProtectedKeyword/spec'; +import type { TSPublicKeyword } from '../token/TSPublicKeyword/spec'; +import type { TSReadonlyKeyword } from '../token/TSReadonlyKeyword/spec'; +import type { TSStaticKeyword } from '../token/TSStaticKeyword/spec'; + +export type Modifier = + | TSAbstractKeyword + | TSAsyncKeyword + | TSDeclareKeyword + | TSExportKeyword + | TSPrivateKeyword + | TSProtectedKeyword + | TSPublicKeyword + | TSReadonlyKeyword + | TSStaticKeyword; diff --git a/packages/ast-spec/src/unions/Node.ts b/packages/ast-spec/src/unions/Node.ts new file mode 100644 index 000000000000..dd7382a1994a --- /dev/null +++ b/packages/ast-spec/src/unions/Node.ts @@ -0,0 +1,325 @@ +import type { ClassProperty } from '../element/ClassProperty/spec'; +import type { MethodDefinition } from '../element/MethodDefinition/spec'; +import type { Property } from '../element/Property/spec'; +import type { SpreadElement } from '../element/SpreadElement/spec'; +import type { TSAbstractClassProperty } from '../element/TSAbstractClassProperty/spec'; +import type { TSAbstractMethodDefinition } from '../element/TSAbstractMethodDefinition/spec'; +import type { TSCallSignatureDeclaration } from '../element/TSCallSignatureDeclaration/spec'; +import type { TSConstructSignatureDeclaration } from '../element/TSConstructSignatureDeclaration/spec'; +import type { TSEnumMember } from '../element/TSEnumMember/spec'; +import type { TSIndexSignature } from '../element/TSIndexSignature/spec'; +import type { TSMethodSignature } from '../element/TSMethodSignature/spec'; +import type { TSPropertySignature } from '../element/TSPropertySignature/spec'; +import type { ArrayExpression } from '../expression/ArrayExpression/spec'; +import type { ArrowFunctionExpression } from '../expression/ArrowFunctionExpression/spec'; +import type { AssignmentExpression } from '../expression/AssignmentExpression/spec'; +import type { AwaitExpression } from '../expression/AwaitExpression/spec'; +import type { BinaryExpression } from '../expression/BinaryExpression/spec'; +import type { CallExpression } from '../expression/CallExpression/spec'; +import type { ChainExpression } from '../expression/ChainExpression/spec'; +import type { ClassExpression } from '../expression/ClassExpression/spec'; +import type { ConditionalExpression } from '../expression/ConditionalExpression/spec'; +import type { FunctionExpression } from '../expression/FunctionExpression/spec'; +import type { Identifier } from '../expression/Identifier/spec'; +import type { ImportExpression } from '../expression/ImportExpression/spec'; +import type { JSXElement } from '../expression/JSXElement/spec'; +import type { JSXFragment } from '../expression/JSXFragment/spec'; +import type { LogicalExpression } from '../expression/LogicalExpression/spec'; +import type { MemberExpression } from '../expression/MemberExpression/spec'; +import type { MetaProperty } from '../expression/MetaProperty/spec'; +import type { NewExpression } from '../expression/NewExpression/spec'; +import type { ObjectExpression } from '../expression/ObjectExpression/spec'; +import type { SequenceExpression } from '../expression/SequenceExpression/spec'; +import type { Super } from '../expression/Super/spec'; +import type { TaggedTemplateExpression } from '../expression/TaggedTemplateExpression/spec'; +import type { TemplateLiteral } from '../expression/TemplateLiteral/spec'; +import type { ThisExpression } from '../expression/ThisExpression/spec'; +import type { TSAsExpression } from '../expression/TSAsExpression/spec'; +import type { TSEmptyBodyFunctionExpression } from '../expression/TSEmptyBodyFunctionExpression/spec'; +import type { TSNonNullExpression } from '../expression/TSNonNullExpression/spec'; +import type { TSTypeAssertion } from '../expression/TSTypeAssertion/spec'; +import type { UnaryExpression } from '../expression/UnaryExpression/spec'; +import type { UpdateExpression } from '../expression/UpdateExpression/spec'; +import type { YieldExpression } from '../expression/YieldExpression/spec'; +import type { ArrayPattern } from '../parameter/ArrayPattern/spec'; +import type { AssignmentPattern } from '../parameter/AssignmentPattern/spec'; +import type { ObjectPattern } from '../parameter/ObjectPattern/spec'; +import type { RestElement } from '../parameter/RestElement/spec'; +import type { TSParameterProperty } from '../parameter/TSParameterProperty/spec'; +import type { CatchClause } from '../special/CatchClause/spec'; +import type { ClassBody } from '../special/ClassBody/spec'; +import type { Decorator } from '../special/Decorator/spec'; +import type { EmptyStatement } from '../special/EmptyStatement/spec'; +import type { ExportSpecifier } from '../special/ExportSpecifier/spec'; +import type { ImportDefaultSpecifier } from '../special/ImportDefaultSpecifier/spec'; +import type { ImportNamespaceSpecifier } from '../special/ImportNamespaceSpecifier/spec'; +import type { ImportSpecifier } from '../special/ImportSpecifier/spec'; +import type { JSXAttribute } from '../special/JSXAttribute/spec'; +import type { JSXClosingElement } from '../special/JSXClosingElement/spec'; +import type { JSXClosingFragment } from '../special/JSXClosingFragment/spec'; +import type { JSXEmptyExpression } from '../special/JSXEmptyExpression/spec'; +import type { JSXExpressionContainer } from '../special/JSXExpressionContainer/spec'; +import type { JSXIdentifier } from '../special/JSXIdentifier/spec'; +import type { JSXMemberExpression } from '../special/JSXMemberExpression/spec'; +import type { JSXOpeningElement } from '../special/JSXOpeningElement/spec'; +import type { JSXOpeningFragment } from '../special/JSXOpeningFragment/spec'; +import type { JSXSpreadAttribute } from '../special/JSXSpreadAttribute/spec'; +import type { JSXSpreadChild } from '../special/JSXSpreadChild/spec'; +import type { JSXText } from '../special/JSXText/spec'; +import type { Program } from '../special/Program/spec'; +import type { SwitchCase } from '../special/SwitchCase/spec'; +import type { TemplateElement } from '../special/TemplateElement/spec'; +import type { TSClassImplements } from '../special/TSClassImplements/spec'; +import type { TSExternalModuleReference } from '../special/TSExternalModuleReference/spec'; +import type { TSInterfaceBody } from '../special/TSInterfaceBody/spec'; +import type { TSInterfaceHeritage } from '../special/TSInterfaceHeritage/spec'; +import type { TSModuleBlock } from '../special/TSModuleBlock/spec'; +import type { TSTypeAnnotation } from '../special/TSTypeAnnotation/spec'; +import type { TSTypeParameter } from '../special/TSTypeParameter/spec'; +import type { TSTypeParameterDeclaration } from '../special/TSTypeParameterDeclaration/spec'; +import type { TSTypeParameterInstantiation } from '../special/TSTypeParameterInstantiation/spec'; +import type { VariableDeclarator } from '../special/VariableDeclarator/spec'; +import type { BlockStatement } from '../statement/BlockStatement/spec'; +import type { BreakStatement } from '../statement/BreakStatement/spec'; +import type { ClassDeclaration } from '../statement/ClassDeclaration/spec'; +import type { ContinueStatement } from '../statement/ContinueStatement/spec'; +import type { DebuggerStatement } from '../statement/DebuggerStatement/spec'; +import type { DoWhileStatement } from '../statement/DoWhileStatement/spec'; +import type { ExportAllDeclaration } from '../statement/ExportAllDeclaration/spec'; +import type { ExportDefaultDeclaration } from '../statement/ExportDefaultDeclaration/spec'; +import type { ExportNamedDeclaration } from '../statement/ExportNamedDeclaration/spec'; +import type { ExpressionStatement } from '../statement/ExpressionStatement/spec'; +import type { ForInStatement } from '../statement/ForInStatement/spec'; +import type { ForOfStatement } from '../statement/ForOfStatement/spec'; +import type { ForStatement } from '../statement/ForStatement/spec'; +import type { FunctionDeclaration } from '../statement/FunctionDeclaration/spec'; +import type { IfStatement } from '../statement/IfStatement/spec'; +import type { ImportDeclaration } from '../statement/ImportDeclaration/spec'; +import type { LabeledStatement } from '../statement/LabeledStatement/spec'; +import type { ReturnStatement } from '../statement/ReturnStatement/spec'; +import type { SwitchStatement } from '../statement/SwitchStatement/spec'; +import type { ThrowStatement } from '../statement/ThrowStatement/spec'; +import type { TryStatement } from '../statement/TryStatement/spec'; +import type { TSDeclareFunction } from '../statement/TSDeclareFunction/spec'; +import type { TSEnumDeclaration } from '../statement/TSEnumDeclaration/spec'; +import type { TSExportAssignment } from '../statement/TSExportAssignment/spec'; +import type { TSImportEqualsDeclaration } from '../statement/TSImportEqualsDeclaration/spec'; +import type { TSInterfaceDeclaration } from '../statement/TSInterfaceDeclaration/spec'; +import type { TSModuleDeclaration } from '../statement/TSModuleDeclaration/spec'; +import type { TSNamespaceExportDeclaration } from '../statement/TSNamespaceExportDeclaration/spec'; +import type { TSTypeAliasDeclaration } from '../statement/TSTypeAliasDeclaration/spec'; +import type { VariableDeclaration } from '../statement/VariableDeclaration/spec'; +import type { WhileStatement } from '../statement/WhileStatement/spec'; +import type { WithStatement } from '../statement/WithStatement/spec'; +import type { TSAbstractKeyword } from '../token/TSAbstractKeyword/spec'; +import type { TSAsyncKeyword } from '../token/TSAsyncKeyword/spec'; +import type { TSDeclareKeyword } from '../token/TSDeclareKeyword/spec'; +import type { TSExportKeyword } from '../token/TSExportKeyword/spec'; +import type { TSPrivateKeyword } from '../token/TSPrivateKeyword/spec'; +import type { TSProtectedKeyword } from '../token/TSProtectedKeyword/spec'; +import type { TSPublicKeyword } from '../token/TSPublicKeyword/spec'; +import type { TSReadonlyKeyword } from '../token/TSReadonlyKeyword/spec'; +import type { TSStaticKeyword } from '../token/TSStaticKeyword/spec'; +import type { TSAnyKeyword } from '../type/TSAnyKeyword/spec'; +import type { TSArrayType } from '../type/TSArrayType/spec'; +import type { TSBigIntKeyword } from '../type/TSBigIntKeyword/spec'; +import type { TSBooleanKeyword } from '../type/TSBooleanKeyword/spec'; +import type { TSConditionalType } from '../type/TSConditionalType/spec'; +import type { TSConstructorType } from '../type/TSConstructorType/spec'; +import type { TSFunctionType } from '../type/TSFunctionType/spec'; +import type { TSImportType } from '../type/TSImportType/spec'; +import type { TSIndexedAccessType } from '../type/TSIndexedAccessType/spec'; +import type { TSInferType } from '../type/TSInferType/spec'; +import type { TSIntersectionType } from '../type/TSIntersectionType/spec'; +import type { TSLiteralType } from '../type/TSLiteralType/spec'; +import type { TSMappedType } from '../type/TSMappedType/spec'; +import type { TSNamedTupleMember } from '../type/TSNamedTupleMember/spec'; +import type { TSNeverKeyword } from '../type/TSNeverKeyword/spec'; +import type { TSNullKeyword } from '../type/TSNullKeyword/spec'; +import type { TSNumberKeyword } from '../type/TSNumberKeyword/spec'; +import type { TSObjectKeyword } from '../type/TSObjectKeyword/spec'; +import type { TSOptionalType } from '../type/TSOptionalType/spec'; +import type { TSParenthesizedType } from '../type/TSParenthesizedType/spec'; +import type { TSQualifiedName } from '../type/TSQualifiedName/spec'; +import type { TSRestType } from '../type/TSRestType/spec'; +import type { TSStringKeyword } from '../type/TSStringKeyword/spec'; +import type { TSSymbolKeyword } from '../type/TSSymbolKeyword/spec'; +import type { TSTemplateLiteralType } from '../type/TSTemplateLiteralType/spec'; +import type { TSThisType } from '../type/TSThisType/spec'; +import type { TSTupleType } from '../type/TSTupleType/spec'; +import type { TSTypeLiteral } from '../type/TSTypeLiteral/spec'; +import type { TSTypeOperator } from '../type/TSTypeOperator/spec'; +import type { TSTypePredicate } from '../type/TSTypePredicate/spec'; +import type { TSTypeQuery } from '../type/TSTypeQuery/spec'; +import type { TSTypeReference } from '../type/TSTypeReference/spec'; +import type { TSUndefinedKeyword } from '../type/TSUndefinedKeyword/spec'; +import type { TSUnionType } from '../type/TSUnionType/spec'; +import type { TSUnknownKeyword } from '../type/TSUnknownKeyword/spec'; +import type { TSVoidKeyword } from '../type/TSVoidKeyword/spec'; +import type { Literal } from './Literal'; + +/* + * NOTE: + * Tokens are not included in the `Node` union below on purpose because they are not ever included as part of the standard AST tree. + */ + +export type Node = + | ArrayExpression + | ArrayPattern + | ArrowFunctionExpression + | AssignmentExpression + | AssignmentPattern + | AwaitExpression + | BinaryExpression + | BlockStatement + | BreakStatement + | CallExpression + | CatchClause + | ChainExpression + | ClassBody + | ClassDeclaration + | ClassExpression + | ClassProperty + | ConditionalExpression + | ContinueStatement + | DebuggerStatement + | Decorator + | DoWhileStatement + | EmptyStatement + | ExportAllDeclaration + | ExportDefaultDeclaration + | ExportNamedDeclaration + | ExportSpecifier + | ExpressionStatement + | ForInStatement + | ForOfStatement + | ForStatement + | FunctionDeclaration + | FunctionExpression + | Identifier + | IfStatement + | ImportDeclaration + | ImportDefaultSpecifier + | ImportExpression + | ImportNamespaceSpecifier + | ImportSpecifier + | JSXAttribute + | JSXClosingElement + | JSXClosingFragment + | JSXElement + | JSXEmptyExpression + | JSXExpressionContainer + | JSXFragment + | JSXIdentifier + | JSXMemberExpression + | JSXOpeningElement + | JSXOpeningFragment + | JSXSpreadAttribute + | JSXSpreadChild + | JSXText + | LabeledStatement + | Literal + | LogicalExpression + | MemberExpression + | MetaProperty + | MethodDefinition + | NewExpression + | ObjectExpression + | ObjectPattern + | Program + | Property + | RestElement + | ReturnStatement + | SequenceExpression + | SpreadElement + | Super + | SwitchCase + | SwitchStatement + | TaggedTemplateExpression + | TemplateElement + | TemplateLiteral + | ThisExpression + | ThrowStatement + | TryStatement + | TSAbstractClassProperty + | TSAbstractKeyword + | TSAbstractMethodDefinition + | TSAnyKeyword + | TSArrayType + | TSAsExpression + | TSAsyncKeyword + | TSBigIntKeyword + | TSBooleanKeyword + | TSCallSignatureDeclaration + | TSClassImplements + | TSConditionalType + | TSConstructorType + | TSConstructSignatureDeclaration + | TSDeclareFunction + | TSDeclareKeyword + | TSEmptyBodyFunctionExpression + | TSEnumDeclaration + | TSEnumMember + | TSExportAssignment + | TSExportKeyword + | TSExternalModuleReference + | TSFunctionType + | TSImportEqualsDeclaration + | TSImportType + | TSIndexedAccessType + | TSIndexSignature + | TSInferType + | TSInterfaceBody + | TSInterfaceDeclaration + | TSInterfaceHeritage + | TSIntersectionType + | TSLiteralType + | TSMappedType + | TSMethodSignature + | TSModuleBlock + | TSModuleDeclaration + | TSNamedTupleMember + | TSNamespaceExportDeclaration + | TSNeverKeyword + | TSNonNullExpression + | TSNullKeyword + | TSNumberKeyword + | TSObjectKeyword + | TSOptionalType + | TSParameterProperty + | TSParenthesizedType + | TSPrivateKeyword + | TSPropertySignature + | TSProtectedKeyword + | TSPublicKeyword + | TSQualifiedName + | TSReadonlyKeyword + | TSRestType + | TSStaticKeyword + | TSStringKeyword + | TSSymbolKeyword + | TSTemplateLiteralType + | TSThisType + | TSTupleType + | TSTypeAliasDeclaration + | TSTypeAnnotation + | TSTypeAssertion + | TSTypeLiteral + | TSTypeOperator + | TSTypeParameter + | TSTypeParameterDeclaration + | TSTypeParameterInstantiation + | TSTypePredicate + | TSTypeQuery + | TSTypeReference + | TSUndefinedKeyword + | TSUnionType + | TSUnknownKeyword + | TSVoidKeyword + | UnaryExpression + | UpdateExpression + | VariableDeclaration + | VariableDeclarator + | WhileStatement + | WithStatement + | YieldExpression; diff --git a/packages/ast-spec/src/unions/ObjectLiteralElement.ts b/packages/ast-spec/src/unions/ObjectLiteralElement.ts new file mode 100644 index 000000000000..d7575c80c1b9 --- /dev/null +++ b/packages/ast-spec/src/unions/ObjectLiteralElement.ts @@ -0,0 +1,8 @@ +import type { MethodDefinition } from '../element/MethodDefinition/spec'; +import type { Property } from '../element/Property/spec'; +import type { SpreadElement } from '../element/SpreadElement/spec'; + +export type ObjectLiteralElement = MethodDefinition | Property | SpreadElement; + +// TODO - breaking change remove this +export type ObjectLiteralElementLike = ObjectLiteralElement; diff --git a/packages/ast-spec/src/unions/Parameter.ts b/packages/ast-spec/src/unions/Parameter.ts new file mode 100644 index 000000000000..766a8dedbe7e --- /dev/null +++ b/packages/ast-spec/src/unions/Parameter.ts @@ -0,0 +1,14 @@ +import type { Identifier } from '../expression/Identifier/spec'; +import type { ArrayPattern } from '../parameter/ArrayPattern/spec'; +import type { AssignmentPattern } from '../parameter/AssignmentPattern/spec'; +import type { ObjectPattern } from '../parameter/ObjectPattern/spec'; +import type { RestElement } from '../parameter/RestElement/spec'; +import type { TSParameterProperty } from '../parameter/TSParameterProperty/spec'; + +export type Parameter = + | ArrayPattern + | AssignmentPattern + | Identifier + | ObjectPattern + | RestElement + | TSParameterProperty; diff --git a/packages/ast-spec/src/unions/PrimaryExpression.ts b/packages/ast-spec/src/unions/PrimaryExpression.ts new file mode 100644 index 000000000000..4b86c0b719be --- /dev/null +++ b/packages/ast-spec/src/unions/PrimaryExpression.ts @@ -0,0 +1,35 @@ +import type { ArrayExpression } from '../expression/ArrayExpression/spec'; +import type { ClassExpression } from '../expression/ClassExpression/spec'; +import type { FunctionExpression } from '../expression/FunctionExpression/spec'; +import type { Identifier } from '../expression/Identifier/spec'; +import type { JSXElement } from '../expression/JSXElement/spec'; +import type { JSXFragment } from '../expression/JSXFragment/spec'; +import type { MetaProperty } from '../expression/MetaProperty/spec'; +import type { ObjectExpression } from '../expression/ObjectExpression/spec'; +import type { Super } from '../expression/Super/spec'; +import type { TemplateLiteral } from '../expression/TemplateLiteral/spec'; +import type { ThisExpression } from '../expression/ThisExpression/spec'; +import type { ArrayPattern } from '../parameter/ArrayPattern/spec'; +import type { ObjectPattern } from '../parameter/ObjectPattern/spec'; +import type { JSXOpeningElement } from '../special/JSXOpeningElement/spec'; +import type { TSNullKeyword } from '../type/TSNullKeyword/spec'; +import type { LiteralExpression } from './LiteralExpression'; + +// TODO - breaking change remove this +export type PrimaryExpression = + | ArrayExpression + | ArrayPattern + | ClassExpression + | FunctionExpression + | Identifier + | JSXElement + | JSXFragment + | JSXOpeningElement + | LiteralExpression + | MetaProperty + | ObjectExpression + | ObjectPattern + | Super + | TemplateLiteral + | ThisExpression + | TSNullKeyword; diff --git a/packages/ast-spec/src/unions/PropertyName.ts b/packages/ast-spec/src/unions/PropertyName.ts new file mode 100644 index 000000000000..56ba04cabbea --- /dev/null +++ b/packages/ast-spec/src/unions/PropertyName.ts @@ -0,0 +1,11 @@ +import type { Identifier } from '../expression/Identifier/spec'; +import type { NumberLiteral } from '../expression/literal/NumberLiteral/spec'; +import type { StringLiteral } from '../expression/literal/StringLiteral/spec'; +import type { Expression } from '../unions/Expression'; + +export type PropertyName = PropertyNameComputed | PropertyNameNonComputed; +export type PropertyNameComputed = Expression; +export type PropertyNameNonComputed = + | Identifier + | NumberLiteral + | StringLiteral; diff --git a/packages/ast-spec/src/unions/Statement.ts b/packages/ast-spec/src/unions/Statement.ts new file mode 100644 index 000000000000..93810d465c63 --- /dev/null +++ b/packages/ast-spec/src/unions/Statement.ts @@ -0,0 +1,78 @@ +import type { BlockStatement } from '../statement/BlockStatement/spec'; +import type { BreakStatement } from '../statement/BreakStatement/spec'; +import type { ClassDeclaration } from '../statement/ClassDeclaration/spec'; +import type { ContinueStatement } from '../statement/ContinueStatement/spec'; +import type { DebuggerStatement } from '../statement/DebuggerStatement/spec'; +import type { DoWhileStatement } from '../statement/DoWhileStatement/spec'; +import type { ExportAllDeclaration } from '../statement/ExportAllDeclaration/spec'; +import type { ExportDefaultDeclaration } from '../statement/ExportDefaultDeclaration/spec'; +import type { ExportNamedDeclaration } from '../statement/ExportNamedDeclaration/spec'; +import type { ExpressionStatement } from '../statement/ExpressionStatement/spec'; +import type { ForInStatement } from '../statement/ForInStatement/spec'; +import type { ForOfStatement } from '../statement/ForOfStatement/spec'; +import type { ForStatement } from '../statement/ForStatement/spec'; +import type { FunctionDeclaration } from '../statement/FunctionDeclaration/spec'; +import type { IfStatement } from '../statement/IfStatement/spec'; +import type { ImportDeclaration } from '../statement/ImportDeclaration/spec'; +import type { LabeledStatement } from '../statement/LabeledStatement/spec'; +import type { ReturnStatement } from '../statement/ReturnStatement/spec'; +import type { SwitchStatement } from '../statement/SwitchStatement/spec'; +import type { ThrowStatement } from '../statement/ThrowStatement/spec'; +import type { TryStatement } from '../statement/TryStatement/spec'; +import type { TSDeclareFunction } from '../statement/TSDeclareFunction/spec'; +import type { TSEnumDeclaration } from '../statement/TSEnumDeclaration/spec'; +import type { TSExportAssignment } from '../statement/TSExportAssignment/spec'; +import type { TSImportEqualsDeclaration } from '../statement/TSImportEqualsDeclaration/spec'; +import type { TSInterfaceDeclaration } from '../statement/TSInterfaceDeclaration/spec'; +import type { TSModuleDeclaration } from '../statement/TSModuleDeclaration/spec'; +import type { TSNamespaceExportDeclaration } from '../statement/TSNamespaceExportDeclaration/spec'; +import type { TSTypeAliasDeclaration } from '../statement/TSTypeAliasDeclaration/spec'; +import type { VariableDeclaration } from '../statement/VariableDeclaration/spec'; +import type { WhileStatement } from '../statement/WhileStatement/spec'; +import type { WithStatement } from '../statement/WithStatement/spec'; + +export type Statement = + | BlockStatement + | BreakStatement + | ClassDeclaration + | ContinueStatement + | DebuggerStatement + | DoWhileStatement + | ExportAllDeclaration + | ExportDefaultDeclaration + | ExportNamedDeclaration + | ExpressionStatement + | ForInStatement + | ForOfStatement + | ForStatement + | FunctionDeclaration + | IfStatement + | ImportDeclaration + | LabeledStatement + | ReturnStatement + | SwitchStatement + | ThrowStatement + | TryStatement + | TSDeclareFunction + | TSEnumDeclaration + | TSExportAssignment + | TSImportEqualsDeclaration + | TSInterfaceDeclaration + | TSModuleDeclaration + | TSNamespaceExportDeclaration + | TSTypeAliasDeclaration + | VariableDeclaration + | WhileStatement + | WithStatement; + +// Certain nodes are only allowed at the top-level +export type ProgramStatement = + | ExportAllDeclaration + | ExportDefaultDeclaration + | ExportNamedDeclaration + | ImportDeclaration + | Statement + | TSImportEqualsDeclaration + | TSNamespaceExportDeclaration; + +// TODO - once we have syntax errors, the types in ProgramStatement should not be in Statement diff --git a/packages/ast-spec/src/unions/TSUnaryExpression.ts b/packages/ast-spec/src/unions/TSUnaryExpression.ts new file mode 100644 index 000000000000..b4dd05627bf6 --- /dev/null +++ b/packages/ast-spec/src/unions/TSUnaryExpression.ts @@ -0,0 +1,13 @@ +import type { AwaitExpression } from '../expression/AwaitExpression/spec'; +import type { TSTypeAssertion } from '../expression/TSTypeAssertion/spec'; +import type { UnaryExpression } from '../expression/UnaryExpression/spec'; +import type { UpdateExpression } from '../expression/UpdateExpression/spec'; +import type { LeftHandSideExpression } from './LeftHandSideExpression'; + +// TODO - breaking change remove this +export type TSUnaryExpression = + | AwaitExpression + | LeftHandSideExpression + | TSTypeAssertion + | UnaryExpression + | UpdateExpression; diff --git a/packages/ast-spec/src/unions/Token.ts b/packages/ast-spec/src/unions/Token.ts new file mode 100644 index 000000000000..3d71cb019a7f --- /dev/null +++ b/packages/ast-spec/src/unions/Token.ts @@ -0,0 +1,26 @@ +import type { BooleanToken } from '../token/BooleanToken/spec'; +import type { IdentifierToken } from '../token/IdentifierToken/spec'; +import type { JSXIdentifierToken } from '../token/JSXIdentifierToken/spec'; +import type { JSXTextToken } from '../token/JSXTextToken/spec'; +import type { KeywordToken } from '../token/KeywordToken/spec'; +import type { NullToken } from '../token/NullToken/spec'; +import type { NumericToken } from '../token/NumericToken/spec'; +import type { PunctuatorToken } from '../token/PunctuatorToken/spec'; +import type { RegularExpressionToken } from '../token/RegularExpressionToken/spec'; +import type { StringToken } from '../token/StringToken/spec'; +import type { TemplateToken } from '../token/TemplateToken/spec'; +import type { Comment } from './Comment'; + +export type Token = + | BooleanToken + | Comment + | IdentifierToken + | JSXIdentifierToken + | JSXTextToken + | KeywordToken + | NullToken + | NumericToken + | PunctuatorToken + | RegularExpressionToken + | StringToken + | TemplateToken; diff --git a/packages/ast-spec/src/unions/TypeElement.ts b/packages/ast-spec/src/unions/TypeElement.ts new file mode 100644 index 000000000000..9a4bbc99c223 --- /dev/null +++ b/packages/ast-spec/src/unions/TypeElement.ts @@ -0,0 +1,12 @@ +import type { TSCallSignatureDeclaration } from '../element/TSCallSignatureDeclaration/spec'; +import type { TSConstructSignatureDeclaration } from '../element/TSConstructSignatureDeclaration/spec'; +import type { TSIndexSignature } from '../element/TSIndexSignature/spec'; +import type { TSMethodSignature } from '../element/TSMethodSignature/spec'; +import type { TSPropertySignature } from '../element/TSPropertySignature/spec'; + +export type TypeElement = + | TSCallSignatureDeclaration + | TSConstructSignatureDeclaration + | TSIndexSignature + | TSMethodSignature + | TSPropertySignature; diff --git a/packages/ast-spec/src/unions/TypeNode.ts b/packages/ast-spec/src/unions/TypeNode.ts new file mode 100644 index 000000000000..6305968abba7 --- /dev/null +++ b/packages/ast-spec/src/unions/TypeNode.ts @@ -0,0 +1,72 @@ +import type { TSAnyKeyword } from '../type/TSAnyKeyword/spec'; +import type { TSArrayType } from '../type/TSArrayType/spec'; +import type { TSBigIntKeyword } from '../type/TSBigIntKeyword/spec'; +import type { TSBooleanKeyword } from '../type/TSBooleanKeyword/spec'; +import type { TSConditionalType } from '../type/TSConditionalType/spec'; +import type { TSConstructorType } from '../type/TSConstructorType/spec'; +import type { TSFunctionType } from '../type/TSFunctionType/spec'; +import type { TSImportType } from '../type/TSImportType/spec'; +import type { TSIndexedAccessType } from '../type/TSIndexedAccessType/spec'; +import type { TSInferType } from '../type/TSInferType/spec'; +import type { TSIntersectionType } from '../type/TSIntersectionType/spec'; +import type { TSLiteralType } from '../type/TSLiteralType/spec'; +import type { TSMappedType } from '../type/TSMappedType/spec'; +import type { TSNamedTupleMember } from '../type/TSNamedTupleMember/spec'; +import type { TSNeverKeyword } from '../type/TSNeverKeyword/spec'; +import type { TSNullKeyword } from '../type/TSNullKeyword/spec'; +import type { TSNumberKeyword } from '../type/TSNumberKeyword/spec'; +import type { TSObjectKeyword } from '../type/TSObjectKeyword/spec'; +import type { TSOptionalType } from '../type/TSOptionalType/spec'; +import type { TSParenthesizedType } from '../type/TSParenthesizedType/spec'; +import type { TSRestType } from '../type/TSRestType/spec'; +import type { TSStringKeyword } from '../type/TSStringKeyword/spec'; +import type { TSSymbolKeyword } from '../type/TSSymbolKeyword/spec'; +import type { TSTemplateLiteralType } from '../type/TSTemplateLiteralType/spec'; +import type { TSThisType } from '../type/TSThisType/spec'; +import type { TSTupleType } from '../type/TSTupleType/spec'; +import type { TSTypeLiteral } from '../type/TSTypeLiteral/spec'; +import type { TSTypeOperator } from '../type/TSTypeOperator/spec'; +import type { TSTypePredicate } from '../type/TSTypePredicate/spec'; +import type { TSTypeQuery } from '../type/TSTypeQuery/spec'; +import type { TSTypeReference } from '../type/TSTypeReference/spec'; +import type { TSUndefinedKeyword } from '../type/TSUndefinedKeyword/spec'; +import type { TSUnionType } from '../type/TSUnionType/spec'; +import type { TSUnknownKeyword } from '../type/TSUnknownKeyword/spec'; +import type { TSVoidKeyword } from '../type/TSVoidKeyword/spec'; + +export type TypeNode = + | TSAnyKeyword + | TSArrayType + | TSBigIntKeyword + | TSBooleanKeyword + | TSConditionalType + | TSConstructorType + | TSFunctionType + | TSImportType + | TSIndexedAccessType + | TSInferType + | TSIntersectionType + | TSLiteralType + | TSMappedType + | TSNamedTupleMember + | TSNeverKeyword + | TSNullKeyword + | TSNumberKeyword + | TSObjectKeyword + | TSOptionalType + | TSParenthesizedType + | TSRestType + | TSStringKeyword + | TSSymbolKeyword + | TSTemplateLiteralType + | TSThisType + | TSTupleType + | TSTypeLiteral + | TSTypeOperator + | TSTypePredicate + | TSTypeQuery + | TSTypeReference + | TSUndefinedKeyword + | TSUnionType + | TSUnknownKeyword + | TSVoidKeyword; diff --git a/packages/ast-spec/tsconfig.build.json b/packages/ast-spec/tsconfig.build.json new file mode 100644 index 000000000000..215a0282df2b --- /dev/null +++ b/packages/ast-spec/tsconfig.build.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "outDir": "./dist", + "rootDir": "./src", + "resolveJsonModule": true + }, + "include": ["src", "typings"] +} diff --git a/packages/ast-spec/tsconfig.json b/packages/ast-spec/tsconfig.json new file mode 100644 index 000000000000..9cea515ba6b2 --- /dev/null +++ b/packages/ast-spec/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.build.json", + "compilerOptions": { + "composite": false, + "rootDir": "." + }, + "include": ["src", "typings", "tests", "tools"] +} diff --git a/packages/eslint-plugin-internal/package.json b/packages/eslint-plugin-internal/package.json index 2b709b1b2bc8..3d0b06f34716 100644 --- a/packages/eslint-plugin-internal/package.json +++ b/packages/eslint-plugin-internal/package.json @@ -6,7 +6,7 @@ "scripts": { "build": "tsc -b tsconfig.build.json", "clean": "tsc -b tsconfig.build.json --clean", - "postclean": "rimraf dist", + "postclean": "rimraf dist && rimraf coverage", "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", "test": "jest --coverage", diff --git a/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts b/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts index bc26d9d9d9a1..64fefc08f8ef 100644 --- a/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts +++ b/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts @@ -408,7 +408,9 @@ export default createRule({ } } - function isNoFormatTemplateTag(tag: TSESTree.Expression): boolean { + function isNoFormatTemplateTag( + tag: TSESTree.LeftHandSideExpression, + ): boolean { return tag.type === AST_NODE_TYPES.Identifier && tag.name === 'noFormat'; } diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json index 129415010739..9388ff3977aa 100644 --- a/packages/eslint-plugin-tslint/package.json +++ b/packages/eslint-plugin-tslint/package.json @@ -31,7 +31,7 @@ "scripts": { "build": "tsc -b tsconfig.build.json", "clean": "tsc -b tsconfig.build.json --clean", - "postclean": "rimraf dist", + "postclean": "rimraf dist && rimraf coverage", "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", "test": "jest --coverage", diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 8a97cce5ed4a..aea3589865c3 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -33,7 +33,7 @@ "check:docs": "jest tests/docs.test.ts --runTestsByPath --silent --runInBand", "check:configs": "jest tests/configs.test.ts --runTestsByPath --silent --runInBand", "clean": "tsc -b tsconfig.build.json --clean", - "postclean": "rimraf dist", + "postclean": "rimraf dist && rimraf coverage", "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", "generate:configs": "../../node_modules/.bin/ts-node --files --transpile-only tools/generate-configs.ts", "generate:rules-lists": "../../node_modules/.bin/ts-node --files --transpile-only tools/generate-rules-lists.ts", diff --git a/packages/eslint-plugin/src/rules/no-loss-of-precision.ts b/packages/eslint-plugin/src/rules/no-loss-of-precision.ts index 47ab5b1a74fa..1e04d080e747 100644 --- a/packages/eslint-plugin/src/rules/no-loss-of-precision.ts +++ b/packages/eslint-plugin/src/rules/no-loss-of-precision.ts @@ -46,7 +46,7 @@ export default util.createRule({ rules.Literal({ ...node, raw: isSeperatedNumeric(node) ? node.raw.replace(/_/g, '') : node.raw, - }); + } as never); }, }; }, diff --git a/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts b/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts index 5014fd33c24d..81b3b0c923da 100644 --- a/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts +++ b/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts @@ -78,7 +78,6 @@ function getGroup(node: TSESTree.TypeNode): Group { return Group.union; // These types should never occur as part of a union/intersection - case AST_NODE_TYPES.TSInterfaceHeritage: case AST_NODE_TYPES.TSNamedTupleMember: case AST_NODE_TYPES.TSOptionalType: case AST_NODE_TYPES.TSRestType: diff --git a/packages/experimental-utils/package.json b/packages/experimental-utils/package.json index abeee6d97ead..36b20a7cc30c 100644 --- a/packages/experimental-utils/package.json +++ b/packages/experimental-utils/package.json @@ -32,7 +32,7 @@ "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", + "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'", "test": "jest --coverage", diff --git a/packages/parser/package.json b/packages/parser/package.json index 4e75c3101893..7fac012ea902 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -34,7 +34,7 @@ "build": "tsc -b tsconfig.build.json", "postbuild": "downlevel-dts dist _ts3.4/dist", "clean": "tsc -b tsconfig.build.json --clean", - "postclean": "rimraf dist", + "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'", "test": "jest --coverage", diff --git a/packages/scope-manager/package.json b/packages/scope-manager/package.json index b9bb0f3f8634..cc532a3bebba 100644 --- a/packages/scope-manager/package.json +++ b/packages/scope-manager/package.json @@ -31,7 +31,7 @@ "build": "tsc -b tsconfig.build.json", "postbuild": "downlevel-dts dist _ts3.4/dist", "clean": "tsc -b tsconfig.build.json --clean", - "postclean": "rimraf dist", + "postclean": "rimraf dist && rimraf _ts3.4 && rimraf coverage", "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", "generate:lib": "../../node_modules/.bin/ts-node --files --transpile-only tools/generate-lib.ts", "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", diff --git a/packages/scope-manager/src/scope/ScopeBase.ts b/packages/scope-manager/src/scope/ScopeBase.ts index 04f38e8a65f3..602dd81a206a 100644 --- a/packages/scope-manager/src/scope/ScopeBase.ts +++ b/packages/scope-manager/src/scope/ScopeBase.ts @@ -87,22 +87,20 @@ function isStrictScope( if (stmt.type !== AST_NODE_TYPES.ExpressionStatement) { break; } - const expr = stmt.expression; - if ( - expr.type !== AST_NODE_TYPES.Literal || - typeof expr.value !== 'string' - ) { + if (stmt.directive === 'use strict') { + return true; + } + + const expr = stmt.expression; + if (expr.type !== AST_NODE_TYPES.Literal) { break; } - if (expr.raw !== null && expr.raw !== undefined) { - if (expr.raw === '"use strict"' || expr.raw === "'use strict'") { - return true; - } - } else { - if (expr.value === 'use strict') { - return true; - } + if (expr.raw === '"use strict"' || expr.raw === "'use strict'") { + return true; + } + if (expr.value === 'use strict') { + return true; } } return false; diff --git a/packages/types/package.json b/packages/types/package.json index 271f3b4e71bc..041f484df845 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -19,7 +19,7 @@ "repository": { "type": "git", "url": "https://github.com/typescript-eslint/typescript-eslint.git", - "directory": "packages/visitor-keys" + "directory": "packages/types" }, "bugs": { "url": "https://github.com/typescript-eslint/typescript-eslint/issues" @@ -31,12 +31,15 @@ "build": "tsc -b tsconfig.build.json", "postbuild": "downlevel-dts dist _ts3.4/dist", "clean": "tsc -b tsconfig.build.json --clean", - "postclean": "rimraf dist", + "postclean": "rimraf dist && rimraf _ts3.4 && rimraf coverage", "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", "generate:lib": "../../node_modules/.bin/ts-node --files --transpile-only ../scope-manager/tools/generate-lib.ts", "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", "typecheck": "tsc -p tsconfig.json --noEmit" }, + "dependencies": { + "@typescript-eslint/ast-spec": "4.11.1" + }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" diff --git a/packages/types/src/ast-node-types.ts b/packages/types/src/ast-node-types.ts index 97c630d94727..93a21bec805d 100644 --- a/packages/types/src/ast-node-types.ts +++ b/packages/types/src/ast-node-types.ts @@ -1,184 +1 @@ -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', - 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', - 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', -} - -export { AST_NODE_TYPES }; - -// Below is a special type-only test which ensures that we don't accidentally leave unused keys in this enum -// eslint-disable-next-line import/first -- purposely down here to colocate it with this hack of a test -import type { Node } from './ts-estree'; - -type GetKeys = keyof Extract; - -type AllKeys = { - readonly [T in AST_NODE_TYPES]: GetKeys; -}; - -type TakesString> = 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'." - void | TakesString; +export { AST_NODE_TYPES } from '@typescript-eslint/ast-spec'; diff --git a/packages/types/src/ast-token-types.ts b/packages/types/src/ast-token-types.ts index 144befece83e..59cf383b1e0c 100644 --- a/packages/types/src/ast-token-types.ts +++ b/packages/types/src/ast-token-types.ts @@ -1,19 +1 @@ -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', -} - -export { AST_TOKEN_TYPES }; +export { AST_TOKEN_TYPES } from '@typescript-eslint/ast-spec'; diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 59df48302df5..7097f1243dc7 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -2,4 +2,4 @@ export { AST_NODE_TYPES } from './ast-node-types'; export { AST_TOKEN_TYPES } from './ast-token-types'; export * from './lib'; export * from './parser-options'; -export * as TSESTree from './ts-estree'; +export * from './ts-estree'; diff --git a/packages/types/src/ts-estree.ts b/packages/types/src/ts-estree.ts index 4dd89c962bef..ccc65809d2d4 100644 --- a/packages/types/src/ts-estree.ts +++ b/packages/types/src/ts-estree.ts @@ -1,1753 +1,20 @@ -import { AST_NODE_TYPES } from './ast-node-types'; -import { AST_TOKEN_TYPES } from './ast-token-types'; +import * as TSESTree from '@typescript-eslint/ast-spec/dist/spec'; -export interface LineAndColumnData { - /** - * Line number (1-indexed) - */ - line: number; - /** - * Column number on the line (0-indexed) - */ - column: number; -} -export interface SourceLocation { - /** - * The position of the first character of the parsed source region - */ - start: LineAndColumnData; - /** - * The position of the first character after the parsed source region - */ - end: LineAndColumnData; -} -export type Range = [number, number]; - -export interface BaseNode { - /** - * The source location information of the node. - */ - loc: SourceLocation; - /** - * An array of two numbers. - * Both numbers are a 0-based index which is the position in the array of source code characters. - * The first is the start position of the node, the second is the end position of the node. - */ - 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; - - // we don't ever set this from within ts-estree - // source?: string | null; -} - -/* - * Token and Comment are pseudo-nodes to represent pieces of source code - * - * NOTE: - * They are not included in the `Node` union below on purpose because they - * are not ever included as part of the standard AST tree. - */ -interface BaseToken extends BaseNode { - value: string; -} - -export interface BooleanToken extends BaseToken { - type: AST_TOKEN_TYPES.Boolean; -} - -export interface IdentifierToken extends BaseToken { - type: AST_TOKEN_TYPES.Identifier; -} - -export interface JSXIdentifierToken extends BaseToken { - type: AST_TOKEN_TYPES.JSXIdentifier; -} - -export interface JSXTextToken extends BaseToken { - type: AST_TOKEN_TYPES.JSXText; -} - -export interface KeywordToken extends BaseToken { - type: AST_TOKEN_TYPES.Keyword; -} - -export interface NullToken extends BaseToken { - type: AST_TOKEN_TYPES.Null; -} - -export interface NumericToken extends BaseToken { - type: AST_TOKEN_TYPES.Numeric; -} - -export interface PunctuatorToken extends BaseToken { - type: AST_TOKEN_TYPES.Punctuator; -} - -export interface RegularExpressionToken extends BaseToken { - type: AST_TOKEN_TYPES.RegularExpression; - regex: { - pattern: string; - flags: string; - }; -} - -export interface StringToken extends BaseToken { - type: AST_TOKEN_TYPES.String; -} - -export interface TemplateToken extends BaseToken { - type: AST_TOKEN_TYPES.Template; -} - -export interface BlockComment extends BaseToken { - type: AST_TOKEN_TYPES.Block; -} - -export interface LineComment extends BaseToken { - type: AST_TOKEN_TYPES.Line; -} +declare module '@typescript-eslint/ast-spec/dist/spec' { + interface BaseNode { + parent?: TSESTree.Node; + } -export type Comment = BlockComment | LineComment; -export type Token = - | BooleanToken - | Comment - | IdentifierToken - | JSXIdentifierToken - | JSXTextToken - | KeywordToken - | NullToken - | NumericToken - | PunctuatorToken - | RegularExpressionToken - | StringToken - | TemplateToken; - -export type OptionalRangeAndLoc = Pick< - T, - Exclude -> & { - range?: Range; - loc?: SourceLocation; -}; - -// Every single valid AST Node -// Please keep it sorted alphabetically. -export type Node = - | ArrayExpression - | ArrayPattern - | ArrowFunctionExpression - | AssignmentExpression - | AssignmentPattern - | AwaitExpression - | BigIntLiteral - | BinaryExpression - | BlockStatement - | BreakStatement - | CallExpression - | CatchClause - | ChainExpression - | ClassBody - | ClassDeclaration - | ClassExpression - | ClassProperty - | ConditionalExpression - | ContinueStatement - | DebuggerStatement - | Decorator - | DoWhileStatement - | EmptyStatement - | ExportAllDeclaration - | ExportDefaultDeclaration - | ExportNamedDeclaration - | ExportSpecifier - | ExpressionStatement - | ForInStatement - | ForOfStatement - | ForStatement - | FunctionDeclaration - | FunctionExpression - | Identifier - | IfStatement - | ImportDeclaration - | ImportDefaultSpecifier - | ImportExpression - | ImportNamespaceSpecifier - | ImportSpecifier - | JSXAttribute - | JSXClosingElement - | JSXClosingFragment - | JSXElement - | JSXEmptyExpression - | JSXExpressionContainer - | JSXFragment - | JSXIdentifier - | JSXMemberExpression - | JSXOpeningElement - | JSXOpeningFragment - | JSXSpreadAttribute - | JSXSpreadChild - | JSXText - | LabeledStatement - | Literal - | LogicalExpression - | MemberExpression - | MetaProperty - | MethodDefinition - | NewExpression - | ObjectExpression - | ObjectPattern - | Program - | Property - | RestElement - | ReturnStatement - | SequenceExpression - | SpreadElement - | Super - | SwitchCase - | SwitchStatement - | TaggedTemplateExpression - | TemplateElement - | TemplateLiteral - | ThisExpression - | ThrowStatement - | TryStatement - | TSAbstractClassProperty - | TSAbstractKeyword - | TSAbstractMethodDefinition - | TSAnyKeyword - | TSArrayType - | TSAsExpression - | TSAsyncKeyword - | TSBigIntKeyword - | TSBooleanKeyword - | TSCallSignatureDeclaration - | TSClassImplements - | TSConditionalType - | TSConstructorType - | TSConstructSignatureDeclaration - | TSDeclareFunction - | TSDeclareKeyword - | TSEmptyBodyFunctionExpression - | TSEnumDeclaration - | TSEnumMember - | TSExportAssignment - | TSExportKeyword - | TSExternalModuleReference - | TSFunctionType - | TSImportEqualsDeclaration - | TSImportType - | TSIndexedAccessType - | TSIndexSignature - | TSInferType - | TSInterfaceBody - | TSInterfaceDeclaration - | TSInterfaceHeritage - | TSIntersectionType - | TSLiteralType - | TSMappedType - | TSMethodSignature - | TSModuleBlock - | TSModuleDeclaration - | TSNamedTupleMember - | TSNamespaceExportDeclaration - | TSNeverKeyword - | TSNonNullExpression - | TSNullKeyword - | TSNumberKeyword - | TSObjectKeyword - | TSOptionalType - | TSParameterProperty - | TSParenthesizedType - | TSPrivateKeyword - | TSPropertySignature - | TSProtectedKeyword - | TSPublicKeyword - | TSQualifiedName - | TSReadonlyKeyword - | TSRestType - | TSStaticKeyword - | TSStringKeyword - | TSSymbolKeyword - | TSTemplateLiteralType - | TSThisType - | TSTupleType - | TSTypeAliasDeclaration - | TSTypeAnnotation - | TSTypeAssertion - | TSTypeLiteral - | TSTypeOperator - | TSTypeParameter - | TSTypeParameterDeclaration - | TSTypeParameterInstantiation - | TSTypePredicate - | TSTypeQuery - | TSTypeReference - | TSUndefinedKeyword - | TSUnionType - | TSUnknownKeyword - | TSVoidKeyword - | UnaryExpression - | UpdateExpression - | VariableDeclaration - | VariableDeclarator - | WhileStatement - | WithStatement - | YieldExpression; - -////////// -// Reusable Unions -// These are based off of types used in the Typescript AST definitions -// **Ensure you sort the union members alphabetically** -////////// - -export type Accessibility = 'public' | 'protected' | 'private'; -export type BindingPattern = ArrayPattern | ObjectPattern; -export type BindingName = BindingPattern | Identifier; -export type ChainElement = - | CallExpression - | MemberExpression - | TSNonNullExpression; -export type ClassElement = - | ClassProperty - | MethodDefinition - | TSAbstractClassProperty - | TSAbstractMethodDefinition - | TSIndexSignature; -export type ClassProperty = - | ClassPropertyComputedName - | ClassPropertyNonComputedName; -export type DeclarationStatement = - | ClassDeclaration - | ClassExpression - | ExportDefaultDeclaration - | ExportAllDeclaration - | ExportNamedDeclaration - | FunctionDeclaration - | TSDeclareFunction - | TSImportEqualsDeclaration - | TSInterfaceDeclaration - | TSModuleDeclaration - | TSNamespaceExportDeclaration - | TSTypeAliasDeclaration - | TSEnumDeclaration; -export type DestructuringPattern = - | Identifier - | ObjectPattern - | ArrayPattern - | RestElement - | AssignmentPattern - | MemberExpression; -export type EntityName = Identifier | TSQualifiedName; -export type ExportDeclaration = - | ClassDeclaration - | ClassExpression - | FunctionDeclaration - | TSDeclareFunction - | TSEnumDeclaration - | TSInterfaceDeclaration - | TSModuleDeclaration - | TSTypeAliasDeclaration - | VariableDeclaration; -export type Expression = - | ArrowFunctionExpression - | AssignmentExpression - | BinaryExpression - | ChainExpression - | ConditionalExpression - | ImportExpression - | JSXClosingElement - | JSXClosingFragment - | JSXExpressionContainer - | JSXOpeningElement - | JSXOpeningFragment - | JSXSpreadChild - | LogicalExpression - | NewExpression - | RestElement - | SequenceExpression - | SpreadElement - | TSAsExpression - | TSUnaryExpression - | YieldExpression; -export type ForInitialiser = Expression | VariableDeclaration; -export type FunctionLike = - | ArrowFunctionExpression - | FunctionDeclaration - | FunctionExpression - | TSDeclareFunction - | TSEmptyBodyFunctionExpression; -export type ImportClause = - | ImportDefaultSpecifier - | ImportNamespaceSpecifier - | ImportSpecifier; -export type IterationStatement = - | DoWhileStatement - | ForInStatement - | ForOfStatement - | ForStatement - | WhileStatement; -export type JSXChild = JSXElement | JSXExpression | JSXFragment | JSXText; -export type JSXExpression = - | JSXEmptyExpression - | JSXSpreadChild - | JSXExpressionContainer; -export type JSXTagNameExpression = JSXIdentifier | JSXMemberExpression; -export type LeftHandSideExpression = - | CallExpression - | ClassExpression - | ClassDeclaration - | FunctionExpression - | LiteralExpression - | MemberExpression - | PrimaryExpression - | TaggedTemplateExpression - | TSNonNullExpression - | TSAsExpression - | ArrowFunctionExpression; -export type Literal = - | BigIntLiteral - | BooleanLiteral - | NumberLiteral - | NullLiteral - | RegExpLiteral - | StringLiteral; -export type LiteralExpression = Literal | TemplateLiteral; -export type MemberExpression = - | MemberExpressionComputedName - | MemberExpressionNonComputedName; -export type MethodDefinition = - | MethodDefinitionComputedName - | MethodDefinitionNonComputedName; -export type Modifier = - | TSAbstractKeyword - | TSAsyncKeyword - | TSDeclareKeyword - | TSExportKeyword - | TSPublicKeyword - | TSPrivateKeyword - | TSProtectedKeyword - | TSReadonlyKeyword - | TSStaticKeyword; -export type ObjectLiteralElementLike = - | MethodDefinition - | Property - | SpreadElement - | TSAbstractMethodDefinition; -export type Parameter = - | ArrayPattern - | AssignmentPattern - | Identifier - | ObjectPattern - | RestElement - | TSParameterProperty; -export type PrimaryExpression = - | ArrayExpression - | ArrayPattern - | ClassExpression - | FunctionExpression - | Identifier - | JSXElement - | JSXFragment - | JSXOpeningElement - | Literal - | LiteralExpression - | MetaProperty - | ObjectExpression - | ObjectPattern - | Super - | TemplateLiteral - | ThisExpression - | TSNullKeyword; -export type ProgramStatement = - | ClassDeclaration - | ExportAllDeclaration - | ExportDefaultDeclaration - | ExportNamedDeclaration - | ImportDeclaration - | Statement - | TSDeclareFunction - | TSEnumDeclaration - | TSExportAssignment - | TSImportEqualsDeclaration - | TSInterfaceDeclaration - | TSNamespaceExportDeclaration - | TSTypeAliasDeclaration; -export type Property = PropertyComputedName | PropertyNonComputedName; -export type PropertyName = PropertyNameComputed | PropertyNameNonComputed; -export type PropertyNameComputed = Expression; -export type PropertyNameNonComputed = - | Identifier - | StringLiteral - | NumberLiteral; -export type Statement = - | BlockStatement - | BreakStatement - | ContinueStatement - | DebuggerStatement - | DeclarationStatement - | EmptyStatement - | ExpressionStatement - | IfStatement - | IterationStatement - | ImportDeclaration - | LabeledStatement - | TSModuleBlock - | ReturnStatement - | SwitchStatement - | ThrowStatement - | TryStatement - | VariableDeclaration - | WithStatement; -export type TSAbstractClassProperty = - | TSAbstractClassPropertyComputedName - | TSAbstractClassPropertyNonComputedName; -export type TSAbstractMethodDefinition = - | TSAbstractMethodDefinitionComputedName - | TSAbstractMethodDefinitionNonComputedName; -export type TSMethodSignature = - | TSMethodSignatureComputedName - | TSMethodSignatureNonComputedName; -export type TSPropertySignature = - | TSPropertySignatureComputedName - | TSPropertySignatureNonComputedName; -export type TSEnumMember = - | TSEnumMemberComputedName - | TSEnumMemberNonComputedName; -export type TSUnaryExpression = - | AwaitExpression - | LeftHandSideExpression - | TSTypeAssertion - | UnaryExpression - | UpdateExpression; -export type TypeElement = - | TSCallSignatureDeclaration - | TSConstructSignatureDeclaration - | TSIndexSignature - | TSMethodSignature - | TSPropertySignature; -export type TypeNode = - | TSAnyKeyword - | TSArrayType - | TSBigIntKeyword - | TSBooleanKeyword - | TSConditionalType - | TSConstructorType - | TSFunctionType - | TSImportType - | TSIndexedAccessType - | TSInferType - | TSInterfaceHeritage - | TSIntersectionType - | TSLiteralType - | TSMappedType - | TSNamedTupleMember - | TSNeverKeyword - | TSNullKeyword - | TSNumberKeyword - | TSObjectKeyword - | TSOptionalType - | TSParenthesizedType - | TSRestType - | TSStringKeyword - | TSSymbolKeyword - | TSTemplateLiteralType - | TSThisType - | TSTupleType - | TSTypeLiteral - | TSTypeOperator - | TSTypePredicate - | TSTypeQuery - | TSTypeReference - | TSUndefinedKeyword - | TSUnionType - | TSUnknownKeyword - | TSVoidKeyword; - -/////////////// -// Base, common types -// **Ensure you sort the interfaces alphabetically** -/////////////// - -interface BinaryExpressionBase extends BaseNode { - operator: string; - left: Expression; - right: Expression; -} + // TODO - make this change as a breaking change + /* + interface BaseNode { + parent: TSESTree.Node; + } -interface CallExpressionBase extends BaseNode { - callee: LeftHandSideExpression; - arguments: Expression[]; - typeParameters?: TSTypeParameterInstantiation; - optional: boolean; + interface Program { + parent?: undefined; + } + */ } -interface ClassDeclarationBase extends BaseNode { - typeParameters?: TSTypeParameterDeclaration; - superTypeParameters?: TSTypeParameterInstantiation; - id: Identifier | null; - body: ClassBody; - superClass: LeftHandSideExpression | null; - implements?: TSClassImplements[]; - abstract?: boolean; - declare?: boolean; - decorators?: Decorator[]; -} - -/** this should not be directly used - instead use ClassPropertyComputedNameBase or ClassPropertyNonComputedNameBase */ -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; -} - -interface ClassPropertyComputedNameBase extends ClassPropertyBase { - key: PropertyNameComputed; - computed: true; -} - -interface ClassPropertyNonComputedNameBase extends ClassPropertyBase { - key: PropertyNameNonComputed; - computed: false; -} - -interface FunctionDeclarationBase extends BaseNode { - id: Identifier | null; - generator: boolean; - expression: boolean; - async: boolean; - params: Parameter[]; - body?: BlockStatement | null; - returnType?: TSTypeAnnotation; - typeParameters?: TSTypeParameterDeclaration; - declare?: boolean; -} - -interface FunctionSignatureBase extends BaseNode { - params: Parameter[]; - returnType?: TSTypeAnnotation; - typeParameters?: TSTypeParameterDeclaration; -} - -interface LiteralBase extends BaseNode { - raw: string; - value: string | boolean | null | number | RegExp | bigint; - regex?: { - pattern: string; - flags: string; - }; -} - -/** this should not be directly used - instead use MemberExpressionComputedNameBase or MemberExpressionNonComputedNameBase */ -interface MemberExpressionBase extends BaseNode { - object: LeftHandSideExpression; - property: Expression | Identifier; - computed: boolean; - optional: boolean; -} - -interface MemberExpressionComputedNameBase extends MemberExpressionBase { - property: Expression; - computed: true; -} - -interface MemberExpressionNonComputedNameBase extends MemberExpressionBase { - property: Identifier; - computed: false; -} - -/** this should not be directly used - instead use MethodDefinitionComputedNameBase or MethodDefinitionNonComputedNameBase */ -interface MethodDefinitionBase extends BaseNode { - key: PropertyName; - value: FunctionExpression | TSEmptyBodyFunctionExpression; - computed: boolean; - static: boolean; - kind: 'method' | 'get' | 'set' | 'constructor'; - optional?: boolean; - decorators?: Decorator[]; - accessibility?: Accessibility; - typeParameters?: TSTypeParameterDeclaration; -} - -interface MethodDefinitionComputedNameBase extends MethodDefinitionBase { - key: PropertyNameComputed; - computed: true; -} - -interface MethodDefinitionNonComputedNameBase extends MethodDefinitionBase { - key: PropertyNameNonComputed; - computed: false; -} - -interface PropertyBase extends BaseNode { - type: AST_NODE_TYPES.Property; - key: PropertyName; - value: - | Expression - | AssignmentPattern - | BindingName - | TSEmptyBodyFunctionExpression; - computed: boolean; - method: boolean; - shorthand: boolean; - optional?: boolean; - kind: 'init' | 'get' | 'set'; -} - -interface TSEnumMemberBase extends BaseNode { - type: AST_NODE_TYPES.TSEnumMember; - id: - | PropertyNameNonComputed - // this should only happen in semantically invalid code (ts error 1164) - | PropertyNameComputed; - initializer?: Expression; - computed?: boolean; -} - -interface TSHeritageBase extends BaseNode { - expression: Expression; - typeParameters?: TSTypeParameterInstantiation; -} - -interface TSMethodSignatureBase extends BaseNode { - type: AST_NODE_TYPES.TSMethodSignature; - key: PropertyName; - computed: boolean; - params: Parameter[]; - optional?: boolean; - returnType?: TSTypeAnnotation; - readonly?: boolean; - typeParameters?: TSTypeParameterDeclaration; - accessibility?: Accessibility; - export?: boolean; - static?: boolean; -} - -interface TSPropertySignatureBase extends BaseNode { - type: AST_NODE_TYPES.TSPropertySignature; - key: PropertyName; - optional?: boolean; - computed: boolean; - typeAnnotation?: TSTypeAnnotation; - initializer?: Expression; - readonly?: boolean; - static?: boolean; - export?: boolean; - accessibility?: Accessibility; -} - -interface UnaryExpressionBase extends BaseNode { - operator: string; - prefix: boolean; - argument: LeftHandSideExpression | Literal | UnaryExpression; -} - -/////////////// -// Typescript ESTree Nodes -// **Ensure you sort the interfaces alphabetically** -/////////////// - -export interface ArrayExpression extends BaseNode { - type: AST_NODE_TYPES.ArrayExpression; - elements: Expression[]; -} - -export interface ArrayPattern extends BaseNode { - type: AST_NODE_TYPES.ArrayPattern; - elements: (DestructuringPattern | null)[]; - typeAnnotation?: TSTypeAnnotation; - optional?: boolean; - decorators?: Decorator[]; -} - -export interface ArrowFunctionExpression extends BaseNode { - type: AST_NODE_TYPES.ArrowFunctionExpression; - generator: boolean; - id: null; - params: Parameter[]; - body: Expression | BlockStatement; - async: boolean; - expression: boolean; - returnType?: TSTypeAnnotation; - typeParameters?: TSTypeParameterDeclaration; -} - -export interface AssignmentExpression extends BinaryExpressionBase { - type: AST_NODE_TYPES.AssignmentExpression; - operator: - | '-=' - | '??=' - | '**=' - | '*=' - | '/=' - | '&&=' - | '&=' - | '%=' - | '^=' - | '+=' - | '<<=' - | '=' - | '>>=' - | '>>>=' - | '|=' - | '||='; -} - -export interface AssignmentPattern extends BaseNode { - type: AST_NODE_TYPES.AssignmentPattern; - left: BindingName; - right: Expression; - typeAnnotation?: TSTypeAnnotation; - optional?: boolean; - decorators?: Decorator[]; -} - -export interface AwaitExpression extends BaseNode { - type: AST_NODE_TYPES.AwaitExpression; - argument: TSUnaryExpression; -} - -export interface BigIntLiteral extends LiteralBase { - type: AST_NODE_TYPES.Literal; - value: bigint | null; - bigint: string; -} - -export interface BinaryExpression extends BinaryExpressionBase { - type: AST_NODE_TYPES.BinaryExpression; -} - -export interface BlockStatement extends BaseNode { - type: AST_NODE_TYPES.BlockStatement; - body: Statement[]; -} - -export interface BooleanLiteral extends LiteralBase { - type: AST_NODE_TYPES.Literal; - value: boolean; -} - -export interface BreakStatement extends BaseNode { - type: AST_NODE_TYPES.BreakStatement; - label: Identifier | null; -} - -export interface ChainExpression extends BaseNode { - type: AST_NODE_TYPES.ChainExpression; - expression: ChainElement; -} - -export interface CallExpression extends CallExpressionBase { - type: AST_NODE_TYPES.CallExpression; -} - -export interface CatchClause extends BaseNode { - type: AST_NODE_TYPES.CatchClause; - param: BindingName | null; - body: BlockStatement; -} - -export interface ClassBody extends BaseNode { - type: AST_NODE_TYPES.ClassBody; - body: ClassElement[]; -} - -export interface ClassDeclaration extends ClassDeclarationBase { - type: AST_NODE_TYPES.ClassDeclaration; -} - -export interface ClassExpression extends ClassDeclarationBase { - type: AST_NODE_TYPES.ClassExpression; -} - -export interface ClassPropertyComputedName - extends ClassPropertyComputedNameBase { - type: AST_NODE_TYPES.ClassProperty; -} - -export interface ClassPropertyNonComputedName - extends ClassPropertyNonComputedNameBase { - type: AST_NODE_TYPES.ClassProperty; -} - -export interface ConditionalExpression extends BaseNode { - type: AST_NODE_TYPES.ConditionalExpression; - test: Expression; - consequent: Expression; - alternate: Expression; -} - -export interface ContinueStatement extends BaseNode { - type: AST_NODE_TYPES.ContinueStatement; - label: Identifier | null; -} - -export interface DebuggerStatement extends BaseNode { - type: AST_NODE_TYPES.DebuggerStatement; -} - -export interface Decorator extends BaseNode { - type: AST_NODE_TYPES.Decorator; - expression: LeftHandSideExpression; -} - -export interface DoWhileStatement extends BaseNode { - type: AST_NODE_TYPES.DoWhileStatement; - test: Expression; - body: Statement; -} - -export interface EmptyStatement extends BaseNode { - type: AST_NODE_TYPES.EmptyStatement; -} - -export interface ExportAllDeclaration extends BaseNode { - type: AST_NODE_TYPES.ExportAllDeclaration; - source: Expression | null; - exportKind: 'type' | 'value'; - exported: Identifier | null; -} - -export interface ExportDefaultDeclaration extends BaseNode { - type: AST_NODE_TYPES.ExportDefaultDeclaration; - declaration: ExportDeclaration | Expression; - exportKind: 'type' | 'value'; -} - -export interface ExportNamedDeclaration extends BaseNode { - type: AST_NODE_TYPES.ExportNamedDeclaration; - declaration: ExportDeclaration | null; - specifiers: ExportSpecifier[]; - source: Expression | null; - exportKind: 'type' | 'value'; -} - -export interface ExportSpecifier extends BaseNode { - type: AST_NODE_TYPES.ExportSpecifier; - local: Identifier; - exported: Identifier; -} - -export interface ExpressionStatement extends BaseNode { - type: AST_NODE_TYPES.ExpressionStatement; - expression: Expression; - directive?: string; -} - -export interface ForInStatement extends BaseNode { - type: AST_NODE_TYPES.ForInStatement; - left: ForInitialiser; - right: Expression; - body: Statement; -} - -export interface ForOfStatement extends BaseNode { - type: AST_NODE_TYPES.ForOfStatement; - left: ForInitialiser; - right: Expression; - body: Statement; - await: boolean; -} - -export interface ForStatement extends BaseNode { - type: AST_NODE_TYPES.ForStatement; - init: Expression | ForInitialiser | null; - test: Expression | null; - update: Expression | null; - body: Statement; -} - -export interface FunctionDeclaration extends FunctionDeclarationBase { - type: AST_NODE_TYPES.FunctionDeclaration; - body: BlockStatement; -} - -export interface FunctionExpression extends FunctionDeclarationBase { - type: AST_NODE_TYPES.FunctionExpression; - body: BlockStatement; -} - -export interface Identifier extends BaseNode { - type: AST_NODE_TYPES.Identifier; - name: string; - typeAnnotation?: TSTypeAnnotation; - optional?: boolean; - decorators?: Decorator[]; -} - -export interface IfStatement extends BaseNode { - type: AST_NODE_TYPES.IfStatement; - test: Expression; - consequent: Statement; - alternate: Statement | null; -} - -export interface ImportDeclaration extends BaseNode { - type: AST_NODE_TYPES.ImportDeclaration; - source: Literal; - specifiers: ImportClause[]; - importKind: 'type' | 'value'; -} - -export interface ImportDefaultSpecifier extends BaseNode { - type: AST_NODE_TYPES.ImportDefaultSpecifier; - local: Identifier; -} - -export interface ImportExpression extends BaseNode { - type: AST_NODE_TYPES.ImportExpression; - source: Expression; -} - -export interface ImportNamespaceSpecifier extends BaseNode { - type: AST_NODE_TYPES.ImportNamespaceSpecifier; - local: Identifier; -} - -export interface ImportSpecifier extends BaseNode { - type: AST_NODE_TYPES.ImportSpecifier; - local: Identifier; - imported: Identifier; -} - -export interface JSXAttribute extends BaseNode { - type: AST_NODE_TYPES.JSXAttribute; - name: JSXIdentifier; - value: Literal | JSXExpression | null; -} - -export interface JSXClosingElement extends BaseNode { - type: AST_NODE_TYPES.JSXClosingElement; - name: JSXTagNameExpression; -} - -export interface JSXClosingFragment extends BaseNode { - type: AST_NODE_TYPES.JSXClosingFragment; -} - -export interface JSXElement extends BaseNode { - type: AST_NODE_TYPES.JSXElement; - openingElement: JSXOpeningElement; - closingElement: JSXClosingElement | null; - children: JSXChild[]; -} - -export interface JSXEmptyExpression extends BaseNode { - type: AST_NODE_TYPES.JSXEmptyExpression; -} - -export interface JSXExpressionContainer extends BaseNode { - type: AST_NODE_TYPES.JSXExpressionContainer; - expression: Expression | JSXEmptyExpression; -} - -export interface JSXFragment extends BaseNode { - type: AST_NODE_TYPES.JSXFragment; - openingFragment: JSXOpeningFragment; - closingFragment: JSXClosingFragment; - children: JSXChild[]; -} - -export interface JSXIdentifier extends BaseNode { - type: AST_NODE_TYPES.JSXIdentifier; - name: string; -} - -export interface JSXMemberExpression extends BaseNode { - type: AST_NODE_TYPES.JSXMemberExpression; - object: JSXTagNameExpression; - property: JSXIdentifier; -} - -export interface JSXOpeningElement extends BaseNode { - type: AST_NODE_TYPES.JSXOpeningElement; - typeParameters?: TSTypeParameterInstantiation; - selfClosing: boolean; - name: JSXTagNameExpression; - attributes: JSXAttribute[]; -} - -export interface JSXOpeningFragment extends BaseNode { - type: AST_NODE_TYPES.JSXOpeningFragment; -} - -export interface JSXSpreadAttribute extends BaseNode { - type: AST_NODE_TYPES.JSXSpreadAttribute; - argument: Expression; -} - -export interface JSXSpreadChild extends BaseNode { - type: AST_NODE_TYPES.JSXSpreadChild; - expression: Expression | JSXEmptyExpression; -} - -export interface JSXText extends BaseNode { - type: AST_NODE_TYPES.JSXText; - value: string; - raw: string; -} - -export interface LabeledStatement extends BaseNode { - type: AST_NODE_TYPES.LabeledStatement; - label: Identifier; - body: Statement; -} - -export interface LogicalExpression extends BinaryExpressionBase { - type: AST_NODE_TYPES.LogicalExpression; -} - -export interface MemberExpressionComputedName - extends MemberExpressionComputedNameBase { - type: AST_NODE_TYPES.MemberExpression; -} - -export interface MemberExpressionNonComputedName - extends MemberExpressionNonComputedNameBase { - type: AST_NODE_TYPES.MemberExpression; -} - -export interface MetaProperty extends BaseNode { - type: AST_NODE_TYPES.MetaProperty; - meta: Identifier; - property: Identifier; -} - -export interface MethodDefinitionComputedName - extends MethodDefinitionComputedNameBase { - type: AST_NODE_TYPES.MethodDefinition; -} - -export interface MethodDefinitionNonComputedName - extends MethodDefinitionNonComputedNameBase { - type: AST_NODE_TYPES.MethodDefinition; -} - -export interface NewExpression extends BaseNode { - type: AST_NODE_TYPES.NewExpression; - callee: LeftHandSideExpression; - arguments: Expression[]; - typeParameters?: TSTypeParameterInstantiation; -} - -export interface NumberLiteral extends LiteralBase { - type: AST_NODE_TYPES.Literal; - value: number; -} - -export interface NullLiteral extends LiteralBase { - type: AST_NODE_TYPES.Literal; - value: null; -} - -export interface ObjectExpression extends BaseNode { - type: AST_NODE_TYPES.ObjectExpression; - properties: ObjectLiteralElementLike[]; -} - -export interface ObjectPattern extends BaseNode { - type: AST_NODE_TYPES.ObjectPattern; - properties: (Property | RestElement)[]; - typeAnnotation?: TSTypeAnnotation; - optional?: boolean; - decorators?: Decorator[]; -} - -export interface Program extends BaseNode { - type: AST_NODE_TYPES.Program; - body: ProgramStatement[]; - sourceType: 'module' | 'script'; - comments?: Comment[]; - tokens?: Token[]; -} - -export interface PropertyComputedName extends PropertyBase { - key: PropertyNameComputed; - computed: true; -} - -export interface PropertyNonComputedName extends PropertyBase { - key: PropertyNameNonComputed; - computed: false; -} - -export interface RegExpLiteral extends LiteralBase { - type: AST_NODE_TYPES.Literal; - value: RegExp; -} - -export interface RestElement extends BaseNode { - type: AST_NODE_TYPES.RestElement; - argument: DestructuringPattern; - typeAnnotation?: TSTypeAnnotation; - optional?: boolean; - value?: AssignmentPattern; - decorators?: Decorator[]; -} - -export interface ReturnStatement extends BaseNode { - type: AST_NODE_TYPES.ReturnStatement; - argument: Expression | null; -} - -export interface SequenceExpression extends BaseNode { - type: AST_NODE_TYPES.SequenceExpression; - expressions: Expression[]; -} - -export interface SpreadElement extends BaseNode { - type: AST_NODE_TYPES.SpreadElement; - argument: Expression; -} - -export interface StringLiteral extends LiteralBase { - type: AST_NODE_TYPES.Literal; - value: string; -} - -export interface Super extends BaseNode { - type: AST_NODE_TYPES.Super; -} - -export interface SwitchCase extends BaseNode { - type: AST_NODE_TYPES.SwitchCase; - test: Expression | null; - consequent: Statement[]; -} - -export interface SwitchStatement extends BaseNode { - type: AST_NODE_TYPES.SwitchStatement; - discriminant: Expression; - cases: SwitchCase[]; -} - -export interface TaggedTemplateExpression extends BaseNode { - type: AST_NODE_TYPES.TaggedTemplateExpression; - typeParameters?: TSTypeParameterInstantiation; - tag: LeftHandSideExpression; - quasi: TemplateLiteral; -} - -export interface TemplateElement extends BaseNode { - type: AST_NODE_TYPES.TemplateElement; - value: { - raw: string; - cooked: string; - }; - tail: boolean; -} - -export interface TemplateLiteral extends BaseNode { - type: AST_NODE_TYPES.TemplateLiteral; - quasis: TemplateElement[]; - expressions: Expression[]; -} - -export interface ThisExpression extends BaseNode { - type: AST_NODE_TYPES.ThisExpression; -} - -export interface ThrowStatement extends BaseNode { - type: AST_NODE_TYPES.ThrowStatement; - argument: Statement | TSAsExpression | null; -} - -export interface TryStatement extends BaseNode { - type: AST_NODE_TYPES.TryStatement; - block: BlockStatement; - handler: CatchClause | null; - finalizer: BlockStatement; -} - -export interface TSAbstractClassPropertyComputedName - extends ClassPropertyComputedNameBase { - type: AST_NODE_TYPES.TSAbstractClassProperty; -} - -export interface TSAbstractClassPropertyNonComputedName - extends ClassPropertyNonComputedNameBase { - type: AST_NODE_TYPES.TSAbstractClassProperty; -} - -export interface TSAbstractKeyword extends BaseNode { - type: AST_NODE_TYPES.TSAbstractKeyword; -} - -export interface TSAbstractMethodDefinitionComputedName - extends MethodDefinitionComputedNameBase { - type: AST_NODE_TYPES.TSAbstractMethodDefinition; -} - -export interface TSAbstractMethodDefinitionNonComputedName - extends MethodDefinitionNonComputedNameBase { - type: AST_NODE_TYPES.TSAbstractMethodDefinition; -} - -export interface TSAnyKeyword extends BaseNode { - type: AST_NODE_TYPES.TSAnyKeyword; -} - -export interface TSArrayType extends BaseNode { - type: AST_NODE_TYPES.TSArrayType; - elementType: TypeNode; -} - -export interface TSAsExpression extends BaseNode { - type: AST_NODE_TYPES.TSAsExpression; - expression: Expression; - typeAnnotation: TypeNode; -} - -export interface TSAsyncKeyword extends BaseNode { - type: AST_NODE_TYPES.TSAsyncKeyword; -} - -export interface TSBigIntKeyword extends BaseNode { - type: AST_NODE_TYPES.TSBigIntKeyword; -} - -export interface TSBooleanKeyword extends BaseNode { - type: AST_NODE_TYPES.TSBooleanKeyword; -} - -export interface TSCallSignatureDeclaration extends FunctionSignatureBase { - type: AST_NODE_TYPES.TSCallSignatureDeclaration; -} - -export interface TSClassImplements extends TSHeritageBase { - type: AST_NODE_TYPES.TSClassImplements; -} - -export interface TSConditionalType extends BaseNode { - type: AST_NODE_TYPES.TSConditionalType; - checkType: TypeNode; - extendsType: TypeNode; - trueType: TypeNode; - falseType: TypeNode; -} - -export interface TSConstructorType extends FunctionSignatureBase { - type: AST_NODE_TYPES.TSConstructorType; -} - -export interface TSConstructSignatureDeclaration extends FunctionSignatureBase { - type: AST_NODE_TYPES.TSConstructSignatureDeclaration; -} - -export interface TSDeclareFunction extends FunctionDeclarationBase { - type: AST_NODE_TYPES.TSDeclareFunction; -} - -export interface TSDeclareKeyword extends BaseNode { - type: AST_NODE_TYPES.TSDeclareKeyword; -} - -export interface TSEmptyBodyFunctionExpression extends FunctionDeclarationBase { - type: AST_NODE_TYPES.TSEmptyBodyFunctionExpression; - body: null; -} - -export interface TSEnumDeclaration extends BaseNode { - type: AST_NODE_TYPES.TSEnumDeclaration; - id: Identifier; - members: TSEnumMember[]; - const?: boolean; - declare?: boolean; - modifiers?: Modifier[]; -} - -/** - * this should only really happen in semantically invalid code (errors 1164 and 2452) - * - * VALID: - * enum Foo { ['a'] } - * - * INVALID: - * const x = 'a'; - * enum Foo { [x] } - * enum Bar { ['a' + 'b'] } - */ -export interface TSEnumMemberComputedName extends TSEnumMemberBase { - id: PropertyNameComputed; - computed: true; -} - -export interface TSEnumMemberNonComputedName extends TSEnumMemberBase { - id: PropertyNameNonComputed; - computed?: false; -} - -export interface TSExportAssignment extends BaseNode { - type: AST_NODE_TYPES.TSExportAssignment; - expression: Expression; -} - -export interface TSExportKeyword extends BaseNode { - type: AST_NODE_TYPES.TSExportKeyword; -} - -export interface TSExternalModuleReference extends BaseNode { - type: AST_NODE_TYPES.TSExternalModuleReference; - expression: Expression; -} - -export interface TSFunctionType extends FunctionSignatureBase { - type: AST_NODE_TYPES.TSFunctionType; -} - -export interface TSImportEqualsDeclaration extends BaseNode { - type: AST_NODE_TYPES.TSImportEqualsDeclaration; - id: Identifier; - moduleReference: EntityName | TSExternalModuleReference; - isExport: boolean; -} - -export interface TSImportType extends BaseNode { - type: AST_NODE_TYPES.TSImportType; - isTypeOf: boolean; - parameter: TypeNode; - qualifier: EntityName | null; - typeParameters: TSTypeParameterInstantiation | null; -} - -export interface TSIndexedAccessType extends BaseNode { - type: AST_NODE_TYPES.TSIndexedAccessType; - objectType: TypeNode; - indexType: TypeNode; -} - -export interface TSIndexSignature extends BaseNode { - type: AST_NODE_TYPES.TSIndexSignature; - parameters: Parameter[]; - typeAnnotation?: TSTypeAnnotation; - readonly?: boolean; - accessibility?: Accessibility; - export?: boolean; - static?: boolean; -} - -export interface TSInferType extends BaseNode { - type: AST_NODE_TYPES.TSInferType; - typeParameter: TSTypeParameter; -} - -export interface TSInterfaceDeclaration extends BaseNode { - type: AST_NODE_TYPES.TSInterfaceDeclaration; - body: TSInterfaceBody; - id: Identifier; - typeParameters?: TSTypeParameterDeclaration; - extends?: TSInterfaceHeritage[]; - implements?: TSInterfaceHeritage[]; - abstract?: boolean; - declare?: boolean; -} - -export interface TSInterfaceBody extends BaseNode { - type: AST_NODE_TYPES.TSInterfaceBody; - body: TypeElement[]; -} - -export interface TSInterfaceHeritage extends TSHeritageBase { - type: AST_NODE_TYPES.TSInterfaceHeritage; -} - -export interface TSIntersectionType extends BaseNode { - type: AST_NODE_TYPES.TSIntersectionType; - types: TypeNode[]; -} - -export interface TSLiteralType extends BaseNode { - type: AST_NODE_TYPES.TSLiteralType; - literal: LiteralExpression | UnaryExpression | UpdateExpression; -} - -export interface TSMappedType extends BaseNode { - type: AST_NODE_TYPES.TSMappedType; - typeParameter: TSTypeParameter; - readonly?: boolean | '-' | '+'; - optional?: boolean | '-' | '+'; - typeAnnotation?: TypeNode; - nameType: TypeNode | null; -} - -export interface TSMethodSignatureComputedName extends TSMethodSignatureBase { - key: PropertyNameComputed; - computed: true; -} - -export interface TSMethodSignatureNonComputedName - extends TSMethodSignatureBase { - key: PropertyNameNonComputed; - computed: false; -} - -export interface TSModuleBlock extends BaseNode { - type: AST_NODE_TYPES.TSModuleBlock; - body: ProgramStatement[]; -} - -export interface TSModuleDeclaration extends BaseNode { - type: AST_NODE_TYPES.TSModuleDeclaration; - id: Identifier | Literal; - body?: TSModuleBlock; - global?: boolean; - declare?: boolean; - modifiers?: Modifier[]; -} - -export interface TSNamedTupleMember extends BaseNode { - type: AST_NODE_TYPES.TSNamedTupleMember; - elementType: TypeNode; - label: Identifier; - optional: boolean; -} - -export interface TSNamespaceExportDeclaration extends BaseNode { - type: AST_NODE_TYPES.TSNamespaceExportDeclaration; - id: Identifier; -} - -export interface TSNeverKeyword extends BaseNode { - type: AST_NODE_TYPES.TSNeverKeyword; -} - -export interface TSNonNullExpression extends BaseNode { - type: AST_NODE_TYPES.TSNonNullExpression; - expression: Expression; -} - -export interface TSNullKeyword extends BaseNode { - type: AST_NODE_TYPES.TSNullKeyword; -} - -export interface TSNumberKeyword extends BaseNode { - type: AST_NODE_TYPES.TSNumberKeyword; -} - -export interface TSObjectKeyword extends BaseNode { - type: AST_NODE_TYPES.TSObjectKeyword; -} - -export interface TSOptionalType extends BaseNode { - type: AST_NODE_TYPES.TSOptionalType; - typeAnnotation: TypeNode; -} - -export interface TSParameterProperty extends BaseNode { - type: AST_NODE_TYPES.TSParameterProperty; - accessibility?: Accessibility; - readonly?: boolean; - static?: boolean; - export?: boolean; - parameter: AssignmentPattern | BindingName | RestElement; - decorators?: Decorator[]; -} - -export interface TSParenthesizedType extends BaseNode { - type: AST_NODE_TYPES.TSParenthesizedType; - typeAnnotation: TypeNode; -} - -export interface TSPropertySignatureComputedName - extends TSPropertySignatureBase { - key: PropertyNameComputed; - computed: true; -} - -export interface TSPropertySignatureNonComputedName - extends TSPropertySignatureBase { - key: PropertyNameNonComputed; - computed: false; -} - -export interface TSPublicKeyword extends BaseNode { - type: AST_NODE_TYPES.TSPublicKeyword; -} - -export interface TSPrivateKeyword extends BaseNode { - type: AST_NODE_TYPES.TSPrivateKeyword; -} - -export interface TSProtectedKeyword extends BaseNode { - type: AST_NODE_TYPES.TSProtectedKeyword; -} - -export interface TSQualifiedName extends BaseNode { - type: AST_NODE_TYPES.TSQualifiedName; - left: EntityName; - right: Identifier; -} - -export interface TSReadonlyKeyword extends BaseNode { - type: AST_NODE_TYPES.TSReadonlyKeyword; -} - -export interface TSRestType extends BaseNode { - type: AST_NODE_TYPES.TSRestType; - typeAnnotation: TypeNode; -} - -export interface TSStaticKeyword extends BaseNode { - type: AST_NODE_TYPES.TSStaticKeyword; -} - -export interface TSStringKeyword extends BaseNode { - type: AST_NODE_TYPES.TSStringKeyword; -} - -export interface TSSymbolKeyword extends BaseNode { - type: AST_NODE_TYPES.TSSymbolKeyword; -} - -export interface TSTemplateLiteralType extends BaseNode { - type: AST_NODE_TYPES.TSTemplateLiteralType; - quasis: TemplateElement[]; - types: TypeNode[]; -} - -export interface TSThisType extends BaseNode { - type: AST_NODE_TYPES.TSThisType; -} - -export interface TSTupleType extends BaseNode { - type: AST_NODE_TYPES.TSTupleType; - elementTypes: TypeNode[]; -} - -export interface TSTypeAliasDeclaration extends BaseNode { - type: AST_NODE_TYPES.TSTypeAliasDeclaration; - id: Identifier; - typeAnnotation: TypeNode; - declare?: boolean; - typeParameters?: TSTypeParameterDeclaration; -} - -export interface TSTypeAnnotation extends BaseNode { - type: AST_NODE_TYPES.TSTypeAnnotation; - typeAnnotation: TypeNode; -} - -export interface TSTypeAssertion extends BaseNode { - type: AST_NODE_TYPES.TSTypeAssertion; - typeAnnotation: TypeNode; - expression: Expression; -} - -export interface TSTypeLiteral extends BaseNode { - type: AST_NODE_TYPES.TSTypeLiteral; - members: TypeElement[]; -} - -export interface TSTypeOperator extends BaseNode { - type: AST_NODE_TYPES.TSTypeOperator; - operator: 'keyof' | 'unique' | 'readonly'; - typeAnnotation?: TypeNode; -} - -export interface TSTypeParameter extends BaseNode { - type: AST_NODE_TYPES.TSTypeParameter; - name: Identifier; - constraint?: TypeNode; - default?: TypeNode; -} - -export interface TSTypeParameterDeclaration extends BaseNode { - type: AST_NODE_TYPES.TSTypeParameterDeclaration; - params: TSTypeParameter[]; -} - -export interface TSTypeParameterInstantiation extends BaseNode { - type: AST_NODE_TYPES.TSTypeParameterInstantiation; - params: TypeNode[]; -} - -export interface TSTypePredicate extends BaseNode { - type: AST_NODE_TYPES.TSTypePredicate; - asserts: boolean; - parameterName: Identifier | TSThisType; - typeAnnotation: TSTypeAnnotation | null; -} - -export interface TSTypeQuery extends BaseNode { - type: AST_NODE_TYPES.TSTypeQuery; - exprName: EntityName; -} - -export interface TSTypeReference extends BaseNode { - type: AST_NODE_TYPES.TSTypeReference; - typeName: EntityName; - typeParameters?: TSTypeParameterInstantiation; -} - -export interface TSUndefinedKeyword extends BaseNode { - type: AST_NODE_TYPES.TSUndefinedKeyword; -} - -export interface TSUnionType extends BaseNode { - type: AST_NODE_TYPES.TSUnionType; - types: TypeNode[]; -} - -export interface TSUnknownKeyword extends BaseNode { - type: AST_NODE_TYPES.TSUnknownKeyword; -} - -export interface TSVoidKeyword extends BaseNode { - type: AST_NODE_TYPES.TSVoidKeyword; -} - -export interface UpdateExpression extends UnaryExpressionBase { - type: AST_NODE_TYPES.UpdateExpression; - operator: '++' | '--'; -} - -export interface UnaryExpression extends UnaryExpressionBase { - type: AST_NODE_TYPES.UnaryExpression; - operator: '+' | '-' | '!' | '~' | 'delete' | 'void' | 'typeof'; -} - -export interface VariableDeclaration extends BaseNode { - type: AST_NODE_TYPES.VariableDeclaration; - // NOTE - this is not guaranteed to have any elements in it. i.e. `const;` - declarations: VariableDeclarator[]; - kind: 'let' | 'const' | 'var'; - declare?: boolean; -} - -export interface VariableDeclarator extends BaseNode { - type: AST_NODE_TYPES.VariableDeclarator; - id: BindingName; - init: Expression | null; - definite?: boolean; -} - -export interface WhileStatement extends BaseNode { - type: AST_NODE_TYPES.WhileStatement; - test: Expression; - body: Statement; -} - -export interface WithStatement extends BaseNode { - type: AST_NODE_TYPES.WithStatement; - object: Expression; - body: Statement; -} - -export interface YieldExpression extends BaseNode { - type: AST_NODE_TYPES.YieldExpression; - delegate: boolean; - argument?: Expression; -} +export * as TSESTree from '@typescript-eslint/ast-spec/dist/spec'; diff --git a/packages/types/tsconfig.build.json b/packages/types/tsconfig.build.json index 215a0282df2b..d3ebde33a315 100644 --- a/packages/types/tsconfig.build.json +++ b/packages/types/tsconfig.build.json @@ -6,5 +6,6 @@ "rootDir": "./src", "resolveJsonModule": true }, - "include": ["src", "typings"] + "include": ["src", "typings"], + "references": [{ "path": "../ast-spec/tsconfig.build.json" }] } diff --git a/packages/types/tsconfig.json b/packages/types/tsconfig.json index 9cea515ba6b2..3b3fadc288cf 100644 --- a/packages/types/tsconfig.json +++ b/packages/types/tsconfig.json @@ -4,5 +4,6 @@ "composite": false, "rootDir": "." }, - "include": ["src", "typings", "tests", "tools"] + "include": ["src", "typings", "tests", "tools"], + "references": [{ "path": "../ast-spec/tsconfig.build.json" }] } diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 4fac62a901a8..1ae143f704c0 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -34,7 +34,7 @@ "build": "tsc -b tsconfig.build.json", "postbuild": "downlevel-dts dist _ts3.4/dist", "clean": "tsc -b tsconfig.build.json --clean", - "postclean": "rimraf dist", + "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'", "test": "jest --coverage", diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index a22eae1a5df5..681f0074764d 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1921,7 +1921,7 @@ export class Converter { // Literals case SyntaxKind.StringLiteral: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.Literal, raw: '', value: '', @@ -1936,7 +1936,7 @@ export class Converter { } case SyntaxKind.NumericLiteral: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, value: Number(node.text), raw: node.getText(), @@ -1969,11 +1969,11 @@ export class Converter { let regex = null; try { regex = new RegExp(pattern, flags); - } catch (exception) { + } catch (exception: unknown) { regex = null; } - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, value: regex, raw: node.text, @@ -1985,14 +1985,14 @@ export class Converter { } case SyntaxKind.TrueKeyword: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, value: true, raw: 'true', }); case SyntaxKind.FalseKeyword: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, value: false, raw: 'false', @@ -2006,7 +2006,7 @@ export class Converter { }); } - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, value: null, raw: 'null', @@ -2150,7 +2150,7 @@ export class Converter { range: [start, end], }); } else { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, value: this.ast.text.slice(start, end), raw: this.ast.text.slice(start, end), diff --git a/packages/visitor-keys/package.json b/packages/visitor-keys/package.json index 2e61912c234a..8ab0cfb66017 100644 --- a/packages/visitor-keys/package.json +++ b/packages/visitor-keys/package.json @@ -31,7 +31,7 @@ "build": "tsc -b tsconfig.build.json", "postbuild": "downlevel-dts dist _ts3.4/dist", "clean": "tsc -b tsconfig.build.json --clean", - "postclean": "rimraf dist", + "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'", "test": "jest --coverage", diff --git a/tests/integration/docker-compose.yml b/tests/integration/docker-compose.yml index abe82a67cfb6..b1df8c206699 100644 --- a/tests/integration/docker-compose.yml +++ b/tests/integration/docker-compose.yml @@ -22,9 +22,11 @@ services: - ../../packages/types/:/usr/types - /usr/types/tests - ../../packages/visitor-keys/:/usr/visitor-keys - - /usr/types/visitor-keys + - /usr/visitor-keys/tests - ../../packages/scope-manager/:/usr/scope-manager - - /usr/types/scope-manager + - /usr/scope-manager/tests + - ../../packages/ast-spec/:/usr/ast-spec + - /usr/ast-spec/tests # Runtime link to all the specific integration test files, so that most updates don't require a rebuild. - ./fixtures/typescript-and-tslint-plugins-together:/usr/linked @@ -47,9 +49,11 @@ services: - ../../packages/types/:/usr/types - /usr/types/tests - ../../packages/visitor-keys/:/usr/visitor-keys - - /usr/types/visitor-keys + - /usr/visitor-keys/tests - ../../packages/scope-manager/:/usr/scope-manager - - /usr/types/scope-manager + - /usr/scope-manager/tests + - ../../packages/ast-spec/:/usr/ast-spec + - /usr/ast-spec/tests # Runtime link to all the specific integration test files, so that most updates don't require a rebuild. - ./fixtures/vue-sfc:/usr/linked @@ -72,9 +76,11 @@ services: - ../../packages/types/:/usr/types - /usr/types/tests - ../../packages/visitor-keys/:/usr/visitor-keys - - /usr/types/visitor-keys + - /usr/visitor-keys/tests - ../../packages/scope-manager/:/usr/scope-manager - - /usr/types/scope-manager + - /usr/scope-manager/tests + - ../../packages/ast-spec/:/usr/ast-spec + - /usr/ast-spec/tests # Runtime link to all the specific integration test files, so that most updates don't require a rebuild. - ./fixtures/vue-jsx:/usr/linked @@ -97,9 +103,11 @@ services: - ../../packages/types/:/usr/types - /usr/types/tests - ../../packages/visitor-keys/:/usr/visitor-keys - - /usr/types/visitor-keys + - /usr/visitor-keys/tests - ../../packages/scope-manager/:/usr/scope-manager - - /usr/types/scope-manager + - /usr/scope-manager/tests + - ../../packages/ast-spec/:/usr/ast-spec + - /usr/ast-spec/tests # Runtime link to all the specific integration test files, so that most updates don't require a rebuild. - ./fixtures/recommended-does-not-require-program:/usr/linked @@ -122,9 +130,11 @@ services: - ../../packages/types/:/usr/types - /usr/types/tests - ../../packages/visitor-keys/:/usr/visitor-keys - - /usr/types/visitor-keys + - /usr/visitor-keys/tests - ../../packages/scope-manager/:/usr/scope-manager - - /usr/types/scope-manager + - /usr/scope-manager/tests + - ../../packages/ast-spec/:/usr/ast-spec + - /usr/ast-spec/tests # Runtime link to all the specific integration test files, so that most updates don't require a rebuild. - ./fixtures/markdown:/usr/linked @@ -147,8 +157,10 @@ services: - ../../packages/types/:/usr/types - /usr/types/tests - ../../packages/visitor-keys/:/usr/visitor-keys - - /usr/types/visitor-keys + - /usr/visitor-keys/tests - ../../packages/scope-manager/:/usr/scope-manager - - /usr/types/scope-manager + - /usr/scope-manager/tests + - ../../packages/ast-spec/:/usr/ast-spec + - /usr/ast-spec/tests # Runtime link to all the specific integration test files, so that most updates don't require a rebuild. - ./fixtures/eslint-v6:/usr/linked diff --git a/tests/integration/fixtures/eslint-v6/test.sh b/tests/integration/fixtures/eslint-v6/test.sh index ab184f9ceb15..e2c988854164 100755 --- a/tests/integration/fixtures/eslint-v6/test.sh +++ b/tests/integration/fixtures/eslint-v6/test.sh @@ -9,6 +9,7 @@ npm install npm install eslint@6.0.0 # Use the local volumes for our own packages +npm install $(npm pack /usr/ast-spec | tail -1) npm install $(npm pack /usr/types | tail -1) npm install $(npm pack /usr/visitor-keys | tail -1) npm install $(npm pack /usr/scope-manager | tail -1) diff --git a/tests/integration/fixtures/markdown/test.sh b/tests/integration/fixtures/markdown/test.sh index 30cd435eaac7..91e4c4f0a045 100755 --- a/tests/integration/fixtures/markdown/test.sh +++ b/tests/integration/fixtures/markdown/test.sh @@ -8,6 +8,7 @@ node /usr/utils/generate-package-json.js npm install # Use the local volumes for our own packages +npm install $(npm pack /usr/ast-spec | tail -1) npm install $(npm pack /usr/types | tail -1) npm install $(npm pack /usr/visitor-keys | tail -1) npm install $(npm pack /usr/scope-manager | tail -1) diff --git a/tests/integration/fixtures/recommended-does-not-require-program/test.sh b/tests/integration/fixtures/recommended-does-not-require-program/test.sh index cfe4d0e6d570..ea25b6d7292d 100755 --- a/tests/integration/fixtures/recommended-does-not-require-program/test.sh +++ b/tests/integration/fixtures/recommended-does-not-require-program/test.sh @@ -8,6 +8,7 @@ node /usr/utils/generate-package-json.js npm install # Use the local volumes for our own packages +npm install $(npm pack /usr/ast-spec | tail -1) npm install $(npm pack /usr/types | tail -1) npm install $(npm pack /usr/visitor-keys | tail -1) npm install $(npm pack /usr/scope-manager | tail -1) diff --git a/tests/integration/fixtures/typescript-and-tslint-plugins-together/test.sh b/tests/integration/fixtures/typescript-and-tslint-plugins-together/test.sh index 6abbeb42aa61..27c243e38081 100755 --- a/tests/integration/fixtures/typescript-and-tslint-plugins-together/test.sh +++ b/tests/integration/fixtures/typescript-and-tslint-plugins-together/test.sh @@ -8,6 +8,7 @@ node /usr/utils/generate-package-json.js npm install # Use the local volumes for our own packages +npm install $(npm pack /usr/ast-spec | tail -1) npm install $(npm pack /usr/types | tail -1) npm install $(npm pack /usr/visitor-keys | tail -1) npm install $(npm pack /usr/scope-manager | tail -1) diff --git a/tests/integration/fixtures/vue-jsx/test.sh b/tests/integration/fixtures/vue-jsx/test.sh index 96376fb0f83c..fc41933a87ec 100755 --- a/tests/integration/fixtures/vue-jsx/test.sh +++ b/tests/integration/fixtures/vue-jsx/test.sh @@ -8,6 +8,7 @@ node /usr/utils/generate-package-json.js npm install # Use the local volumes for our own packages +npm install $(npm pack /usr/ast-spec | tail -1) npm install $(npm pack /usr/types | tail -1) npm install $(npm pack /usr/visitor-keys | tail -1) npm install $(npm pack /usr/scope-manager | tail -1) diff --git a/tests/integration/fixtures/vue-sfc/test.sh b/tests/integration/fixtures/vue-sfc/test.sh index 80f7cfe4adf4..e22a51a62c62 100755 --- a/tests/integration/fixtures/vue-sfc/test.sh +++ b/tests/integration/fixtures/vue-sfc/test.sh @@ -8,6 +8,7 @@ node /usr/utils/generate-package-json.js npm install # Use the local volumes for our own packages +npm install $(npm pack /usr/ast-spec | tail -1) npm install $(npm pack /usr/types | tail -1) npm install $(npm pack /usr/visitor-keys | tail -1) npm install $(npm pack /usr/scope-manager | tail -1) diff --git a/yarn.lock b/yarn.lock index d518c0ccfd72..e37a5cecf719 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3738,6 +3738,11 @@ eslint-plugin-jest@^23.20.0: dependencies: "@typescript-eslint/experimental-utils" "^2.5.0" +eslint-plugin-simple-import-sort@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-7.0.0.tgz#a1dad262f46d2184a90095a60c66fef74727f0f8" + integrity sha512-U3vEDB5zhYPNfxT5TYR7u01dboFZp+HNpnGhkDB2g/2E4wZ/g1Q9Ton8UwCLfRV9yAKyYqDh62oHOamvkFxsvw== + eslint-scope@^5.0.0, eslint-scope@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.0.tgz#d0f971dfe59c69e0cada684b23d49dbf82600ce5"