From c35d7216949e085e6bb3139da71cf35a4b5fa51a Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 20 Aug 2024 14:11:28 -0400 Subject: [PATCH 1/2] chore: enable eslint-plugin-perfectionist on ast-spec package --- eslint.config.mjs | 14 +++- packages/ast-spec/src/ast-node-types.ts | 5 +- packages/ast-spec/src/base/LiteralBase.ts | 2 +- .../ast-spec/src/base/MethodDefinitionBase.ts | 16 ++--- .../ast-spec/src/base/OptionalRangeAndLoc.ts | 9 +-- packages/ast-spec/src/base/Position.ts | 8 +-- .../src/base/PropertyDefinitionBase.ts | 20 +++--- packages/ast-spec/src/base/SourceLocation.ts | 8 +-- .../ast-spec/src/base/UnaryExpressionBase.ts | 2 +- .../declaration/ExportAllDeclaration/spec.ts | 2 +- .../ExportDefaultDeclaration/spec.ts | 2 +- .../ExportNamedDeclaration/spec.ts | 2 +- .../declaration/FunctionDeclaration/spec.ts | 2 +- .../src/declaration/ImportDeclaration/spec.ts | 2 +- .../src/declaration/TSDeclareFunction/spec.ts | 2 +- .../src/declaration/TSEnumDeclaration/spec.ts | 2 +- .../TSImportEqualsDeclaration/spec.ts | 28 ++++---- .../TSInterfaceDeclaration/spec.ts | 2 +- .../declaration/TSModuleDeclaration/spec.ts | 62 ++++++++-------- .../TSNamespaceExportDeclaration/spec.ts | 2 +- .../TSTypeAliasDeclaration/spec.ts | 2 +- .../declaration/VariableDeclaration/spec.ts | 14 ++-- .../ast-spec/src/element/Property/spec.ts | 16 ++--- .../src/element/SpreadElement/spec.ts | 2 +- .../ast-spec/src/element/StaticBlock/spec.ts | 2 +- .../ast-spec/src/element/TSEnumMember/spec.ts | 8 +-- .../src/element/TSIndexSignature/spec.ts | 6 +- .../src/element/TSMethodSignature/spec.ts | 6 +- .../src/element/TSPropertySignature/spec.ts | 12 ++-- packages/ast-spec/src/element/spec.ts | 4 +- .../src/expression/ArrayExpression/spec.ts | 2 +- .../ArrowFunctionExpression/spec.ts | 8 +-- .../AssignmentOperatorToText.ts | 24 +++---- .../expression/AssignmentExpression/spec.ts | 4 +- .../src/expression/AwaitExpression/spec.ts | 2 +- .../BinaryExpression/BinaryOperatorToText.ts | 40 +++++------ .../src/expression/BinaryExpression/spec.ts | 4 +- .../src/expression/CallExpression/spec.ts | 6 +- .../src/expression/ChainExpression/spec.ts | 2 +- .../src/expression/ClassExpression/spec.ts | 2 +- .../expression/ConditionalExpression/spec.ts | 6 +- .../src/expression/FunctionExpression/spec.ts | 2 +- .../src/expression/Identifier/spec.ts | 6 +- .../src/expression/ImportExpression/spec.ts | 4 +- .../src/expression/JSXElement/spec.ts | 6 +- .../src/expression/JSXFragment/spec.ts | 6 +- .../src/expression/LogicalExpression/spec.ts | 4 +- .../src/expression/MemberExpression/spec.ts | 12 ++-- .../src/expression/MetaProperty/spec.ts | 2 +- .../src/expression/NewExpression/spec.ts | 4 +- .../src/expression/ObjectExpression/spec.ts | 2 +- .../src/expression/SequenceExpression/spec.ts | 2 +- .../src/expression/TSAsExpression/spec.ts | 2 +- .../TSEmptyBodyFunctionExpression/spec.ts | 2 +- .../TSInstantiationExpression/spec.ts | 2 +- .../expression/TSNonNullExpression/spec.ts | 2 +- .../expression/TSSatisfiesExpression/spec.ts | 2 +- .../src/expression/TSTypeAssertion/spec.ts | 2 +- .../src/expression/TemplateLiteral/spec.ts | 4 +- .../src/expression/UnaryExpression/spec.ts | 2 +- .../src/expression/UpdateExpression/spec.ts | 2 +- .../src/expression/YieldExpression/spec.ts | 4 +- .../expression/literal/BigIntLiteral/spec.ts | 2 +- .../expression/literal/BooleanLiteral/spec.ts | 2 +- .../expression/literal/NullLiteral/spec.ts | 2 +- .../expression/literal/RegExpLiteral/spec.ts | 4 +- packages/ast-spec/src/expression/spec.ts | 9 ++- packages/ast-spec/src/index.ts | 27 ++++--- .../ast-spec/src/jsx/JSXAttribute/spec.ts | 2 +- .../src/jsx/JSXClosingElement/spec.ts | 2 +- .../src/jsx/JSXExpressionContainer/spec.ts | 2 +- .../ast-spec/src/jsx/JSXIdentifier/spec.ts | 2 +- .../src/jsx/JSXMemberExpression/spec.ts | 2 +- .../src/jsx/JSXNamespacedName/spec.ts | 4 +- .../src/jsx/JSXOpeningElement/spec.ts | 6 +- .../src/jsx/JSXSpreadAttribute/spec.ts | 2 +- .../ast-spec/src/jsx/JSXSpreadChild/spec.ts | 2 +- packages/ast-spec/src/jsx/JSXText/spec.ts | 2 +- .../src/parameter/ArrayPattern/spec.ts | 6 +- .../src/parameter/AssignmentPattern/spec.ts | 6 +- .../src/parameter/ObjectPattern/spec.ts | 6 +- .../src/parameter/RestElement/spec.ts | 6 +- .../src/parameter/TSParameterProperty/spec.ts | 8 +-- .../ast-spec/src/special/CatchClause/spec.ts | 4 +- .../ast-spec/src/special/ClassBody/spec.ts | 2 +- .../ast-spec/src/special/Decorator/spec.ts | 2 +- .../src/special/ExportSpecifier/spec.ts | 4 +- .../src/special/ImportAttribute/spec.ts | 2 +- .../special/ImportDefaultSpecifier/spec.ts | 2 +- .../special/ImportNamespaceSpecifier/spec.ts | 2 +- .../src/special/ImportSpecifier/spec.ts | 4 +- .../src/special/PrivateIdentifier/spec.ts | 2 +- packages/ast-spec/src/special/Program/spec.ts | 4 +- .../ast-spec/src/special/SwitchCase/spec.ts | 4 +- .../ast-spec/src/special/TSEnumBody/spec.ts | 2 +- .../special/TSExternalModuleReference/spec.ts | 2 +- .../src/special/TSInterfaceBody/spec.ts | 2 +- .../src/special/TSModuleBlock/spec.ts | 2 +- .../src/special/TSTypeParameter/spec.ts | 6 +- .../TSTypeParameterDeclaration/spec.ts | 2 +- .../TSTypeParameterInstantiation/spec.ts | 2 +- .../src/special/TemplateElement/spec.ts | 4 +- .../src/special/VariableDeclarator/spec.ts | 22 +++--- packages/ast-spec/src/special/spec.ts | 2 +- .../src/statement/BlockStatement/spec.ts | 2 +- .../src/statement/BreakStatement/spec.ts | 2 +- .../src/statement/ContinueStatement/spec.ts | 2 +- .../src/statement/DoWhileStatement/spec.ts | 4 +- .../src/statement/ExpressionStatement/spec.ts | 4 +- .../src/statement/ForInStatement/spec.ts | 4 +- .../src/statement/ForOfStatement/spec.ts | 6 +- .../src/statement/ForStatement/spec.ts | 4 +- .../src/statement/IfStatement/spec.ts | 6 +- .../src/statement/LabeledStatement/spec.ts | 4 +- .../src/statement/ReturnStatement/spec.ts | 2 +- .../src/statement/SwitchStatement/spec.ts | 4 +- .../src/statement/TSExportAssignment/spec.ts | 2 +- .../src/statement/ThrowStatement/spec.ts | 2 +- .../src/statement/TryStatement/spec.ts | 4 +- .../src/statement/WhileStatement/spec.ts | 4 +- .../src/statement/WithStatement/spec.ts | 4 +- packages/ast-spec/src/statement/spec.ts | 2 +- .../PunctuatorToken/PunctuatorTokenToText.ts | 72 +++++++++---------- .../src/token/RegularExpressionToken/spec.ts | 4 +- .../ast-spec/src/type/TSArrayType/spec.ts | 2 +- .../src/type/TSConditionalType/spec.ts | 4 +- .../src/type/TSConstructorType/spec.ts | 2 +- .../ast-spec/src/type/TSImportType/spec.ts | 2 +- .../src/type/TSIndexedAccessType/spec.ts | 4 +- .../ast-spec/src/type/TSLiteralType/spec.ts | 2 +- .../ast-spec/src/type/TSMappedType/spec.ts | 14 ++-- .../src/type/TSNamedTupleMember/spec.ts | 2 +- .../ast-spec/src/type/TSQualifiedName/spec.ts | 2 +- .../src/type/TSTemplateLiteralType/spec.ts | 2 +- .../ast-spec/src/type/TSTupleType/spec.ts | 2 +- .../ast-spec/src/type/TSTypeLiteral/spec.ts | 2 +- .../ast-spec/src/type/TSTypeOperator/spec.ts | 2 +- .../ast-spec/src/type/TSTypePredicate/spec.ts | 2 +- .../ast-spec/src/type/TSTypeQuery/spec.ts | 2 +- packages/ast-spec/tests/fixtures.test.ts | 58 +++++++-------- packages/ast-spec/tests/util/parsers/babel.ts | 8 ++- .../tests/util/parsers/parser-types.ts | 18 ++--- .../tests/util/parsers/typescript-estree.ts | 7 +- .../ast-spec/tests/util/serialize-error.ts | 8 +-- .../ast-spec/tests/util/serializers/Node.ts | 9 +-- .../ast-spec/tests/util/serializers/string.ts | 6 +- packages/ast-spec/tests/util/snapshot-diff.ts | 4 +- .../ast-spec/typings/babel-eslint-parser.d.ts | 2 +- 148 files changed, 465 insertions(+), 459 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 60b302d8cb50..053f17b3d5bf 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -578,8 +578,12 @@ export default tseslint.config( }, { extends: [perfectionistPlugin.configs['recommended-alphabetical']], - files: ['packages/utils/src/**/*.ts'], + files: [ + 'packages/ast-spec/{src,tests,typings}/**/*.ts', + 'packages/utils/src/**/*.ts', + ], rules: { + '@typescript-eslint/sort-type-constituents': 'off', 'perfectionist/sort-classes': [ 'error', { @@ -588,6 +592,14 @@ export default tseslint.config( type: 'natural', }, ], + 'perfectionist/sort-enums': [ + 'error', + { + order: 'asc', + partitionByComment: true, + type: 'natural', + }, + ], 'perfectionist/sort-objects': [ 'error', { diff --git a/packages/ast-spec/src/ast-node-types.ts b/packages/ast-spec/src/ast-node-types.ts index ea4b3207f116..bf65ba722091 100644 --- a/packages/ast-spec/src/ast-node-types.ts +++ b/packages/ast-spec/src/ast-node-types.ts @@ -90,7 +90,6 @@ export enum AST_NODE_TYPES { YieldExpression = 'YieldExpression', // TS_prefixed nodes - TSAbstractAccessorProperty = 'TSAbstractAccessorProperty', TSAbstractKeyword = 'TSAbstractKeyword', TSAbstractMethodDefinition = 'TSAbstractMethodDefinition', @@ -109,19 +108,19 @@ export enum AST_NODE_TYPES { TSDeclareFunction = 'TSDeclareFunction', TSDeclareKeyword = 'TSDeclareKeyword', TSEmptyBodyFunctionExpression = 'TSEmptyBodyFunctionExpression', - TSEnumDeclaration = 'TSEnumDeclaration', TSEnumBody = 'TSEnumBody', + TSEnumDeclaration = 'TSEnumDeclaration', TSEnumMember = 'TSEnumMember', TSExportAssignment = 'TSExportAssignment', TSExportKeyword = 'TSExportKeyword', TSExternalModuleReference = 'TSExternalModuleReference', TSFunctionType = 'TSFunctionType', - TSInstantiationExpression = 'TSInstantiationExpression', TSImportEqualsDeclaration = 'TSImportEqualsDeclaration', TSImportType = 'TSImportType', TSIndexedAccessType = 'TSIndexedAccessType', TSIndexSignature = 'TSIndexSignature', TSInferType = 'TSInferType', + TSInstantiationExpression = 'TSInstantiationExpression', TSInterfaceBody = 'TSInterfaceBody', TSInterfaceDeclaration = 'TSInterfaceDeclaration', TSInterfaceHeritage = 'TSInterfaceHeritage', diff --git a/packages/ast-spec/src/base/LiteralBase.ts b/packages/ast-spec/src/base/LiteralBase.ts index c878fe7b7aa5..52d17c496b9b 100644 --- a/packages/ast-spec/src/base/LiteralBase.ts +++ b/packages/ast-spec/src/base/LiteralBase.ts @@ -2,7 +2,7 @@ import type { AST_NODE_TYPES } from '../ast-node-types'; import type { BaseNode } from './BaseNode'; export interface LiteralBase extends BaseNode { - type: AST_NODE_TYPES.Literal; raw: string; + type: AST_NODE_TYPES.Literal; value: RegExp | bigint | boolean | number | string | null; } diff --git a/packages/ast-spec/src/base/MethodDefinitionBase.ts b/packages/ast-spec/src/base/MethodDefinitionBase.ts index f2815458d58c..fedd2ca46a49 100644 --- a/packages/ast-spec/src/base/MethodDefinitionBase.ts +++ b/packages/ast-spec/src/base/MethodDefinitionBase.ts @@ -12,30 +12,30 @@ 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; + accessibility: Accessibility | undefined; computed: boolean; - static: boolean; + decorators: Decorator[]; + key: PropertyName; kind: 'constructor' | 'get' | 'method' | 'set'; optional: boolean; - decorators: Decorator[]; - accessibility: Accessibility | undefined; override: boolean; + static: boolean; + value: FunctionExpression | TSEmptyBodyFunctionExpression; } export interface MethodDefinitionComputedNameBase extends MethodDefinitionBase { - key: PropertyNameComputed; computed: true; + key: PropertyNameComputed; } export interface MethodDefinitionNonComputedNameBase extends MethodDefinitionBase { - key: PropertyNameNonComputed; computed: false; + key: PropertyNameNonComputed; } export interface ClassMethodDefinitionNonComputedNameBase extends MethodDefinitionBase { - key: ClassPropertyNameNonComputed; computed: false; + key: ClassPropertyNameNonComputed; } diff --git a/packages/ast-spec/src/base/OptionalRangeAndLoc.ts b/packages/ast-spec/src/base/OptionalRangeAndLoc.ts index d9b8cc9f874d..96fae9597ac8 100644 --- a/packages/ast-spec/src/base/OptionalRangeAndLoc.ts +++ b/packages/ast-spec/src/base/OptionalRangeAndLoc.ts @@ -2,10 +2,7 @@ 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; +export type OptionalRangeAndLoc = { loc?: SourceLocation; -}; + range?: Range; +} & Pick>; diff --git a/packages/ast-spec/src/base/Position.ts b/packages/ast-spec/src/base/Position.ts index 672fe5d5d4d0..5a8bc7af3355 100644 --- a/packages/ast-spec/src/base/Position.ts +++ b/packages/ast-spec/src/base/Position.ts @@ -1,10 +1,10 @@ export interface Position { - /** - * Line number (1-indexed) - */ - line: number; /** * Column number on the line (0-indexed) */ column: number; + /** + * Line number (1-indexed) + */ + line: number; } diff --git a/packages/ast-spec/src/base/PropertyDefinitionBase.ts b/packages/ast-spec/src/base/PropertyDefinitionBase.ts index a379ac922427..ab53ca53c21f 100644 --- a/packages/ast-spec/src/base/PropertyDefinitionBase.ts +++ b/packages/ast-spec/src/base/PropertyDefinitionBase.ts @@ -11,34 +11,34 @@ import type { Accessibility } from './Accessibility'; import type { BaseNode } from './BaseNode'; interface PropertyDefinitionBase extends BaseNode { - key: PropertyName; - value: Expression | null; + accessibility: Accessibility | undefined; computed: boolean; - static: boolean; declare: boolean; - readonly: boolean; decorators: Decorator[]; - accessibility: Accessibility | undefined; - optional: boolean; definite: boolean; - typeAnnotation: TSTypeAnnotation | undefined; + key: PropertyName; + optional: boolean; override: boolean; + readonly: boolean; + static: boolean; + typeAnnotation: TSTypeAnnotation | undefined; + value: Expression | null; } export interface PropertyDefinitionComputedNameBase extends PropertyDefinitionBase { - key: PropertyNameComputed; computed: true; + key: PropertyNameComputed; } export interface PropertyDefinitionNonComputedNameBase extends PropertyDefinitionBase { - key: PropertyNameNonComputed; computed: false; + key: PropertyNameNonComputed; } export interface ClassPropertyDefinitionNonComputedNameBase extends PropertyDefinitionBase { - key: ClassPropertyNameNonComputed; computed: false; + key: ClassPropertyNameNonComputed; } diff --git a/packages/ast-spec/src/base/SourceLocation.ts b/packages/ast-spec/src/base/SourceLocation.ts index 67b5246fed5d..e0a9ac6ee97f 100644 --- a/packages/ast-spec/src/base/SourceLocation.ts +++ b/packages/ast-spec/src/base/SourceLocation.ts @@ -1,12 +1,12 @@ import type { Position } from './Position'; export interface SourceLocation { - /** - * The position of the first character of the parsed source region - */ - start: Position; /** * The position of the first character after the parsed source region */ end: Position; + /** + * The position of the first character of the parsed source region + */ + start: Position; } diff --git a/packages/ast-spec/src/base/UnaryExpressionBase.ts b/packages/ast-spec/src/base/UnaryExpressionBase.ts index 6401c7e73fb2..354dcedb08db 100644 --- a/packages/ast-spec/src/base/UnaryExpressionBase.ts +++ b/packages/ast-spec/src/base/UnaryExpressionBase.ts @@ -2,7 +2,7 @@ import type { Expression } from '../unions/Expression'; import type { BaseNode } from './BaseNode'; export interface UnaryExpressionBase extends BaseNode { + argument: Expression; operator: string; prefix: boolean; - argument: Expression; } diff --git a/packages/ast-spec/src/declaration/ExportAllDeclaration/spec.ts b/packages/ast-spec/src/declaration/ExportAllDeclaration/spec.ts index 5c397c3ceb02..e4dd0c3710f4 100644 --- a/packages/ast-spec/src/declaration/ExportAllDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/ExportAllDeclaration/spec.ts @@ -6,7 +6,6 @@ import type { ImportAttribute } from '../../special/ImportAttribute/spec'; import type { ExportKind } from '../ExportAndImportKind'; export interface ExportAllDeclaration extends BaseNode { - type: AST_NODE_TYPES.ExportAllDeclaration; /** * The assertions declared for the export. * @example @@ -36,4 +35,5 @@ export interface ExportAllDeclaration extends BaseNode { * The source module being exported from. */ source: StringLiteral; + type: AST_NODE_TYPES.ExportAllDeclaration; } diff --git a/packages/ast-spec/src/declaration/ExportDefaultDeclaration/spec.ts b/packages/ast-spec/src/declaration/ExportDefaultDeclaration/spec.ts index d0e750211d6f..b33bdb26098d 100644 --- a/packages/ast-spec/src/declaration/ExportDefaultDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/ExportDefaultDeclaration/spec.ts @@ -3,7 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { DefaultExportDeclarations } from '../../unions/ExportDeclaration'; export interface ExportDefaultDeclaration extends BaseNode { - type: AST_NODE_TYPES.ExportDefaultDeclaration; /** * The declaration being exported. */ @@ -12,4 +11,5 @@ export interface ExportDefaultDeclaration extends BaseNode { * The kind of the export. Always `value` for default exports. */ exportKind: 'value'; + type: AST_NODE_TYPES.ExportDefaultDeclaration; } diff --git a/packages/ast-spec/src/declaration/ExportNamedDeclaration/spec.ts b/packages/ast-spec/src/declaration/ExportNamedDeclaration/spec.ts index 79c266d9b5fc..58329b91f309 100644 --- a/packages/ast-spec/src/declaration/ExportNamedDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/ExportNamedDeclaration/spec.ts @@ -7,7 +7,6 @@ import type { NamedExportDeclarations } from '../../unions/ExportDeclaration'; import type { ExportKind } from '../ExportAndImportKind'; interface ExportNamedDeclarationBase extends BaseNode { - type: AST_NODE_TYPES.ExportNamedDeclaration; /** * The assertions declared for the export. * @example @@ -53,6 +52,7 @@ interface ExportNamedDeclarationBase extends BaseNode { * This will be an empty array if `declaration` is not `null` */ specifiers: ExportSpecifier[]; + type: AST_NODE_TYPES.ExportNamedDeclaration; } /** diff --git a/packages/ast-spec/src/declaration/FunctionDeclaration/spec.ts b/packages/ast-spec/src/declaration/FunctionDeclaration/spec.ts index 78264715da0e..2059b331c45c 100644 --- a/packages/ast-spec/src/declaration/FunctionDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/FunctionDeclaration/spec.ts @@ -4,10 +4,10 @@ import type { Identifier } from '../../expression/Identifier/spec'; import type { BlockStatement } from '../../statement/BlockStatement/spec'; interface FunctionDeclarationBase extends FunctionBase { - type: AST_NODE_TYPES.FunctionDeclaration; body: BlockStatement; declare: false; expression: false; + type: AST_NODE_TYPES.FunctionDeclaration; } /** diff --git a/packages/ast-spec/src/declaration/ImportDeclaration/spec.ts b/packages/ast-spec/src/declaration/ImportDeclaration/spec.ts index 6ef26630fbb7..e3d200f850f7 100644 --- a/packages/ast-spec/src/declaration/ImportDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/ImportDeclaration/spec.ts @@ -6,7 +6,6 @@ import type { ImportClause } from '../../unions/ImportClause'; import type { ImportKind } from '../ExportAndImportKind'; export interface ImportDeclaration extends BaseNode { - type: AST_NODE_TYPES.ImportDeclaration; /** * The assertions declared for the export. * @example @@ -44,4 +43,5 @@ export interface ImportDeclaration extends BaseNode { * ``` */ specifiers: ImportClause[]; + type: AST_NODE_TYPES.ImportDeclaration; } diff --git a/packages/ast-spec/src/declaration/TSDeclareFunction/spec.ts b/packages/ast-spec/src/declaration/TSDeclareFunction/spec.ts index ab75a908aa87..55dad7af54c8 100644 --- a/packages/ast-spec/src/declaration/TSDeclareFunction/spec.ts +++ b/packages/ast-spec/src/declaration/TSDeclareFunction/spec.ts @@ -2,7 +2,6 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { FunctionBase } from '../../base/FunctionBase'; interface TSDeclareFunctionBase extends FunctionBase { - type: AST_NODE_TYPES.TSDeclareFunction; /** * TS1183: An implementation cannot be declared in ambient contexts. */ @@ -12,6 +11,7 @@ interface TSDeclareFunctionBase extends FunctionBase { */ declare: boolean; expression: false; + type: AST_NODE_TYPES.TSDeclareFunction; } /** diff --git a/packages/ast-spec/src/declaration/TSEnumDeclaration/spec.ts b/packages/ast-spec/src/declaration/TSEnumDeclaration/spec.ts index e10a95f7e902..6c818a4655bc 100644 --- a/packages/ast-spec/src/declaration/TSEnumDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/TSEnumDeclaration/spec.ts @@ -5,7 +5,6 @@ import type { Identifier } from '../../expression/Identifier/spec'; import type { TSEnumBody } from '../../special/TSEnumBody/spec'; export interface TSEnumDeclaration extends BaseNode { - type: AST_NODE_TYPES.TSEnumDeclaration; /** * The body of the enum. */ @@ -35,4 +34,5 @@ export interface TSEnumDeclaration extends BaseNode { * @deprecated Use {@link body} instead. */ members: TSEnumMember[]; + type: AST_NODE_TYPES.TSEnumDeclaration; } diff --git a/packages/ast-spec/src/declaration/TSImportEqualsDeclaration/spec.ts b/packages/ast-spec/src/declaration/TSImportEqualsDeclaration/spec.ts index 617a020b8368..1ba5e12eff5d 100644 --- a/packages/ast-spec/src/declaration/TSImportEqualsDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/TSImportEqualsDeclaration/spec.ts @@ -6,11 +6,15 @@ import type { TSQualifiedName } from '../../type/TSQualifiedName/spec'; import type { ImportKind } from '../ExportAndImportKind'; interface TSImportEqualsDeclarationBase extends BaseNode { - type: AST_NODE_TYPES.TSImportEqualsDeclaration; /** * The locally imported name. */ id: Identifier; + /** + * The kind of the import. Always `'value'` unless `moduleReference` is a + * `TSExternalModuleReference`. + */ + importKind: ImportKind; /** * The value being aliased. * @example @@ -21,15 +25,15 @@ interface TSImportEqualsDeclarationBase extends BaseNode { * ``` */ moduleReference: Identifier | TSExternalModuleReference | TSQualifiedName; - /** - * The kind of the import. Always `'value'` unless `moduleReference` is a - * `TSExternalModuleReference`. - */ - importKind: ImportKind; + type: AST_NODE_TYPES.TSImportEqualsDeclaration; } export interface TSImportEqualsNamespaceDeclaration extends TSImportEqualsDeclarationBase { + /** + * The kind of the import. + */ + importKind: 'value'; /** * The value being aliased. * ``` @@ -38,14 +42,14 @@ export interface TSImportEqualsNamespaceDeclaration * ``` */ moduleReference: Identifier | TSQualifiedName; - /** - * The kind of the import. - */ - importKind: 'value'; } export interface TSImportEqualsRequireDeclaration extends TSImportEqualsDeclarationBase { + /** + * The kind of the import. + */ + importKind: ImportKind; /** * The value being aliased. * ``` @@ -53,10 +57,6 @@ export interface TSImportEqualsRequireDeclaration * ``` */ moduleReference: TSExternalModuleReference; - /** - * The kind of the import. - */ - importKind: ImportKind; } export type TSImportEqualsDeclaration = diff --git a/packages/ast-spec/src/declaration/TSInterfaceDeclaration/spec.ts b/packages/ast-spec/src/declaration/TSInterfaceDeclaration/spec.ts index 545160dd34dd..0b42e52142ad 100644 --- a/packages/ast-spec/src/declaration/TSInterfaceDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/TSInterfaceDeclaration/spec.ts @@ -6,7 +6,6 @@ import type { TSInterfaceHeritage } from '../../special/TSInterfaceHeritage/spec import type { TSTypeParameterDeclaration } from '../../special/TSTypeParameterDeclaration/spec'; export interface TSInterfaceDeclaration extends BaseNode { - type: AST_NODE_TYPES.TSInterfaceDeclaration; /** * The body of the interface */ @@ -23,6 +22,7 @@ export interface TSInterfaceDeclaration extends BaseNode { * The name of this interface */ id: Identifier; + type: AST_NODE_TYPES.TSInterfaceDeclaration; /** * The generic type parameters declared for the interface. Empty declaration * (`<>`) is different from no declaration. diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts b/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts index e745b1015c94..3c47fd1e449b 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts @@ -9,41 +9,39 @@ import type { Literal } from '../../unions/Literal'; export type TSModuleDeclarationKind = 'global' | 'module' | 'namespace'; interface TSModuleDeclarationBase extends BaseNode { - type: AST_NODE_TYPES.TSModuleDeclaration; - /** - * The name of the module - * ``` - * namespace A {} - * namespace A.B.C {} - * module 'a' {} - * ``` - */ - id: Identifier | Literal | TSQualifiedName; /** * The body of the module. * This can only be `undefined` for the code `declare module 'mod';` */ body?: TSModuleBlock; /** - * Whether this is a global declaration + * Whether the module is `declare`d * @example * ```ts - * declare global {} + * declare namespace F {} * ``` - * - * @deprecated Use {@link kind} instead */ + declare: boolean; // TODO - remove this in the next major (we have `.kind` now) global: boolean; /** - * Whether the module is `declare`d + * Whether this is a global declaration * @example * ```ts - * declare namespace F {} + * declare global {} * ``` + * + * @deprecated Use {@link kind} instead */ - declare: boolean; - + /** + * The name of the module + * ``` + * namespace A {} + * namespace A.B.C {} + * module 'a' {} + * ``` + */ + id: Identifier | Literal | TSQualifiedName; /** * The keyword used to define this module declaration * @example @@ -59,21 +57,23 @@ interface TSModuleDeclarationBase extends BaseNode { * ``` */ kind: TSModuleDeclarationKind; + + type: AST_NODE_TYPES.TSModuleDeclaration; } export interface TSModuleDeclarationNamespace extends TSModuleDeclarationBase { - kind: 'namespace'; - id: Identifier | TSQualifiedName; body: TSModuleBlock; + id: Identifier | TSQualifiedName; + kind: 'namespace'; } export interface TSModuleDeclarationGlobal extends TSModuleDeclarationBase { - kind: 'global'; + body: TSModuleBlock; /** * This will always be an Identifier with name `global` */ id: Identifier; - body: TSModuleBlock; + kind: 'global'; } interface TSModuleDeclarationModuleBase extends TSModuleDeclarationBase { @@ -88,10 +88,10 @@ interface TSModuleDeclarationModuleBase extends TSModuleDeclarationBase { */ export interface TSModuleDeclarationModuleWithStringIdNotDeclared extends TSModuleDeclarationModuleBase { - kind: 'module'; - id: StringLiteral; - declare: false; body: TSModuleBlock; + declare: false; + id: StringLiteral; + kind: 'module'; } /** * A string module declaration that is declared: @@ -102,10 +102,10 @@ export interface TSModuleDeclarationModuleWithStringIdNotDeclared */ export interface TSModuleDeclarationModuleWithStringIdDeclared extends TSModuleDeclarationModuleBase { - kind: 'module'; - id: StringLiteral; - declare: true; body?: TSModuleBlock; + declare: true; + id: StringLiteral; + kind: 'module'; } /** * The legacy module declaration, replaced with namespace declarations. @@ -115,12 +115,12 @@ export interface TSModuleDeclarationModuleWithStringIdDeclared */ export interface TSModuleDeclarationModuleWithIdentifierId extends TSModuleDeclarationModuleBase { - kind: 'module'; + // Maybe not worth fixing since it's legacy + body: TSModuleBlock; id: Identifier; // TODO: we emit the wrong AST for `module A.B {}` // https://github.com/typescript-eslint/typescript-eslint/pull/6272 only fixed namespaces - // Maybe not worth fixing since it's legacy - body: TSModuleBlock; + kind: 'module'; } export type TSModuleDeclarationModuleWithStringId = diff --git a/packages/ast-spec/src/declaration/TSNamespaceExportDeclaration/spec.ts b/packages/ast-spec/src/declaration/TSNamespaceExportDeclaration/spec.ts index 183af4e80efc..5b50d9686d1e 100644 --- a/packages/ast-spec/src/declaration/TSNamespaceExportDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/TSNamespaceExportDeclaration/spec.ts @@ -9,9 +9,9 @@ import type { Identifier } from '../../expression/Identifier/spec'; * ``` */ export interface TSNamespaceExportDeclaration extends BaseNode { - type: AST_NODE_TYPES.TSNamespaceExportDeclaration; /** * The name of the global variable that's exported as namespace */ id: Identifier; + type: AST_NODE_TYPES.TSNamespaceExportDeclaration; } diff --git a/packages/ast-spec/src/declaration/TSTypeAliasDeclaration/spec.ts b/packages/ast-spec/src/declaration/TSTypeAliasDeclaration/spec.ts index b2a9d248b73e..5f52ec5d9016 100644 --- a/packages/ast-spec/src/declaration/TSTypeAliasDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/TSTypeAliasDeclaration/spec.ts @@ -5,7 +5,6 @@ import type { TSTypeParameterDeclaration } from '../../special/TSTypeParameterDe import type { TypeNode } from '../../unions/TypeNode'; export interface TSTypeAliasDeclaration extends BaseNode { - type: AST_NODE_TYPES.TSTypeAliasDeclaration; /** * Whether the type was `declare`d. * @example @@ -18,6 +17,7 @@ export interface TSTypeAliasDeclaration extends BaseNode { * The name of the type. */ id: Identifier; + type: AST_NODE_TYPES.TSTypeAliasDeclaration; /** * The "value" (type) of the declaration */ diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts index cc2eb3f3eed3..55fca8d49c31 100644 --- a/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/VariableDeclaration/spec.ts @@ -10,7 +10,6 @@ import type { } from '../../special/VariableDeclarator/spec'; interface LetOrConstOrVarDeclarationBase extends BaseNode { - type: AST_NODE_TYPES.VariableDeclaration; /** * The variables declared by this declaration. * Always non-empty. @@ -39,12 +38,11 @@ interface LetOrConstOrVarDeclarationBase extends BaseNode { * ``` */ kind: 'const' | 'let' | 'var'; + type: AST_NODE_TYPES.VariableDeclaration; } export interface LetOrVarDeclaredDeclaration extends LetOrConstOrVarDeclarationBase { - kind: 'let' | 'var'; - declare: true; /** * In a `declare let` declaration, the declarators must not have definite assignment * assertions or initializers. @@ -56,12 +54,12 @@ export interface LetOrVarDeclaredDeclaration * ``` */ declarations: VariableDeclaratorNoInit[]; + declare: true; + kind: 'let' | 'var'; } export interface LetOrVarNonDeclaredDeclaration extends LetOrConstOrVarDeclarationBase { - kind: 'let' | 'var'; - declare: false; /** * In a `let`/`var` declaration, the declarators may have definite assignment * assertions or initializers, but not both. @@ -70,10 +68,11 @@ export interface LetOrVarNonDeclaredDeclaration | VariableDeclaratorDefiniteAssignment | VariableDeclaratorMaybeInit )[]; + declare: false; + kind: 'let' | 'var'; } export interface ConstDeclaration extends LetOrConstOrVarDeclarationBase { - kind: 'const'; /** * In a `declare const` declaration, the declarators may have initializers, but * not definite assignment assertions. Each declarator cannot have both an @@ -83,6 +82,7 @@ export interface ConstDeclaration extends LetOrConstOrVarDeclarationBase { * no initializer. */ declarations: VariableDeclaratorMaybeInit[]; + kind: 'const'; } export type LetOrConstOrVarDeclaration = @@ -91,7 +91,6 @@ export type LetOrConstOrVarDeclaration = | LetOrVarNonDeclaredDeclaration; interface UsingDeclarationBase extends BaseNode { - type: AST_NODE_TYPES.VariableDeclaration; /** * This value will always be `false` * because 'declare' modifier cannot appear on a 'using' declaration. @@ -106,6 +105,7 @@ interface UsingDeclarationBase extends BaseNode { * ``` */ kind: 'await using' | 'using'; + type: AST_NODE_TYPES.VariableDeclaration; } export interface UsingInNormalContextDeclaration extends UsingDeclarationBase { diff --git a/packages/ast-spec/src/element/Property/spec.ts b/packages/ast-spec/src/element/Property/spec.ts index e10b6b464358..d550d3610507 100644 --- a/packages/ast-spec/src/element/Property/spec.ts +++ b/packages/ast-spec/src/element/Property/spec.ts @@ -11,27 +11,27 @@ import type { } from '../../unions/PropertyName'; interface PropertyBase extends BaseNode { - type: AST_NODE_TYPES.Property; + computed: boolean; key: PropertyName; + kind: 'get' | 'init' | 'set'; + method: boolean; + optional: boolean; + shorthand: boolean; + type: AST_NODE_TYPES.Property; 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; + key: PropertyNameComputed; } export interface PropertyNonComputedName extends PropertyBase { - key: PropertyNameNonComputed; computed: false; + key: PropertyNameNonComputed; } 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 index 13a691901710..cd48c6dd390f 100644 --- a/packages/ast-spec/src/element/SpreadElement/spec.ts +++ b/packages/ast-spec/src/element/SpreadElement/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { Expression } from '../../unions/Expression'; export interface SpreadElement extends BaseNode { - type: AST_NODE_TYPES.SpreadElement; argument: Expression; + type: AST_NODE_TYPES.SpreadElement; } diff --git a/packages/ast-spec/src/element/StaticBlock/spec.ts b/packages/ast-spec/src/element/StaticBlock/spec.ts index 526a5f65f6d8..3af22c439f21 100644 --- a/packages/ast-spec/src/element/StaticBlock/spec.ts +++ b/packages/ast-spec/src/element/StaticBlock/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { Statement } from '../../unions/Statement'; export interface StaticBlock extends BaseNode { - type: AST_NODE_TYPES.StaticBlock; body: Statement[]; + type: AST_NODE_TYPES.StaticBlock; } diff --git a/packages/ast-spec/src/element/TSEnumMember/spec.ts b/packages/ast-spec/src/element/TSEnumMember/spec.ts index ba5b81a13b1a..78aba458bc22 100644 --- a/packages/ast-spec/src/element/TSEnumMember/spec.ts +++ b/packages/ast-spec/src/element/TSEnumMember/spec.ts @@ -7,12 +7,12 @@ import type { } from '../../unions/PropertyName'; interface TSEnumMemberBase extends BaseNode { - type: AST_NODE_TYPES.TSEnumMember; + computed: boolean; id: | PropertyNameComputed // this should only happen in semantically invalid code (ts error 1164) | PropertyNameNonComputed; initializer: Expression | undefined; - computed: boolean; + type: AST_NODE_TYPES.TSEnumMember; } /** @@ -30,13 +30,13 @@ interface TSEnumMemberBase extends BaseNode { * ``` */ export interface TSEnumMemberComputedName extends TSEnumMemberBase { - id: PropertyNameComputed; computed: true; + id: PropertyNameComputed; } export interface TSEnumMemberNonComputedName extends TSEnumMemberBase { - id: PropertyNameNonComputed; computed: false; + id: PropertyNameNonComputed; } export type TSEnumMember = diff --git a/packages/ast-spec/src/element/TSIndexSignature/spec.ts b/packages/ast-spec/src/element/TSIndexSignature/spec.ts index 4f514e757147..12b49ab2af56 100644 --- a/packages/ast-spec/src/element/TSIndexSignature/spec.ts +++ b/packages/ast-spec/src/element/TSIndexSignature/spec.ts @@ -5,10 +5,10 @@ import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; import type { Parameter } from '../../unions/Parameter'; export interface TSIndexSignature extends BaseNode { - type: AST_NODE_TYPES.TSIndexSignature; + accessibility: Accessibility | undefined; parameters: Parameter[]; - typeAnnotation: TSTypeAnnotation | undefined; readonly: boolean; - accessibility: Accessibility | undefined; static: boolean; + type: AST_NODE_TYPES.TSIndexSignature; + typeAnnotation: TSTypeAnnotation | undefined; } diff --git a/packages/ast-spec/src/element/TSMethodSignature/spec.ts b/packages/ast-spec/src/element/TSMethodSignature/spec.ts index 9f75ee603c97..80a1011625be 100644 --- a/packages/ast-spec/src/element/TSMethodSignature/spec.ts +++ b/packages/ast-spec/src/element/TSMethodSignature/spec.ts @@ -11,7 +11,6 @@ import type { } from '../../unions/PropertyName'; interface TSMethodSignatureBase extends BaseNode { - type: AST_NODE_TYPES.TSMethodSignature; accessibility: Accessibility | undefined; computed: boolean; key: PropertyName; @@ -21,17 +20,18 @@ interface TSMethodSignatureBase extends BaseNode { readonly: boolean; returnType: TSTypeAnnotation | undefined; static: boolean; + type: AST_NODE_TYPES.TSMethodSignature; typeParameters: TSTypeParameterDeclaration | undefined; } export interface TSMethodSignatureComputedName extends TSMethodSignatureBase { - key: PropertyNameComputed; computed: true; + key: PropertyNameComputed; } export interface TSMethodSignatureNonComputedName extends TSMethodSignatureBase { - key: PropertyNameNonComputed; computed: false; + key: PropertyNameNonComputed; } export type TSMethodSignature = diff --git a/packages/ast-spec/src/element/TSPropertySignature/spec.ts b/packages/ast-spec/src/element/TSPropertySignature/spec.ts index e695085ca408..4f4aca808d3b 100644 --- a/packages/ast-spec/src/element/TSPropertySignature/spec.ts +++ b/packages/ast-spec/src/element/TSPropertySignature/spec.ts @@ -9,26 +9,26 @@ import type { } from '../../unions/PropertyName'; interface TSPropertySignatureBase extends BaseNode { - type: AST_NODE_TYPES.TSPropertySignature; + accessibility: Accessibility | undefined; + computed: boolean; key: PropertyName; optional: boolean; - computed: boolean; - typeAnnotation: TSTypeAnnotation | undefined; readonly: boolean; static: boolean; - accessibility: Accessibility | undefined; + type: AST_NODE_TYPES.TSPropertySignature; + typeAnnotation: TSTypeAnnotation | undefined; } export interface TSPropertySignatureComputedName extends TSPropertySignatureBase { - key: PropertyNameComputed; computed: true; + key: PropertyNameComputed; } export interface TSPropertySignatureNonComputedName extends TSPropertySignatureBase { - key: PropertyNameNonComputed; computed: false; + key: PropertyNameNonComputed; } export type TSPropertySignature = diff --git a/packages/ast-spec/src/element/spec.ts b/packages/ast-spec/src/element/spec.ts index eeecc41028cb..6edf6efe39af 100644 --- a/packages/ast-spec/src/element/spec.ts +++ b/packages/ast-spec/src/element/spec.ts @@ -1,12 +1,12 @@ export * from './AccessorProperty/spec'; -export * from './PropertyDefinition/spec'; export * from './MethodDefinition/spec'; export * from './Property/spec'; +export * from './PropertyDefinition/spec'; export * from './SpreadElement/spec'; export * from './StaticBlock/spec'; export * from './TSAbstractAccessorProperty/spec'; -export * from './TSAbstractPropertyDefinition/spec'; export * from './TSAbstractMethodDefinition/spec'; +export * from './TSAbstractPropertyDefinition/spec'; export * from './TSCallSignatureDeclaration/spec'; export * from './TSConstructSignatureDeclaration/spec'; export * from './TSEnumMember/spec'; diff --git a/packages/ast-spec/src/expression/ArrayExpression/spec.ts b/packages/ast-spec/src/expression/ArrayExpression/spec.ts index 3dccf5c6ab8a..3a904afddcff 100644 --- a/packages/ast-spec/src/expression/ArrayExpression/spec.ts +++ b/packages/ast-spec/src/expression/ArrayExpression/spec.ts @@ -4,9 +4,9 @@ import type { SpreadElement } from '../../element/SpreadElement/spec'; import type { Expression } from '../../unions/Expression'; export interface ArrayExpression extends BaseNode { - type: AST_NODE_TYPES.ArrayExpression; /** * an element will be `null` in the case of a sparse array: `[1, ,3]` */ elements: (Expression | SpreadElement | null)[]; + type: AST_NODE_TYPES.ArrayExpression; } diff --git a/packages/ast-spec/src/expression/ArrowFunctionExpression/spec.ts b/packages/ast-spec/src/expression/ArrowFunctionExpression/spec.ts index 8532636554a7..f86c2cf1f712 100644 --- a/packages/ast-spec/src/expression/ArrowFunctionExpression/spec.ts +++ b/packages/ast-spec/src/expression/ArrowFunctionExpression/spec.ts @@ -7,13 +7,13 @@ import type { Expression } from '../../unions/Expression'; import type { Parameter } from '../../unions/Parameter'; export interface ArrowFunctionExpression extends BaseNode { - type: AST_NODE_TYPES.ArrowFunctionExpression; + async: boolean; + body: BlockStatement | Expression; + expression: boolean; generator: boolean; id: null; params: Parameter[]; - body: BlockStatement | Expression; - async: boolean; - expression: boolean; returnType: TSTypeAnnotation | undefined; + type: AST_NODE_TYPES.ArrowFunctionExpression; typeParameters: TSTypeParameterDeclaration | undefined; } diff --git a/packages/ast-spec/src/expression/AssignmentExpression/AssignmentOperatorToText.ts b/packages/ast-spec/src/expression/AssignmentExpression/AssignmentOperatorToText.ts index 9cebd34b8df2..858c7a9e2a17 100644 --- a/packages/ast-spec/src/expression/AssignmentExpression/AssignmentOperatorToText.ts +++ b/packages/ast-spec/src/expression/AssignmentExpression/AssignmentOperatorToText.ts @@ -1,20 +1,20 @@ import type { SyntaxKind } from 'typescript'; export interface AssignmentOperatorToText { - [SyntaxKind.EqualsToken]: '='; - [SyntaxKind.PlusEqualsToken]: '+='; - [SyntaxKind.MinusEqualsToken]: '-='; - [SyntaxKind.AsteriskEqualsToken]: '*='; + [SyntaxKind.AmpersandAmpersandEqualsToken]: '&&='; + [SyntaxKind.AmpersandEqualsToken]: '&='; [SyntaxKind.AsteriskAsteriskEqualsToken]: '**='; - [SyntaxKind.SlashEqualsToken]: '/='; - [SyntaxKind.PercentEqualsToken]: '%='; - [SyntaxKind.LessThanLessThanEqualsToken]: '<<='; + [SyntaxKind.AsteriskEqualsToken]: '*='; + [SyntaxKind.BarBarEqualsToken]: '||='; + [SyntaxKind.BarEqualsToken]: '|='; + [SyntaxKind.CaretEqualsToken]: '^='; + [SyntaxKind.EqualsToken]: '='; [SyntaxKind.GreaterThanGreaterThanEqualsToken]: '>>='; [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: '>>>='; - [SyntaxKind.AmpersandEqualsToken]: '&='; - [SyntaxKind.BarEqualsToken]: '|='; - [SyntaxKind.BarBarEqualsToken]: '||='; - [SyntaxKind.AmpersandAmpersandEqualsToken]: '&&='; + [SyntaxKind.LessThanLessThanEqualsToken]: '<<='; + [SyntaxKind.MinusEqualsToken]: '-='; + [SyntaxKind.PercentEqualsToken]: '%='; + [SyntaxKind.PlusEqualsToken]: '+='; [SyntaxKind.QuestionQuestionEqualsToken]: '??='; - [SyntaxKind.CaretEqualsToken]: '^='; + [SyntaxKind.SlashEqualsToken]: '/='; } diff --git a/packages/ast-spec/src/expression/AssignmentExpression/spec.ts b/packages/ast-spec/src/expression/AssignmentExpression/spec.ts index cbe97f55e519..d4cfeea7ef28 100644 --- a/packages/ast-spec/src/expression/AssignmentExpression/spec.ts +++ b/packages/ast-spec/src/expression/AssignmentExpression/spec.ts @@ -7,8 +7,8 @@ import type { AssignmentOperatorToText } from './AssignmentOperatorToText'; export * from './AssignmentOperatorToText'; export interface AssignmentExpression extends BaseNode { - type: AST_NODE_TYPES.AssignmentExpression; - operator: ValueOf; left: Expression; + operator: ValueOf; right: Expression; + type: AST_NODE_TYPES.AssignmentExpression; } diff --git a/packages/ast-spec/src/expression/AwaitExpression/spec.ts b/packages/ast-spec/src/expression/AwaitExpression/spec.ts index c476c916a335..173ee879bd7d 100644 --- a/packages/ast-spec/src/expression/AwaitExpression/spec.ts +++ b/packages/ast-spec/src/expression/AwaitExpression/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { Expression } from '../../unions/Expression'; export interface AwaitExpression extends BaseNode { - type: AST_NODE_TYPES.AwaitExpression; argument: Expression; + type: AST_NODE_TYPES.AwaitExpression; } diff --git a/packages/ast-spec/src/expression/BinaryExpression/BinaryOperatorToText.ts b/packages/ast-spec/src/expression/BinaryExpression/BinaryOperatorToText.ts index b19373f54d22..95fa2f654497 100644 --- a/packages/ast-spec/src/expression/BinaryExpression/BinaryOperatorToText.ts +++ b/packages/ast-spec/src/expression/BinaryExpression/BinaryOperatorToText.ts @@ -2,34 +2,34 @@ import type { SyntaxKind } from 'typescript'; // the members of ts.BinaryOperator export interface BinaryOperatorToText { - [SyntaxKind.InstanceOfKeyword]: 'instanceof'; - [SyntaxKind.InKeyword]: 'in'; + // logical + [SyntaxKind.AmpersandAmpersandToken]: '&&'; + // bitwise + [SyntaxKind.AmpersandToken]: '&'; // math [SyntaxKind.AsteriskAsteriskToken]: '**'; [SyntaxKind.AsteriskToken]: '*'; - [SyntaxKind.SlashToken]: '/'; - [SyntaxKind.PercentToken]: '%'; - [SyntaxKind.PlusToken]: '+'; - [SyntaxKind.MinusToken]: '-'; - - // bitwise - [SyntaxKind.AmpersandToken]: '&'; + [SyntaxKind.BarBarToken]: '||'; [SyntaxKind.BarToken]: '|'; [SyntaxKind.CaretToken]: '^'; - [SyntaxKind.LessThanLessThanToken]: '<<'; - [SyntaxKind.GreaterThanGreaterThanToken]: '>>'; - [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: '>>>'; + [SyntaxKind.EqualsEqualsEqualsToken]: '==='; - // logical - [SyntaxKind.AmpersandAmpersandToken]: '&&'; - [SyntaxKind.BarBarToken]: '||'; - [SyntaxKind.LessThanToken]: '<'; - [SyntaxKind.LessThanEqualsToken]: '<='; - [SyntaxKind.GreaterThanToken]: '>'; - [SyntaxKind.GreaterThanEqualsToken]: '>='; [SyntaxKind.EqualsEqualsToken]: '=='; - [SyntaxKind.EqualsEqualsEqualsToken]: '==='; [SyntaxKind.ExclamationEqualsEqualsToken]: '!=='; [SyntaxKind.ExclamationEqualsToken]: '!='; + [SyntaxKind.GreaterThanEqualsToken]: '>='; + [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: '>>>'; + [SyntaxKind.GreaterThanGreaterThanToken]: '>>'; + + [SyntaxKind.GreaterThanToken]: '>'; + [SyntaxKind.InKeyword]: 'in'; + [SyntaxKind.InstanceOfKeyword]: 'instanceof'; + [SyntaxKind.LessThanEqualsToken]: '<='; + [SyntaxKind.LessThanLessThanToken]: '<<'; + [SyntaxKind.LessThanToken]: '<'; + [SyntaxKind.MinusToken]: '-'; + [SyntaxKind.PercentToken]: '%'; + [SyntaxKind.PlusToken]: '+'; + [SyntaxKind.SlashToken]: '/'; } diff --git a/packages/ast-spec/src/expression/BinaryExpression/spec.ts b/packages/ast-spec/src/expression/BinaryExpression/spec.ts index d42f1d4e77f4..9547483403bb 100644 --- a/packages/ast-spec/src/expression/BinaryExpression/spec.ts +++ b/packages/ast-spec/src/expression/BinaryExpression/spec.ts @@ -8,8 +8,8 @@ import type { BinaryOperatorToText } from './BinaryOperatorToText'; export * from './BinaryOperatorToText'; export interface BinaryExpression extends BaseNode { - type: AST_NODE_TYPES.BinaryExpression; - operator: ValueOf; left: Expression | PrivateIdentifier; + operator: ValueOf; right: Expression; + 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 index f380de25bc9d..dec2522217a7 100644 --- a/packages/ast-spec/src/expression/CallExpression/spec.ts +++ b/packages/ast-spec/src/expression/CallExpression/spec.ts @@ -5,9 +5,9 @@ import type { CallExpressionArgument } from '../../unions/CallExpressionArgument import type { Expression } from '../../unions/Expression'; export interface CallExpression extends BaseNode { - type: AST_NODE_TYPES.CallExpression; - callee: Expression; arguments: CallExpressionArgument[]; - typeArguments: TSTypeParameterInstantiation | undefined; + callee: Expression; optional: boolean; + type: AST_NODE_TYPES.CallExpression; + typeArguments: TSTypeParameterInstantiation | undefined; } diff --git a/packages/ast-spec/src/expression/ChainExpression/spec.ts b/packages/ast-spec/src/expression/ChainExpression/spec.ts index dfad50f3580f..fca341de2295 100644 --- a/packages/ast-spec/src/expression/ChainExpression/spec.ts +++ b/packages/ast-spec/src/expression/ChainExpression/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { ChainElement } from '../../unions/ChainElement'; export interface ChainExpression extends BaseNode { - type: AST_NODE_TYPES.ChainExpression; expression: ChainElement; + type: AST_NODE_TYPES.ChainExpression; } diff --git a/packages/ast-spec/src/expression/ClassExpression/spec.ts b/packages/ast-spec/src/expression/ClassExpression/spec.ts index 71a7be13140a..0f436394aa07 100644 --- a/packages/ast-spec/src/expression/ClassExpression/spec.ts +++ b/packages/ast-spec/src/expression/ClassExpression/spec.ts @@ -2,7 +2,7 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { ClassBase } from '../../base/ClassBase'; export interface ClassExpression extends ClassBase { - type: AST_NODE_TYPES.ClassExpression; abstract: false; declare: false; + 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 index 545fc9497b77..a4a6e9cba4d7 100644 --- a/packages/ast-spec/src/expression/ConditionalExpression/spec.ts +++ b/packages/ast-spec/src/expression/ConditionalExpression/spec.ts @@ -3,8 +3,8 @@ 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; + consequent: Expression; + test: Expression; + type: AST_NODE_TYPES.ConditionalExpression; } diff --git a/packages/ast-spec/src/expression/FunctionExpression/spec.ts b/packages/ast-spec/src/expression/FunctionExpression/spec.ts index 41f592a972f0..79057f2061e1 100644 --- a/packages/ast-spec/src/expression/FunctionExpression/spec.ts +++ b/packages/ast-spec/src/expression/FunctionExpression/spec.ts @@ -3,7 +3,7 @@ import type { FunctionBase } from '../../base/FunctionBase'; import type { BlockStatement } from '../../statement/BlockStatement/spec'; export interface FunctionExpression extends FunctionBase { - type: AST_NODE_TYPES.FunctionExpression; body: BlockStatement; expression: false; + type: AST_NODE_TYPES.FunctionExpression; } diff --git a/packages/ast-spec/src/expression/Identifier/spec.ts b/packages/ast-spec/src/expression/Identifier/spec.ts index d18ba7b9b993..b7cce6aa6706 100644 --- a/packages/ast-spec/src/expression/Identifier/spec.ts +++ b/packages/ast-spec/src/expression/Identifier/spec.ts @@ -4,9 +4,9 @@ import type { Decorator } from '../../special/Decorator/spec'; import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; export interface Identifier extends BaseNode { - type: AST_NODE_TYPES.Identifier; + decorators: Decorator[]; name: string; - typeAnnotation: TSTypeAnnotation | undefined; optional: boolean; - decorators: Decorator[]; + type: AST_NODE_TYPES.Identifier; + typeAnnotation: TSTypeAnnotation | undefined; } diff --git a/packages/ast-spec/src/expression/ImportExpression/spec.ts b/packages/ast-spec/src/expression/ImportExpression/spec.ts index 6aef75ac0e1e..f6f95e097dd3 100644 --- a/packages/ast-spec/src/expression/ImportExpression/spec.ts +++ b/packages/ast-spec/src/expression/ImportExpression/spec.ts @@ -3,7 +3,7 @@ import type { BaseNode } from '../../base/BaseNode'; import type { Expression } from '../../unions/Expression'; export interface ImportExpression extends BaseNode { - type: AST_NODE_TYPES.ImportExpression; - source: Expression; attributes: Expression | null; + source: Expression; + type: AST_NODE_TYPES.ImportExpression; } diff --git a/packages/ast-spec/src/expression/JSXElement/spec.ts b/packages/ast-spec/src/expression/JSXElement/spec.ts index 32a514f677a3..50d2b58f5b65 100644 --- a/packages/ast-spec/src/expression/JSXElement/spec.ts +++ b/packages/ast-spec/src/expression/JSXElement/spec.ts @@ -5,8 +5,8 @@ import type { JSXOpeningElement } from '../../jsx/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[]; + closingElement: JSXClosingElement | null; + openingElement: JSXOpeningElement; + type: AST_NODE_TYPES.JSXElement; } diff --git a/packages/ast-spec/src/expression/JSXFragment/spec.ts b/packages/ast-spec/src/expression/JSXFragment/spec.ts index 9adce12ada58..2ef1068d56df 100644 --- a/packages/ast-spec/src/expression/JSXFragment/spec.ts +++ b/packages/ast-spec/src/expression/JSXFragment/spec.ts @@ -5,8 +5,8 @@ import type { JSXOpeningFragment } from '../../jsx/JSXOpeningFragment/spec'; import type { JSXChild } from '../../unions/JSXChild'; export interface JSXFragment extends BaseNode { - type: AST_NODE_TYPES.JSXFragment; - openingFragment: JSXOpeningFragment; - closingFragment: JSXClosingFragment; children: JSXChild[]; + closingFragment: JSXClosingFragment; + openingFragment: JSXOpeningFragment; + type: AST_NODE_TYPES.JSXFragment; } diff --git a/packages/ast-spec/src/expression/LogicalExpression/spec.ts b/packages/ast-spec/src/expression/LogicalExpression/spec.ts index 1eda8e3b615e..3e7d06b29d1c 100644 --- a/packages/ast-spec/src/expression/LogicalExpression/spec.ts +++ b/packages/ast-spec/src/expression/LogicalExpression/spec.ts @@ -3,8 +3,8 @@ import type { BaseNode } from '../../base/BaseNode'; import type { Expression } from '../../unions/Expression'; export interface LogicalExpression extends BaseNode { - type: AST_NODE_TYPES.LogicalExpression; - operator: '??' | '&&' | '||'; left: Expression; + operator: '&&' | '??' | '||'; right: Expression; + 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 index a0a7cc65a33d..f4e9f2f3e0a0 100644 --- a/packages/ast-spec/src/expression/MemberExpression/spec.ts +++ b/packages/ast-spec/src/expression/MemberExpression/spec.ts @@ -5,22 +5,22 @@ import type { Expression } from '../../unions/Expression'; import type { Identifier } from '../Identifier/spec'; interface MemberExpressionBase extends BaseNode { - object: Expression; - property: Expression | Identifier | PrivateIdentifier; computed: boolean; + object: Expression; optional: boolean; + property: Expression | Identifier | PrivateIdentifier; } export interface MemberExpressionComputedName extends MemberExpressionBase { - type: AST_NODE_TYPES.MemberExpression; - property: Expression; computed: true; + property: Expression; + type: AST_NODE_TYPES.MemberExpression; } export interface MemberExpressionNonComputedName extends MemberExpressionBase { - type: AST_NODE_TYPES.MemberExpression; - property: Identifier | PrivateIdentifier; computed: false; + property: Identifier | PrivateIdentifier; + type: AST_NODE_TYPES.MemberExpression; } export type MemberExpression = diff --git a/packages/ast-spec/src/expression/MetaProperty/spec.ts b/packages/ast-spec/src/expression/MetaProperty/spec.ts index 5bc9afb81113..18e8d84068ab 100644 --- a/packages/ast-spec/src/expression/MetaProperty/spec.ts +++ b/packages/ast-spec/src/expression/MetaProperty/spec.ts @@ -3,7 +3,7 @@ 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; + type: AST_NODE_TYPES.MetaProperty; } diff --git a/packages/ast-spec/src/expression/NewExpression/spec.ts b/packages/ast-spec/src/expression/NewExpression/spec.ts index c4478bd476d8..adc069341bb5 100644 --- a/packages/ast-spec/src/expression/NewExpression/spec.ts +++ b/packages/ast-spec/src/expression/NewExpression/spec.ts @@ -5,8 +5,8 @@ import type { CallExpressionArgument } from '../../unions/CallExpressionArgument import type { Expression } from '../../unions/Expression'; export interface NewExpression extends BaseNode { - type: AST_NODE_TYPES.NewExpression; - callee: Expression; arguments: CallExpressionArgument[]; + callee: Expression; + type: AST_NODE_TYPES.NewExpression; typeArguments: TSTypeParameterInstantiation | undefined; } diff --git a/packages/ast-spec/src/expression/ObjectExpression/spec.ts b/packages/ast-spec/src/expression/ObjectExpression/spec.ts index 0573a2a76faf..a96f0fac5350 100644 --- a/packages/ast-spec/src/expression/ObjectExpression/spec.ts +++ b/packages/ast-spec/src/expression/ObjectExpression/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { ObjectLiteralElement } from '../../unions/ObjectLiteralElement'; export interface ObjectExpression extends BaseNode { - type: AST_NODE_TYPES.ObjectExpression; properties: ObjectLiteralElement[]; + type: AST_NODE_TYPES.ObjectExpression; } diff --git a/packages/ast-spec/src/expression/SequenceExpression/spec.ts b/packages/ast-spec/src/expression/SequenceExpression/spec.ts index fa571adb4f08..a63ed2ecf29f 100644 --- a/packages/ast-spec/src/expression/SequenceExpression/spec.ts +++ b/packages/ast-spec/src/expression/SequenceExpression/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { Expression } from '../../unions/Expression'; export interface SequenceExpression extends BaseNode { - type: AST_NODE_TYPES.SequenceExpression; expressions: Expression[]; + type: AST_NODE_TYPES.SequenceExpression; } diff --git a/packages/ast-spec/src/expression/TSAsExpression/spec.ts b/packages/ast-spec/src/expression/TSAsExpression/spec.ts index b90925a53ca7..669f2339e2c9 100644 --- a/packages/ast-spec/src/expression/TSAsExpression/spec.ts +++ b/packages/ast-spec/src/expression/TSAsExpression/spec.ts @@ -4,7 +4,7 @@ import type { Expression } from '../../unions/Expression'; import type { TypeNode } from '../../unions/TypeNode'; export interface TSAsExpression extends BaseNode { - type: AST_NODE_TYPES.TSAsExpression; expression: Expression; + type: AST_NODE_TYPES.TSAsExpression; typeAnnotation: TypeNode; } diff --git a/packages/ast-spec/src/expression/TSEmptyBodyFunctionExpression/spec.ts b/packages/ast-spec/src/expression/TSEmptyBodyFunctionExpression/spec.ts index 77c8779c7d14..ad637d21d35c 100644 --- a/packages/ast-spec/src/expression/TSEmptyBodyFunctionExpression/spec.ts +++ b/packages/ast-spec/src/expression/TSEmptyBodyFunctionExpression/spec.ts @@ -2,7 +2,7 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { FunctionBase } from '../../base/FunctionBase'; export interface TSEmptyBodyFunctionExpression extends FunctionBase { - type: AST_NODE_TYPES.TSEmptyBodyFunctionExpression; body: null; id: null; + type: AST_NODE_TYPES.TSEmptyBodyFunctionExpression; } diff --git a/packages/ast-spec/src/expression/TSInstantiationExpression/spec.ts b/packages/ast-spec/src/expression/TSInstantiationExpression/spec.ts index 2219a440bdf7..3219cb8657fb 100644 --- a/packages/ast-spec/src/expression/TSInstantiationExpression/spec.ts +++ b/packages/ast-spec/src/expression/TSInstantiationExpression/spec.ts @@ -4,7 +4,7 @@ import type { TSTypeParameterInstantiation } from '../../special/spec'; import type { Expression } from '../../unions/Expression'; export interface TSInstantiationExpression extends BaseNode { - type: AST_NODE_TYPES.TSInstantiationExpression; expression: Expression; + type: AST_NODE_TYPES.TSInstantiationExpression; typeArguments: TSTypeParameterInstantiation; } diff --git a/packages/ast-spec/src/expression/TSNonNullExpression/spec.ts b/packages/ast-spec/src/expression/TSNonNullExpression/spec.ts index fd25d33d372f..19e7187192f8 100644 --- a/packages/ast-spec/src/expression/TSNonNullExpression/spec.ts +++ b/packages/ast-spec/src/expression/TSNonNullExpression/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { Expression } from '../../unions/Expression'; export interface TSNonNullExpression extends BaseNode { - type: AST_NODE_TYPES.TSNonNullExpression; expression: Expression; + type: AST_NODE_TYPES.TSNonNullExpression; } diff --git a/packages/ast-spec/src/expression/TSSatisfiesExpression/spec.ts b/packages/ast-spec/src/expression/TSSatisfiesExpression/spec.ts index 1297ade3eba8..39e1c59f8ffe 100644 --- a/packages/ast-spec/src/expression/TSSatisfiesExpression/spec.ts +++ b/packages/ast-spec/src/expression/TSSatisfiesExpression/spec.ts @@ -4,7 +4,7 @@ import type { Expression } from '../../unions/Expression'; import type { TypeNode } from '../../unions/TypeNode'; export interface TSSatisfiesExpression extends BaseNode { - type: AST_NODE_TYPES.TSSatisfiesExpression; expression: Expression; + type: AST_NODE_TYPES.TSSatisfiesExpression; typeAnnotation: TypeNode; } diff --git a/packages/ast-spec/src/expression/TSTypeAssertion/spec.ts b/packages/ast-spec/src/expression/TSTypeAssertion/spec.ts index d820f8fcc378..a410c7f78ddc 100644 --- a/packages/ast-spec/src/expression/TSTypeAssertion/spec.ts +++ b/packages/ast-spec/src/expression/TSTypeAssertion/spec.ts @@ -4,7 +4,7 @@ import type { Expression } from '../../unions/Expression'; import type { TypeNode } from '../../unions/TypeNode'; export interface TSTypeAssertion extends BaseNode { + expression: Expression; type: AST_NODE_TYPES.TSTypeAssertion; typeAnnotation: TypeNode; - expression: Expression; } diff --git a/packages/ast-spec/src/expression/TemplateLiteral/spec.ts b/packages/ast-spec/src/expression/TemplateLiteral/spec.ts index 4d92ef79176d..4d2c031313de 100644 --- a/packages/ast-spec/src/expression/TemplateLiteral/spec.ts +++ b/packages/ast-spec/src/expression/TemplateLiteral/spec.ts @@ -4,7 +4,7 @@ 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[]; + quasis: TemplateElement[]; + type: AST_NODE_TYPES.TemplateLiteral; } diff --git a/packages/ast-spec/src/expression/UnaryExpression/spec.ts b/packages/ast-spec/src/expression/UnaryExpression/spec.ts index 26ec8a0e9cdf..db16f93b69fd 100644 --- a/packages/ast-spec/src/expression/UnaryExpression/spec.ts +++ b/packages/ast-spec/src/expression/UnaryExpression/spec.ts @@ -2,6 +2,6 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { UnaryExpressionBase } from '../../base/UnaryExpressionBase'; export interface UnaryExpression extends UnaryExpressionBase { + operator: '!' | '+' | '~' | '-' | 'delete' | 'typeof' | 'void'; 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 index 909815fdabf3..2a5b8466c7d3 100644 --- a/packages/ast-spec/src/expression/UpdateExpression/spec.ts +++ b/packages/ast-spec/src/expression/UpdateExpression/spec.ts @@ -2,6 +2,6 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { UnaryExpressionBase } from '../../base/UnaryExpressionBase'; export interface UpdateExpression extends UnaryExpressionBase { + operator: '++' | '--'; 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 index 00c64731e734..5c219c6d8e0d 100644 --- a/packages/ast-spec/src/expression/YieldExpression/spec.ts +++ b/packages/ast-spec/src/expression/YieldExpression/spec.ts @@ -3,7 +3,7 @@ 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 | undefined; + delegate: boolean; + type: AST_NODE_TYPES.YieldExpression; } diff --git a/packages/ast-spec/src/expression/literal/BigIntLiteral/spec.ts b/packages/ast-spec/src/expression/literal/BigIntLiteral/spec.ts index 2df33369cf74..e9bd8f2ce90c 100644 --- a/packages/ast-spec/src/expression/literal/BigIntLiteral/spec.ts +++ b/packages/ast-spec/src/expression/literal/BigIntLiteral/spec.ts @@ -1,6 +1,6 @@ import type { LiteralBase } from '../../../base/LiteralBase'; export interface BigIntLiteral extends LiteralBase { - value: bigint | null; bigint: string; + value: bigint | null; } diff --git a/packages/ast-spec/src/expression/literal/BooleanLiteral/spec.ts b/packages/ast-spec/src/expression/literal/BooleanLiteral/spec.ts index be7477f015cb..a96d54142032 100644 --- a/packages/ast-spec/src/expression/literal/BooleanLiteral/spec.ts +++ b/packages/ast-spec/src/expression/literal/BooleanLiteral/spec.ts @@ -1,6 +1,6 @@ import type { LiteralBase } from '../../../base/LiteralBase'; export interface BooleanLiteral extends LiteralBase { - value: boolean; raw: 'false' | 'true'; + value: boolean; } diff --git a/packages/ast-spec/src/expression/literal/NullLiteral/spec.ts b/packages/ast-spec/src/expression/literal/NullLiteral/spec.ts index 03ff8a43c866..c6a4840d6ef5 100644 --- a/packages/ast-spec/src/expression/literal/NullLiteral/spec.ts +++ b/packages/ast-spec/src/expression/literal/NullLiteral/spec.ts @@ -1,6 +1,6 @@ import type { LiteralBase } from '../../../base/LiteralBase'; export interface NullLiteral extends LiteralBase { - value: null; raw: 'null'; + value: null; } diff --git a/packages/ast-spec/src/expression/literal/RegExpLiteral/spec.ts b/packages/ast-spec/src/expression/literal/RegExpLiteral/spec.ts index f72b53c7956b..4df77eddebf4 100644 --- a/packages/ast-spec/src/expression/literal/RegExpLiteral/spec.ts +++ b/packages/ast-spec/src/expression/literal/RegExpLiteral/spec.ts @@ -1,9 +1,9 @@ import type { LiteralBase } from '../../../base/LiteralBase'; export interface RegExpLiteral extends LiteralBase { - value: RegExp | null; regex: { - pattern: string; flags: string; + pattern: string; }; + value: RegExp | null; } diff --git a/packages/ast-spec/src/expression/spec.ts b/packages/ast-spec/src/expression/spec.ts index f753672d472d..5162ebf49116 100644 --- a/packages/ast-spec/src/expression/spec.ts +++ b/packages/ast-spec/src/expression/spec.ts @@ -12,6 +12,7 @@ export * from './Identifier/spec'; export * from './ImportExpression/spec'; export * from './JSXElement/spec'; export * from './JSXFragment/spec'; +export * from './literal/spec'; export * from './LogicalExpression/spec'; export * from './MemberExpression/spec'; export * from './MetaProperty/spec'; @@ -19,17 +20,15 @@ export * from './NewExpression/spec'; export * from './ObjectExpression/spec'; export * from './SequenceExpression/spec'; export * from './Super/spec'; +export * from './TaggedTemplateExpression/spec'; +export * from './TemplateLiteral/spec'; +export * from './ThisExpression/spec'; export * from './TSAsExpression/spec'; export * from './TSEmptyBodyFunctionExpression/spec'; export * from './TSInstantiationExpression/spec'; export * from './TSNonNullExpression/spec'; export * from './TSSatisfiesExpression/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 index 3ca95ed64176..f46a8a804b5b 100644 --- a/packages/ast-spec/src/index.ts +++ b/packages/ast-spec/src/index.ts @@ -1,3 +1,5 @@ +export * from './ast-node-types'; +export * from './ast-token-types'; 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/NodeOrTokenData'; @@ -5,7 +7,15 @@ export * from './base/OptionalRangeAndLoc'; export * from './base/Position'; export * from './base/Range'; export * from './base/SourceLocation'; - +export * from './declaration/spec'; +export * from './element/spec'; +export * from './expression/spec'; +export * from './jsx/spec'; +export * from './parameter/spec'; +export * from './special/spec'; +export * from './statement/spec'; +export * from './token/spec'; +export * from './type/spec'; export * from './unions/BindingName'; export * from './unions/BindingPattern'; export * from './unions/CallExpressionArgument'; @@ -33,20 +43,7 @@ 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/TSUnaryExpression'; export * from './unions/TypeElement'; export * from './unions/TypeNode'; - -export * from './declaration/spec'; -export * from './element/spec'; -export * from './expression/spec'; -export * from './jsx/spec'; -export * from './parameter/spec'; -export * from './special/spec'; -export * from './statement/spec'; -export * from './token/spec'; -export * from './type/spec'; - -export * from './ast-node-types'; -export * from './ast-token-types'; diff --git a/packages/ast-spec/src/jsx/JSXAttribute/spec.ts b/packages/ast-spec/src/jsx/JSXAttribute/spec.ts index c8e52b244578..0749db9b4356 100644 --- a/packages/ast-spec/src/jsx/JSXAttribute/spec.ts +++ b/packages/ast-spec/src/jsx/JSXAttribute/spec.ts @@ -7,7 +7,7 @@ import type { JSXIdentifier } from '../JSXIdentifier/spec'; import type { JSXNamespacedName } from '../JSXNamespacedName/spec'; export interface JSXAttribute extends BaseNode { - type: AST_NODE_TYPES.JSXAttribute; name: JSXIdentifier | JSXNamespacedName; + type: AST_NODE_TYPES.JSXAttribute; value: JSXElement | JSXExpression | Literal | null; } diff --git a/packages/ast-spec/src/jsx/JSXClosingElement/spec.ts b/packages/ast-spec/src/jsx/JSXClosingElement/spec.ts index ea698d6059ed..01135281cccb 100644 --- a/packages/ast-spec/src/jsx/JSXClosingElement/spec.ts +++ b/packages/ast-spec/src/jsx/JSXClosingElement/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { JSXTagNameExpression } from '../../unions/JSXTagNameExpression'; export interface JSXClosingElement extends BaseNode { - type: AST_NODE_TYPES.JSXClosingElement; name: JSXTagNameExpression; + type: AST_NODE_TYPES.JSXClosingElement; } diff --git a/packages/ast-spec/src/jsx/JSXExpressionContainer/spec.ts b/packages/ast-spec/src/jsx/JSXExpressionContainer/spec.ts index 1a0673e6fd15..510410bf083a 100644 --- a/packages/ast-spec/src/jsx/JSXExpressionContainer/spec.ts +++ b/packages/ast-spec/src/jsx/JSXExpressionContainer/spec.ts @@ -4,6 +4,6 @@ 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; + type: AST_NODE_TYPES.JSXExpressionContainer; } diff --git a/packages/ast-spec/src/jsx/JSXIdentifier/spec.ts b/packages/ast-spec/src/jsx/JSXIdentifier/spec.ts index 1d7b71d67ab0..622cd8a7a758 100644 --- a/packages/ast-spec/src/jsx/JSXIdentifier/spec.ts +++ b/packages/ast-spec/src/jsx/JSXIdentifier/spec.ts @@ -2,6 +2,6 @@ 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; + type: AST_NODE_TYPES.JSXIdentifier; } diff --git a/packages/ast-spec/src/jsx/JSXMemberExpression/spec.ts b/packages/ast-spec/src/jsx/JSXMemberExpression/spec.ts index e0cda9c16ee4..169607be6e77 100644 --- a/packages/ast-spec/src/jsx/JSXMemberExpression/spec.ts +++ b/packages/ast-spec/src/jsx/JSXMemberExpression/spec.ts @@ -4,7 +4,7 @@ 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; + type: AST_NODE_TYPES.JSXMemberExpression; } diff --git a/packages/ast-spec/src/jsx/JSXNamespacedName/spec.ts b/packages/ast-spec/src/jsx/JSXNamespacedName/spec.ts index 22443d938eca..446b426c7f69 100644 --- a/packages/ast-spec/src/jsx/JSXNamespacedName/spec.ts +++ b/packages/ast-spec/src/jsx/JSXNamespacedName/spec.ts @@ -3,7 +3,7 @@ import type { BaseNode } from '../../base/BaseNode'; import type { JSXIdentifier } from '../JSXIdentifier/spec'; export interface JSXNamespacedName extends BaseNode { - type: AST_NODE_TYPES.JSXNamespacedName; - namespace: JSXIdentifier; name: JSXIdentifier; + namespace: JSXIdentifier; + type: AST_NODE_TYPES.JSXNamespacedName; } diff --git a/packages/ast-spec/src/jsx/JSXOpeningElement/spec.ts b/packages/ast-spec/src/jsx/JSXOpeningElement/spec.ts index 157512bc7908..6e6bbb7564be 100644 --- a/packages/ast-spec/src/jsx/JSXOpeningElement/spec.ts +++ b/packages/ast-spec/src/jsx/JSXOpeningElement/spec.ts @@ -6,9 +6,9 @@ import type { JSXAttribute } from '../JSXAttribute/spec'; import type { JSXSpreadAttribute } from '../JSXSpreadAttribute/spec'; export interface JSXOpeningElement extends BaseNode { + attributes: (JSXAttribute | JSXSpreadAttribute)[]; + name: JSXTagNameExpression; + selfClosing: boolean; type: AST_NODE_TYPES.JSXOpeningElement; typeArguments: TSTypeParameterInstantiation | undefined; - selfClosing: boolean; - name: JSXTagNameExpression; - attributes: (JSXAttribute | JSXSpreadAttribute)[]; } diff --git a/packages/ast-spec/src/jsx/JSXSpreadAttribute/spec.ts b/packages/ast-spec/src/jsx/JSXSpreadAttribute/spec.ts index db6e6fc1d1bc..e412aab4e068 100644 --- a/packages/ast-spec/src/jsx/JSXSpreadAttribute/spec.ts +++ b/packages/ast-spec/src/jsx/JSXSpreadAttribute/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { Expression } from '../../unions/Expression'; export interface JSXSpreadAttribute extends BaseNode { - type: AST_NODE_TYPES.JSXSpreadAttribute; argument: Expression; + type: AST_NODE_TYPES.JSXSpreadAttribute; } diff --git a/packages/ast-spec/src/jsx/JSXSpreadChild/spec.ts b/packages/ast-spec/src/jsx/JSXSpreadChild/spec.ts index 53fe53555c30..4ee9b2e4cf4a 100644 --- a/packages/ast-spec/src/jsx/JSXSpreadChild/spec.ts +++ b/packages/ast-spec/src/jsx/JSXSpreadChild/spec.ts @@ -4,6 +4,6 @@ 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; + type: AST_NODE_TYPES.JSXSpreadChild; } diff --git a/packages/ast-spec/src/jsx/JSXText/spec.ts b/packages/ast-spec/src/jsx/JSXText/spec.ts index a323493fba90..fa4a354fff48 100644 --- a/packages/ast-spec/src/jsx/JSXText/spec.ts +++ b/packages/ast-spec/src/jsx/JSXText/spec.ts @@ -2,7 +2,7 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BaseNode } from '../../base/BaseNode'; export interface JSXText extends BaseNode { + raw: string; type: AST_NODE_TYPES.JSXText; value: string; - raw: string; } diff --git a/packages/ast-spec/src/parameter/ArrayPattern/spec.ts b/packages/ast-spec/src/parameter/ArrayPattern/spec.ts index 9fd684b8044c..930ca91acd21 100644 --- a/packages/ast-spec/src/parameter/ArrayPattern/spec.ts +++ b/packages/ast-spec/src/parameter/ArrayPattern/spec.ts @@ -5,9 +5,9 @@ import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; import type { DestructuringPattern } from '../../unions/DestructuringPattern'; export interface ArrayPattern extends BaseNode { - type: AST_NODE_TYPES.ArrayPattern; + decorators: Decorator[]; elements: (DestructuringPattern | null)[]; - typeAnnotation: TSTypeAnnotation | undefined; optional: boolean; - decorators: Decorator[]; + type: AST_NODE_TYPES.ArrayPattern; + typeAnnotation: TSTypeAnnotation | undefined; } diff --git a/packages/ast-spec/src/parameter/AssignmentPattern/spec.ts b/packages/ast-spec/src/parameter/AssignmentPattern/spec.ts index 208a44e82984..aefcb6dd540e 100644 --- a/packages/ast-spec/src/parameter/AssignmentPattern/spec.ts +++ b/packages/ast-spec/src/parameter/AssignmentPattern/spec.ts @@ -6,10 +6,10 @@ import type { BindingName } from '../../unions/BindingName'; import type { Expression } from '../../unions/Expression'; export interface AssignmentPattern extends BaseNode { - type: AST_NODE_TYPES.AssignmentPattern; + decorators: Decorator[]; left: BindingName; + optional: boolean; right: Expression; + type: AST_NODE_TYPES.AssignmentPattern; typeAnnotation: TSTypeAnnotation | undefined; - optional: boolean; - decorators: Decorator[]; } diff --git a/packages/ast-spec/src/parameter/ObjectPattern/spec.ts b/packages/ast-spec/src/parameter/ObjectPattern/spec.ts index 76c53798a4d7..2b7219b7bc79 100644 --- a/packages/ast-spec/src/parameter/ObjectPattern/spec.ts +++ b/packages/ast-spec/src/parameter/ObjectPattern/spec.ts @@ -6,9 +6,9 @@ import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec'; import type { RestElement } from '../RestElement/spec'; export interface ObjectPattern extends BaseNode { - type: AST_NODE_TYPES.ObjectPattern; + decorators: Decorator[]; + optional: boolean; properties: (Property | RestElement)[]; + type: AST_NODE_TYPES.ObjectPattern; typeAnnotation: TSTypeAnnotation | undefined; - optional: boolean; - decorators: Decorator[]; } diff --git a/packages/ast-spec/src/parameter/RestElement/spec.ts b/packages/ast-spec/src/parameter/RestElement/spec.ts index 59f077988649..ed2ad1254b32 100644 --- a/packages/ast-spec/src/parameter/RestElement/spec.ts +++ b/packages/ast-spec/src/parameter/RestElement/spec.ts @@ -6,10 +6,10 @@ 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 | undefined; + decorators: Decorator[]; optional: boolean; + type: AST_NODE_TYPES.RestElement; + typeAnnotation: TSTypeAnnotation | undefined; value: AssignmentPattern | undefined; - decorators: Decorator[]; } diff --git a/packages/ast-spec/src/parameter/TSParameterProperty/spec.ts b/packages/ast-spec/src/parameter/TSParameterProperty/spec.ts index 56b5f5595292..38290e391720 100644 --- a/packages/ast-spec/src/parameter/TSParameterProperty/spec.ts +++ b/packages/ast-spec/src/parameter/TSParameterProperty/spec.ts @@ -7,11 +7,11 @@ import type { AssignmentPattern } from '../AssignmentPattern/spec'; import type { RestElement } from '../RestElement/spec'; export interface TSParameterProperty extends BaseNode { - type: AST_NODE_TYPES.TSParameterProperty; accessibility: Accessibility | undefined; - readonly: boolean; - static: boolean; + decorators: Decorator[]; override: boolean; parameter: AssignmentPattern | BindingName | RestElement; - decorators: Decorator[]; + readonly: boolean; + static: boolean; + type: AST_NODE_TYPES.TSParameterProperty; } diff --git a/packages/ast-spec/src/special/CatchClause/spec.ts b/packages/ast-spec/src/special/CatchClause/spec.ts index dea8168acda0..e083e7cd308d 100644 --- a/packages/ast-spec/src/special/CatchClause/spec.ts +++ b/packages/ast-spec/src/special/CatchClause/spec.ts @@ -4,7 +4,7 @@ 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; + param: BindingName | null; + type: AST_NODE_TYPES.CatchClause; } diff --git a/packages/ast-spec/src/special/ClassBody/spec.ts b/packages/ast-spec/src/special/ClassBody/spec.ts index 11c93d540fb3..92ab12ba3a21 100644 --- a/packages/ast-spec/src/special/ClassBody/spec.ts +++ b/packages/ast-spec/src/special/ClassBody/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { ClassElement } from '../../unions/ClassElement'; export interface ClassBody extends BaseNode { - type: AST_NODE_TYPES.ClassBody; body: ClassElement[]; + type: AST_NODE_TYPES.ClassBody; } diff --git a/packages/ast-spec/src/special/Decorator/spec.ts b/packages/ast-spec/src/special/Decorator/spec.ts index 3c8d1e819042..26e4c85c221c 100644 --- a/packages/ast-spec/src/special/Decorator/spec.ts +++ b/packages/ast-spec/src/special/Decorator/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { LeftHandSideExpression } from '../../unions/LeftHandSideExpression'; export interface Decorator extends BaseNode { - type: AST_NODE_TYPES.Decorator; expression: LeftHandSideExpression; + type: AST_NODE_TYPES.Decorator; } diff --git a/packages/ast-spec/src/special/ExportSpecifier/spec.ts b/packages/ast-spec/src/special/ExportSpecifier/spec.ts index 89d106d9565d..0e2f93eb1f3c 100644 --- a/packages/ast-spec/src/special/ExportSpecifier/spec.ts +++ b/packages/ast-spec/src/special/ExportSpecifier/spec.ts @@ -4,8 +4,8 @@ import type { ExportKind } from '../../declaration/ExportAndImportKind'; import type { Identifier } from '../../expression/Identifier/spec'; export interface ExportSpecifier extends BaseNode { - type: AST_NODE_TYPES.ExportSpecifier; - local: Identifier; exported: Identifier; exportKind: ExportKind; + local: Identifier; + type: AST_NODE_TYPES.ExportSpecifier; } diff --git a/packages/ast-spec/src/special/ImportAttribute/spec.ts b/packages/ast-spec/src/special/ImportAttribute/spec.ts index 988e31bb8585..3001b2d08890 100644 --- a/packages/ast-spec/src/special/ImportAttribute/spec.ts +++ b/packages/ast-spec/src/special/ImportAttribute/spec.ts @@ -4,7 +4,7 @@ import type { Identifier } from '../../expression/Identifier/spec'; import type { Literal } from '../../unions/Literal'; export interface ImportAttribute extends BaseNode { - type: AST_NODE_TYPES.ImportAttribute; key: Identifier | Literal; + type: AST_NODE_TYPES.ImportAttribute; value: Literal; } diff --git a/packages/ast-spec/src/special/ImportDefaultSpecifier/spec.ts b/packages/ast-spec/src/special/ImportDefaultSpecifier/spec.ts index c4ad22f20340..0a68010c0008 100644 --- a/packages/ast-spec/src/special/ImportDefaultSpecifier/spec.ts +++ b/packages/ast-spec/src/special/ImportDefaultSpecifier/spec.ts @@ -3,6 +3,6 @@ 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; + type: AST_NODE_TYPES.ImportDefaultSpecifier; } diff --git a/packages/ast-spec/src/special/ImportNamespaceSpecifier/spec.ts b/packages/ast-spec/src/special/ImportNamespaceSpecifier/spec.ts index eec79636f1fc..e4fd7eb3da01 100644 --- a/packages/ast-spec/src/special/ImportNamespaceSpecifier/spec.ts +++ b/packages/ast-spec/src/special/ImportNamespaceSpecifier/spec.ts @@ -3,6 +3,6 @@ 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; + type: AST_NODE_TYPES.ImportNamespaceSpecifier; } diff --git a/packages/ast-spec/src/special/ImportSpecifier/spec.ts b/packages/ast-spec/src/special/ImportSpecifier/spec.ts index 3634cb48b240..3589c88da438 100644 --- a/packages/ast-spec/src/special/ImportSpecifier/spec.ts +++ b/packages/ast-spec/src/special/ImportSpecifier/spec.ts @@ -4,8 +4,8 @@ import type { ImportKind } from '../../declaration/ExportAndImportKind'; import type { Identifier } from '../../expression/Identifier/spec'; export interface ImportSpecifier extends BaseNode { - type: AST_NODE_TYPES.ImportSpecifier; - local: Identifier; imported: Identifier; importKind: ImportKind; + local: Identifier; + type: AST_NODE_TYPES.ImportSpecifier; } diff --git a/packages/ast-spec/src/special/PrivateIdentifier/spec.ts b/packages/ast-spec/src/special/PrivateIdentifier/spec.ts index f1d2172b8374..544366dd9c31 100644 --- a/packages/ast-spec/src/special/PrivateIdentifier/spec.ts +++ b/packages/ast-spec/src/special/PrivateIdentifier/spec.ts @@ -2,6 +2,6 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BaseNode } from '../../base/BaseNode'; export interface PrivateIdentifier extends BaseNode { - type: AST_NODE_TYPES.PrivateIdentifier; name: string; + type: AST_NODE_TYPES.PrivateIdentifier; } diff --git a/packages/ast-spec/src/special/Program/spec.ts b/packages/ast-spec/src/special/Program/spec.ts index e338dbf677ec..3c7d153579d9 100644 --- a/packages/ast-spec/src/special/Program/spec.ts +++ b/packages/ast-spec/src/special/Program/spec.ts @@ -5,9 +5,9 @@ import type { ProgramStatement } from '../../unions/Statement'; import type { Token } from '../../unions/Token'; export interface Program extends NodeOrTokenData { - type: AST_NODE_TYPES.Program; body: ProgramStatement[]; - sourceType: 'module' | 'script'; comments: Comment[] | undefined; + sourceType: 'module' | 'script'; tokens: Token[] | undefined; + type: AST_NODE_TYPES.Program; } diff --git a/packages/ast-spec/src/special/SwitchCase/spec.ts b/packages/ast-spec/src/special/SwitchCase/spec.ts index f48f323536a4..3831472648ca 100644 --- a/packages/ast-spec/src/special/SwitchCase/spec.ts +++ b/packages/ast-spec/src/special/SwitchCase/spec.ts @@ -4,7 +4,7 @@ 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[]; + test: Expression | null; + type: AST_NODE_TYPES.SwitchCase; } diff --git a/packages/ast-spec/src/special/TSEnumBody/spec.ts b/packages/ast-spec/src/special/TSEnumBody/spec.ts index 3cdb9bbccdf0..82cf9cc700e7 100644 --- a/packages/ast-spec/src/special/TSEnumBody/spec.ts +++ b/packages/ast-spec/src/special/TSEnumBody/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { TSEnumMember } from '../../element/TSEnumMember/spec'; export interface TSEnumBody extends BaseNode { - type: AST_NODE_TYPES.TSEnumBody; members: TSEnumMember[]; + type: AST_NODE_TYPES.TSEnumBody; } diff --git a/packages/ast-spec/src/special/TSExternalModuleReference/spec.ts b/packages/ast-spec/src/special/TSExternalModuleReference/spec.ts index debc2daff41b..ac5a347e53bd 100644 --- a/packages/ast-spec/src/special/TSExternalModuleReference/spec.ts +++ b/packages/ast-spec/src/special/TSExternalModuleReference/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { StringLiteral } from '../../expression/literal/StringLiteral/spec'; export interface TSExternalModuleReference extends BaseNode { - type: AST_NODE_TYPES.TSExternalModuleReference; expression: StringLiteral; + type: AST_NODE_TYPES.TSExternalModuleReference; } diff --git a/packages/ast-spec/src/special/TSInterfaceBody/spec.ts b/packages/ast-spec/src/special/TSInterfaceBody/spec.ts index 1ee1c901c14d..6cd50199ab3c 100644 --- a/packages/ast-spec/src/special/TSInterfaceBody/spec.ts +++ b/packages/ast-spec/src/special/TSInterfaceBody/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { TypeElement } from '../../unions/TypeElement'; export interface TSInterfaceBody extends BaseNode { - type: AST_NODE_TYPES.TSInterfaceBody; body: TypeElement[]; + type: AST_NODE_TYPES.TSInterfaceBody; } diff --git a/packages/ast-spec/src/special/TSModuleBlock/spec.ts b/packages/ast-spec/src/special/TSModuleBlock/spec.ts index 9fed19af3b80..14cf0b1a01aa 100644 --- a/packages/ast-spec/src/special/TSModuleBlock/spec.ts +++ b/packages/ast-spec/src/special/TSModuleBlock/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { ProgramStatement } from '../../unions/Statement'; export interface TSModuleBlock extends BaseNode { - type: AST_NODE_TYPES.TSModuleBlock; body: ProgramStatement[]; + type: AST_NODE_TYPES.TSModuleBlock; } diff --git a/packages/ast-spec/src/special/TSTypeParameter/spec.ts b/packages/ast-spec/src/special/TSTypeParameter/spec.ts index a1295bfa7a93..1e4ecb4b659c 100644 --- a/packages/ast-spec/src/special/TSTypeParameter/spec.ts +++ b/packages/ast-spec/src/special/TSTypeParameter/spec.ts @@ -4,11 +4,11 @@ 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; + const: boolean; constraint: TypeNode | undefined; default: TypeNode | undefined; in: boolean; + name: Identifier; out: boolean; - const: boolean; + type: AST_NODE_TYPES.TSTypeParameter; } diff --git a/packages/ast-spec/src/special/TSTypeParameterDeclaration/spec.ts b/packages/ast-spec/src/special/TSTypeParameterDeclaration/spec.ts index ac8971e38a0c..4e91a27bba7f 100644 --- a/packages/ast-spec/src/special/TSTypeParameterDeclaration/spec.ts +++ b/packages/ast-spec/src/special/TSTypeParameterDeclaration/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { TSTypeParameter } from '../TSTypeParameter/spec'; export interface TSTypeParameterDeclaration extends BaseNode { - type: AST_NODE_TYPES.TSTypeParameterDeclaration; params: TSTypeParameter[]; + type: AST_NODE_TYPES.TSTypeParameterDeclaration; } diff --git a/packages/ast-spec/src/special/TSTypeParameterInstantiation/spec.ts b/packages/ast-spec/src/special/TSTypeParameterInstantiation/spec.ts index e5122c2f6a5c..1f0df78b0a72 100644 --- a/packages/ast-spec/src/special/TSTypeParameterInstantiation/spec.ts +++ b/packages/ast-spec/src/special/TSTypeParameterInstantiation/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { TypeNode } from '../../unions/TypeNode'; export interface TSTypeParameterInstantiation extends BaseNode { - type: AST_NODE_TYPES.TSTypeParameterInstantiation; params: TypeNode[]; + type: AST_NODE_TYPES.TSTypeParameterInstantiation; } diff --git a/packages/ast-spec/src/special/TemplateElement/spec.ts b/packages/ast-spec/src/special/TemplateElement/spec.ts index abf4dc910457..c7e7833de575 100644 --- a/packages/ast-spec/src/special/TemplateElement/spec.ts +++ b/packages/ast-spec/src/special/TemplateElement/spec.ts @@ -2,10 +2,10 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BaseNode } from '../../base/BaseNode'; export interface TemplateElement extends BaseNode { + tail: boolean; type: AST_NODE_TYPES.TemplateElement; value: { - raw: string; cooked: string; + raw: string; }; - tail: boolean; } diff --git a/packages/ast-spec/src/special/VariableDeclarator/spec.ts b/packages/ast-spec/src/special/VariableDeclarator/spec.ts index 12b0b83c3862..c9cacd9c37e8 100644 --- a/packages/ast-spec/src/special/VariableDeclarator/spec.ts +++ b/packages/ast-spec/src/special/VariableDeclarator/spec.ts @@ -7,7 +7,12 @@ import type { Expression } from '../../unions/Expression'; // TODO: these declarator types can probably be refined further, especially // their differences when used in different contexts (e.g. for...of) interface VariableDeclaratorBase extends BaseNode { - type: AST_NODE_TYPES.VariableDeclarator; + /** + * Whether there's definite assignment assertion (`let x!: number`). + * If `true`, then: `id` must be an identifier with a type annotation, + * `init` must be `null`, and the declarator must be a `var`/`let` declarator. + */ + definite: boolean; /** * The name(s) of the variable(s). */ @@ -17,17 +22,12 @@ interface VariableDeclaratorBase extends BaseNode { * in a `declare const`. */ init: Expression | null; - /** - * Whether there's definite assignment assertion (`let x!: number`). - * If `true`, then: `id` must be an identifier with a type annotation, - * `init` must be `null`, and the declarator must be a `var`/`let` declarator. - */ - definite: boolean; + type: AST_NODE_TYPES.VariableDeclarator; } export interface VariableDeclaratorNoInit extends VariableDeclaratorBase { - init: null; definite: false; + init: null; } export interface VariableDeclaratorMaybeInit extends VariableDeclaratorBase { @@ -36,12 +36,12 @@ export interface VariableDeclaratorMaybeInit extends VariableDeclaratorBase { export interface VariableDeclaratorDefiniteAssignment extends VariableDeclaratorBase { + definite: true; /** * The name of the variable. Must have a type annotation. */ id: Identifier; init: null; - definite: true; } export type LetOrConstOrVarDeclarator = @@ -50,15 +50,15 @@ export type LetOrConstOrVarDeclarator = | VariableDeclaratorNoInit; export interface UsingInNormalContextDeclarator extends VariableDeclaratorBase { + definite: false; id: Identifier; init: Expression; - definite: false; } export interface UsingInForOfDeclarator extends VariableDeclaratorBase { + definite: false; id: Identifier; init: null; - definite: false; } export type UsingDeclarator = diff --git a/packages/ast-spec/src/special/spec.ts b/packages/ast-spec/src/special/spec.ts index 24ef5463f150..1e7ad26877a9 100644 --- a/packages/ast-spec/src/special/spec.ts +++ b/packages/ast-spec/src/special/spec.ts @@ -10,6 +10,7 @@ export * from './ImportSpecifier/spec'; export * from './PrivateIdentifier/spec'; export * from './Program/spec'; export * from './SwitchCase/spec'; +export * from './TemplateElement/spec'; export * from './TSClassImplements/spec'; export * from './TSEnumBody/spec'; export * from './TSExternalModuleReference/spec'; @@ -20,5 +21,4 @@ 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 index 298a962e5161..430ba2383202 100644 --- a/packages/ast-spec/src/statement/BlockStatement/spec.ts +++ b/packages/ast-spec/src/statement/BlockStatement/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { Statement } from '../../unions/Statement'; export interface BlockStatement extends BaseNode { - type: AST_NODE_TYPES.BlockStatement; body: Statement[]; + type: AST_NODE_TYPES.BlockStatement; } diff --git a/packages/ast-spec/src/statement/BreakStatement/spec.ts b/packages/ast-spec/src/statement/BreakStatement/spec.ts index 0441c298d365..3048106c5191 100644 --- a/packages/ast-spec/src/statement/BreakStatement/spec.ts +++ b/packages/ast-spec/src/statement/BreakStatement/spec.ts @@ -3,6 +3,6 @@ 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; + type: AST_NODE_TYPES.BreakStatement; } diff --git a/packages/ast-spec/src/statement/ContinueStatement/spec.ts b/packages/ast-spec/src/statement/ContinueStatement/spec.ts index 70f2373dc217..82e7b80bda4a 100644 --- a/packages/ast-spec/src/statement/ContinueStatement/spec.ts +++ b/packages/ast-spec/src/statement/ContinueStatement/spec.ts @@ -3,6 +3,6 @@ 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; + type: AST_NODE_TYPES.ContinueStatement; } diff --git a/packages/ast-spec/src/statement/DoWhileStatement/spec.ts b/packages/ast-spec/src/statement/DoWhileStatement/spec.ts index 933ce61b2c4c..04f00b7d2fb1 100644 --- a/packages/ast-spec/src/statement/DoWhileStatement/spec.ts +++ b/packages/ast-spec/src/statement/DoWhileStatement/spec.ts @@ -4,7 +4,7 @@ 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; + test: Expression; + type: AST_NODE_TYPES.DoWhileStatement; } diff --git a/packages/ast-spec/src/statement/ExpressionStatement/spec.ts b/packages/ast-spec/src/statement/ExpressionStatement/spec.ts index 9ae5cd1f31d3..1f260232bfa8 100644 --- a/packages/ast-spec/src/statement/ExpressionStatement/spec.ts +++ b/packages/ast-spec/src/statement/ExpressionStatement/spec.ts @@ -3,7 +3,7 @@ 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 | undefined; + expression: Expression; + type: AST_NODE_TYPES.ExpressionStatement; } diff --git a/packages/ast-spec/src/statement/ForInStatement/spec.ts b/packages/ast-spec/src/statement/ForInStatement/spec.ts index 7abe3b2f5fad..e6176e4c4d38 100644 --- a/packages/ast-spec/src/statement/ForInStatement/spec.ts +++ b/packages/ast-spec/src/statement/ForInStatement/spec.ts @@ -5,8 +5,8 @@ import type { ForInitialiser } from '../../unions/ForInitialiser'; import type { Statement } from '../../unions/Statement'; export interface ForInStatement extends BaseNode { - type: AST_NODE_TYPES.ForInStatement; + body: Statement; left: ForInitialiser; right: Expression; - body: Statement; + type: AST_NODE_TYPES.ForInStatement; } diff --git a/packages/ast-spec/src/statement/ForOfStatement/spec.ts b/packages/ast-spec/src/statement/ForOfStatement/spec.ts index 595f9c9e7166..9fa6113b9e03 100644 --- a/packages/ast-spec/src/statement/ForOfStatement/spec.ts +++ b/packages/ast-spec/src/statement/ForOfStatement/spec.ts @@ -5,9 +5,9 @@ import type { ForOfInitialiser } from '../../unions/ForOfInitialiser'; import type { Statement } from '../../unions/Statement'; export interface ForOfStatement extends BaseNode { - type: AST_NODE_TYPES.ForOfStatement; + await: boolean; + body: Statement; left: ForOfInitialiser; right: Expression; - body: Statement; - await: boolean; + type: AST_NODE_TYPES.ForOfStatement; } diff --git a/packages/ast-spec/src/statement/ForStatement/spec.ts b/packages/ast-spec/src/statement/ForStatement/spec.ts index 1b56756b3a50..d9ff7df4c82f 100644 --- a/packages/ast-spec/src/statement/ForStatement/spec.ts +++ b/packages/ast-spec/src/statement/ForStatement/spec.ts @@ -5,9 +5,9 @@ import type { ForInitialiser } from '../../unions/ForInitialiser'; import type { Statement } from '../../unions/Statement'; export interface ForStatement extends BaseNode { - type: AST_NODE_TYPES.ForStatement; + body: Statement; init: Expression | ForInitialiser | null; test: Expression | null; + type: AST_NODE_TYPES.ForStatement; update: Expression | null; - body: Statement; } diff --git a/packages/ast-spec/src/statement/IfStatement/spec.ts b/packages/ast-spec/src/statement/IfStatement/spec.ts index f9081923e64a..6159260797b8 100644 --- a/packages/ast-spec/src/statement/IfStatement/spec.ts +++ b/packages/ast-spec/src/statement/IfStatement/spec.ts @@ -4,8 +4,8 @@ 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; + consequent: Statement; + test: Expression; + type: AST_NODE_TYPES.IfStatement; } diff --git a/packages/ast-spec/src/statement/LabeledStatement/spec.ts b/packages/ast-spec/src/statement/LabeledStatement/spec.ts index d007008d3a4b..a8e0c9896215 100644 --- a/packages/ast-spec/src/statement/LabeledStatement/spec.ts +++ b/packages/ast-spec/src/statement/LabeledStatement/spec.ts @@ -4,7 +4,7 @@ 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; + label: Identifier; + type: AST_NODE_TYPES.LabeledStatement; } diff --git a/packages/ast-spec/src/statement/ReturnStatement/spec.ts b/packages/ast-spec/src/statement/ReturnStatement/spec.ts index d7758715c8dd..6fdaa911878a 100644 --- a/packages/ast-spec/src/statement/ReturnStatement/spec.ts +++ b/packages/ast-spec/src/statement/ReturnStatement/spec.ts @@ -3,6 +3,6 @@ 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; + type: AST_NODE_TYPES.ReturnStatement; } diff --git a/packages/ast-spec/src/statement/SwitchStatement/spec.ts b/packages/ast-spec/src/statement/SwitchStatement/spec.ts index 9c76f81455c8..63152d55bdf5 100644 --- a/packages/ast-spec/src/statement/SwitchStatement/spec.ts +++ b/packages/ast-spec/src/statement/SwitchStatement/spec.ts @@ -4,7 +4,7 @@ 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[]; + discriminant: Expression; + type: AST_NODE_TYPES.SwitchStatement; } diff --git a/packages/ast-spec/src/statement/TSExportAssignment/spec.ts b/packages/ast-spec/src/statement/TSExportAssignment/spec.ts index 3792bc5012b1..7096aee66cde 100644 --- a/packages/ast-spec/src/statement/TSExportAssignment/spec.ts +++ b/packages/ast-spec/src/statement/TSExportAssignment/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { Expression } from '../../unions/Expression'; export interface TSExportAssignment extends BaseNode { - type: AST_NODE_TYPES.TSExportAssignment; expression: Expression; + type: AST_NODE_TYPES.TSExportAssignment; } diff --git a/packages/ast-spec/src/statement/ThrowStatement/spec.ts b/packages/ast-spec/src/statement/ThrowStatement/spec.ts index ac47bd98778c..b8fc7be7787a 100644 --- a/packages/ast-spec/src/statement/ThrowStatement/spec.ts +++ b/packages/ast-spec/src/statement/ThrowStatement/spec.ts @@ -4,6 +4,6 @@ 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; + type: AST_NODE_TYPES.ThrowStatement; } diff --git a/packages/ast-spec/src/statement/TryStatement/spec.ts b/packages/ast-spec/src/statement/TryStatement/spec.ts index 0435fbeb2100..b786996b3064 100644 --- a/packages/ast-spec/src/statement/TryStatement/spec.ts +++ b/packages/ast-spec/src/statement/TryStatement/spec.ts @@ -4,8 +4,8 @@ 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; + handler: CatchClause | null; + type: AST_NODE_TYPES.TryStatement; } diff --git a/packages/ast-spec/src/statement/WhileStatement/spec.ts b/packages/ast-spec/src/statement/WhileStatement/spec.ts index 1c9492c77140..e4ef33c229ae 100644 --- a/packages/ast-spec/src/statement/WhileStatement/spec.ts +++ b/packages/ast-spec/src/statement/WhileStatement/spec.ts @@ -4,7 +4,7 @@ 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; + test: Expression; + type: AST_NODE_TYPES.WhileStatement; } diff --git a/packages/ast-spec/src/statement/WithStatement/spec.ts b/packages/ast-spec/src/statement/WithStatement/spec.ts index c661a5175b9a..71b9b3936765 100644 --- a/packages/ast-spec/src/statement/WithStatement/spec.ts +++ b/packages/ast-spec/src/statement/WithStatement/spec.ts @@ -4,7 +4,7 @@ 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; + object: Expression; + type: AST_NODE_TYPES.WithStatement; } diff --git a/packages/ast-spec/src/statement/spec.ts b/packages/ast-spec/src/statement/spec.ts index 2621cf53004e..b581e0a26853 100644 --- a/packages/ast-spec/src/statement/spec.ts +++ b/packages/ast-spec/src/statement/spec.ts @@ -11,8 +11,8 @@ export * from './IfStatement/spec'; export * from './LabeledStatement/spec'; export * from './ReturnStatement/spec'; export * from './SwitchStatement/spec'; -export * from './TSExportAssignment/spec'; export * from './ThrowStatement/spec'; export * from './TryStatement/spec'; +export * from './TSExportAssignment/spec'; export * from './WhileStatement/spec'; export * from './WithStatement/spec'; diff --git a/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts b/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts index a3ea5b151613..3f9678993c4b 100644 --- a/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts +++ b/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts @@ -3,49 +3,49 @@ import type { SyntaxKind } from 'typescript'; import type { AssignmentOperatorToText } from '../../expression/AssignmentExpression/AssignmentOperatorToText'; export interface PunctuatorTokenToText extends AssignmentOperatorToText { - [SyntaxKind.OpenBraceToken]: '{'; + [SyntaxKind.AmpersandAmpersandToken]: '&&'; + [SyntaxKind.AmpersandToken]: '&'; + [SyntaxKind.AsteriskAsteriskToken]: '**'; + [SyntaxKind.AsteriskToken]: '*'; + [SyntaxKind.AtToken]: '@'; + [SyntaxKind.BacktickToken]: '`'; + [SyntaxKind.BarBarToken]: '||'; + [SyntaxKind.BarToken]: '|'; + [SyntaxKind.CaretToken]: '^'; [SyntaxKind.CloseBraceToken]: '}'; - [SyntaxKind.OpenParenToken]: '('; - [SyntaxKind.CloseParenToken]: ')'; - [SyntaxKind.OpenBracketToken]: '['; [SyntaxKind.CloseBracketToken]: ']'; - [SyntaxKind.DotToken]: '.'; - [SyntaxKind.DotDotDotToken]: '...'; - [SyntaxKind.SemicolonToken]: ';'; + [SyntaxKind.CloseParenToken]: ')'; + [SyntaxKind.ColonToken]: ':'; [SyntaxKind.CommaToken]: ','; - [SyntaxKind.QuestionDotToken]: '?.'; - [SyntaxKind.LessThanToken]: '<'; - [SyntaxKind.LessThanSlashToken]: ''; - [SyntaxKind.LessThanEqualsToken]: '<='; - [SyntaxKind.GreaterThanEqualsToken]: '>='; - [SyntaxKind.EqualsEqualsToken]: '=='; - [SyntaxKind.ExclamationEqualsToken]: '!='; + [SyntaxKind.DotDotDotToken]: '...'; + [SyntaxKind.DotToken]: '.'; [SyntaxKind.EqualsEqualsEqualsToken]: '==='; - [SyntaxKind.ExclamationEqualsEqualsToken]: '!=='; + [SyntaxKind.EqualsEqualsToken]: '=='; [SyntaxKind.EqualsGreaterThanToken]: '=>'; - [SyntaxKind.PlusToken]: '+'; + [SyntaxKind.ExclamationEqualsEqualsToken]: '!=='; + [SyntaxKind.ExclamationEqualsToken]: '!='; + [SyntaxKind.ExclamationToken]: '!'; + [SyntaxKind.GreaterThanEqualsToken]: '>='; + [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: '>>>'; + [SyntaxKind.GreaterThanGreaterThanToken]: '>>'; + [SyntaxKind.GreaterThanToken]: '>'; + [SyntaxKind.HashToken]: '#'; + [SyntaxKind.LessThanEqualsToken]: '<='; + [SyntaxKind.LessThanLessThanToken]: '<<'; + [SyntaxKind.LessThanSlashToken]: '>'; - [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: '>>>'; - [SyntaxKind.AmpersandToken]: '&'; - [SyntaxKind.BarToken]: '|'; - [SyntaxKind.CaretToken]: '^'; - [SyntaxKind.ExclamationToken]: '!'; - [SyntaxKind.TildeToken]: '~'; - [SyntaxKind.AmpersandAmpersandToken]: '&&'; - [SyntaxKind.BarBarToken]: '||'; - [SyntaxKind.QuestionToken]: '?'; - [SyntaxKind.ColonToken]: ':'; - [SyntaxKind.AtToken]: '@'; + [SyntaxKind.PlusToken]: '+'; + [SyntaxKind.QuestionDotToken]: '?.'; [SyntaxKind.QuestionQuestionToken]: '??'; - [SyntaxKind.BacktickToken]: '`'; - [SyntaxKind.HashToken]: '#'; + [SyntaxKind.QuestionToken]: '?'; + [SyntaxKind.SemicolonToken]: ';'; + [SyntaxKind.SlashToken]: '/'; + [SyntaxKind.TildeToken]: '~'; } diff --git a/packages/ast-spec/src/token/RegularExpressionToken/spec.ts b/packages/ast-spec/src/token/RegularExpressionToken/spec.ts index 7b0bb09d5262..a60a58d1ecbd 100644 --- a/packages/ast-spec/src/token/RegularExpressionToken/spec.ts +++ b/packages/ast-spec/src/token/RegularExpressionToken/spec.ts @@ -2,9 +2,9 @@ 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; + pattern: string; }; + type: AST_TOKEN_TYPES.RegularExpression; } diff --git a/packages/ast-spec/src/type/TSArrayType/spec.ts b/packages/ast-spec/src/type/TSArrayType/spec.ts index f7aa4f16a596..82a71db74c37 100644 --- a/packages/ast-spec/src/type/TSArrayType/spec.ts +++ b/packages/ast-spec/src/type/TSArrayType/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { TypeNode } from '../../unions/TypeNode'; export interface TSArrayType extends BaseNode { - type: AST_NODE_TYPES.TSArrayType; elementType: TypeNode; + type: AST_NODE_TYPES.TSArrayType; } diff --git a/packages/ast-spec/src/type/TSConditionalType/spec.ts b/packages/ast-spec/src/type/TSConditionalType/spec.ts index 979fcb3e6026..59ec3ece270b 100644 --- a/packages/ast-spec/src/type/TSConditionalType/spec.ts +++ b/packages/ast-spec/src/type/TSConditionalType/spec.ts @@ -3,9 +3,9 @@ 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; + trueType: TypeNode; + type: AST_NODE_TYPES.TSConditionalType; } diff --git a/packages/ast-spec/src/type/TSConstructorType/spec.ts b/packages/ast-spec/src/type/TSConstructorType/spec.ts index 08e19757d14a..b6d5797f39c6 100644 --- a/packages/ast-spec/src/type/TSConstructorType/spec.ts +++ b/packages/ast-spec/src/type/TSConstructorType/spec.ts @@ -2,6 +2,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; abstract: boolean; + type: AST_NODE_TYPES.TSConstructorType; } diff --git a/packages/ast-spec/src/type/TSImportType/spec.ts b/packages/ast-spec/src/type/TSImportType/spec.ts index f85074de7154..34143ed919c4 100644 --- a/packages/ast-spec/src/type/TSImportType/spec.ts +++ b/packages/ast-spec/src/type/TSImportType/spec.ts @@ -5,8 +5,8 @@ import type { EntityName } from '../../unions/EntityName'; import type { TypeNode } from '../../unions/TypeNode'; export interface TSImportType extends BaseNode { - type: AST_NODE_TYPES.TSImportType; argument: TypeNode; qualifier: EntityName | null; + type: AST_NODE_TYPES.TSImportType; typeArguments: TSTypeParameterInstantiation | null; } diff --git a/packages/ast-spec/src/type/TSIndexedAccessType/spec.ts b/packages/ast-spec/src/type/TSIndexedAccessType/spec.ts index 86a22e22a16e..54b1fd99b074 100644 --- a/packages/ast-spec/src/type/TSIndexedAccessType/spec.ts +++ b/packages/ast-spec/src/type/TSIndexedAccessType/spec.ts @@ -3,7 +3,7 @@ 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; + objectType: TypeNode; + type: AST_NODE_TYPES.TSIndexedAccessType; } diff --git a/packages/ast-spec/src/type/TSLiteralType/spec.ts b/packages/ast-spec/src/type/TSLiteralType/spec.ts index 39f6ae0d2961..ccdd0265ac2b 100644 --- a/packages/ast-spec/src/type/TSLiteralType/spec.ts +++ b/packages/ast-spec/src/type/TSLiteralType/spec.ts @@ -5,6 +5,6 @@ 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; + type: AST_NODE_TYPES.TSLiteralType; } diff --git a/packages/ast-spec/src/type/TSMappedType/spec.ts b/packages/ast-spec/src/type/TSMappedType/spec.ts index 44f64ac8621a..46041e852dcc 100644 --- a/packages/ast-spec/src/type/TSMappedType/spec.ts +++ b/packages/ast-spec/src/type/TSMappedType/spec.ts @@ -5,15 +5,13 @@ import type { TSTypeParameter } from '../../special/TSTypeParameter/spec'; import type { TypeNode } from '../../unions/TypeNode'; export interface TSMappedType extends BaseNode { - type: AST_NODE_TYPES.TSMappedType; - - /** @deprecated Use {@link `constraint`} and {@link `key`} instead. */ - typeParameter: TSTypeParameter; - constraint: TypeNode; key: Identifier; - readonly: boolean | '-' | '+' | undefined; - optional: boolean | '-' | '+' | undefined; - typeAnnotation: TypeNode | undefined; nameType: TypeNode | null; + optional: '+' | '-' | boolean | undefined; + readonly: '+' | '-' | boolean | undefined; + type: AST_NODE_TYPES.TSMappedType; + typeAnnotation: TypeNode | undefined; + /** @deprecated Use {@link `constraint`} and {@link `key`} instead. */ + typeParameter: TSTypeParameter; } diff --git a/packages/ast-spec/src/type/TSNamedTupleMember/spec.ts b/packages/ast-spec/src/type/TSNamedTupleMember/spec.ts index 540d8bf19db5..29e5fadf4d3d 100644 --- a/packages/ast-spec/src/type/TSNamedTupleMember/spec.ts +++ b/packages/ast-spec/src/type/TSNamedTupleMember/spec.ts @@ -4,8 +4,8 @@ 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; + type: AST_NODE_TYPES.TSNamedTupleMember; } diff --git a/packages/ast-spec/src/type/TSQualifiedName/spec.ts b/packages/ast-spec/src/type/TSQualifiedName/spec.ts index cdd6feeee0ef..61c61702b5b9 100644 --- a/packages/ast-spec/src/type/TSQualifiedName/spec.ts +++ b/packages/ast-spec/src/type/TSQualifiedName/spec.ts @@ -4,7 +4,7 @@ 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; + type: AST_NODE_TYPES.TSQualifiedName; } diff --git a/packages/ast-spec/src/type/TSTemplateLiteralType/spec.ts b/packages/ast-spec/src/type/TSTemplateLiteralType/spec.ts index c2e8783da873..052b82c6241b 100644 --- a/packages/ast-spec/src/type/TSTemplateLiteralType/spec.ts +++ b/packages/ast-spec/src/type/TSTemplateLiteralType/spec.ts @@ -4,7 +4,7 @@ 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[]; + type: AST_NODE_TYPES.TSTemplateLiteralType; types: TypeNode[]; } diff --git a/packages/ast-spec/src/type/TSTupleType/spec.ts b/packages/ast-spec/src/type/TSTupleType/spec.ts index 641a0c15b4c6..58fec673558b 100644 --- a/packages/ast-spec/src/type/TSTupleType/spec.ts +++ b/packages/ast-spec/src/type/TSTupleType/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { TypeNode } from '../../unions/TypeNode'; export interface TSTupleType extends BaseNode { - type: AST_NODE_TYPES.TSTupleType; elementTypes: TypeNode[]; + type: AST_NODE_TYPES.TSTupleType; } diff --git a/packages/ast-spec/src/type/TSTypeLiteral/spec.ts b/packages/ast-spec/src/type/TSTypeLiteral/spec.ts index 243179d23d9f..838a7e7e97a0 100644 --- a/packages/ast-spec/src/type/TSTypeLiteral/spec.ts +++ b/packages/ast-spec/src/type/TSTypeLiteral/spec.ts @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode'; import type { TypeElement } from '../../unions/TypeElement'; export interface TSTypeLiteral extends BaseNode { - type: AST_NODE_TYPES.TSTypeLiteral; members: TypeElement[]; + type: AST_NODE_TYPES.TSTypeLiteral; } diff --git a/packages/ast-spec/src/type/TSTypeOperator/spec.ts b/packages/ast-spec/src/type/TSTypeOperator/spec.ts index f6d530c084f0..f38c0fc950cb 100644 --- a/packages/ast-spec/src/type/TSTypeOperator/spec.ts +++ b/packages/ast-spec/src/type/TSTypeOperator/spec.ts @@ -3,7 +3,7 @@ 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'; + type: AST_NODE_TYPES.TSTypeOperator; typeAnnotation: TypeNode | undefined; } diff --git a/packages/ast-spec/src/type/TSTypePredicate/spec.ts b/packages/ast-spec/src/type/TSTypePredicate/spec.ts index cd34a31bcaf0..dd296ebc2a24 100644 --- a/packages/ast-spec/src/type/TSTypePredicate/spec.ts +++ b/packages/ast-spec/src/type/TSTypePredicate/spec.ts @@ -5,8 +5,8 @@ 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; + type: AST_NODE_TYPES.TSTypePredicate; typeAnnotation: TSTypeAnnotation | null; } diff --git a/packages/ast-spec/src/type/TSTypeQuery/spec.ts b/packages/ast-spec/src/type/TSTypeQuery/spec.ts index e5cad59b9c71..0a09d2cf48a5 100644 --- a/packages/ast-spec/src/type/TSTypeQuery/spec.ts +++ b/packages/ast-spec/src/type/TSTypeQuery/spec.ts @@ -5,7 +5,7 @@ import type { EntityName } from '../../unions/EntityName'; import type { TSImportType } from '../TSImportType/spec'; export interface TSTypeQuery extends BaseNode { - type: AST_NODE_TYPES.TSTypeQuery; exprName: EntityName | TSImportType; + type: AST_NODE_TYPES.TSTypeQuery; typeArguments: TSTypeParameterInstantiation | undefined; } diff --git a/packages/ast-spec/tests/fixtures.test.ts b/packages/ast-spec/tests/fixtures.test.ts index e0cdcc832fe2..87a42cffa6d3 100644 --- a/packages/ast-spec/tests/fixtures.test.ts +++ b/packages/ast-spec/tests/fixtures.test.ts @@ -1,16 +1,16 @@ -import fs from 'node:fs'; -import path from 'node:path'; - import * as glob from 'glob'; import makeDir from 'make-dir'; +import fs from 'node:fs'; +import path from 'node:path'; -import { parseBabel } from './util/parsers/babel'; import type { Fixture, ParserResponse, ParserResponseError, ParserResponseSuccess, } from './util/parsers/parser-types'; + +import { parseBabel } from './util/parsers/babel'; import { ParserResponseType } from './util/parsers/parser-types'; import { parseTSESTree } from './util/parsers/typescript-estree'; import { serializeError } from './util/serialize-error'; @@ -29,28 +29,28 @@ const fixturesWithASTDifferences = new Set(); const fixturesWithTokenDifferences = new Set(); const fixturesConfiguredToExpectBabelToNotSupport = new Map(); enum ErrorLabel { - TSESTree = "TSESTree errored but Babel didn't", Babel = "Babel errored but TSESTree didn't", Both = 'Both errored', None = 'No errors', + TSESTree = "TSESTree errored but Babel didn't", } const fixturesWithErrorDifferences = { - [ErrorLabel.TSESTree]: new Set(), [ErrorLabel.Babel]: new Set(), + [ErrorLabel.TSESTree]: new Set(), } as const; const VALID_FIXTURES: readonly string[] = glob.sync( `**/fixtures/*/fixture.{ts,tsx}`, { - cwd: SRC_DIR, absolute: true, + cwd: SRC_DIR, }, ); const ERROR_FIXTURES: readonly string[] = glob.sync( `**/fixtures/_error_/*/fixture.{ts,tsx}`, { - cwd: SRC_DIR, absolute: true, + cwd: SRC_DIR, }, ); @@ -80,33 +80,33 @@ const FIXTURES: readonly Fixture[] = [...VALID_FIXTURES, ...ERROR_FIXTURES].map( relative: path.relative(SRC_DIR, absolute).replaceAll('\\', '/'), segments, snapshotFiles: { + error: { + alignment: (i: number) => + path.join(snapshotPath, `${i}-Alignment-Error.shot`), + babel: (i: number) => + path.join(snapshotPath, `${i}-Babel-Error.shot`), + tsestree: (i: number) => + path.join(snapshotPath, `${i}-TSESTree-Error.shot`), + }, success: { - tsestree: { + alignment: { ast: (i: number) => - path.join(snapshotPath, `${i}-TSESTree-AST.shot`), + path.join(snapshotPath, `${i}-AST-Alignment-AST.shot`), tokens: (i: number) => - path.join(snapshotPath, `${i}-TSESTree-Tokens.shot`), + path.join(snapshotPath, `${i}-AST-Alignment-Tokens.shot`), }, babel: { ast: (i: number) => path.join(snapshotPath, `${i}-Babel-AST.shot`), tokens: (i: number) => path.join(snapshotPath, `${i}-Babel-Tokens.shot`), }, - alignment: { + tsestree: { ast: (i: number) => - path.join(snapshotPath, `${i}-AST-Alignment-AST.shot`), + path.join(snapshotPath, `${i}-TSESTree-AST.shot`), tokens: (i: number) => - path.join(snapshotPath, `${i}-AST-Alignment-Tokens.shot`), + path.join(snapshotPath, `${i}-TSESTree-Tokens.shot`), }, }, - error: { - tsestree: (i: number) => - path.join(snapshotPath, `${i}-TSESTree-Error.shot`), - babel: (i: number) => - path.join(snapshotPath, `${i}-Babel-Error.shot`), - alignment: (i: number) => - path.join(snapshotPath, `${i}-Alignment-Error.shot`), - }, }, snapshotPath, }; @@ -277,9 +277,6 @@ function nestDescribe(fixture: Fixture, segments = fixture.segments): void { it('Should parse with no errors', () => { // log the error for debug purposes in case there wasn't supposed to be an error switch (errorLabel) { - case ErrorLabel.None: - return; - case ErrorLabel.Babel: expectErrorResponse(babelParsed); if (fixture.config.expectBabelToNotSupport == null) { @@ -287,15 +284,18 @@ function nestDescribe(fixture: Fixture, segments = fixture.segments): void { } break; - case ErrorLabel.TSESTree: + case ErrorLabel.Both: + expectErrorResponse(babelParsed); expectErrorResponse(tsestreeParsed); + console.error('Babel:\n', babelParsed.error); console.error('TSESTree:\n', tsestreeParsed.error); break; - case ErrorLabel.Both: - expectErrorResponse(babelParsed); + case ErrorLabel.None: + return; + + case ErrorLabel.TSESTree: expectErrorResponse(tsestreeParsed); - console.error('Babel:\n', babelParsed.error); console.error('TSESTree:\n', tsestreeParsed.error); break; } diff --git a/packages/ast-spec/tests/util/parsers/babel.ts b/packages/ast-spec/tests/util/parsers/babel.ts index 54ccd07f7e72..26a62a576c1d 100644 --- a/packages/ast-spec/tests/util/parsers/babel.ts +++ b/packages/ast-spec/tests/util/parsers/babel.ts @@ -1,7 +1,9 @@ import type { ParserOptions } from '@babel/core'; + import { parse } from '@babel/eslint-parser'; import type { Fixture, ParserResponse } from './parser-types'; + import { ParserResponseType } from './parser-types'; const PLUGINS: NonNullable = [ @@ -35,18 +37,18 @@ export function parseBabel(fixture: Fixture, contents: string): ParserResponse { requireConfigFile: false, sourceType: 'unambiguous', }); - const { tokens: _, comments: __, ...program } = result; + const { comments: __, tokens: _, ...program } = result; return { - type: ParserResponseType.NoError, ast: program, error: 'NO ERROR', tokens: result.tokens, + type: ParserResponseType.NoError, }; } catch (error: unknown) { return { - type: ParserResponseType.Error, error, + type: ParserResponseType.Error, }; } } diff --git a/packages/ast-spec/tests/util/parsers/parser-types.ts b/packages/ast-spec/tests/util/parsers/parser-types.ts index 496ba192236b..6c96e3d893f6 100644 --- a/packages/ast-spec/tests/util/parsers/parser-types.ts +++ b/packages/ast-spec/tests/util/parsers/parser-types.ts @@ -15,15 +15,15 @@ export interface Fixture { readonly relative: string; readonly segments: string[]; readonly snapshotFiles: { - readonly success: { - readonly tsestree: SuccessSnapshotPaths; - readonly babel: SuccessSnapshotPaths; - readonly alignment: SuccessSnapshotPaths; - }; readonly error: { - readonly tsestree: SnapshotPathFn; - readonly babel: SnapshotPathFn; readonly alignment: SnapshotPathFn; + readonly babel: SnapshotPathFn; + readonly tsestree: SnapshotPathFn; + }; + readonly success: { + readonly alignment: SuccessSnapshotPaths; + readonly babel: SuccessSnapshotPaths; + readonly tsestree: SuccessSnapshotPaths; }; }; readonly snapshotPath: string; @@ -35,14 +35,14 @@ export enum ParserResponseType { } export interface ParserResponseSuccess { - readonly type: ParserResponseType.NoError; readonly ast: unknown; // this exists for the error alignment test snapshots readonly error: 'NO ERROR'; readonly tokens: unknown; + readonly type: ParserResponseType.NoError; } export interface ParserResponseError { - readonly type: ParserResponseType.Error; readonly error: unknown; + readonly type: ParserResponseType.Error; } export type ParserResponse = ParserResponseError | ParserResponseSuccess; diff --git a/packages/ast-spec/tests/util/parsers/typescript-estree.ts b/packages/ast-spec/tests/util/parsers/typescript-estree.ts index e73330a2f576..c3cdb6e14193 100644 --- a/packages/ast-spec/tests/util/parsers/typescript-estree.ts +++ b/packages/ast-spec/tests/util/parsers/typescript-estree.ts @@ -1,4 +1,5 @@ import type { Fixture, ParserResponse } from './parser-types'; + import { ParserResponseType } from './parser-types'; import { parse } from './typescript-estree-import'; @@ -16,18 +17,18 @@ export function parseTSESTree( suppressDeprecatedPropertyWarnings: true, tokens: true, }); - const { tokens: _, comments: __, ...program } = result; + const { comments: __, tokens: _, ...program } = result; return { - type: ParserResponseType.NoError, ast: program, error: 'NO ERROR', tokens: result.tokens, + type: ParserResponseType.NoError, }; } catch (error: unknown) { return { - type: ParserResponseType.Error, error, + type: ParserResponseType.Error, }; } } diff --git a/packages/ast-spec/tests/util/serialize-error.ts b/packages/ast-spec/tests/util/serialize-error.ts index aa071edbe174..8a54fe232230 100644 --- a/packages/ast-spec/tests/util/serialize-error.ts +++ b/packages/ast-spec/tests/util/serialize-error.ts @@ -8,17 +8,17 @@ export function serializeError(error: unknown, contents: string): unknown { } const { - name, + location: { end, start }, message, - location: { start, end }, + name, } = error; return `${name} ${codeFrameColumns( contents, { - start: { line: start.line, column: start.column + 1 }, - end: { line: end.line, column: end.column + 1 }, + end: { column: end.column + 1, line: end.line }, + start: { column: start.column + 1, line: start.line }, }, { highlightCode: false, message }, )}`; diff --git a/packages/ast-spec/tests/util/serializers/Node.ts b/packages/ast-spec/tests/util/serializers/Node.ts index a0fe170f4501..73d394b9ce3f 100644 --- a/packages/ast-spec/tests/util/serializers/Node.ts +++ b/packages/ast-spec/tests/util/serializers/Node.ts @@ -1,6 +1,7 @@ import type { NewPlugin } from 'pretty-format'; import type * as TSESTree from '../../../src'; + import { AST_NODE_TYPES } from '../../../src'; function sortKeys( @@ -38,11 +39,8 @@ function hasValidType(type: unknown): type is string { } const serializer: NewPlugin = { - test(val: unknown) { - return isObject(val) && hasValidType(val.type); - }, serialize( - node: TSESTree.Node & Record, + node: Record & TSESTree.Node, config, indentation, depth, @@ -88,6 +86,9 @@ const serializer: NewPlugin = { return outputLines.join('\n'); }, + test(val: unknown) { + return isObject(val) && hasValidType(val.type); + }, }; export { serializer }; diff --git a/packages/ast-spec/tests/util/serializers/string.ts b/packages/ast-spec/tests/util/serializers/string.ts index 399124eaa139..5d399d1a14fd 100644 --- a/packages/ast-spec/tests/util/serializers/string.ts +++ b/packages/ast-spec/tests/util/serializers/string.ts @@ -3,9 +3,6 @@ import type { NewPlugin } from 'pretty-format'; // custom string serializer so that we can use single-quoted strings instead of double quoted strings // this plays nicer with the way that the snapshot diff result, which is a pure string const serializer: NewPlugin = { - test(val: unknown) { - return typeof val === 'string'; - }, serialize( str: string, // config, @@ -33,6 +30,9 @@ const serializer: NewPlugin = { return characters.join(''); }, + test(val: unknown) { + return typeof val === 'string'; + }, }; export { serializer }; diff --git a/packages/ast-spec/tests/util/snapshot-diff.ts b/packages/ast-spec/tests/util/snapshot-diff.ts index 8da117f8ba36..4587f4ad1134 100644 --- a/packages/ast-spec/tests/util/snapshot-diff.ts +++ b/packages/ast-spec/tests/util/snapshot-diff.ts @@ -18,13 +18,13 @@ function diffStrings( expand: false, // we want to show the entire file in the diff // that way you don't have to try and figure out what lines map to which sections - contextLines: Number.MAX_SAFE_INTEGER, aAnnotation: valueAName, - bAnnotation: valueBName, aColor: identity, + bAnnotation: valueBName, bColor: identity, changeColor: identity, commonColor: identity, + contextLines: Number.MAX_SAFE_INTEGER, patchColor: identity, }); } diff --git a/packages/ast-spec/typings/babel-eslint-parser.d.ts b/packages/ast-spec/typings/babel-eslint-parser.d.ts index 4bcf8911caf3..bed3516269d0 100644 --- a/packages/ast-spec/typings/babel-eslint-parser.d.ts +++ b/packages/ast-spec/typings/babel-eslint-parser.d.ts @@ -14,9 +14,9 @@ declare module '@babel/eslint-parser' { } export interface BabelAST { - readonly tokens: unknown; readonly comments: unknown; readonly [k: string]: unknown; + readonly tokens: unknown; } export function parse(code: string, options: Options): BabelAST; From 08988caf65f5188974cdcb63d9ba28032be51896 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 20 Aug 2024 15:40:17 -0400 Subject: [PATCH 2/2] fix: TODO comment for TSModuleDeclaration --- packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts b/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts index 3c47fd1e449b..6072ae41b071 100644 --- a/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts +++ b/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts @@ -23,7 +23,6 @@ interface TSModuleDeclarationBase extends BaseNode { */ declare: boolean; // TODO - remove this in the next major (we have `.kind` now) - global: boolean; /** * Whether this is a global declaration * @example @@ -33,6 +32,7 @@ interface TSModuleDeclarationBase extends BaseNode { * * @deprecated Use {@link kind} instead */ + global: boolean; /** * The name of the module * ```