From 5d99110c21060dd4ed23a9754c06a817b55447c4 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Sep 2024 14:35:54 -0400 Subject: [PATCH 01/10] Add initial slim AstNode API --- scripts/build/options.mjs | 3 +- scripts/build/tests.mjs | 1 + src/compiler/_namespaces/ts.ast.ts | 8 + src/compiler/_namespaces/ts.ts | 5 +- src/compiler/ast.ts | 10422 ++++++++++++++++ src/compiler/debug.ts | 159 +- src/compiler/factory/astNodeFactory.ts | 5922 +++++++++ src/compiler/factory/astNodeTests.ts | 1475 +++ src/compiler/factory/astParenthesizerRules.ts | 821 ++ src/compiler/factory/baseNodeFactory.ts | 60 - src/compiler/factory/emitNode.ts | 46 +- src/compiler/factory/nodeFactory.ts | 4718 ++----- src/compiler/factory/parenthesizerRules.ts | 599 +- src/compiler/parser.ts | 70 +- src/compiler/transformers/es2015.ts | 3 + src/compiler/types.ts | 449 +- src/compiler/utilities.ts | 64 +- src/compiler/utilitiesPublic.ts | 14 +- src/harness/harnessUtils.ts | 130 +- src/harness/typeWriter.ts | 8 +- src/services/services.ts | 638 +- src/services/textChanges.ts | 4 +- src/testRunner/unittests/helpers.ts | 3 +- src/testRunner/unittests/jsDocParsing.ts | 2 +- src/testRunner/unittests/transform.ts | 2 +- ...Correctly.@@ does not start a new tag.json | 3 + ...ocComments.parsesCorrectly.@link tags.json | 48 + ...y.Chained tags, no leading whitespace.json | 8 + ...ectly.Initial star space is not a tag.json | 2 + ...ts.parsesCorrectly.Nested @param tags.json | 12 + ...parsesCorrectly.argSynonymForParamTag.json | 5 + ...sCorrectly.argumentSynonymForParamTag.json | 5 + ...parsesCorrectly.asteriskAfterPreamble.json | 4 + ...DocComments.parsesCorrectly.authorTag.json | 51 + ...sCorrectly.consecutive newline tokens.json | 2 + ...omments.parsesCorrectly.exceptionTag1.json | 5 + ...omments.parsesCorrectly.exceptionTag2.json | 2 + ...omments.parsesCorrectly.exceptionTag3.json | 5 + ...ocComments.parsesCorrectly.importTag1.json | 5 + ...ocComments.parsesCorrectly.importTag2.json | 8 +- ...ocComments.parsesCorrectly.importTag3.json | 6 + ...ocComments.parsesCorrectly.importTag4.json | 6 + ...ments.parsesCorrectly.leadingAsterisk.json | 4 + ...less-than and greater-than characters.json | 3 + ...ly.no space before @ is not a new tag.json | 10 + ...nts.parsesCorrectly.noLeadingAsterisk.json | 4 + ...Comments.parsesCorrectly.noReturnType.json | 2 + ...cComments.parsesCorrectly.oneParamTag.json | 5 + ...DocComments.parsesCorrectly.paramTag1.json | 5 + ...arsesCorrectly.paramTagBracketedName1.json | 5 + ...arsesCorrectly.paramTagBracketedName2.json | 5 + ...parsesCorrectly.paramTagNameThenType1.json | 5 + ...parsesCorrectly.paramTagNameThenType2.json | 5 + ...ents.parsesCorrectly.paramWithoutType.json | 3 + ...ocComments.parsesCorrectly.returnTag1.json | 4 + ...ocComments.parsesCorrectly.returnTag2.json | 4 + ...cComments.parsesCorrectly.returnsTag1.json | 4 + ...Comments.parsesCorrectly.satisfiesTag.json | 4 + ...cComments.parsesCorrectly.templateTag.json | 4 + ...Comments.parsesCorrectly.templateTag2.json | 6 + ...Comments.parsesCorrectly.templateTag3.json | 6 + ...Comments.parsesCorrectly.templateTag4.json | 6 + ...Comments.parsesCorrectly.templateTag5.json | 6 + ...Comments.parsesCorrectly.templateTag6.json | 6 + ...ocComments.parsesCorrectly.throwsTag1.json | 5 + ...ocComments.parsesCorrectly.throwsTag2.json | 2 + ...ocComments.parsesCorrectly.throwsTag3.json | 5 + ...Comments.parsesCorrectly.twoParamTag2.json | 10 + ...parsesCorrectly.twoParamTagOnSameLine.json | 10 + .../DocComments.parsesCorrectly.typeTag.json | 4 + ...sCorrectly.typedefTagWithChildrenTags.json | 15 + ...s.parsesCorrectly.functionReturnType1.json | 2 +- ...essions.parsesCorrectly.functionType2.json | 2 +- ...rrectly.functionTypeWithTrailingComma.json | 2 +- ...eExpressions.parsesCorrectly.newType1.json | 2 +- ...Expressions.parsesCorrectly.thisType1.json | 2 +- tests/baselines/reference/api/typescript.d.ts | 317 +- ...deprecated-ParseForTypeErrors-file.js.diff | 2 +- ...deprecated-ParseForTypeErrors-file.ts.diff | 6 +- .../deprecated-ParseForTypeInfo-file.js.diff | 2 +- .../deprecated-ParseForTypeInfo-file.ts.diff | 10 +- .../deprecated-ParseNone-file.js.diff | 10 +- .../deprecated-ParseNone-file.ts.diff | 10 +- .../link-ParseForTypeErrors-file.js.diff | 2 +- .../link-ParseForTypeErrors-file.ts.diff | 2 +- .../link-ParseForTypeInfo-file.js.diff | 2 +- .../link-ParseForTypeInfo-file.ts.diff | 2 +- .../link-ParseNone-file.js.diff | 2 +- .../link-ParseNone-file.ts.diff | 2 +- .../see-ParseForTypeErrors-file.js.diff | 2 +- .../see-ParseForTypeErrors-file.ts.diff | 2 +- .../see-ParseForTypeInfo-file.js.diff | 2 +- .../see-ParseForTypeInfo-file.ts.diff | 4 +- .../see-ParseNone-file.js.diff | 4 +- .../see-ParseNone-file.ts.diff | 4 +- 95 files changed, 20631 insertions(+), 5726 deletions(-) create mode 100644 src/compiler/_namespaces/ts.ast.ts create mode 100644 src/compiler/ast.ts create mode 100644 src/compiler/factory/astNodeFactory.ts create mode 100644 src/compiler/factory/astNodeTests.ts create mode 100644 src/compiler/factory/astParenthesizerRules.ts delete mode 100644 src/compiler/factory/baseNodeFactory.ts diff --git a/scripts/build/options.mjs b/scripts/build/options.mjs index 0d3a209335947..ac498b8576c41 100644 --- a/scripts/build/options.mjs +++ b/scripts/build/options.mjs @@ -4,7 +4,7 @@ import os from "os"; const ci = ["1", "true"].includes(process.env.CI ?? ""); const parsed = minimist(process.argv.slice(2), { - boolean: ["dirty", "light", "colors", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built", "ci", "bundle", "typecheck", "lint", "coverage"], + boolean: ["dirty", "light", "colors", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built", "ci", "bundle", "typecheck", "lint", "coverage", "bail"], string: ["browser", "tests", "break", "host", "reporter", "stackTraceLimit", "timeout", "shards", "shardId"], alias: { b: "browser", @@ -66,6 +66,7 @@ export default options; * @property {boolean} built * @property {boolean} soft * @property {boolean} fix + * @property {boolean} bail * @property {string} browser * @property {string} tests * @property {boolean} skipSysTests diff --git a/scripts/build/tests.mjs b/scripts/build/tests.mjs index ba9e03548a01b..19a29bde59858 100644 --- a/scripts/build/tests.mjs +++ b/scripts/build/tests.mjs @@ -98,6 +98,7 @@ export async function runConsoleTests(runJs, defaultReporter, runInParallel, opt // default timeout is 2sec which really should be enough, but maybe we just need a small amount longer if (!runInParallel) { args.push(mochaJs); + if (cmdLineOptions.bail) args.push("--bail"); args.push("-R", findUpFile("scripts/failed-tests.cjs")); args.push("-O", '"reporter=' + reporter + (keepFailed ? ",keepFailed=true" : "") + '"'); if (tests) { diff --git a/src/compiler/_namespaces/ts.ast.ts b/src/compiler/_namespaces/ts.ast.ts new file mode 100644 index 0000000000000..e80ad13e119b6 --- /dev/null +++ b/src/compiler/_namespaces/ts.ast.ts @@ -0,0 +1,8 @@ +/** @internal */ +export * from "../ast.js"; +/** @internal */ +export * from "../factory/astNodeTests.js"; +/** @internal */ +export * from "../factory/astNodeFactory.js"; +/** @internal */ +export * from "../factory/astParenthesizerRules.js"; diff --git a/src/compiler/_namespaces/ts.ts b/src/compiler/_namespaces/ts.ts index 94fb16857d38e..ba2aa8541c636 100644 --- a/src/compiler/_namespaces/ts.ts +++ b/src/compiler/_namespaces/ts.ts @@ -13,7 +13,6 @@ export * from "../diagnosticInformationMap.generated.js"; export * from "../scanner.js"; export * from "../utilitiesPublic.js"; export * from "../utilities.js"; -export * from "../factory/baseNodeFactory.js"; export * from "../factory/parenthesizerRules.js"; export * from "../factory/nodeConverters.js"; export * from "../factory/nodeFactory.js"; @@ -76,3 +75,7 @@ import * as moduleSpecifiers from "./ts.moduleSpecifiers.js"; export { moduleSpecifiers }; import * as performance from "./ts.performance.js"; export { performance }; +/** @internal */ +import * as ast from "./ts.ast.js"; +/** @internal */ +export { ast }; \ No newline at end of file diff --git a/src/compiler/ast.ts b/src/compiler/ast.ts new file mode 100644 index 0000000000000..ef895d1bac90b --- /dev/null +++ b/src/compiler/ast.ts @@ -0,0 +1,10422 @@ +import * as ts from "./_namespaces/ts.js"; +import { + __String, + AmdDependency, + AssignmentOperator, + BinaryOperator, + CheckJsDirective, + CommentDirective, + computePositionOfLineAndCharacter, + containsObjectRestOrSpread, + createMultiMap, + createScanner, + Debug, + DiagnosticWithLocation, + EmitFlags, + EmitNode, + emptyArray, + FileReference, + find, + FlowNode, + forEach, + forEachChild, + getAssignmentDeclarationKind, + getLineAndCharacterOfPosition, + getLineStarts, + getNodeChildren, + getNonAssignedNameOfDeclaration, + getSourceFileOfNode, + getTextOfIdentifierOrLiteral, + getTokenPosOfNode, + getTransformFlagsSubtreeExclusions, + hasProperty, + hasSyntacticModifier, + hasTabstop, + idText, + isBindingPattern, + isComputedPropertyName, + isJSDocCommentContainingNode, + isLogicalOrCoalescingAssignmentOperator, + isNamedExports, + isPrivateIdentifier, + isPropertyAccessExpression, + isPropertyName, + isStringOrNumericLiteralLike, + JSDocArray, + KeywordSyntaxKind, + LanguageVariant, + lastOrUndefined, + ModifierFlags, + ModifierSyntaxKind, + modifierToFlag, + NodeFlags, + NodeId, + PackageJsonInfo, + Path, + positionIsSynthesized, + PostfixUnaryOperator, + PrefixUnaryOperator, + PunctuationSyntaxKind, + ReadonlyPragmaMap, + ResolutionMode, + Scanner, + ScriptKind, + ScriptTarget, + setNodeChildren, + Symbol, + SymbolTable, + SyntaxKind, + TokenFlags, + TokenSyntaxKind, + TransformFlags, + Type, + TypeNodeSyntaxKind, + updateSourceFile, +} from "./_namespaces/ts.js"; +import { isAstParenthesizedExpression } from "./_namespaces/ts.ast.js"; + +/** @internal */ +export type NextContainer = AstNode; + +/** @internal */ +export class AstNodeId { + id: NodeId = 0; +} + +// TODO: This shouldn't be exported but not exporting breaks dtsBundler +/** @internal */ +export class AstNodeExtraFields { + id = new AstNodeId(); + original: AstNode | undefined = undefined; + emitNode: EmitNode | undefined = undefined; + modifierFlagsCache = ModifierFlags.None; + transformFlags: TransformFlags | undefined = undefined; + __pos: number | undefined = undefined; + __end: number | undefined = undefined; +} + +let astNodeCloneCore: (node: AstNode) => AstNode; +let astNodeShadowCore: (node: AstNode) => AstNode; +let astNodeMaybeExtra: (node: AstNode) => AstNodeExtraFields | undefined; + +/** @internal */ +export class AstNode = Node> { + static { + astNodeCloneCore = node => node.cloneCore(); + astNodeShadowCore = node => node.shadowCore(); + astNodeMaybeExtra = node => node._extra; + } + + private _node: N | undefined = undefined; + private _nodeConstructor: NodeConstructor = undefined!; + private _extra: AstNodeExtraFields | undefined = undefined; + + readonly kind: N["kind"] = 0; + readonly data: N["data"] = undefined!; + + parent: AstNode> | undefined = undefined; + flags: NodeFlags; + pos = -1; + end = -1; + + constructor(kind: N["kind"], data: N["data"], nodeConstructor: NodeConstructor, flags = NodeFlags.None) { + this.kind = kind; + this.data = data; + this.flags = flags; + this._nodeConstructor = nodeConstructor; + } + + get node() { return this._node ??= new this._nodeConstructor(this); } + + get id() { return this._extra?.id.id ?? 0; } + set id(value) { this.extra.id.id = value; } + get original() { return this._extra?.original; } + set original(value) { this.extra.original = value; } + get emitNode() { return this._extra?.emitNode; } + set emitNode(value) { this.extra.emitNode = value; } + get transformFlags() { + const transformFlags = this._extra?.transformFlags; + if (transformFlags === undefined) { + this.extra.transformFlags = TransformFlags.None; + return this.extra.transformFlags = this.data.computeTransformFlags(this); + } + return transformFlags; + } + set transformFlags(value) { this.extra.transformFlags = value; } + + get modifierFlagsCache() { return this._extra?.modifierFlagsCache ?? ModifierFlags.None; } + set modifierFlagsCache(value) { this.extra.modifierFlagsCache = value; } + + /*private*/ get extra() { return this._extra ??= new AstNodeExtraFields(); } + + /** + * Creates a shallow data-only clone of this node. + * + * Note to implementors: This method should not be overridden. + * @sealed + */ + clone(): AstNode { + return this.data.cloneNode(this); + } + + /** + * Creates a shallow data-only clone of this node. + * + * @virtual + */ + protected cloneCore(): AstNode { + const clone = new AstNode(this.kind, this.data.clone(), this._nodeConstructor, this.flags); + if (this._extra?.transformFlags !== undefined) clone.transformFlags = this.transformFlags; + return clone; + } + + /** + * Creates a new data object using this object as the prototype. + * This is primarily used for the purpose of redirecting source files. + * + * Note to implementors: This method should not be overridden. + * @sealed + */ + shadow(): AstNode { + return this.data.shadowNode(this); + } + + /** + * Creates a new data object using this object as the prototype. + * This is primarily used for the purpose of redirecting source files. + * + * @virtual + */ + protected shadowCore(): AstNode { + const clone = new AstNode(this.kind, this.data.shadow(), this._nodeConstructor, this.flags); + clone._extra = Object.create(this.extra); + clone.parent = this.parent; + clone.pos = this.pos; + clone.end = this.end; + return clone; + } + + static Token(kind: K) { + const makeToken = AstNode._tokenFactoryMap.get(kind); + return (makeToken ? makeToken() : new AstNode(kind, new AstTokenData(), Token)) as AstToken; + } + + private static _tokenFactoryMap = new Map AstToken>([ + [SyntaxKind.NumericLiteral, this.NumericLiteral], + [SyntaxKind.BigIntLiteral, this.BigIntLiteral], + [SyntaxKind.StringLiteral, this.StringLiteral], + [SyntaxKind.JsxText, this.JsxText], + [SyntaxKind.RegularExpressionLiteral, this.RegularExpressionLiteral], + [SyntaxKind.NoSubstitutionTemplateLiteral, this.NoSubstitutionTemplateLiteral], + [SyntaxKind.TemplateHead, this.TemplateHead], + [SyntaxKind.TemplateMiddle, this.TemplateMiddle], + [SyntaxKind.TemplateTail, this.TemplateTail], + [SyntaxKind.Identifier, this.Identifier], + [SyntaxKind.PrivateIdentifier, this.PrivateIdentifier], + [SyntaxKind.EndOfFileToken, this.EndOfFileToken], + [SyntaxKind.ThisKeyword, this.ThisExpression], + [SyntaxKind.SuperKeyword, this.SuperExpression], + [SyntaxKind.ImportKeyword, this.ImportExpression], + [SyntaxKind.NullKeyword, this.NullLiteral], + [SyntaxKind.TrueKeyword, this.TrueLiteral], + [SyntaxKind.FalseKeyword, this.FalseLiteral], + ]); + + static EndOfFileToken() { return new AstNode(SyntaxKind.EndOfFileToken, new AstEndOfFileTokenData(), EndOfFileToken); } + static ThisExpression() { return new AstNode(SyntaxKind.ThisKeyword, new AstThisExpressionData(), ThisExpression); } + static SuperExpression() { return new AstNode(SyntaxKind.SuperKeyword, new AstSuperExpressionData(), SuperExpression); } + static ImportExpression() { return new AstNode(SyntaxKind.ImportKeyword, new AstTokenData(), ImportExpression); } + static NullLiteral() { return new AstNode(SyntaxKind.NullKeyword, new AstTokenData(), NullLiteral); } + static TrueLiteral() { return new AstNode(SyntaxKind.TrueKeyword, new AstTokenData(), TrueLiteral); } + static FalseLiteral() { return new AstNode(SyntaxKind.FalseKeyword, new AstTokenData(), FalseLiteral); } + static Identifier() { return new AstNode(SyntaxKind.Identifier, new AstIdentifierData(), Identifier); } + static QualifiedName() { return new AstNode(SyntaxKind.QualifiedName, new AstQualifiedNameData(), QualifiedName); } + static ComputedPropertyName() { return new AstNode(SyntaxKind.ComputedPropertyName, new AstComputedPropertyNameData(), ComputedPropertyName); } + static PrivateIdentifier() { return new AstNode(SyntaxKind.PrivateIdentifier, new AstPrivateIdentifierData(), PrivateIdentifier); } + static TypeParameterDeclaration() { return new AstNode(SyntaxKind.TypeParameter, new AstTypeParameterDeclarationData(), TypeParameterDeclaration); } + static ParameterDeclaration() { return new AstNode(SyntaxKind.Parameter, new AstParameterDeclarationData(), ParameterDeclaration); } + static Decorator() { return new AstNode(SyntaxKind.Decorator, new AstDecoratorData(), Decorator); } + static PropertySignature() { return new AstNode(SyntaxKind.PropertySignature, new AstPropertySignatureData(), PropertySignature); } + static CallSignatureDeclaration() { return new AstNode(SyntaxKind.CallSignature, new AstCallSignatureDeclarationData(), CallSignatureDeclaration); } + static ConstructSignatureDeclaration() { return new AstNode(SyntaxKind.ConstructSignature, new AstConstructSignatureDeclarationData(), ConstructSignatureDeclaration); } + static VariableDeclaration() { return new AstNode(SyntaxKind.VariableDeclaration, new AstVariableDeclarationData(), VariableDeclaration); } + static VariableDeclarationList() { return new AstNode(SyntaxKind.VariableDeclarationList, new AstVariableDeclarationListData(), VariableDeclarationList); } + static BindingElement() { return new AstNode(SyntaxKind.BindingElement, new AstBindingElementData(), BindingElement); } + static PropertyDeclaration() { return new AstNode(SyntaxKind.PropertyDeclaration, new AstPropertyDeclarationData(), PropertyDeclaration); } + static PropertyAssignment() { return new AstNode(SyntaxKind.PropertyAssignment, new AstPropertyAssignmentData(), PropertyAssignment); } + static ShorthandPropertyAssignment() { return new AstNode(SyntaxKind.ShorthandPropertyAssignment, new AstShorthandPropertyAssignmentData(), ShorthandPropertyAssignment); } + static SpreadAssignment() { return new AstNode(SyntaxKind.SpreadAssignment, new AstSpreadAssignmentData(), SpreadAssignment); } + static ObjectBindingPattern() { return new AstNode(SyntaxKind.ObjectBindingPattern, new AstObjectBindingPatternData(), ObjectBindingPattern); } + static ArrayBindingPattern() { return new AstNode(SyntaxKind.ArrayBindingPattern, new AstArrayBindingPatternData(), ArrayBindingPattern); } + static FunctionDeclaration() { return new AstNode(SyntaxKind.FunctionDeclaration, new AstFunctionDeclarationData(), FunctionDeclaration); } + static MethodSignature() { return new AstNode(SyntaxKind.MethodSignature, new AstMethodSignatureData(), MethodSignature); } + static MethodDeclaration() { return new AstNode(SyntaxKind.MethodDeclaration, new AstMethodDeclarationData(), MethodDeclaration); } + static ConstructorDeclaration() { return new AstNode(SyntaxKind.Constructor, new AstConstructorDeclarationData(), ConstructorDeclaration); } + static SemicolonClassElement() { return new AstNode(SyntaxKind.SemicolonClassElement, new AstSemicolonClassElementData(), SemicolonClassElement); } + static GetAccessorDeclaration() { return new AstNode(SyntaxKind.GetAccessor, new AstGetAccessorDeclarationData(), GetAccessorDeclaration); } + static SetAccessorDeclaration() { return new AstNode(SyntaxKind.SetAccessor, new AstSetAccessorDeclarationData(), SetAccessorDeclaration); } + static IndexSignatureDeclaration() { return new AstNode(SyntaxKind.IndexSignature, new AstIndexSignatureDeclarationData(), IndexSignatureDeclaration); } + static ClassStaticBlockDeclaration() { return new AstNode(SyntaxKind.ClassStaticBlockDeclaration, new AstClassStaticBlockDeclarationData(), ClassStaticBlockDeclaration); } + /** @deprecated */ + static ImportTypeAssertionContainer() { return new AstNode(SyntaxKind.ImportTypeAssertionContainer, new AstImportTypeAssertionContainerData(), ImportTypeAssertionContainer); } + static ImportTypeNode() { return new AstNode(SyntaxKind.ImportType, new AstImportTypeNodeData(), ImportTypeNode); } + static ThisTypeNode() { return new AstNode(SyntaxKind.ThisType, new AstThisTypeNodeData(), ThisTypeNode); } + static FunctionTypeNode() { return new AstNode(SyntaxKind.FunctionType, new AstFunctionTypeNodeData(), FunctionTypeNode); } + static ConstructorTypeNode() { return new AstNode(SyntaxKind.ConstructorType, new AstConstructorTypeNodeData(), ConstructorTypeNode); } + static TypeReferenceNode() { return new AstNode(SyntaxKind.TypeReference, new AstTypeReferenceNodeData(), TypeReferenceNode); } + static TypePredicateNode() { return new AstNode(SyntaxKind.TypePredicate, new AstTypePredicateNodeData(), TypePredicateNode); } + static TypeQueryNode() { return new AstNode(SyntaxKind.TypeQuery, new AstTypeQueryNodeData(), TypeQueryNode); } + static TypeLiteralNode() { return new AstNode(SyntaxKind.TypeLiteral, new AstTypeLiteralNodeData(), TypeLiteralNode); } + static ArrayTypeNode() { return new AstNode(SyntaxKind.ArrayType, new AstArrayTypeNodeData(), ArrayTypeNode); } + static TupleTypeNode() { return new AstNode(SyntaxKind.TupleType, new AstTupleTypeNodeData(), TupleTypeNode); } + static NamedTupleMember() { return new AstNode(SyntaxKind.NamedTupleMember, new AstNamedTupleMemberData(), NamedTupleMember); } + static OptionalTypeNode() { return new AstNode(SyntaxKind.OptionalType, new AstOptionalTypeNodeData(), OptionalTypeNode); } + static RestTypeNode() { return new AstNode(SyntaxKind.RestType, new AstRestTypeNodeData(), RestTypeNode); } + static UnionTypeNode() { return new AstNode(SyntaxKind.UnionType, new AstUnionTypeNodeData(), UnionTypeNode); } + static IntersectionTypeNode() { return new AstNode(SyntaxKind.IntersectionType, new AstIntersectionTypeNodeData(), IntersectionTypeNode); } + static ConditionalTypeNode() { return new AstNode(SyntaxKind.ConditionalType, new AstConditionalTypeNodeData(), ConditionalTypeNode); } + static InferTypeNode() { return new AstNode(SyntaxKind.InferType, new AstInferTypeNodeData(), InferTypeNode); } + static ParenthesizedTypeNode() { return new AstNode(SyntaxKind.ParenthesizedType, new AstParenthesizedTypeNodeData(), ParenthesizedTypeNode); } + static TypeOperatorNode() { return new AstNode(SyntaxKind.TypeOperator, new AstTypeOperatorNodeData(), TypeOperatorNode); } + static IndexedAccessTypeNode() { return new AstNode(SyntaxKind.IndexedAccessType, new AstIndexedAccessTypeNodeData(), IndexedAccessTypeNode); } + static MappedTypeNode() { return new AstNode(SyntaxKind.MappedType, new AstMappedTypeNodeData(), MappedTypeNode); } + static LiteralTypeNode() { return new AstNode(SyntaxKind.LiteralType, new AstLiteralTypeNodeData(), LiteralTypeNode); } + static StringLiteral() { return new AstNode(SyntaxKind.StringLiteral, new AstStringLiteralData(), StringLiteral); } + static TemplateLiteralTypeNode() { return new AstNode(SyntaxKind.TemplateLiteralType, new AstTemplateLiteralTypeNodeData(), TemplateLiteralTypeNode); } + static TemplateLiteralTypeSpan() { return new AstNode(SyntaxKind.TemplateLiteralTypeSpan, new AstTemplateLiteralTypeSpanData(), TemplateLiteralTypeSpan); } + static OmittedExpression() { return new AstNode(SyntaxKind.OmittedExpression, new AstOmittedExpressionData(), OmittedExpression); } + static PrefixUnaryExpression() { return new AstNode(SyntaxKind.PrefixUnaryExpression, new AstPrefixUnaryExpressionData(), PrefixUnaryExpression); } + static PostfixUnaryExpression() { return new AstNode(SyntaxKind.PostfixUnaryExpression, new AstPostfixUnaryExpressionData(), PostfixUnaryExpression); } + static DeleteExpression() { return new AstNode(SyntaxKind.DeleteExpression, new AstDeleteExpressionData(), DeleteExpression); } + static TypeOfExpression() { return new AstNode(SyntaxKind.TypeOfExpression, new AstTypeOfExpressionData(), TypeOfExpression); } + static VoidExpression() { return new AstNode(SyntaxKind.VoidExpression, new AstVoidExpressionData(), VoidExpression); } + static AwaitExpression() { return new AstNode(SyntaxKind.AwaitExpression, new AstAwaitExpressionData(), AwaitExpression); } + static YieldExpression() { return new AstNode(SyntaxKind.YieldExpression, new AstYieldExpressionData(), YieldExpression); } + static BinaryExpression() { return new AstNode(SyntaxKind.BinaryExpression, new AstBinaryExpressionData(), BinaryExpression); } + static ConditionalExpression() { return new AstNode(SyntaxKind.ConditionalExpression, new AstConditionalExpressionData(), ConditionalExpression); } + static FunctionExpression() { return new AstNode(SyntaxKind.FunctionExpression, new AstFunctionExpressionData(), FunctionExpression); } + static ArrowFunction() { return new AstNode(SyntaxKind.ArrowFunction, new AstArrowFunctionData(), ArrowFunction); } + static RegularExpressionLiteral() { return new AstNode(SyntaxKind.RegularExpressionLiteral, new AstRegularExpressionLiteralData(), RegularExpressionLiteral); } + static NoSubstitutionTemplateLiteral() { return new AstNode(SyntaxKind.NoSubstitutionTemplateLiteral, new AstNoSubstitutionTemplateLiteralData(), NoSubstitutionTemplateLiteral); } + static NumericLiteral() { return new AstNode(SyntaxKind.NumericLiteral, new AstNumericLiteralData(), NumericLiteral); } + static BigIntLiteral() { return new AstNode(SyntaxKind.BigIntLiteral, new AstBigIntLiteralData(), BigIntLiteral); } + static TemplateHead() { return new AstNode(SyntaxKind.TemplateHead, new AstTemplateHeadData(), TemplateHead); } + static TemplateMiddle() { return new AstNode(SyntaxKind.TemplateMiddle, new AstTemplateMiddleData(), TemplateMiddle); } + static TemplateTail() { return new AstNode(SyntaxKind.TemplateTail, new AstTemplateTailData(), TemplateTail); } + static TemplateExpression() { return new AstNode(SyntaxKind.TemplateExpression, new AstTemplateExpressionData(), TemplateExpression); } + static TemplateSpan() { return new AstNode(SyntaxKind.TemplateSpan, new AstTemplateSpanData(), TemplateSpan); } + static ParenthesizedExpression() { return new AstNode(SyntaxKind.ParenthesizedExpression, new AstParenthesizedExpressionData(), ParenthesizedExpression); } + static ArrayLiteralExpression() { return new AstNode(SyntaxKind.ArrayLiteralExpression, new AstArrayLiteralExpressionData(), ArrayLiteralExpression); } + static SpreadElement() { return new AstNode(SyntaxKind.SpreadElement, new AstSpreadElementData(), SpreadElement); } + static ObjectLiteralExpression() { return new AstNode(SyntaxKind.ObjectLiteralExpression, new AstObjectLiteralExpressionData(), ObjectLiteralExpression); } + static PropertyAccessExpression() { return new AstNode(SyntaxKind.PropertyAccessExpression, new AstPropertyAccessExpressionData(), PropertyAccessExpression); } + static PropertyAccessChain() { return new AstNode(SyntaxKind.PropertyAccessExpression, new AstPropertyAccessExpressionData(), PropertyAccessExpression, NodeFlags.OptionalChain) as AstPropertyAccessChain; } + static ElementAccessExpression() { return new AstNode(SyntaxKind.ElementAccessExpression, new AstElementAccessExpressionData(), ElementAccessExpression); } + static ElementAccessChain() { return new AstNode(SyntaxKind.ElementAccessExpression, new AstElementAccessExpressionData(), ElementAccessExpression, NodeFlags.OptionalChain) as AstElementAccessChain; } + static CallExpression() { return new AstNode(SyntaxKind.CallExpression, new AstCallExpressionData(), CallExpression); } + static CallChain() { return new AstNode(SyntaxKind.CallExpression, new AstCallExpressionData(), CallExpression, NodeFlags.OptionalChain) as AstCallChain; } + static ExpressionWithTypeArguments() { return new AstNode(SyntaxKind.ExpressionWithTypeArguments, new AstExpressionWithTypeArgumentsData(), ExpressionWithTypeArguments); } + static NewExpression() { return new AstNode(SyntaxKind.NewExpression, new AstNewExpressionData(), NewExpression); } + static TaggedTemplateExpression() { return new AstNode(SyntaxKind.TaggedTemplateExpression, new AstTaggedTemplateExpressionData(), TaggedTemplateExpression); } + static AsExpression() { return new AstNode(SyntaxKind.AsExpression, new AstAsExpressionData(), AsExpression); } + static TypeAssertion() { return new AstNode(SyntaxKind.TypeAssertionExpression, new AstTypeAssertionData(), TypeAssertion); } + static SatisfiesExpression() { return new AstNode(SyntaxKind.SatisfiesExpression, new AstSatisfiesExpressionData(), SatisfiesExpression); } + static NonNullExpression() { return new AstNode(SyntaxKind.NonNullExpression, new AstNonNullExpressionData(), NonNullExpression); } + static NonNullChain() { return new AstNode(SyntaxKind.NonNullExpression, new AstNonNullExpressionData(), NonNullExpression, NodeFlags.OptionalChain) as AstNonNullChain; } + static MetaProperty() { return new AstNode(SyntaxKind.MetaProperty, new AstMetaPropertyData(), MetaProperty); } + static JsxElement() { return new AstNode(SyntaxKind.JsxElement, new AstJsxElementData(), JsxElement); } + static JsxAttributes() { return new AstNode(SyntaxKind.JsxAttributes, new AstJsxAttributesData(), JsxAttributes); } + static JsxNamespacedName() { return new AstNode(SyntaxKind.JsxNamespacedName, new AstJsxNamespacedNameData(), JsxNamespacedName); } + static JsxOpeningElement() { return new AstNode(SyntaxKind.JsxOpeningElement, new AstJsxOpeningElementData(), JsxOpeningElement); } + static JsxSelfClosingElement() { return new AstNode(SyntaxKind.JsxSelfClosingElement, new AstJsxSelfClosingElementData(), JsxSelfClosingElement); } + static JsxFragment() { return new AstNode(SyntaxKind.JsxFragment, new AstJsxFragmentData(), JsxFragment); } + static JsxOpeningFragment() { return new AstNode(SyntaxKind.JsxOpeningFragment, new AstJsxOpeningFragmentData(), JsxOpeningFragment); } + static JsxClosingFragment() { return new AstNode(SyntaxKind.JsxClosingFragment, new AstJsxClosingFragmentData(), JsxClosingFragment); } + static JsxAttribute() { return new AstNode(SyntaxKind.JsxAttribute, new AstJsxAttributeData(), JsxAttribute); } + static JsxSpreadAttribute() { return new AstNode(SyntaxKind.JsxSpreadAttribute, new AstJsxSpreadAttributeData(), JsxSpreadAttribute); } + static JsxClosingElement() { return new AstNode(SyntaxKind.JsxClosingElement, new AstJsxClosingElementData(), JsxClosingElement); } + static JsxExpression() { return new AstNode(SyntaxKind.JsxExpression, new AstJsxExpressionData(), JsxExpression); } + static JsxText() { return new AstNode(SyntaxKind.JsxText, new AstJsxTextData(), JsxText); } + static EmptyStatement() { return new AstNode(SyntaxKind.EmptyStatement, new AstEmptyStatementData(), EmptyStatement); } + static DebuggerStatement() { return new AstNode(SyntaxKind.DebuggerStatement, new AstDebuggerStatementData(), DebuggerStatement); } + static MissingDeclaration() { return new AstNode(SyntaxKind.MissingDeclaration, new AstMissingDeclarationData(), MissingDeclaration); } + static Block() { return new AstNode(SyntaxKind.Block, new AstBlockData(), Block); } + static VariableStatement() { return new AstNode(SyntaxKind.VariableStatement, new AstVariableStatementData(), VariableStatement); } + static ExpressionStatement() { return new AstNode(SyntaxKind.ExpressionStatement, new AstExpressionStatementData(), ExpressionStatement); } + static IfStatement() { return new AstNode(SyntaxKind.IfStatement, new AstIfStatementData(), IfStatement); } + static DoStatement() { return new AstNode(SyntaxKind.DoStatement, new AstDoStatementData(), DoStatement); } + static WhileStatement() { return new AstNode(SyntaxKind.WhileStatement, new AstWhileStatementData(), WhileStatement); } + static ForStatement() { return new AstNode(SyntaxKind.ForStatement, new AstForStatementData(), ForStatement); } + static ForInStatement() { return new AstNode(SyntaxKind.ForInStatement, new AstForInStatementData(), ForInStatement); } + static ForOfStatement() { return new AstNode(SyntaxKind.ForOfStatement, new AstForOfStatementData(), ForOfStatement); } + static BreakStatement() { return new AstNode(SyntaxKind.BreakStatement, new AstBreakStatementData(), BreakStatement); } + static ContinueStatement() { return new AstNode(SyntaxKind.ContinueStatement, new AstContinueStatementData(), ContinueStatement); } + static ReturnStatement() { return new AstNode(SyntaxKind.ReturnStatement, new AstReturnStatementData(), ReturnStatement); } + static WithStatement() { return new AstNode(SyntaxKind.WithStatement, new AstWithStatementData(), WithStatement); } + static SwitchStatement() { return new AstNode(SyntaxKind.SwitchStatement, new AstSwitchStatementData(), SwitchStatement); } + static CaseBlock() { return new AstNode(SyntaxKind.CaseBlock, new AstCaseBlockData(), CaseBlock); } + static CaseClause() { return new AstNode(SyntaxKind.CaseClause, new AstCaseClauseData(), CaseClause); } + static DefaultClause() { return new AstNode(SyntaxKind.DefaultClause, new AstDefaultClauseData(), DefaultClause); } + static LabeledStatement() { return new AstNode(SyntaxKind.LabeledStatement, new AstLabeledStatementData(), LabeledStatement); } + static ThrowStatement() { return new AstNode(SyntaxKind.ThrowStatement, new AstThrowStatementData(), ThrowStatement); } + static TryStatement() { return new AstNode(SyntaxKind.TryStatement, new AstTryStatementData(), TryStatement); } + static CatchClause() { return new AstNode(SyntaxKind.CatchClause, new AstCatchClauseData(), CatchClause); } + static ClassDeclaration() { return new AstNode(SyntaxKind.ClassDeclaration, new AstClassDeclarationData(), ClassDeclaration); } + static ClassExpression() { return new AstNode(SyntaxKind.ClassExpression, new AstClassExpressionData(), ClassExpression); } + static InterfaceDeclaration() { return new AstNode(SyntaxKind.InterfaceDeclaration, new AstInterfaceDeclarationData(), InterfaceDeclaration); } + static HeritageClause() { return new AstNode(SyntaxKind.HeritageClause, new AstHeritageClauseData(), HeritageClause); } + static TypeAliasDeclaration() { return new AstNode(SyntaxKind.TypeAliasDeclaration, new AstTypeAliasDeclarationData(), TypeAliasDeclaration); } + static EnumMember() { return new AstNode(SyntaxKind.EnumMember, new AstEnumMemberData(), EnumMember); } + static EnumDeclaration() { return new AstNode(SyntaxKind.EnumDeclaration, new AstEnumDeclarationData(), EnumDeclaration); } + static ModuleDeclaration() { return new AstNode(SyntaxKind.ModuleDeclaration, new AstModuleDeclarationData(), ModuleDeclaration); } + static ModuleBlock() { return new AstNode(SyntaxKind.ModuleBlock, new AstModuleBlockData(), ModuleBlock); } + static ImportEqualsDeclaration() { return new AstNode(SyntaxKind.ImportEqualsDeclaration, new AstImportEqualsDeclarationData(), ImportEqualsDeclaration); } + static ExternalModuleReference() { return new AstNode(SyntaxKind.ExternalModuleReference, new AstExternalModuleReferenceData(), ExternalModuleReference); } + static ImportDeclaration() { return new AstNode(SyntaxKind.ImportDeclaration, new AstImportDeclarationData(), ImportDeclaration); } + static ImportClause() { return new AstNode(SyntaxKind.ImportClause, new AstImportClauseData(), ImportClause); } + static ImportAttribute() { return new AstNode(SyntaxKind.ImportAttribute, new AstImportAttributeData(), ImportAttribute); } + static ImportAttributes() { return new AstNode(SyntaxKind.ImportAttributes, new AstImportAttributesData(), ImportAttributes); } + static NamespaceImport() { return new AstNode(SyntaxKind.NamespaceImport, new AstNamespaceImportData(), NamespaceImport); } + static NamespaceExport() { return new AstNode(SyntaxKind.NamespaceExport, new AstNamespaceExportData(), NamespaceExport); } + static NamespaceExportDeclaration() { return new AstNode(SyntaxKind.NamespaceExportDeclaration, new AstNamespaceExportDeclarationData(), NamespaceExportDeclaration); } + static ExportDeclaration() { return new AstNode(SyntaxKind.ExportDeclaration, new AstExportDeclarationData(), ExportDeclaration); } + static NamedImports() { return new AstNode(SyntaxKind.NamedImports, new AstNamedImportsData(), NamedImports); } + static NamedExports() { return new AstNode(SyntaxKind.NamedExports, new AstNamedExportsData(), NamedExports); } + static ImportSpecifier() { return new AstNode(SyntaxKind.ImportSpecifier, new AstImportSpecifierData(), ImportSpecifier); } + static ExportSpecifier() { return new AstNode(SyntaxKind.ExportSpecifier, new AstExportSpecifierData(), ExportSpecifier); } + static ExportAssignment() { return new AstNode(SyntaxKind.ExportAssignment, new AstExportAssignmentData(), ExportAssignment); } + static JSDocTypeExpression() { return new AstNode(SyntaxKind.JSDocTypeExpression, new AstJSDocTypeExpressionData(), JSDocTypeExpression); } + static JSDocNameReference() { return new AstNode(SyntaxKind.JSDocNameReference, new AstJSDocNameReferenceData(), JSDocNameReference); } + static JSDocMemberName() { return new AstNode(SyntaxKind.JSDocMemberName, new AstJSDocMemberNameData(), JSDocMemberName); } + static JSDocAllType() { return new AstNode(SyntaxKind.JSDocAllType, new AstJSDocAllTypeData(), JSDocAllType); } + static JSDocUnknownType() { return new AstNode(SyntaxKind.JSDocUnknownType, new AstJSDocUnknownTypeData(), JSDocUnknownType); } + static JSDocNonNullableType() { return new AstNode(SyntaxKind.JSDocNonNullableType, new AstJSDocNonNullableTypeData(), JSDocNonNullableType); } + static JSDocNullableType() { return new AstNode(SyntaxKind.JSDocNullableType, new AstJSDocNullableTypeData(), JSDocNullableType); } + static JSDocOptionalType() { return new AstNode(SyntaxKind.JSDocOptionalType, new AstJSDocOptionalTypeData(), JSDocOptionalType); } + static JSDocFunctionType() { return new AstNode(SyntaxKind.JSDocFunctionType, new AstJSDocFunctionTypeData(), JSDocFunctionType); } + static JSDocVariadicType() { return new AstNode(SyntaxKind.JSDocVariadicType, new AstJSDocVariadicTypeData(), JSDocVariadicType); } + static JSDocNamepathType() { return new AstNode(SyntaxKind.JSDocNamepathType, new AstJSDocNamepathTypeData(), JSDocNamepathType); } + static JSDocNode() { return new AstNode(SyntaxKind.JSDoc, new AstJSDocNodeData(), JSDocNode); } + static JSDocLink() { return new AstNode(SyntaxKind.JSDocLink, new AstJSDocLinkData(), JSDocLink); } + static JSDocLinkCode() { return new AstNode(SyntaxKind.JSDocLinkCode, new AstJSDocLinkCodeData(), JSDocLinkCode); } + static JSDocLinkPlain() { return new AstNode(SyntaxKind.JSDocLinkPlain, new AstJSDocLinkPlainData(), JSDocLinkPlain); } + static JSDocText() { return new AstNode(SyntaxKind.JSDocText, new AstJSDocTextData(), JSDocText); } + static JSDocUnknownTag() { return new AstNode(SyntaxKind.JSDocTag, new AstJSDocUnknownTagData(), JSDocUnknownTag); } + static JSDocAugmentsTag() { return new AstNode(SyntaxKind.JSDocAugmentsTag, new AstJSDocAugmentsTagData(), JSDocAugmentsTag); } + static JSDocImplementsTag() { return new AstNode(SyntaxKind.JSDocImplementsTag, new AstJSDocImplementsTagData(), JSDocImplementsTag); } + static JSDocAuthorTag() { return new AstNode(SyntaxKind.JSDocAuthorTag, new AstJSDocAuthorTagData(), JSDocAuthorTag); } + static JSDocDeprecatedTag() { return new AstNode(SyntaxKind.JSDocDeprecatedTag, new AstJSDocDeprecatedTagData(), JSDocDeprecatedTag); } + static JSDocClassTag() { return new AstNode(SyntaxKind.JSDocClassTag, new AstJSDocClassTagData(), JSDocClassTag); } + static JSDocPublicTag() { return new AstNode(SyntaxKind.JSDocPublicTag, new AstJSDocPublicTagData(), JSDocPublicTag); } + static JSDocPrivateTag() { return new AstNode(SyntaxKind.JSDocPrivateTag, new AstJSDocPrivateTagData(), JSDocPrivateTag); } + static JSDocProtectedTag() { return new AstNode(SyntaxKind.JSDocProtectedTag, new AstJSDocProtectedTagData(), JSDocProtectedTag); } + static JSDocReadonlyTag() { return new AstNode(SyntaxKind.JSDocReadonlyTag, new AstJSDocReadonlyTagData(), JSDocReadonlyTag); } + static JSDocOverrideTag() { return new AstNode(SyntaxKind.JSDocOverrideTag, new AstJSDocOverrideTagData(), JSDocOverrideTag); } + static JSDocEnumTag() { return new AstNode(SyntaxKind.JSDocEnumTag, new AstJSDocEnumTagData(), JSDocEnumTag); } + static JSDocThisTag() { return new AstNode(SyntaxKind.JSDocThisTag, new AstJSDocThisTagData(), JSDocThisTag); } + static JSDocTemplateTag() { return new AstNode(SyntaxKind.JSDocTemplateTag, new AstJSDocTemplateTagData(), JSDocTemplateTag); } + static JSDocSeeTag() { return new AstNode(SyntaxKind.JSDocSeeTag, new AstJSDocSeeTagData(), JSDocSeeTag); } + static JSDocReturnTag() { return new AstNode(SyntaxKind.JSDocReturnTag, new AstJSDocReturnTagData(), JSDocReturnTag); } + static JSDocTypeTag() { return new AstNode(SyntaxKind.JSDocTypeTag, new AstJSDocTypeTagData(), JSDocTypeTag); } + static JSDocTypedefTag() { return new AstNode(SyntaxKind.JSDocTypedefTag, new AstJSDocTypedefTagData(), JSDocTypedefTag); } + static JSDocCallbackTag() { return new AstNode(SyntaxKind.JSDocCallbackTag, new AstJSDocCallbackTagData(), JSDocCallbackTag); } + static JSDocOverloadTag() { return new AstNode(SyntaxKind.JSDocOverloadTag, new AstJSDocOverloadTagData(), JSDocOverloadTag); } + static JSDocThrowsTag() { return new AstNode(SyntaxKind.JSDocThrowsTag, new AstJSDocThrowsTagData(), JSDocThrowsTag); } + static JSDocSignature() { return new AstNode(SyntaxKind.JSDocSignature, new AstJSDocSignatureData(), JSDocSignature); } + static JSDocPropertyTag() { return new AstNode(SyntaxKind.JSDocPropertyTag, new AstJSDocPropertyTagData(), JSDocPropertyTag); } + static JSDocParameterTag() { return new AstNode(SyntaxKind.JSDocParameterTag, new AstJSDocParameterTagData(), JSDocParameterTag); } + static JSDocTypeLiteral() { return new AstNode(SyntaxKind.JSDocTypeLiteral, new AstJSDocTypeLiteralData(), JSDocTypeLiteral); } + static JSDocSatisfiesTag() { return new AstNode(SyntaxKind.JSDocSatisfiesTag, new AstJSDocSatisfiesTagData(), JSDocSatisfiesTag); } + static JSDocImportTag() { return new AstNode(SyntaxKind.JSDocImportTag, new AstJSDocImportTagData(), JSDocImportTag); } + static SourceFile() { return new AstNode(SyntaxKind.SourceFile, new AstSourceFileData(), SourceFile); } + static SyntheticExpression() { return new AstNode(SyntaxKind.SyntheticExpression, new AstSyntheticExpressionData(), SyntheticExpression); } + static Bundle() { return new AstNode(SyntaxKind.Bundle, new AstBundleData(), Bundle); } + static SyntaxList() { return new AstNode(SyntaxKind.SyntaxList, new AstSyntaxListData(), SyntaxList); } + static NotEmittedStatement() { return new AstNode(SyntaxKind.NotEmittedStatement, new AstNotEmittedStatementData(), NotEmittedStatement); } + static NotEmittedTypeElement() { return new AstNode(SyntaxKind.NotEmittedTypeElement, new AstNotEmittedTypeElementData(), NotEmittedTypeElement); } + static PartiallyEmittedExpression() { return new AstNode(SyntaxKind.PartiallyEmittedExpression, new AstPartiallyEmittedExpressionData(), PartiallyEmittedExpression); } + static CommaListExpression() { return new AstNode(SyntaxKind.CommaListExpression, new AstCommaListExpressionData(), CommaListExpression); } + static SyntheticReferenceExpression() { return new AstNode(SyntaxKind.SyntheticReferenceExpression, new AstSyntheticReferenceExpressionData(), SyntheticReferenceExpression); } +} + +type AstNodeOneOf = N extends unknown ? AstNode : never; + +/** @internal */ +export class AstData { + computeTransformFlags(node: AstNode): TransformFlags { + void node; + return TransformFlags.None; + } + + /** + * Controls cloning the provided node. + */ + cloneNode(node: AstNode): AstNode { + return astNodeCloneCore(node); + } + + /** + * Creates a shallow, member-wise clone of this data object. + */ + clone(): AstData { + const clone = this.createInstance(); + this.copyProperties(clone); + return clone; + } + + /** + * Creates a new instance of a data object with the same prototype as this object. + */ + protected createInstance(): AstData { + return Object.create(Object.getPrototypeOf(this)); + } + + /** + * Copies the properties of this object to the provided object. + */ + protected copyProperties(clone: AstData) { + for (const key in this) { + if (hasProperty(this, key)) { + (clone as any)[key] = (this as any)[key]; + } + } + } + + /** + * Controls creation of a shadow node for the provided node. + * This is primarily used for the purpose of redirecting source files. + */ + shadowNode(node: AstNode): AstNode { + return astNodeShadowCore(node); + } + + /** + * Creates a new data object using this object as the prototype. + * This is primarily used for the purpose of redirecting source files. + */ + shadow(): AstData { + return Object.create(this); + } +} + +/** @internal */ +export class AstTypeScriptNodeData extends AstData { + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.ContainsTypeScript; + } +} + +/** @internal */ +export class Node implements ts.Node { + readonly ast: AstNode>; + + constructor(ast: AstNode>) { + this.ast = ast; + + // catch any excess properties assigned to the Node + Object.preventExtensions(this); + } + + get kind(): K { return this.ast.kind; } + get data(): T { return this.ast.data; } + get pos(): number { return this.ast.pos; } + set pos(value) { this.ast.pos = value; } + get end(): number { return this.ast.end; } + set end(value) { this.ast.end = value; } + get flags(): NodeFlags { return this.ast.flags; } + set flags(value) { this.ast.flags = value; } + get modifierFlagsCache(): ModifierFlags { return this.ast.modifierFlagsCache; } + set modifierFlagsCache(value) { this.ast.modifierFlagsCache = value; } + get transformFlags(): TransformFlags { return this.ast.transformFlags; } + set transformFlags(value) { this.ast.transformFlags = value; } + get parent(): Node { return this.ast.parent?.node!; } // TODO: remove `!` + set parent(value) { this.ast.parent = value?.ast; } + get id(): number { return this.ast.id; } + set id(value) { this.ast.id = value; } + get original(): Node | undefined { return this.ast.original?.node; } + set original(value) { this.ast.original = value?.ast; } + get emitNode(): EmitNode | undefined { return this.ast.emitNode; } + set emitNode(value) { this.ast.emitNode = value; } + get __pos(): number | undefined { return astNodeMaybeExtra(this.ast)?.__pos; } // eslint-disable-line @typescript-eslint/naming-convention + set __pos(value) { this.ast.extra.__pos = value; } // eslint-disable-line @typescript-eslint/naming-convention + get __end(): number | undefined { return astNodeMaybeExtra(this.ast)?.__end; } // eslint-disable-line @typescript-eslint/naming-convention + set __end(value) { this.ast.extra.__end = value; } // eslint-disable-line @typescript-eslint/naming-convention + + // TODO: remove + validate() { + if (this.pos >= 0 && this.end >= 0) Debug.assert(this.pos <= this.end, "pos and end are out of order", () => `node.kind: ${Debug.formatSyntaxKind(this.kind)}`); + + let pos = this.pos; + this.forEachChild(child => { + (child as Node).validate(); + Debug.assert(child.pos === -1 || child.pos >= this.pos && child.pos <= this.end, `child.pos out of range`, () => `child.kind: ${Debug.formatSyntaxKind(child.kind)}`); + Debug.assert(child.end === -1 || child.end >= this.pos && child.end <= this.end, `child.end out of range`, () => `child.kind: ${Debug.formatSyntaxKind(child.kind)}`); + Debug.assert(child.pos === -1 || child.pos >= pos, `child.pos out of order`, () => `child.kind: ${Debug.formatSyntaxKind(child.kind)}`); + if (child.flags & NodeFlags.Synthesized) Debug.assert(this.flags & NodeFlags.Synthesized, "synthetic child in non-synthetic parent", () => `child.kind: ${Debug.formatSyntaxKind(child.kind)}`); + pos = child.end; + }, children => { + Debug.assert(children.pos === -1 || children.pos >= this.pos && children.pos <= this.end, `children.pos out of range`, () => `parent.kind: ${Debug.formatSyntaxKind(this.kind)}`); + Debug.assert(children.end === -1 || children.end >= this.pos && children.end <= this.end, `children.end out of range`, () => `parent.kind: ${Debug.formatSyntaxKind(this.kind)}`); + for (const child of children) { + (child as Node).validate(); + Debug.assert(child.pos === -1 || child.pos >= children.pos && child.pos <= children.end, `child.pos out of range`, () => `child.kind: ${Debug.formatSyntaxKind(child.kind)}`); + Debug.assert(child.end === -1 || child.end >= children.pos && child.end <= children.end, `child.end out of range`, () => `child.kind: ${Debug.formatSyntaxKind(child.kind)}`); + Debug.assert(child.pos === -1 || child.pos >= pos, `child.pos out of order`, () => `child.kind: ${Debug.formatSyntaxKind(child.kind)}`); + if (child.flags & NodeFlags.Synthesized) Debug.assert(this.flags & NodeFlags.Synthesized, "synthetic child in non-synthetic parent", () => `child.kind: ${Debug.formatSyntaxKind(child.kind)}`); + pos = child.end; + } + }); + Debug.assert(pos <= this.end, "children extend past end of parent", () => `parent.kind: ${Debug.formatSyntaxKind(this.kind)}`); + } + + private assertHasRealPosition(message?: string) { + // eslint-disable-next-line local/debug-assert + Debug.assert(!positionIsSynthesized(this.pos) && !positionIsSynthesized(this.end), message || "Node must have a real position for this operation"); + } + + public getSourceFile(): ts.SourceFile { + return getSourceFileOfNode(this); + } + + public getStart(sourceFile?: ts.SourceFileLike, includeJsDocComment?: boolean): number { + this.assertHasRealPosition(); + return getTokenPosOfNode(this, sourceFile, includeJsDocComment); + } + + public getFullStart(): number { + this.assertHasRealPosition(); + return this.pos; + } + + public getEnd(): number { + this.assertHasRealPosition(); + return this.end; + } + + public getWidth(sourceFile?: ts.SourceFile): number { + this.assertHasRealPosition(); + return this.getEnd() - this.getStart(sourceFile); + } + + public getFullWidth(): number { + this.assertHasRealPosition(); + return this.end - this.pos; + } + + public getLeadingTriviaWidth(sourceFile?: ts.SourceFile): number { + this.assertHasRealPosition(); + return this.getStart(sourceFile) - this.pos; + } + + public getFullText(sourceFile?: ts.SourceFile): string { + this.assertHasRealPosition(); + return (sourceFile || this.getSourceFile()).text.substring(this.pos, this.end); + } + + public getText(sourceFile?: ts.SourceFile): string { + this.assertHasRealPosition(); + if (!sourceFile) { + sourceFile = this.getSourceFile(); + } + return sourceFile.text.substring(this.getStart(sourceFile), this.getEnd()); + } + + public getChildCount(sourceFile?: ts.SourceFile): number { + return this.getChildren(sourceFile).length; + } + + public getChildAt(index: number, sourceFile?: ts.SourceFile): ts.Node { + return this.getChildren(sourceFile)[index]; + } + + public getChildren(sourceFile: ts.SourceFileLike = getSourceFileOfNode(this)): readonly ts.Node[] { + this.assertHasRealPosition("Node without a real position cannot be scanned and thus has no token nodes - use forEachChild and collect the result if that's fine"); + return getNodeChildren(this, sourceFile) ?? setNodeChildren(this, sourceFile, createChildren(this, sourceFile)); + } + + public getFirstToken(sourceFile?: ts.SourceFileLike): ts.Node | undefined { + this.assertHasRealPosition(); + const children = this.getChildren(sourceFile) as readonly Node[]; + if (!children.length) { + return undefined; + } + + const child = find(children, kid => kid.kind < SyntaxKind.FirstJSDocNode || kid.kind > SyntaxKind.LastJSDocNode)!; + return child.kind < SyntaxKind.FirstNode ? + child : + child.getFirstToken(sourceFile); + } + + public getLastToken(sourceFile?: ts.SourceFileLike): ts.Node | undefined { + this.assertHasRealPosition(); + const children = this.getChildren(sourceFile) as readonly Node[]; + + const child = lastOrUndefined(children); + if (!child) { + return undefined; + } + + return child.kind < SyntaxKind.FirstNode ? child : child.getLastToken(sourceFile); + } + + public forEachChild(cbNode: (node: ts.Node) => T, cbNodeArray?: (nodes: ts.NodeArray) => T): T | undefined { + return forEachChild(this, cbNode, cbNodeArray); + } +} + +Debug.registerDebugInfo(() => { + if (!ts.hasProperty(Node.prototype, "__debugKind")) { + const weakNodeTextMap = new WeakMap(); + + Object.defineProperties(Node.prototype, { + // for use with vscode-js-debug's new customDescriptionGenerator in launch.json + __tsDebuggerDisplay: { + value(this: Node) { + const nodeHeader = + ts.isGeneratedIdentifier(this) ? "GeneratedIdentifier" : + ts.isIdentifier(this) ? `Identifier '${idText(this)}'` : + ts.isPrivateIdentifier(this) ? `PrivateIdentifier '${idText(this)}'` : + ts.isStringLiteral(this) ? `StringLiteral ${JSON.stringify(this.text.length < 10 ? this.text : this.text.slice(10) + "...")}` : + ts.isNumericLiteral(this) ? `NumericLiteral ${this.text}` : + ts.isBigIntLiteral(this) ? `BigIntLiteral ${this.text}n` : + ts.isTypeParameterDeclaration(this) ? "TypeParameterDeclaration" : + ts.isParameter(this) ? "ParameterDeclaration" : + ts.isConstructorDeclaration(this) ? "ConstructorDeclaration" : + ts.isGetAccessorDeclaration(this) ? "GetAccessorDeclaration" : + ts.isSetAccessorDeclaration(this) ? "SetAccessorDeclaration" : + ts.isCallSignatureDeclaration(this) ? "CallSignatureDeclaration" : + ts.isConstructSignatureDeclaration(this) ? "ConstructSignatureDeclaration" : + ts.isIndexSignatureDeclaration(this) ? "IndexSignatureDeclaration" : + ts.isTypePredicateNode(this) ? "TypePredicateNode" : + ts.isTypeReferenceNode(this) ? "TypeReferenceNode" : + ts.isFunctionTypeNode(this) ? "FunctionTypeNode" : + ts.isConstructorTypeNode(this) ? "ConstructorTypeNode" : + ts.isTypeQueryNode(this) ? "TypeQueryNode" : + ts.isTypeLiteralNode(this) ? "TypeLiteralNode" : + ts.isArrayTypeNode(this) ? "ArrayTypeNode" : + ts.isTupleTypeNode(this) ? "TupleTypeNode" : + ts.isOptionalTypeNode(this) ? "OptionalTypeNode" : + ts.isRestTypeNode(this) ? "RestTypeNode" : + ts.isUnionTypeNode(this) ? "UnionTypeNode" : + ts.isIntersectionTypeNode(this) ? "IntersectionTypeNode" : + ts.isConditionalTypeNode(this) ? "ConditionalTypeNode" : + ts.isInferTypeNode(this) ? "InferTypeNode" : + ts.isParenthesizedTypeNode(this) ? "ParenthesizedTypeNode" : + ts.isThisTypeNode(this) ? "ThisTypeNode" : + ts.isTypeOperatorNode(this) ? "TypeOperatorNode" : + ts.isIndexedAccessTypeNode(this) ? "IndexedAccessTypeNode" : + ts.isMappedTypeNode(this) ? "MappedTypeNode" : + ts.isLiteralTypeNode(this) ? "LiteralTypeNode" : + ts.isNamedTupleMember(this) ? "NamedTupleMember" : + ts.isImportTypeNode(this) ? "ImportTypeNode" : + Debug.formatSyntaxKind(this.kind); + return `${nodeHeader}${this.flags ? ` (${Debug.formatNodeFlags(this.flags)})` : ""}`; + }, + }, + __debugKind: { + get(this: Node) { + return Debug.formatSyntaxKind(this.kind); + }, + }, + __debugNodeFlags: { + get(this: Node) { + return Debug.formatNodeFlags(this.flags); + }, + }, + __debugModifierFlags: { + get(this: Node) { + return Debug.formatModifierFlags(ts.getEffectiveModifierFlagsNoCache(this)); + }, + }, + __debugTransformFlags: { + get(this: Node) { + return Debug.formatTransformFlags(this.transformFlags); + }, + }, + __debugIsParseTreeNode: { + get(this: Node) { + return ts.isParseTreeNode(this); + }, + }, + __debugEmitFlags: { + get(this: Node) { + return Debug.formatEmitFlags(ts.getEmitFlags(this)); + }, + }, + __debugGetText: { + value(this: Node, includeTrivia?: boolean) { + if (ts.nodeIsSynthesized(this)) return ""; + // avoid recomputing + let text = weakNodeTextMap.get(this); + if (text === undefined) { + const parseNode = ts.getParseTreeNode(this); + const sourceFile = parseNode && getSourceFileOfNode(parseNode); + text = sourceFile ? ts.getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : ""; + weakNodeTextMap.set(this, text); + } + return text; + }, + }, + }); + } +}); + +/** @internal */ +export type NodeConstructor = new (ast: AstNode>) => N; + +/** @internal */ +export class AstNodeArrayExtraFields { + nodes: NodeArray | undefined = undefined; + hasTrailingComma: boolean = false; + transformFlags: TransformFlags | undefined = undefined; + __pos: number | undefined = undefined; + __end: number | undefined = undefined; +} + +let astNodeArrayMaybeExtra: (nodes: AstNodeArray) => AstNodeArrayExtraFields | undefined; + +/** @internal */ +export class AstNodeArray { + static { + astNodeArrayMaybeExtra = nodes => nodes._extra; + } + + readonly items: readonly N[] = undefined!; + pos = -1; + end = -1; + + private _extra: AstNodeArrayExtraFields | undefined = undefined; + + constructor(items: readonly N[], hasTrailingComma = false) { + this.items = items; + this.hasTrailingComma = hasTrailingComma; + } + + /** @private */ get extra() { return this._extra ??= new AstNodeArrayExtraFields(); } + + get nodes() { return this.extra.nodes ??= new NodeArray(this); } + get hasTrailingComma() { return this._extra?.hasTrailingComma ?? false; } + set hasTrailingComma(value) { this.extra.hasTrailingComma = value; } + + get transformFlags() { + let transformFlags = this._extra?.transformFlags; + if (transformFlags === undefined) { + transformFlags = TransformFlags.None; + for (const child of this.items) { + transformFlags |= propagateChildFlags(child); + } + this.extra.transformFlags = transformFlags; + } + return transformFlags; + } + set transformFlags(value) { this.extra.transformFlags = value; } +} + +/** @internal */ +export class NodeArray extends Array implements ts.NodeArray { + readonly ast: AstNodeArray; + + constructor(ast: AstNodeArray) { + super(...ast.items.map(item => item.node as N)); + this.ast = ast; + + // catch any excess properties assigned to the array + Object.preventExtensions(this); + } + + static override get [globalThis.Symbol.species]() { return Array; } + + get pos() { return this.ast.pos; } + set pos(value) { this.ast.pos = value; } + get end() { return this.ast.end; } + set end(value) { this.ast.end = value; } + get hasTrailingComma() { return this.ast.hasTrailingComma; } + set hasTrailingComma(value) { this.ast.hasTrailingComma = value; } + get transformFlags() { return this.ast.transformFlags; } + set transformFlags(value) { this.ast.transformFlags = value; } + + get __pos() { return astNodeArrayMaybeExtra(this.ast)?.__pos; } // eslint-disable-line @typescript-eslint/naming-convention + set __pos(value) { this.ast.extra.__pos = value; } // eslint-disable-line @typescript-eslint/naming-convention + get __end() { return astNodeArrayMaybeExtra(this.ast)?.__end; } // eslint-disable-line @typescript-eslint/naming-convention + set __end(value) { this.ast.extra.__end = value; } // eslint-disable-line @typescript-eslint/naming-convention +} + +Debug.registerDebugInfo(() => { + if (!("__tsDebuggerDisplay" in NodeArray.prototype)) { // eslint-disable-line local/no-in-operator + Object.defineProperties(NodeArray.prototype, { + __tsDebuggerDisplay: { + value(this: NodeArray, defaultValue: string) { + // An `Array` with extra properties is rendered as `[A, B, prop1: 1, prop2: 2]`. Most of + // these aren't immediately useful so we trim off the `prop1: ..., prop2: ...` part from the + // formatted string. + // This regex can trigger slow backtracking because of overlapping potential captures. + // We don't care, this is debug code that's only enabled with a debugger attached - + // we're just taking note of it for anyone checking regex performance in the future. + defaultValue = String(defaultValue).replace(/(?:,[\s\w]+:[^,]+)+\]$/, "]"); + return `NodeArray ${defaultValue}`; + }, + }, + }); + } +}); + +/** @internal */ +export interface JSDocContainer extends Node { + _jsdocContainerBrand: any; + + get jsDoc(): JSDocArray | undefined; + set jsDoc(value: JSDocArray | undefined); +} + +/** @internal */ +export interface FlowContainer extends Node { + _flowContainerBrand: any; + + get flowNode(): FlowNode | undefined; + set flowNode(value: FlowNode | undefined); +} + +/** @internal */ +export interface LocalsContainer extends Node { + _localsContainerBrand: any; + + get locals(): SymbolTable | undefined; + set locals(value: SymbolTable | undefined); + get nextContainer(): HasLocals | undefined; + set nextContainer(value: HasLocals | undefined); +} + +/** @internal */ +export type HasLocals = + | ArrowFunction + | Block + | CallSignatureDeclaration + | CaseBlock + | CatchClause + | ClassStaticBlockDeclaration + | ConditionalTypeNode + | ConstructorDeclaration + | ConstructorTypeNode + | ConstructSignatureDeclaration + | ForStatement + | ForInStatement + | ForOfStatement + | FunctionDeclaration + | FunctionExpression + | FunctionTypeNode + | GetAccessorDeclaration + | IndexSignatureDeclaration + | JSDocCallbackTag + | JSDocEnumTag + | JSDocFunctionType + | JSDocSignature + | JSDocTypedefTag + | MappedTypeNode + | MethodDeclaration + | MethodSignature + | ModuleDeclaration + | SetAccessorDeclaration + | SourceFile + | TypeAliasDeclaration; + +/** @internal */ +export type AstHasLocals = AstNodeOneOf; + +// NOTE: Changing the following list requires changes to: +// - `canHaveDecorators` in factory/utilities.ts +// - `updateModifiers` in factory/nodeFactory.ts +/** @internal */ +export type HasDecorators = + | ParameterDeclaration + | PropertyDeclaration + | MethodDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration + | ClassExpression + | ClassDeclaration; + +/** @internal */ +export type AstHasDecorators = AstNodeOneOf; + +// NOTE: Changing the following list requires changes to: +// - `canHaveModifiers` in factory/utilitiesPublic.ts +// - `updateModifiers` in factory/nodeFactory.ts +/** @internal */ +export type HasModifiers = + | TypeParameterDeclaration + | ParameterDeclaration + | ConstructorTypeNode + | PropertySignature + | PropertyDeclaration + | MethodSignature + | MethodDeclaration + | ConstructorDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration + | IndexSignatureDeclaration + | FunctionExpression + | ArrowFunction + | ClassExpression + | VariableStatement + | FunctionDeclaration + | ClassDeclaration + | InterfaceDeclaration + | TypeAliasDeclaration + | EnumDeclaration + | ModuleDeclaration + | ImportEqualsDeclaration + | ImportDeclaration + | ExportAssignment + | ExportDeclaration; + +/** @internal */ +export type AstHasModifiers = AstNodeOneOf; + +/** @internal */ +export interface Declaration extends Node { + readonly ast: AstDeclaration; + _declarationBrand: any; + + get symbol(): Symbol; + set symbol(value: Symbol); + get localSymbol(): Symbol | undefined; + set localSymbol(value: Symbol | undefined); +} + +/** @internal */ +export type AstDeclaration = AstNode; + +/** @internal */ +export interface TypeNode extends Node { + readonly ast: AstTypeNode; + _typeNodeBrand: any; +} + +/** @internal */ +export type AstTypeNode = AstNode>; + +/** @internal */ +export interface Statement extends JSDocContainer { + readonly ast: AstStatement; + _statementBrand: any; +} + +/** @internal */ +export type AstStatement = AstNode; + +/** @internal */ +export interface Expression extends Node { + readonly ast: AstExpression; + _expressionBrand: any; +} + +/** @internal */ +export type AstExpression = AstNode; + +/** @internal */ +export interface UnaryExpression extends Expression { + readonly ast: AstUnaryExpression; + _unaryExpressionBrand: any; +} + +/** @internal */ +export type AstUnaryExpression = AstNode; + +/** @internal */ +export interface UpdateExpression extends UnaryExpression { + readonly ast: AstUpdateExpression; + _updateExpressionBrand: any; +} + +/** @internal */ +export type AstUpdateExpression = AstNode; + +/** @internal */ +export interface LeftHandSideExpression extends UpdateExpression { + readonly ast: AstLeftHandSideExpression; + _leftHandSideExpressionBrand: any; +} + +/** @internal */ +export type AstLeftHandSideExpression = AstNode; + +/** @internal */ +export interface MemberExpression extends LeftHandSideExpression { + readonly ast: AstMemberExpression; + _memberExpressionBrand: any; +} + +/** @internal */ +export type AstMemberExpression = AstNode; + +/** @internal */ +export interface PrimaryExpression extends MemberExpression { + readonly ast: AstPrimaryExpression; + _primaryExpressionBrand: any; +} + +/** @internal */ +export type AstPrimaryExpression = AstNode; + +/** @internal */ +export interface LiteralExpression extends PrimaryExpression { + readonly ast: AstLiteralExpression; + _literalExpressionBrand: any; + + get text(): string; + set text(value: string); +} + +/** @internal */ +export type AstLiteralExpression = AstNode; + +/** @internal */ +export class Token extends Node implements ts.Token { + public override getChildCount(_sourceFile?: ts.SourceFile): number { + return this.getChildren().length; + } + + public override getChildAt(index: number, _sourceFile?: ts.SourceFile): ts.Node { + return this.getChildren()[index]; + } + + public override getChildren(_sourceFile?: ts.SourceFileLike): readonly ts.Node[] { + return this.kind === SyntaxKind.EndOfFileToken ? (this as Node as EndOfFileToken).jsDoc || emptyArray : emptyArray; + } + + public override getFirstToken(_sourceFile?: ts.SourceFileLike): ts.Node | undefined { + return undefined; + } + + public override getLastToken(_sourceFile?: ts.SourceFileLike): ts.Node | undefined { + return undefined; + } + + public override forEachChild(_cbNode: (node: ts.Node) => T, _cbNodeArray?: (nodes: ts.NodeArray) => T): T | undefined { + return undefined; + } +} + +/** @internal */ +export class AstTokenData extends AstData { + override computeTransformFlags(node: AstNode): TransformFlags { + switch (node.kind) { + case SyntaxKind.AsyncKeyword: + // 'async' modifier is ES2017 (async functions) or ES2018 (async generators) + return TransformFlags.ContainsES2017 | TransformFlags.ContainsES2018; + case SyntaxKind.UsingKeyword: + return TransformFlags.ContainsESNext; + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + case SyntaxKind.ReadonlyKeyword: + case SyntaxKind.AbstractKeyword: + case SyntaxKind.DeclareKeyword: + case SyntaxKind.ConstKeyword: + case SyntaxKind.AnyKeyword: + case SyntaxKind.NumberKeyword: + case SyntaxKind.BigIntKeyword: + case SyntaxKind.NeverKeyword: + case SyntaxKind.ObjectKeyword: + case SyntaxKind.InKeyword: + case SyntaxKind.OutKeyword: + case SyntaxKind.OverrideKeyword: + case SyntaxKind.StringKeyword: + case SyntaxKind.BooleanKeyword: + case SyntaxKind.SymbolKeyword: + case SyntaxKind.VoidKeyword: + case SyntaxKind.UnknownKeyword: + case SyntaxKind.UndefinedKeyword: // `undefined` is an Identifier in the expression case. + return TransformFlags.ContainsTypeScript; + case SyntaxKind.SuperKeyword: + return TransformFlags.ContainsES2015 | TransformFlags.ContainsLexicalSuper; + case SyntaxKind.StaticKeyword: + return TransformFlags.ContainsES2015; + case SyntaxKind.AccessorKeyword: + return TransformFlags.ContainsClassFields; + case SyntaxKind.ThisKeyword: + // 'this' indicates a lexical 'this' + return TransformFlags.ContainsLexicalThis; + } + return TransformFlags.None; + } +} + +/** @internal */ +export class EndOfFileToken extends Token implements JSDocContainer, ts.EndOfFileToken { + declare readonly ast: AstEndOfFileToken; + + declare _jsdocContainerBrand: any; + + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } +} + +/** @internal */ +export class AstEndOfFileTokenData extends AstTokenData { + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) +} + +/** @internal */ +export class ThisExpression extends Token implements PrimaryExpression, FlowContainer, ts.ThisExpression { + declare readonly ast: AstThisExpression; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _flowContainerBrand: any; + + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstThisExpressionData extends AstTokenData { + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) +} + +/** @internal */ +export class SuperExpression extends Token implements PrimaryExpression, FlowContainer, ts.SuperExpression { + declare readonly ast: AstSuperExpression; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _flowContainerBrand: any; + + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstSuperExpressionData extends AstTokenData { + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) +} + +/** @internal */ +export class ImportExpression extends Token implements PrimaryExpression, ts.ImportExpression { + declare readonly ast: AstImportExpression; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; +} + +/** @internal */ +export class NullLiteral extends Token implements PrimaryExpression, ts.NullLiteral { + declare readonly ast: AstNullLiteral; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; +} + +/** @internal */ +export class TrueLiteral extends Token implements PrimaryExpression, ts.TrueLiteral { + declare readonly ast: AstTrueLiteral; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; +} + +/** @internal */ +export class FalseLiteral extends Token implements PrimaryExpression, ts.FalseLiteral { + declare readonly ast: AstFalseLiteral; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; +} + +/** @internal */ +export type BooleanLiteral = + | TrueLiteral + | FalseLiteral + ; + +/** @internal */ +export type AstBooleanLiteral = AstNodeOneOf; + +// Punctuation + +/** @internal */ +export interface PunctuationToken extends Token { } + +/** @internal */ +export type DotToken = PunctuationToken; +/** @internal */ +export type DotDotDotToken = PunctuationToken; +/** @internal */ +export type QuestionToken = PunctuationToken; +/** @internal */ +export type ExclamationToken = PunctuationToken; +/** @internal */ +export type ColonToken = PunctuationToken; +/** @internal */ +export type EqualsToken = PunctuationToken; +/** @internal */ +export type AmpersandAmpersandEqualsToken = PunctuationToken; +/** @internal */ +export type BarBarEqualsToken = PunctuationToken; +/** @internal */ +export type QuestionQuestionEqualsToken = PunctuationToken; +/** @internal */ +export type AsteriskToken = PunctuationToken; +/** @internal */ +export type EqualsGreaterThanToken = PunctuationToken; +/** @internal */ +export type PlusToken = PunctuationToken; +/** @internal */ +export type MinusToken = PunctuationToken; +/** @internal */ +export type QuestionDotToken = PunctuationToken; + +/** @internal */ +export type AstPunctuationToken = AstNode>; + +/** @internal */ +export type AstDotToken = AstNode; +/** @internal */ +export type AstDotDotDotToken = AstNode; +/** @internal */ +export type AstQuestionToken = AstNode; +/** @internal */ +export type AstExclamationToken = AstNode; +/** @internal */ +export type AstColonToken = AstNode; +/** @internal */ +export type AstEqualsToken = AstNode; +/** @internal */ +export type AstAmpersandAmpersandEqualsToken = AstNode; +/** @internal */ +export type AstBarBarEqualsToken = AstNode; +/** @internal */ +export type AstQuestionQuestionEqualsToken = AstNode; +/** @internal */ +export type AstAsteriskToken = AstNode; +/** @internal */ +export type AstEqualsGreaterThanToken = AstNode; +/** @internal */ +export type AstPlusToken = AstNode; +/** @internal */ +export type AstMinusToken = AstNode; +/** @internal */ +export type AstQuestionDotToken = AstNode; + +// Keywords + +/** @internal */ +export interface KeywordToken extends Token { } + +/** @internal */ +export type AssertsKeyword = KeywordToken; +/** @internal */ +export type AssertKeyword = KeywordToken; +/** @internal */ +export type AwaitKeyword = KeywordToken; +/** @internal */ +export type CaseKeyword = KeywordToken; + +/** @internal */ +export type AstKeywordToken = AstNode>; + +/** @internal */ +export type AstAssertsKeyword = AstNode; +/** @internal */ +export type AstAssertKeyword = AstNode; +/** @internal */ +export type AstAwaitKeyword = AstNode; +/** @internal */ +export type AstCaseKeyword = AstNode; + +// Modifiers + +/** @internal */ +export interface ModifierToken extends KeywordToken { } + +/** @internal */ +export type AbstractKeyword = ModifierToken; +/** @internal */ +export type AccessorKeyword = ModifierToken; +/** @internal */ +export type AsyncKeyword = ModifierToken; +/** @internal */ +export type ConstKeyword = ModifierToken; +/** @internal */ +export type DeclareKeyword = ModifierToken; +/** @internal */ +export type DefaultKeyword = ModifierToken; +/** @internal */ +export type ExportKeyword = ModifierToken; +/** @internal */ +export type InKeyword = ModifierToken; +/** @internal */ +export type PrivateKeyword = ModifierToken; +/** @internal */ +export type ProtectedKeyword = ModifierToken; +/** @internal */ +export type PublicKeyword = ModifierToken; +/** @internal */ +export type ReadonlyKeyword = ModifierToken; +/** @internal */ +export type OutKeyword = ModifierToken; +/** @internal */ +export type OverrideKeyword = ModifierToken; +/** @internal */ +export type StaticKeyword = ModifierToken; + +/** @internal */ +export type AstModifierToken = AstNode>; + +/** @internal */ +export type AstAbstractKeyword = AstNode; +/** @internal */ +export type AstAccessorKeyword = AstNode; +/** @internal */ +export type AstAsyncKeyword = AstNode; +/** @internal */ +export type AstConstKeyword = AstNode; +/** @internal */ +export type AstDeclareKeyword = AstNode; +/** @internal */ +export type AstDefaultKeyword = AstNode; +/** @internal */ +export type AstExportKeyword = AstNode; +/** @internal */ +export type AstInKeyword = AstNode; +/** @internal */ +export type AstPrivateKeyword = AstNode; +/** @internal */ +export type AstProtectedKeyword = AstNode; +/** @internal */ +export type AstPublicKeyword = AstNode; +/** @internal */ +export type AstReadonlyKeyword = AstNode; +/** @internal */ +export type AstOutKeyword = AstNode; +/** @internal */ +export type AstOverrideKeyword = AstNode; +/** @internal */ +export type AstStaticKeyword = AstNode; + +/** @internal */ +export type Modifier = + | AbstractKeyword + | AccessorKeyword + | AsyncKeyword + | ConstKeyword + | DeclareKeyword + | DefaultKeyword + | ExportKeyword + | InKeyword + | PrivateKeyword + | ProtectedKeyword + | PublicKeyword + | OutKeyword + | OverrideKeyword + | ReadonlyKeyword + | StaticKeyword; + +/** @internal */ +export type AstModifier = AstNodeOneOf; + +/** @internal */ +export type ModifierLike = + | Modifier + | Decorator; + +/** @internal */ +export type AstModifierLike = AstNodeOneOf; + +/** @internal */ +export class Identifier extends Token implements PrimaryExpression, JSDocContainer, FlowContainer, Declaration, ts.Identifier { + declare readonly ast: AstIdentifier; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get escapedText(): __String { return this.ast.data.escapedText; } + set escapedText(value: __String) { this.ast.data.escapedText = value; } + get resolvedSymbol(): Symbol { return this.ast.data.resolvedSymbol; } + set resolvedSymbol(value: Symbol) { this.ast.data.resolvedSymbol = value; } + get symbol(): Symbol { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value) { this.ast.data.flowNode = value; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value) { this.ast.data.jsDoc = value; } + + get text() { return idText(this); } +} + +/** @internal */ +export class AstIdentifierData extends AstTokenData { + escapedText: __String = undefined!; + resolvedSymbol: Symbol = undefined!; // TransientIdentifier + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(node: AstNode): TransformFlags { + let transformFlags = TransformFlags.None; + if (this.escapedText === "await") { + transformFlags |= TransformFlags.ContainsPossibleTopLevelAwait; + } + if (node.flags & NodeFlags.IdentifierHasExtendedUnicodeEscape) { + transformFlags |= TransformFlags.ContainsES2015; + } + return transformFlags; + } +} + +/** @internal */ +export class QualifiedName extends Node implements FlowContainer, ts.QualifiedName { + declare readonly ast: AstQualifiedName; + + declare _flowContainerBrand: any; + + get left(): EntityName { return this.ast.data.left?.node; } + set left(value: EntityName) { this.ast.data.left = value?.ast; } + get right(): Identifier { return this.ast.data.right?.node; } + set right(value: Identifier) { this.ast.data.right = value?.ast; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstQualifiedNameData extends AstData { + left: AstEntityName = undefined!; + right: AstIdentifier = undefined!; + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.left) | + propagateIdentifierNameFlags(this.right); + } +} + +/** @internal */ +export type EntityName = + | Identifier + | QualifiedName; + +/** @internal */ +export type AstEntityName = AstNodeOneOf; + +/** @internal */ +export type BindingName = + | Identifier + | BindingPattern; + +/** @internal */ +export type AstBindingName = AstNodeOneOf; + +/** @internal */ +export type PropertyName = + | Identifier + | StringLiteral + | NoSubstitutionTemplateLiteral + | NumericLiteral + | ComputedPropertyName + | PrivateIdentifier + | BigIntLiteral; + +/** @internal */ +export type AstPropertyName = AstNodeOneOf; + +/** @internal */ +export type MemberName = + | Identifier + | PrivateIdentifier; + +/** @internal */ +export type AstMemberName = AstNodeOneOf; + +/** @internal */ +export type DeclarationName = + | PropertyName + | JsxAttributeName + | StringLiteralLike + | ElementAccessExpression + | BindingPattern + | EntityNameExpression; + +/** @internal */ +export type AstDeclarationName = AstNodeOneOf; + +/** @internal */ +export class ComputedPropertyName extends Node implements ts.ComputedPropertyName { + declare readonly ast: AstComputedPropertyName; + + override get parent() { return super.parent as Declaration; } + override set parent(value) { super.parent = value; } + + get expression(): Expression { return this.ast.data.expression?.node; } + set expression(value: Expression) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstComputedPropertyNameData extends AstData { + expression: AstExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + TransformFlags.ContainsES2015 | + TransformFlags.ContainsComputedPropertyName; + } +} + +/** @internal */ +export class PrivateIdentifier extends Token implements ts.PrivateIdentifier { + declare readonly ast: AstPrivateIdentifier; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get escapedText(): __String { return this.ast.data.escapedText; } + set escapedText(value: __String) { this.ast.data.escapedText = value; } + + get text() { return idText(this); } +} + +/** @internal */ +export class AstPrivateIdentifierData extends AstTokenData { + escapedText: __String = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.ContainsClassFields; + } +} + +/** @internal */ +export class TypeParameterDeclaration extends Node implements JSDocContainer, Declaration, ts.TypeParameterDeclaration { + declare readonly ast: AstTypeParameterDeclaration; + + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as DeclarationWithTypeParameterChildren | InferTypeNode; } + override set parent(value) { super.parent = value; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + set modifiers(value: NodeArray | undefined) { this.ast.data.modifiers = value?.ast; } + get name(): Identifier { return this.ast.data.name?.node; } + set name(value: Identifier) { this.ast.data.name = value?.ast; } + get constraint(): TypeNode | undefined { return this.ast.data.constraint?.node; } + set constraint(value: TypeNode | undefined) { this.ast.data.constraint = value?.ast; } + get default(): TypeNode | undefined { return this.ast.data.default?.node; } + set default(value: TypeNode | undefined) { this.ast.data.default = value?.ast; } + get expression(): Expression | undefined { return this.ast.data.expression?.node; } + set expression(value: Expression | undefined) { this.ast.data.expression = value?.ast; } + get symbol(): Symbol { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value) { this.ast.data.jsDoc = value; } +} + +/** @internal */ +export class AstTypeParameterDeclarationData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined = undefined; + name: AstIdentifier = undefined!; + constraint: AstTypeNode | undefined = undefined; + default: AstTypeNode | undefined = undefined; + expression: AstExpression | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) +} + +/** @internal */ +export class ParameterDeclaration extends Node implements Declaration, JSDocContainer, ts.ParameterDeclaration { + declare readonly ast: AstParameterDeclaration; + + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as SignatureDeclaration; } + override set parent(value) { super.parent = value; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + set modifiers(value: NodeArray | undefined) { this.ast.data.modifiers = value?.ast; } + get dotDotDotToken(): DotDotDotToken | undefined { return this.ast.data.dotDotDotToken?.node; } + set dotDotDotToken(value: DotDotDotToken | undefined) { this.ast.data.dotDotDotToken = value?.ast; } + get name(): BindingName { return this.ast.data.name?.node; } + set name(value: BindingName) { this.ast.data.name = value?.ast; } + get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } + set questionToken(value: QuestionToken | undefined) { this.ast.data.questionToken = value?.ast; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + set type(value: TypeNode | undefined) { this.ast.data.type = value?.ast; } + get initializer(): Expression | undefined { return this.ast.data.initializer?.node; } + set initializer(value: Expression | undefined) { this.ast.data.initializer = value?.ast; } + get symbol(): Symbol { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value) { this.ast.data.jsDoc = value; } +} + +/** @internal */ +export class AstParameterDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + dotDotDotToken: AstDotDotDotToken | undefined = undefined; + name: AstBindingName = undefined!; + questionToken: AstQuestionToken | undefined = undefined; + type: AstTypeNode | undefined = undefined; + initializer: AstExpression | undefined = undefined; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + const name = this.name; + if (name?.kind === SyntaxKind.Identifier && name.data.escapedText === "this") { + return TransformFlags.ContainsTypeScript; + } + return propagateChildrenFlags(this.modifiers) | + propagateChildFlags(this.dotDotDotToken) | + propagateNameFlags(this.name) | + propagateChildFlags(this.questionToken) | + propagateChildFlags(this.initializer) | + (this.questionToken ?? this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + (this.dotDotDotToken ?? this.initializer ? TransformFlags.ContainsES2015 : TransformFlags.None) | + (modifiersToFlags(this.modifiers?.items) & ModifierFlags.ParameterPropertyModifier ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None); + } +} + +/** @internal */ +export class Decorator extends Node implements ts.Decorator { + declare readonly ast: AstDecorator; + + override get parent() { return super.parent as Declaration; } + override set parent(value) { super.parent = value; } + + get expression(): LeftHandSideExpression { return this.ast.data.expression?.node; } + set expression(value: LeftHandSideExpression) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstDecoratorData extends AstData { + expression: AstLeftHandSideExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + TransformFlags.ContainsTypeScript | + TransformFlags.ContainsTypeScriptClassSyntax | + TransformFlags.ContainsDecorators; + } +} + +/** @internal */ +export class PropertySignature extends Node implements Declaration, JSDocContainer, ts.PropertySignature { + declare readonly ast: AstPropertySignature; + + declare _typeElementBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as TypeLiteralNode | InterfaceDeclaration; } + override set parent(value) { super.parent = value; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + set modifiers(value: NodeArray | undefined) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get questionToken() { return this.ast.data.questionToken?.node; } + set questionToken(value) { this.ast.data.questionToken = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get initializer() { return this.ast.data.initializer?.node; } + set initializer(value) { this.ast.data.initializer = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } +} + +/** @internal */ +export class AstPropertySignatureData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined = undefined; + name: AstPropertyName = undefined!; + questionToken: AstQuestionToken | undefined = undefined; + type: AstTypeNode | undefined = undefined; + initializer: AstExpression | undefined = undefined; // initialized by parser (grammar error) + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) +} + +/** @internal */ +export type SignatureDeclaration = + | CallSignatureDeclaration + | ConstructSignatureDeclaration + | MethodSignature + | IndexSignatureDeclaration + | FunctionTypeNode + | ConstructorTypeNode + | JSDocFunctionType + | FunctionDeclaration + | MethodDeclaration + | ConstructorDeclaration + | AccessorDeclaration + | FunctionExpression + | ArrowFunction; + +/** @internal */ +export type AstSignatureDeclaration = AstNodeOneOf; + +/** @internal */ +export class CallSignatureDeclaration extends Node implements LocalsContainer, Declaration, JSDocContainer, TypeElement, ts.CallSignatureDeclaration { + declare readonly ast: AstCallSignatureDeclaration; + + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _typeElementBrand: any; + declare _localsContainerBrand: any; + + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstCallSignatureDeclarationData extends AstTypeScriptNodeData { + typeParameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode | undefined = undefined; + typeArguments: AstNodeArray | undefined = undefined; // quick info + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) +} + +/** @internal */ +export class ConstructSignatureDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.ConstructSignatureDeclaration { + declare readonly ast: AstConstructSignatureDeclaration; + + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _typeElementBrand: any; + declare _localsContainerBrand: any; + + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstConstructSignatureDeclarationData extends AstTypeScriptNodeData { + typeParameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode | undefined = undefined; + typeArguments: AstNodeArray | undefined = undefined; // quick info + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class VariableDeclaration extends Node implements JSDocContainer, Declaration, ts.VariableDeclaration { + declare readonly ast: AstVariableDeclaration; + + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as VariableDeclarationList | CatchClause; } + override set parent(value) { super.parent = value; } + + get name(): BindingName { return this.ast.data.name?.node; } + set name(value: BindingName) { this.ast.data.name = value?.ast; } + get exclamationToken(): ExclamationToken | undefined { return this.ast.data.exclamationToken?.node; } + set exclamationToken(value: ExclamationToken | undefined) { this.ast.data.exclamationToken = value?.ast; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + set type(value: TypeNode | undefined) { this.ast.data.type = value?.ast; } + get initializer(): Expression | undefined { return this.ast.data.initializer?.node; } + set initializer(value: Expression | undefined) { this.ast.data.initializer = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstVariableDeclarationData extends AstData { + name: AstBindingName = undefined!; + exclamationToken: AstExclamationToken | undefined = undefined; + type: AstTypeNode | undefined = undefined; + initializer: AstExpression | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateNameFlags(this.name) | + propagateChildFlags(this.initializer) | + (this.exclamationToken ?? this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); + } +} + +/** @internal */ +export class VariableDeclarationList extends Node implements ts.VariableDeclarationList { + declare readonly ast: AstVariableDeclarationList; + + override get parent() { return super.parent as VariableStatement | ForStatement | ForOfStatement | ForInStatement; } + override set parent(value) { super.parent = value; } + + get declarations() { return this.ast.data.declarations.nodes; } + set declarations(value) { this.ast.data.declarations = value?.ast; } +} + +/** @internal */ +export class AstVariableDeclarationListData extends AstData { + declarations: AstNodeArray = undefined!; + + override computeTransformFlags(node: AstNode): TransformFlags { + let transformFlags = propagateChildrenFlags(this.declarations) | + TransformFlags.ContainsHoistedDeclarationOrCompletion; + if (node.flags & NodeFlags.BlockScoped) { + transformFlags |= TransformFlags.ContainsES2015 | + TransformFlags.ContainsBlockScopedBinding; + } + if (node.flags & NodeFlags.Using) { + transformFlags |= TransformFlags.ContainsESNext; + } + return transformFlags; + } +} + +/** @internal */ +export class BindingElement extends Node implements Declaration, FlowContainer, ts.BindingElement { + declare readonly ast: AstBindingElement; + + declare _declarationBrand: any; + declare _flowContainerBrand: any; + + override get parent() { return super.parent as BindingPattern; } + override set parent(value) { super.parent = value; } + + get propertyName() { return this.ast.data.propertyName?.node; } + set propertyName(value) { this.ast.data.propertyName = value?.ast; } + get dotDotDotToken() { return this.ast.data.dotDotDotToken?.node; } + set dotDotDotToken(value) { this.ast.data.dotDotDotToken = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get initializer() { return this.ast.data.initializer?.node; } + set initializer(value) { this.ast.data.initializer = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstBindingElementData extends AstData { + propertyName: AstPropertyName | undefined = undefined; + dotDotDotToken: AstDotDotDotToken | undefined = undefined; + name: AstBindingName = undefined!; + initializer: AstExpression | undefined = undefined; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.dotDotDotToken) | + propagateNameFlags(this.propertyName) | + propagateNameFlags(this.name) | + propagateChildFlags(this.initializer) | + (this.dotDotDotToken ? TransformFlags.ContainsRestOrSpread : TransformFlags.None) | + TransformFlags.ContainsES2015; + } +} + +/** @internal */ +export class PropertyDeclaration extends Node implements JSDocContainer, Declaration, ts.PropertyDeclaration { + declare readonly ast: AstPropertyDeclaration; + + declare _classElementBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as ClassLikeDeclaration; } + override set parent(value) { super.parent = value; } + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get questionToken() { return this.ast.data.questionToken?.node; } + set questionToken(value) { this.ast.data.questionToken = value?.ast; } + get exclamationToken() { return this.ast.data.exclamationToken?.node; } + set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get initializer() { return this.ast.data.initializer?.node; } + set initializer(value) { this.ast.data.initializer = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstPropertyDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + name: AstPropertyName = undefined!; + questionToken: AstQuestionToken | undefined = undefined; + exclamationToken: AstExclamationToken | undefined = undefined; + type: AstTypeNode | undefined = undefined; + initializer: AstExpression | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(node: AstNode): TransformFlags { + const modifierFlags = modifiersToFlags(this.modifiers?.items); + const isAmbient = node.flags & NodeFlags.Ambient || modifierFlags & ModifierFlags.Ambient; + + return propagateChildrenFlags(this.modifiers) | + propagateNameFlags(this.name) | + propagateChildFlags(this.initializer) | + (isAmbient || this.questionToken || this.exclamationToken || this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + (this.name.kind === SyntaxKind.ComputedPropertyName || modifierFlags & ModifierFlags.Static && this.initializer ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None) | + TransformFlags.ContainsClassFields; + } +} + +/** @internal */ +export class PropertyAssignment extends Node implements ObjectLiteralElement, JSDocContainer, Declaration, ts.PropertyAssignment { + declare readonly ast: AstPropertyAssignment; + + declare _objectLiteralBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as ObjectLiteralExpression; } + override set parent(value) { super.parent = value; } + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get initializer() { return this.ast.data.initializer?.node; } + set initializer(value) { this.ast.data.initializer = value?.ast; } + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get questionToken() { return this.ast.data.questionToken?.node; } + set questionToken(value) { this.ast.data.questionToken = value?.ast; } + get exclamationToken() { return this.ast.data.exclamationToken?.node; } + set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstPropertyAssignmentData extends AstData { + modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) + name: AstPropertyName = undefined!; + questionToken: AstQuestionToken | undefined = undefined; // initialized by parser (grammar error) + exclamationToken: AstExclamationToken | undefined = undefined; // initialized by parser (grammar error) + initializer: AstExpression = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateNameFlags(this.name) | + propagateChildFlags(this.initializer); + } +} + +/** @internal */ +export class ShorthandPropertyAssignment extends Node implements ObjectLiteralElement, JSDocContainer, Declaration, ts.ShorthandPropertyAssignment { + declare readonly ast: AstShorthandPropertyAssignment; + + declare _objectLiteralBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as ObjectLiteralExpression; } + override set parent(value) { super.parent = value; } + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get equalsToken() { return this.ast.data.equalsToken?.node; } + set equalsToken(value) { this.ast.data.equalsToken = value?.ast; } + get objectAssignmentInitializer() { return this.ast.data.objectAssignmentInitializer?.node; } + set objectAssignmentInitializer(value) { this.ast.data.objectAssignmentInitializer = value?.ast; } + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get questionToken() { return this.ast.data.questionToken?.node; } + set questionToken(value) { this.ast.data.questionToken = value?.ast; } + get exclamationToken() { return this.ast.data.exclamationToken?.node; } + set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstShorthandPropertyAssignmentData extends AstData { + modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) + name: AstIdentifier = undefined!; + questionToken: AstQuestionToken | undefined = undefined; // initialized by parser (grammar error) + exclamationToken: AstExclamationToken | undefined = undefined; // initialized by parser (grammar error) + equalsToken: AstEqualsToken | undefined = undefined; // initialized by parser (grammar error) + objectAssignmentInitializer: AstExpression | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateIdentifierNameFlags(this.name) | + propagateChildFlags(this.objectAssignmentInitializer) | + TransformFlags.ContainsES2015; + } +} + +/** @internal */ +export class SpreadAssignment extends Node implements ObjectLiteralElement, JSDocContainer, Declaration, ts.SpreadAssignment { + declare readonly ast: AstSpreadAssignment; + + declare _objectLiteralBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as ObjectLiteralExpression; } + override set parent(value) { super.parent = value; } + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstSpreadAssignmentData extends AstData { + expression: AstExpression = undefined!; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + TransformFlags.ContainsES2018 | + TransformFlags.ContainsObjectRestOrSpread; + } +} + +/** @internal */ +export type BindingPattern = + | ObjectBindingPattern + | ArrayBindingPattern + ; + +/** @internal */ +export type AstBindingPattern = AstNodeOneOf; + +/** @internal */ +export type ArrayBindingElement = + | BindingElement + | OmittedExpression + ; + +/** @internal */ +export type AstArrayBindingElement = AstNodeOneOf; + +/** @internal */ +export class ObjectBindingPattern extends Node implements ts.ObjectBindingPattern { + declare readonly ast: AstObjectBindingPattern; + + override get parent() { return super.parent as VariableDeclaration | ParameterDeclaration | BindingElement; } + override set parent(value) { super.parent = value; } + + get elements() { return this.ast.data.elements?.nodes!; } // TODO: remove `!` + set elements(value) { this.ast.data.elements = value?.ast; } +} + +/** @internal */ +export class AstObjectBindingPatternData extends AstData { + elements: AstNodeArray | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildrenFlags(this.elements) | + TransformFlags.ContainsES2015 | + TransformFlags.ContainsBindingPattern; + if (transformFlags & TransformFlags.ContainsRestOrSpread) { + transformFlags |= TransformFlags.ContainsES2018 | TransformFlags.ContainsObjectRestOrSpread; + } + return transformFlags; + } +} + +/** @internal */ +export class ArrayBindingPattern extends Node implements ts.ArrayBindingPattern { + declare readonly ast: AstArrayBindingPattern; + + override get parent() { return super.parent as VariableDeclaration | ParameterDeclaration | BindingElement; } + override set parent(value) { super.parent = value; } + + get elements() { return this.ast.data.elements?.nodes!; } // TODO: remove `!` + set elements(value) { this.ast.data.elements = value?.ast; } +} + +/** @internal */ +export class AstArrayBindingPatternData extends AstData { + elements: AstNodeArray | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildrenFlags(this.elements) | + TransformFlags.ContainsES2015 | + TransformFlags.ContainsBindingPattern; + } +} + +/** @internal */ +export class FunctionDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.FunctionDeclaration { + declare readonly ast: AstFunctionDeclaration; + + declare _functionLikeDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _statementBrand: any; + declare _localsContainerBrand: any; + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get asteriskToken() { return this.ast.data.asteriskToken?.node; } + set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get body() { return this.ast.data.body?.node; } + set body(value) { this.ast.data.body = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get endFlowNode() { return this.ast.data.endFlowNode; } + set endFlowNode(value) { this.ast.data.endFlowNode = value; } + get returnFlowNode() { return this.ast.data.returnFlowNode; } + set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } + + get typeArguments() { return this.ast.data.typeArguments?.nodes; } // Used for quick info, replaces typeParameters for instantiated signatures + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } +} + +/** @internal */ +export class AstFunctionDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + asteriskToken: AstAsteriskToken | undefined = undefined; + name: AstIdentifier | undefined = undefined; + typeParameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode | undefined = undefined; + body: AstFunctionBody | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // Used for quick info, replaces typeParameters for instantiated signatures + + override computeTransformFlags(_: AstNode): TransformFlags { + if (!this.body || modifiersToFlags(this.modifiers?.items) & ModifierFlags.Ambient) { + return TransformFlags.ContainsTypeScript; + } + else { + const isAsync = modifiersToFlags(this.modifiers?.items) & ModifierFlags.Async; + const isGenerator = !!this.asteriskToken; + const isAsyncGenerator = isAsync && isGenerator; + + return propagateChildrenFlags(this.modifiers) | + propagateChildFlags(this.asteriskToken) | + propagateNameFlags(this.name) | + propagateChildrenFlags(this.typeParameters) | + propagateChildrenFlags(this.parameters) | + propagateChildFlags(this.type) | + (propagateChildFlags(this.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | + (isAsyncGenerator ? TransformFlags.ContainsES2018 : + isAsync ? TransformFlags.ContainsES2017 : + isGenerator ? TransformFlags.ContainsGenerator : + TransformFlags.None) | + (this.typeParameters || this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + TransformFlags.ContainsHoistedDeclarationOrCompletion; + } + } +} + +/** @internal */ +export class MethodSignature extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.MethodSignature { + declare readonly ast: AstMethodSignature; + + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _typeElementBrand: any; + declare _localsContainerBrand: any; + + override get parent() { return super.parent as TypeLiteralNode | InterfaceDeclaration; } + override set parent(value) { super.parent = value; } + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get questionToken() { return this.ast.data.questionToken?.node; } + set questionToken(value) { this.ast.data.questionToken = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstMethodSignatureData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined = undefined; + name: AstPropertyName = undefined!; + questionToken: AstQuestionToken | undefined = undefined; + typeParameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode | undefined = undefined; + typeArguments: AstNodeArray | undefined = undefined; // quick info + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class MethodDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, FlowContainer, ts.MethodDeclaration { + declare readonly ast: AstMethodDeclaration; + + declare _functionLikeDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _classElementBrand: any; + declare _objectLiteralBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + + override get parent() { return super.parent as ClassLikeDeclaration | ObjectLiteralExpression; } + override set parent(value) { super.parent = value; } + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get asteriskToken() { return this.ast.data.asteriskToken?.node; } + set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get questionToken() { return this.ast.data.questionToken?.node; } + set questionToken(value) { this.ast.data.questionToken = value?.ast; } + get exclamationToken() { return this.ast.data.exclamationToken?.node; } + set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get body() { return this.ast.data.body?.node; } + set body(value) { this.ast.data.body = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } + get endFlowNode() { return this.ast.data.endFlowNode; } + set endFlowNode(value) { this.ast.data.endFlowNode = value; } + get returnFlowNode() { return this.ast.data.returnFlowNode; } + set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } +} + +/** @internal */ +export class AstMethodDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + asteriskToken: AstAsteriskToken | undefined = undefined; + name: AstPropertyName = undefined!; + questionToken: AstQuestionToken | undefined = undefined; + exclamationToken: AstExclamationToken | undefined = undefined; // initialized by parser (grammar error) + typeParameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode | undefined = undefined; + body: AstFunctionBody | undefined = undefined; + typeArguments: AstNodeArray | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + if (!this.body) { + return TransformFlags.ContainsTypeScript; + } + else { + const isAsync = modifiersToFlags(this.modifiers?.items) & ModifierFlags.Async; + const isGenerator = !!this.asteriskToken; + const isAsyncGenerator = isAsync && isGenerator; + + return propagateChildrenFlags(this.modifiers) | + propagateChildFlags(this.asteriskToken) | + propagateNameFlags(this.name) | + propagateChildFlags(this.questionToken) | + propagateChildrenFlags(this.typeParameters) | + propagateChildrenFlags(this.parameters) | + propagateChildFlags(this.type) | + (propagateChildFlags(this.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | + (isAsyncGenerator ? TransformFlags.ContainsES2018 : + isAsync ? TransformFlags.ContainsES2017 : + isGenerator ? TransformFlags.ContainsGenerator : + TransformFlags.None) | + (this.questionToken || this.typeParameters || this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + TransformFlags.ContainsES2015; + } + } +} + +/** @internal */ +export class ConstructorDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.ConstructorDeclaration { + declare readonly ast: AstConstructorDeclaration; + + declare _functionLikeDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _classElementBrand: any; + declare _localsContainerBrand: any; + + override get parent() { return super.parent as ClassLikeDeclaration; } + override set parent(value) { super.parent = value; } + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get body() { return this.ast.data.body?.node; } + set body(value) { this.ast.data.body = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get endFlowNode() { return this.ast.data.endFlowNode; } + set endFlowNode(value) { this.ast.data.endFlowNode = value; } + get returnFlowNode() { return this.ast.data.returnFlowNode; } + set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } +} + +/** @internal */ +export class AstConstructorDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + body: AstFunctionBody | undefined = undefined; + typeParameters: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode | undefined = undefined; // initialized by parser (grammar error) + typeArguments: AstNodeArray | undefined = undefined; // quick info + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + if (!this.body) { + return TransformFlags.ContainsTypeScript; + } + else { + return propagateChildrenFlags(this.modifiers) | + propagateChildrenFlags(this.parameters) | + (propagateChildFlags(this.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | + TransformFlags.ContainsES2015; + } + } +} + +/** @internal */ +export class SemicolonClassElement extends Node implements JSDocContainer, ts.SemicolonClassElement { + declare readonly ast: AstSemicolonClassElement; + + declare _classElementBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare symbol: never; + declare localSymbol: never; + + override get parent() { return super.parent as ClassLikeDeclaration; } + override set parent(value) { super.parent = value; } + + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } +} + +/** @internal */ +export class AstSemicolonClassElementData extends AstData { + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.None; + } +} + +/** @internal */ +export class GetAccessorDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, FlowContainer, ts.GetAccessorDeclaration { + declare readonly ast: AstGetAccessorDeclaration; + + declare _functionLikeDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _classElementBrand: any; + declare _typeElementBrand: any; + declare _objectLiteralBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + + override get parent() { return super.parent as ClassLikeDeclaration | ObjectLiteralExpression; } + override set parent(value) { super.parent = value; } + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get body() { return this.ast.data.body?.node; } + set body(value) { this.ast.data.body = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } + get endFlowNode() { return this.ast.data.endFlowNode; } + set endFlowNode(value) { this.ast.data.endFlowNode = value; } + get returnFlowNode() { return this.ast.data.returnFlowNode; } + set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } +} + +/** @internal */ +export class AstGetAccessorDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + name: AstPropertyName = undefined!; + body: AstFunctionBody | undefined = undefined; + typeParameters: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode | undefined = undefined; + typeArguments: AstNodeArray | undefined = undefined; // quick info + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + if (!this.body) { + return TransformFlags.ContainsTypeScript; + } + else { + return propagateChildrenFlags(this.modifiers) | + propagateNameFlags(this.name) | + propagateChildrenFlags(this.parameters) | + propagateChildFlags(this.type) | + (propagateChildFlags(this.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | + (this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); + } + + } +} + +/** @internal */ +export class SetAccessorDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, FlowContainer, ts.SetAccessorDeclaration { + declare readonly ast: AstSetAccessorDeclaration; + + declare _functionLikeDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _classElementBrand: any; + declare _typeElementBrand: any; + declare _objectLiteralBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + + override get parent() { return super.parent as ClassLikeDeclaration | ObjectLiteralExpression; } + override set parent(value) { super.parent = value; } + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get body() { return this.ast.data.body?.node; } + set body(value) { this.ast.data.body = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } + get endFlowNode() { return this.ast.data.endFlowNode; } + set endFlowNode(value) { this.ast.data.endFlowNode = value; } + get returnFlowNode() { return this.ast.data.returnFlowNode; } + set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } +} + +/** @internal */ +export class AstSetAccessorDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + name: AstPropertyName = undefined!; + body: AstFunctionBody | undefined = undefined; + typeParameters: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode | undefined = undefined; // initialized by parser (grammar error) + typeArguments: AstNodeArray | undefined = undefined; // quick info + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + if (!this.body) { + return TransformFlags.ContainsTypeScript; + } + else { + return propagateChildrenFlags(this.modifiers) | + propagateNameFlags(this.name) | + propagateChildrenFlags(this.parameters) | + (propagateChildFlags(this.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | + (this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); + } + } +} + +/** @internal */ +export type AccessorDeclaration = + | GetAccessorDeclaration + | SetAccessorDeclaration + ; + +/** @internal */ +export type AstAccessorDeclaration = AstNodeOneOf; + +/** @internal */ +export class IndexSignatureDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.IndexSignatureDeclaration { + declare readonly ast: AstIndexSignatureDeclaration; + + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _classElementBrand: any; + declare _typeElementBrand: any; + declare _localsContainerBrand: any; + + override get parent() { return super.parent as ObjectTypeDeclaration; } + override set parent(value) { super.parent = value; } + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node!; } + set type(value) { this.ast.data.type = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstIndexSignatureDeclarationData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined = undefined; + typeParameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode | undefined = undefined; + typeArguments: AstNodeArray | undefined = undefined; // quick info + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class ClassStaticBlockDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.ClassStaticBlockDeclaration { + declare readonly ast: AstClassStaticBlockDeclaration; + + declare _classElementBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + + override get parent() { return super.parent as ClassLikeDeclaration; } + override set parent(value) { super.parent = value; } + + get body() { return this.ast.data.body?.node; } + set body(value) { this.ast.data.body = value?.ast; } + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get endFlowNode() { return this.ast.data.endFlowNode; } + set endFlowNode(value) { this.ast.data.endFlowNode = value; } + get returnFlowNode() { return this.ast.data.returnFlowNode; } + set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } +} + +/** @internal */ +export class AstClassStaticBlockDeclarationData extends AstData { + body: AstBlock = undefined!; + modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.body) | TransformFlags.ContainsClassFields; + } +} + +/** + * @deprecated + * @internal + */ +export class ImportTypeAssertionContainer extends Node implements ts.ImportTypeAssertionContainer { + declare readonly ast: AstImportTypeAssertionContainer; + + override get parent() { return super.parent as ImportTypeNode; } + override set parent(value) { super.parent = value; } + + /** @deprecated */ + get assertClause() { return this.ast.data.assertClause?.node; } + set assertClause(value) { this.ast.data.assertClause = value?.ast; } + get multiLine() { return this.ast.data.multiLine; } + set multiLine(value) { this.ast.data.multiLine = value; } +} + +/** + * @deprecated + * @internal + */ +export type AstImportTypeAssertionContainer = AstNode; + +/** + * @deprecated + * @internal + */ +export class AstImportTypeAssertionContainerData extends AstTypeScriptNodeData { + assertClause: AstImportAttributes = undefined!; + multiLine: boolean = false; +} + +/** @internal */ +export class ImportTypeNode extends Node implements ts.ImportTypeNode { + declare readonly ast: AstImportTypeNode; + + declare _typeNodeBrand: any; + + get isTypeOf() { return this.ast.data.isTypeOf; } + set isTypeOf(value) { this.ast.data.isTypeOf = value; } + get argument() { return this.ast.data.argument?.node; } + set argument(value) { this.ast.data.argument = value?.ast; } + /** @deprecated */ + get attributes() { return this.ast.data.attributes?.node; } + set attributes(value) { this.ast.data.attributes = value?.ast; } + get assertions() { return this.ast.data.assertions?.node; } + set assertions(value) { this.ast.data.assertions = value?.ast; } + get qualifier() { return this.ast.data.qualifier?.node; } + set qualifier(value) { this.ast.data.qualifier = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } +} + +/** @internal */ +export class AstImportTypeNodeData extends AstTypeScriptNodeData { + isTypeOf: boolean = false; + argument: AstTypeNode = undefined!; + assertions: AstImportTypeAssertionContainer | undefined = undefined; + attributes: AstImportAttributes | undefined = undefined; + qualifier: AstEntityName | undefined = undefined; + typeArguments: AstNodeArray | undefined = undefined; +} + +/** @internal */ +export interface KeywordTypeNode extends KeywordToken, TypeNode { + readonly ast: AstKeywordTypeNode; + readonly kind: TKind; + _typeNodeBrand: any; +} + +/** @internal */ +export type AstKeywordTypeNode = AstNode>; + +/** @internal */ +export class ThisTypeNode extends Node implements ts.ThisTypeNode { + declare readonly ast: AstThisTypeNode; + + declare _typeNodeBrand: any; +} + +/** @internal */ +export class AstThisTypeNodeData extends AstTypeScriptNodeData { +} + +/** @internal */ +export class FunctionTypeNode extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.FunctionTypeNode { + declare readonly ast: AstFunctionTypeNode; + + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstFunctionTypeNodeData extends AstTypeScriptNodeData { + typeParameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode = undefined!; + typeArguments: AstNodeArray | undefined = undefined; // quick info + modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class ConstructorTypeNode extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.ConstructorTypeNode { + declare readonly ast: AstConstructorTypeNode; + + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstConstructorTypeNodeData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined = undefined; + typeParameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode = undefined!; + typeArguments: AstNodeArray | undefined = undefined; // quick info + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class TypeReferenceNode extends Node implements ts.TypeReferenceNode { + declare readonly ast: AstTypeReferenceNode; + + declare _typeNodeBrand: any; + + get typeName() { return this.ast.data.typeName?.node; } + set typeName(value) { this.ast.data.typeName = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } +} + +/** @internal */ +export class AstTypeReferenceNodeData extends AstTypeScriptNodeData { + typeName: AstEntityName = undefined!; + typeArguments: AstNodeArray | undefined = undefined; +} + +/** @internal */ +export class TypePredicateNode extends Node implements ts.TypePredicateNode { + declare readonly ast: AstTypePredicateNode; + + declare _typeNodeBrand: any; + + override get parent() { return super.parent as SignatureDeclaration | JSDocTypeExpression; } + override set parent(value) { super.parent = value; } + + get assertsModifier() { return this.ast.data.assertsModifier?.node; } + set assertsModifier(value) { this.ast.data.assertsModifier = value?.ast; } + get parameterName() { return this.ast.data.parameterName?.node; } + set parameterName(value) { this.ast.data.parameterName = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } +} + +/** @internal */ +export class AstTypePredicateNodeData extends AstTypeScriptNodeData { + assertsModifier: AstAssertsKeyword | undefined = undefined; + parameterName: AstIdentifier | AstThisTypeNode = undefined!; + type: AstTypeNode | undefined = undefined; +} + +/** @internal */ +export class TypeQueryNode extends Node implements ts.TypeQueryNode { + declare readonly ast: AstTypeQueryNode; + + declare _typeNodeBrand: any; + + get exprName() { return this.ast.data.exprName?.node; } + set exprName(value) { this.ast.data.exprName = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } +} + +/** @internal */ +export class AstTypeQueryNodeData extends AstTypeScriptNodeData { + exprName: AstEntityName = undefined!; + typeArguments: AstNodeArray | undefined = undefined; +} + +/** @internal */ +export class TypeLiteralNode extends Node implements Declaration, ts.TypeLiteralNode { + declare readonly ast: AstTypeLiteralNode; + + declare _typeNodeBrand: any; + declare _declarationBrand: any; + + get members() { return this.ast.data.members?.nodes!; } // TODO: remove '!' + set members(value) { this.ast.data.members = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstTypeLiteralNodeData extends AstTypeScriptNodeData { + members: AstNodeArray | undefined = undefined; + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) +} + +/** @internal */ +export class ArrayTypeNode extends Node implements ts.ArrayTypeNode { + declare readonly ast: AstArrayTypeNode; + + declare _typeNodeBrand: any; + + get elementType() { return this.ast.data.elementType?.node; } + set elementType(value) { this.ast.data.elementType = value?.ast; } +} + +/** @internal */ +export class AstArrayTypeNodeData extends AstTypeScriptNodeData { + elementType: AstTypeNode = undefined!; +} + +/** @internal */ +export class TupleTypeNode extends Node implements ts.TupleTypeNode { + declare readonly ast: AstTupleTypeNode; + + declare _typeNodeBrand: any; + + get elements(): NodeArray { return this.ast.data.elements?.nodes!; } // TODO: remove '!' + set elements(value: NodeArray) { this.ast.data.elements = value?.ast; } +} + +/** @internal */ +export class AstTupleTypeNodeData extends AstTypeScriptNodeData { + elements: AstNodeArray | undefined = undefined; +} + +/** @internal */ +export class NamedTupleMember extends Node implements JSDocContainer, Declaration, ts.NamedTupleMember { + declare readonly ast: AstNamedTupleMember; + + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + get dotDotDotToken() { return this.ast.data.dotDotDotToken?.node; } + set dotDotDotToken(value) { this.ast.data.dotDotDotToken = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get questionToken() { return this.ast.data.questionToken?.node; } + set questionToken(value) { this.ast.data.questionToken = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstNamedTupleMemberData extends AstTypeScriptNodeData { + dotDotDotToken: AstDotDotDotToken | undefined = undefined; + name: AstIdentifier = undefined!; + questionToken: AstQuestionToken | undefined = undefined; + type: AstTypeNode = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) +} + +/** @internal */ +export class OptionalTypeNode extends Node implements ts.OptionalTypeNode { + declare readonly ast: AstOptionalTypeNode; + + declare _typeNodeBrand: any; + + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } +} + +/** @internal */ +export class AstOptionalTypeNodeData extends AstTypeScriptNodeData { + type: AstTypeNode = undefined!; +} + +/** @internal */ +export class RestTypeNode extends Node implements ts.RestTypeNode { + declare readonly ast: AstRestTypeNode; + + declare _typeNodeBrand: any; + + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } +} + +/** @internal */ +export class AstRestTypeNodeData extends AstTypeScriptNodeData { + type: AstTypeNode = undefined!; +} + +/** @internal */ +export class UnionTypeNode extends Node implements ts.UnionTypeNode { + declare readonly ast: AstUnionTypeNode; + + declare _typeNodeBrand: any; + + get types() { return this.ast.data.types?.nodes!; } // TODO: remove '!' + set types(value) { this.ast.data.types = value?.ast; } +} + +/** @internal */ +export class AstUnionTypeNodeData extends AstTypeScriptNodeData { + types: AstNodeArray | undefined = undefined; +} + +/** @internal */ +export class IntersectionTypeNode extends Node implements ts.IntersectionTypeNode { + declare readonly ast: AstIntersectionTypeNode; + + declare _typeNodeBrand: any; + + get types() { return this.ast.data.types?.nodes!; } // TODO: remove '!' + set types(value) { this.ast.data.types = value?.ast; } +} + +/** @internal */ +export class AstIntersectionTypeNodeData extends AstTypeScriptNodeData { + types: AstNodeArray | undefined = undefined; +} + +/** @internal */ +export class ConditionalTypeNode extends Node implements LocalsContainer, ts.ConditionalTypeNode { + declare readonly ast: AstConditionalTypeNode; + + declare _typeNodeBrand: any; + declare _localsContainerBrand: any; + + get checkType() { return this.ast.data.checkType?.node; } + set checkType(value) { this.ast.data.checkType = value?.ast; } + get extendsType() { return this.ast.data.extendsType?.node; } + set extendsType(value) { this.ast.data.extendsType = value?.ast; } + get trueType() { return this.ast.data.trueType?.node; } + set trueType(value) { this.ast.data.trueType = value?.ast; } + get falseType() { return this.ast.data.falseType?.node; } + set falseType(value) { this.ast.data.falseType = value?.ast; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstConditionalTypeNodeData extends AstTypeScriptNodeData { + checkType: AstTypeNode = undefined!; + extendsType: AstTypeNode = undefined!; + trueType: AstTypeNode = undefined!; + falseType: AstTypeNode = undefined!; + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class InferTypeNode extends Node implements ts.InferTypeNode { + declare readonly ast: AstInferTypeNode; + + declare _typeNodeBrand: any; + + get typeParameter() { return this.ast.data.typeParameter?.node; } + set typeParameter(value) { this.ast.data.typeParameter = value?.ast; } +} + +/** @internal */ +export class AstInferTypeNodeData extends AstTypeScriptNodeData { + typeParameter: AstTypeParameterDeclaration = undefined!; +} + +/** @internal */ +export class ParenthesizedTypeNode extends Node implements ts.ParenthesizedTypeNode { + declare readonly ast: AstParenthesizedTypeNode; + + declare _typeNodeBrand: any; + + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } +} + +/** @internal */ +export class AstParenthesizedTypeNodeData extends AstTypeScriptNodeData { + type: AstTypeNode = undefined!; +} + +/** @internal */ +export class TypeOperatorNode extends Node implements ts.TypeOperatorNode { + declare readonly ast: AstTypeOperatorNode; + + declare _typeNodeBrand: any; + + get operator() { return this.ast.data.operator; } + set operator(value) { this.ast.data.operator = value; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } +} + +/** @internal */ +export class AstTypeOperatorNodeData extends AstTypeScriptNodeData { + operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword = undefined!; + type: AstTypeNode = undefined!; +} + +/** @internal */ +export class IndexedAccessTypeNode extends Node implements ts.IndexedAccessTypeNode { + declare readonly ast: AstIndexedAccessTypeNode; + + declare _typeNodeBrand: any; + + get objectType() { return this.ast.data.objectType?.node; } + set objectType(value) { this.ast.data.objectType = value?.ast; } + get indexType() { return this.ast.data.indexType?.node; } + set indexType(value) { this.ast.data.indexType = value?.ast; } +} + +/** @internal */ +export class AstIndexedAccessTypeNodeData extends AstTypeScriptNodeData { + objectType: AstTypeNode = undefined!; + indexType: AstTypeNode = undefined!; +} + +/** @internal */ +export class MappedTypeNode extends Node implements Declaration, LocalsContainer, ts.MappedTypeNode { + declare readonly ast: AstMappedTypeNode; + + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare _localsContainerBrand: any; + + get readonlyToken() { return this.ast.data.readonlyToken?.node; } + set readonlyToken(value) { this.ast.data.readonlyToken = value?.ast; } + get typeParameter() { return this.ast.data.typeParameter?.node; } + set typeParameter(value) { this.ast.data.typeParameter = value?.ast; } + get nameType() { return this.ast.data.nameType?.node; } + set nameType(value) { this.ast.data.nameType = value?.ast; } + get questionToken() { return this.ast.data.questionToken?.node; } + set questionToken(value) { this.ast.data.questionToken = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get members() { return this.ast.data.members?.nodes; } + set members(value) { this.ast.data.members = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstMappedTypeNodeData extends AstTypeScriptNodeData { + readonlyToken: AstReadonlyKeyword | AstPlusToken | AstMinusToken | undefined = undefined; + typeParameter: AstTypeParameterDeclaration = undefined!; + nameType: AstTypeNode | undefined = undefined; + questionToken: AstQuestionToken | AstPlusToken | AstMinusToken | undefined = undefined; + type: AstTypeNode | undefined = undefined; + members: AstNodeArray | undefined = undefined; + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class LiteralTypeNode extends Node implements ts.LiteralTypeNode { + declare readonly ast: AstLiteralTypeNode; + + declare _typeNodeBrand: any; + + get literal() { return this.ast.data.literal?.node; } + set literal(value) { this.ast.data.literal = value?.ast; } +} + +/** @internal */ +export class AstLiteralTypeNodeData extends AstTypeScriptNodeData { + literal: AstNullLiteral | AstBooleanLiteral | AstLiteralExpression | AstPrefixUnaryExpression = undefined!; +} + +/** @internal */ +export type PropertyNameLiteral = + | Identifier + | StringLiteralLike + | NumericLiteral + | JsxNamespacedName + | BigIntLiteral; + +/** @internal */ +export type AstPropertyNameLiteral = AstNodeOneOf; + +/** @internal */ +export class TemplateLiteralTypeNode extends Node implements ts.TemplateLiteralTypeNode { + declare readonly ast: AstTemplateLiteralTypeNode; + + declare _typeNodeBrand: any; + + get head() { return this.ast.data.head?.node; } + set head(value) { this.ast.data.head = value?.ast; } + get templateSpans() { return this.ast.data.templateSpans?.nodes!; } // TODO: remove '!' + set templateSpans(value) { this.ast.data.templateSpans = value?.ast; } +} + +/** @internal */ +export class AstTemplateLiteralTypeNodeData extends AstTypeScriptNodeData { + head: AstTemplateHead = undefined!; + templateSpans: AstNodeArray | undefined = undefined; +} + +/** @internal */ +export class TemplateLiteralTypeSpan extends Node implements ts.TemplateLiteralTypeSpan { + declare readonly ast: AstTemplateLiteralTypeSpan; + + declare _typeNodeBrand: any; + + override get parent() { return super.parent as TemplateLiteralTypeNode; } + override set parent(value) { super.parent = value; } + + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get literal() { return this.ast.data.literal?.node; } + set literal(value) { this.ast.data.literal = value?.ast; } +} + +/** @internal */ +export class AstTemplateLiteralTypeSpanData extends AstTypeScriptNodeData { + type: AstTypeNode = undefined!; + literal: AstTemplateMiddle | AstTemplateTail = undefined!; +} + +/** @internal */ +export type Literal = + | NumericLiteral + | BigIntLiteral + | StringLiteral + | JsxText + | RegularExpressionLiteral + | NoSubstitutionTemplateLiteral + ; + +/** @internal */ +export type AstLiteral = AstNodeOneOf; + +/** @internal */ +export class OmittedExpression extends Node implements ts.OmittedExpression { + declare readonly ast: AstOmittedExpression; + + declare _expressionBrand: any; +} + +/** @internal */ +export class AstOmittedExpressionData extends AstData { + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.None; + } +} + +/** @internal */ +export class PrefixUnaryExpression extends Node implements ts.PrefixUnaryExpression { + declare readonly ast: AstPrefixUnaryExpression; + + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get operator() { return this.ast.data.operator; } + set operator(value) { this.ast.data.operator = value; } + get operand() { return this.ast.data.operand?.node; } + set operand(value) { this.ast.data.operand = value?.ast; } +} + +/** @internal */ +export class AstPrefixUnaryExpressionData extends AstData { + operator: PrefixUnaryOperator = undefined!; + operand: AstUnaryExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.operand); + // Only set this flag for non-generated identifiers and non-"local" names. See the + // comment in `visitPreOrPostfixUnaryExpression` in module.ts + if ( + (this.operator === SyntaxKind.PlusPlusToken || this.operator === SyntaxKind.MinusMinusToken) && + this.operand.kind === SyntaxKind.Identifier && + (!this.operand.emitNode || + !this.operand.emitNode.autoGenerate && + !(this.operand.emitNode.flags & EmitFlags.LocalName)) + ) { + transformFlags |= TransformFlags.ContainsUpdateExpressionForIdentifier; + } + return transformFlags; + } +} + +/** @internal */ +export class PostfixUnaryExpression extends Node implements ts.PostfixUnaryExpression { + declare readonly ast: AstPostfixUnaryExpression; + + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get operand() { return this.ast.data.operand?.node; } + set operand(value) { this.ast.data.operand = value?.ast; } + get operator() { return this.ast.data.operator; } + set operator(value) { this.ast.data.operator = value; } +} + +/** @internal */ +export class AstPostfixUnaryExpressionData extends AstData { + operand: AstLeftHandSideExpression = undefined!; + operator: PostfixUnaryOperator = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.operand); + // Only set this flag for non-generated identifiers and non-"local" names. See the + // comment in `visitPreOrPostfixUnaryExpression` in module.ts + if ( + this.operand.kind === SyntaxKind.Identifier && + (!this.operand.emitNode || + !this.operand.emitNode.autoGenerate && + !(this.operand.emitNode.flags & EmitFlags.LocalName)) + ) { + transformFlags |= TransformFlags.ContainsUpdateExpressionForIdentifier; + } + return transformFlags; + } +} + +/** @internal */ +export class DeleteExpression extends Node implements ts.DeleteExpression { + declare readonly ast: AstDeleteExpression; + + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstDeleteExpressionData extends AstData { + expression: AstUnaryExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression); + } +} + +/** @internal */ +export class TypeOfExpression extends Node implements ts.TypeOfExpression { + declare readonly ast: AstTypeOfExpression; + + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstTypeOfExpressionData extends AstData { + expression: AstUnaryExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression); + } +} + +/** @internal */ +export class VoidExpression extends Node implements ts.VoidExpression { + declare readonly ast: AstVoidExpression; + + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstVoidExpressionData extends AstData { + expression: AstUnaryExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression); + } +} + +/** @internal */ +export class AwaitExpression extends Node implements ts.AwaitExpression { + declare readonly ast: AstAwaitExpression; + + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstAwaitExpressionData extends AstData { + expression: AstUnaryExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + TransformFlags.ContainsES2017 | + TransformFlags.ContainsES2018 | + TransformFlags.ContainsAwait; + } +} + +/** @internal */ +export class YieldExpression extends Node implements ts.YieldExpression { + declare readonly ast: AstYieldExpression; + + declare _expressionBrand: any; + + get asteriskToken() { return this.ast.data.asteriskToken?.node; } + set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstYieldExpressionData extends AstData { + asteriskToken: AstAsteriskToken | undefined = undefined; + expression: AstExpression | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + propagateChildFlags(this.asteriskToken) | + TransformFlags.ContainsES2015 | + TransformFlags.ContainsES2018 | + TransformFlags.ContainsYield; + } +} + +/** @internal */ +export type BinaryOperatorToken = Token; + +/** @internal */ +export type AstBinaryOperatorToken = AstNode; + +/** @internal */ +export class BinaryExpression extends Node implements JSDocContainer, Declaration, ts.BinaryExpression { + declare readonly ast: AstBinaryExpression; + + declare _expressionBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + get left() { return this.ast.data.left?.node; } + set left(value) { this.ast.data.left = value?.ast; } + get operatorToken() { return this.ast.data.operatorToken?.node; } + set operatorToken(value) { this.ast.data.operatorToken = value?.ast; } + get right() { return this.ast.data.right?.node; } + set right(value) { this.ast.data.right = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstBinaryExpressionData extends AstData { + left: AstExpression = undefined!; + operatorToken: AstBinaryOperatorToken = undefined!; + right: AstExpression = undefined!; + cachedLiteralKind: SyntaxKind | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + const operatorKind = this.operatorToken.kind; + let transformFlags = propagateChildFlags(this.left) | + propagateChildFlags(this.operatorToken) | + propagateChildFlags(this.right); + if (operatorKind === SyntaxKind.QuestionQuestionToken) { + transformFlags |= TransformFlags.ContainsES2020; + } + else if (operatorKind === SyntaxKind.EqualsToken) { + if (this.left.kind === SyntaxKind.ObjectLiteralExpression) { + transformFlags |= TransformFlags.ContainsES2015 | + TransformFlags.ContainsES2018 | + TransformFlags.ContainsDestructuringAssignment | + propagateAssignmentPatternFlags(this.left as AstObjectLiteralExpression); + } + else if (this.left.kind === SyntaxKind.ArrayLiteralExpression) { + transformFlags |= TransformFlags.ContainsES2015 | + TransformFlags.ContainsDestructuringAssignment | + propagateAssignmentPatternFlags(this.left as AstArrayLiteralExpression); + } + } + else if (operatorKind === SyntaxKind.AsteriskAsteriskToken || operatorKind === SyntaxKind.AsteriskAsteriskEqualsToken) { + transformFlags |= TransformFlags.ContainsES2016; + } + else if (isLogicalOrCoalescingAssignmentOperator(operatorKind)) { + transformFlags |= TransformFlags.ContainsES2021; + } + if (operatorKind === SyntaxKind.InKeyword && this.left.kind === SyntaxKind.PrivateIdentifier) { + transformFlags |= TransformFlags.ContainsPrivateIdentifierInExpression; + } + return transformFlags; + } +} + +/** @internal */ +export type AssignmentOperatorToken = Token; + +/** @internal */ +export interface AssignmentExpression extends BinaryExpression { + readonly left: LeftHandSideExpression; + readonly operatorToken: TOperator; +} + +/** @internal */ +export interface ObjectDestructuringAssignment extends AssignmentExpression { + readonly left: ObjectLiteralExpression; +} + +/** @internal */ +export interface ArrayDestructuringAssignment extends AssignmentExpression { + readonly left: ArrayLiteralExpression; +} + +/** @internal */ +export type DestructuringAssignment = + | ObjectDestructuringAssignment + | ArrayDestructuringAssignment; + +/** @internal */ +export type AstDestructuringAssignment = AstNodeOneOf; + +/** @internal */ +export class ConditionalExpression extends Node implements ts.ConditionalExpression { + declare readonly ast: AstConditionalExpression; + + declare _expressionBrand: any; + + get condition() { return this.ast.data.condition?.node; } + set condition(value) { this.ast.data.condition = value?.ast; } + get questionToken() { return this.ast.data.questionToken?.node; } + set questionToken(value) { this.ast.data.questionToken = value?.ast; } + get whenTrue() { return this.ast.data.whenTrue?.node; } + set whenTrue(value) { this.ast.data.whenTrue = value?.ast; } + get colonToken() { return this.ast.data.colonToken?.node; } + set colonToken(value) { this.ast.data.colonToken = value?.ast; } + get whenFalse() { return this.ast.data.whenFalse?.node; } + set whenFalse(value) { this.ast.data.whenFalse = value?.ast; } +} + +/** @internal */ +export class AstConditionalExpressionData extends AstData { + condition: AstExpression = undefined!; + questionToken: AstQuestionToken = undefined!; + whenTrue: AstExpression = undefined!; + colonToken: AstToken = undefined!; + whenFalse: AstExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.condition) | + propagateChildFlags(this.questionToken) | + propagateChildFlags(this.whenTrue) | + propagateChildFlags(this.colonToken) | + propagateChildFlags(this.whenFalse); + } +} + +/** @internal */ +export type FunctionBody = + | Block; + +/** @internal */ +export type AstFunctionBody = AstNodeOneOf; + +/** @internal */ +export type ConciseBody = + | FunctionBody + | Expression; + +/** @internal */ +export type AstConciseBody = AstNodeOneOf; + +/** @internal */ +export class FunctionExpression extends Node implements JSDocContainer, Declaration, LocalsContainer, FlowContainer, ts.FunctionExpression { + declare readonly ast: AstFunctionExpression; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _functionLikeDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get asteriskToken() { return this.ast.data.asteriskToken?.node; } + set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ get typeArguments() { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get body() { return this.ast.data.body?.node; } + set body(value) { this.ast.data.body = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } + get endFlowNode() { return this.ast.data.endFlowNode; } + set endFlowNode(value) { this.ast.data.endFlowNode = value; } + get returnFlowNode() { return this.ast.data.returnFlowNode; } + set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } +} + +/** @internal */ +export class AstFunctionExpressionData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + asteriskToken: AstAsteriskToken | undefined = undefined; + name: AstIdentifier | undefined = undefined; + typeParameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode | undefined = undefined; + body: AstFunctionBody = undefined!; + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // Used for quick info, replaces typeParameters for instantiated signatures + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + const isAsync = modifiersToFlags(this.modifiers?.items) & ModifierFlags.Async; + const isGenerator = !!this.asteriskToken; + const isAsyncGenerator = isAsync && isGenerator; + return propagateChildrenFlags(this.modifiers) | + propagateChildFlags(this.asteriskToken) | + propagateNameFlags(this.name) | + propagateChildrenFlags(this.typeParameters) | + propagateChildrenFlags(this.parameters) | + propagateChildFlags(this.type) | + (propagateChildFlags(this.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | + (isAsyncGenerator ? TransformFlags.ContainsES2018 : + isAsync ? TransformFlags.ContainsES2017 : + isGenerator ? TransformFlags.ContainsGenerator : + TransformFlags.None) | + (this.typeParameters || this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + TransformFlags.ContainsHoistedDeclarationOrCompletion; + } +} + +/** @internal */ +export type ImmediatelyInvokedFunctionExpression = CallExpression & { readonly expression: FunctionExpression; }; + +/** @internal */ +export class ArrowFunction extends Node implements JSDocContainer, Declaration, LocalsContainer, FlowContainer, ts.ArrowFunction { + declare readonly ast: AstArrowFunction; + + declare _expressionBrand: any; + declare _functionLikeDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + declare name: never; + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get equalsGreaterThanToken() { return this.ast.data.equalsGreaterThanToken?.node; } + set equalsGreaterThanToken(value) { this.ast.data.equalsGreaterThanToken = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get body() { return this.ast.data.body?.node; } + set body(value) { this.ast.data.body = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } + get endFlowNode() { return this.ast.data.endFlowNode; } + set endFlowNode(value) { this.ast.data.endFlowNode = value; } + get returnFlowNode() { return this.ast.data.returnFlowNode; } + set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } +} + +/** @internal */ +export class AstArrowFunctionData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + equalsGreaterThanToken: AstToken = undefined!; + typeParameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode | undefined = undefined; + body: AstConciseBody = undefined!; + typeArguments: AstNodeArray | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + const isAsync = modifiersToFlags(this.modifiers?.items) & ModifierFlags.Async; + return propagateChildrenFlags(this.modifiers) | + propagateChildrenFlags(this.typeParameters) | + propagateChildrenFlags(this.parameters) | + propagateChildFlags(this.type) | + propagateChildFlags(this.equalsGreaterThanToken) | + (propagateChildFlags(this.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | + (this.typeParameters || this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + (isAsync ? TransformFlags.ContainsES2017 | TransformFlags.ContainsLexicalThis : TransformFlags.None) | + TransformFlags.ContainsES2015; + } +} + +/** @internal */ +export type ImmediatelyInvokedArrowFunction = CallExpression & { readonly expression: ParenthesizedExpression & { readonly expression: ArrowFunction; }; }; + +/** @internal */ +export class RegularExpressionLiteral extends Token implements ts.RegularExpressionLiteral { + declare readonly ast: AstRegularExpressionLiteral; + + declare _literalExpressionBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } + get isUnterminated() { return this.ast.data.isUnterminated; } + set isUnterminated(value) { this.ast.data.isUnterminated = value; } + get hasExtendedUnicodeEscape() { return this.ast.data.hasExtendedUnicodeEscape; } + set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } +} + +/** @internal */ +export class AstRegularExpressionLiteralData extends AstTokenData { + text: string = ""; + isUnterminated: boolean | undefined = undefined; + hasExtendedUnicodeEscape: boolean | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.None; + } +} + +/** @internal */ +export class StringLiteral extends Token implements LiteralExpression, Declaration, ts.StringLiteral { + declare readonly ast: AstStringLiteral; + + declare _literalExpressionBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } + get singleQuote() { return this.ast.data.singleQuote; } + set singleQuote(value) { this.ast.data.singleQuote = value; } + get isUnterminated() { return this.ast.data.isUnterminated; } + set isUnterminated(value) { this.ast.data.isUnterminated = value; } + get hasExtendedUnicodeEscape() { return this.ast.data.hasExtendedUnicodeEscape; } + set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + get textSourceNode() { return this.ast.data.textSourceNode?.node; } + set textSourceNode(value) { this.ast.data.textSourceNode = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstStringLiteralData extends AstTokenData { + text: string = ""; + singleQuote: boolean | undefined = undefined; + isUnterminated: boolean = false; + hasExtendedUnicodeEscape: boolean = false; + + textSourceNode?: AstNode | undefined; + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return this.hasExtendedUnicodeEscape ? TransformFlags.ContainsES2015 : TransformFlags.None; + } +} + +/** @internal */ +export class NoSubstitutionTemplateLiteral extends Token implements Declaration, ts.NoSubstitutionTemplateLiteral { + declare readonly ast: AstNoSubstitutionTemplateLiteral; + + declare _literalExpressionBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } + get rawText() { return this.ast.data.rawText; } + set rawText(value) { this.ast.data.rawText = value; } + get isUnterminated() { return this.ast.data.isUnterminated; } + set isUnterminated(value) { this.ast.data.isUnterminated = value; } + get hasExtendedUnicodeEscape() { return this.ast.data.hasExtendedUnicodeEscape; } + set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + get templateFlags() { return this.ast.data.templateFlags; } + set templateFlags(value) { this.ast.data.templateFlags = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstNoSubstitutionTemplateLiteralData extends AstTokenData { + text: string = ""; + rawText: string | undefined = undefined; + isUnterminated: boolean | undefined = undefined; + hasExtendedUnicodeEscape: boolean | undefined = undefined; + templateFlags = TokenFlags.None; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); + } +} + +/** @internal */ +export type PseudoLiteralToken = + | TemplateHead + | TemplateMiddle + | TemplateTail; + +/** @internal */ +export type AstPseudoLiteralToken = AstNodeOneOf; + +/** @internal */ +export type TemplateLiteralToken = + | NoSubstitutionTemplateLiteral + | PseudoLiteralToken; + +/** @internal */ +export type AstTemplateLiteralToken = AstNodeOneOf; + +/** @internal */ +export type StringLiteralLike = + | StringLiteral + | NoSubstitutionTemplateLiteral; + +/** @internal */ +export type AstStringLiteralLike = AstNodeOneOf; + +/** @internal */ +export class NumericLiteral extends Token implements Declaration, ts.NumericLiteral { + declare readonly ast: AstNumericLiteral; + + declare _literalExpressionBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } + get numericLiteralFlags() { return this.ast.data.numericLiteralFlags; } + set numericLiteralFlags(value) { this.ast.data.numericLiteralFlags = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstNumericLiteralData extends AstTokenData { + text: string = ""; + numericLiteralFlags = TokenFlags.None; + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return this.numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier ? TransformFlags.ContainsES2015 : TransformFlags.None; + } +} + +/** @internal */ +export class BigIntLiteral extends Token implements ts.BigIntLiteral { + declare readonly ast: AstBigIntLiteral; + + declare _literalExpressionBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } +} + +/** @internal */ +export class AstBigIntLiteralData extends AstTokenData { + text: string = ""; + + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.ContainsES2020; + } +} + +/** @internal */ +export type LiteralToken = + | NumericLiteral + | BigIntLiteral + | StringLiteral + | JsxText + | RegularExpressionLiteral + | NoSubstitutionTemplateLiteral; + +/** @internal */ +export type AstLiteralToken = AstNodeOneOf; + +/** @internal */ +export class TemplateHead extends Token implements ts.TemplateHead { + declare readonly ast: AstTemplateHead; + + override get parent() { return super.parent as TemplateExpression | TemplateLiteralTypeNode; } + override set parent(value) { super.parent = value; } + + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } + get isUnterminated() { return this.ast.data.isUnterminated; } + set isUnterminated(value) { this.ast.data.isUnterminated = value; } + get hasExtendedUnicodeEscape() { return this.ast.data.hasExtendedUnicodeEscape; } + set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + get rawText() { return this.ast.data.rawText; } + set rawText(value) { this.ast.data.rawText = value; } + get templateFlags() { return this.ast.data.templateFlags; } + set templateFlags(value) { this.ast.data.templateFlags = value; } +} + +/** @internal */ +export class AstTemplateHeadData extends AstTokenData { + text = ""; + isUnterminated: boolean | undefined = undefined; + hasExtendedUnicodeEscape: boolean | undefined = undefined; + rawText: string | undefined = undefined; + templateFlags = TokenFlags.None; + + override computeTransformFlags(_: AstNode): TransformFlags { + return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); + } +} + +/** @internal */ +export class TemplateMiddle extends Token implements ts.TemplateMiddle { + declare readonly ast: AstTemplateMiddle; + + override get parent() { return super.parent as TemplateSpan | TemplateLiteralTypeSpan; } + override set parent(value) { super.parent = value; } + + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } + get isUnterminated() { return this.ast.data.isUnterminated; } + set isUnterminated(value) { this.ast.data.isUnterminated = value; } + get hasExtendedUnicodeEscape() { return this.ast.data.hasExtendedUnicodeEscape; } + set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + get rawText() { return this.ast.data.rawText; } + set rawText(value) { this.ast.data.rawText = value; } + get templateFlags() { return this.ast.data.templateFlags; } + set templateFlags(value) { this.ast.data.templateFlags = value; } +} + +/** @internal */ +export class AstTemplateMiddleData extends AstTokenData { + text = ""; + isUnterminated: boolean | undefined = undefined; + hasExtendedUnicodeEscape: boolean | undefined = undefined; + rawText: string | undefined = undefined; + templateFlags = TokenFlags.None; + + override computeTransformFlags(_: AstNode): TransformFlags { + return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); + } +} + +/** @internal */ +export class TemplateTail extends Token implements ts.TemplateTail { + declare readonly ast: AstTemplateTail; + + override get parent() { return super.parent as TemplateSpan | TemplateLiteralTypeSpan; } + override set parent(value) { super.parent = value; } + + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } + get isUnterminated() { return this.ast.data.isUnterminated; } + set isUnterminated(value) { this.ast.data.isUnterminated = value; } + get hasExtendedUnicodeEscape() { return this.ast.data.hasExtendedUnicodeEscape; } + set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + get rawText() { return this.ast.data.rawText; } + set rawText(value) { this.ast.data.rawText = value; } + get templateFlags() { return this.ast.data.templateFlags; } + set templateFlags(value) { this.ast.data.templateFlags = value; } +} + +/** @internal */ +export class AstTemplateTailData extends AstTokenData { + text = ""; + isUnterminated: boolean | undefined = undefined; + hasExtendedUnicodeEscape: boolean | undefined = undefined; + rawText: string | undefined = undefined; + templateFlags = TokenFlags.None; + + override computeTransformFlags(_: AstNode): TransformFlags { + return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); + } +} + +/** @internal */ +export class TemplateExpression extends Node implements ts.TemplateExpression { + declare readonly ast: AstTemplateExpression; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get head() { return this.ast.data.head?.node; } + set head(value) { this.ast.data.head = value?.ast; } + get templateSpans() { return this.ast.data.templateSpans?.nodes!; } // TODO: remove `!` + set templateSpans(value) { this.ast.data.templateSpans = value?.ast; } +} + +/** @internal */ +export class AstTemplateExpressionData extends AstData { + head: AstTemplateHead = undefined!; + templateSpans: AstNodeArray | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.head) | + propagateChildrenFlags(this.templateSpans) | + TransformFlags.ContainsES2015; + } +} + +/** @internal */ +export class TemplateSpan extends Node implements ts.TemplateSpan { + declare readonly ast: AstTemplateSpan; + + override get parent() { return super.parent as TemplateExpression; } + override set parent(value) { super.parent = value; } + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get literal() { return this.ast.data.literal?.node; } + set literal(value) { this.ast.data.literal = value?.ast; } +} + +/** @internal */ +export class AstTemplateSpanData extends AstData { + expression: AstExpression = undefined!; + literal: AstTemplateMiddle | AstTemplateTail = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + propagateChildFlags(this.literal) | + TransformFlags.ContainsES2015; + } +} + +/** @internal */ +export class ParenthesizedExpression extends Node implements JSDocContainer, ts.ParenthesizedExpression { + declare readonly ast: AstParenthesizedExpression; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _jsdocContainerBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } +} + +/** @internal */ +export class AstParenthesizedExpressionData extends AstData { + expression: AstExpression = undefined!; + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression); + } +} + +/** @internal */ +export interface JSDocTypeAssertion extends ParenthesizedExpression { + readonly ast: AstJSDocTypeAssertion; + readonly _jsDocTypeAssertionBrand: never; +} + +/** @internal */ +export type AstJSDocTypeAssertion = AstNode; + +/** @internal */ +export class ArrayLiteralExpression extends Node implements ts.ArrayLiteralExpression { + declare readonly ast: AstArrayLiteralExpression; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get elements(): NodeArray { return this.ast.data.elements?.nodes!; } // TODO: remove '!' + set elements(value: NodeArray) { this.ast.data.elements = value?.ast; } + get multiLine() { return this.ast.data.multiLine; } + set multiLine(value) { this.ast.data.multiLine = value; } +} + +/** @internal */ +export class AstArrayLiteralExpressionData extends AstData { + elements: AstNodeArray | undefined = undefined; + multiLine: boolean | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildrenFlags(this.elements); + } +} + +/** @internal */ +export class SpreadElement extends Node implements ts.SpreadElement { + declare readonly ast: AstSpreadElement; + + declare _expressionBrand: any; + + override get parent() { return super.parent as ArrayLiteralExpression | CallExpression | NewExpression; } + override set parent(value) { super.parent = value; } + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstSpreadElementData extends AstData { + expression: AstExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + TransformFlags.ContainsES2015 | + TransformFlags.ContainsRestOrSpread; + } +} + +/** @internal */ +export interface ObjectLiteralElement extends Declaration { + /** @internal */ readonly ast: AstObjectLiteralElement; + _objectLiteralBrand: any; +} + +/** @internal */ +export type AstObjectLiteralElement = AstNode; + +/** @internal */ +export type ObjectLiteralElementLike = + | PropertyAssignment + | ShorthandPropertyAssignment + | SpreadAssignment + | MethodDeclaration + | AccessorDeclaration + ; + +/** @internal */ +export type AstObjectLiteralElementLike = AstNodeOneOf; + +/** @internal */ +export class ObjectLiteralExpression extends Node implements JSDocContainer, Declaration, ts.ObjectLiteralExpression { + declare readonly ast: AstObjectLiteralExpression; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + get properties() { return this.ast.data.properties?.nodes!; } // TODO: remove '!' + set properties(value) { this.ast.data.properties = value?.ast; } + get multiLine() { return this.ast.data.multiLine; } + set multiLine(value) { this.ast.data.multiLine = value; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstObjectLiteralExpressionData extends AstData { + properties: AstNodeArray | undefined = undefined; + multiLine: boolean | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildrenFlags(this.properties); + } +} + +/** @internal */ +export class PropertyAccessExpression extends Node implements JSDocContainer, Declaration, FlowContainer, ts.PropertyAccessExpression { + declare readonly ast: AstPropertyAccessExpression; + + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get questionDotToken() { return this.ast.data.questionDotToken?.node; } + set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstPropertyAccessExpressionData extends AstData { + expression: AstLeftHandSideExpression = undefined!; + questionDotToken: AstToken | undefined = undefined; + name: AstMemberName = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(node: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.expression) | + propagateChildFlags(this.questionDotToken) | + (this.name.kind === SyntaxKind.Identifier ? + propagateIdentifierNameFlags(this.name as AstIdentifier) : + propagateChildFlags(this.name) | TransformFlags.ContainsPrivateIdentifierInExpression); + if (node.flags & NodeFlags.OptionalChain) { + transformFlags |= TransformFlags.ContainsES2020;; + } + else if (this.expression.kind === SyntaxKind.SuperKeyword) { + // super method calls require a lexical 'this' + // super method calls require 'super' hoisting in ES2017 and ES2018 async functions and async generators + transformFlags |= TransformFlags.ContainsES2017 | + TransformFlags.ContainsES2018; + } + return transformFlags; + } +} + +/** @internal */ +export interface PropertyAccessEntityNameExpression extends PropertyAccessExpression { + _propertyAccessExpressionLikeQualifiedNameBrand?: any; + readonly ast: AstPropertyAccessEntityNameExpression; + readonly data: AstPropertyAccessEntityNameExpressionData; + readonly expression: EntityNameExpression; + readonly name: Identifier; +} + +/** @internal */ +export type AstPropertyAccessEntityNameExpression = AstNode; + +/** @internal */ +export interface AstPropertyAccessEntityNameExpressionData extends AstPropertyAccessExpressionData { + expression: AstEntityNameExpression; + name: AstIdentifier; +} + +/** @internal */ +export type EntityNameExpression = + | Identifier + | PropertyAccessEntityNameExpression; + +/** @internal */ +export type AstEntityNameExpression = AstNodeOneOf; + +/** @internal */ +export interface PropertyAccessChain extends PropertyAccessExpression { + _optionalChainBrand: any; + readonly ast: AstPropertyAccessChain; + readonly name: MemberName; +} + +/** @internal */ +export type AstPropertyAccessChain = AstNode; + +/** @internal */ +export interface PropertyAccessChainRoot extends PropertyAccessChain { + readonly questionDotToken: QuestionDotToken; +} + +/** @internal */ +export type AstPropertyAccessChainRoot = AstNode; + +/** @internal */ +export class ElementAccessExpression extends Node implements JSDocContainer, Declaration, FlowContainer, ts.ElementAccessExpression { + declare readonly ast: AstElementAccessExpression; + + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get questionDotToken() { return this.ast.data.questionDotToken?.node; } + set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } + get argumentExpression() { return this.ast.data.argumentExpression?.node; } + set argumentExpression(value) { this.ast.data.argumentExpression = value?.ast; } + + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstElementAccessExpressionData extends AstData { + expression: AstLeftHandSideExpression = undefined!; + questionDotToken: AstToken | undefined = undefined; + argumentExpression: AstExpression = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(node: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.expression) | + propagateChildFlags(this.questionDotToken) | + propagateChildFlags(this.argumentExpression); + if (node.flags & NodeFlags.OptionalChain) { + transformFlags |= TransformFlags.ContainsES2020; + } + else if (this.expression.kind === SyntaxKind.SuperKeyword) { + // super method calls require a lexical 'this' + // super method calls require 'super' hoisting in ES2017 and ES2018 async functions and async generators + transformFlags |= TransformFlags.ContainsES2017 | + TransformFlags.ContainsES2018; + } + return transformFlags; + } +} + +/** @internal */ +export interface ElementAccessChain extends ElementAccessExpression { + readonly ast: AstElementAccessChain; + _optionalChainBrand: any; +} + +/** @internal */ +export type AstElementAccessChain = AstNode; + +/** @internal */ +export interface ElementAccessChainRoot extends ElementAccessChain { + readonly questionDotToken: QuestionDotToken; +} + +/** @internal */ +export type AstElementAccessChainRoot = AstNode; + +/** @internal */ +export class CallExpression extends Node implements Declaration, ts.CallExpression { + declare readonly ast: AstCallExpression; + + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get questionDotToken() { return this.ast.data.questionDotToken?.node; } + set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get arguments() { return this.ast.data.arguments?.nodes!; } // TODO: remove `!` + set arguments(value) { this.ast.data.arguments = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstCallExpressionData extends AstData { + expression: AstLeftHandSideExpression = undefined!; + questionDotToken: AstQuestionDotToken | undefined = undefined; + typeArguments: AstNodeArray | undefined = undefined; + arguments: AstNodeArray | undefined = undefined; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(node: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.expression) | + propagateChildFlags(this.questionDotToken) | + propagateChildrenFlags(this.typeArguments) | + propagateChildrenFlags(this.arguments); + if (this.typeArguments) { + transformFlags |= TransformFlags.ContainsTypeScript; + } + if ((this.expression.kind === SyntaxKind.PropertyAccessExpression || + this.expression.kind === SyntaxKind.ElementAccessExpression) && + (this.expression as AstNode).data.expression.kind === SyntaxKind.SuperKeyword + ) { + transformFlags |= TransformFlags.ContainsLexicalThis; + } + if (node.flags & NodeFlags.OptionalChain) { + transformFlags |= TransformFlags.ContainsES2020; + } + else if (this.expression.kind === SyntaxKind.ImportKeyword) { + transformFlags |= TransformFlags.ContainsDynamicImport; + } + return transformFlags; + } +} + +/** @internal */ +export interface CallChain extends CallExpression { + readonly ast: AstCallChain; + _optionalChainBrand: any; +} + +/** @internal */ +export type AstCallChain = AstNode; + +/** @internal */ +export interface CallChainRoot extends CallChain { + readonly questionDotToken: QuestionDotToken; +} + +/** @internal */ +export type AstCallChainRoot = AstNode; + +/** @internal */ +export type OptionalChainRoot = + | PropertyAccessChainRoot + | ElementAccessChainRoot + | CallChainRoot; + +/** @internal */ +export type AstOptionalChainRoot = AstNodeOneOf; + +/** @internal */ +export class ExpressionWithTypeArguments extends Node implements ts.ExpressionWithTypeArguments { + declare readonly ast: AstExpressionWithTypeArguments; + + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _typeNodeBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } +} + +/** @internal */ +export class AstExpressionWithTypeArgumentsData extends AstData { + expression: AstLeftHandSideExpression = undefined!; + typeArguments: AstNodeArray | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + propagateChildrenFlags(this.typeArguments) | + TransformFlags.ContainsES2015; + } +} + +/** @internal */ +export class NewExpression extends Node implements Declaration, ts.NewExpression { + declare readonly ast: AstNewExpression; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get arguments() { return this.ast.data.arguments?.nodes; } + set arguments(value) { this.ast.data.arguments = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstNewExpressionData extends AstData { + expression: AstLeftHandSideExpression = undefined!; + typeArguments: AstNodeArray | undefined = undefined; + arguments: AstNodeArray | undefined = undefined; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.expression) | + propagateChildrenFlags(this.typeArguments) | + propagateChildrenFlags(this.arguments) | + TransformFlags.ContainsES2020; + if (this.typeArguments) { + transformFlags |= TransformFlags.ContainsTypeScript; + } + return transformFlags; + } +} + +/** @internal */ +export type TemplateLiteral = + | TemplateExpression + | NoSubstitutionTemplateLiteral + ; + +/** @internal */ +export type AstTemplateLiteral = AstNodeOneOf; + +/** @internal */ +export class TaggedTemplateExpression extends Node implements ts.TaggedTemplateExpression { + declare readonly ast: AstTaggedTemplateExpression; + + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get tag() { return this.ast.data.tag?.node; } + set tag(value) { this.ast.data.tag = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get template() { return this.ast.data.template?.node; } + set template(value) { this.ast.data.template = value?.ast; } + get questionDotToken() { return this.ast.data.questionDotToken?.node; } + set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } +} + +/** @internal */ +export class AstTaggedTemplateExpressionData extends AstData { + tag: AstLeftHandSideExpression = undefined!; + typeArguments: AstNodeArray | undefined = undefined; + template: AstTemplateLiteral = undefined!; + questionDotToken: AstToken | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.tag) | + propagateChildrenFlags(this.typeArguments) | + propagateChildFlags(this.template) | + TransformFlags.ContainsES2015; + if (this.typeArguments) { + transformFlags |= TransformFlags.ContainsTypeScript; + } + if (hasInvalidEscape(this.template)) { + transformFlags |= TransformFlags.ContainsES2018; + } + return transformFlags; + } +} + +/** @internal */ +export class AsExpression extends Node implements ts.AsExpression { + declare readonly ast: AstAsExpression; + + declare _expressionBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } +} + +/** @internal */ +export class AstAsExpressionData extends AstData { + expression: AstExpression = undefined!; + type: AstTypeNode = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + propagateChildFlags(this.type) | + TransformFlags.ContainsTypeScript; + } +} + +/** @internal */ +export class TypeAssertion extends Node implements ts.TypeAssertion { + declare readonly ast: AstTypeAssertion; + + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstTypeAssertionData extends AstData { + type: AstTypeNode = undefined!; + expression: AstUnaryExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + propagateChildFlags(this.type) | + TransformFlags.ContainsTypeScript; + } +} + +/** @internal */ +export class SatisfiesExpression extends Node implements ts.SatisfiesExpression { + declare readonly ast: AstSatisfiesExpression; + + declare _expressionBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } +} + +/** @internal */ +export class AstSatisfiesExpressionData extends AstData { + expression: AstExpression = undefined!; + type: AstTypeNode = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + propagateChildFlags(this.type) | + TransformFlags.ContainsTypeScript; + } +} + +/** @internal */ +export class NonNullExpression extends Node implements ts.NonNullExpression { + declare readonly ast: AstNonNullExpression; + + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get expression(): Expression { return this.ast.data.expression?.node; } + set expression(value: Expression) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstNonNullExpressionData extends AstData { + expression: AstExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + TransformFlags.ContainsTypeScript; + } +} + +/** @internal */ +export interface NonNullChain extends NonNullExpression { + readonly ast: AstNonNullChain; + _optionalChainBrand: any; +} + +/** @internal */ +export type AstNonNullChain = AstNode; + +/** @internal */ +export class MetaProperty extends Node implements FlowContainer, ts.MetaProperty { + declare readonly ast: AstMetaProperty; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _flowContainerBrand: any; + + get keywordToken(): SyntaxKind.ImportKeyword | SyntaxKind.NewKeyword { return this.ast.data.keywordToken; } + set keywordToken(value: SyntaxKind.ImportKeyword | SyntaxKind.NewKeyword) { this.ast.data.keywordToken = value; } + get name(): Identifier { return this.ast.data.name?.node; } + set name(value: Identifier) { this.ast.data.name = value?.ast; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstMetaPropertyData extends AstData { + keywordToken: SyntaxKind.NewKeyword | SyntaxKind.ImportKeyword = undefined!; + name: AstIdentifier = undefined!; + + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.name); + switch (this.keywordToken) { + case SyntaxKind.NewKeyword: + transformFlags |= TransformFlags.ContainsES2015; + break; + case SyntaxKind.ImportKeyword: + transformFlags |= TransformFlags.ContainsES2020; + break; + default: + return Debug.assertNever(this.keywordToken); + } + return transformFlags; + } +} + +/** @internal */ +export class JsxElement extends Node implements ts.JsxElement { + declare readonly ast: AstJsxElement; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get openingElement(): JsxOpeningElement { return this.ast.data.openingElement?.node; } + set openingElement(value: JsxOpeningElement) { this.ast.data.openingElement = value?.ast; } + get children(): NodeArray { return this.ast.data.children.nodes; } + set children(value: NodeArray) { this.ast.data.children = value?.ast; } + get closingElement(): JsxClosingElement { return this.ast.data.closingElement?.node; } + set closingElement(value: JsxClosingElement) { this.ast.data.closingElement = value?.ast; } +} + +/** @internal */ +export class AstJsxElementData extends AstData { + openingElement: AstJsxOpeningElement = undefined!; + children: AstNodeArray = undefined!; + closingElement: AstJsxClosingElement = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.openingElement) | + propagateChildrenFlags(this.children) | + propagateChildFlags(this.closingElement) | + TransformFlags.ContainsJsx; + } +} + +/** @internal */ +export type JsxOpeningLikeElement = + | JsxSelfClosingElement + | JsxOpeningElement + ; + +/** @internal */ +export type AstJsxOpeningLikeElement = AstNodeOneOf; + +/** @internal */ +export type JsxAttributeLike = + | JsxAttribute + | JsxSpreadAttribute; + +/** @internal */ +export type AstJsxAttributeLike = AstNodeOneOf; + +/** @internal */ +export type JsxAttributeName = + | Identifier + | JsxNamespacedName; + +/** @internal */ +export type AstJsxAttributeName = AstNodeOneOf; + +/** @internal */ +export type JsxTagNameExpression = + | Identifier + | ThisExpression + | JsxTagNamePropertyAccess + | JsxNamespacedName; + +/** @internal */ +export type AstJsxTagNameExpression = AstNodeOneOf; + +/** @internal */ +export interface JsxTagNamePropertyAccess extends PropertyAccessExpression { + readonly ast: AstJsxTagNamePropertyAccess; + readonly data: AstJsxTagNamePropertyAccessData; + readonly expression: Identifier | ThisExpression | JsxTagNamePropertyAccess; +} + +/** @internal */ +export type AstJsxTagNamePropertyAccess = AstNode; + +/** @internal */ +export interface AstJsxTagNamePropertyAccessData extends AstPropertyAccessExpressionData { + expression: AstIdentifier | AstThisExpression | AstJsxTagNamePropertyAccess; +} + +/** @internal */ +export class JsxAttributes extends Node implements Declaration, ts.JsxAttributes { + declare readonly ast: AstJsxAttributes; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + + override get parent() { return super.parent as JsxOpeningLikeElement; } + override set parent(value) { super.parent = value; } + + get properties() { return this.ast.data.properties.nodes; } + set properties(value) { this.ast.data.properties = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstJsxAttributesData extends AstData { + properties: AstNodeArray = undefined!; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildrenFlags(this.properties) | + TransformFlags.ContainsJsx; + } +} + +/** @internal */ +export class JsxNamespacedName extends Node implements ts.JsxNamespacedName { + declare readonly ast: AstJsxNamespacedName; + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get namespace() { return this.ast.data.namespace?.node; } + set namespace(value) { this.ast.data.namespace = value?.ast; } +} + +/** @internal */ +export class AstJsxNamespacedNameData extends AstData { + name: AstIdentifier = undefined!; + namespace: AstIdentifier = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.namespace) | + propagateChildFlags(this.name) | + TransformFlags.ContainsJsx; + } +} + +/** @internal */ +export class JsxOpeningElement extends Node implements ts.JsxOpeningElement { + declare readonly ast: AstJsxOpeningElement; + + declare _expressionBrand: any; + + override get parent() { return super.parent as JsxElement; } + override set parent(value) { super.parent = value; } + + get tagName() { return this.ast.data.tagName?.node; } + set tagName(value) { this.ast.data.tagName = value.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get attributes() { return this.ast.data.attributes?.node; } + set attributes(value) { this.ast.data.attributes = value?.ast; } +} + +/** @internal */ +export class AstJsxOpeningElementData extends AstData { + tagName: AstJsxTagNameExpression = undefined!; + typeArguments: AstNodeArray | undefined = undefined; + attributes: AstJsxAttributes = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.tagName) | + propagateChildrenFlags(this.typeArguments) | + propagateChildFlags(this.attributes) | + TransformFlags.ContainsJsx; + if (this.typeArguments) { + transformFlags |= TransformFlags.ContainsTypeScript; + } + return transformFlags; + } +} + +/** @internal */ +export class JsxClosingElement extends Node implements ts.JsxClosingElement { + declare readonly ast: AstJsxClosingElement; + + override get parent() { return super.parent as JsxElement; } + override set parent(value) { super.parent = value; } + + get tagName() { return this.ast.data.tagName?.node; } + set tagName(value) { this.ast.data.tagName = value.ast; } +} + +/** @internal */ +export class AstJsxClosingElementData extends AstData { + tagName: AstJsxTagNameExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.tagName) | + TransformFlags.ContainsJsx; + } +} + +/** @internal */ +export class JsxSelfClosingElement extends Node implements ts.JsxSelfClosingElement { + declare readonly ast: AstJsxSelfClosingElement; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get tagName() { return this.ast.data.tagName?.node; } + set tagName(value) { this.ast.data.tagName = value.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get attributes() { return this.ast.data.attributes?.node; } + set attributes(value) { this.ast.data.attributes = value?.ast; } +} + +/** @internal */ +export class AstJsxSelfClosingElementData extends AstData { + tagName: AstJsxTagNameExpression = undefined!; + typeArguments: AstNodeArray | undefined = undefined; + attributes: AstJsxAttributes = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.tagName) | + propagateChildrenFlags(this.typeArguments) | + propagateChildFlags(this.attributes) | + TransformFlags.ContainsJsx; + if (this.typeArguments) { + transformFlags |= TransformFlags.ContainsTypeScript; + } + return transformFlags; + } +} + +/** @internal */ +export class JsxFragment extends Node implements ts.JsxFragment { + declare readonly ast: AstJsxFragment; + + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get openingFragment(): JsxOpeningFragment { return this.ast.data.openingFragment?.node; } + set openingFragment(value: JsxOpeningFragment) { this.ast.data.openingFragment = value?.ast; } + get children(): NodeArray { return this.ast.data.children.nodes; } + set children(value: NodeArray) { this.ast.data.children = value?.ast; } + get closingFragment(): JsxClosingFragment { return this.ast.data.closingFragment?.node; } + set closingFragment(value: JsxClosingFragment) { this.ast.data.closingFragment = value?.ast; } +} + +/** @internal */ +export class AstJsxFragmentData extends AstData { + openingFragment: AstJsxOpeningFragment = undefined!; + children: AstNodeArray = undefined!; + closingFragment: AstJsxClosingFragment = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.openingFragment) | + propagateChildrenFlags(this.children) | + propagateChildFlags(this.closingFragment) | + TransformFlags.ContainsJsx; + } +} + +/** @internal */ +export class JsxOpeningFragment extends Node implements ts.JsxOpeningFragment { + declare readonly ast: AstJsxOpeningFragment; + + declare _expressionBrand: any; // TODO: is this accurate? + + override get parent() { return super.parent as JsxFragment; } + override set parent(value) { super.parent = value; } +} + +/** @internal */ +export class AstJsxOpeningFragmentData extends AstData { + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.ContainsJsx; + } +} + +/** @internal */ +export class JsxClosingFragment extends Node implements ts.JsxClosingFragment { + declare readonly ast: AstJsxClosingFragment; + + declare _expressionBrand: any; // TODO: is this accurate? + + override get parent() { return super.parent as JsxFragment; } + override set parent(value) { super.parent = value; } +} + +/** @internal */ +export class AstJsxClosingFragmentData extends AstData { + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.ContainsJsx; + } +} + +/** @internal */ +export class JsxAttribute extends Node implements Declaration, ts.JsxAttribute { + declare readonly ast: AstJsxAttribute; + + declare _declarationBrand: any; + + override get parent() { return super.parent as JsxAttributes; } + override set parent(value) { super.parent = value; } + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get initializer() { return this.ast.data.initializer?.node; } + set initializer(value) { this.ast.data.initializer = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstJsxAttributeData extends AstData { + name: AstJsxAttributeName = undefined!; + initializer: AstJsxAttributeValue | undefined = undefined; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.name) | + propagateChildFlags(this.initializer) | + TransformFlags.ContainsJsx; + } +} + +/** @internal */ +export type JsxAttributeValue = + | StringLiteral + | JsxExpression + | JsxElement + | JsxSelfClosingElement + | JsxFragment; + +/** @internal */ +export type AstJsxAttributeValue = AstNodeOneOf; + +/** @internal */ +export class JsxSpreadAttribute extends Node implements ts.JsxSpreadAttribute { + declare readonly ast: AstJsxSpreadAttribute; + + declare _objectLiteralBrand: any; + declare _declarationBrand: any; + declare symbol: never; + declare localSymbol: never; + + override get parent() { return super.parent as JsxAttributes; } + override set parent(value) { super.parent = value; } + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstJsxSpreadAttributeData extends AstData { + expression: AstExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + TransformFlags.ContainsJsx; + } +} + +/** @internal */ +export class JsxExpression extends Node implements ts.JsxExpression { + declare readonly ast: AstJsxExpression; + + declare _expressionBrand: any; // TODO: is this accurate? + + override get parent() { return super.parent as JsxElement | JsxFragment | JsxAttributeLike; } + override set parent(value) { super.parent = value; } + + get dotDotDotToken() { return this.ast.data.dotDotDotToken?.node; } + set dotDotDotToken(value) { this.ast.data.dotDotDotToken = value?.ast; } + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstJsxExpressionData extends AstData { + dotDotDotToken: AstDotDotDotToken | undefined = undefined; + expression: AstExpression | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.dotDotDotToken) | + propagateChildFlags(this.expression) | + TransformFlags.ContainsJsx; + } +} + +/** @internal */ +export class JsxText extends Token implements ts.JsxText { + declare readonly ast: AstJsxText; + + override get parent() { return super.parent as JsxElement | JsxFragment; } + override set parent(value) { super.parent = value; } + + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } + get isUnterminated() { return this.ast.data.isUnterminated; } + set isUnterminated(value) { this.ast.data.isUnterminated = value; } + get hasExtendedUnicodeEscape() { return this.ast.data.hasExtendedUnicodeEscape; } + set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + get containsOnlyTriviaWhiteSpaces() { return this.ast.data.containsOnlyTriviaWhiteSpaces; } + set containsOnlyTriviaWhiteSpaces(value) { this.ast.data.containsOnlyTriviaWhiteSpaces = value; } +} + +/** @internal */ +export class AstJsxTextData extends AstData { + text = ""; + isUnterminated: boolean | undefined = undefined; + hasExtendedUnicodeEscape: boolean | undefined = undefined; + containsOnlyTriviaWhiteSpaces: boolean = false; + + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.ContainsJsx; + } +} + +/** @internal */ +export type JsxChild = + | JsxText + | JsxExpression + | JsxElement + | JsxSelfClosingElement + | JsxFragment + ; + +/** @internal */ +export type AstJsxChild = AstNodeOneOf; + + +/** @internal */ +export type IterationStatement = + | DoStatement + | WhileStatement + | ForStatement + | ForInOrOfStatement + ; + +/** @internal */ +export type AstIterationStatement = AstNodeOneOf; + +/** @internal */ +export class EmptyStatement extends Node implements JSDocContainer, ts.EmptyStatement { + declare readonly ast: AstEmptyStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } +} + +/** @internal */ +export class AstEmptyStatementData extends AstData { + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.None; + } +} + +/** @internal */ +export class DebuggerStatement extends Node implements JSDocContainer, FlowContainer, ts.DebuggerStatement { + declare readonly ast: AstDebuggerStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstDebuggerStatementData extends AstData { + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.None; + } +} + +/** @internal */ +export class MissingDeclaration extends Node implements JSDocContainer, Declaration, ts.MissingDeclaration { + declare readonly ast: AstMissingDeclaration; + + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstMissingDeclarationData extends AstData { + name: AstIdentifier | undefined = undefined; + modifiers: AstNodeArray | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.None; + } +} + +/** @internal */ +export class Block extends Node implements JSDocContainer, LocalsContainer, ts.Block { + declare readonly ast: AstBlock; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + + get statements() { return this.ast.data.statements?.nodes!; } // TODO: remove `!` + set statements(value) { this.ast.data.statements = value?.ast; } + get multiLine() { return this.ast.data.multiLine; } + set multiLine(value) { this.ast.data.multiLine = value; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstBlockData extends AstData { + statements: AstNodeArray | undefined = undefined; + multiLine: boolean | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildrenFlags(this.statements); + } +} + +/** @internal */ +export class VariableStatement extends Node implements JSDocContainer, FlowContainer, ts.VariableStatement { + declare readonly ast: AstVariableStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get declarationList() { return this.ast.data.declarationList?.node; } + set declarationList(value) { this.ast.data.declarationList = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstVariableStatementData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + declarationList: AstVariableDeclarationList = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildrenFlags(this.modifiers) | + propagateChildFlags(this.declarationList); + if (modifiersToFlags(this.modifiers?.items) & ModifierFlags.Ambient) { + transformFlags = TransformFlags.ContainsTypeScript; + } + return transformFlags; + } +} + +/** @internal */ +export class ExpressionStatement extends Node implements JSDocContainer, FlowContainer, ts.ExpressionStatement { + declare readonly ast: AstExpressionStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstExpressionStatementData extends AstData { + expression: AstExpression = undefined!; + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression); + } +} + +/** @internal */ +export interface PrologueDirective extends ExpressionStatement { + readonly expression: StringLiteral; +} + +/** @internal */ +export class IfStatement extends Node implements JSDocContainer, FlowContainer, ts.IfStatement { + declare readonly ast: AstIfStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get thenStatement() { return this.ast.data.thenStatement?.node; } + set thenStatement(value) { this.ast.data.thenStatement = value?.ast; } + get elseStatement() { return this.ast.data.elseStatement?.node; } + set elseStatement(value) { this.ast.data.elseStatement = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstIfStatementData extends AstData { + expression: AstExpression = undefined!; + thenStatement: AstStatement = undefined!; + elseStatement: AstStatement | undefined = undefined; + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + propagateChildFlags(this.thenStatement) | + propagateChildFlags(this.elseStatement); + } +} + +/** @internal */ +export class DoStatement extends Node implements JSDocContainer, FlowContainer, ts.DoStatement { + declare readonly ast: AstDoStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get statement() { return this.ast.data.statement?.node; } + set statement(value) { this.ast.data.statement = value?.ast; } + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstDoStatementData extends AstData { + statement: AstStatement = undefined!; + expression: AstExpression = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.statement) | + propagateChildFlags(this.expression); + } +} + +/** @internal */ +export class WhileStatement extends Node implements JSDocContainer, FlowContainer, ts.WhileStatement { + declare readonly ast: AstWhileStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get statement() { return this.ast.data.statement?.node; } + set statement(value) { this.ast.data.statement = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstWhileStatementData extends AstData { + expression: AstExpression = undefined!; + statement: AstStatement = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + propagateChildFlags(this.statement); + } +} + +/** @internal */ +export type ForInitializer = + | VariableDeclarationList + | Expression + ; + +/** @internal */ +export type AstForInitializer = AstNodeOneOf; + + +/** @internal */ +export class ForStatement extends Node implements JSDocContainer, LocalsContainer, FlowContainer, ts.ForStatement { + declare readonly ast: AstForStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + + get initializer() { return this.ast.data.initializer?.node; } + set initializer(value) { this.ast.data.initializer = value?.ast; } + get condition() { return this.ast.data.condition?.node; } + set condition(value) { this.ast.data.condition = value?.ast; } + get incrementor() { return this.ast.data.incrementor?.node; } + set incrementor(value) { this.ast.data.incrementor = value?.ast; } + get statement() { return this.ast.data.statement?.node; } + set statement(value) { this.ast.data.statement = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstForStatementData extends AstData { + initializer: AstForInitializer | undefined = undefined; + condition: AstExpression | undefined = undefined; + incrementor: AstExpression | undefined = undefined; + statement: AstStatement = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.initializer) | + propagateChildFlags(this.condition) | + propagateChildFlags(this.incrementor) | + propagateChildFlags(this.statement); + } +} + +/** @internal */ +export type ForInOrOfStatement = + | ForInStatement + | ForOfStatement + ; + +/** @internal */ +export type AstForInOrOfStatement = AstNodeOneOf; + +/** @internal */ +export class ForInStatement extends Node implements JSDocContainer, LocalsContainer, FlowContainer, ts.ForInStatement { + declare readonly ast: AstForInStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + + get initializer() { return this.ast.data.initializer?.node; } + set initializer(value) { this.ast.data.initializer = value?.ast; } + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get statement() { return this.ast.data.statement?.node; } + set statement(value) { this.ast.data.statement = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstForInStatementData extends AstData { + initializer: AstForInitializer = undefined!; + expression: AstExpression = undefined!; + statement: AstStatement = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.initializer) | + propagateChildFlags(this.expression) | + propagateChildFlags(this.statement); + } +} + +/** @internal */ +export class ForOfStatement extends Node implements JSDocContainer, LocalsContainer, FlowContainer, ts.ForOfStatement { + declare readonly ast: AstForOfStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + + get awaitModifier() { return this.ast.data.awaitModifier?.node; } + set awaitModifier(value) { this.ast.data.awaitModifier = value?.ast; } + get initializer() { return this.ast.data.initializer?.node; } + set initializer(value) { this.ast.data.initializer = value?.ast; } + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get statement() { return this.ast.data.statement?.node; } + set statement(value) { this.ast.data.statement = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstForOfStatementData extends AstData { + awaitModifier: AstToken | undefined = undefined; + initializer: AstForInitializer = undefined!; + expression: AstExpression = undefined!; + statement: AstStatement = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.awaitModifier) | + propagateChildFlags(this.initializer) | + propagateChildFlags(this.expression) | + propagateChildFlags(this.statement) | + TransformFlags.ContainsES2015; + if (this.awaitModifier) { + transformFlags |= TransformFlags.ContainsES2018; + } + return transformFlags; + } +} + +/** @internal */ +export class BreakStatement extends Node implements JSDocContainer, FlowContainer, ts.BreakStatement { + declare readonly ast: AstBreakStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get label() { return this.ast.data.label?.node; } + set label(value) { this.ast.data.label = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstBreakStatementData extends AstData { + label: AstIdentifier | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.label) | + TransformFlags.ContainsHoistedDeclarationOrCompletion; + } +} + +/** @internal */ +export class ContinueStatement extends Node implements JSDocContainer, FlowContainer, ts.ContinueStatement { + declare readonly ast: AstContinueStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get label() { return this.ast.data.label?.node; } + set label(value) { this.ast.data.label = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export type BreakOrContinueStatement = + | BreakStatement + | ContinueStatement; + +/** @internal */ +export type AstBreakOrContinueStatement = AstNodeOneOf; + +/** @internal */ +export class AstContinueStatementData extends AstData { + label: AstIdentifier | undefined = undefined; + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.label) | + TransformFlags.ContainsHoistedDeclarationOrCompletion; + } +} + +/** @internal */ +export class ReturnStatement extends Node implements JSDocContainer, FlowContainer, ts.ReturnStatement { + declare readonly ast: AstReturnStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstReturnStatementData extends AstData { + expression: AstExpression | undefined = undefined; + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + // return in an ES2018 async generator must be awaited + return propagateChildFlags(this.expression) | + TransformFlags.ContainsES2018 | + TransformFlags.ContainsHoistedDeclarationOrCompletion; + } +} + +/** @internal */ +export class WithStatement extends Node implements JSDocContainer, FlowContainer, ts.WithStatement { + declare readonly ast: AstWithStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get statement() { return this.ast.data.statement?.node; } + set statement(value) { this.ast.data.statement = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstWithStatementData extends AstData { + expression: AstExpression = undefined!; + statement: AstStatement = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + propagateChildFlags(this.statement); + } +} + +/** @internal */ +export class SwitchStatement extends Node implements JSDocContainer, FlowContainer, ts.SwitchStatement { + declare readonly ast: AstSwitchStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get caseBlock() { return this.ast.data.caseBlock?.node; } + set caseBlock(value) { this.ast.data.caseBlock = value?.ast; } + get possiblyExhaustive() { return this.ast.data.possiblyExhaustive; } + set possiblyExhaustive(value) { this.ast.data.possiblyExhaustive = value; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstSwitchStatementData extends AstData { + expression: AstExpression = undefined!; + caseBlock: AstCaseBlock = undefined!; + possiblyExhaustive: boolean = false; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + propagateChildFlags(this.caseBlock); + } +} + +/** @internal */ +export class CaseBlock extends Node implements LocalsContainer, ts.CaseBlock { + declare readonly ast: AstCaseBlock; + + declare _localsContainerBrand: any; + + override get parent() { return super.parent as SwitchStatement; } + override set parent(value) { super.parent = value; } + + get clauses() { return this.ast.data.clauses?.nodes!; } // TODO: remove '!' + set clauses(value) { this.ast.data.clauses = value?.ast; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstCaseBlockData extends AstData { + clauses: AstNodeArray | undefined = undefined; + + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildrenFlags(this.clauses); + } +} + +/** @internal */ +export class CaseClause extends Node implements JSDocContainer, ts.CaseClause { + declare readonly ast: AstCaseClause; + + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as CaseBlock; } + override set parent(value) { super.parent = value; } + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get statements() { return this.ast.data.statements?.nodes!; } // TODO: remove `!` + set statements(value) { this.ast.data.statements = value?.ast; } + get fallthroughFlowNode() { return this.ast.data.fallthroughFlowNode; } + set fallthroughFlowNode(value) { this.ast.data.fallthroughFlowNode = value; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } +} + +/** @internal */ +export class AstCaseClauseData extends AstData { + expression: AstExpression = undefined!; + statements: AstNodeArray | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + fallthroughFlowNode?: FlowNode | undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + propagateChildrenFlags(this.statements); + } +} + +/** @internal */ +export class DefaultClause extends Node implements ts.DefaultClause { + declare readonly ast: AstDefaultClause; + + override get parent() { return super.parent as CaseBlock; } + override set parent(value) { super.parent = value; } + + get statements() { return this.ast.data.statements?.nodes!; } // TODO: remove `!` + set statements(value) { this.ast.data.statements = value?.ast; } + get fallthroughFlowNode() { return this.ast.data.fallthroughFlowNode; } + set fallthroughFlowNode(value) { this.ast.data.fallthroughFlowNode = value; } +} + +/** @internal */ +export class AstDefaultClauseData extends AstData { + statements: AstNodeArray | undefined = undefined; + + fallthroughFlowNode?: FlowNode | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildrenFlags(this.statements); + } +} + +/** @internal */ +export type CaseOrDefaultClause = + | CaseClause + | DefaultClause + ; + +/** @internal */ +export type AstCaseOrDefaultClause = AstNodeOneOf; + +/** @internal */ +export class LabeledStatement extends Node implements JSDocContainer, FlowContainer, ts.LabeledStatement { + declare readonly ast: AstLabeledStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get label() { return this.ast.data.label?.node; } + set label(value) { this.ast.data.label = value?.ast; } + get statement() { return this.ast.data.statement?.node; } + set statement(value) { this.ast.data.statement = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstLabeledStatementData extends AstData { + label: AstIdentifier = undefined!; + statement: AstStatement = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.label) | + propagateChildFlags(this.statement); + } +} + +/** @internal */ +export class ThrowStatement extends Node implements JSDocContainer, FlowContainer, ts.ThrowStatement { + declare readonly ast: AstThrowStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstThrowStatementData extends AstData { + expression: AstExpression = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression); + } +} + +/** @internal */ +export class TryStatement extends Node implements JSDocContainer, FlowContainer, ts.TryStatement { + declare readonly ast: AstTryStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + + get tryBlock() { return this.ast.data.tryBlock?.node; } + set tryBlock(value) { this.ast.data.tryBlock = value?.ast; } + get catchClause() { return this.ast.data.catchClause?.node; } + set catchClause(value) { this.ast.data.catchClause = value?.ast; } + get finallyBlock() { return this.ast.data.finallyBlock?.node; } + set finallyBlock(value) { this.ast.data.finallyBlock = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +/** @internal */ +export class AstTryStatementData extends AstData { + tryBlock: AstBlock = undefined!; + catchClause: AstCatchClause | undefined = undefined; + finallyBlock: AstBlock | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.tryBlock) | + propagateChildFlags(this.catchClause) | + propagateChildFlags(this.finallyBlock); + } +} + +/** @internal */ +export class CatchClause extends Node implements LocalsContainer, ts.CatchClause { + declare readonly ast: AstCatchClause; + + declare _localsContainerBrand: any; + + override get parent() { return super.parent as TryStatement; } + override set parent(value) { super.parent = value; } + + get variableDeclaration() { return this.ast.data.variableDeclaration?.node; } + set variableDeclaration(value) { this.ast.data.variableDeclaration = value?.ast; } + get block() { return this.ast.data.block?.node; } + set block(value) { this.ast.data.block = value?.ast; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstCatchClauseData extends AstData { + variableDeclaration: AstVariableDeclaration | undefined = undefined; + block: AstBlock = undefined!; + + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.variableDeclaration) | + propagateChildFlags(this.block) | + (!this.variableDeclaration ? TransformFlags.ContainsES2019 : TransformFlags.None); + } +} + +/** @internal */ +export type ObjectTypeDeclaration = + | ClassLikeDeclaration + | InterfaceDeclaration + | TypeLiteralNode; + +/** @internal */ +export type AstObjectTypeDeclaration = AstNodeOneOf; + +/** @internal */ +export type DeclarationWithTypeParameterChildren = + | SignatureDeclaration + | ClassLikeDeclaration + | InterfaceDeclaration + | TypeAliasDeclaration + | JSDocTemplateTag; + +/** @internal */ +export type AstDeclarationWithTypeParameterChildren = AstNodeOneOf; + +/** @internal */ +export type ClassElement = + | PropertyDeclaration + | MethodDeclaration + | ConstructorDeclaration + | SemicolonClassElement + | AccessorDeclaration + | IndexSignatureDeclaration + | ClassStaticBlockDeclaration + ; + +/** @internal */ +export type AstClassElement = AstNodeOneOf; + +/** @internal */ +export type ClassLikeDeclaration = + | ClassDeclaration + | ClassExpression; + +/** @internal */ +export type AstClassLikeDeclaration = AstNodeOneOf; + +/** @internal */ +export class ClassDeclaration extends Node implements JSDocContainer, Declaration, ts.ClassDeclaration { + declare readonly ast: AstClassDeclaration; + + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get heritageClauses() { return this.ast.data.heritageClauses?.nodes; } + set heritageClauses(value) { this.ast.data.heritageClauses = value?.ast; } + get members(): NodeArray { return this.ast.data.members?.nodes!; } // TODO: remove `!` + set members(value: NodeArray) { this.ast.data.members = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstClassDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + name: AstIdentifier | undefined = undefined; + typeParameters: AstNodeArray | undefined = undefined; + heritageClauses: AstNodeArray | undefined = undefined; + members: AstNodeArray | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + if (modifiersToFlags(this.modifiers?.items) & ModifierFlags.Ambient) { + return TransformFlags.ContainsTypeScript; + } + else { + let transformFlags = propagateChildrenFlags(this.modifiers) | + propagateNameFlags(this.name) | + propagateChildrenFlags(this.typeParameters) | + propagateChildrenFlags(this.heritageClauses) | + propagateChildrenFlags(this.members) | + (this.typeParameters ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + TransformFlags.ContainsES2015; + if (transformFlags & TransformFlags.ContainsTypeScriptClassSyntax) { + transformFlags |= TransformFlags.ContainsTypeScript; + } + return transformFlags; + } + } +} + +/** @internal */ +export class ClassExpression extends Node implements JSDocContainer, Declaration, ts.ClassExpression { + declare readonly ast: AstClassExpression; + + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get heritageClauses() { return this.ast.data.heritageClauses?.nodes; } + set heritageClauses(value) { this.ast.data.heritageClauses = value?.ast; } + get members() { return this.ast.data.members?.nodes!; } // TODO: remove `!` + set members(value) { this.ast.data.members = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstClassExpressionData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + name: AstIdentifier | undefined = undefined; + typeParameters: AstNodeArray | undefined = undefined; + heritageClauses: AstNodeArray | undefined = undefined; + members: AstNodeArray | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildrenFlags(this.modifiers) | + propagateNameFlags(this.name) | + propagateChildrenFlags(this.typeParameters) | + propagateChildrenFlags(this.heritageClauses) | + propagateChildrenFlags(this.members) | + (this.typeParameters ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + TransformFlags.ContainsES2015; + } +} + +/** @internal */ +export interface TypeElement extends Declaration { + readonly ast: AstTypeElement; + _typeElementBrand: any; +} + +/** @internal */ +export type AstTypeElement = AstNode; + +// type TypeElement = +// | CallSignatureDeclaration +// | ConstructSignatureDeclaration +// | MethodSignature +// | IndexSignatureDeclaration +// | PropertySignature +// | AccessorDeclaration +// ; + +/** @internal */ +export class InterfaceDeclaration extends Node implements JSDocContainer, Declaration, ts.InterfaceDeclaration { + declare readonly ast: AstInterfaceDeclaration; + + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get heritageClauses() { return this.ast.data.heritageClauses?.nodes; } + set heritageClauses(value) { this.ast.data.heritageClauses = value?.ast; } + get members() { return this.ast.data.members?.nodes!; } // TODO: remove '!' + set members(value) { this.ast.data.members = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstInterfaceDeclarationData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined = undefined; + name: AstIdentifier = undefined!; + typeParameters: AstNodeArray | undefined = undefined; + heritageClauses: AstNodeArray | undefined = undefined; + members: AstNodeArray | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) +} + +/** @internal */ +export class HeritageClause extends Node implements ts.HeritageClause { + declare readonly ast: AstHeritageClause; + + override get parent() { return super.parent as InterfaceDeclaration | ClassLikeDeclaration; } + override set parent(value) { super.parent = value; } + + get token() { return this.ast.data.token; } + set token(value) { this.ast.data.token = value; } + get types() { return this.ast.data.types?.nodes!; } // TODO: remove '!' + set types(value) { this.ast.data.types = value?.ast; } +} + +/** @internal */ +export class AstHeritageClauseData extends AstData { + token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword = undefined!; + types: AstNodeArray | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + switch (this.token) { + case SyntaxKind.ExtendsKeyword: + return propagateChildrenFlags(this.types) | TransformFlags.ContainsES2015; + case SyntaxKind.ImplementsKeyword: + return propagateChildrenFlags(this.types) | TransformFlags.ContainsTypeScript; + default: + return Debug.assertNever(this.token); + } + } +} + +/** @internal */ +export class TypeAliasDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.TypeAliasDeclaration { + declare readonly ast: AstTypeAliasDeclaration; + + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstTypeAliasDeclarationData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined = undefined; + name: AstIdentifier = undefined!; + typeParameters: AstNodeArray | undefined = undefined; + type: AstTypeNode = undefined!; + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class EnumDeclaration extends Node implements JSDocContainer, Declaration, ts.EnumDeclaration { + declare readonly ast: AstEnumDeclaration; + + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get members() { return this.ast.data.members?.nodes!; } // TODO: remove '!' + set members(value) { this.ast.data.members = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstEnumDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + name: AstIdentifier = undefined!; + members: AstNodeArray | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildrenFlags(this.modifiers) | + propagateChildFlags(this.name) | + propagateChildrenFlags(this.members) | + TransformFlags.ContainsTypeScript; + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Enum declarations cannot contain `await` + return transformFlags; + } +} + +/** @internal */ +export class EnumMember extends Node implements JSDocContainer, Declaration, ts.EnumMember { + declare readonly ast: AstEnumMember; + + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as EnumDeclaration; } + override set parent(value) { super.parent = value; } + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get initializer() { return this.ast.data.initializer?.node; } + set initializer(value) { this.ast.data.initializer = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstEnumMemberData extends AstData { + name: AstPropertyName = undefined!; + initializer: AstExpression | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.name) | + propagateChildFlags(this.initializer) | + TransformFlags.ContainsTypeScript; + } +} + +/** @internal */ +export type ModuleName = + | Identifier + | StringLiteral + ; + +/** @internal */ +export type AstModuleName = AstNodeOneOf; + +/** @internal */ +export type ModuleBody = + | NamespaceBody + | JSDocNamespaceBody + ; + +/** @internal */ +export type AstModuleBody = AstNodeOneOf; + +/** @internal */ +export class ModuleDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.ModuleDeclaration { + declare readonly ast: AstModuleDeclaration; + + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + + override get parent() { return super.parent as ModuleBlock | SourceFile; } + override set parent(value) { super.parent = value; } + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get body() { return this.ast.data.body?.node; } + set body(value) { this.ast.data.body = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstModuleDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + name: AstModuleName = undefined!; + body: AstModuleBody | AstJSDocNamespaceDeclaration | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + if (modifiersToFlags(this.modifiers?.items) & ModifierFlags.Ambient) { + return TransformFlags.ContainsTypeScript; + } + else { + let transformFlags = propagateChildrenFlags(this.modifiers) | + propagateChildFlags(this.name) | + propagateChildFlags(this.body) | + TransformFlags.ContainsTypeScript; + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Module declarations cannot contain `await`. + return transformFlags; + } + } +} + +/** @internal */ +export type NamespaceBody = + | ModuleBlock + | NamespaceDeclaration + ; + +/** @internal */ +export type AstNamespaceBody = AstNodeOneOf; + +/** @internal */ +export interface NamespaceDeclaration extends ModuleDeclaration { + readonly ast: AstNamespaceDeclaration; + readonly data: AstNamespaceDeclarationData; + readonly name: Identifier; + readonly body: NamespaceBody; +} + +/** @internal */ +export type AstNamespaceDeclaration = AstNode; + +/** @internal */ +export interface AstNamespaceDeclarationData extends AstModuleDeclarationData { + name: AstIdentifier; + body: AstNamespaceBody; +} + +/** @internal */ +export type JSDocNamespaceBody = + | Identifier + | JSDocNamespaceDeclaration + ; + +/** @internal */ +export type AstJSDocNamespaceBody = AstNodeOneOf; + +/** @internal */ +export interface JSDocNamespaceDeclaration extends ModuleDeclaration { + readonly ast: AstJSDocNamespaceDeclaration; + readonly data: AstJSDocNamespaceDeclarationData; + readonly name: Identifier; + readonly body: JSDocNamespaceBody | undefined; +} + +/** @internal */ +export type AstJSDocNamespaceDeclaration = AstNode; + +/** @internal */ +export interface AstJSDocNamespaceDeclarationData extends AstModuleDeclarationData { + name: AstIdentifier; + body: AstJSDocNamespaceBody | undefined; +} + +/** @internal */ +export class ModuleBlock extends Node implements JSDocContainer, ts.ModuleBlock { + declare readonly ast: AstModuleBlock; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as ModuleDeclaration; } + override set parent(value) { super.parent = value; } + + get statements() { return this.ast.data.statements?.nodes!; } // TODO: remove `!` + set statements(value) { this.ast.data.statements = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } +} + +/** @internal */ +export class AstModuleBlockData extends AstData { + statements: AstNodeArray | undefined = undefined; + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildrenFlags(this.statements); + } +} + +/** @internal */ +export type ModuleReference = + | EntityName + | ExternalModuleReference + ; + +/** @internal */ +export type AstModuleReference = AstNodeOneOf; + +/** @internal */ +export class ImportEqualsDeclaration extends Node implements JSDocContainer, Declaration, ts.ImportEqualsDeclaration { + declare readonly ast: AstImportEqualsDeclaration; + + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as ModuleBlock | SourceFile; } + override set parent(value) { super.parent = value; } + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get isTypeOnly() { return this.ast.data.isTypeOnly; } + set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } + get moduleReference() { return this.ast.data.moduleReference?.node; } + set moduleReference(value) { this.ast.data.moduleReference = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstImportEqualsDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + name: AstIdentifier = undefined!; + isTypeOnly: boolean = undefined!; + moduleReference: AstModuleReference = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildrenFlags(this.modifiers) | + propagateIdentifierNameFlags(this.name) | + propagateChildFlags(this.moduleReference); + + if (this.moduleReference.kind !== SyntaxKind.ExternalModuleReference) { + transformFlags |= TransformFlags.ContainsTypeScript; + } + + return transformFlags & ~TransformFlags.ContainsPossibleTopLevelAwait; // Import= declaration is always parsed in an Await context + } +} + +/** @internal */ +export class ExternalModuleReference extends Node implements ts.ExternalModuleReference { + declare readonly ast: AstExternalModuleReference; + + override get parent() { return super.parent as ImportEqualsDeclaration; } + override set parent(value) { super.parent = value; } + + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstExternalModuleReferenceData extends AstData { + expression: AstExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + // always parsed in an Await context + return propagateChildFlags(this.expression) & ~TransformFlags.ContainsPossibleTopLevelAwait; + } +} + +/** @internal */ +export class ImportDeclaration extends Node implements JSDocContainer, Declaration, ts.ImportDeclaration { + declare readonly ast: AstImportDeclaration; + + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as ModuleBlock | SourceFile; } + override set parent(value) { super.parent = value; } + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get importClause() { return this.ast.data.importClause?.node; } + set importClause(value) { this.ast.data.importClause = value?.ast; } + get moduleSpecifier() { return this.ast.data.moduleSpecifier?.node; } + set moduleSpecifier(value) { this.ast.data.moduleSpecifier = value?.ast; } + get attributes() { return this.ast.data.attributes?.node; } + set attributes(value) { this.ast.data.attributes = value?.ast; } + /** @deprecated */ + get assertClause() { return this.ast.data.attributes?.node; } + set assertClause(value) { this.ast.data.attributes = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstImportDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + importClause: AstImportClause | undefined = undefined; + moduleSpecifier: AstExpression = undefined!; + attributes: AstImportAttributes | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.importClause) | + propagateChildFlags(this.moduleSpecifier); + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context + return transformFlags; + } +} + +/** @internal */ +export type NamedImportBindings = + | NamespaceImport + | NamedImports + ; + +/** @internal */ +export type AstNamedImportBindings = AstNodeOneOf; + +/** @internal */ +export type NamedExportBindings = + | NamespaceExport + | NamedExports + ; + +/** @internal */ +export type AstNamedExportBindings = AstNodeOneOf; + +/** @internal */ +export class ImportClause extends Node implements Declaration, ts.ImportClause { + declare readonly ast: AstImportClause; + + declare _declarationBrand: any; + + override get parent() { return super.parent as ImportDeclaration | JSDocImportTag; } + override set parent(value) { super.parent = value; } + + get isTypeOnly() { return this.ast.data.isTypeOnly; } + set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get namedBindings() { return this.ast.data.namedBindings?.node; } + set namedBindings(value) { this.ast.data.namedBindings = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstImportClauseData extends AstData { + isTypeOnly: boolean = false; + name: AstIdentifier | undefined = undefined; + namedBindings: AstNamedImportBindings | undefined = undefined; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.name) | + propagateChildFlags(this.namedBindings); + if (this.isTypeOnly) { + transformFlags |= TransformFlags.ContainsTypeScript; + } + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context + return transformFlags; + } +} + +/** @internal */ +export type AssertionKey = + | Identifier + | StringLiteral + ; + +/** @internal */ +export type AstAssertionKey = AstNodeOneOf; + +/** + * @deprecated + * @internal + */ +export type AssertEntry = ImportAttribute; + +/** + * @deprecated + * @internal + */ +export type AstAssertEntry = AstImportAttribute; + +/** @internal */ +export type ImportAttributeName = + | Identifier + | StringLiteral; + +/** @internal */ +export type AstImportAttributeName = AstNodeOneOf; + +/** @internal */ +export class ImportAttribute extends Node implements ts.ImportAttribute { + declare readonly ast: AstImportAttribute; + + override get parent() { return super.parent as ImportAttributes; } + override set parent(value) { super.parent = value; } + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get value() { return this.ast.data.value?.node; } + set value(value) { this.ast.data.value = value?.ast; } +} + +/** @internal */ +export class AstImportAttributeData extends AstData { + name: AstImportAttributeName = undefined!; + value: AstExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.ContainsESNext; + } +} + +/** + * @deprecated + * @internal + */ +export type AssertClause = ImportAttributes; + +/** + * @deprecated + * @internal + */ +export type AstAssertClause = AstNode; + +/** @internal */ +export class ImportAttributes extends Node implements ts.ImportAttributes { + declare readonly ast: AstImportAttributes; + + override get parent() { return super.parent as ImportDeclaration | ExportDeclaration; } + override set parent(value) { super.parent = value; } + + get token() { return this.ast.data.token; } + set token(value) { this.ast.data.token = value; } + get elements() { return this.ast.data.elements?.nodes!; } // TODO: remove `!` + set elements(value) { this.ast.data.elements = value?.ast; } + get multiLine() { return this.ast.data.multiLine; } + set multiLine(value) { this.ast.data.multiLine = value; } +} + +/** @internal */ +export class AstImportAttributesData extends AstData { + token: SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword = undefined!; + elements: AstNodeArray | undefined = undefined; + multiLine: boolean | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.ContainsESNext; + } +} + +/** @internal */ +export class NamespaceImport extends Node implements Declaration, ts.NamespaceImport { + declare readonly ast: AstNamespaceImport; + + declare _declarationBrand: any; + + override get parent() { return super.parent as ImportClause; } + override set parent(value) { super.parent = value; } + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstNamespaceImportData extends AstData { + name: AstIdentifier = undefined!; + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.name); + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context + return transformFlags; + } +} + +/** @internal */ +export class NamespaceExport extends Node implements Declaration, ts.NamespaceExport { + declare readonly ast: AstNamespaceExport; + + declare _declarationBrand: any; + + override get parent() { return super.parent as ExportDeclaration; } + override set parent(value) { super.parent = value; } + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstNamespaceExportData extends AstData { + name: AstModuleExportName = undefined!; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.name) | + TransformFlags.ContainsES2020; + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context + return transformFlags; + } +} + +/** @internal */ +export class NamespaceExportDeclaration extends Node implements JSDocContainer, Declaration, ts.NamespaceExportDeclaration { + declare readonly ast: AstNamespaceExportDeclaration; + + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstNamespaceExportDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) + name: AstIdentifier = undefined!; + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateIdentifierNameFlags(this.name) | + TransformFlags.ContainsTypeScript; + } +} + +/** @internal */ +export class ExportDeclaration extends Node implements JSDocContainer, Declaration, ts.ExportDeclaration { + declare readonly ast: AstExportDeclaration; + + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as SourceFile | ModuleBlock; } + override set parent(value) { super.parent = value; } + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get isTypeOnly() { return this.ast.data.isTypeOnly; } + set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } + get exportClause() { return this.ast.data.exportClause?.node; } + set exportClause(value) { this.ast.data.exportClause = value?.ast; } + get moduleSpecifier() { return this.ast.data.moduleSpecifier?.node; } + set moduleSpecifier(value) { this.ast.data.moduleSpecifier = value?.ast; } + get attributes() { return this.ast.data.attributes?.node; } + set attributes(value) { this.ast.data.attributes = value?.ast; } + /** @deprecated */ + get assertClause() { return this.ast.data.attributes?.node; } + set assertClause(value) { this.ast.data.attributes = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstExportDeclarationData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + isTypeOnly = false; + exportClause: AstNamedExportBindings | undefined = undefined; + moduleSpecifier: AstExpression | undefined = undefined; + attributes: AstImportAttributes | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildrenFlags(this.modifiers) | + propagateChildFlags(this.exportClause) | + propagateChildFlags(this.moduleSpecifier); + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context + return transformFlags; + } +} + +/** @internal */ +export class NamedImports extends Node implements ts.NamedImports { + declare readonly ast: AstNamedImports; + + override get parent() { return super.parent as ImportClause; } + override set parent(value) { super.parent = value; } + + get elements() { return this.ast.data.elements.nodes; } + set elements(value) { this.ast.data.elements = value?.ast; } +} + +/** @internal */ +export class AstNamedImportsData extends AstData { + elements: AstNodeArray = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildrenFlags(this.elements); + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context + return transformFlags; + } +} + +/** @internal */ +export class NamedExports extends Node implements ts.NamedExports { + declare readonly ast: AstNamedExports; + + override get parent() { return super.parent as ExportDeclaration; } + override set parent(value) { super.parent = value; } + + get elements() { return this.ast.data.elements?.nodes!; } // TODO: remove '!' + set elements(value) { this.ast.data.elements = value?.ast; } +} + +/** @internal */ +export class AstNamedExportsData extends AstData { + elements: AstNodeArray | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildrenFlags(this.elements); + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context + return transformFlags; + } +} + +/** @internal */ +export class ImportSpecifier extends Node implements Declaration, ts.ImportSpecifier { + declare readonly ast: AstImportSpecifier; + + declare _declarationBrand: any; + + override get parent() { return super.parent as NamedImports; } + override set parent(value) { super.parent = value; } + + get propertyName() { return this.ast.data.propertyName?.node; } + set propertyName(value) { this.ast.data.propertyName = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get isTypeOnly() { return this.ast.data.isTypeOnly; } + set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstImportSpecifierData extends AstData { + propertyName: AstModuleExportName | undefined = undefined; + name: AstIdentifier = undefined!; + isTypeOnly = false; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.propertyName) | + propagateChildFlags(this.name); + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context + return transformFlags; + } +} + +/** @internal */ +export class ExportSpecifier extends Node implements Declaration, JSDocContainer, ts.ExportSpecifier { + declare readonly ast: AstExportSpecifier; + + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + + override get parent() { return super.parent as NamedExports; } + override set parent(value) { super.parent = value; } + + get isTypeOnly() { return this.ast.data.isTypeOnly; } + set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } + get propertyName() { return this.ast.data.propertyName?.node; } + set propertyName(value) { this.ast.data.propertyName = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstExportSpecifierData extends AstData { + isTypeOnly = false; + propertyName: AstModuleExportName | undefined = undefined; + name: AstModuleExportName = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.propertyName) | + propagateChildFlags(this.name); + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context + return transformFlags; + } +} + +/** @internal */ +export type ModuleExportName = + | Identifier + | StringLiteral; + +/** @internal */ +export type AstModuleExportName = AstNodeOneOf; + +/** @internal */ +export class ExportAssignment extends Node implements JSDocContainer, Declaration, ts.ExportAssignment { + declare readonly ast: AstExportAssignment; + + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare name: never; + + override get parent() { return super.parent as SourceFile; } + override set parent(value) { super.parent = value; } + + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get isExportEquals() { return this.ast.data.isExportEquals; } + set isExportEquals(value) { this.ast.data.isExportEquals = value; } + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstExportAssignmentData extends AstData { + modifiers: AstNodeArray | undefined = undefined; + isExportEquals: boolean | undefined = undefined; + expression: AstExpression = undefined!; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildrenFlags(this.modifiers) | propagateChildFlags(this.expression); + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context + return transformFlags; + } +} + +/** @internal */ +export class JSDocTypeExpression extends Node implements ts.JSDocTypeExpression { + declare readonly ast: AstJSDocTypeExpression; + + declare _typeNodeBrand: any; + + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } +} + +/** @internal */ +export class AstJSDocTypeExpressionData extends AstData { + type: AstTypeNode = undefined!; +} + +/** @internal */ +export class JSDocNameReference extends Node implements ts.JSDocNameReference { + declare readonly ast: AstJSDocNameReference; + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } +} + +/** @internal */ +export class AstJSDocNameReferenceData extends AstData { + name: AstEntityName | AstJSDocMemberName = undefined!; +} + +/** @internal */ +export class JSDocMemberName extends Node implements ts.JSDocMemberName { + declare readonly ast: AstJSDocMemberName; + + get left() { return this.ast.data.left?.node; } + set left(value) { this.ast.data.left = value?.ast; } + get right() { return this.ast.data.right?.node; } + set right(value) { this.ast.data.right = value?.ast; } +} + +/** @internal */ +export class AstJSDocMemberNameData extends AstData { + left: AstEntityName | AstJSDocMemberName = undefined!; + right: AstIdentifier = undefined!; +} + +/** @internal */ +export type JSDocType = + | JSDocAllType + | JSDocUnknownType + | JSDocNonNullableType + | JSDocNullableType + | JSDocOptionalType + | JSDocFunctionType + | JSDocVariadicType + | JSDocNamepathType; + +/** @internal */ +export type AstJSDocType = AstNodeOneOf; + +/** @internal */ +export class JSDocAllType extends Node implements ts.JSDocAllType { + declare readonly ast: AstJSDocAllType; + + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; +} + +/** @internal */ +export class AstJSDocAllTypeData extends AstData { +} + +/** @internal */ +export class JSDocUnknownType extends Node implements ts.JSDocUnknownType { + declare readonly ast: AstJSDocUnknownType; + + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; +} + +/** @internal */ +export class AstJSDocUnknownTypeData extends AstData { +} + +/** @internal */ +export class JSDocNonNullableType extends Node implements ts.JSDocNonNullableType { + declare readonly ast: AstJSDocNonNullableType; + + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get postfix() { return this.ast.data.postfix; } + set postfix(value) { this.ast.data.postfix = value; } +} + +/** @internal */ +export class AstJSDocNonNullableTypeData extends AstData { + type: AstTypeNode = undefined!; + postfix = false; +} + +/** @internal */ +export class JSDocNullableType extends Node implements ts.JSDocNullableType { + declare readonly ast: AstJSDocNullableType; + + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get postfix() { return this.ast.data.postfix; } + set postfix(value) { this.ast.data.postfix = value; } +} + +/** @internal */ +export class AstJSDocNullableTypeData extends AstData { + type: AstTypeNode = undefined!; + postfix = false; +} + +/** @internal */ +export class JSDocOptionalType extends Node implements ts.JSDocOptionalType { + declare readonly ast: AstJSDocOptionalType; + + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } +} + +/** @internal */ +export class AstJSDocOptionalTypeData extends AstData { + type: AstTypeNode = undefined!; +} + +/** @internal */ +export class JSDocFunctionType extends Node implements Declaration, LocalsContainer, ts.JSDocFunctionType { + declare readonly ast: AstJSDocFunctionType; + + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare name: never; + + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstJSDocFunctionTypeData extends AstData { + typeParameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray | undefined = undefined; + type: AstTypeNode | undefined = undefined; + typeArguments: AstNodeArray | undefined = undefined; // quick info + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class JSDocVariadicType extends Node implements ts.JSDocVariadicType { + declare readonly ast: AstJSDocVariadicType; + + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } +} + +/** @internal */ +export class AstJSDocVariadicTypeData extends AstData { + type: AstTypeNode = undefined!; +} + +/** @internal */ +export class JSDocNamepathType extends Node implements ts.JSDocNamepathType { + declare readonly ast: AstJSDocNamepathType; + + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } +} + +/** @internal */ +export class AstJSDocNamepathTypeData extends AstData { + type: AstTypeNode = undefined!; +} + +/** @internal */ +export class JSDocNode extends Node implements ts.JSDoc { + declare readonly ast: AstJSDocNode; + + override get parent() { return super.parent as HasJSDoc; } + override set parent(value) { super.parent = value; } + + get tags() { return this.ast.data.tags?.nodes; } + set tags(value) { this.ast.data.tags = value?.ast; } + get comment() { + const comment = this.ast.data.comment; + return typeof comment === "string" ? comment : comment?.nodes; + } + set comment(value) { this.ast.data.comment = typeof value === "string" ? value : value?.ast; } +} + +/** @internal */ +export class AstJSDocNodeData extends AstData { + comment: string | AstNodeArray | undefined = undefined; + tags: AstNodeArray | undefined = undefined; +} + +/** @internal */ +export type HasJSDoc = + | AccessorDeclaration + | ArrowFunction + | BinaryExpression + | Block + | BreakStatement + | CallSignatureDeclaration + | CaseClause + | ClassLikeDeclaration + | ClassStaticBlockDeclaration + | ConstructorDeclaration + | ConstructorTypeNode + | ConstructSignatureDeclaration + | ContinueStatement + | DebuggerStatement + | DoStatement + | ElementAccessExpression + | EmptyStatement + | EndOfFileToken + | EnumDeclaration + | EnumMember + | ExportAssignment + | ExportDeclaration + | ExportSpecifier + | ExpressionStatement + | ForInStatement + | ForOfStatement + | ForStatement + | FunctionDeclaration + | FunctionExpression + | FunctionTypeNode + | Identifier + | IfStatement + | ImportDeclaration + | ImportEqualsDeclaration + | IndexSignatureDeclaration + | InterfaceDeclaration + | JSDocFunctionType + | JSDocSignature + | LabeledStatement + | MethodDeclaration + | MethodSignature + | ModuleDeclaration + | NamedTupleMember + | NamespaceExportDeclaration + | ObjectLiteralExpression + | ParameterDeclaration + | ParenthesizedExpression + | PropertyAccessExpression + | PropertyAssignment + | PropertyDeclaration + | PropertySignature + | ReturnStatement + | SemicolonClassElement + | ShorthandPropertyAssignment + | SpreadAssignment + | SwitchStatement + | ThrowStatement + | TryStatement + | TypeAliasDeclaration + | TypeParameterDeclaration + | VariableDeclaration + | VariableStatement + | WhileStatement + | WithStatement; + +/** @internal */ +export type AstHasJSDoc = AstNodeOneOf; + +/** @internal */ +export type JSDocTag = + | JSDocUnknownTag + | JSDocAugmentsTag + | JSDocImplementsTag + | JSDocAuthorTag + | JSDocDeprecatedTag + | JSDocClassTag + | JSDocPublicTag + | JSDocPrivateTag + | JSDocProtectedTag + | JSDocReadonlyTag + | JSDocOverrideTag + | JSDocEnumTag + | JSDocThisTag + | JSDocTemplateTag + | JSDocSeeTag + | JSDocReturnTag + | JSDocTypeTag + | JSDocTypedefTag + | JSDocCallbackTag + | JSDocOverloadTag + | JSDocThrowsTag + | JSDocPropertyTag + | JSDocParameterTag + | JSDocSatisfiesTag + | JSDocImportTag + ; + +/** @internal */ +export type AstJSDocTag = AstNodeOneOf; + +/** @internal */ +export class JSDocLink extends Node implements ts.JSDocLink { + declare readonly ast: AstJSDocLink; + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } +} + +/** @internal */ +export class AstJSDocLinkData extends AstData { + name: AstEntityName | AstJSDocMemberName | undefined = undefined; + text = ""; +} + +/** @internal */ +export class JSDocLinkCode extends Node implements ts.JSDocLinkCode { + declare readonly ast: AstJSDocLinkCode; + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } +} + +/** @internal */ +export class AstJSDocLinkCodeData extends AstData { + name: AstEntityName | AstJSDocMemberName | undefined = undefined; + text = ""; +} + +/** @internal */ +export class JSDocLinkPlain extends Node implements ts.JSDocLinkPlain { + declare readonly ast: AstJSDocLinkPlain; + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } +} + +/** @internal */ +export class AstJSDocLinkPlainData extends AstData { + name: AstEntityName | AstJSDocMemberName | undefined = undefined; + text = ""; +} + +/** @internal */ +export type JSDocComment = + | JSDocText + | JSDocLink + | JSDocLinkCode + | JSDocLinkPlain + ; + +/** @internal */ +export type AstJSDocComment = AstNodeOneOf; + +/** @internal */ +export class JSDocText extends Node implements ts.JSDocText { + declare readonly ast: AstJSDocText; + + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } +} + +/** @internal */ +export class AstJSDocTextData extends AstData { + text = ""; +} + +/** @internal */ +export class BaseJSDocTag extends Node implements ts.JSDocTag { + declare readonly ast: AstBaseJSDocTag; + + override get parent() { return super.parent as JSDocNode | JSDocTypeLiteral; } + override set parent(value) { super.parent = value; } + + get tagName() { return this.ast.data.tagName?.node; } + set tagName(value) { this.ast.data.tagName = value?.ast; } + get comment() { + const comment = this.ast.data.comment; + return typeof comment === "string" ? comment : comment?.nodes; + } + set comment(value) { this.ast.data.comment = typeof value === "string" ? value : value?.ast; } +} + +/** @internal */ +export type AstBaseJSDocTag = AstNode>; + +/** @internal */ +export class AstJSDocTagData extends AstData { + tagName: AstIdentifier = undefined!; + comment: string | AstNodeArray | undefined = undefined; + + override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.None; + } +} + +/** @internal */ +export class JSDocUnknownTag extends BaseJSDocTag implements ts.JSDocUnknownTag { + declare readonly ast: AstJSDocUnknownTag; +} + +/** @internal */ +export class AstJSDocUnknownTagData extends AstJSDocTagData { +} + +/** @internal */ +export interface JSDocClassReference extends ExpressionWithTypeArguments { + readonly ast: AstJSDocClassReference; + readonly data: AstJSDocClassReferenceData; + readonly expression: Identifier | PropertyAccessEntityNameExpression; +} + +/** @internal */ +export type AstJSDocClassReference = AstNode; + +/** @internal */ +export interface AstJSDocClassReferenceData extends AstExpressionWithTypeArgumentsData { + expression: AstIdentifier | AstPropertyAccessEntityNameExpression; +} + +/** @internal */ +export class JSDocAugmentsTag extends BaseJSDocTag implements ts.JSDocAugmentsTag { + declare readonly ast: AstJSDocAugmentsTag; + get class() { return this.ast.data.class.node; } + set class(value) { this.ast.data.class = value.ast; } +} + +/** @internal */ +export class AstJSDocAugmentsTagData extends AstJSDocTagData { + class: AstJSDocClassReference = undefined!; +} + +/** @internal */ +export class JSDocImplementsTag extends BaseJSDocTag implements ts.JSDocImplementsTag { + declare readonly ast: AstJSDocImplementsTag; + get class() { return this.ast.data.class.node; } + set class(value) { this.ast.data.class = value.ast; } +} + +/** @internal */ +export class AstJSDocImplementsTagData extends AstJSDocTagData { + class: AstJSDocClassReference = undefined!; +} + +/** @internal */ +export class JSDocAuthorTag extends BaseJSDocTag implements ts.JSDocAuthorTag { + declare readonly ast: AstJSDocAuthorTag; +} + +/** @internal */ +export class AstJSDocAuthorTagData extends AstJSDocTagData { +} + +/** @internal */ +export class JSDocDeprecatedTag extends BaseJSDocTag implements ts.JSDocDeprecatedTag { + declare readonly ast: AstJSDocDeprecatedTag; +} + +/** @internal */ +export class AstJSDocDeprecatedTagData extends AstJSDocTagData { +} + +/** @internal */ +export class JSDocClassTag extends BaseJSDocTag implements ts.JSDocClassTag { + declare readonly ast: AstJSDocClassTag; +} + +/** @internal */ +export class AstJSDocClassTagData extends AstJSDocTagData { +} + +/** @internal */ +export class JSDocPublicTag extends BaseJSDocTag implements ts.JSDocPublicTag { + declare readonly ast: AstJSDocPublicTag; +} + +/** @internal */ +export class AstJSDocPublicTagData extends AstJSDocTagData { +} + +/** @internal */ +export class JSDocPrivateTag extends BaseJSDocTag implements ts.JSDocPrivateTag { + declare readonly ast: AstJSDocPrivateTag; +} + +/** @internal */ +export class AstJSDocPrivateTagData extends AstJSDocTagData { +} + +/** @internal */ +export class JSDocProtectedTag extends BaseJSDocTag implements ts.JSDocProtectedTag { + declare readonly ast: AstJSDocProtectedTag; +} + +/** @internal */ +export class AstJSDocProtectedTagData extends AstJSDocTagData { +} + +/** @internal */ +export class JSDocReadonlyTag extends BaseJSDocTag implements ts.JSDocReadonlyTag { + declare readonly ast: AstJSDocReadonlyTag; +} + +/** @internal */ +export class AstJSDocReadonlyTagData extends AstJSDocTagData { +} + +/** @internal */ +export class JSDocOverrideTag extends BaseJSDocTag implements ts.JSDocOverrideTag { + declare readonly ast: AstJSDocOverrideTag; +} + +/** @internal */ +export class AstJSDocOverrideTagData extends AstJSDocTagData { +} + +/** @internal */ +export class JSDocEnumTag extends BaseJSDocTag implements Declaration, LocalsContainer, ts.JSDocEnumTag { + declare readonly ast: AstJSDocEnumTag; + declare _declarationBrand: any; + declare _localsContainerBrand: any; + + override get parent() { return super.parent as JSDocNode; } + override set parent(value) { super.parent = value; } + + get typeExpression() { return this.ast.data.typeExpression?.node; } + set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstJSDocEnumTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression = undefined!; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class JSDocThisTag extends BaseJSDocTag implements ts.JSDocThisTag { + declare readonly ast: AstJSDocThisTag; + get typeExpression() { return this.ast.data.typeExpression?.node; } + set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } +} + +/** @internal */ +export class AstJSDocThisTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression = undefined!; +} + +/** @internal */ +export class JSDocTemplateTag extends BaseJSDocTag implements ts.JSDocTemplateTag { + declare readonly ast: AstJSDocTemplateTag; + get constraint() { return this.ast.data.constraint?.node; } + set constraint(value) { this.ast.data.constraint = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes!; } // TODO: remove `!` + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } +} + +/** @internal */ +export class AstJSDocTemplateTagData extends AstJSDocTagData { + constraint: AstJSDocTypeExpression | undefined = undefined; + typeParameters: AstNodeArray | undefined = undefined; +} + +/** @internal */ +export class JSDocSeeTag extends BaseJSDocTag implements ts.JSDocSeeTag { + declare readonly ast: AstJSDocSeeTag; + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } +} + +/** @internal */ +export class AstJSDocSeeTagData extends AstJSDocTagData { + name: AstJSDocNameReference | undefined = undefined; +} + +/** @internal */ +export class JSDocReturnTag extends BaseJSDocTag implements ts.JSDocReturnTag { + declare readonly ast: AstJSDocReturnTag; + get typeExpression() { return this.ast.data.typeExpression?.node; } + set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } +} + +/** @internal */ +export class AstJSDocReturnTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression | undefined = undefined; +} + +/** @internal */ +export class JSDocTypeTag extends BaseJSDocTag implements ts.JSDocTypeTag { + declare readonly ast: AstJSDocTypeTag; + get typeExpression() { return this.ast.data.typeExpression?.node; } + set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } +} + +/** @internal */ +export class AstJSDocTypeTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression = undefined!; +} + +/** @internal */ +export class JSDocTypedefTag extends BaseJSDocTag implements Declaration, LocalsContainer, ts.JSDocTypedefTag { + declare readonly ast: AstJSDocTypedefTag; + declare _declarationBrand: any; + declare _localsContainerBrand: any; + + override get parent() { return super.parent as JSDocNode; } + override set parent(value) { super.parent = value; } + + get fullName() { return this.ast.data.fullName?.node; } + set fullName(value) { this.ast.data.fullName = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get typeExpression() { return this.ast.data.typeExpression?.node; } + set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstJSDocTypedefTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression | AstJSDocTypeLiteral | undefined = undefined; + fullName: AstJSDocNamespaceDeclaration | AstIdentifier | undefined = undefined; + name: AstIdentifier | undefined = undefined; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class JSDocCallbackTag extends BaseJSDocTag implements Declaration, LocalsContainer, ts.JSDocCallbackTag { + declare readonly ast: AstJSDocCallbackTag; + declare _declarationBrand: any; + declare _localsContainerBrand: any; + + override get parent() { return super.parent as JSDocNode; } + override set parent(value) { super.parent = value; } + + get fullName() { return this.ast.data.fullName?.node; } + set fullName(value) { this.ast.data.fullName = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get typeExpression() { return this.ast.data.typeExpression?.node; } + set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstJSDocCallbackTagData extends AstJSDocTagData { + fullName: AstJSDocNamespaceDeclaration | AstIdentifier | undefined = undefined; + name: AstIdentifier | undefined = undefined; + typeExpression: AstJSDocSignature = undefined!; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class JSDocOverloadTag extends BaseJSDocTag implements ts.JSDocOverloadTag { + declare readonly ast: AstJSDocOverloadTag; + + override get parent() { return super.parent as JSDocNode; } + override set parent(value) { super.parent = value; } + + get typeExpression() { return this.ast.data.typeExpression?.node; } + set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } +} + +/** @internal */ +export class AstJSDocOverloadTagData extends AstJSDocTagData { + typeExpression: AstJSDocSignature = undefined!; +} + +/** @internal */ +export class JSDocThrowsTag extends BaseJSDocTag implements ts.JSDocThrowsTag { + declare readonly ast: AstJSDocThrowsTag; + get typeExpression() { return this.ast.data.typeExpression?.node; } + set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } +} + +/** @internal */ +export class AstJSDocThrowsTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression | undefined = undefined; +} + +/** @internal */ +export class JSDocSignature extends Node implements Declaration, LocalsContainer, ts.JSDocSignature { + declare readonly ast: AstJSDocSignature; + + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters.nodes; } + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { return this.ast.data.type?.node; } + set type(value) { this.ast.data.type = value?.ast; } + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value) { this.ast.data.jsDoc = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } +} + +/** @internal */ +export class AstJSDocSignatureData extends AstData { + typeParameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; + type: AstJSDocReturnTag | undefined = undefined; + + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; +} + +/** @internal */ +export class JSDocPropertyTag extends BaseJSDocTag implements Declaration, ts.JSDocPropertyTag { + declare readonly ast: AstJSDocPropertyTag; + declare _declarationBrand: any; + + override get parent() { return super.parent as JSDocNode; } + override set parent(value) { super.parent = value; } + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get typeExpression() { return this.ast.data.typeExpression?.node; } + set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + get isNameFirst() { return this.ast.data.isNameFirst; } + set isNameFirst(value) { this.ast.data.isNameFirst = value; } + get isBracketed() { return this.ast.data.isBracketed; } + set isBracketed(value) { this.ast.data.isBracketed = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstJSDocPropertyTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression | undefined = undefined; + name: AstEntityName = undefined!; + isNameFirst = false; + isBracketed = false; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) +} + +/** @internal */ +export class JSDocParameterTag extends BaseJSDocTag implements Declaration, ts.JSDocParameterTag { + declare readonly ast: AstJSDocParameterTag; + declare _declarationBrand: any; + + override get parent() { return super.parent as JSDocNode; } + override set parent(value) { super.parent = value; } + + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get typeExpression() { return this.ast.data.typeExpression?.node; } + set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + get isNameFirst() { return this.ast.data.isNameFirst; } + set isNameFirst(value) { this.ast.data.isNameFirst = value; } + get isBracketed() { return this.ast.data.isBracketed; } + set isBracketed(value) { this.ast.data.isBracketed = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstJSDocParameterTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression | undefined = undefined; + name: AstEntityName = undefined!; + isNameFirst = false; + isBracketed = false; + + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) +} + +/** @internal */ +export type JSDocPropertyLikeTag = + | JSDocPropertyTag + | JSDocParameterTag + ; + +/** @internal */ +export type AstJSDocPropertyLikeTag = AstNodeOneOf; + +/** @internal */ +export class JSDocTypeLiteral extends Node implements Declaration, ts.JSDocTypeLiteral { + declare readonly ast: AstJSDocTypeLiteral; + + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare _declarationBrand: any; + + get jsDocPropertyTags() { return this.ast.data.jsDocPropertyTags?.nodes; } + set jsDocPropertyTags(value) { this.ast.data.jsDocPropertyTags = value?.ast; } + get isArrayType() { return this.ast.data.isArrayType; } + set isArrayType(value) { this.ast.data.isArrayType = value; } + get symbol() { return this.ast.data.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstJSDocTypeLiteralData extends AstData { + jsDocPropertyTags: AstNodeArray | undefined = undefined; + isArrayType = false; + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) +} + +/** @internal */ +export class JSDocSatisfiesTag extends BaseJSDocTag implements ts.JSDocSatisfiesTag { + declare readonly ast: AstJSDocSatisfiesTag; + get typeExpression() { return this.ast.data.typeExpression?.node; } + set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } +} + +/** @internal */ +export class AstJSDocSatisfiesTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression = undefined!; +} + +/** @internal */ +export class JSDocImportTag extends BaseJSDocTag implements ts.JSDocImportTag { + declare readonly ast: AstJSDocImportTag; + + override get parent() { return super.parent as JSDocNode; } + override set parent(value) { super.parent = value; } + + get importClause() { return this.ast.data.importClause?.node; } + set importClause(value) { this.ast.data.importClause = value?.ast; } + get moduleSpecifier() { return this.ast.data.moduleSpecifier?.node; } + set moduleSpecifier(value) { this.ast.data.moduleSpecifier = value?.ast; } + get attributes() { return this.ast.data.attributes?.node; } + set attributes(value) { this.ast.data.attributes = value?.ast; } +} + +/** @internal */ +export class AstJSDocImportTagData extends AstJSDocTagData { + importClause: AstImportClause | undefined = undefined; + moduleSpecifier: AstExpression = undefined!; + attributes: AstImportAttributes | undefined = undefined; +} + +/** @internal */ +export class SyntheticExpression extends Node implements ts.SyntheticExpression { + declare readonly ast: AstSyntheticExpression; + declare _expressionBrand: any; + + get isSpread(): boolean { return this.ast.data.isSpread; } + set isSpread(value: boolean) { this.ast.data.isSpread = value; } + get type(): ts.Type { return this.ast.data.type; } + set type(value: ts.Type) { this.ast.data.type = value; } + get tupleNameSource(): ParameterDeclaration | NamedTupleMember | undefined { return this.ast.data.tupleNameSource?.node; } + set tupleNameSource(value: ParameterDeclaration | NamedTupleMember | undefined) { this.ast.data.tupleNameSource = value?.ast; } +} + +/** @internal */ +export class AstSyntheticExpressionData extends AstData { + isSpread = false; + type: Type = undefined!; + tupleNameSource: AstParameterDeclaration | AstNamedTupleMember | undefined = undefined; +} + +/** @internal */ +export class Bundle extends Node implements ts.Bundle { + declare readonly ast: AstBundle; + + get sourceFiles(): readonly SourceFile[] { return this.ast.data.sourceFiles; } + set sourceFiles(value: readonly SourceFile[]) { this.ast.data.sourceFiles = value; } + get syntheticFileReferences(): readonly FileReference[] | undefined { return this.ast.data.syntheticFileReferences; } + set syntheticFileReferences(value: readonly FileReference[] | undefined) { this.ast.data.syntheticFileReferences = value; } + get syntheticTypeReferences(): readonly FileReference[] | undefined { return this.ast.data.syntheticTypeReferences; } + set syntheticTypeReferences(value: readonly FileReference[] | undefined) { this.ast.data.syntheticTypeReferences = value; } + get syntheticLibReferences(): readonly FileReference[] | undefined { return this.ast.data.syntheticLibReferences; } + set syntheticLibReferences(value: readonly FileReference[] | undefined) { this.ast.data.syntheticLibReferences = value; } + get hasNoDefaultLib(): boolean | undefined { return this.ast.data.hasNoDefaultLib; } + set hasNoDefaultLib(value: boolean | undefined) { this.ast.data.hasNoDefaultLib = value; } +} + +/** @internal */ +export class AstBundleData extends AstData { + sourceFiles: readonly SourceFile[] = undefined!; + syntheticFileReferences?: readonly FileReference[]; + syntheticTypeReferences?: readonly FileReference[]; + syntheticLibReferences?: readonly FileReference[]; + hasNoDefaultLib?: boolean; +} + +/** @internal */ +export class SyntaxList extends Node implements ts.SyntaxList { + get _children(): readonly Node[] { return this.ast.data._children; } + set _children(value: readonly Node[]) { this.ast.data._children = value; } +} + +/** @internal */ +export class AstSyntaxListData extends AstData { + _children!: readonly Node[]; +} + +/** @internal */ +export class NotEmittedStatement extends Node implements ts.NotEmittedStatement { + declare readonly ast: AstNotEmittedStatement; + + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + + get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } +} + +/** @internal */ +export class AstNotEmittedStatementData extends AstData { + jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) +} + +/** @internal */ +export class NotEmittedTypeElement extends Node implements ts.NotEmittedTypeElement { + declare readonly ast: AstNotEmittedTypeElement; + + declare _typeElementBrand: any; + declare _declarationBrand: any; + + get name(): PropertyName | undefined { return this.ast.data.name?.node; } + set name(value: PropertyName | undefined) { this.ast.data.name = value?.ast; } + get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } + set questionToken(value: QuestionToken | undefined) { this.ast.data.questionToken = value?.ast; } + get symbol(): Symbol { return this.ast.data.symbol; } + set symbol(value: Symbol) { this.ast.data.symbol = value; } + get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + set localSymbol(value: Symbol | undefined) { this.ast.data.localSymbol = value; } +} + +/** @internal */ +export class AstNotEmittedTypeElementData extends AstData { + name: AstPropertyName | undefined = undefined; + questionToken: AstQuestionToken | undefined = undefined; + symbol: Symbol = undefined!; + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) +} + +/** @internal */ +export class PartiallyEmittedExpression extends Node implements ts.PartiallyEmittedExpression { + declare readonly ast: AstPartiallyEmittedExpression; + + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get expression(): Expression { return this.ast.data.expression?.node; } + set expression(value: Expression) { this.ast.data.expression = value?.ast; } +} + +/** @internal */ +export class AstPartiallyEmittedExpressionData extends AstData { + expression: AstExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression); + } +} + +/** @internal */ +export class CommaListExpression extends Node implements ts.CommaListExpression { + declare readonly ast: AstCommaListExpression; + + declare _expressionBrand: any; + + get elements(): NodeArray { return this.ast.data.elements.nodes; } + set elements(value: NodeArray) { this.ast.data.elements = value?.ast; } +} + +/** @internal */ +export class AstCommaListExpressionData extends AstData { + elements: AstNodeArray = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildrenFlags(this.elements); + } +} + +/** @internal */ +export class SyntheticReferenceExpression extends Node implements ts.SyntheticReferenceExpression { + declare readonly ast: AstSyntheticReferenceExpression; + + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + + get expression(): Expression { return this.ast.data.expression?.node; } + set expression(value: Expression) { this.ast.data.expression = value?.ast; } + get thisArg(): Expression { return this.ast.data.thisArg?.node; } + set thisArg(value: Expression) { this.ast.data.thisArg = value?.ast; } +} + +/** @internal */ +export class AstSyntheticReferenceExpressionData extends AstData { + expression: AstExpression = undefined!; + thisArg: AstExpression = undefined!; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression) | + propagateChildFlags(this.thisArg); + } +} + +/** @internal */ +export class SourceFile extends Node implements Declaration, LocalsContainer, ts.SourceFile { + declare readonly ast: AstSourceFile; + + declare _declarationBrand: any; + declare _localsContainerBrand: any; + + get statements() { return this.ast.data.statements?.nodes!; } // TODO: remove `!` + set statements(value) { this.ast.data.statements = value?.ast; } + get endOfFileToken() { return this.ast.data.endOfFileToken?.node; } + set endOfFileToken(value) { this.ast.data.endOfFileToken = value?.ast; } + get fileName() { return this.ast.data.fileName; } + set fileName(value) { this.ast.data.fileName = value; } + + get path() { return this.ast.data.path; } + set path(value) { this.ast.data.path = value; } + get text() { return this.ast.data.text; } + set text(value) { this.ast.data.text = value; } + get resolvedPath() { return this.ast.data.resolvedPath; } + set resolvedPath(value) { this.ast.data.resolvedPath = value; } + get originalFileName() { return this.ast.data.originalFileName; } + set originalFileName(value) { this.ast.data.originalFileName = value; } + get amdDependencies() { return this.ast.data.amdDependencies; } + set amdDependencies(value) { this.ast.data.amdDependencies = value; } + get moduleName() { return this.ast.data.moduleName; } + set moduleName(value) { this.ast.data.moduleName = value; } + get referencedFiles() { return this.ast.data.referencedFiles; } + set referencedFiles(value) { this.ast.data.referencedFiles = value; } + get typeReferenceDirectives() { return this.ast.data.typeReferenceDirectives; } + set typeReferenceDirectives(value) { this.ast.data.typeReferenceDirectives = value; } + get libReferenceDirectives() { return this.ast.data.libReferenceDirectives; } + set libReferenceDirectives(value) { this.ast.data.libReferenceDirectives = value; } + get languageVariant() { return this.ast.data.languageVariant; } + set languageVariant(value) { this.ast.data.languageVariant = value; } + get isDeclarationFile() { return this.ast.data.isDeclarationFile; } + set isDeclarationFile(value) { this.ast.data.isDeclarationFile = value; } + get renamedDependencies() { return this.ast.data.renamedDependencies; } + set renamedDependencies(value) { this.ast.data.renamedDependencies = value; } + get hasNoDefaultLib() { return this.ast.data.hasNoDefaultLib; } + set hasNoDefaultLib(value) { this.ast.data.hasNoDefaultLib = value; } + get languageVersion() { return this.ast.data.languageVersion; } + set languageVersion(value) { this.ast.data.languageVersion = value; } + get impliedNodeFormat() { return this.ast.data.impliedNodeFormat; } + set impliedNodeFormat(value) { this.ast.data.impliedNodeFormat = value; } + get scriptKind() { return this.ast.data.scriptKind; } + set scriptKind(value) { this.ast.data.scriptKind = value; } + get pragmas() { return this.ast.data.pragmas; } + set pragmas(value) { this.ast.data.pragmas = value; } + get externalModuleIndicator() { return this.ast.data.externalModuleIndicator; } + set externalModuleIndicator(value) { this.ast.data.externalModuleIndicator = value; } + get commonJsModuleIndicator() { return this.ast.data.commonJsModuleIndicator; } + set commonJsModuleIndicator(value) { this.ast.data.commonJsModuleIndicator = value; } + get identifiers() { return this.ast.data.identifiers; } + set identifiers(value) { this.ast.data.identifiers = value; } + get parseDiagnostics() { return this.ast.data.parseDiagnostics; } + set parseDiagnostics(value) { this.ast.data.parseDiagnostics = value; } + get bindDiagnostics() { return this.ast.data.bindDiagnostics; } + set bindDiagnostics(value) { this.ast.data.bindDiagnostics = value; } + get bindSuggestionDiagnostics() { return this.ast.data.bindSuggestionDiagnostics; } + set bindSuggestionDiagnostics(value) { this.ast.data.bindSuggestionDiagnostics = value; } + get lineMap() { return this.ast.data.lineMap; } + set lineMap(value) { this.ast.data.lineMap = value; } + get jsDocDiagnostics() { return this.ast.data.jsDocDiagnostics; } + set jsDocDiagnostics(value) { this.ast.data.jsDocDiagnostics = value; } + get commentDirectives() { return this.ast.data.commentDirectives; } + set commentDirectives(value) { this.ast.data.commentDirectives = value; } + get checkJsDirective() { return this.ast.data.checkJsDirective; } + set checkJsDirective(value) { this.ast.data.checkJsDirective = value; } + get version() { return this.ast.data.version; } + set version(value) { this.ast.data.version = value; } + + get symbol() { return this.ast.data.declaration.symbol!; } // TODO: remove `!` + set symbol(value) { this.ast.data.declaration.symbol = value; } + get localSymbol() { return this.ast.data.declaration.localSymbol; } + set localSymbol(value) { this.ast.data.declaration.localSymbol = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get redirectInfo() { return this.ast.data.redirectInfo; } + set redirectInfo(value) { this.ast.data.redirectInfo = value; } + get packageJsonLocations() { return this.ast.data.packageJsonLocations; } + set packageJsonLocations(value) { this.ast.data.packageJsonLocations = value; } + get packageJsonScope() { return this.ast.data.packageJsonScope; } + set packageJsonScope(value) { this.ast.data.packageJsonScope = value; } + get setExternalModuleIndicator() { return this.ast.data.setExternalModuleIndicator; } + set setExternalModuleIndicator(value) { this.ast.data.setExternalModuleIndicator = value; } + get jsGlobalAugmentations() { return this.ast.data.jsGlobalAugmentations; } + set jsGlobalAugmentations(value) { this.ast.data.jsGlobalAugmentations = value; } + get nodeCount() { return this.ast.data.nodeCount; } + set nodeCount(value) { this.ast.data.nodeCount = value; } + get identifierCount() { return this.ast.data.identifierCount; } + set identifierCount(value) { this.ast.data.identifierCount = value; } + get symbolCount() { return this.ast.data.symbolCount; } + set symbolCount(value) { this.ast.data.symbolCount = value; } + get additionalSyntacticDiagnostics() { return this.ast.data.additionalSyntacticDiagnostics; } + set additionalSyntacticDiagnostics(value) { this.ast.data.additionalSyntacticDiagnostics = value; } + get classifiableNames() { return this.ast.data.classifiableNames; } + set classifiableNames(value) { this.ast.data.classifiableNames = value; } + get imports() { return this.ast.data.imports; } + set imports(value) { this.ast.data.imports = value; } + get moduleAugmentations() { return this.ast.data.moduleAugmentations; } + set moduleAugmentations(value) { this.ast.data.moduleAugmentations = value; } + get patternAmbientModules() { return this.ast.data.patternAmbientModules; } + set patternAmbientModules(value) { this.ast.data.patternAmbientModules = value; } + get ambientModuleNames() { return this.ast.data.ambientModuleNames; } + set ambientModuleNames(value) { this.ast.data.ambientModuleNames = value; } + get localJsxNamespace() { return this.ast.data.localJsxNamespace; } + set localJsxNamespace(value) { this.ast.data.localJsxNamespace = value; } + get localJsxFragmentNamespace() { return this.ast.data.localJsxFragmentNamespace; } + set localJsxFragmentNamespace(value) { this.ast.data.localJsxFragmentNamespace = value; } + get localJsxFactory() { return this.ast.data.localJsxFactory; } + set localJsxFactory(value) { this.ast.data.localJsxFactory = value; } + get localJsxFragmentFactory() { return this.ast.data.localJsxFragmentFactory; } + set localJsxFragmentFactory(value) { this.ast.data.localJsxFragmentFactory = value; } + get endFlowNode() { return this.ast.data.endFlowNode; } + set endFlowNode(value) { this.ast.data.endFlowNode = value; } + get jsDocParsingMode() { return this.ast.data.jsDocParsingMode; } + set jsDocParsingMode(value) { this.ast.data.jsDocParsingMode = value; } + + get scriptSnapshot() { return this.ast.data.scriptSnapshot; } + set scriptSnapshot(value) { this.ast.data.scriptSnapshot = value; } + get nameTable() { return this.ast.data.nameTable; } + set nameTable(value) { this.ast.data.nameTable = value; } + + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + + get extendedSourceFiles() { return this.ast.data.extendedSourceFiles; } + set extendedSourceFiles(value) { this.ast.data.extendedSourceFiles = value; } + get configFileSpecs() { return this.ast.data.configFileSpecs; } + set configFileSpecs(value) { this.ast.data.configFileSpecs = value; } + + public update(newText: string, textChangeRange: ts.TextChangeRange): ts.SourceFile { + return updateSourceFile(this, newText, textChangeRange); + } + + public getLineAndCharacterOfPosition(position: number): ts.LineAndCharacter { + return getLineAndCharacterOfPosition(this, position); + } + + public getLineStarts(): readonly number[] { + return getLineStarts(this); + } + + public getPositionOfLineAndCharacter(line: number, character: number, allowEdits?: true): number { + return computePositionOfLineAndCharacter(getLineStarts(this), line, character, this.text, allowEdits); + } + + public getLineEndOfPosition(pos: number): number { + const { line } = this.getLineAndCharacterOfPosition(pos); + const lineStarts = this.getLineStarts(); + + let lastCharPos: number | undefined; + if (line + 1 >= lineStarts.length) { + lastCharPos = this.getEnd(); + } + if (!lastCharPos) { + lastCharPos = lineStarts[line + 1] - 1; + } + + const fullText = this.getFullText(); + // if the new line is "\r\n", we should return the last non-new-line-character position + return fullText[lastCharPos] === "\n" && fullText[lastCharPos - 1] === "\r" ? lastCharPos - 1 : lastCharPos; + } + + public getNamedDeclarations(): Map { + if (!this.ast.data.namedDeclarations) { + this.ast.data.namedDeclarations = this.computeNamedDeclarations(); + } + + return this.ast.data.namedDeclarations; + } + + private computeNamedDeclarations(): Map { + const result = createMultiMap(); + + this.forEachChild(visit); + + return result; + + function addDeclaration(declaration: ts.Declaration) { + const name = getDeclarationName(declaration); + if (name) { + result.add(name, declaration); + } + } + + function getDeclarations(name: string) { + let declarations = result.get(name); + if (!declarations) { + result.set(name, declarations = []); + } + return declarations; + } + + function getDeclarationName(declaration: ts.Declaration) { + const name = getNonAssignedNameOfDeclaration(declaration); + return name && (isComputedPropertyName(name) && isPropertyAccessExpression(name.expression) ? (name.expression.name as MemberName).text + : isPropertyName(name) ? getNameFromPropertyName(name) : undefined); + } + + function visit(node: ts.Node): void { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + const functionDeclaration = node as ts.FunctionLikeDeclaration; + const declarationName = getDeclarationName(functionDeclaration); + + if (declarationName) { + const declarations = getDeclarations(declarationName); + const lastDeclaration = lastOrUndefined(declarations); + + // Check whether this declaration belongs to an "overload group". + if (lastDeclaration && functionDeclaration.parent === lastDeclaration.parent && functionDeclaration.symbol === lastDeclaration.symbol) { + // Overwrite the last declaration if it was an overload + // and this one is an implementation. + if (functionDeclaration.body && !(lastDeclaration as ts.FunctionLikeDeclaration).body) { + declarations[declarations.length - 1] = functionDeclaration; + } + } + else { + declarations.push(functionDeclaration); + } + } + forEachChild(node, visit); + break; + + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ExportSpecifier: + case SyntaxKind.ImportSpecifier: + case SyntaxKind.ImportClause: + case SyntaxKind.NamespaceImport: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.TypeLiteral: + addDeclaration(node as ts.Declaration); + forEachChild(node, visit); + break; + + case SyntaxKind.Parameter: + // Only consider parameter properties + if (!hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) { + break; + } + // falls through + + case SyntaxKind.VariableDeclaration: + case SyntaxKind.BindingElement: { + const decl = node as ts.VariableDeclaration; + if (isBindingPattern(decl.name)) { + forEachChild(decl.name, visit); + break; + } + if (decl.initializer) { + visit(decl.initializer); + } + } + // falls through + case SyntaxKind.EnumMember: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + addDeclaration(node as ts.Declaration); + break; + + case SyntaxKind.ExportDeclaration: + // Handle named exports case e.g.: + // export {a, b as B} from "mod"; + const exportDeclaration = node as ts.ExportDeclaration; + if (exportDeclaration.exportClause) { + if (isNamedExports(exportDeclaration.exportClause)) { + forEach(exportDeclaration.exportClause.elements, visit); + } + else { + visit(exportDeclaration.exportClause.name); + } + } + break; + + case SyntaxKind.ImportDeclaration: + const importClause = (node as ImportDeclaration).importClause; + if (importClause) { + // Handle default import case e.g.: + // import d from "mod"; + if (importClause.name) { + addDeclaration(importClause.name); + } + + // Handle named bindings in imports e.g.: + // import * as NS from "mod"; + // import {a, b as B} from "mod"; + if (importClause.namedBindings) { + if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + addDeclaration(importClause.namedBindings); + } + else { + forEach(importClause.namedBindings.elements, visit); + } + } + } + break; + + case SyntaxKind.BinaryExpression: + if (getAssignmentDeclarationKind(node as ts.BinaryExpression) !== ts.AssignmentDeclarationKind.None) { + addDeclaration(node as ts.BinaryExpression); + } + // falls through + + default: + forEachChild(node, visit); + } + } + } +} + +/** @internal */ +export class AstDeclarationData { + symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) +} + +/** @internal */ +export class AstSourceFileData extends AstData { + declaration = new AstDeclarationData(); + statements: AstNodeArray | undefined = undefined; + endOfFileToken: AstEndOfFileToken = undefined!; + text = ""; + fileName = ""; + path = "" as Path; + resolvedPath = "" as Path; + originalFileName = ""; + languageVersion = ScriptTarget.ES5; + languageVariant: LanguageVariant = 0; + scriptKind: ScriptKind = 0; + isDeclarationFile = false; + hasNoDefaultLib = false; + locals: SymbolTable | undefined = undefined; + nextContainer: NextContainer | undefined = undefined; + endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + nodeCount = 0; + identifierCount = 0; + symbolCount = 0; + parseDiagnostics: DiagnosticWithLocation[] = undefined!; + bindDiagnostics: DiagnosticWithLocation[] = undefined!; + bindSuggestionDiagnostics: DiagnosticWithLocation[] | undefined = undefined; + lineMap: readonly number[] = undefined!; + externalModuleIndicator: Node | true | undefined = undefined; + setExternalModuleIndicator?: ((file: ts.SourceFile) => void) | undefined = undefined; + pragmas: ReadonlyPragmaMap = undefined!; + checkJsDirective: CheckJsDirective | undefined = undefined; + referencedFiles: readonly FileReference[] = undefined!; + typeReferenceDirectives: readonly FileReference[] = undefined!; + libReferenceDirectives: readonly FileReference[] = undefined!; + amdDependencies: AmdDependency[] = undefined!; + commentDirectives: CommentDirective[] | undefined = undefined; + identifiers: Map = undefined!; + packageJsonLocations?: readonly string[] | undefined = undefined; + packageJsonScope?: PackageJsonInfo | undefined = undefined; + imports: readonly ts.StringLiteralLike[] = undefined!; + moduleAugmentations: readonly (ts.Identifier | ts.StringLiteral)[] = undefined!; + ambientModuleNames: readonly string[] = undefined!; + classifiableNames?: ReadonlySet<__String> | undefined = undefined; + impliedNodeFormat: ResolutionMode | undefined = undefined; + moduleName: string | undefined = undefined; + renamedDependencies: Map = undefined!; + commonJsModuleIndicator: Node | undefined = undefined; + version: string = undefined!; + redirectInfo?: ts.RedirectInfo | undefined = undefined; + jsGlobalAugmentations?: SymbolTable | undefined = undefined; + additionalSyntacticDiagnostics?: readonly DiagnosticWithLocation[] | undefined = undefined; + patternAmbientModules?: ts.PatternAmbientModule[] | undefined = undefined; + localJsxNamespace?: __String | undefined = undefined; + localJsxFragmentNamespace?: __String | undefined = undefined; + localJsxFactory?: ts.EntityName | undefined = undefined; + localJsxFragmentFactory?: ts.EntityName | undefined = undefined; + jsDocParsingMode?: ts.JSDocParsingMode | undefined = undefined; + jsDocDiagnostics: DiagnosticWithLocation[] | undefined = undefined; + namedDeclarations: Map | undefined = undefined; + + // TODO: fix type + scriptSnapshot: any = undefined; + nameTable: Map<__String, number> | undefined = undefined; + + // TsConfigSourceFile + extendedSourceFiles?: string[]; + configFileSpecs?: ts.ConfigFileSpecs; + + override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildrenFlags(this.statements) | + propagateChildFlags(this.endOfFileToken); + } + + override cloneNode(node: AstNode): AstNode { + if (this.redirectInfo) { + const clone = (this.redirectInfo.redirectTarget as SourceFile).ast.shadow() as AstSourceFile; + this.copyProperties(clone.data); + clone.emitNode = undefined; + return clone; + } + return super.cloneNode(node); + } +} + +/** @internal */ +export type AstToken = AstNode>; +/** @internal */ +export type AstEndOfFileToken = AstNode; +/** @internal */ +export type AstThisExpression = AstNode; +/** @internal */ +export type AstSuperExpression = AstNode; +/** @internal */ +export type AstImportExpression = AstNode; +/** @internal */ +export type AstNullLiteral = AstNode; +/** @internal */ +export type AstTrueLiteral = AstNode; +/** @internal */ +export type AstFalseLiteral = AstNode; +/** @internal */ +export type AstIdentifier = AstNode; +/** @internal */ +export type AstQualifiedName = AstNode; +/** @internal */ +export type AstComputedPropertyName = AstNode; +/** @internal */ +export type AstPrivateIdentifier = AstNode; +/** @internal */ +export type AstTypeParameterDeclaration = AstNode; +/** @internal */ +export type AstParameterDeclaration = AstNode; +/** @internal */ +export type AstDecorator = AstNode; +/** @internal */ +export type AstPropertySignature = AstNode; +/** @internal */ +export type AstCallSignatureDeclaration = AstNode; +/** @internal */ +export type AstConstructSignatureDeclaration = AstNode; +/** @internal */ +export type AstVariableDeclaration = AstNode; +/** @internal */ +export type AstVariableDeclarationList = AstNode; +/** @internal */ +export type AstBindingElement = AstNode; +/** @internal */ +export type AstPropertyDeclaration = AstNode; +/** @internal */ +export type AstPropertyAssignment = AstNode; +/** @internal */ +export type AstShorthandPropertyAssignment = AstNode; +/** @internal */ +export type AstSpreadAssignment = AstNode; +/** @internal */ +export type AstObjectBindingPattern = AstNode; +/** @internal */ +export type AstArrayBindingPattern = AstNode; +/** @internal */ +export type AstFunctionDeclaration = AstNode; +/** @internal */ +export type AstMethodSignature = AstNode; +/** @internal */ +export type AstMethodDeclaration = AstNode; +/** @internal */ +export type AstConstructorDeclaration = AstNode; +/** @internal */ +export type AstSemicolonClassElement = AstNode; +/** @internal */ +export type AstGetAccessorDeclaration = AstNode; +/** @internal */ +export type AstSetAccessorDeclaration = AstNode; +/** @internal */ +export type AstIndexSignatureDeclaration = AstNode; +/** @internal */ +export type AstClassStaticBlockDeclaration = AstNode; +/** @internal */ +export type AstImportTypeNode = AstNode; +/** @internal */ +export type AstThisTypeNode = AstNode; +/** @internal */ +export type AstFunctionTypeNode = AstNode; +/** @internal */ +export type AstConstructorTypeNode = AstNode; +/** @internal */ +export type AstTypeReferenceNode = AstNode; +/** @internal */ +export type AstTypePredicateNode = AstNode; +/** @internal */ +export type AstTypeQueryNode = AstNode; +/** @internal */ +export type AstTypeLiteralNode = AstNode; +/** @internal */ +export type AstArrayTypeNode = AstNode; +/** @internal */ +export type AstTupleTypeNode = AstNode; +/** @internal */ +export type AstNamedTupleMember = AstNode; +/** @internal */ +export type AstOptionalTypeNode = AstNode; +/** @internal */ +export type AstRestTypeNode = AstNode; +/** @internal */ +export type AstUnionTypeNode = AstNode; +/** @internal */ +export type AstIntersectionTypeNode = AstNode; +/** @internal */ +export type AstConditionalTypeNode = AstNode; +/** @internal */ +export type AstInferTypeNode = AstNode; +/** @internal */ +export type AstParenthesizedTypeNode = AstNode; +/** @internal */ +export type AstTypeOperatorNode = AstNode; +/** @internal */ +export type AstIndexedAccessTypeNode = AstNode; +/** @internal */ +export type AstMappedTypeNode = AstNode; +/** @internal */ +export type AstLiteralTypeNode = AstNode; +/** @internal */ +export type AstStringLiteral = AstNode; +/** @internal */ +export type AstTemplateLiteralTypeNode = AstNode; +/** @internal */ +export type AstTemplateLiteralTypeSpan = AstNode; +/** @internal */ +export type AstOmittedExpression = AstNode; +/** @internal */ +export type AstPrefixUnaryExpression = AstNode; +/** @internal */ +export type AstPostfixUnaryExpression = AstNode; +/** @internal */ +export type AstDeleteExpression = AstNode; +/** @internal */ +export type AstTypeOfExpression = AstNode; +/** @internal */ +export type AstVoidExpression = AstNode; +/** @internal */ +export type AstAwaitExpression = AstNode; +/** @internal */ +export type AstYieldExpression = AstNode; +/** @internal */ +export type AstBinaryExpression = AstNode; +/** @internal */ +export type AstConditionalExpression = AstNode; +/** @internal */ +export type AstFunctionExpression = AstNode; +/** @internal */ +export type AstArrowFunction = AstNode; +/** @internal */ +export type AstRegularExpressionLiteral = AstNode; +/** @internal */ +export type AstNoSubstitutionTemplateLiteral = AstNode; +/** @internal */ +export type AstNumericLiteral = AstNode; +/** @internal */ +export type AstBigIntLiteral = AstNode; +/** @internal */ +export type AstTemplateHead = AstNode; +/** @internal */ +export type AstTemplateMiddle = AstNode; +/** @internal */ +export type AstTemplateTail = AstNode; +/** @internal */ +export type AstTemplateExpression = AstNode; +/** @internal */ +export type AstTemplateSpan = AstNode; +/** @internal */ +export type AstParenthesizedExpression = AstNode; +/** @internal */ +export type AstArrayLiteralExpression = AstNode; +/** @internal */ +export type AstSpreadElement = AstNode; +/** @internal */ +export type AstObjectLiteralExpression = AstNode; +/** @internal */ +export type AstPropertyAccessExpression = AstNode; +/** @internal */ +export type AstElementAccessExpression = AstNode; +/** @internal */ +export type AstCallExpression = AstNode; +/** @internal */ +export type AstExpressionWithTypeArguments = AstNode; +/** @internal */ +export type AstNewExpression = AstNode; +/** @internal */ +export type AstTaggedTemplateExpression = AstNode; +/** @internal */ +export type AstAsExpression = AstNode; +/** @internal */ +export type AstTypeAssertion = AstNode; +/** @internal */ +export type AstSatisfiesExpression = AstNode; +/** @internal */ +export type AstNonNullExpression = AstNode; +/** @internal */ +export type AstMetaProperty = AstNode; +/** @internal */ +export type AstJsxElement = AstNode; +/** @internal */ +export type AstJsxAttributes = AstNode; +/** @internal */ +export type AstJsxNamespacedName = AstNode; +/** @internal */ +export type AstJsxOpeningElement = AstNode; +/** @internal */ +export type AstJsxSelfClosingElement = AstNode; +/** @internal */ +export type AstJsxFragment = AstNode; +/** @internal */ +export type AstJsxOpeningFragment = AstNode; +/** @internal */ +export type AstJsxClosingFragment = AstNode; +/** @internal */ +export type AstJsxAttribute = AstNode; +/** @internal */ +export type AstJsxSpreadAttribute = AstNode; +/** @internal */ +export type AstJsxClosingElement = AstNode; +/** @internal */ +export type AstJsxExpression = AstNode; +/** @internal */ +export type AstJsxText = AstNode; +/** @internal */ +export type AstEmptyStatement = AstNode; +/** @internal */ +export type AstDebuggerStatement = AstNode; +/** @internal */ +export type AstMissingDeclaration = AstNode; +/** @internal */ +export type AstBlock = AstNode; +/** @internal */ +export type AstVariableStatement = AstNode; +/** @internal */ +export type AstExpressionStatement = AstNode; +/** @internal */ +export type AstIfStatement = AstNode; +/** @internal */ +export type AstDoStatement = AstNode; +/** @internal */ +export type AstWhileStatement = AstNode; +/** @internal */ +export type AstForStatement = AstNode; +/** @internal */ +export type AstForInStatement = AstNode; +/** @internal */ +export type AstForOfStatement = AstNode; +/** @internal */ +export type AstBreakStatement = AstNode; +/** @internal */ +export type AstContinueStatement = AstNode; +/** @internal */ +export type AstReturnStatement = AstNode; +/** @internal */ +export type AstWithStatement = AstNode; +/** @internal */ +export type AstSwitchStatement = AstNode; +/** @internal */ +export type AstCaseBlock = AstNode; +/** @internal */ +export type AstCaseClause = AstNode; +/** @internal */ +export type AstDefaultClause = AstNode; +/** @internal */ +export type AstLabeledStatement = AstNode; +/** @internal */ +export type AstThrowStatement = AstNode; +/** @internal */ +export type AstTryStatement = AstNode; +/** @internal */ +export type AstCatchClause = AstNode; +/** @internal */ +export type AstClassDeclaration = AstNode; +/** @internal */ +export type AstClassExpression = AstNode; +/** @internal */ +export type AstInterfaceDeclaration = AstNode; +/** @internal */ +export type AstHeritageClause = AstNode; +/** @internal */ +export type AstTypeAliasDeclaration = AstNode; +/** @internal */ +export type AstEnumMember = AstNode; +/** @internal */ +export type AstEnumDeclaration = AstNode; +/** @internal */ +export type AstModuleDeclaration = AstNode; +/** @internal */ +export type AstModuleBlock = AstNode; +/** @internal */ +export type AstImportEqualsDeclaration = AstNode; +/** @internal */ +export type AstExternalModuleReference = AstNode; +/** @internal */ +export type AstImportDeclaration = AstNode; +/** @internal */ +export type AstImportClause = AstNode; +/** @internal */ +export type AstImportAttribute = AstNode; +/** @internal */ +export type AstImportAttributes = AstNode; +/** @internal */ +export type AstNamespaceImport = AstNode; +/** @internal */ +export type AstNamespaceExport = AstNode; +/** @internal */ +export type AstNamespaceExportDeclaration = AstNode; +/** @internal */ +export type AstExportDeclaration = AstNode; +/** @internal */ +export type AstNamedImports = AstNode; +/** @internal */ +export type AstNamedExports = AstNode; +/** @internal */ +export type AstImportSpecifier = AstNode; +/** @internal */ +export type AstExportSpecifier = AstNode; +/** @internal */ +export type AstExportAssignment = AstNode; +/** @internal */ +export type AstJSDocTypeExpression = AstNode; +/** @internal */ +export type AstJSDocNameReference = AstNode; +/** @internal */ +export type AstJSDocMemberName = AstNode; +/** @internal */ +export type AstJSDocAllType = AstNode; +/** @internal */ +export type AstJSDocUnknownType = AstNode; +/** @internal */ +export type AstJSDocNonNullableType = AstNode; +/** @internal */ +export type AstJSDocNullableType = AstNode; +/** @internal */ +export type AstJSDocOptionalType = AstNode; +/** @internal */ +export type AstJSDocFunctionType = AstNode; +/** @internal */ +export type AstJSDocVariadicType = AstNode; +/** @internal */ +export type AstJSDocNamepathType = AstNode; +/** @internal */ +export type AstJSDocNode = AstNode; +/** @internal */ +export type AstJSDocLink = AstNode; +/** @internal */ +export type AstJSDocLinkCode = AstNode; +/** @internal */ +export type AstJSDocLinkPlain = AstNode; +/** @internal */ +export type AstJSDocText = AstNode; +/** @internal */ +export type AstJSDocUnknownTag = AstNode; +/** @internal */ +export type AstJSDocAugmentsTag = AstNode; +/** @internal */ +export type AstJSDocImplementsTag = AstNode; +/** @internal */ +export type AstJSDocAuthorTag = AstNode; +/** @internal */ +export type AstJSDocDeprecatedTag = AstNode; +/** @internal */ +export type AstJSDocClassTag = AstNode; +/** @internal */ +export type AstJSDocPublicTag = AstNode; +/** @internal */ +export type AstJSDocPrivateTag = AstNode; +/** @internal */ +export type AstJSDocProtectedTag = AstNode; +/** @internal */ +export type AstJSDocReadonlyTag = AstNode; +/** @internal */ +export type AstJSDocOverrideTag = AstNode; +/** @internal */ +export type AstJSDocEnumTag = AstNode; +/** @internal */ +export type AstJSDocThisTag = AstNode; +/** @internal */ +export type AstJSDocTemplateTag = AstNode; +/** @internal */ +export type AstJSDocSeeTag = AstNode; +/** @internal */ +export type AstJSDocReturnTag = AstNode; +/** @internal */ +export type AstJSDocTypeTag = AstNode; +/** @internal */ +export type AstJSDocTypedefTag = AstNode; +/** @internal */ +export type AstJSDocCallbackTag = AstNode; +/** @internal */ +export type AstJSDocOverloadTag = AstNode; +/** @internal */ +export type AstJSDocThrowsTag = AstNode; +/** @internal */ +export type AstJSDocSignature = AstNode; +/** @internal */ +export type AstJSDocPropertyTag = AstNode; +/** @internal */ +export type AstJSDocParameterTag = AstNode; +/** @internal */ +export type AstJSDocTypeLiteral = AstNode; +/** @internal */ +export type AstJSDocSatisfiesTag = AstNode; +/** @internal */ +export type AstJSDocImportTag = AstNode; +/** @internal */ +export type AstSourceFile = AstNode; +/** @internal */ +export type AstSyntheticExpression = AstNode; +/** @internal */ +export type AstBundle = AstNode; +/** @internal */ +export type AstSyntaxList = AstNode; +/** @internal */ +export type AstNotEmittedStatement = AstNode; +/** @internal */ +export type AstNotEmittedTypeElement = AstNode; +/** @internal */ +export type AstPartiallyEmittedExpression = AstNode; +/** @internal */ +export type AstCommaListExpression = AstNode; +/** @internal */ +export type AstSyntheticReferenceExpression = AstNode; + +function propagateNameFlags(node: AstPropertyName | AstBindingPattern | AstNoSubstitutionTemplateLiteral | undefined) { + return node?.kind === SyntaxKind.Identifier ? propagateIdentifierNameFlags(node) : propagateChildFlags(node); +} + +function propagateIdentifierNameFlags(node: AstIdentifier) { + // An IdentifierName is allowed to be `await` + return propagateChildFlags(node) & ~TransformFlags.ContainsPossibleTopLevelAwait; +} + +function propagatePropertyNameFlagsOfChild(node: AstPropertyName, transformFlags: TransformFlags) { + return transformFlags | (node.transformFlags & TransformFlags.PropertyNamePropagatingFlags); +} + +function propagateChildFlags(child: AstNode | undefined): TransformFlags { + if (!child) return TransformFlags.None; + const childFlags = child.transformFlags & ~getTransformFlagsSubtreeExclusions(child.kind); + return isNamedDeclaration(child) && child.data.name && isAstPropertyName(child.data.name) ? propagatePropertyNameFlagsOfChild(child.data.name, childFlags) : childFlags; +} + +function propagateChildrenFlags(children: AstNodeArray | undefined): TransformFlags { + return children ? children.transformFlags : TransformFlags.None; +} + +function propagateAssignmentPatternFlags(node: AstObjectLiteralExpression | AstArrayLiteralExpression): TransformFlags { + // TODO: use algorithm that does not instantiate Node + return containsObjectRestOrSpread(node.node) ? TransformFlags.ContainsObjectRestOrSpread : TransformFlags.None; +} + +function getTransformFlagsOfTemplateLiteralLike(templateFlags: TokenFlags) { + let transformFlags = TransformFlags.ContainsES2015; + if (templateFlags) { + transformFlags |= TransformFlags.ContainsES2018; + } + return transformFlags; +} + +/** @internal */ +export type NamedDeclaration = + | FunctionDeclaration + | FunctionExpression + | ClassExpression + | ClassDeclaration + | MethodDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration + | PropertyDeclaration + | InterfaceDeclaration + | MethodSignature + | PropertySignature + | TypeAliasDeclaration + | EnumDeclaration + | EnumMember + | ModuleDeclaration + | VariableDeclaration + | ParameterDeclaration + | BindingElement + | TypeParameterDeclaration + | ImportEqualsDeclaration + | NamespaceExportDeclaration + | ImportClause + | NamespaceImport + | NamespaceExport + | ImportSpecifier + | ExportSpecifier + | JSDocTypedefTag + | JSDocCallbackTag; + +/** @internal */ +export type AstNamedDeclaration = AstNodeOneOf; + +function isNamedDeclaration(node: AstNode): node is AstNamedDeclaration { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ClassExpression: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.PropertySignature: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.EnumMember: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.VariableDeclaration: + case SyntaxKind.Parameter: + case SyntaxKind.BindingElement: + case SyntaxKind.TypeParameter: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.NamespaceExportDeclaration: + case SyntaxKind.ImportClause: + case SyntaxKind.NamespaceImport: + case SyntaxKind.NamespaceExport: + case SyntaxKind.ImportSpecifier: + case SyntaxKind.ExportSpecifier: + case SyntaxKind.JSDocTypedefTag: + case SyntaxKind.JSDocCallbackTag: + return true; + } + return false; +} + +function isAstPropertyName(node: AstNode): node is AstPropertyName { + const kind = node.kind; + return kind === SyntaxKind.Identifier + || kind === SyntaxKind.PrivateIdentifier + || kind === SyntaxKind.StringLiteral + || kind === SyntaxKind.NumericLiteral + || kind === SyntaxKind.ComputedPropertyName; +} + +function modifiersToFlags(modifiers: readonly AstModifierLike[] | undefined) { + let flags = ModifierFlags.None; + if (modifiers) { + for (const modifier of modifiers) { + flags |= modifierToFlag(modifier.kind); + } + } + return flags; +} + +// copied from utilities.ts +function containsInvalidEscapeFlag(node: AstTemplateLiteralToken): boolean { + return !!(node.data.templateFlags & TokenFlags.ContainsInvalidEscape); +} + +// copied from utilities.ts +function hasInvalidEscape(template: AstTemplateLiteral): boolean { + return template && !!(isNoSubstitutionTemplateLiteral(template) + ? containsInvalidEscapeFlag(template) + : (containsInvalidEscapeFlag(template.data.head) || template.data.templateSpans?.items.some(span => containsInvalidEscapeFlag(span.data.literal)))); +} + +function isNoSubstitutionTemplateLiteral(template: AstTemplateLiteral): template is AstNoSubstitutionTemplateLiteral { + return template.kind === SyntaxKind.NoSubstitutionTemplateLiteral; +} + +// copied from services/utilities.ts +function getNameFromPropertyName(name: ts.PropertyName): string | undefined { + return name.kind === SyntaxKind.ComputedPropertyName + // treat computed property names where expression is string/numeric literal as just string/numeric literal + ? isStringOrNumericLiteralLike(name.expression) ? name.expression.text : undefined + : isPrivateIdentifier(name) ? idText(name) : getTextOfIdentifierOrLiteral(name); +} + +// copied form services/services.ts +let _scanner: Scanner | undefined; + +function scanner() { + _scanner ??= createScanner(ScriptTarget.Latest, /*skipTrivia*/ true); + return _scanner; +} + +function createChildren(node: Node, sourceFile: ts.SourceFileLike | undefined): readonly ts.Node[] { + const children: ts.Node[] = []; + + if (isJSDocCommentContainingNode(node)) { + /** Don't add trivia for "tokens" since this is in a comment. */ + node.forEachChild(child => { + children.push(child); + }); + return children; + } + + scanner().setText((sourceFile || node.getSourceFile()).text); + let pos = node.pos; + const processNode = (child: ts.Node) => { + addSyntheticNodes(children, pos, child.pos, node); + children.push(child); + pos = child.end; + }; + const processNodes = (nodes: ts.NodeArray) => { + addSyntheticNodes(children, pos, nodes.pos, node); + children.push(createSyntaxList(nodes, node)); + pos = nodes.end; + }; + // jsDocComments need to be the first children + forEach((node as ts.Node as ts.JSDocContainer).jsDoc, processNode); + // For syntactic classifications, all trivia are classified together, including jsdoc comments. + // For that to work, the jsdoc comments should still be the leading trivia of the first child. + // Restoring the scanner position ensures that. + pos = node.pos; + node.forEachChild(processNode, processNodes); + addSyntheticNodes(children, pos, node.end, node); + scanner().setText(undefined); + return children; +} + +function createNode(kind: TKind, pos: number, end: number, parent: ts.Node): ts.Node { + const astNode = kind === SyntaxKind.StringLiteral ? AstNode.StringLiteral() : AstNode.Token(kind); + astNode.pos = pos; + astNode.end = end; + astNode.parent = (parent as Node).ast; + astNode.flags = parent.flags & NodeFlags.ContextFlags; + return astNode.node; +} + +function addSyntheticNodes(nodes: ts.Node[], pos: number, end: number, parent: ts.Node): void { + scanner().resetTokenState(pos); + while (pos < end) { + const token = scanner().scan(); + const textPos = scanner().getTokenEnd(); + if (textPos <= end) { + Debug.assert(ts.isTokenKind(token)); + if (token === SyntaxKind.Identifier) { + if (hasTabstop(parent)) { + continue; + } + Debug.fail(`Did not expect ${Debug.formatSyntaxKind(parent.kind)} to have an ${Debug.formatSyntaxKind(token)} in its trivia`); + } + nodes.push(createNode(token as TokenSyntaxKind, pos, textPos, parent)); + } + pos = textPos; + if (token === SyntaxKind.EndOfFileToken) { + break; + } + } +} + +function createSyntaxList(nodes: ts.NodeArray, parent: ts.Node): ts.Node { + const list = AstNode.SyntaxList(); + list.pos = nodes.pos; + list.end = nodes.end; + list.parent = (parent as Node).ast; + const children: ts.Node[] = []; + let pos = nodes.pos; + for (const node of nodes) { + addSyntheticNodes(children, pos, node.pos, parent); + children.push(node); + pos = node.end; + } + addSyntheticNodes(children, pos, nodes.end, parent); + list.data._children = children as Node[]; + return list.node; +} + +/** @internal */ +export function getAstSourceFileNodeOfNode(node: AstNode | undefined): AstSourceFile | undefined { + while (node && node.kind !== SyntaxKind.SourceFile) { + node = node.parent; + } + return node as AstSourceFile | undefined; +} + +/** @internal */ +export function getAstParseTreeNode(node: AstNode | undefined, nodeTest?: (node: AstNode) => boolean): AstNode | undefined { + if (node === undefined) { + return node; + } + while (node) { + if (ts.isParseTreeNode(node)) { + return !nodeTest || nodeTest(node) ? node : undefined; + } + node = node.original; + } + return undefined; +} + +/** @internal */ +export function isAstJSDocTypeAssertion(node: AstNode): node is AstJSDocTypeAssertion { + return isAstParenthesizedExpression(node) + && !!(node.flags & NodeFlags.JavaScriptFile) + && !!ts.getJSDocTypeTag(node.node); // TODO: don't invoke node +} + +/** @internal */ +export type OuterExpression = + | ParenthesizedExpression + | TypeAssertion + | SatisfiesExpression + | AsExpression + | NonNullExpression + | ExpressionWithTypeArguments + | PartiallyEmittedExpression; + +/** @internal */ +export type AstOuterExpression = AstNodeOneOf; + +/** @internal */ +export function isAstOuterExpression(node: AstNode, kinds = ts.OuterExpressionKinds.All): node is AstOuterExpression { + switch (node.kind) { + case SyntaxKind.ParenthesizedExpression: + if (kinds & ts.OuterExpressionKinds.ExcludeJSDocTypeAssertion && isAstJSDocTypeAssertion(node)) { + return false; + } + return (kinds & ts.OuterExpressionKinds.Parentheses) !== 0; + case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.AsExpression: + case SyntaxKind.SatisfiesExpression: + return (kinds & ts.OuterExpressionKinds.TypeAssertions) !== 0; + case SyntaxKind.ExpressionWithTypeArguments: + return (kinds & ts.OuterExpressionKinds.ExpressionsWithTypeArguments) !== 0; + case SyntaxKind.NonNullExpression: + return (kinds & ts.OuterExpressionKinds.NonNullAssertions) !== 0; + case SyntaxKind.PartiallyEmittedExpression: + return (kinds & ts.OuterExpressionKinds.PartiallyEmittedExpressions) !== 0; + } + return false; +} + +/** @internal */ +export function skipAstOuterExpressions(node: AstNode, kinds = ts.OuterExpressionKinds.All) { + while (isAstOuterExpression(node, kinds)) { + node = node.data.expression; + } + return node; +} + +/** @internal */ +export interface NodeType { + [SyntaxKind.Unknown]: Token, + [SyntaxKind.EndOfFileToken]: EndOfFileToken, + [SyntaxKind.SingleLineCommentTrivia]: Token, + [SyntaxKind.MultiLineCommentTrivia]: Token, + [SyntaxKind.NewLineTrivia]: Token, + [SyntaxKind.WhitespaceTrivia]: Token, + [SyntaxKind.ShebangTrivia]: Token, + [SyntaxKind.ConflictMarkerTrivia]: Token, + [SyntaxKind.NonTextFileMarkerTrivia]: never, + [SyntaxKind.NumericLiteral]: NumericLiteral, + [SyntaxKind.BigIntLiteral]: BigIntLiteral, + [SyntaxKind.StringLiteral]: StringLiteral, + [SyntaxKind.JsxText]: JsxText, + [SyntaxKind.JsxTextAllWhiteSpaces]: never, + [SyntaxKind.RegularExpressionLiteral]: RegularExpressionLiteral, + [SyntaxKind.NoSubstitutionTemplateLiteral]: NoSubstitutionTemplateLiteral, + [SyntaxKind.TemplateHead]: TemplateHead, + [SyntaxKind.TemplateMiddle]: TemplateMiddle, + [SyntaxKind.TemplateTail]: TemplateTail, + [SyntaxKind.OpenBraceToken]: Token, + [SyntaxKind.CloseBraceToken]: Token, + [SyntaxKind.OpenParenToken]: Token, + [SyntaxKind.CloseParenToken]: Token, + [SyntaxKind.OpenBracketToken]: Token, + [SyntaxKind.CloseBracketToken]: Token, + [SyntaxKind.DotToken]: Token, + [SyntaxKind.DotDotDotToken]: Token, + [SyntaxKind.SemicolonToken]: Token, + [SyntaxKind.CommaToken]: Token, + [SyntaxKind.QuestionDotToken]: Token, + [SyntaxKind.LessThanToken]: Token, + [SyntaxKind.LessThanSlashToken]: Token, + [SyntaxKind.GreaterThanToken]: Token, + [SyntaxKind.LessThanEqualsToken]: Token, + [SyntaxKind.GreaterThanEqualsToken]: Token, + [SyntaxKind.EqualsEqualsToken]: Token, + [SyntaxKind.ExclamationEqualsToken]: Token, + [SyntaxKind.EqualsEqualsEqualsToken]: Token, + [SyntaxKind.ExclamationEqualsEqualsToken]: Token, + [SyntaxKind.EqualsGreaterThanToken]: Token, + [SyntaxKind.PlusToken]: Token, + [SyntaxKind.MinusToken]: Token, + [SyntaxKind.AsteriskToken]: Token, + [SyntaxKind.AsteriskAsteriskToken]: Token, + [SyntaxKind.SlashToken]: Token, + [SyntaxKind.PercentToken]: Token, + [SyntaxKind.PlusPlusToken]: Token, + [SyntaxKind.MinusMinusToken]: Token, + [SyntaxKind.LessThanLessThanToken]: Token, + [SyntaxKind.GreaterThanGreaterThanToken]: Token, + [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: Token, + [SyntaxKind.AmpersandToken]: Token, + [SyntaxKind.BarToken]: Token, + [SyntaxKind.CaretToken]: Token, + [SyntaxKind.ExclamationToken]: Token, + [SyntaxKind.TildeToken]: Token, + [SyntaxKind.AmpersandAmpersandToken]: Token, + [SyntaxKind.BarBarToken]: Token, + [SyntaxKind.QuestionToken]: Token, + [SyntaxKind.ColonToken]: Token, + [SyntaxKind.AtToken]: Token, + [SyntaxKind.QuestionQuestionToken]: Token, + [SyntaxKind.BacktickToken]: Token, + [SyntaxKind.HashToken]: Token, + [SyntaxKind.EqualsToken]: Token, + [SyntaxKind.PlusEqualsToken]: Token, + [SyntaxKind.MinusEqualsToken]: Token, + [SyntaxKind.AsteriskEqualsToken]: Token, + [SyntaxKind.AsteriskAsteriskEqualsToken]: Token, + [SyntaxKind.SlashEqualsToken]: Token, + [SyntaxKind.PercentEqualsToken]: Token, + [SyntaxKind.LessThanLessThanEqualsToken]: Token, + [SyntaxKind.GreaterThanGreaterThanEqualsToken]: Token, + [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: Token, + [SyntaxKind.AmpersandEqualsToken]: Token, + [SyntaxKind.BarEqualsToken]: Token, + [SyntaxKind.BarBarEqualsToken]: Token, + [SyntaxKind.AmpersandAmpersandEqualsToken]: Token, + [SyntaxKind.QuestionQuestionEqualsToken]: Token, + [SyntaxKind.CaretEqualsToken]: Token, + [SyntaxKind.Identifier]: Identifier, + [SyntaxKind.PrivateIdentifier]: PrivateIdentifier, + [SyntaxKind.JSDocCommentTextToken]: never, + [SyntaxKind.BreakKeyword]: Token, + [SyntaxKind.CaseKeyword]: Token, + [SyntaxKind.CatchKeyword]: Token, + [SyntaxKind.ClassKeyword]: Token, + [SyntaxKind.ConstKeyword]: Token, + [SyntaxKind.ContinueKeyword]: Token, + [SyntaxKind.DebuggerKeyword]: Token, + [SyntaxKind.DefaultKeyword]: Token, + [SyntaxKind.DeleteKeyword]: Token, + [SyntaxKind.DoKeyword]: Token, + [SyntaxKind.ElseKeyword]: Token, + [SyntaxKind.EnumKeyword]: Token, + [SyntaxKind.ExportKeyword]: Token, + [SyntaxKind.ExtendsKeyword]: Token, + [SyntaxKind.FalseKeyword]: FalseLiteral, + [SyntaxKind.FinallyKeyword]: Token, + [SyntaxKind.ForKeyword]: Token, + [SyntaxKind.FunctionKeyword]: Token, + [SyntaxKind.IfKeyword]: Token, + [SyntaxKind.ImportKeyword]: ImportExpression, + [SyntaxKind.InKeyword]: Token, + [SyntaxKind.InstanceOfKeyword]: Token, + [SyntaxKind.NewKeyword]: Token, + [SyntaxKind.NullKeyword]: NullLiteral, + [SyntaxKind.ReturnKeyword]: Token, + [SyntaxKind.SuperKeyword]: SuperExpression, + [SyntaxKind.SwitchKeyword]: Token, + [SyntaxKind.ThisKeyword]: ThisExpression, + [SyntaxKind.ThrowKeyword]: Token, + [SyntaxKind.TrueKeyword]: TrueLiteral, + [SyntaxKind.TryKeyword]: Token, + [SyntaxKind.TypeOfKeyword]: Token, + [SyntaxKind.VarKeyword]: Token, + [SyntaxKind.VoidKeyword]: Token, + [SyntaxKind.WhileKeyword]: Token, + [SyntaxKind.WithKeyword]: Token, + [SyntaxKind.ImplementsKeyword]: Token, + [SyntaxKind.InterfaceKeyword]: Token, + [SyntaxKind.LetKeyword]: Token, + [SyntaxKind.PackageKeyword]: Token, + [SyntaxKind.PrivateKeyword]: Token, + [SyntaxKind.ProtectedKeyword]: Token, + [SyntaxKind.PublicKeyword]: Token, + [SyntaxKind.StaticKeyword]: Token, + [SyntaxKind.YieldKeyword]: Token, + [SyntaxKind.AbstractKeyword]: Token, + [SyntaxKind.AccessorKeyword]: Token, + [SyntaxKind.AsKeyword]: Token, + [SyntaxKind.AssertsKeyword]: Token, + [SyntaxKind.AssertKeyword]: Token, + [SyntaxKind.AnyKeyword]: Token, + [SyntaxKind.AsyncKeyword]: Token, + [SyntaxKind.AwaitKeyword]: Token, + [SyntaxKind.BooleanKeyword]: Token, + [SyntaxKind.ConstructorKeyword]: Token, + [SyntaxKind.DeclareKeyword]: Token, + [SyntaxKind.GetKeyword]: Token, + [SyntaxKind.InferKeyword]: Token, + [SyntaxKind.IntrinsicKeyword]: Token, + [SyntaxKind.IsKeyword]: Token, + [SyntaxKind.KeyOfKeyword]: Token, + [SyntaxKind.ModuleKeyword]: Token, + [SyntaxKind.NamespaceKeyword]: Token, + [SyntaxKind.NeverKeyword]: Token, + [SyntaxKind.OutKeyword]: Token, + [SyntaxKind.ReadonlyKeyword]: Token, + [SyntaxKind.RequireKeyword]: Token, + [SyntaxKind.NumberKeyword]: Token, + [SyntaxKind.ObjectKeyword]: Token, + [SyntaxKind.SatisfiesKeyword]: Token, + [SyntaxKind.SetKeyword]: Token, + [SyntaxKind.StringKeyword]: Token, + [SyntaxKind.SymbolKeyword]: Token, + [SyntaxKind.TypeKeyword]: Token, + [SyntaxKind.UndefinedKeyword]: Token, + [SyntaxKind.UniqueKeyword]: Token, + [SyntaxKind.UnknownKeyword]: Token, + [SyntaxKind.UsingKeyword]: Token, + [SyntaxKind.FromKeyword]: Token, + [SyntaxKind.GlobalKeyword]: Token, + [SyntaxKind.BigIntKeyword]: Token, + [SyntaxKind.OverrideKeyword]: Token, + [SyntaxKind.OfKeyword]: Token, + [SyntaxKind.QualifiedName]: QualifiedName, + [SyntaxKind.ComputedPropertyName]: ComputedPropertyName, + [SyntaxKind.Decorator]: Decorator, + [SyntaxKind.TypeParameter]: TypeParameterDeclaration, + [SyntaxKind.CallSignature]: CallSignatureDeclaration, + [SyntaxKind.ConstructSignature]: ConstructSignatureDeclaration, + [SyntaxKind.VariableDeclaration]: VariableDeclaration, + [SyntaxKind.VariableDeclarationList]: VariableDeclarationList, + [SyntaxKind.Parameter]: ParameterDeclaration, + [SyntaxKind.BindingElement]: BindingElement, + [SyntaxKind.PropertySignature]: PropertySignature, + [SyntaxKind.PropertyDeclaration]: PropertyDeclaration, + [SyntaxKind.PropertyAssignment]: PropertyAssignment, + [SyntaxKind.ShorthandPropertyAssignment]: ShorthandPropertyAssignment, + [SyntaxKind.SpreadAssignment]: SpreadAssignment, + [SyntaxKind.ObjectBindingPattern]: ObjectBindingPattern, + [SyntaxKind.ArrayBindingPattern]: ArrayBindingPattern, + [SyntaxKind.FunctionDeclaration]: FunctionDeclaration, + [SyntaxKind.MethodSignature]: MethodSignature, + [SyntaxKind.MethodDeclaration]: MethodDeclaration, + [SyntaxKind.Constructor]: ConstructorDeclaration, + [SyntaxKind.SemicolonClassElement]: SemicolonClassElement, + [SyntaxKind.GetAccessor]: GetAccessorDeclaration, + [SyntaxKind.SetAccessor]: SetAccessorDeclaration, + [SyntaxKind.IndexSignature]: IndexSignatureDeclaration, + [SyntaxKind.ClassStaticBlockDeclaration]: ClassStaticBlockDeclaration, + [SyntaxKind.ImportTypeAssertionContainer]: ImportTypeAssertionContainer, + [SyntaxKind.ImportType]: ImportTypeNode, + [SyntaxKind.ThisType]: ThisTypeNode, + [SyntaxKind.FunctionType]: FunctionTypeNode, + [SyntaxKind.ConstructorType]: ConstructorTypeNode, + [SyntaxKind.TypeReference]: TypeReferenceNode, + [SyntaxKind.TypePredicate]: TypePredicateNode, + [SyntaxKind.TypeQuery]: TypeQueryNode, + [SyntaxKind.TypeLiteral]: TypeLiteralNode, + [SyntaxKind.ArrayType]: ArrayTypeNode, + [SyntaxKind.TupleType]: TupleTypeNode, + [SyntaxKind.NamedTupleMember]: NamedTupleMember, + [SyntaxKind.OptionalType]: OptionalTypeNode, + [SyntaxKind.RestType]: RestTypeNode, + [SyntaxKind.UnionType]: UnionTypeNode, + [SyntaxKind.IntersectionType]: IntersectionTypeNode, + [SyntaxKind.ConditionalType]: ConditionalTypeNode, + [SyntaxKind.InferType]: InferTypeNode, + [SyntaxKind.ParenthesizedType]: ParenthesizedTypeNode, + [SyntaxKind.TypeOperator]: TypeOperatorNode, + [SyntaxKind.IndexedAccessType]: IndexedAccessTypeNode, + [SyntaxKind.MappedType]: MappedTypeNode, + [SyntaxKind.LiteralType]: LiteralTypeNode, + [SyntaxKind.TemplateLiteralType]: TemplateLiteralTypeNode, + [SyntaxKind.TemplateLiteralTypeSpan]: TemplateLiteralTypeSpan, + [SyntaxKind.OmittedExpression]: OmittedExpression, + [SyntaxKind.PrefixUnaryExpression]: PrefixUnaryExpression, + [SyntaxKind.PostfixUnaryExpression]: PostfixUnaryExpression, + [SyntaxKind.DeleteExpression]: DeleteExpression, + [SyntaxKind.TypeOfExpression]: TypeOfExpression, + [SyntaxKind.VoidExpression]: VoidExpression, + [SyntaxKind.AwaitExpression]: AwaitExpression, + [SyntaxKind.YieldExpression]: YieldExpression, + [SyntaxKind.BinaryExpression]: BinaryExpression, + [SyntaxKind.ConditionalExpression]: ConditionalExpression, + [SyntaxKind.FunctionExpression]: FunctionExpression, + [SyntaxKind.ArrowFunction]: ArrowFunction, + [SyntaxKind.TemplateExpression]: TemplateExpression, + [SyntaxKind.TemplateSpan]: TemplateSpan, + [SyntaxKind.ParenthesizedExpression]: ParenthesizedExpression, + [SyntaxKind.ArrayLiteralExpression]: ArrayLiteralExpression, + [SyntaxKind.SpreadElement]: SpreadElement, + [SyntaxKind.ObjectLiteralExpression]: ObjectLiteralExpression, + [SyntaxKind.PropertyAccessExpression]: PropertyAccessExpression, + [SyntaxKind.ElementAccessExpression]: ElementAccessExpression, + [SyntaxKind.CallExpression]: CallExpression, + [SyntaxKind.ExpressionWithTypeArguments]: ExpressionWithTypeArguments, + [SyntaxKind.NewExpression]: NewExpression, + [SyntaxKind.TaggedTemplateExpression]: TaggedTemplateExpression, + [SyntaxKind.AsExpression]: AsExpression, + [SyntaxKind.TypeAssertionExpression]: TypeAssertion, + [SyntaxKind.SyntheticExpression]: SyntheticExpression, + [SyntaxKind.SatisfiesExpression]: SatisfiesExpression, + [SyntaxKind.NonNullExpression]: NonNullExpression, + [SyntaxKind.MetaProperty]: MetaProperty, + [SyntaxKind.JsxElement]: JsxElement, + [SyntaxKind.JsxAttributes]: JsxAttributes, + [SyntaxKind.JsxNamespacedName]: JsxNamespacedName, + [SyntaxKind.JsxOpeningElement]: JsxOpeningElement, + [SyntaxKind.JsxSelfClosingElement]: JsxSelfClosingElement, + [SyntaxKind.JsxFragment]: JsxFragment, + [SyntaxKind.JsxOpeningFragment]: JsxOpeningFragment, + [SyntaxKind.JsxClosingFragment]: JsxClosingFragment, + [SyntaxKind.JsxAttribute]: JsxAttribute, + [SyntaxKind.JsxSpreadAttribute]: JsxSpreadAttribute, + [SyntaxKind.JsxClosingElement]: JsxClosingElement, + [SyntaxKind.JsxExpression]: JsxExpression, + [SyntaxKind.EmptyStatement]: EmptyStatement, + [SyntaxKind.DebuggerStatement]: DebuggerStatement, + [SyntaxKind.MissingDeclaration]: MissingDeclaration, + [SyntaxKind.Block]: Block, + [SyntaxKind.VariableStatement]: VariableStatement, + [SyntaxKind.ExpressionStatement]: ExpressionStatement, + [SyntaxKind.IfStatement]: IfStatement, + [SyntaxKind.DoStatement]: DoStatement, + [SyntaxKind.WhileStatement]: WhileStatement, + [SyntaxKind.ForStatement]: ForStatement, + [SyntaxKind.ForInStatement]: ForInStatement, + [SyntaxKind.ForOfStatement]: ForOfStatement, + [SyntaxKind.BreakStatement]: BreakStatement, + [SyntaxKind.ContinueStatement]: ContinueStatement, + [SyntaxKind.ReturnStatement]: ReturnStatement, + [SyntaxKind.WithStatement]: WithStatement, + [SyntaxKind.SwitchStatement]: SwitchStatement, + [SyntaxKind.CaseBlock]: CaseBlock, + [SyntaxKind.CaseClause]: CaseClause, + [SyntaxKind.DefaultClause]: DefaultClause, + [SyntaxKind.LabeledStatement]: LabeledStatement, + [SyntaxKind.ThrowStatement]: ThrowStatement, + [SyntaxKind.TryStatement]: TryStatement, + [SyntaxKind.CatchClause]: CatchClause, + [SyntaxKind.ClassDeclaration]: ClassDeclaration, + [SyntaxKind.ClassExpression]: ClassExpression, + [SyntaxKind.InterfaceDeclaration]: InterfaceDeclaration, + [SyntaxKind.HeritageClause]: HeritageClause, + [SyntaxKind.TypeAliasDeclaration]: TypeAliasDeclaration, + [SyntaxKind.EnumMember]: EnumMember, + [SyntaxKind.EnumDeclaration]: EnumDeclaration, + [SyntaxKind.ModuleDeclaration]: ModuleDeclaration, + [SyntaxKind.ModuleBlock]: ModuleBlock, + [SyntaxKind.ImportEqualsDeclaration]: ImportEqualsDeclaration, + [SyntaxKind.ExternalModuleReference]: ExternalModuleReference, + [SyntaxKind.ImportDeclaration]: ImportDeclaration, + [SyntaxKind.ImportClause]: ImportClause, + [SyntaxKind.ImportAttribute]: ImportAttribute, + [SyntaxKind.ImportAttributes]: ImportAttributes, + [SyntaxKind.NamespaceImport]: NamespaceImport, + [SyntaxKind.NamespaceExport]: NamespaceExport, + [SyntaxKind.NamespaceExportDeclaration]: NamespaceExportDeclaration, + [SyntaxKind.ExportDeclaration]: ExportDeclaration, + [SyntaxKind.NamedImports]: NamedImports, + [SyntaxKind.NamedExports]: NamedExports, + [SyntaxKind.ImportSpecifier]: ImportSpecifier, + [SyntaxKind.ExportSpecifier]: ExportSpecifier, + [SyntaxKind.ExportAssignment]: ExportAssignment, + [SyntaxKind.JSDocTypeExpression]: JSDocTypeExpression, + [SyntaxKind.JSDocNameReference]: JSDocNameReference, + [SyntaxKind.JSDocMemberName]: JSDocMemberName, + [SyntaxKind.JSDocAllType]: JSDocAllType, + [SyntaxKind.JSDocUnknownType]: JSDocUnknownType, + [SyntaxKind.JSDocNonNullableType]: JSDocNonNullableType, + [SyntaxKind.JSDocNullableType]: JSDocNullableType, + [SyntaxKind.JSDocOptionalType]: JSDocOptionalType, + [SyntaxKind.JSDocFunctionType]: JSDocFunctionType, + [SyntaxKind.JSDocVariadicType]: JSDocVariadicType, + [SyntaxKind.JSDocNamepathType]: JSDocNamepathType, + [SyntaxKind.JSDoc]: JSDocNode, + [SyntaxKind.JSDocLink]: JSDocLink, + [SyntaxKind.JSDocLinkCode]: JSDocLinkCode, + [SyntaxKind.JSDocLinkPlain]: JSDocLinkPlain, + [SyntaxKind.JSDocText]: JSDocText, + [SyntaxKind.JSDocTag]: JSDocUnknownTag, + [SyntaxKind.JSDocAugmentsTag]: JSDocAugmentsTag, + [SyntaxKind.JSDocImplementsTag]: JSDocImplementsTag, + [SyntaxKind.JSDocAuthorTag]: JSDocAuthorTag, + [SyntaxKind.JSDocDeprecatedTag]: JSDocDeprecatedTag, + [SyntaxKind.JSDocClassTag]: JSDocClassTag, + [SyntaxKind.JSDocPublicTag]: JSDocPublicTag, + [SyntaxKind.JSDocPrivateTag]: JSDocPrivateTag, + [SyntaxKind.JSDocProtectedTag]: JSDocProtectedTag, + [SyntaxKind.JSDocReadonlyTag]: JSDocReadonlyTag, + [SyntaxKind.JSDocOverrideTag]: JSDocOverrideTag, + [SyntaxKind.JSDocEnumTag]: JSDocEnumTag, + [SyntaxKind.JSDocThisTag]: JSDocThisTag, + [SyntaxKind.JSDocTemplateTag]: JSDocTemplateTag, + [SyntaxKind.JSDocSeeTag]: JSDocSeeTag, + [SyntaxKind.JSDocReturnTag]: JSDocReturnTag, + [SyntaxKind.JSDocTypeTag]: JSDocTypeTag, + [SyntaxKind.JSDocTypedefTag]: JSDocTypedefTag, + [SyntaxKind.JSDocCallbackTag]: JSDocCallbackTag, + [SyntaxKind.JSDocOverloadTag]: JSDocOverloadTag, + [SyntaxKind.JSDocThrowsTag]: JSDocThrowsTag, + [SyntaxKind.JSDocSignature]: JSDocSignature, + [SyntaxKind.JSDocPropertyTag]: JSDocPropertyTag, + [SyntaxKind.JSDocParameterTag]: JSDocParameterTag, + [SyntaxKind.JSDocTypeLiteral]: JSDocTypeLiteral, + [SyntaxKind.JSDocSatisfiesTag]: JSDocSatisfiesTag, + [SyntaxKind.JSDocImportTag]: JSDocImportTag, + [SyntaxKind.SourceFile]: SourceFile, + [SyntaxKind.Bundle]: Bundle, + [SyntaxKind.SyntaxList]: SyntaxList, + [SyntaxKind.NotEmittedStatement]: NotEmittedStatement, + [SyntaxKind.NotEmittedTypeElement]: NotEmittedTypeElement, + [SyntaxKind.PartiallyEmittedExpression]: PartiallyEmittedExpression, + [SyntaxKind.CommaListExpression]: CommaListExpression, + [SyntaxKind.SyntheticReferenceExpression]: SyntheticReferenceExpression, + [SyntaxKind.Count]: never, + [SyntaxKind.NonTextFileMarkerTrivia]: never, +} + +/** @internal */ +export interface AstNodeType { + [SyntaxKind.Unknown]: AstToken, + [SyntaxKind.EndOfFileToken]: AstEndOfFileToken, + [SyntaxKind.SingleLineCommentTrivia]: AstToken, + [SyntaxKind.MultiLineCommentTrivia]: AstToken, + [SyntaxKind.NewLineTrivia]: AstToken, + [SyntaxKind.WhitespaceTrivia]: AstToken, + [SyntaxKind.ShebangTrivia]: AstToken, + [SyntaxKind.ConflictMarkerTrivia]: AstToken, + [SyntaxKind.NonTextFileMarkerTrivia]: never, + [SyntaxKind.NumericLiteral]: AstNumericLiteral, + [SyntaxKind.BigIntLiteral]: AstBigIntLiteral, + [SyntaxKind.StringLiteral]: AstStringLiteral, + [SyntaxKind.JsxText]: AstJsxText, + [SyntaxKind.JsxTextAllWhiteSpaces]: never, + [SyntaxKind.RegularExpressionLiteral]: AstRegularExpressionLiteral, + [SyntaxKind.NoSubstitutionTemplateLiteral]: AstNoSubstitutionTemplateLiteral, + [SyntaxKind.TemplateHead]: AstTemplateHead, + [SyntaxKind.TemplateMiddle]: AstTemplateMiddle, + [SyntaxKind.TemplateTail]: AstTemplateTail, + [SyntaxKind.OpenBraceToken]: AstToken, + [SyntaxKind.CloseBraceToken]: AstToken, + [SyntaxKind.OpenParenToken]: AstToken, + [SyntaxKind.CloseParenToken]: AstToken, + [SyntaxKind.OpenBracketToken]: AstToken, + [SyntaxKind.CloseBracketToken]: AstToken, + [SyntaxKind.DotToken]: AstToken, + [SyntaxKind.DotDotDotToken]: AstToken, + [SyntaxKind.SemicolonToken]: AstToken, + [SyntaxKind.CommaToken]: AstToken, + [SyntaxKind.QuestionDotToken]: AstToken, + [SyntaxKind.LessThanToken]: AstToken, + [SyntaxKind.LessThanSlashToken]: AstToken, + [SyntaxKind.GreaterThanToken]: AstToken, + [SyntaxKind.LessThanEqualsToken]: AstToken, + [SyntaxKind.GreaterThanEqualsToken]: AstToken, + [SyntaxKind.EqualsEqualsToken]: AstToken, + [SyntaxKind.ExclamationEqualsToken]: AstToken, + [SyntaxKind.EqualsEqualsEqualsToken]: AstToken, + [SyntaxKind.ExclamationEqualsEqualsToken]: AstToken, + [SyntaxKind.EqualsGreaterThanToken]: AstToken, + [SyntaxKind.PlusToken]: AstToken, + [SyntaxKind.MinusToken]: AstToken, + [SyntaxKind.AsteriskToken]: AstToken, + [SyntaxKind.AsteriskAsteriskToken]: AstToken, + [SyntaxKind.SlashToken]: AstToken, + [SyntaxKind.PercentToken]: AstToken, + [SyntaxKind.PlusPlusToken]: AstToken, + [SyntaxKind.MinusMinusToken]: AstToken, + [SyntaxKind.LessThanLessThanToken]: AstToken, + [SyntaxKind.GreaterThanGreaterThanToken]: AstToken, + [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: AstToken, + [SyntaxKind.AmpersandToken]: AstToken, + [SyntaxKind.BarToken]: AstToken, + [SyntaxKind.CaretToken]: AstToken, + [SyntaxKind.ExclamationToken]: AstToken, + [SyntaxKind.TildeToken]: AstToken, + [SyntaxKind.AmpersandAmpersandToken]: AstToken, + [SyntaxKind.BarBarToken]: AstToken, + [SyntaxKind.QuestionToken]: AstToken, + [SyntaxKind.ColonToken]: AstToken, + [SyntaxKind.AtToken]: AstToken, + [SyntaxKind.QuestionQuestionToken]: AstToken, + [SyntaxKind.BacktickToken]: AstToken, + [SyntaxKind.HashToken]: AstToken, + [SyntaxKind.EqualsToken]: AstToken, + [SyntaxKind.PlusEqualsToken]: AstToken, + [SyntaxKind.MinusEqualsToken]: AstToken, + [SyntaxKind.AsteriskEqualsToken]: AstToken, + [SyntaxKind.AsteriskAsteriskEqualsToken]: AstToken, + [SyntaxKind.SlashEqualsToken]: AstToken, + [SyntaxKind.PercentEqualsToken]: AstToken, + [SyntaxKind.LessThanLessThanEqualsToken]: AstToken, + [SyntaxKind.GreaterThanGreaterThanEqualsToken]: AstToken, + [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: AstToken, + [SyntaxKind.AmpersandEqualsToken]: AstToken, + [SyntaxKind.BarEqualsToken]: AstToken, + [SyntaxKind.BarBarEqualsToken]: AstToken, + [SyntaxKind.AmpersandAmpersandEqualsToken]: AstToken, + [SyntaxKind.QuestionQuestionEqualsToken]: AstToken, + [SyntaxKind.CaretEqualsToken]: AstToken, + [SyntaxKind.Identifier]: AstIdentifier, + [SyntaxKind.PrivateIdentifier]: AstPrivateIdentifier, + [SyntaxKind.JSDocCommentTextToken]: never, + [SyntaxKind.BreakKeyword]: AstToken, + [SyntaxKind.CaseKeyword]: AstToken, + [SyntaxKind.CatchKeyword]: AstToken, + [SyntaxKind.ClassKeyword]: AstToken, + [SyntaxKind.ConstKeyword]: AstToken, + [SyntaxKind.ContinueKeyword]: AstToken, + [SyntaxKind.DebuggerKeyword]: AstToken, + [SyntaxKind.DefaultKeyword]: AstToken, + [SyntaxKind.DeleteKeyword]: AstToken, + [SyntaxKind.DoKeyword]: AstToken, + [SyntaxKind.ElseKeyword]: AstToken, + [SyntaxKind.EnumKeyword]: AstToken, + [SyntaxKind.ExportKeyword]: AstToken, + [SyntaxKind.ExtendsKeyword]: AstToken, + [SyntaxKind.FalseKeyword]: AstFalseLiteral, + [SyntaxKind.FinallyKeyword]: AstToken, + [SyntaxKind.ForKeyword]: AstToken, + [SyntaxKind.FunctionKeyword]: AstToken, + [SyntaxKind.IfKeyword]: AstToken, + [SyntaxKind.ImportKeyword]: AstImportExpression, + [SyntaxKind.InKeyword]: AstToken, + [SyntaxKind.InstanceOfKeyword]: AstToken, + [SyntaxKind.NewKeyword]: AstToken, + [SyntaxKind.NullKeyword]: AstNullLiteral, + [SyntaxKind.ReturnKeyword]: AstToken, + [SyntaxKind.SuperKeyword]: AstSuperExpression, + [SyntaxKind.SwitchKeyword]: AstToken, + [SyntaxKind.ThisKeyword]: AstThisExpression, + [SyntaxKind.ThrowKeyword]: AstToken, + [SyntaxKind.TrueKeyword]: AstTrueLiteral, + [SyntaxKind.TryKeyword]: AstToken, + [SyntaxKind.TypeOfKeyword]: AstToken, + [SyntaxKind.VarKeyword]: AstToken, + [SyntaxKind.VoidKeyword]: AstToken, + [SyntaxKind.WhileKeyword]: AstToken, + [SyntaxKind.WithKeyword]: AstToken, + [SyntaxKind.ImplementsKeyword]: AstToken, + [SyntaxKind.InterfaceKeyword]: AstToken, + [SyntaxKind.LetKeyword]: AstToken, + [SyntaxKind.PackageKeyword]: AstToken, + [SyntaxKind.PrivateKeyword]: AstToken, + [SyntaxKind.ProtectedKeyword]: AstToken, + [SyntaxKind.PublicKeyword]: AstToken, + [SyntaxKind.StaticKeyword]: AstToken, + [SyntaxKind.YieldKeyword]: AstToken, + [SyntaxKind.AbstractKeyword]: AstToken, + [SyntaxKind.AccessorKeyword]: AstToken, + [SyntaxKind.AsKeyword]: AstToken, + [SyntaxKind.AssertsKeyword]: AstToken, + [SyntaxKind.AssertKeyword]: AstToken, + [SyntaxKind.AnyKeyword]: AstToken, + [SyntaxKind.AsyncKeyword]: AstToken, + [SyntaxKind.AwaitKeyword]: AstToken, + [SyntaxKind.BooleanKeyword]: AstToken, + [SyntaxKind.ConstructorKeyword]: AstToken, + [SyntaxKind.DeclareKeyword]: AstToken, + [SyntaxKind.GetKeyword]: AstToken, + [SyntaxKind.InferKeyword]: AstToken, + [SyntaxKind.IntrinsicKeyword]: AstToken, + [SyntaxKind.IsKeyword]: AstToken, + [SyntaxKind.KeyOfKeyword]: AstToken, + [SyntaxKind.ModuleKeyword]: AstToken, + [SyntaxKind.NamespaceKeyword]: AstToken, + [SyntaxKind.NeverKeyword]: AstToken, + [SyntaxKind.OutKeyword]: AstToken, + [SyntaxKind.ReadonlyKeyword]: AstToken, + [SyntaxKind.RequireKeyword]: AstToken, + [SyntaxKind.NumberKeyword]: AstToken, + [SyntaxKind.ObjectKeyword]: AstToken, + [SyntaxKind.SatisfiesKeyword]: AstToken, + [SyntaxKind.SetKeyword]: AstToken, + [SyntaxKind.StringKeyword]: AstToken, + [SyntaxKind.SymbolKeyword]: AstToken, + [SyntaxKind.TypeKeyword]: AstToken, + [SyntaxKind.UndefinedKeyword]: AstToken, + [SyntaxKind.UniqueKeyword]: AstToken, + [SyntaxKind.UnknownKeyword]: AstToken, + [SyntaxKind.UsingKeyword]: AstToken, + [SyntaxKind.FromKeyword]: AstToken, + [SyntaxKind.GlobalKeyword]: AstToken, + [SyntaxKind.BigIntKeyword]: AstToken, + [SyntaxKind.OverrideKeyword]: AstToken, + [SyntaxKind.OfKeyword]: AstToken, + [SyntaxKind.QualifiedName]: AstQualifiedName, + [SyntaxKind.ComputedPropertyName]: AstComputedPropertyName, + [SyntaxKind.Decorator]: AstDecorator, + [SyntaxKind.TypeParameter]: AstTypeParameterDeclaration, + [SyntaxKind.CallSignature]: AstCallSignatureDeclaration, + [SyntaxKind.ConstructSignature]: AstConstructSignatureDeclaration, + [SyntaxKind.VariableDeclaration]: AstVariableDeclaration, + [SyntaxKind.VariableDeclarationList]: AstVariableDeclarationList, + [SyntaxKind.Parameter]: AstParameterDeclaration, + [SyntaxKind.BindingElement]: AstBindingElement, + [SyntaxKind.PropertySignature]: AstPropertySignature, + [SyntaxKind.PropertyDeclaration]: AstPropertyDeclaration, + [SyntaxKind.PropertyAssignment]: AstPropertyAssignment, + [SyntaxKind.ShorthandPropertyAssignment]: AstShorthandPropertyAssignment, + [SyntaxKind.SpreadAssignment]: AstSpreadAssignment, + [SyntaxKind.ObjectBindingPattern]: AstObjectBindingPattern, + [SyntaxKind.ArrayBindingPattern]: AstArrayBindingPattern, + [SyntaxKind.FunctionDeclaration]: AstFunctionDeclaration, + [SyntaxKind.MethodSignature]: AstMethodSignature, + [SyntaxKind.MethodDeclaration]: AstMethodDeclaration, + [SyntaxKind.Constructor]: AstConstructorDeclaration, + [SyntaxKind.SemicolonClassElement]: AstSemicolonClassElement, + [SyntaxKind.GetAccessor]: AstGetAccessorDeclaration, + [SyntaxKind.SetAccessor]: AstSetAccessorDeclaration, + [SyntaxKind.IndexSignature]: AstIndexSignatureDeclaration, + [SyntaxKind.ClassStaticBlockDeclaration]: AstClassStaticBlockDeclaration, + [SyntaxKind.ImportTypeAssertionContainer]: AstImportTypeAssertionContainer, + [SyntaxKind.ImportType]: AstImportTypeNode, + [SyntaxKind.ThisType]: AstThisTypeNode, + [SyntaxKind.FunctionType]: AstFunctionTypeNode, + [SyntaxKind.ConstructorType]: AstConstructorTypeNode, + [SyntaxKind.TypeReference]: AstTypeReferenceNode, + [SyntaxKind.TypePredicate]: AstTypePredicateNode, + [SyntaxKind.TypeQuery]: AstTypeQueryNode, + [SyntaxKind.TypeLiteral]: AstTypeLiteralNode, + [SyntaxKind.ArrayType]: AstArrayTypeNode, + [SyntaxKind.TupleType]: AstTupleTypeNode, + [SyntaxKind.NamedTupleMember]: AstNamedTupleMember, + [SyntaxKind.OptionalType]: AstOptionalTypeNode, + [SyntaxKind.RestType]: AstRestTypeNode, + [SyntaxKind.UnionType]: AstUnionTypeNode, + [SyntaxKind.IntersectionType]: AstIntersectionTypeNode, + [SyntaxKind.ConditionalType]: AstConditionalTypeNode, + [SyntaxKind.InferType]: AstInferTypeNode, + [SyntaxKind.ParenthesizedType]: AstParenthesizedTypeNode, + [SyntaxKind.TypeOperator]: AstTypeOperatorNode, + [SyntaxKind.IndexedAccessType]: AstIndexedAccessTypeNode, + [SyntaxKind.MappedType]: AstMappedTypeNode, + [SyntaxKind.LiteralType]: AstLiteralTypeNode, + [SyntaxKind.TemplateLiteralType]: AstTemplateLiteralTypeNode, + [SyntaxKind.TemplateLiteralTypeSpan]: AstTemplateLiteralTypeSpan, + [SyntaxKind.OmittedExpression]: AstOmittedExpression, + [SyntaxKind.PrefixUnaryExpression]: AstPrefixUnaryExpression, + [SyntaxKind.PostfixUnaryExpression]: AstPostfixUnaryExpression, + [SyntaxKind.DeleteExpression]: AstDeleteExpression, + [SyntaxKind.TypeOfExpression]: AstTypeOfExpression, + [SyntaxKind.VoidExpression]: AstVoidExpression, + [SyntaxKind.AwaitExpression]: AstAwaitExpression, + [SyntaxKind.YieldExpression]: AstYieldExpression, + [SyntaxKind.BinaryExpression]: AstBinaryExpression, + [SyntaxKind.ConditionalExpression]: AstConditionalExpression, + [SyntaxKind.FunctionExpression]: AstFunctionExpression, + [SyntaxKind.ArrowFunction]: AstArrowFunction, + [SyntaxKind.TemplateExpression]: AstTemplateExpression, + [SyntaxKind.TemplateSpan]: AstTemplateSpan, + [SyntaxKind.ParenthesizedExpression]: AstParenthesizedExpression, + [SyntaxKind.ArrayLiteralExpression]: AstArrayLiteralExpression, + [SyntaxKind.SpreadElement]: AstSpreadElement, + [SyntaxKind.ObjectLiteralExpression]: AstObjectLiteralExpression, + [SyntaxKind.PropertyAccessExpression]: AstPropertyAccessExpression, + [SyntaxKind.ElementAccessExpression]: AstElementAccessExpression, + [SyntaxKind.CallExpression]: AstCallExpression, + [SyntaxKind.ExpressionWithTypeArguments]: AstExpressionWithTypeArguments, + [SyntaxKind.NewExpression]: AstNewExpression, + [SyntaxKind.TaggedTemplateExpression]: AstTaggedTemplateExpression, + [SyntaxKind.AsExpression]: AstAsExpression, + [SyntaxKind.TypeAssertionExpression]: AstTypeAssertion, + [SyntaxKind.SyntheticExpression]: AstSyntheticExpression, + [SyntaxKind.SatisfiesExpression]: AstSatisfiesExpression, + [SyntaxKind.NonNullExpression]: AstNonNullExpression, + [SyntaxKind.MetaProperty]: AstMetaProperty, + [SyntaxKind.JsxElement]: AstJsxElement, + [SyntaxKind.JsxAttributes]: AstJsxAttributes, + [SyntaxKind.JsxNamespacedName]: AstJsxNamespacedName, + [SyntaxKind.JsxOpeningElement]: AstJsxOpeningElement, + [SyntaxKind.JsxSelfClosingElement]: AstJsxSelfClosingElement, + [SyntaxKind.JsxFragment]: AstJsxFragment, + [SyntaxKind.JsxOpeningFragment]: AstJsxOpeningFragment, + [SyntaxKind.JsxClosingFragment]: AstJsxClosingFragment, + [SyntaxKind.JsxAttribute]: AstJsxAttribute, + [SyntaxKind.JsxSpreadAttribute]: AstJsxSpreadAttribute, + [SyntaxKind.JsxClosingElement]: AstJsxClosingElement, + [SyntaxKind.JsxExpression]: AstJsxExpression, + [SyntaxKind.EmptyStatement]: AstEmptyStatement, + [SyntaxKind.DebuggerStatement]: AstDebuggerStatement, + [SyntaxKind.MissingDeclaration]: AstMissingDeclaration, + [SyntaxKind.Block]: AstBlock, + [SyntaxKind.VariableStatement]: AstVariableStatement, + [SyntaxKind.ExpressionStatement]: AstExpressionStatement, + [SyntaxKind.IfStatement]: AstIfStatement, + [SyntaxKind.DoStatement]: AstDoStatement, + [SyntaxKind.WhileStatement]: AstWhileStatement, + [SyntaxKind.ForStatement]: AstForStatement, + [SyntaxKind.ForInStatement]: AstForInStatement, + [SyntaxKind.ForOfStatement]: AstForOfStatement, + [SyntaxKind.BreakStatement]: AstBreakStatement, + [SyntaxKind.ContinueStatement]: AstContinueStatement, + [SyntaxKind.ReturnStatement]: AstReturnStatement, + [SyntaxKind.WithStatement]: AstWithStatement, + [SyntaxKind.SwitchStatement]: AstSwitchStatement, + [SyntaxKind.CaseBlock]: AstCaseBlock, + [SyntaxKind.CaseClause]: AstCaseClause, + [SyntaxKind.DefaultClause]: AstDefaultClause, + [SyntaxKind.LabeledStatement]: AstLabeledStatement, + [SyntaxKind.ThrowStatement]: AstThrowStatement, + [SyntaxKind.TryStatement]: AstTryStatement, + [SyntaxKind.CatchClause]: AstCatchClause, + [SyntaxKind.ClassDeclaration]: AstClassDeclaration, + [SyntaxKind.ClassExpression]: AstClassExpression, + [SyntaxKind.InterfaceDeclaration]: AstInterfaceDeclaration, + [SyntaxKind.HeritageClause]: AstHeritageClause, + [SyntaxKind.TypeAliasDeclaration]: AstTypeAliasDeclaration, + [SyntaxKind.EnumMember]: AstEnumMember, + [SyntaxKind.EnumDeclaration]: AstEnumDeclaration, + [SyntaxKind.ModuleDeclaration]: AstModuleDeclaration, + [SyntaxKind.ModuleBlock]: AstModuleBlock, + [SyntaxKind.ImportEqualsDeclaration]: AstImportEqualsDeclaration, + [SyntaxKind.ExternalModuleReference]: AstExternalModuleReference, + [SyntaxKind.ImportDeclaration]: AstImportDeclaration, + [SyntaxKind.ImportClause]: AstImportClause, + [SyntaxKind.ImportAttribute]: AstImportAttribute, + [SyntaxKind.ImportAttributes]: AstImportAttributes, + [SyntaxKind.NamespaceImport]: AstNamespaceImport, + [SyntaxKind.NamespaceExport]: AstNamespaceExport, + [SyntaxKind.NamespaceExportDeclaration]: AstNamespaceExportDeclaration, + [SyntaxKind.ExportDeclaration]: AstExportDeclaration, + [SyntaxKind.NamedImports]: AstNamedImports, + [SyntaxKind.NamedExports]: AstNamedExports, + [SyntaxKind.ImportSpecifier]: AstImportSpecifier, + [SyntaxKind.ExportSpecifier]: AstExportSpecifier, + [SyntaxKind.ExportAssignment]: AstExportAssignment, + [SyntaxKind.JSDocTypeExpression]: AstJSDocTypeExpression, + [SyntaxKind.JSDocNameReference]: AstJSDocNameReference, + [SyntaxKind.JSDocMemberName]: AstJSDocMemberName, + [SyntaxKind.JSDocAllType]: AstJSDocAllType, + [SyntaxKind.JSDocUnknownType]: AstJSDocUnknownType, + [SyntaxKind.JSDocNonNullableType]: AstJSDocNonNullableType, + [SyntaxKind.JSDocNullableType]: AstJSDocNullableType, + [SyntaxKind.JSDocOptionalType]: AstJSDocOptionalType, + [SyntaxKind.JSDocFunctionType]: AstJSDocFunctionType, + [SyntaxKind.JSDocVariadicType]: AstJSDocVariadicType, + [SyntaxKind.JSDocNamepathType]: AstJSDocNamepathType, + [SyntaxKind.JSDoc]: AstJSDocNode, + [SyntaxKind.JSDocLink]: AstJSDocLink, + [SyntaxKind.JSDocLinkCode]: AstJSDocLinkCode, + [SyntaxKind.JSDocLinkPlain]: AstJSDocLinkPlain, + [SyntaxKind.JSDocText]: AstJSDocText, + [SyntaxKind.JSDocTag]: AstJSDocUnknownTag, + [SyntaxKind.JSDocAugmentsTag]: AstJSDocAugmentsTag, + [SyntaxKind.JSDocImplementsTag]: AstJSDocImplementsTag, + [SyntaxKind.JSDocAuthorTag]: AstJSDocAuthorTag, + [SyntaxKind.JSDocDeprecatedTag]: AstJSDocDeprecatedTag, + [SyntaxKind.JSDocClassTag]: AstJSDocClassTag, + [SyntaxKind.JSDocPublicTag]: AstJSDocPublicTag, + [SyntaxKind.JSDocPrivateTag]: AstJSDocPrivateTag, + [SyntaxKind.JSDocProtectedTag]: AstJSDocProtectedTag, + [SyntaxKind.JSDocReadonlyTag]: AstJSDocReadonlyTag, + [SyntaxKind.JSDocOverrideTag]: AstJSDocOverrideTag, + [SyntaxKind.JSDocEnumTag]: AstJSDocEnumTag, + [SyntaxKind.JSDocThisTag]: AstJSDocThisTag, + [SyntaxKind.JSDocTemplateTag]: AstJSDocTemplateTag, + [SyntaxKind.JSDocSeeTag]: AstJSDocSeeTag, + [SyntaxKind.JSDocReturnTag]: AstJSDocReturnTag, + [SyntaxKind.JSDocTypeTag]: AstJSDocTypeTag, + [SyntaxKind.JSDocTypedefTag]: AstJSDocTypedefTag, + [SyntaxKind.JSDocCallbackTag]: AstJSDocCallbackTag, + [SyntaxKind.JSDocOverloadTag]: AstJSDocOverloadTag, + [SyntaxKind.JSDocThrowsTag]: AstJSDocThrowsTag, + [SyntaxKind.JSDocSignature]: AstJSDocSignature, + [SyntaxKind.JSDocPropertyTag]: AstJSDocPropertyTag, + [SyntaxKind.JSDocParameterTag]: AstJSDocParameterTag, + [SyntaxKind.JSDocTypeLiteral]: AstJSDocTypeLiteral, + [SyntaxKind.JSDocSatisfiesTag]: AstJSDocSatisfiesTag, + [SyntaxKind.JSDocImportTag]: AstJSDocImportTag, + [SyntaxKind.SourceFile]: AstSourceFile, + [SyntaxKind.Bundle]: AstBundle, + [SyntaxKind.SyntaxList]: AstSyntaxList, + [SyntaxKind.NotEmittedStatement]: AstNotEmittedStatement, + [SyntaxKind.NotEmittedTypeElement]: AstNotEmittedTypeElement, + [SyntaxKind.PartiallyEmittedExpression]: AstPartiallyEmittedExpression, + [SyntaxKind.CommaListExpression]: AstCommaListExpression, + [SyntaxKind.SyntheticReferenceExpression]: AstSyntheticReferenceExpression, + [SyntaxKind.Count]: never, + [SyntaxKind.NonTextFileMarkerTrivia]: never, +} diff --git a/src/compiler/debug.ts b/src/compiler/debug.ts index 7468b2aeceaaa..be5d6400c7d3d 100644 --- a/src/compiler/debug.ts +++ b/src/compiler/debug.ts @@ -11,53 +11,12 @@ import { FlowLabel, FlowNode, FlowSwitchClause, - getEffectiveModifierFlagsNoCache, - getEmitFlags, getOwnKeys, - getParseTreeNode, getSourceFileOfNode, getSourceTextOfNodeFromSourceFile, hasProperty, - idText, IntrinsicType, - isArrayTypeNode, - isBigIntLiteral, - isCallSignatureDeclaration, - isConditionalTypeNode, - isConstructorDeclaration, - isConstructorTypeNode, - isConstructSignatureDeclaration, isDefaultClause, - isFunctionTypeNode, - isGeneratedIdentifier, - isGetAccessorDeclaration, - isIdentifier, - isImportTypeNode, - isIndexedAccessTypeNode, - isIndexSignatureDeclaration, - isInferTypeNode, - isIntersectionTypeNode, - isLiteralTypeNode, - isMappedTypeNode, - isNamedTupleMember, - isNumericLiteral, - isOptionalTypeNode, - isParameter, - isParenthesizedTypeNode, - isParseTreeNode, - isPrivateIdentifier, - isRestTypeNode, - isSetAccessorDeclaration, - isStringLiteral, - isThisTypeNode, - isTupleTypeNode, - isTypeLiteralNode, - isTypeOperatorNode, - isTypeParameterDeclaration, - isTypePredicateNode, - isTypeQueryNode, - isTypeReferenceNode, - isUnionTypeNode, LiteralType, map, MatchingKeys, @@ -67,7 +26,6 @@ import { NodeArray, NodeCheckFlags, NodeFlags, - nodeIsSynthesized, noop, objectAllocator, ObjectFlags, @@ -362,8 +320,7 @@ export namespace Debug { * This is useful in cases where we switch on `node.kind` and can be reasonably sure the type is accurate, and * as a result can reduce the number of unnecessary casts. */ - export function type(value: unknown): asserts value is T; - export function type(_value: unknown) {} + export function type(value: unknown): asserts value is T {} export function getFunctionName(func: AnyFunction) { if (typeof func !== "function") { @@ -607,6 +564,16 @@ export namespace Debug { } } + const debugInfoRegistrations: (() => void)[] = []; + export function registerDebugInfo(cb: () => void) { + if (isDebugInfoEnabled) { + cb(); + } + else { + debugInfoRegistrations.push(cb); + } + } + /** * Injects debug information into frequently used types. */ @@ -615,8 +582,6 @@ export namespace Debug { // avoid recomputing const weakTypeTextMap = new WeakMap(); - const weakNodeTextMap = new WeakMap(); - // Add additional properties in debug mode to assist with debugging. Object.defineProperties(objectAllocator.getSymbolConstructor().prototype, { // for use with vscode-js-debug's new customDescriptionGenerator in launch.json @@ -702,106 +667,10 @@ export namespace Debug { }, }); - const nodeConstructors = [ - objectAllocator.getNodeConstructor(), - objectAllocator.getIdentifierConstructor(), - objectAllocator.getTokenConstructor(), - objectAllocator.getSourceFileConstructor(), - ]; - - for (const ctor of nodeConstructors) { - if (!hasProperty(ctor.prototype, "__debugKind")) { - Object.defineProperties(ctor.prototype, { - // for use with vscode-js-debug's new customDescriptionGenerator in launch.json - __tsDebuggerDisplay: { - value(this: Node) { - const nodeHeader = isGeneratedIdentifier(this) ? "GeneratedIdentifier" : - isIdentifier(this) ? `Identifier '${idText(this)}'` : - isPrivateIdentifier(this) ? `PrivateIdentifier '${idText(this)}'` : - isStringLiteral(this) ? `StringLiteral ${JSON.stringify(this.text.length < 10 ? this.text : this.text.slice(10) + "...")}` : - isNumericLiteral(this) ? `NumericLiteral ${this.text}` : - isBigIntLiteral(this) ? `BigIntLiteral ${this.text}n` : - isTypeParameterDeclaration(this) ? "TypeParameterDeclaration" : - isParameter(this) ? "ParameterDeclaration" : - isConstructorDeclaration(this) ? "ConstructorDeclaration" : - isGetAccessorDeclaration(this) ? "GetAccessorDeclaration" : - isSetAccessorDeclaration(this) ? "SetAccessorDeclaration" : - isCallSignatureDeclaration(this) ? "CallSignatureDeclaration" : - isConstructSignatureDeclaration(this) ? "ConstructSignatureDeclaration" : - isIndexSignatureDeclaration(this) ? "IndexSignatureDeclaration" : - isTypePredicateNode(this) ? "TypePredicateNode" : - isTypeReferenceNode(this) ? "TypeReferenceNode" : - isFunctionTypeNode(this) ? "FunctionTypeNode" : - isConstructorTypeNode(this) ? "ConstructorTypeNode" : - isTypeQueryNode(this) ? "TypeQueryNode" : - isTypeLiteralNode(this) ? "TypeLiteralNode" : - isArrayTypeNode(this) ? "ArrayTypeNode" : - isTupleTypeNode(this) ? "TupleTypeNode" : - isOptionalTypeNode(this) ? "OptionalTypeNode" : - isRestTypeNode(this) ? "RestTypeNode" : - isUnionTypeNode(this) ? "UnionTypeNode" : - isIntersectionTypeNode(this) ? "IntersectionTypeNode" : - isConditionalTypeNode(this) ? "ConditionalTypeNode" : - isInferTypeNode(this) ? "InferTypeNode" : - isParenthesizedTypeNode(this) ? "ParenthesizedTypeNode" : - isThisTypeNode(this) ? "ThisTypeNode" : - isTypeOperatorNode(this) ? "TypeOperatorNode" : - isIndexedAccessTypeNode(this) ? "IndexedAccessTypeNode" : - isMappedTypeNode(this) ? "MappedTypeNode" : - isLiteralTypeNode(this) ? "LiteralTypeNode" : - isNamedTupleMember(this) ? "NamedTupleMember" : - isImportTypeNode(this) ? "ImportTypeNode" : - formatSyntaxKind(this.kind); - return `${nodeHeader}${this.flags ? ` (${formatNodeFlags(this.flags)})` : ""}`; - }, - }, - __debugKind: { - get(this: Node) { - return formatSyntaxKind(this.kind); - }, - }, - __debugNodeFlags: { - get(this: Node) { - return formatNodeFlags(this.flags); - }, - }, - __debugModifierFlags: { - get(this: Node) { - return formatModifierFlags(getEffectiveModifierFlagsNoCache(this)); - }, - }, - __debugTransformFlags: { - get(this: Node) { - return formatTransformFlags(this.transformFlags); - }, - }, - __debugIsParseTreeNode: { - get(this: Node) { - return isParseTreeNode(this); - }, - }, - __debugEmitFlags: { - get(this: Node) { - return formatEmitFlags(getEmitFlags(this)); - }, - }, - __debugGetText: { - value(this: Node, includeTrivia?: boolean) { - if (nodeIsSynthesized(this)) return ""; - // avoid recomputing - let text = weakNodeTextMap.get(this); - if (text === undefined) { - const parseNode = getParseTreeNode(this); - const sourceFile = parseNode && getSourceFileOfNode(parseNode); - text = sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : ""; - weakNodeTextMap.set(this, text); - } - return text; - }, - }, - }); - } + for (const cb of debugInfoRegistrations) { + cb(); } + debugInfoRegistrations.length = 0; isDebugInfoEnabled = true; } diff --git a/src/compiler/factory/astNodeFactory.ts b/src/compiler/factory/astNodeFactory.ts new file mode 100644 index 0000000000000..e00fae1b7f860 --- /dev/null +++ b/src/compiler/factory/astNodeFactory.ts @@ -0,0 +1,5922 @@ +import { + AstArrayBindingElement, + AstArrayBindingPattern, + AstArrayLiteralExpression, + AstArrayTypeNode, + AstArrowFunction, + AstAsExpression, + AstAssertClause, + AstAssertEntry, + AstAssertionKey, + AstAssertsKeyword, + AstAsteriskToken, + AstAwaitExpression, + AstAwaitKeyword, + AstBaseJSDocTag, + AstBigIntLiteral, + AstBinaryExpression, + AstBinaryOperatorToken, + AstBindingElement, + AstBindingName, + AstBlock, + AstBooleanLiteral, + AstBreakStatement, + AstBundle, + AstCallChain, + AstCallExpression, + AstCallSignatureDeclaration, + AstCaseBlock, + AstCaseClause, + AstCaseOrDefaultClause, + AstCatchClause, + AstClassDeclaration, + AstClassElement, + AstClassExpression, + AstClassStaticBlockDeclaration, + AstColonToken, + AstCommaListExpression, + AstComputedPropertyName, + AstConciseBody, + AstConditionalExpression, + AstConditionalTypeNode, + AstConstructorDeclaration, + AstConstructorTypeNode, + AstConstructSignatureDeclaration, + AstContinueStatement, + AstDebuggerStatement, + AstDeclarationName, + AstDecorator, + AstDefaultClause, + AstDeleteExpression, + AstDoStatement, + AstDotDotDotToken, + AstElementAccessChain, + AstElementAccessExpression, + AstEmptyStatement, + AstEndOfFileToken, + AstEntityName, + AstEnumDeclaration, + AstEnumMember, + AstEqualsGreaterThanToken, + AstExclamationToken, + AstExportAssignment, + AstExportDeclaration, + AstExportSpecifier, + AstExpression, + AstExpressionStatement, + AstExpressionWithTypeArguments, + AstExternalModuleReference, + AstFalseLiteral, + AstForInitializer, + AstForInStatement, + AstForOfStatement, + AstForStatement, + AstFunctionDeclaration, + AstFunctionExpression, + AstFunctionTypeNode, + AstGetAccessorDeclaration, + AstHeritageClause, + AstIdentifier, + AstIfStatement, + AstImportAttribute, + AstImportAttributeName, + AstImportAttributes, + AstImportClause, + AstImportDeclaration, + AstImportEqualsDeclaration, + AstImportSpecifier, + AstImportTypeAssertionContainer, + AstImportTypeNode, + AstIndexedAccessTypeNode, + AstIndexSignatureDeclaration, + AstInferTypeNode, + AstInterfaceDeclaration, + AstIntersectionTypeNode, + AstJSDocAllType, + AstJSDocAugmentsTag, + AstJSDocAuthorTag, + AstJSDocCallbackTag, + AstJSDocClassTag, + AstJSDocComment, + AstJSDocDeprecatedTag, + AstJSDocEnumTag, + AstJSDocFunctionType, + AstJSDocImplementsTag, + AstJSDocImportTag, + AstJSDocLink, + AstJSDocLinkCode, + AstJSDocLinkPlain, + AstJSDocMemberName, + AstJSDocNamepathType, + AstJSDocNameReference, + AstJSDocNamespaceBody, + AstJSDocNamespaceDeclaration, + AstJSDocNode, + AstJSDocNonNullableType, + AstJSDocNullableType, + AstJSDocOptionalType, + AstJSDocOverloadTag, + AstJSDocOverrideTag, + AstJSDocParameterTag, + AstJSDocPrivateTag, + AstJSDocPropertyLikeTag, + AstJSDocPropertyTag, + AstJSDocProtectedTag, + AstJSDocPublicTag, + AstJSDocReadonlyTag, + AstJSDocReturnTag, + AstJSDocSatisfiesTag, + AstJSDocSeeTag, + AstJSDocSignature, + AstJSDocTag, + AstJSDocTemplateTag, + AstJSDocText, + AstJSDocThisTag, + AstJSDocThrowsTag, + AstJSDocTypedefTag, + AstJSDocTypeExpression, + AstJSDocTypeLiteral, + AstJSDocTypeTag, + AstJSDocUnknownTag, + AstJSDocUnknownType, + AstJSDocVariadicType, + AstJsxAttribute, + AstJsxAttributeLike, + AstJsxAttributeName, + AstJsxAttributes, + AstJsxAttributeValue, + AstJsxChild, + AstJsxClosingElement, + AstJsxClosingFragment, + AstJsxElement, + AstJsxExpression, + AstJsxFragment, + AstJsxNamespacedName, + AstJsxOpeningElement, + AstJsxOpeningFragment, + AstJsxSelfClosingElement, + AstJsxSpreadAttribute, + AstJsxTagNameExpression, + AstJsxText, + AstKeywordToken, + AstKeywordTypeNode, + AstLabeledStatement, + AstLeftHandSideExpression, + AstLiteralToken, + AstLiteralTypeNode, + AstMappedTypeNode, + AstMemberName, + AstMetaProperty, + AstMethodDeclaration, + AstMethodSignature, + AstMinusToken, + AstMissingDeclaration, + AstModifier, + AstModifierLike, + AstModifierToken, + AstModuleBlock, + AstModuleBody, + AstModuleDeclaration, + AstModuleExportName, + AstModuleName, + AstModuleReference, + AstNamedExportBindings, + AstNamedExports, + AstNamedImportBindings, + AstNamedImports, + AstNamedTupleMember, + AstNamespaceExport, + AstNamespaceExportDeclaration, + AstNamespaceImport, + AstNewExpression, + AstNode, + AstNodeArray, + AstNonNullChain, + AstNonNullExpression, + AstNoSubstitutionTemplateLiteral, + AstNotEmittedStatement, + AstNotEmittedTypeElement, + AstNullLiteral, + AstNumericLiteral, + AstObjectBindingPattern, + AstObjectLiteralElementLike, + AstObjectLiteralExpression, + AstOmittedExpression, + AstOptionalTypeNode, + AstOuterExpression, + AstParameterDeclaration, + AstParenthesizedExpression, + AstParenthesizedTypeNode, + AstParenthesizerRules, + AstPartiallyEmittedExpression, + AstPlusToken, + AstPostfixUnaryExpression, + AstPrefixUnaryExpression, + AstPrivateIdentifier, + AstPropertyAccessChain, + AstPropertyAccessExpression, + AstPropertyAssignment, + AstPropertyDeclaration, + AstPropertyName, + AstPropertySignature, + AstPunctuationToken, + AstQualifiedName, + AstQuestionDotToken, + AstQuestionToken, + AstReadonlyKeyword, + AstRegularExpressionLiteral, + AstRestTypeNode, + AstReturnStatement, + AstSatisfiesExpression, + AstSemicolonClassElement, + AstSetAccessorDeclaration, + AstShorthandPropertyAssignment, + AstSourceFile, + AstSpreadAssignment, + AstSpreadElement, + AstStatement, + AstStringLiteral, + AstSuperExpression, + AstSwitchStatement, + AstSyntaxList, + AstSyntheticExpression, + AstSyntheticReferenceExpression, + AstTaggedTemplateExpression, + AstTemplateExpression, + AstTemplateHead, + AstTemplateLiteral, + AstTemplateLiteralToken, + AstTemplateLiteralTypeNode, + AstTemplateLiteralTypeSpan, + AstTemplateMiddle, + AstTemplateSpan, + AstTemplateTail, + AstThisExpression, + AstThisTypeNode, + AstThrowStatement, + AstToken, + AstTrueLiteral, + AstTryStatement, + AstTupleTypeNode, + AstTypeAliasDeclaration, + AstTypeAssertion, + AstTypeElement, + AstTypeLiteralNode, + AstTypeNode, + AstTypeOfExpression, + AstTypeOperatorNode, + AstTypeParameterDeclaration, + AstTypePredicateNode, + AstTypeQueryNode, + AstTypeReferenceNode, + AstUnionTypeNode, + AstVariableDeclaration, + AstVariableDeclarationList, + AstVariableStatement, + AstVoidExpression, + AstWhileStatement, + AstWithStatement, + AstYieldExpression, + createAstParenthesizerRules, + isAstBinaryExpression, + isAstCallChain, + isAstCommaListExpression, + isAstCommaToken, + isAstElementAccessChain, + isAstExclamationToken, + isAstIdentifier, + isAstNonNullChain, + isAstNotEmittedStatement, + isAstOmittedExpression, + isAstOuterExpression, + isAstParenthesizedExpression, + isAstPrivateIdentifier, + isAstPropertyAccessChain, + isAstQuestionToken, + isAstVariableDeclaration, + LiteralToken, + MetaProperty, + Node, + nullAstParenthesizerRules, + SourceFile, +} from "../_namespaces/ts.ast.js"; +import { + BinaryOperator, + cast, + CharacterCodes, + createScanner, + Debug, + EmitFlags, + escapeLeadingUnderscores, + FileReference, + getCommentRange, + getIdentifierAutoGenerate, + getIdentifierTypeArguments, + getSourceMapRange, + getSyntheticLeadingComments, + getSyntheticTrailingComments, + identity, + isParseTreeNode, + KeywordSyntaxKind, + KeywordTypeSyntaxKind, + LanguageVariant, + lastOrUndefined, + memoize, + mergeEmitNode, + ModifierFlags, + ModifierSyntaxKind, + NodeFactoryFlags, + NodeFlags, + nodeIsSynthesized, + OuterExpressionKinds, + PostfixUnaryOperator, + PrefixUnaryOperator, + PseudoBigInt, + pseudoBigIntToString, + PunctuationSyntaxKind, + RedirectInfo, + sameFlatMap, + Scanner, + ScriptTarget, + setEmitFlags, + setIdentifierAutoGenerate, + setIdentifierTypeArguments, + setTextRange, + some, + startsWith, + SyntaxKind, + TokenFlags, + TokenSyntaxKind, + Type, +} from "../_namespaces/ts.js"; + +/** @internal */ +export interface AstGeneratedNamePart { + /** an additional prefix to insert before the text sourced from `node` */ + prefix?: string; + node: AstIdentifier | AstPrivateIdentifier; + /** an additional suffix to insert after the text sourced from `node` */ + suffix?: string; +} + +/** @internal */ +export interface AstPropertyDescriptorAttributes { + enumerable?: boolean | AstExpression; + configurable?: boolean | AstExpression; + writable?: boolean | AstExpression; + value?: AstExpression; + get?: AstExpression; + set?: AstExpression; +} + +/** @internal */ +export interface AstCallBinding { + target: AstLeftHandSideExpression; + thisArg: AstExpression; +} + +/** @internal */ +export type AstVisitResult = T | AstNodeArrayLike; + +/** @internal */ +export type AstNodeArrayLike = readonly T[] | AstNodeArray; + +/** @internal */ +export interface AstNodeFactory { + /** @internal */ readonly parenthesizer: AstParenthesizerRules; + // /** @internal */ readonly converters: NodeConverters; + /** @internal */ readonly flags: NodeFactoryFlags; + + createNodeArray(elements?: readonly T[], hasTrailingComma?: boolean): AstNodeArray; + + // + // Literals + // + + createNumericLiteral(value: string | number, numericLiteralFlags?: TokenFlags): AstNumericLiteral; + createBigIntLiteral(value: string | PseudoBigInt): AstBigIntLiteral; + createStringLiteral(text: string, isSingleQuote?: boolean): AstStringLiteral; + /** @internal */ createStringLiteral(text: string, isSingleQuote?: boolean, hasExtendedUnicodeEscape?: boolean): AstStringLiteral; // eslint-disable-line @typescript-eslint/unified-signatures + createRegularExpressionLiteral(text: string): AstRegularExpressionLiteral; + + // + // Identifiers + // + + createIdentifier(text: string): AstIdentifier; + /** @internal */ createIdentifier(text: string, hasExtendedUnicodeEscape?: boolean): AstIdentifier; // eslint-disable-line @typescript-eslint/unified-signatures + + createPrivateIdentifier(text: string): AstPrivateIdentifier; + + // + // Punctuation + // + + createToken(token: SyntaxKind.SuperKeyword): AstSuperExpression; + createToken(token: SyntaxKind.ThisKeyword): AstThisExpression; + createToken(token: SyntaxKind.NullKeyword): AstNullLiteral; + createToken(token: SyntaxKind.TrueKeyword): AstTrueLiteral; + createToken(token: SyntaxKind.FalseKeyword): AstFalseLiteral; + createToken(token: SyntaxKind.EndOfFileToken): AstEndOfFileToken; + createToken(token: SyntaxKind.Unknown): AstToken; + createToken(token: TKind): AstPunctuationToken; + createToken(token: TKind): AstKeywordTypeNode; + createToken(token: TKind): AstModifierToken; + createToken(token: TKind): AstKeywordToken; + /** @internal */ createToken(token: TKind): AstToken; + + // + // Reserved words + // + + createSuper(): AstSuperExpression; + createThis(): AstThisExpression; + createNull(): AstNullLiteral; + createTrue(): AstTrueLiteral; + createFalse(): AstFalseLiteral; + + // + // Modifiers + // + + createModifier(kind: T): AstModifierToken; + createModifiersFromModifierFlags(flags: ModifierFlags): AstModifier[] | undefined; + + // + // Names + // + + createQualifiedName(left: AstEntityName, right: string | AstIdentifier): AstQualifiedName; + updateQualifiedName(node: AstQualifiedName, left: AstEntityName, right: AstIdentifier): AstQualifiedName; + createComputedPropertyName(expression: AstExpression): AstComputedPropertyName; + updateComputedPropertyName(node: AstComputedPropertyName, expression: AstExpression): AstComputedPropertyName; + + // + // Signature elements + // + + createTypeParameterDeclaration(modifiers: AstNodeArrayLike | undefined, name: string | AstIdentifier, constraint?: AstTypeNode, defaultType?: AstTypeNode): AstTypeParameterDeclaration; + updateTypeParameterDeclaration(node: AstTypeParameterDeclaration, modifiers: AstNodeArrayLike | undefined, name: AstIdentifier, constraint: AstTypeNode | undefined, defaultType: AstTypeNode | undefined): AstTypeParameterDeclaration; + createParameterDeclaration(modifiers: AstNodeArrayLike | undefined, dotDotDotToken: AstDotDotDotToken | undefined, name: string | AstBindingName, questionToken?: AstQuestionToken, type?: AstTypeNode, initializer?: AstExpression): AstParameterDeclaration; + updateParameterDeclaration(node: AstParameterDeclaration, modifiers: AstNodeArrayLike | undefined, dotDotDotToken: AstDotDotDotToken | undefined, name: string | AstBindingName, questionToken: AstQuestionToken | undefined, type: AstTypeNode | undefined, initializer: AstExpression | undefined): AstParameterDeclaration; + createDecorator(expression: AstExpression): AstDecorator; + updateDecorator(node: AstDecorator, expression: AstExpression): AstDecorator; + + // + // Type Elements + // + + createPropertySignature(modifiers: AstNodeArrayLike | undefined, name: AstPropertyName | string, questionToken: AstQuestionToken | undefined, type: AstTypeNode | undefined): AstPropertySignature; + updatePropertySignature(node: AstPropertySignature, modifiers: AstNodeArrayLike | undefined, name: AstPropertyName, questionToken: AstQuestionToken | undefined, type: AstTypeNode | undefined): AstPropertySignature; + createPropertyDeclaration(modifiers: AstNodeArrayLike | undefined, name: string | AstPropertyName, questionOrExclamationToken: AstQuestionToken | AstExclamationToken | undefined, type: AstTypeNode | undefined, initializer: AstExpression | undefined): AstPropertyDeclaration; + updatePropertyDeclaration(node: AstPropertyDeclaration, modifiers: AstNodeArrayLike | undefined, name: string | AstPropertyName, questionOrExclamationToken: AstQuestionToken | AstExclamationToken | undefined, type: AstTypeNode | undefined, initializer: AstExpression | undefined): AstPropertyDeclaration; + createMethodSignature(modifiers: AstNodeArrayLike | undefined, name: string | AstPropertyName, questionToken: AstQuestionToken | undefined, typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode | undefined): AstMethodSignature; + updateMethodSignature(node: AstMethodSignature, modifiers: AstNodeArrayLike | undefined, name: AstPropertyName, questionToken: AstQuestionToken | undefined, typeParameters: AstNodeArray | undefined, parameters: AstNodeArray, type: AstTypeNode | undefined): AstMethodSignature; + createMethodDeclaration(modifiers: AstNodeArrayLike | undefined, asteriskToken: AstAsteriskToken | undefined, name: string | AstPropertyName, questionToken: AstQuestionToken | undefined, typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode | undefined, body: AstBlock | undefined): AstMethodDeclaration; + updateMethodDeclaration(node: AstMethodDeclaration, modifiers: AstNodeArrayLike | undefined, asteriskToken: AstAsteriskToken | undefined, name: AstPropertyName, questionToken: AstQuestionToken | undefined, typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode | undefined, body: AstBlock | undefined): AstMethodDeclaration; + createConstructorDeclaration(modifiers: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, body: AstBlock | undefined): AstConstructorDeclaration; + updateConstructorDeclaration(node: AstConstructorDeclaration, modifiers: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, body: AstBlock | undefined): AstConstructorDeclaration; + createGetAccessorDeclaration(modifiers: AstNodeArrayLike | undefined, name: string | AstPropertyName, parameters: AstNodeArrayLike, type: AstTypeNode | undefined, body: AstBlock | undefined): AstGetAccessorDeclaration; + updateGetAccessorDeclaration(node: AstGetAccessorDeclaration, modifiers: AstNodeArrayLike | undefined, name: AstPropertyName, parameters: AstNodeArrayLike, type: AstTypeNode | undefined, body: AstBlock | undefined): AstGetAccessorDeclaration; + createSetAccessorDeclaration(modifiers: AstNodeArrayLike | undefined, name: string | AstPropertyName, parameters: AstNodeArrayLike, body: AstBlock | undefined): AstSetAccessorDeclaration; + updateSetAccessorDeclaration(node: AstSetAccessorDeclaration, modifiers: AstNodeArrayLike | undefined, name: AstPropertyName, parameters: AstNodeArrayLike, body: AstBlock | undefined): AstSetAccessorDeclaration; + createCallSignature(typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode | undefined): AstCallSignatureDeclaration; + updateCallSignature(node: AstCallSignatureDeclaration, typeParameters: AstNodeArray | undefined, parameters: AstNodeArray, type: AstTypeNode | undefined): AstCallSignatureDeclaration; + createConstructSignature(typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode | undefined): AstConstructSignatureDeclaration; + updateConstructSignature(node: AstConstructSignatureDeclaration, typeParameters: AstNodeArray | undefined, parameters: AstNodeArray, type: AstTypeNode | undefined): AstConstructSignatureDeclaration; + createIndexSignature(modifiers: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode): AstIndexSignatureDeclaration; + /** @internal */ createIndexSignature(modifiers: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode | undefined): AstIndexSignatureDeclaration; // eslint-disable-line @typescript-eslint/unified-signatures + updateIndexSignature(node: AstIndexSignatureDeclaration, modifiers: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode): AstIndexSignatureDeclaration; + createTemplateLiteralTypeSpan(type: AstTypeNode, literal: AstTemplateMiddle | AstTemplateTail): AstTemplateLiteralTypeSpan; + updateTemplateLiteralTypeSpan(node: AstTemplateLiteralTypeSpan, type: AstTypeNode, literal: AstTemplateMiddle | AstTemplateTail): AstTemplateLiteralTypeSpan; + createClassStaticBlockDeclaration(body: AstBlock): AstClassStaticBlockDeclaration; + updateClassStaticBlockDeclaration(node: AstClassStaticBlockDeclaration, body: AstBlock): AstClassStaticBlockDeclaration; + + // + // Types + // + + createKeywordTypeNode(kind: TKind): AstKeywordTypeNode; + createTypePredicateNode(assertsModifier: AstAssertsKeyword | undefined, parameterName: AstIdentifier | AstThisTypeNode | string, type: AstTypeNode | undefined): AstTypePredicateNode; + updateTypePredicateNode(node: AstTypePredicateNode, assertsModifier: AstAssertsKeyword | undefined, parameterName: AstIdentifier | AstThisTypeNode, type: AstTypeNode | undefined): AstTypePredicateNode; + createTypeReferenceNode(typeName: string | AstEntityName, typeArguments?: AstNodeArrayLike): AstTypeReferenceNode; + updateTypeReferenceNode(node: AstTypeReferenceNode, typeName: AstEntityName, typeArguments: AstNodeArray | undefined): AstTypeReferenceNode; + createFunctionTypeNode(typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode): AstFunctionTypeNode; + updateFunctionTypeNode(node: AstFunctionTypeNode, typeParameters: AstNodeArray | undefined, parameters: AstNodeArray, type: AstTypeNode): AstFunctionTypeNode; + createConstructorTypeNode(modifiers: AstNodeArrayLike | undefined, typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode): AstConstructorTypeNode; + updateConstructorTypeNode(node: AstConstructorTypeNode, modifiers: AstNodeArrayLike | undefined, typeParameters: AstNodeArray | undefined, parameters: AstNodeArray, type: AstTypeNode): AstConstructorTypeNode; + createTypeQueryNode(exprName: AstEntityName, typeArguments?: AstNodeArrayLike): AstTypeQueryNode; + updateTypeQueryNode(node: AstTypeQueryNode, exprName: AstEntityName, typeArguments?: AstNodeArrayLike): AstTypeQueryNode; + createTypeLiteralNode(members: AstNodeArrayLike | undefined): AstTypeLiteralNode; + updateTypeLiteralNode(node: AstTypeLiteralNode, members: AstNodeArray): AstTypeLiteralNode; + createArrayTypeNode(elementType: AstTypeNode): AstArrayTypeNode; + updateArrayTypeNode(node: AstArrayTypeNode, elementType: AstTypeNode): AstArrayTypeNode; + createTupleTypeNode(elements: AstNodeArrayLike): AstTupleTypeNode; + updateTupleTypeNode(node: AstTupleTypeNode, elements: AstNodeArrayLike): AstTupleTypeNode; + createNamedTupleMember(dotDotDotToken: AstDotDotDotToken | undefined, name: AstIdentifier, questionToken: AstQuestionToken | undefined, type: AstTypeNode): AstNamedTupleMember; + updateNamedTupleMember(node: AstNamedTupleMember, dotDotDotToken: AstDotDotDotToken | undefined, name: AstIdentifier, questionToken: AstQuestionToken | undefined, type: AstTypeNode): AstNamedTupleMember; + createOptionalTypeNode(type: AstTypeNode): AstOptionalTypeNode; + updateOptionalTypeNode(node: AstOptionalTypeNode, type: AstTypeNode): AstOptionalTypeNode; + createRestTypeNode(type: AstTypeNode): AstRestTypeNode; + updateRestTypeNode(node: AstRestTypeNode, type: AstTypeNode): AstRestTypeNode; + createUnionTypeNode(types: AstNodeArrayLike): AstUnionTypeNode; + updateUnionTypeNode(node: AstUnionTypeNode, types: AstNodeArray): AstUnionTypeNode; + createIntersectionTypeNode(types: AstNodeArrayLike): AstIntersectionTypeNode; + updateIntersectionTypeNode(node: AstIntersectionTypeNode, types: AstNodeArray): AstIntersectionTypeNode; + createConditionalTypeNode(checkType: AstTypeNode, extendsType: AstTypeNode, trueType: AstTypeNode, falseType: AstTypeNode): AstConditionalTypeNode; + updateConditionalTypeNode(node: AstConditionalTypeNode, checkType: AstTypeNode, extendsType: AstTypeNode, trueType: AstTypeNode, falseType: AstTypeNode): AstConditionalTypeNode; + createInferTypeNode(typeParameter: AstTypeParameterDeclaration): AstInferTypeNode; + updateInferTypeNode(node: AstInferTypeNode, typeParameter: AstTypeParameterDeclaration): AstInferTypeNode; + createImportTypeNode(argument: AstTypeNode, attributes?: AstImportAttributes, qualifier?: AstEntityName, typeArguments?: AstNodeArrayLike, isTypeOf?: boolean): AstImportTypeNode; + updateImportTypeNode(node: AstImportTypeNode, argument: AstTypeNode, attributes: AstImportAttributes | undefined, qualifier: AstEntityName | undefined, typeArguments: AstNodeArrayLike | undefined, isTypeOf?: boolean): AstImportTypeNode; + createParenthesizedType(type: AstTypeNode): AstParenthesizedTypeNode; + updateParenthesizedType(node: AstParenthesizedTypeNode, type: AstTypeNode): AstParenthesizedTypeNode; + createThisTypeNode(): AstThisTypeNode; + createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: AstTypeNode): AstTypeOperatorNode; + updateTypeOperatorNode(node: AstTypeOperatorNode, type: AstTypeNode): AstTypeOperatorNode; + createIndexedAccessTypeNode(objectType: AstTypeNode, indexType: AstTypeNode): AstIndexedAccessTypeNode; + updateIndexedAccessTypeNode(node: AstIndexedAccessTypeNode, objectType: AstTypeNode, indexType: AstTypeNode): AstIndexedAccessTypeNode; + createMappedTypeNode(readonlyToken: AstReadonlyKeyword | AstPlusToken | AstMinusToken | undefined, typeParameter: AstTypeParameterDeclaration, nameType: AstTypeNode | undefined, questionToken: AstQuestionToken | AstPlusToken | AstMinusToken | undefined, type: AstTypeNode | undefined, members: AstNodeArray | undefined): AstMappedTypeNode; + updateMappedTypeNode(node: AstMappedTypeNode, readonlyToken: AstReadonlyKeyword | AstPlusToken | AstMinusToken | undefined, typeParameter: AstTypeParameterDeclaration, nameType: AstTypeNode | undefined, questionToken: AstQuestionToken | AstPlusToken | AstMinusToken | undefined, type: AstTypeNode | undefined, members: AstNodeArray | undefined): AstMappedTypeNode; + createLiteralTypeNode(literal: AstLiteralTypeNode["data"]["literal"]): AstLiteralTypeNode; + updateLiteralTypeNode(node: AstLiteralTypeNode, literal: AstLiteralTypeNode["data"]["literal"]): AstLiteralTypeNode; + createTemplateLiteralType(head: AstTemplateHead, templateSpans: AstNodeArrayLike): AstTemplateLiteralTypeNode; + updateTemplateLiteralType(node: AstTemplateLiteralTypeNode, head: AstTemplateHead, templateSpans: AstNodeArrayLike): AstTemplateLiteralTypeNode; + + // + // Binding Patterns + // + + createObjectBindingPattern(elements: AstNodeArrayLike): AstObjectBindingPattern; + updateObjectBindingPattern(node: AstObjectBindingPattern, elements: AstNodeArrayLike): AstObjectBindingPattern; + createArrayBindingPattern(elements: AstNodeArrayLike): AstArrayBindingPattern; + updateArrayBindingPattern(node: AstArrayBindingPattern, elements: AstNodeArrayLike): AstArrayBindingPattern; + createBindingElement(dotDotDotToken: AstDotDotDotToken | undefined, propertyName: string | AstPropertyName | undefined, name: string | AstBindingName, initializer?: AstExpression): AstBindingElement; + updateBindingElement(node: AstBindingElement, dotDotDotToken: AstDotDotDotToken | undefined, propertyName: AstPropertyName | undefined, name: AstBindingName, initializer: AstExpression | undefined): AstBindingElement; + + // + // Expression + // + + createArrayLiteralExpression(elements?: AstNodeArrayLike, multiLine?: boolean): AstArrayLiteralExpression; + updateArrayLiteralExpression(node: AstArrayLiteralExpression, elements: AstNodeArrayLike): AstArrayLiteralExpression; + createObjectLiteralExpression(properties?: AstNodeArrayLike, multiLine?: boolean): AstObjectLiteralExpression; + updateObjectLiteralExpression(node: AstObjectLiteralExpression, properties: AstNodeArrayLike): AstObjectLiteralExpression; + createPropertyAccessExpression(expression: AstExpression, name: string | AstMemberName): AstPropertyAccessExpression; + updatePropertyAccessExpression(node: AstPropertyAccessExpression, expression: AstExpression, name: AstMemberName): AstPropertyAccessExpression; + createPropertyAccessChain(expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, name: string | AstMemberName): AstPropertyAccessChain; + updatePropertyAccessChain(node: AstPropertyAccessChain, expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, name: AstMemberName): AstPropertyAccessChain; + createElementAccessExpression(expression: AstExpression, index: number | AstExpression): AstElementAccessExpression; + updateElementAccessExpression(node: AstElementAccessExpression, expression: AstExpression, argumentExpression: AstExpression): AstElementAccessExpression; + createElementAccessChain(expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, index: number | AstExpression): AstElementAccessChain; + updateElementAccessChain(node: AstElementAccessChain, expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, argumentExpression: AstExpression): AstElementAccessChain; + createCallExpression(expression: AstExpression, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike | undefined): AstCallExpression; + updateCallExpression(node: AstCallExpression, expression: AstExpression, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike): AstCallExpression; + createCallChain(expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike | undefined): AstCallChain; + updateCallChain(node: AstCallChain, expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike): AstCallChain; + createNewExpression(expression: AstExpression, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike | undefined): AstNewExpression; + updateNewExpression(node: AstNewExpression, expression: AstExpression, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike | undefined): AstNewExpression; + createTaggedTemplateExpression(tag: AstExpression, typeArguments: AstNodeArrayLike | undefined, template: AstTemplateLiteral): AstTaggedTemplateExpression; + updateTaggedTemplateExpression(node: AstTaggedTemplateExpression, tag: AstExpression, typeArguments: AstNodeArrayLike | undefined, template: AstTemplateLiteral): AstTaggedTemplateExpression; + createTypeAssertion(type: AstTypeNode, expression: AstExpression): AstTypeAssertion; + updateTypeAssertion(node: AstTypeAssertion, type: AstTypeNode, expression: AstExpression): AstTypeAssertion; + createParenthesizedExpression(expression: AstExpression): AstParenthesizedExpression; + updateParenthesizedExpression(node: AstParenthesizedExpression, expression: AstExpression): AstParenthesizedExpression; + createFunctionExpression(modifiers: AstNodeArrayLike | undefined, asteriskToken: AstAsteriskToken | undefined, name: string | AstIdentifier | undefined, typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike | undefined, type: AstTypeNode | undefined, body: AstBlock): AstFunctionExpression; + updateFunctionExpression(node: AstFunctionExpression, modifiers: AstNodeArrayLike | undefined, asteriskToken: AstAsteriskToken | undefined, name: AstIdentifier | undefined, typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode | undefined, body: AstBlock): AstFunctionExpression; + createArrowFunction(modifiers: AstNodeArrayLike | undefined, typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode | undefined, equalsGreaterThanToken: AstEqualsGreaterThanToken | undefined, body: AstConciseBody): AstArrowFunction; + updateArrowFunction(node: AstArrowFunction, modifiers: AstNodeArrayLike | undefined, typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode | undefined, equalsGreaterThanToken: AstEqualsGreaterThanToken, body: AstConciseBody): AstArrowFunction; + createDeleteExpression(expression: AstExpression): AstDeleteExpression; + updateDeleteExpression(node: AstDeleteExpression, expression: AstExpression): AstDeleteExpression; + createTypeOfExpression(expression: AstExpression): AstTypeOfExpression; + updateTypeOfExpression(node: AstTypeOfExpression, expression: AstExpression): AstTypeOfExpression; + createVoidExpression(expression: AstExpression): AstVoidExpression; + updateVoidExpression(node: AstVoidExpression, expression: AstExpression): AstVoidExpression; + createAwaitExpression(expression: AstExpression): AstAwaitExpression; + updateAwaitExpression(node: AstAwaitExpression, expression: AstExpression): AstAwaitExpression; + createPrefixUnaryExpression(operator: PrefixUnaryOperator, operand: AstExpression): AstPrefixUnaryExpression; + updatePrefixUnaryExpression(node: AstPrefixUnaryExpression, operand: AstExpression): AstPrefixUnaryExpression; + createPostfixUnaryExpression(operand: AstExpression, operator: PostfixUnaryOperator): AstPostfixUnaryExpression; + updatePostfixUnaryExpression(node: AstPostfixUnaryExpression, operand: AstExpression): AstPostfixUnaryExpression; + createBinaryExpression(left: AstExpression, operator: BinaryOperator | AstBinaryOperatorToken, right: AstExpression): AstBinaryExpression; + updateBinaryExpression(node: AstBinaryExpression, left: AstExpression, operator: BinaryOperator | AstBinaryOperatorToken, right: AstExpression): AstBinaryExpression; + createConditionalExpression(condition: AstExpression, questionToken: AstQuestionToken | undefined, whenTrue: AstExpression, colonToken: AstColonToken | undefined, whenFalse: AstExpression): AstConditionalExpression; + updateConditionalExpression(node: AstConditionalExpression, condition: AstExpression, questionToken: AstQuestionToken, whenTrue: AstExpression, colonToken: AstColonToken, whenFalse: AstExpression): AstConditionalExpression; + createTemplateExpression(head: AstTemplateHead, templateSpans: AstNodeArrayLike): AstTemplateExpression; + updateTemplateExpression(node: AstTemplateExpression, head: AstTemplateHead, templateSpans: AstNodeArrayLike): AstTemplateExpression; + createTemplateHead(text: string, rawText?: string, templateFlags?: TokenFlags): AstTemplateHead; + createTemplateHead(text: string | undefined, rawText: string, templateFlags?: TokenFlags): AstTemplateHead; + createTemplateMiddle(text: string, rawText?: string, templateFlags?: TokenFlags): AstTemplateMiddle; + createTemplateMiddle(text: string | undefined, rawText: string, templateFlags?: TokenFlags): AstTemplateMiddle; + createTemplateTail(text: string, rawText?: string, templateFlags?: TokenFlags): AstTemplateTail; + createTemplateTail(text: string | undefined, rawText: string, templateFlags?: TokenFlags): AstTemplateTail; + createNoSubstitutionTemplateLiteral(text: string, rawText?: string): AstNoSubstitutionTemplateLiteral; + createNoSubstitutionTemplateLiteral(text: string | undefined, rawText: string): AstNoSubstitutionTemplateLiteral; + /** @internal */ createLiteralLikeNode(kind: AstLiteralToken["kind"] | SyntaxKind.JsxTextAllWhiteSpaces, text: string): AstLiteralToken; + /** @internal */ createTemplateLiteralLikeNode(kind: AstTemplateLiteralToken["kind"], text: string, rawText: string | undefined, templateFlags: TokenFlags | undefined): AstTemplateLiteralToken; + createYieldExpression(asteriskToken: AstAsteriskToken, expression: AstExpression): AstYieldExpression; + createYieldExpression(asteriskToken: undefined, expression: AstExpression | undefined): AstYieldExpression; + /** @internal */ createYieldExpression(asteriskToken: AstAsteriskToken | undefined, expression: AstExpression | undefined): AstYieldExpression; // eslint-disable-line @typescript-eslint/unified-signatures + updateYieldExpression(node: AstYieldExpression, asteriskToken: AstAsteriskToken | undefined, expression: AstExpression | undefined): AstYieldExpression; + createSpreadElement(expression: AstExpression): AstSpreadElement; + updateSpreadElement(node: AstSpreadElement, expression: AstExpression): AstSpreadElement; + createClassExpression(modifiers: AstNodeArrayLike | undefined, name: string | AstIdentifier | undefined, typeParameters: AstNodeArrayLike | undefined, heritageClauses: AstNodeArrayLike | undefined, members: AstNodeArrayLike): AstClassExpression; + updateClassExpression(node: AstClassExpression, modifiers: AstNodeArrayLike | undefined, name: AstIdentifier | undefined, typeParameters: AstNodeArrayLike | undefined, heritageClauses: AstNodeArrayLike | undefined, members: AstNodeArrayLike): AstClassExpression; + createOmittedExpression(): AstOmittedExpression; + createExpressionWithTypeArguments(expression: AstExpression, typeArguments: AstNodeArrayLike | undefined): AstExpressionWithTypeArguments; + updateExpressionWithTypeArguments(node: AstExpressionWithTypeArguments, expression: AstExpression, typeArguments: AstNodeArrayLike | undefined): AstExpressionWithTypeArguments; + createAsExpression(expression: AstExpression, type: AstTypeNode): AstAsExpression; + updateAsExpression(node: AstAsExpression, expression: AstExpression, type: AstTypeNode): AstAsExpression; + createNonNullExpression(expression: AstExpression): AstNonNullExpression; + updateNonNullExpression(node: AstNonNullExpression, expression: AstExpression): AstNonNullExpression; + createNonNullChain(expression: AstExpression): AstNonNullChain; + updateNonNullChain(node: AstNonNullChain, expression: AstExpression): AstNonNullChain; + createMetaProperty(keywordToken: MetaProperty["keywordToken"], name: AstIdentifier): AstMetaProperty; + updateMetaProperty(node: AstMetaProperty, name: AstIdentifier): AstMetaProperty; + createSatisfiesExpression(expression: AstExpression, type: AstTypeNode): AstSatisfiesExpression; + updateSatisfiesExpression(node: AstSatisfiesExpression, expression: AstExpression, type: AstTypeNode): AstSatisfiesExpression; + + // + // Misc + // + + createTemplateSpan(expression: AstExpression, literal: AstTemplateMiddle | AstTemplateTail): AstTemplateSpan; + updateTemplateSpan(node: AstTemplateSpan, expression: AstExpression, literal: AstTemplateMiddle | AstTemplateTail): AstTemplateSpan; + createSemicolonClassElement(): AstSemicolonClassElement; + + // + // Element + // + + createBlock(statements: AstNodeArrayLike, multiLine?: boolean): AstBlock; + updateBlock(node: AstBlock, statements: AstNodeArrayLike): AstBlock; + createVariableStatement(modifiers: AstNodeArrayLike | undefined, declarationList: AstVariableDeclarationList | AstNodeArrayLike): AstVariableStatement; + updateVariableStatement(node: AstVariableStatement, modifiers: AstNodeArrayLike | undefined, declarationList: AstVariableDeclarationList): AstVariableStatement; + createEmptyStatement(): AstEmptyStatement; + createExpressionStatement(expression: AstExpression): AstExpressionStatement; + updateExpressionStatement(node: AstExpressionStatement, expression: AstExpression): AstExpressionStatement; + createIfStatement(expression: AstExpression, thenStatement: AstStatement, elseStatement?: AstStatement): AstIfStatement; + updateIfStatement(node: AstIfStatement, expression: AstExpression, thenStatement: AstStatement, elseStatement: AstStatement | undefined): AstIfStatement; + createDoStatement(statement: AstStatement, expression: AstExpression): AstDoStatement; + updateDoStatement(node: AstDoStatement, statement: AstStatement, expression: AstExpression): AstDoStatement; + createWhileStatement(expression: AstExpression, statement: AstStatement): AstWhileStatement; + updateWhileStatement(node: AstWhileStatement, expression: AstExpression, statement: AstStatement): AstWhileStatement; + createForStatement(initializer: AstForInitializer | undefined, condition: AstExpression | undefined, incrementor: AstExpression | undefined, statement: AstStatement): AstForStatement; + updateForStatement(node: AstForStatement, initializer: AstForInitializer | undefined, condition: AstExpression | undefined, incrementor: AstExpression | undefined, statement: AstStatement): AstForStatement; + createForInStatement(initializer: AstForInitializer, expression: AstExpression, statement: AstStatement): AstForInStatement; + updateForInStatement(node: AstForInStatement, initializer: AstForInitializer, expression: AstExpression, statement: AstStatement): AstForInStatement; + createForOfStatement(awaitModifier: AstAwaitKeyword | undefined, initializer: AstForInitializer, expression: AstExpression, statement: AstStatement): AstForOfStatement; + updateForOfStatement(node: AstForOfStatement, awaitModifier: AstAwaitKeyword | undefined, initializer: AstForInitializer, expression: AstExpression, statement: AstStatement): AstForOfStatement; + createContinueStatement(label?: string | AstIdentifier): AstContinueStatement; + updateContinueStatement(node: AstContinueStatement, label: AstIdentifier | undefined): AstContinueStatement; + createBreakStatement(label?: string | AstIdentifier): AstBreakStatement; + updateBreakStatement(node: AstBreakStatement, label: AstIdentifier | undefined): AstBreakStatement; + createReturnStatement(expression?: AstExpression): AstReturnStatement; + updateReturnStatement(node: AstReturnStatement, expression: AstExpression | undefined): AstReturnStatement; + createWithStatement(expression: AstExpression, statement: AstStatement): AstWithStatement; + updateWithStatement(node: AstWithStatement, expression: AstExpression, statement: AstStatement): AstWithStatement; + createSwitchStatement(expression: AstExpression, caseBlock: AstCaseBlock): AstSwitchStatement; + updateSwitchStatement(node: AstSwitchStatement, expression: AstExpression, caseBlock: AstCaseBlock): AstSwitchStatement; + createLabeledStatement(label: string | AstIdentifier, statement: AstStatement): AstLabeledStatement; + updateLabeledStatement(node: AstLabeledStatement, label: AstIdentifier, statement: AstStatement): AstLabeledStatement; + createThrowStatement(expression: AstExpression): AstThrowStatement; + updateThrowStatement(node: AstThrowStatement, expression: AstExpression): AstThrowStatement; + createTryStatement(tryBlock: AstBlock, catchClause: AstCatchClause | undefined, finallyBlock: AstBlock | undefined): AstTryStatement; + updateTryStatement(node: AstTryStatement, tryBlock: AstBlock, catchClause: AstCatchClause | undefined, finallyBlock: AstBlock | undefined): AstTryStatement; + createDebuggerStatement(): AstDebuggerStatement; + createVariableDeclaration(name: string | AstBindingName, exclamationToken?: AstExclamationToken, type?: AstTypeNode, initializer?: AstExpression): AstVariableDeclaration; + updateVariableDeclaration(node: AstVariableDeclaration, name: AstBindingName, exclamationToken: AstExclamationToken | undefined, type: AstTypeNode | undefined, initializer: AstExpression | undefined): AstVariableDeclaration; + createVariableDeclarationList(declarations: AstNodeArrayLike, flags?: NodeFlags): AstVariableDeclarationList; + updateVariableDeclarationList(node: AstVariableDeclarationList, declarations: AstNodeArrayLike): AstVariableDeclarationList; + createFunctionDeclaration(modifiers: AstNodeArrayLike | undefined, asteriskToken: AstAsteriskToken | undefined, name: string | AstIdentifier | undefined, typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode | undefined, body: AstBlock | undefined): AstFunctionDeclaration; + updateFunctionDeclaration(node: AstFunctionDeclaration, modifiers: AstNodeArrayLike | undefined, asteriskToken: AstAsteriskToken | undefined, name: AstIdentifier | undefined, typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstTypeNode | undefined, body: AstBlock | undefined): AstFunctionDeclaration; + createClassDeclaration(modifiers: AstNodeArrayLike | undefined, name: string | AstIdentifier | undefined, typeParameters: AstNodeArrayLike | undefined, heritageClauses: AstNodeArrayLike | undefined, members: AstNodeArrayLike): AstClassDeclaration; + updateClassDeclaration(node: AstClassDeclaration, modifiers: AstNodeArrayLike | undefined, name: AstIdentifier | undefined, typeParameters: AstNodeArrayLike | undefined, heritageClauses: AstNodeArrayLike | undefined, members: AstNodeArrayLike): AstClassDeclaration; + createInterfaceDeclaration(modifiers: AstNodeArrayLike | undefined, name: string | AstIdentifier, typeParameters: AstNodeArrayLike | undefined, heritageClauses: AstNodeArrayLike | undefined, members: AstNodeArrayLike): AstInterfaceDeclaration; + updateInterfaceDeclaration(node: AstInterfaceDeclaration, modifiers: AstNodeArrayLike | undefined, name: AstIdentifier, typeParameters: AstNodeArrayLike | undefined, heritageClauses: AstNodeArrayLike | undefined, members: AstNodeArrayLike): AstInterfaceDeclaration; + createTypeAliasDeclaration(modifiers: AstNodeArrayLike | undefined, name: string | AstIdentifier, typeParameters: AstNodeArrayLike | undefined, type: AstTypeNode): AstTypeAliasDeclaration; + updateTypeAliasDeclaration(node: AstTypeAliasDeclaration, modifiers: AstNodeArrayLike | undefined, name: AstIdentifier, typeParameters: AstNodeArrayLike | undefined, type: AstTypeNode): AstTypeAliasDeclaration; + createEnumDeclaration(modifiers: AstNodeArrayLike | undefined, name: string | AstIdentifier, members: AstNodeArrayLike): AstEnumDeclaration; + updateEnumDeclaration(node: AstEnumDeclaration, modifiers: AstNodeArrayLike | undefined, name: AstIdentifier, members: AstNodeArrayLike): AstEnumDeclaration; + createModuleDeclaration(modifiers: AstNodeArrayLike | undefined, name: AstModuleName, body: AstModuleBody | undefined, flags?: NodeFlags): AstModuleDeclaration; + updateModuleDeclaration(node: AstModuleDeclaration, modifiers: AstNodeArrayLike | undefined, name: AstModuleName, body: AstModuleBody | undefined): AstModuleDeclaration; + createModuleBlock(statements: AstNodeArrayLike): AstModuleBlock; + updateModuleBlock(node: AstModuleBlock, statements: AstNodeArrayLike): AstModuleBlock; + createCaseBlock(clauses: AstNodeArrayLike): AstCaseBlock; + updateCaseBlock(node: AstCaseBlock, clauses: AstNodeArrayLike): AstCaseBlock; + createNamespaceExportDeclaration(name: string | AstIdentifier): AstNamespaceExportDeclaration; + updateNamespaceExportDeclaration(node: AstNamespaceExportDeclaration, name: AstIdentifier): AstNamespaceExportDeclaration; + createImportEqualsDeclaration(modifiers: AstNodeArrayLike | undefined, isTypeOnly: boolean, name: string | AstIdentifier, moduleReference: AstModuleReference): AstImportEqualsDeclaration; + updateImportEqualsDeclaration(node: AstImportEqualsDeclaration, modifiers: AstNodeArrayLike | undefined, isTypeOnly: boolean, name: AstIdentifier, moduleReference: AstModuleReference): AstImportEqualsDeclaration; + createImportDeclaration(modifiers: AstNodeArrayLike | undefined, importClause: AstImportClause | undefined, moduleSpecifier: AstExpression, attributes?: AstImportAttributes): AstImportDeclaration; + updateImportDeclaration(node: AstImportDeclaration, modifiers: AstNodeArrayLike | undefined, importClause: AstImportClause | undefined, moduleSpecifier: AstExpression, attributes: AstImportAttributes | undefined): AstImportDeclaration; + createImportClause(isTypeOnly: boolean, name: AstIdentifier | undefined, namedBindings: AstNamedImportBindings | undefined): AstImportClause; + updateImportClause(node: AstImportClause, isTypeOnly: boolean, name: AstIdentifier | undefined, namedBindings: AstNamedImportBindings | undefined): AstImportClause; + /** @deprecated */ createAssertClause(elements: AstNodeArray, multiLine?: boolean): AstAssertClause; + /** @deprecated */ updateAssertClause(node: AstAssertClause, elements: AstNodeArray, multiLine?: boolean): AstAssertClause; + /** @deprecated */ createAssertEntry(name: AstAssertionKey, value: AstExpression): AstImportAttribute; + /** @deprecated */ updateAssertEntry(node: AstImportAttribute, name: AstAssertionKey, value: AstExpression): AstImportAttribute; + /** @deprecated */ createImportTypeAssertionContainer(clause: AstAssertClause, multiLine?: boolean): AstImportTypeAssertionContainer; + /** @deprecated */ updateImportTypeAssertionContainer(node: AstImportTypeAssertionContainer, clause: AstAssertClause, multiLine?: boolean): AstImportTypeAssertionContainer; + createImportAttributes(elements: AstNodeArray, multiLine?: boolean): AstImportAttributes; + /** @internal */ createImportAttributes(elements: AstNodeArray, multiLine?: boolean, token?: AstImportAttributes["data"]["token"]): AstImportAttributes; // eslint-disable-line @typescript-eslint/unified-signatures + updateImportAttributes(node: AstImportAttributes, elements: AstNodeArray, multiLine?: boolean): AstImportAttributes; + createImportAttribute(name: AstImportAttributeName, value: AstExpression): AstImportAttribute; + updateImportAttribute(node: AstImportAttribute, name: AstImportAttributeName, value: AstExpression): AstImportAttribute; + createNamespaceImport(name: AstIdentifier): AstNamespaceImport; + updateNamespaceImport(node: AstNamespaceImport, name: AstIdentifier): AstNamespaceImport; + createNamespaceExport(name: AstModuleExportName): AstNamespaceExport; + updateNamespaceExport(node: AstNamespaceExport, name: AstModuleExportName): AstNamespaceExport; + createNamedImports(elements: AstNodeArrayLike): AstNamedImports; + updateNamedImports(node: AstNamedImports, elements: AstNodeArrayLike): AstNamedImports; + createImportSpecifier(isTypeOnly: boolean, propertyName: AstModuleExportName | undefined, name: AstIdentifier): AstImportSpecifier; + updateImportSpecifier(node: AstImportSpecifier, isTypeOnly: boolean, propertyName: AstModuleExportName | undefined, name: AstIdentifier): AstImportSpecifier; + createExportAssignment(modifiers: AstNodeArrayLike | undefined, isExportEquals: boolean | undefined, expression: AstExpression): AstExportAssignment; + updateExportAssignment(node: AstExportAssignment, modifiers: AstNodeArrayLike | undefined, expression: AstExpression): AstExportAssignment; + createExportDeclaration(modifiers: AstNodeArrayLike | undefined, isTypeOnly: boolean, exportClause: AstNamedExportBindings | undefined, moduleSpecifier?: AstExpression, attributes?: AstImportAttributes): AstExportDeclaration; + updateExportDeclaration(node: AstExportDeclaration, modifiers: AstNodeArrayLike | undefined, isTypeOnly: boolean, exportClause: AstNamedExportBindings | undefined, moduleSpecifier: AstExpression | undefined, attributes: AstImportAttributes | undefined): AstExportDeclaration; + createNamedExports(elements: AstNodeArrayLike): AstNamedExports; + updateNamedExports(node: AstNamedExports, elements: AstNodeArrayLike): AstNamedExports; + createExportSpecifier(isTypeOnly: boolean, propertyName: string | AstModuleExportName | undefined, name: string | AstModuleExportName): AstExportSpecifier; + updateExportSpecifier(node: AstExportSpecifier, isTypeOnly: boolean, propertyName: AstModuleExportName | undefined, name: AstModuleExportName): AstExportSpecifier; + /** @internal */ createMissingDeclaration(): AstMissingDeclaration; + + // + // Module references + // + + createExternalModuleReference(expression: AstExpression): AstExternalModuleReference; + updateExternalModuleReference(node: AstExternalModuleReference, expression: AstExpression): AstExternalModuleReference; + + // + // JSDoc + // + + createJSDocAllType(): AstJSDocAllType; + createJSDocUnknownType(): AstJSDocUnknownType; + createJSDocNonNullableType(type: AstTypeNode, postfix?: boolean): AstJSDocNonNullableType; + updateJSDocNonNullableType(node: AstJSDocNonNullableType, type: AstTypeNode): AstJSDocNonNullableType; + createJSDocNullableType(type: AstTypeNode, postfix?: boolean): AstJSDocNullableType; + updateJSDocNullableType(node: AstJSDocNullableType, type: AstTypeNode): AstJSDocNullableType; + createJSDocOptionalType(type: AstTypeNode): AstJSDocOptionalType; + updateJSDocOptionalType(node: AstJSDocOptionalType, type: AstTypeNode): AstJSDocOptionalType; + createJSDocFunctionType(parameters: AstNodeArrayLike, type: AstTypeNode | undefined): AstJSDocFunctionType; + updateJSDocFunctionType(node: AstJSDocFunctionType, parameters: AstNodeArrayLike, type: AstTypeNode | undefined): AstJSDocFunctionType; + createJSDocVariadicType(type: AstTypeNode): AstJSDocVariadicType; + updateJSDocVariadicType(node: AstJSDocVariadicType, type: AstTypeNode): AstJSDocVariadicType; + createJSDocNamepathType(type: AstTypeNode): AstJSDocNamepathType; + updateJSDocNamepathType(node: AstJSDocNamepathType, type: AstTypeNode): AstJSDocNamepathType; + createJSDocTypeExpression(type: AstTypeNode): AstJSDocTypeExpression; + updateJSDocTypeExpression(node: AstJSDocTypeExpression, type: AstTypeNode): AstJSDocTypeExpression; + createJSDocNameReference(name: AstEntityName | AstJSDocMemberName): AstJSDocNameReference; + updateJSDocNameReference(node: AstJSDocNameReference, name: AstEntityName | AstJSDocMemberName): AstJSDocNameReference; + createJSDocMemberName(left: AstEntityName | AstJSDocMemberName, right: AstIdentifier): AstJSDocMemberName; + updateJSDocMemberName(node: AstJSDocMemberName, left: AstEntityName | AstJSDocMemberName, right: AstIdentifier): AstJSDocMemberName; + createJSDocLink(name: AstEntityName | AstJSDocMemberName | undefined, text: string): AstJSDocLink; + updateJSDocLink(node: AstJSDocLink, name: AstEntityName | AstJSDocMemberName | undefined, text: string): AstJSDocLink; + createJSDocLinkCode(name: AstEntityName | AstJSDocMemberName | undefined, text: string): AstJSDocLinkCode; + updateJSDocLinkCode(node: AstJSDocLinkCode, name: AstEntityName | AstJSDocMemberName | undefined, text: string): AstJSDocLinkCode; + createJSDocLinkPlain(name: AstEntityName | AstJSDocMemberName | undefined, text: string): AstJSDocLinkPlain; + updateJSDocLinkPlain(node: AstJSDocLinkPlain, name: AstEntityName | AstJSDocMemberName | undefined, text: string): AstJSDocLinkPlain; + createJSDocTypeLiteral(jsDocPropertyTags?: AstNodeArrayLike, isArrayType?: boolean): AstJSDocTypeLiteral; + updateJSDocTypeLiteral(node: AstJSDocTypeLiteral, jsDocPropertyTags: AstNodeArrayLike | undefined, isArrayType: boolean | undefined): AstJSDocTypeLiteral; + createJSDocSignature(typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type?: AstJSDocReturnTag): AstJSDocSignature; + updateJSDocSignature(node: AstJSDocSignature, typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstJSDocReturnTag | undefined): AstJSDocSignature; + createJSDocTemplateTag(tagName: AstIdentifier | undefined, constraint: AstJSDocTypeExpression | undefined, typeParameters: AstNodeArrayLike, comment?: string | AstNodeArray): AstJSDocTemplateTag; + updateJSDocTemplateTag(node: AstJSDocTemplateTag, tagName: AstIdentifier | undefined, constraint: AstJSDocTypeExpression | undefined, typeParameters: AstNodeArrayLike, comment: string | AstNodeArray | undefined): AstJSDocTemplateTag; + createJSDocTypedefTag(tagName: AstIdentifier | undefined, typeExpression?: AstJSDocTypeExpression | AstJSDocTypeLiteral, fullName?: AstIdentifier | AstJSDocNamespaceDeclaration, comment?: string | AstNodeArray): AstJSDocTypedefTag; + updateJSDocTypedefTag(node: AstJSDocTypedefTag, tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression | AstJSDocTypeLiteral | undefined, fullName: AstIdentifier | AstJSDocNamespaceDeclaration | undefined, comment: string | AstNodeArray | undefined): AstJSDocTypedefTag; + createJSDocParameterTag(tagName: AstIdentifier | undefined, name: AstEntityName, isBracketed: boolean, typeExpression?: AstJSDocTypeExpression, isNameFirst?: boolean, comment?: string | AstNodeArray): AstJSDocParameterTag; + updateJSDocParameterTag(node: AstJSDocParameterTag, tagName: AstIdentifier | undefined, name: AstEntityName, isBracketed: boolean, typeExpression: AstJSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | AstNodeArray | undefined): AstJSDocParameterTag; + createJSDocPropertyTag(tagName: AstIdentifier | undefined, name: AstEntityName, isBracketed: boolean, typeExpression?: AstJSDocTypeExpression, isNameFirst?: boolean, comment?: string | AstNodeArray): AstJSDocPropertyTag; + updateJSDocPropertyTag(node: AstJSDocPropertyTag, tagName: AstIdentifier | undefined, name: AstEntityName, isBracketed: boolean, typeExpression: AstJSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | AstNodeArray | undefined): AstJSDocPropertyTag; + createJSDocTypeTag(tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression, comment?: string | AstNodeArray): AstJSDocTypeTag; + updateJSDocTypeTag(node: AstJSDocTypeTag, tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression, comment: string | AstNodeArray | undefined): AstJSDocTypeTag; + createJSDocSeeTag(tagName: AstIdentifier | undefined, nameExpression: AstJSDocNameReference | undefined, comment?: string | AstNodeArray): AstJSDocSeeTag; + updateJSDocSeeTag(node: AstJSDocSeeTag, tagName: AstIdentifier | undefined, nameExpression: AstJSDocNameReference | undefined, comment?: string | AstNodeArray): AstJSDocSeeTag; + createJSDocReturnTag(tagName: AstIdentifier | undefined, typeExpression?: AstJSDocTypeExpression, comment?: string | AstNodeArray): AstJSDocReturnTag; + updateJSDocReturnTag(node: AstJSDocReturnTag, tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression | undefined, comment: string | AstNodeArray | undefined): AstJSDocReturnTag; + createJSDocThisTag(tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression, comment?: string | AstNodeArray): AstJSDocThisTag; + updateJSDocThisTag(node: AstJSDocThisTag, tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression | undefined, comment: string | AstNodeArray | undefined): AstJSDocThisTag; + createJSDocEnumTag(tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression, comment?: string | AstNodeArray): AstJSDocEnumTag; + updateJSDocEnumTag(node: AstJSDocEnumTag, tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression, comment: string | AstNodeArray | undefined): AstJSDocEnumTag; + createJSDocCallbackTag(tagName: AstIdentifier | undefined, typeExpression: AstJSDocSignature, fullName?: AstIdentifier | AstJSDocNamespaceDeclaration, comment?: string | AstNodeArray): AstJSDocCallbackTag; + updateJSDocCallbackTag(node: AstJSDocCallbackTag, tagName: AstIdentifier | undefined, typeExpression: AstJSDocSignature, fullName: AstIdentifier | AstJSDocNamespaceDeclaration | undefined, comment: string | AstNodeArray | undefined): AstJSDocCallbackTag; + createJSDocOverloadTag(tagName: AstIdentifier | undefined, typeExpression: AstJSDocSignature, comment?: string | AstNodeArray): AstJSDocOverloadTag; + updateJSDocOverloadTag(node: AstJSDocOverloadTag, tagName: AstIdentifier | undefined, typeExpression: AstJSDocSignature, comment: string | AstNodeArray | undefined): AstJSDocOverloadTag; + createJSDocAugmentsTag(tagName: AstIdentifier | undefined, className: AstJSDocAugmentsTag["data"]["class"], comment?: string | AstNodeArray): AstJSDocAugmentsTag; + updateJSDocAugmentsTag(node: AstJSDocAugmentsTag, tagName: AstIdentifier | undefined, className: AstJSDocAugmentsTag["data"]["class"], comment: string | AstNodeArray | undefined): AstJSDocAugmentsTag; + createJSDocImplementsTag(tagName: AstIdentifier | undefined, className: AstJSDocImplementsTag["data"]["class"], comment?: string | AstNodeArray): AstJSDocImplementsTag; + updateJSDocImplementsTag(node: AstJSDocImplementsTag, tagName: AstIdentifier | undefined, className: AstJSDocImplementsTag["data"]["class"], comment: string | AstNodeArray | undefined): AstJSDocImplementsTag; + createJSDocAuthorTag(tagName: AstIdentifier | undefined, comment?: string | AstNodeArray): AstJSDocAuthorTag; + updateJSDocAuthorTag(node: AstJSDocAuthorTag, tagName: AstIdentifier | undefined, comment: string | AstNodeArray | undefined): AstJSDocAuthorTag; + createJSDocClassTag(tagName: AstIdentifier | undefined, comment?: string | AstNodeArray): AstJSDocClassTag; + updateJSDocClassTag(node: AstJSDocClassTag, tagName: AstIdentifier | undefined, comment: string | AstNodeArray | undefined): AstJSDocClassTag; + createJSDocPublicTag(tagName: AstIdentifier | undefined, comment?: string | AstNodeArray): AstJSDocPublicTag; + updateJSDocPublicTag(node: AstJSDocPublicTag, tagName: AstIdentifier | undefined, comment: string | AstNodeArray | undefined): AstJSDocPublicTag; + createJSDocPrivateTag(tagName: AstIdentifier | undefined, comment?: string | AstNodeArray): AstJSDocPrivateTag; + updateJSDocPrivateTag(node: AstJSDocPrivateTag, tagName: AstIdentifier | undefined, comment: string | AstNodeArray | undefined): AstJSDocPrivateTag; + createJSDocProtectedTag(tagName: AstIdentifier | undefined, comment?: string | AstNodeArray): AstJSDocProtectedTag; + updateJSDocProtectedTag(node: AstJSDocProtectedTag, tagName: AstIdentifier | undefined, comment: string | AstNodeArray | undefined): AstJSDocProtectedTag; + createJSDocReadonlyTag(tagName: AstIdentifier | undefined, comment?: string | AstNodeArray): AstJSDocReadonlyTag; + updateJSDocReadonlyTag(node: AstJSDocReadonlyTag, tagName: AstIdentifier | undefined, comment: string | AstNodeArray | undefined): AstJSDocReadonlyTag; + createJSDocUnknownTag(tagName: AstIdentifier, comment?: string | AstNodeArray): AstJSDocUnknownTag; + updateJSDocUnknownTag(node: AstJSDocUnknownTag, tagName: AstIdentifier, comment: string | AstNodeArray | undefined): AstJSDocUnknownTag; + createJSDocDeprecatedTag(tagName: AstIdentifier | undefined, comment?: string | AstNodeArray): AstJSDocDeprecatedTag; + updateJSDocDeprecatedTag(node: AstJSDocDeprecatedTag, tagName: AstIdentifier | undefined, comment?: string | AstNodeArray): AstJSDocDeprecatedTag; + createJSDocOverrideTag(tagName: AstIdentifier | undefined, comment?: string | AstNodeArray): AstJSDocOverrideTag; + updateJSDocOverrideTag(node: AstJSDocOverrideTag, tagName: AstIdentifier | undefined, comment?: string | AstNodeArray): AstJSDocOverrideTag; + createJSDocThrowsTag(tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression | undefined, comment?: string | AstNodeArray): AstJSDocThrowsTag; + updateJSDocThrowsTag(node: AstJSDocThrowsTag, tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression | undefined, comment?: string | AstNodeArray | undefined): AstJSDocThrowsTag; + createJSDocSatisfiesTag(tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression, comment?: string | AstNodeArray): AstJSDocSatisfiesTag; + updateJSDocSatisfiesTag(node: AstJSDocSatisfiesTag, tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression, comment: string | AstNodeArray | undefined): AstJSDocSatisfiesTag; + createJSDocImportTag(tagName: AstIdentifier | undefined, importClause: AstImportClause | undefined, moduleSpecifier: AstExpression, attributes?: AstImportAttributes, comment?: string | AstNodeArray): AstJSDocImportTag; + updateJSDocImportTag(node: AstJSDocImportTag, tagName: AstIdentifier | undefined, importClause: AstImportClause | undefined, moduleSpecifier: AstExpression, attributes: AstImportAttributes | undefined, comment: string | AstNodeArray | undefined): AstJSDocImportTag; + createJSDocText(text: string): AstJSDocText; + updateJSDocText(node: AstJSDocText, text: string): AstJSDocText; + createJSDocComment(comment?: string | AstNodeArray | undefined, tags?: AstNodeArrayLike | undefined): AstJSDocNode; + updateJSDocComment(node: AstJSDocNode, comment: string | AstNodeArray | undefined, tags: AstNodeArrayLike | undefined): AstJSDocNode; + + // + // JSX + // + + createJsxElement(openingElement: AstJsxOpeningElement, children: AstNodeArrayLike, closingElement: AstJsxClosingElement): AstJsxElement; + updateJsxElement(node: AstJsxElement, openingElement: AstJsxOpeningElement, children: AstNodeArrayLike, closingElement: AstJsxClosingElement): AstJsxElement; + createJsxSelfClosingElement(tagName: AstJsxTagNameExpression, typeArguments: AstNodeArrayLike | undefined, attributes: AstJsxAttributes): AstJsxSelfClosingElement; + updateJsxSelfClosingElement(node: AstJsxSelfClosingElement, tagName: AstJsxTagNameExpression, typeArguments: AstNodeArrayLike | undefined, attributes: AstJsxAttributes): AstJsxSelfClosingElement; + createJsxOpeningElement(tagName: AstJsxTagNameExpression, typeArguments: AstNodeArrayLike | undefined, attributes: AstJsxAttributes): AstJsxOpeningElement; + updateJsxOpeningElement(node: AstJsxOpeningElement, tagName: AstJsxTagNameExpression, typeArguments: AstNodeArrayLike | undefined, attributes: AstJsxAttributes): AstJsxOpeningElement; + createJsxClosingElement(tagName: AstJsxTagNameExpression): AstJsxClosingElement; + updateJsxClosingElement(node: AstJsxClosingElement, tagName: AstJsxTagNameExpression): AstJsxClosingElement; + createJsxFragment(openingFragment: AstJsxOpeningFragment, children: AstNodeArrayLike, closingFragment: AstJsxClosingFragment): AstJsxFragment; + createJsxText(text: string, containsOnlyTriviaWhiteSpaces?: boolean): AstJsxText; + updateJsxText(node: AstJsxText, text: string, containsOnlyTriviaWhiteSpaces?: boolean): AstJsxText; + createJsxOpeningFragment(): AstJsxOpeningFragment; + createJsxClosingFragment(): AstJsxClosingFragment; + updateJsxFragment(node: AstJsxFragment, openingFragment: AstJsxOpeningFragment, children: AstNodeArrayLike, closingFragment: AstJsxClosingFragment): AstJsxFragment; + createJsxAttribute(name: AstJsxAttributeName, initializer: AstJsxAttributeValue | undefined): AstJsxAttribute; + updateJsxAttribute(node: AstJsxAttribute, name: AstJsxAttributeName, initializer: AstJsxAttributeValue | undefined): AstJsxAttribute; + createJsxAttributes(properties: AstNodeArrayLike): AstJsxAttributes; + updateJsxAttributes(node: AstJsxAttributes, properties: AstNodeArrayLike): AstJsxAttributes; + createJsxSpreadAttribute(expression: AstExpression): AstJsxSpreadAttribute; + updateJsxSpreadAttribute(node: AstJsxSpreadAttribute, expression: AstExpression): AstJsxSpreadAttribute; + createJsxExpression(dotDotDotToken: AstDotDotDotToken | undefined, expression: AstExpression | undefined): AstJsxExpression; + updateJsxExpression(node: AstJsxExpression, expression: AstExpression | undefined): AstJsxExpression; + createJsxNamespacedName(namespace: AstIdentifier, name: AstIdentifier): AstJsxNamespacedName; + updateJsxNamespacedName(node: AstJsxNamespacedName, namespace: AstIdentifier, name: AstIdentifier): AstJsxNamespacedName; + + // + // Clauses + // + + createCaseClause(expression: AstExpression, statements: AstNodeArrayLike): AstCaseClause; + updateCaseClause(node: AstCaseClause, expression: AstExpression, statements: AstNodeArrayLike): AstCaseClause; + createDefaultClause(statements: AstNodeArrayLike): AstDefaultClause; + updateDefaultClause(node: AstDefaultClause, statements: AstNodeArrayLike): AstDefaultClause; + createHeritageClause(token: AstHeritageClause["data"]["token"], types: AstNodeArrayLike): AstHeritageClause; + updateHeritageClause(node: AstHeritageClause, types: AstNodeArrayLike): AstHeritageClause; + createCatchClause(variableDeclaration: string | AstBindingName | AstVariableDeclaration | undefined, block: AstBlock): AstCatchClause; + updateCatchClause(node: AstCatchClause, variableDeclaration: AstVariableDeclaration | undefined, block: AstBlock): AstCatchClause; + + // + // Property assignments + // + + createPropertyAssignment(name: string | AstPropertyName, initializer: AstExpression): AstPropertyAssignment; + updatePropertyAssignment(node: AstPropertyAssignment, name: AstPropertyName, initializer: AstExpression): AstPropertyAssignment; + createShorthandPropertyAssignment(name: string | AstIdentifier, objectAssignmentInitializer?: AstExpression): AstShorthandPropertyAssignment; + updateShorthandPropertyAssignment(node: AstShorthandPropertyAssignment, name: AstIdentifier, objectAssignmentInitializer: AstExpression | undefined): AstShorthandPropertyAssignment; + createSpreadAssignment(expression: AstExpression): AstSpreadAssignment; + updateSpreadAssignment(node: AstSpreadAssignment, expression: AstExpression): AstSpreadAssignment; + + // + // Enum + // + + createEnumMember(name: string | AstPropertyName, initializer?: AstExpression): AstEnumMember; + updateEnumMember(node: AstEnumMember, name: AstPropertyName, initializer: AstExpression | undefined): AstEnumMember; + + // + // Top-level nodes + // + + createSourceFile(statements: AstNodeArrayLike, endOfFileToken: AstEndOfFileToken, flags: NodeFlags): AstSourceFile; + updateSourceFile(node: AstSourceFile, statements: AstNodeArrayLike, isDeclarationFile?: boolean, referencedFiles?: readonly FileReference[], typeReferences?: readonly FileReference[], hasNoDefaultLib?: boolean, libReferences?: readonly FileReference[]): AstSourceFile; + + /** @internal */ createRedirectedSourceFile(redirectInfo: RedirectInfo): AstSourceFile; + + // + // Synthetic Nodes + // + /** @internal */ createSyntheticExpression(type: Type, isSpread?: boolean, tupleNameSource?: AstParameterDeclaration | AstNamedTupleMember): AstSyntheticExpression; + /** @internal */ createSyntaxList(children: readonly Node[]): AstSyntaxList; + + // + // Transformation nodes + // + + createNotEmittedStatement(original: AstNode): AstNotEmittedStatement; + createNotEmittedTypeElement(): AstNotEmittedTypeElement; + createPartiallyEmittedExpression(expression: AstExpression, original?: AstNode): AstPartiallyEmittedExpression; + updatePartiallyEmittedExpression(node: AstPartiallyEmittedExpression, expression: AstExpression): AstPartiallyEmittedExpression; + /** @internal */ createSyntheticReferenceExpression(expression: AstExpression, thisArg: AstExpression): AstSyntheticReferenceExpression; + /** @internal */ updateSyntheticReferenceExpression(node: AstSyntheticReferenceExpression, expression: AstExpression, thisArg: AstExpression): AstSyntheticReferenceExpression; + createCommaListExpression(elements: AstNodeArrayLike): AstCommaListExpression; + updateCommaListExpression(node: AstCommaListExpression, elements: AstNodeArrayLike): AstCommaListExpression; + createBundle(sourceFiles: readonly SourceFile[]): AstBundle; + updateBundle(node: AstBundle, sourceFiles: readonly SourceFile[]): AstBundle; + + cloneNode(node: T): T; + restoreOuterExpressions(outerExpression: AstExpression | undefined, innerExpression: AstExpression, kinds?: OuterExpressionKinds): AstExpression; + + // // + // // Common operators + // // + + // createComma(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createAssignment(left: AstObjectLiteralExpression | AstArrayLiteralExpression, right: AstExpression): AstDestructuringAssignment; + // createAssignment(left: AstExpression, right: AstExpression): AssignmentExpression; + // createLogicalOr(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createLogicalAnd(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createBitwiseOr(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createBitwiseXor(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createBitwiseAnd(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createStrictEquality(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createStrictInequality(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createEquality(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createInequality(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createLessThan(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createLessThanEquals(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createGreaterThan(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createGreaterThanEquals(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createLeftShift(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createRightShift(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createUnsignedRightShift(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createAdd(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createSubtract(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createMultiply(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createDivide(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createModulo(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createExponent(left: AstExpression, right: AstExpression): AstBinaryExpression; + // createPrefixPlus(operand: AstExpression): AstPrefixUnaryExpression; + // createPrefixMinus(operand: AstExpression): AstPrefixUnaryExpression; + // createPrefixIncrement(operand: AstExpression): AstPrefixUnaryExpression; + // createPrefixDecrement(operand: AstExpression): AstPrefixUnaryExpression; + // createBitwiseNot(operand: AstExpression): AstPrefixUnaryExpression; + // createLogicalNot(operand: AstExpression): AstPrefixUnaryExpression; + // createPostfixIncrement(operand: AstExpression): AstPostfixUnaryExpression; + // createPostfixDecrement(operand: AstExpression): AstPostfixUnaryExpression; + + // // + // // Compound Nodes + // // + + // createImmediatelyInvokedFunctionExpression(statements: AstNodeArrayLike): AstCallExpression; + // createImmediatelyInvokedFunctionExpression(statements: AstNodeArrayLike, param: AstParameterDeclaration, paramValue: AstExpression): AstCallExpression; + // createImmediatelyInvokedArrowFunction(statements: AstNodeArrayLike): AstImmediatelyInvokedArrowFunction; + // createImmediatelyInvokedArrowFunction(statements: AstNodeArrayLike, param: AstParameterDeclaration, paramValue: AstExpression): AstImmediatelyInvokedArrowFunction; + + // createVoidZero(): AstVoidExpression; + // createExportDefault(expression: AstExpression): AstExportAssignment; + // createExternalModuleExport(exportName: AstIdentifier): AstExportDeclaration; + + // /** @internal */ createTypeCheck(value: AstExpression, tag: TypeOfTag): AstExpression; + // /** @internal */ createIsNotTypeCheck(value: AstExpression, tag: TypeOfTag): AstExpression; + // /** @internal */ createMethodCall(object: AstExpression, methodName: string | AstIdentifier, argumentsList: AstNodeArrayLike): AstCallExpression; + // /** @internal */ createGlobalMethodCall(globalObjectName: string, globalMethodName: string, argumentsList: AstNodeArrayLike): AstCallExpression; + // /** @internal */ createFunctionBindCall(target: AstExpression, thisArg: AstExpression, argumentsList: AstNodeArrayLike): AstCallExpression; + // /** @internal */ createFunctionCallCall(target: AstExpression, thisArg: AstExpression, argumentsList: AstNodeArrayLike): AstCallExpression; + // /** @internal */ createFunctionApplyCall(target: AstExpression, thisArg: AstExpression, argumentsExpression: AstExpression): AstCallExpression; + // /** @internal */ createObjectDefinePropertyCall(target: AstExpression, propertyName: string | AstExpression, attributes: AstExpression): AstCallExpression; + // /** @internal */ createObjectGetOwnPropertyDescriptorCall(target: AstExpression, propertyName: string | AstExpression): AstCallExpression; + // /** @internal */ createReflectGetCall(target: AstExpression, propertyKey: AstExpression, receiver?: AstExpression): AstCallExpression; + // /** @internal */ createReflectSetCall(target: AstExpression, propertyKey: AstExpression, value: AstExpression, receiver?: AstExpression): AstCallExpression; + // /** @internal */ createPropertyDescriptor(attributes: AstPropertyDescriptorAttributes, singleLine?: boolean): AstObjectLiteralExpression; + // /** @internal */ createArraySliceCall(array: AstExpression, start?: number | AstExpression): AstCallExpression; + // /** @internal */ createArrayConcatCall(array: AstExpression, values: AstNodeArrayLike): AstCallExpression; + // /** @internal */ createCallBinding(expression: AstExpression, recordTempVariable: (temp: AstIdentifier) => void, languageVersion?: ScriptTarget, cacheIdentifiers?: boolean): AstCallBinding; + // /** + // * Wraps an expression that cannot be an assignment target in an expression that can be. + // * + // * Given a `paramName` of `_a`: + // * ``` + // * Reflect.set(obj, "x", _a) + // * ``` + // * Becomes + // * ```ts + // * ({ set value(_a) { Reflect.set(obj, "x", _a); } }).value + // * ``` + // * + // * @param paramName + // * @param expression + // * + // * @internal + // */ + // createAssignmentTargetWrapper(paramName: AstIdentifier, expression: AstExpression): AstPropertyAccessExpression; + // /** @internal */ inlineExpressions(expressions: AstNodeArrayLike): AstExpression; + // /** + // * Gets the internal name of a declaration. This is primarily used for declarations that can be + // * referred to by name in the body of an ES5 class function body. An internal name will *never* + // * be prefixed with an module or namespace export modifier like "exports." when emitted as an + // * expression. An internal name will also *never* be renamed due to a collision with a block + // * scoped variable. + // * + // * @param node The declaration. + // * @param allowComments A value indicating whether comments may be emitted for the name. + // * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. + // * + // * @internal + // */ + // getInternalName(node: AstDeclaration, allowComments?: boolean, allowSourceMaps?: boolean): AstIdentifier; + // /** + // * Gets the local name of a declaration. This is primarily used for declarations that can be + // * referred to by name in the declaration's immediate scope (classes, enums, namespaces). A + // * local name will *never* be prefixed with an module or namespace export modifier like + // * "exports." when emitted as an expression. + // * + // * @param node The declaration. + // * @param allowComments A value indicating whether comments may be emitted for the name. + // * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. + // * @param ignoreAssignedName Indicates that the assigned name of a declaration shouldn't be considered. + // * + // * @internal + // */ + // getLocalName(node: AstDeclaration, allowComments?: boolean, allowSourceMaps?: boolean, ignoreAssignedName?: boolean): AstIdentifier; + // /** + // * Gets the export name of a declaration. This is primarily used for declarations that can be + // * referred to by name in the declaration's immediate scope (classes, enums, namespaces). An + // * export name will *always* be prefixed with a module or namespace export modifier like + // * `"exports."` when emitted as an expression if the name points to an exported symbol. + // * + // * @param node The declaration. + // * @param allowComments A value indicating whether comments may be emitted for the name. + // * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. + // * + // * @internal + // */ + // getExportName(node: AstDeclaration, allowComments?: boolean, allowSourceMaps?: boolean): AstIdentifier; + // /** + // * Gets the name of a declaration for use in declarations. + // * + // * @param node The declaration. + // * @param allowComments A value indicating whether comments may be emitted for the name. + // * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. + // * + // * @internal + // */ + // getDeclarationName(node: AstDeclaration | undefined, allowComments?: boolean, allowSourceMaps?: boolean): AstIdentifier; + // /** + // * Gets a namespace-qualified name for use in expressions. + // * + // * @param ns The namespace identifier. + // * @param name The name. + // * @param allowComments A value indicating whether comments may be emitted for the name. + // * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. + // * + // * @internal + // */ + // getNamespaceMemberName(ns: AstIdentifier, name: AstIdentifier, allowComments?: boolean, allowSourceMaps?: boolean): AstPropertyAccessExpression; + // /** + // * Gets the exported name of a declaration for use in expressions. + // * + // * An exported name will *always* be prefixed with an module or namespace export modifier like + // * "exports." if the name points to an exported symbol. + // * + // * @param ns The namespace identifier. + // * @param node The declaration. + // * @param allowComments A value indicating whether comments may be emitted for the name. + // * @param allowSourceMaps A value indicating whether source maps may be emitted for the name. + // * + // * @internal + // */ + // getExternalModuleOrNamespaceExportName(ns: AstIdentifier | undefined, node: AstDeclaration, allowComments?: boolean, allowSourceMaps?: boolean): AstIdentifier | AstPropertyAccessExpression; + + // // + // // Utilities + // // + + // restoreOuterExpressions(outerExpression: AstExpression | undefined, innerExpression: AstExpression, kinds?: OuterExpressionKinds): AstExpression; + // /** @internal */ restoreEnclosingLabel(node: AstStatement, outermostLabeledStatement: AstLabeledStatement | undefined, afterRestoreLabelCallback?: (node: AstLabeledStatement) => void): AstStatement; + // /** @internal */ createUseStrictPrologue(): AstPrologueDirective; + // /** + // * Copies any necessary standard and custom prologue-directives into target array. + // * @param source origin statements array + // * @param target result statements array + // * @param ensureUseStrict boolean determining whether the function need to add prologue-directives + // * @param visitor Optional callback used to visit any custom prologue directives. + // * + // * @internal + // */ + // copyPrologue(source: AstNodeArrayLike, target: AstStatement[], ensureUseStrict?: boolean, visitor?: (node: AstNode) => AstVisitResult): number; + // /** + // * Copies only the standard (string-expression) prologue-directives into the target statement-array. + // * @param source origin statements array + // * @param target result statements array + // * @param statementOffset The offset at which to begin the copy. + // * @param ensureUseStrict boolean determining whether the function need to add prologue-directives + // * + // * @internal + // */ + // copyStandardPrologue(source: AstNodeArrayLike, target: AstStatement[], statementOffset: number | undefined, ensureUseStrict?: boolean): number; + // /** + // * Copies only the custom prologue-directives into target statement-array. + // * @param source origin statements array + // * @param target result statements array + // * @param statementOffset The offset at which to begin the copy. + // * @param visitor Optional callback used to visit any custom prologue directives. + // * + // * @internal + // */ + // copyCustomPrologue(source: AstNodeArrayLike, target: AstStatement[], statementOffset: number, visitor?: (node: AstNode) => AstVisitResult, filter?: (node: AstStatement) => boolean): number; + // /** @internal */ copyCustomPrologue(source: AstNodeArrayLike, target: AstStatement[], statementOffset: number | undefined, visitor?: (node: AstNode) => AstVisitResult, filter?: (node: AstStatement) => boolean): number | undefined; + // /** @internal */ ensureUseStrict(statements: AstNodeArray): AstNodeArray; + // /** @internal */ liftToBlock(nodes: AstNodeArrayLike): AstStatement; + // /** + // * Merges generated lexical declarations into a new statement list. + // * + // * @internal + // */ + // mergeLexicalEnvironment(statements: AstNodeArray, declarations: AstNodeArrayLike | undefined): AstNodeArray; + // /** + // * Appends generated lexical declarations to an array of statements. + // * + // * @internal + // */ + // mergeLexicalEnvironment(statements: AstStatement[], declarations: AstNodeArrayLike | undefined): AstStatement[]; + // /** + // * Creates a shallow, memberwise clone of a node. + // * - The result will have its `original` pointer set to `node`. + // * - The result will have its `pos` and `end` set to `-1`. + // * - *DO NOT USE THIS* if a more appropriate function is available. + // * + // * @internal + // */ + // cloneNode(node: T): T; + // /** + // * Updates a node that may contain modifiers, replacing only the modifiers of the node. + // */ + // replaceModifiers(node: T, modifiers: AstNodeArrayLike | ModifierFlags | undefined): T; + // /** + // * Updates a node that may contain decorators or modifiers, replacing only the decorators and modifiers of the node. + // */ + // replaceDecoratorsAndModifiers(node: T, modifiers: AstNodeArrayLike | undefined): T; + // /** + // * Updates a node that contains a property name, replacing only the name of the node. + // */ + // replacePropertyName(node: T, name: T["data"]["name"]): T; +} + +/** + * Creates a `NodeFactory` that can be used to create and update a syntax tree. + * @param flags Flags that control factory behavior. + * + * @internal + */ +export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: AstNode) => void): AstNodeFactory { + const setOriginal = flags & NodeFactoryFlags.NoOriginalNode ? identity : setOriginalNode; + + // Lazily load the parenthesizer, node converters, and some factory methods until they are used. + const parenthesizerRules = memoize(() => flags & NodeFactoryFlags.NoParenthesizerRules ? nullAstParenthesizerRules : createAstParenthesizerRules(factory)); + // const converters = memoize(() => flags & NodeFactoryFlags.NoNodeConverters ? nullNodeConverters : Debug.fail("not implemented")); + + // // lazy initializaton of common operator factories + // const getBinaryCreateFunction = memoizeOne((operator: BinaryOperator) => (left: Expression, right: Expression) => createBinaryExpression(left, operator, right)); + // const getPrefixUnaryCreateFunction = memoizeOne((operator: PrefixUnaryOperator) => (operand: Expression) => createPrefixUnaryExpression(operator, operand)); + // const getPostfixUnaryCreateFunction = memoizeOne((operator: PostfixUnaryOperator) => (operand: Expression) => createPostfixUnaryExpression(operand, operator)); + + const factory: AstNodeFactory = { + get parenthesizer() { + return parenthesizerRules(); + }, + // get converters() { + // return converters(); + // }, + flags, + createNodeArray, + createNumericLiteral, + createBigIntLiteral, + createStringLiteral, + createRegularExpressionLiteral, + createLiteralLikeNode, + createIdentifier, + createPrivateIdentifier, + createToken, + createSuper, + createThis, + createNull, + createTrue, + createFalse, + createModifier, + createModifiersFromModifierFlags, + createQualifiedName, + updateQualifiedName, + createComputedPropertyName, + updateComputedPropertyName, + createTypeParameterDeclaration, + updateTypeParameterDeclaration, + createParameterDeclaration, + updateParameterDeclaration, + createDecorator, + updateDecorator, + createPropertySignature, + updatePropertySignature, + createPropertyDeclaration, + updatePropertyDeclaration, + createMethodSignature, + updateMethodSignature, + createMethodDeclaration, + updateMethodDeclaration, + createConstructorDeclaration, + updateConstructorDeclaration, + createGetAccessorDeclaration, + updateGetAccessorDeclaration, + createSetAccessorDeclaration, + updateSetAccessorDeclaration, + createCallSignature, + updateCallSignature, + createConstructSignature, + updateConstructSignature, + createIndexSignature, + updateIndexSignature, + createClassStaticBlockDeclaration, + updateClassStaticBlockDeclaration, + createTemplateLiteralTypeSpan, + updateTemplateLiteralTypeSpan, + createKeywordTypeNode, + createTypePredicateNode, + updateTypePredicateNode, + createTypeReferenceNode, + updateTypeReferenceNode, + createFunctionTypeNode, + updateFunctionTypeNode, + createConstructorTypeNode, + updateConstructorTypeNode, + createTypeQueryNode, + updateTypeQueryNode, + createTypeLiteralNode, + updateTypeLiteralNode, + createArrayTypeNode, + updateArrayTypeNode, + createTupleTypeNode, + updateTupleTypeNode, + createNamedTupleMember, + updateNamedTupleMember, + createOptionalTypeNode, + updateOptionalTypeNode, + createRestTypeNode, + updateRestTypeNode, + createUnionTypeNode, + updateUnionTypeNode, + createIntersectionTypeNode, + updateIntersectionTypeNode, + createConditionalTypeNode, + updateConditionalTypeNode, + createInferTypeNode, + updateInferTypeNode, + createImportTypeNode, + updateImportTypeNode, + createParenthesizedType, + updateParenthesizedType, + createThisTypeNode, + createTypeOperatorNode, + updateTypeOperatorNode, + createIndexedAccessTypeNode, + updateIndexedAccessTypeNode, + createMappedTypeNode, + updateMappedTypeNode, + createLiteralTypeNode, + updateLiteralTypeNode, + createTemplateLiteralType, + updateTemplateLiteralType, + createObjectBindingPattern, + updateObjectBindingPattern, + createArrayBindingPattern, + updateArrayBindingPattern, + createBindingElement, + updateBindingElement, + createArrayLiteralExpression, + updateArrayLiteralExpression, + createObjectLiteralExpression, + updateObjectLiteralExpression, + createPropertyAccessExpression, + updatePropertyAccessExpression, + createPropertyAccessChain, + updatePropertyAccessChain, + createElementAccessExpression, + updateElementAccessExpression, + createElementAccessChain, + updateElementAccessChain, + createCallExpression, + updateCallExpression, + createCallChain, + updateCallChain, + createNewExpression, + updateNewExpression, + createTaggedTemplateExpression, + updateTaggedTemplateExpression, + createTypeAssertion, + updateTypeAssertion, + createParenthesizedExpression, + updateParenthesizedExpression, + createFunctionExpression, + updateFunctionExpression, + createArrowFunction, + updateArrowFunction, + createDeleteExpression, + updateDeleteExpression, + createTypeOfExpression, + updateTypeOfExpression, + createVoidExpression, + updateVoidExpression, + createAwaitExpression, + updateAwaitExpression, + createPrefixUnaryExpression, + updatePrefixUnaryExpression, + createPostfixUnaryExpression, + updatePostfixUnaryExpression, + createBinaryExpression, + updateBinaryExpression, + createConditionalExpression, + updateConditionalExpression, + createTemplateExpression, + updateTemplateExpression, + createTemplateHead, + createTemplateMiddle, + createTemplateTail, + createNoSubstitutionTemplateLiteral, + createTemplateLiteralLikeNode, + createYieldExpression, + updateYieldExpression, + createSpreadElement, + updateSpreadElement, + createClassExpression, + updateClassExpression, + createOmittedExpression, + createExpressionWithTypeArguments, + updateExpressionWithTypeArguments, + createAsExpression, + updateAsExpression, + createNonNullExpression, + updateNonNullExpression, + createSatisfiesExpression, + updateSatisfiesExpression, + createNonNullChain, + updateNonNullChain, + createMetaProperty, + updateMetaProperty, + createTemplateSpan, + updateTemplateSpan, + createSemicolonClassElement, + createBlock, + updateBlock, + createVariableStatement, + updateVariableStatement, + createEmptyStatement, + createExpressionStatement, + updateExpressionStatement, + createIfStatement, + updateIfStatement, + createDoStatement, + updateDoStatement, + createWhileStatement, + updateWhileStatement, + createForStatement, + updateForStatement, + createForInStatement, + updateForInStatement, + createForOfStatement, + updateForOfStatement, + createContinueStatement, + updateContinueStatement, + createBreakStatement, + updateBreakStatement, + createReturnStatement, + updateReturnStatement, + createWithStatement, + updateWithStatement, + createSwitchStatement, + updateSwitchStatement, + createLabeledStatement, + updateLabeledStatement, + createThrowStatement, + updateThrowStatement, + createTryStatement, + updateTryStatement, + createDebuggerStatement, + createVariableDeclaration, + updateVariableDeclaration, + createVariableDeclarationList, + updateVariableDeclarationList, + createFunctionDeclaration, + updateFunctionDeclaration, + createClassDeclaration, + updateClassDeclaration, + createInterfaceDeclaration, + updateInterfaceDeclaration, + createTypeAliasDeclaration, + updateTypeAliasDeclaration, + createEnumDeclaration, + updateEnumDeclaration, + createModuleDeclaration, + updateModuleDeclaration, + createModuleBlock, + updateModuleBlock, + createCaseBlock, + updateCaseBlock, + createNamespaceExportDeclaration, + updateNamespaceExportDeclaration, + createImportEqualsDeclaration, + updateImportEqualsDeclaration, + createImportDeclaration, + updateImportDeclaration, + createImportClause, + updateImportClause, + createAssertClause, + updateAssertClause, + createAssertEntry, + updateAssertEntry, + createImportTypeAssertionContainer, + updateImportTypeAssertionContainer, + createImportAttributes, + updateImportAttributes, + createImportAttribute, + updateImportAttribute, + createNamespaceImport, + updateNamespaceImport, + createNamespaceExport, + updateNamespaceExport, + createNamedImports, + updateNamedImports, + createImportSpecifier, + updateImportSpecifier, + createExportAssignment, + updateExportAssignment, + createExportDeclaration, + updateExportDeclaration, + createNamedExports, + updateNamedExports, + createExportSpecifier, + updateExportSpecifier, + createMissingDeclaration, + createExternalModuleReference, + updateExternalModuleReference, + createJSDocAllType, + createJSDocUnknownType, + createJSDocNonNullableType, + updateJSDocNonNullableType, + createJSDocNullableType, + updateJSDocNullableType, + createJSDocOptionalType, + updateJSDocOptionalType, + createJSDocVariadicType, + updateJSDocVariadicType, + createJSDocNamepathType, + updateJSDocNamepathType, + createJSDocFunctionType, + updateJSDocFunctionType, + createJSDocTypeLiteral, + updateJSDocTypeLiteral, + createJSDocTypeExpression, + updateJSDocTypeExpression, + createJSDocSignature, + updateJSDocSignature, + createJSDocTemplateTag, + updateJSDocTemplateTag, + createJSDocTypedefTag, + updateJSDocTypedefTag, + createJSDocParameterTag, + updateJSDocParameterTag, + createJSDocPropertyTag, + updateJSDocPropertyTag, + createJSDocCallbackTag, + updateJSDocCallbackTag, + createJSDocOverloadTag, + updateJSDocOverloadTag, + createJSDocAugmentsTag, + updateJSDocAugmentsTag, + createJSDocImplementsTag, + updateJSDocImplementsTag, + createJSDocSeeTag, + updateJSDocSeeTag, + createJSDocImportTag, + updateJSDocImportTag, + createJSDocNameReference, + updateJSDocNameReference, + createJSDocMemberName, + updateJSDocMemberName, + createJSDocLink, + updateJSDocLink, + createJSDocLinkCode, + updateJSDocLinkCode, + createJSDocLinkPlain, + updateJSDocLinkPlain, + createJSDocTypeTag(tagName, typeExpression, comment) { + return createJSDocTypeLikeTag(AstNode.JSDocTypeTag, tagName, typeExpression, comment); + }, + updateJSDocTypeTag(node, tagName, typeExpression, comment) { + return updateJSDocTypeLikeTag(AstNode.JSDocTypeTag, node, tagName, typeExpression, comment); + }, + createJSDocReturnTag(tagName, typeExpression, comment) { + return createJSDocTypeLikeTag(AstNode.JSDocReturnTag, tagName, typeExpression, comment); + }, + updateJSDocReturnTag(node, tagName, typeExpression, comment) { + return updateJSDocTypeLikeTag(AstNode.JSDocReturnTag, node, tagName, typeExpression, comment); + }, + createJSDocThisTag(tagName, typeExpression, comment) { + return createJSDocTypeLikeTag(AstNode.JSDocThisTag, tagName, typeExpression, comment); + }, + updateJSDocThisTag(node, tagName, typeExpression, comment) { + return updateJSDocTypeLikeTag(AstNode.JSDocThisTag, node, tagName, typeExpression, comment); + }, + createJSDocThrowsTag(tagName, typeExpression, comment) { + return createJSDocTypeLikeTag(AstNode.JSDocThrowsTag, tagName, typeExpression, comment); + }, + updateJSDocThrowsTag(node, tagName, typeExpression, comment) { + return updateJSDocTypeLikeTag(AstNode.JSDocThrowsTag, node, tagName, typeExpression, comment); + }, + createJSDocSatisfiesTag(tagName, typeExpression, comment) { + return createJSDocTypeLikeTag(AstNode.JSDocSatisfiesTag, tagName, typeExpression, comment); + }, + updateJSDocSatisfiesTag(node, tagName, typeExpression, comment) { + return updateJSDocTypeLikeTag(AstNode.JSDocSatisfiesTag, node, tagName, typeExpression, comment); + }, + createJSDocAuthorTag(tagName, comment) { + return createJSDocSimpleTag(AstNode.JSDocAuthorTag, tagName, comment); + }, + updateJSDocAuthorTag(node, tagName, comment) { + return updateJSDocSimpleTag(AstNode.JSDocAuthorTag, node, tagName, comment); + }, + createJSDocClassTag(tagName, comment) { + return createJSDocSimpleTag(AstNode.JSDocClassTag, tagName, comment); + }, + updateJSDocClassTag(node, tagName, comment) { + return updateJSDocSimpleTag(AstNode.JSDocClassTag, node, tagName, comment); + }, + createJSDocPublicTag(tagName, comment) { + return createJSDocSimpleTag(AstNode.JSDocPublicTag, tagName, comment); + }, + updateJSDocPublicTag(node, tagName, comment) { + return updateJSDocSimpleTag(AstNode.JSDocPublicTag, node, tagName, comment); + }, + createJSDocPrivateTag(tagName, comment) { + return createJSDocSimpleTag(AstNode.JSDocPrivateTag, tagName, comment); + }, + updateJSDocPrivateTag(node, tagName, comment) { + return updateJSDocSimpleTag(AstNode.JSDocPrivateTag, node, tagName, comment); + }, + createJSDocProtectedTag(tagName, comment) { + return createJSDocSimpleTag(AstNode.JSDocProtectedTag, tagName, comment); + }, + updateJSDocProtectedTag(node, tagName, comment) { + return updateJSDocSimpleTag(AstNode.JSDocProtectedTag, node, tagName, comment); + }, + createJSDocReadonlyTag(tagName, comment) { + return createJSDocSimpleTag(AstNode.JSDocReadonlyTag, tagName, comment); + }, + updateJSDocReadonlyTag(node, tagName, comment) { + return updateJSDocSimpleTag(AstNode.JSDocReadonlyTag, node, tagName, comment); + }, + createJSDocOverrideTag(tagName, comment) { + return createJSDocSimpleTag(AstNode.JSDocOverrideTag, tagName, comment); + }, + updateJSDocOverrideTag(node, tagName, comment) { + return updateJSDocSimpleTag(AstNode.JSDocOverrideTag, node, tagName, comment); + }, + createJSDocDeprecatedTag(tagName, comment) { + return createJSDocSimpleTag(AstNode.JSDocDeprecatedTag, tagName, comment); + }, + updateJSDocDeprecatedTag(node, tagName, comment) { + return updateJSDocSimpleTag(AstNode.JSDocDeprecatedTag, node, tagName, comment); + }, + + createJSDocEnumTag, + updateJSDocEnumTag, + createJSDocUnknownTag, + updateJSDocUnknownTag, + createJSDocText, + updateJSDocText, + createJSDocComment, + updateJSDocComment, + createJsxElement, + updateJsxElement, + createJsxSelfClosingElement, + updateJsxSelfClosingElement, + createJsxOpeningElement, + updateJsxOpeningElement, + createJsxClosingElement, + updateJsxClosingElement, + createJsxFragment, + createJsxText, + updateJsxText, + createJsxOpeningFragment, + createJsxClosingFragment, + updateJsxFragment, + createJsxAttribute, + updateJsxAttribute, + createJsxAttributes, + updateJsxAttributes, + createJsxSpreadAttribute, + updateJsxSpreadAttribute, + createJsxExpression, + updateJsxExpression, + createJsxNamespacedName, + updateJsxNamespacedName, + createCaseClause, + updateCaseClause, + createDefaultClause, + updateDefaultClause, + createHeritageClause, + updateHeritageClause, + createCatchClause, + updateCatchClause, + createPropertyAssignment, + updatePropertyAssignment, + createShorthandPropertyAssignment, + updateShorthandPropertyAssignment, + createSpreadAssignment, + updateSpreadAssignment, + createEnumMember, + updateEnumMember, + createSourceFile, + updateSourceFile, + createRedirectedSourceFile, + createBundle, + updateBundle, + createSyntheticExpression, + createSyntaxList, + createNotEmittedStatement, + createNotEmittedTypeElement, + createPartiallyEmittedExpression, + updatePartiallyEmittedExpression, + createCommaListExpression, + updateCommaListExpression, + createSyntheticReferenceExpression, + updateSyntheticReferenceExpression, + cloneNode, + restoreOuterExpressions, + }; + + return factory; + + // @api + function createNodeArray(elements?: AstNodeArrayLike, hasTrailingComma?: boolean): AstNodeArray { + if (elements instanceof AstNodeArray) { + return elements; + } + + return new AstNodeArray(elements ?? [], hasTrailingComma); + } + + function finishUpdateBaseSignatureDeclaration(updated: T, original: T) { + if (updated !== original) { + // copy children used for quick info + updated.data.typeArguments = original.data.typeArguments; + } + return update(updated, original); + } + + // + // Literals + // + + // @api + function createNumericLiteral(value: string | number, numericLiteralFlags: TokenFlags = TokenFlags.None): AstNumericLiteral { + const text = typeof value === "number" ? value + "" : value; + Debug.assert(text.charCodeAt(0) !== CharacterCodes.minus, "Negative numbers should be created in combination with createPrefixUnaryExpression"); + const node = AstNode.NumericLiteral(); + node.data.text = text; + node.data.numericLiteralFlags = numericLiteralFlags; + return finish(node); + } + + // @api + function createBigIntLiteral(value: string | PseudoBigInt): AstBigIntLiteral { + const node = AstNode.BigIntLiteral(); + node.data.text = typeof value === "string" ? value : pseudoBigIntToString(value) + "n"; + return finish(node); + } + + function createBaseStringLiteral(text: string, isSingleQuote?: boolean) { + const node = AstNode.StringLiteral(); + node.data.text = text; + node.data.singleQuote = isSingleQuote; + return finish(node); + } + + // @api + function createStringLiteral(text: string, isSingleQuote?: boolean, hasExtendedUnicodeEscape = false): AstStringLiteral { + const node = createBaseStringLiteral(text, isSingleQuote); + node.data.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape; + return finish(node); + } + + // @api + function createRegularExpressionLiteral(text: string): AstRegularExpressionLiteral { + const node = AstNode.RegularExpressionLiteral(); + node.data.text = text; + return finish(node); + } + + // @api + function createLiteralLikeNode(kind: LiteralToken["kind"] | SyntaxKind.JsxTextAllWhiteSpaces, text: string): AstLiteralToken { + switch (kind) { + case SyntaxKind.NumericLiteral: + return createNumericLiteral(text, /*numericLiteralFlags*/ 0); + case SyntaxKind.BigIntLiteral: + return createBigIntLiteral(text); + case SyntaxKind.StringLiteral: + return createStringLiteral(text, /*isSingleQuote*/ undefined); + case SyntaxKind.JsxText: + return createJsxText(text, /*containsOnlyTriviaWhiteSpaces*/ false); + case SyntaxKind.JsxTextAllWhiteSpaces: + return createJsxText(text, /*containsOnlyTriviaWhiteSpaces*/ true); + case SyntaxKind.RegularExpressionLiteral: + return createRegularExpressionLiteral(text); + case SyntaxKind.NoSubstitutionTemplateLiteral: + return createTemplateLiteralLikeNode(kind, text, /*rawText*/ undefined, /*templateFlags*/ 0) as AstNoSubstitutionTemplateLiteral; + } + } + + // + // Identifiers + // + + // @api + function createIdentifier(text: string, hasExtendedUnicodeEscape?: boolean): AstIdentifier { + const node = AstNode.Identifier(); + node.data.escapedText = escapeLeadingUnderscores(text); + if (hasExtendedUnicodeEscape) node.flags |= NodeFlags.IdentifierHasExtendedUnicodeEscape; + return finish(node); + } + + // @api + function createPrivateIdentifier(text: string): AstPrivateIdentifier { + if (!startsWith(text, "#")) Debug.fail("First character of private identifier must be #: " + text); + const node = AstNode.PrivateIdentifier(); + node.data.escapedText = escapeLeadingUnderscores(text); + return finish(node); + } + + // + // Punctuation + // + + // @api + function createToken(token: SyntaxKind.SuperKeyword): AstSuperExpression; + function createToken(token: SyntaxKind.ThisKeyword): AstThisExpression; + function createToken(token: SyntaxKind.NullKeyword): AstNullLiteral; + function createToken(token: SyntaxKind.TrueKeyword): AstTrueLiteral; + function createToken(token: SyntaxKind.FalseKeyword): AstFalseLiteral; + function createToken(token: SyntaxKind.EndOfFileToken): AstEndOfFileToken; + function createToken(token: SyntaxKind.Unknown): AstToken; + function createToken(token: TKind): AstPunctuationToken; + function createToken(token: TKind): AstKeywordTypeNode; + function createToken(token: TKind): AstModifierToken; + function createToken(token: TKind): AstKeywordToken; + function createToken(token: TKind): AstToken; + function createToken(token: TKind) { + Debug.assert(token >= SyntaxKind.FirstToken && token <= SyntaxKind.LastToken, "Invalid token"); + Debug.assert(token <= SyntaxKind.FirstTemplateToken || token >= SyntaxKind.LastTemplateToken, "Invalid token. Use 'createTemplateLiteralLikeNode' to create template literals."); + Debug.assert(token <= SyntaxKind.FirstLiteralToken || token >= SyntaxKind.LastLiteralToken, "Invalid token. Use 'createLiteralLikeNode' to create literals."); + Debug.assert(token !== SyntaxKind.Identifier, "Invalid token. Use 'createIdentifier' to create identifiers"); + return finish(AstNode.Token(token)); + } + + // + // Reserved words + // + + // @api + function createSuper() { + return createToken(SyntaxKind.SuperKeyword); + } + + // @api + function createThis() { + return createToken(SyntaxKind.ThisKeyword); + } + + // @api + function createNull() { + return createToken(SyntaxKind.NullKeyword); + } + + // @api + function createTrue() { + return createToken(SyntaxKind.TrueKeyword); + } + + // @api + function createFalse() { + return createToken(SyntaxKind.FalseKeyword); + } + + // + // Modifiers + // + + // @api + function createModifier(kind: T) { + return createToken(kind); + } + + // @api + function createModifiersFromModifierFlags(flags: ModifierFlags) { + const result: AstModifier[] = []; + if (flags & ModifierFlags.Export) result.push(createModifier(SyntaxKind.ExportKeyword)); + if (flags & ModifierFlags.Ambient) result.push(createModifier(SyntaxKind.DeclareKeyword)); + if (flags & ModifierFlags.Default) result.push(createModifier(SyntaxKind.DefaultKeyword)); + if (flags & ModifierFlags.Const) result.push(createModifier(SyntaxKind.ConstKeyword)); + if (flags & ModifierFlags.Public) result.push(createModifier(SyntaxKind.PublicKeyword)); + if (flags & ModifierFlags.Private) result.push(createModifier(SyntaxKind.PrivateKeyword)); + if (flags & ModifierFlags.Protected) result.push(createModifier(SyntaxKind.ProtectedKeyword)); + if (flags & ModifierFlags.Abstract) result.push(createModifier(SyntaxKind.AbstractKeyword)); + if (flags & ModifierFlags.Static) result.push(createModifier(SyntaxKind.StaticKeyword)); + if (flags & ModifierFlags.Override) result.push(createModifier(SyntaxKind.OverrideKeyword)); + if (flags & ModifierFlags.Readonly) result.push(createModifier(SyntaxKind.ReadonlyKeyword)); + if (flags & ModifierFlags.Accessor) result.push(createModifier(SyntaxKind.AccessorKeyword)); + if (flags & ModifierFlags.Async) result.push(createModifier(SyntaxKind.AsyncKeyword)); + if (flags & ModifierFlags.In) result.push(createModifier(SyntaxKind.InKeyword)); + if (flags & ModifierFlags.Out) result.push(createModifier(SyntaxKind.OutKeyword)); + return result.length ? result : undefined; + } + + // + // Names + // + + // @api + function createQualifiedName(left: AstEntityName, right: string | AstIdentifier) { + const node = AstNode.QualifiedName(); + node.data.left = left; + node.data.right = asName(right); + return finish(node); + } + + // @api + function updateQualifiedName(node: AstQualifiedName, left: AstEntityName, right: AstIdentifier) { + return node.data.left !== left + || node.data.right !== right + ? update(createQualifiedName(left, right), node) + : node; + } + + // @api + function createComputedPropertyName(expression: AstExpression) { + const node = AstNode.ComputedPropertyName(); + node.data.expression = parenthesizerRules().parenthesizeExpressionOfComputedPropertyName(expression); + return finish(node); + } + + // @api + function updateComputedPropertyName(node: AstComputedPropertyName, expression: AstExpression) { + return node.data.expression !== expression + ? update(createComputedPropertyName(expression), node) + : node; + } + + // + // Signature elements + // + + // @api + function createTypeParameterDeclaration(modifiers: AstNodeArrayLike | undefined, name: string | AstIdentifier, constraint?: AstTypeNode, defaultType?: AstTypeNode): AstTypeParameterDeclaration { + const node = AstNode.TypeParameterDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.name = asName(name); + node.data.constraint = constraint; + node.data.default = defaultType; + return finish(node); + } + + // @api + function updateTypeParameterDeclaration(node: AstTypeParameterDeclaration, modifiers: AstNodeArrayLike | undefined, name: AstIdentifier, constraint: AstTypeNode | undefined, defaultType: AstTypeNode | undefined): AstTypeParameterDeclaration { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.name !== name + || node.data.constraint !== constraint + || node.data.default !== defaultType + ? update(createTypeParameterDeclaration(modifiers, name, constraint, defaultType), node) + : node; + } + + // @api + function createParameterDeclaration( + modifiers: AstNodeArrayLike | undefined, + dotDotDotToken: AstDotDotDotToken | undefined, + name: string | AstBindingName, + questionToken?: AstQuestionToken, + type?: AstTypeNode, + initializer?: AstExpression, + ) { + const node = AstNode.ParameterDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.dotDotDotToken = dotDotDotToken; + node.data.name = asName(name); + node.data.questionToken = questionToken; + node.data.type = type; + node.data.initializer = asInitializer(initializer); + return finish(node); + } + + // @api + function updateParameterDeclaration( + node: AstParameterDeclaration, + modifiers: AstNodeArrayLike | undefined, + dotDotDotToken: AstDotDotDotToken | undefined, + name: string | AstBindingName, + questionToken: AstQuestionToken | undefined, + type: AstTypeNode | undefined, + initializer: AstExpression | undefined, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.dotDotDotToken !== dotDotDotToken + || node.data.name !== name + || node.data.questionToken !== questionToken + || node.data.type !== type + || node.data.initializer !== initializer + ? update(createParameterDeclaration(modifiers, dotDotDotToken, name, questionToken, type, initializer), node) + : node; + } + + // @api + function createDecorator(expression: AstExpression) { + const node = AstNode.Decorator(); + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); + return finish(node); + } + + // @api + function updateDecorator(node: AstDecorator, expression: AstExpression) { + return node.data.expression !== expression + ? update(createDecorator(expression), node) + : node; + } + + // + // Type Elements + // + + // @api + function createPropertySignature( + modifiers: AstNodeArrayLike | undefined, + name: AstPropertyName | string, + questionToken: AstQuestionToken | undefined, + type: AstTypeNode | undefined, + ): AstPropertySignature { + const node = AstNode.PropertySignature(); + node.data.modifiers = asNodeArray(modifiers); + node.data.name = asName(name); + node.data.type = type; + node.data.questionToken = questionToken; + return finish(node); + } + + // @api + function updatePropertySignature( + node: AstPropertySignature, + modifiers: AstNodeArrayLike | undefined, + name: AstPropertyName, + questionToken: AstQuestionToken | undefined, + type: AstTypeNode | undefined, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.name !== name + || node.data.questionToken !== questionToken + || node.data.type !== type + ? finishUpdatePropertySignature(createPropertySignature(modifiers, name, questionToken, type), node) + : node; + } + + function finishUpdatePropertySignature(updated: AstPropertySignature, original: AstPropertySignature) { + if (updated !== original) { + // copy children used only for error reporting + updated.data.initializer = original.data.initializer; + } + return update(updated, original); + } + + // @api + function createPropertyDeclaration( + modifiers: AstNodeArrayLike | undefined, + name: string | AstPropertyName, + questionOrExclamationToken: AstQuestionToken | AstExclamationToken | undefined, + type: AstTypeNode | undefined, + initializer: AstExpression | undefined, + ) { + const node = AstNode.PropertyDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.name = asName(name); + node.data.questionToken = questionOrExclamationToken && isAstQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined; + node.data.exclamationToken = questionOrExclamationToken && isAstExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined; + node.data.type = type; + node.data.initializer = asInitializer(initializer); + return finish(node); + } + + // @api + function updatePropertyDeclaration( + node: AstPropertyDeclaration, + modifiers: AstNodeArrayLike | undefined, + name: string | AstPropertyName, + questionOrExclamationToken: AstQuestionToken | AstExclamationToken | undefined, + type: AstTypeNode | undefined, + initializer: AstExpression | undefined, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.name !== name + || node.data.questionToken !== (questionOrExclamationToken !== undefined && isAstQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined) + || node.data.exclamationToken !== (questionOrExclamationToken !== undefined && isAstExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined) + || node.data.type !== type + || node.data.initializer !== initializer + ? update(createPropertyDeclaration(modifiers, name, questionOrExclamationToken, type, initializer), node) + : node; + } + + // @api + function createMethodSignature( + modifiers: AstNodeArrayLike | undefined, + name: string | AstPropertyName, + questionToken: AstQuestionToken | undefined, + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + ) { + const node = AstNode.MethodSignature(); + node.data.modifiers = asNodeArray(modifiers); + node.data.name = asName(name); + node.data.questionToken = questionToken; + node.data.typeParameters = asNodeArray(typeParameters); + node.data.parameters = asNodeArray(parameters); + node.data.type = type; + return finish(node); + } + + // @api + function updateMethodSignature( + node: AstMethodSignature, + modifiers: AstNodeArrayLike | undefined, + name: AstPropertyName, + questionToken: AstQuestionToken | undefined, + typeParameters: AstNodeArray | undefined, + parameters: AstNodeArray, + type: AstTypeNode | undefined, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.name !== name + || node.data.questionToken !== questionToken + || !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + ? finishUpdateBaseSignatureDeclaration(createMethodSignature(modifiers, name, questionToken, typeParameters, parameters, type), node) + : node; + } + + // @api + function createMethodDeclaration( + modifiers: AstNodeArrayLike | undefined, + asteriskToken: AstAsteriskToken | undefined, + name: string | AstPropertyName, + questionToken: AstQuestionToken | undefined, + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + body: AstBlock | undefined, + ) { + const node = AstNode.MethodDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.asteriskToken = asteriskToken; + node.data.name = asName(name); + node.data.questionToken = questionToken; + node.data.typeParameters = asNodeArray(typeParameters); + node.data.parameters = createNodeArray(parameters); + node.data.type = type; + node.data.body = body; + return finish(node); + } + + // @api + function updateMethodDeclaration( + node: AstMethodDeclaration, + modifiers: AstNodeArrayLike | undefined, + asteriskToken: AstAsteriskToken | undefined, + name: AstPropertyName, + questionToken: AstQuestionToken | undefined, + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + body: AstBlock | undefined, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.asteriskToken !== asteriskToken + || node.data.name !== name + || node.data.questionToken !== questionToken + || !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + || node.data.body !== body + ? finishUpdateMethodDeclaration(createMethodDeclaration(modifiers, asteriskToken, name, questionToken, typeParameters, parameters, type, body), node) + : node; + } + + function finishUpdateMethodDeclaration(updated: AstMethodDeclaration, original: AstMethodDeclaration) { + if (updated !== original) { + // copy children used only for error reporting + updated.data.exclamationToken = original.data.exclamationToken; + } + return update(updated, original); + } + + // @api + function createClassStaticBlockDeclaration( + body: AstBlock, + ): AstClassStaticBlockDeclaration { + const node = AstNode.ClassStaticBlockDeclaration(); + node.data.body = body; + return finish(node); + } + + // @api + function updateClassStaticBlockDeclaration( + node: AstClassStaticBlockDeclaration, + body: AstBlock, + ): AstClassStaticBlockDeclaration { + return node.data.body !== body + ? finishUpdateClassStaticBlockDeclaration(createClassStaticBlockDeclaration(body), node) + : node; + } + + function finishUpdateClassStaticBlockDeclaration(updated: AstClassStaticBlockDeclaration, original: AstClassStaticBlockDeclaration) { + if (updated !== original) { + // copy children used only for error reporting + updated.data.modifiers = original.data.modifiers; + } + return update(updated, original); + } + + // @api + function createConstructorDeclaration( + modifiers: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + body: AstBlock | undefined, + ) { + const node = AstNode.ConstructorDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.parameters = createNodeArray(parameters); + node.data.body = body; + return finish(node); + } + + // @api + function updateConstructorDeclaration( + node: AstConstructorDeclaration, + modifiers: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + body: AstBlock | undefined, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || !sameNodeArray(node.data.parameters, parameters) + || node.data.body !== body + ? finishUpdateConstructorDeclaration(createConstructorDeclaration(modifiers, parameters, body), node) + : node; + } + + function finishUpdateConstructorDeclaration(updated: AstConstructorDeclaration, original: AstConstructorDeclaration) { + if (updated !== original) { + updated.data.typeParameters = original.data.typeParameters; + updated.data.type = original.data.type; + } + return finishUpdateBaseSignatureDeclaration(updated, original); + } + + // @api + function createGetAccessorDeclaration( + modifiers: AstNodeArrayLike | undefined, + name: string | AstPropertyName, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + body: AstBlock | undefined, + ) { + const node = AstNode.GetAccessorDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.name = asName(name); + node.data.parameters = createNodeArray(parameters); + node.data.type = type; + node.data.body = body; + return finish(node); + } + + // @api + function updateGetAccessorDeclaration( + node: AstGetAccessorDeclaration, + modifiers: AstNodeArrayLike | undefined, + name: AstPropertyName, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + body: AstBlock | undefined, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.name !== name + || !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + || node.data.body !== body + ? finishUpdateGetAccessorDeclaration(createGetAccessorDeclaration(modifiers, name, parameters, type, body), node) + : node; + } + + function finishUpdateGetAccessorDeclaration(updated: AstGetAccessorDeclaration, original: AstGetAccessorDeclaration) { + if (updated !== original) { + // copy children used only for error reporting + updated.data.typeParameters = original.data.typeParameters; + } + return finishUpdateBaseSignatureDeclaration(updated, original); + } + + // @api + function createSetAccessorDeclaration( + modifiers: AstNodeArrayLike | undefined, + name: string | AstPropertyName, + parameters: AstNodeArrayLike, + body: AstBlock | undefined, + ) { + const node = AstNode.SetAccessorDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.name = asName(name); + node.data.parameters = createNodeArray(parameters); + node.data.body = body; + return finish(node); + } + + // @api + function updateSetAccessorDeclaration( + node: AstSetAccessorDeclaration, + modifiers: AstNodeArrayLike | undefined, + name: AstPropertyName, + parameters: AstNodeArrayLike, + body: AstBlock | undefined, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.name !== name + || !sameNodeArray(node.data.parameters, parameters) + || node.data.body !== body + ? finishUpdateSetAccessorDeclaration(createSetAccessorDeclaration(modifiers, name, parameters, body), node) + : node; + } + + function finishUpdateSetAccessorDeclaration(updated: AstSetAccessorDeclaration, original: AstSetAccessorDeclaration) { + if (updated !== original) { + // copy children used only for error reporting + updated.data.typeParameters = original.data.typeParameters; + updated.data.type = original.data.type; + } + return finishUpdateBaseSignatureDeclaration(updated, original); + } + + // @api + function createCallSignature( + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + ): AstCallSignatureDeclaration { + const node = AstNode.CallSignatureDeclaration(); + node.data.typeParameters = asNodeArray(typeParameters); + node.data.parameters = asNodeArray(parameters); + node.data.type = type; + return finish(node); + } + + // @api + function updateCallSignature( + node: AstCallSignatureDeclaration, + typeParameters: AstNodeArray | undefined, + parameters: AstNodeArray, + type: AstTypeNode | undefined, + ) { + return !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + ? finishUpdateBaseSignatureDeclaration(createCallSignature(typeParameters, parameters, type), node) + : node; + } + + // @api + function createConstructSignature( + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + ): AstConstructSignatureDeclaration { + const node = AstNode.ConstructSignatureDeclaration(); + node.data.typeParameters = asNodeArray(typeParameters); + node.data.parameters = asNodeArray(parameters); + node.data.type = type; + return finish(node); + } + + // @api + function updateConstructSignature( + node: AstConstructSignatureDeclaration, + typeParameters: AstNodeArray | undefined, + parameters: AstNodeArray, + type: AstTypeNode | undefined, + ) { + return !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + ? finishUpdateBaseSignatureDeclaration(createConstructSignature(typeParameters, parameters, type), node) + : node; + } + + // @api + function createIndexSignature( + modifiers: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + ): AstIndexSignatureDeclaration { + const node = AstNode.IndexSignatureDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.parameters = asNodeArray(parameters); + node.data.type = type!; // TODO(rbuckton): We mark this as required in IndexSignatureDeclaration, but it looks like the parser allows it to be elided. + return finish(node); + } + + // @api + function updateIndexSignature( + node: AstIndexSignatureDeclaration, + modifiers: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode, + ) { + return !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + || !sameNodeArray(node.data.modifiers, modifiers) + ? finishUpdateBaseSignatureDeclaration(createIndexSignature(modifiers, parameters, type), node) + : node; + } + + // @api + function createTemplateLiteralTypeSpan(type: AstTypeNode, literal: AstTemplateMiddle | AstTemplateTail) { + const node = AstNode.TemplateLiteralTypeSpan(); + node.data.type = type; + node.data.literal = literal; + return finish(node); + } + + // @api + function updateTemplateLiteralTypeSpan(node: AstTemplateLiteralTypeSpan, type: AstTypeNode, literal: AstTemplateMiddle | AstTemplateTail) { + return node.data.type !== type + || node.data.literal !== literal + ? update(createTemplateLiteralTypeSpan(type, literal), node) + : node; + } + + // + // Types + // + + // @api + function createKeywordTypeNode(kind: TKind) { + return createToken(kind); + } + + // @api + function createTypePredicateNode(assertsModifier: AstAssertsKeyword | undefined, parameterName: AstIdentifier | AstThisTypeNode | string, type: AstTypeNode | undefined) { + const node = AstNode.TypePredicateNode(); + node.data.assertsModifier = assertsModifier; + node.data.parameterName = asName(parameterName); + node.data.type = type; + return finish(node); + } + + // @api + function updateTypePredicateNode(node: AstTypePredicateNode, assertsModifier: AstAssertsKeyword | undefined, parameterName: AstIdentifier | AstThisTypeNode, type: AstTypeNode | undefined) { + return node.data.assertsModifier !== assertsModifier + || node.data.parameterName !== parameterName + || node.data.type !== type + ? update(createTypePredicateNode(assertsModifier, parameterName, type), node) + : node; + } + + // @api + function createTypeReferenceNode(typeName: string | AstEntityName, typeArguments: AstNodeArrayLike | undefined) { + const node = AstNode.TypeReferenceNode(); + node.data.typeName = asName(typeName); + node.data.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(createNodeArray(typeArguments)); + return finish(node); + } + + // @api + function updateTypeReferenceNode(node: AstTypeReferenceNode, typeName: AstEntityName, typeArguments: AstNodeArray | undefined) { + return node.data.typeName !== typeName + || !sameNodeArray(node.data.typeArguments, typeArguments) + ? update(createTypeReferenceNode(typeName, typeArguments), node) + : node; + } + + // @api + function createFunctionTypeNode( + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode, + ): AstFunctionTypeNode { + const node = AstNode.FunctionTypeNode(); + node.data.typeParameters = asNodeArray(typeParameters); + node.data.parameters = asNodeArray(parameters); + node.data.type = type; + return finish(node); + } + + // @api + function updateFunctionTypeNode( + node: AstFunctionTypeNode, + typeParameters: AstNodeArray | undefined, + parameters: AstNodeArray, + type: AstTypeNode, + ) { + return !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + ? finishUpdateFunctionTypeNode(createFunctionTypeNode(typeParameters, parameters, type), node) + : node; + } + + function finishUpdateFunctionTypeNode(updated: AstFunctionTypeNode, original: AstFunctionTypeNode) { + if (updated !== original) { + // copy children used only for error reporting + updated.data.modifiers = original.data.modifiers; + } + return finishUpdateBaseSignatureDeclaration(updated, original); + } + + // @api + function createConstructorTypeNode( + modifiers: AstNodeArrayLike | undefined, + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode, + ): AstConstructorTypeNode { + const node = AstNode.ConstructorTypeNode(); + node.data.modifiers = asNodeArray(modifiers); + node.data.typeParameters = asNodeArray(typeParameters); + node.data.parameters = asNodeArray(parameters); + node.data.type = type; + return finish(node); + } + + // @api + function updateConstructorTypeNode( + node: AstConstructorTypeNode, + modifiers: AstNodeArrayLike | undefined, + typeParameters: AstNodeArray | undefined, + parameters: AstNodeArray, + type: AstTypeNode, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + ? finishUpdateBaseSignatureDeclaration(createConstructorTypeNode(modifiers, typeParameters, parameters, type), node) + : node; + } + + // @api + function createTypeQueryNode(exprName: AstEntityName, typeArguments?: AstNodeArrayLike) { + const node = AstNode.TypeQueryNode(); + node.data.exprName = exprName; + node.data.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); + return finish(node); + } + + // @api + function updateTypeQueryNode(node: AstTypeQueryNode, exprName: AstEntityName, typeArguments?: AstNodeArrayLike) { + return node.data.exprName !== exprName + || !sameNodeArray(node.data.typeArguments, typeArguments) + ? update(createTypeQueryNode(exprName, typeArguments), node) + : node; + } + + // @api + function createTypeLiteralNode(members: AstNodeArrayLike | undefined) { + const node = AstNode.TypeLiteralNode(); + node.data.members = createNodeArray(members); + return finish(node); + } + + // @api + function updateTypeLiteralNode(node: AstTypeLiteralNode, members: AstNodeArray) { + return !sameNodeArray(node.data.members, members) + ? update(createTypeLiteralNode(members), node) + : node; + } + + // @api + function createArrayTypeNode(elementType: AstTypeNode) { + const node = AstNode.ArrayTypeNode(); + node.data.elementType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(elementType); + return finish(node); + } + + // @api + function updateArrayTypeNode(node: AstArrayTypeNode, elementType: AstTypeNode): AstArrayTypeNode { + return node.data.elementType !== elementType + ? update(createArrayTypeNode(elementType), node) + : node; + } + + // @api + function createTupleTypeNode(elements: AstNodeArrayLike) { + const node = AstNode.TupleTypeNode(); + node.data.elements = createNodeArray(parenthesizerRules().parenthesizeElementTypesOfTupleType(elements)); + return finish(node); + } + + // @api + function updateTupleTypeNode(node: AstTupleTypeNode, elements: AstNodeArrayLike) { + return !sameNodeArray(node.data.elements, elements) + ? update(createTupleTypeNode(elements), node) + : node; + } + + // @api + function createNamedTupleMember(dotDotDotToken: AstDotDotDotToken | undefined, name: AstIdentifier, questionToken: AstQuestionToken | undefined, type: AstTypeNode) { + const node = AstNode.NamedTupleMember(); + node.data.dotDotDotToken = dotDotDotToken; + node.data.name = name; + node.data.questionToken = questionToken; + node.data.type = type; + return finish(node); + } + + // @api + function updateNamedTupleMember(node: AstNamedTupleMember, dotDotDotToken: AstDotDotDotToken | undefined, name: AstIdentifier, questionToken: AstQuestionToken | undefined, type: AstTypeNode) { + return node.data.dotDotDotToken !== dotDotDotToken + || node.data.name !== name + || node.data.questionToken !== questionToken + || node.data.type !== type + ? update(createNamedTupleMember(dotDotDotToken, name, questionToken, type), node) + : node; + } + + // @api + function createOptionalTypeNode(type: AstTypeNode) { + const node = AstNode.OptionalTypeNode(); + node.data.type = parenthesizerRules().parenthesizeTypeOfOptionalType(type); + return finish(node); + } + + // @api + function updateOptionalTypeNode(node: AstOptionalTypeNode, type: AstTypeNode): AstOptionalTypeNode { + return node.data.type !== type + ? update(createOptionalTypeNode(type), node) + : node; + } + + // @api + function createRestTypeNode(type: AstTypeNode) { + const node = AstNode.RestTypeNode(); + node.data.type = type; + return finish(node); + } + + // @api + function updateRestTypeNode(node: AstRestTypeNode, type: AstTypeNode): AstRestTypeNode { + return node.data.type !== type + ? update(createRestTypeNode(type), node) + : node; + } + + // @api + function createUnionTypeNode(types: AstNodeArrayLike): AstUnionTypeNode { + const node = AstNode.UnionTypeNode(); + node.data.types = createNodeArray(parenthesizerRules().parenthesizeConstituentTypesOfUnionType(types)); + return finish(node); + } + + // @api + function updateUnionTypeNode(node: AstUnionTypeNode, types: AstNodeArray) { + return !sameNodeArray(node.data.types, types) + ? update(createUnionTypeNode(types), node) + : node; + } + + // @api + function createIntersectionTypeNode(types: AstNodeArrayLike): AstIntersectionTypeNode { + const node = AstNode.IntersectionTypeNode(); + node.data.types = createNodeArray(parenthesizerRules().parenthesizeConstituentTypesOfIntersectionType(types)); + return finish(node); + } + + // @api + function updateIntersectionTypeNode(node: AstIntersectionTypeNode, types: AstNodeArray) { + return !sameNodeArray(node.data.types, types) + ? update(createIntersectionTypeNode(types), node) + : node; + } + + // @api + function createConditionalTypeNode(checkType: AstTypeNode, extendsType: AstTypeNode, trueType: AstTypeNode, falseType: AstTypeNode) { + const node = AstNode.ConditionalTypeNode(); + node.data.checkType = parenthesizerRules().parenthesizeCheckTypeOfConditionalType(checkType); + node.data.extendsType = parenthesizerRules().parenthesizeExtendsTypeOfConditionalType(extendsType); + node.data.trueType = trueType; + node.data.falseType = falseType; + return finish(node); + } + + // @api + function updateConditionalTypeNode(node: AstConditionalTypeNode, checkType: AstTypeNode, extendsType: AstTypeNode, trueType: AstTypeNode, falseType: AstTypeNode) { + return node.data.checkType !== checkType + || node.data.extendsType !== extendsType + || node.data.trueType !== trueType + || node.data.falseType !== falseType + ? update(createConditionalTypeNode(checkType, extendsType, trueType, falseType), node) + : node; + } + + // @api + function createInferTypeNode(typeParameter: AstTypeParameterDeclaration) { + const node = AstNode.InferTypeNode(); + node.data.typeParameter = typeParameter; + return finish(node); + } + + // @api + function updateInferTypeNode(node: AstInferTypeNode, typeParameter: AstTypeParameterDeclaration) { + return node.data.typeParameter !== typeParameter + ? update(createInferTypeNode(typeParameter), node) + : node; + } + + // @api + function createTemplateLiteralType(head: AstTemplateHead, templateSpans: AstNodeArrayLike) { + const node = AstNode.TemplateLiteralTypeNode(); + node.data.head = head; + node.data.templateSpans = createNodeArray(templateSpans); + return finish(node); + } + + // @api + function updateTemplateLiteralType(node: AstTemplateLiteralTypeNode, head: AstTemplateHead, templateSpans: AstNodeArrayLike) { + return node.data.head !== head + || !sameNodeArray(node.data.templateSpans, templateSpans) + ? update(createTemplateLiteralType(head, templateSpans), node) + : node; + } + + // @api + function createImportTypeNode( + argument: AstTypeNode, + attributes?: AstImportAttributes, + qualifier?: AstEntityName, + typeArguments?: AstNodeArrayLike, + isTypeOf = false, + ): AstImportTypeNode { + const node = AstNode.ImportTypeNode(); + node.data.argument = argument; + node.data.attributes = attributes; + + // TODO: remove this? 'assertions' is never defined here + if (node.data.assertions && node.data.assertions.data.assertClause && node.data.attributes) { + (node.data.assertions).data.assertClause = node.data.attributes; + } + + node.data.qualifier = qualifier; + node.data.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); + node.data.isTypeOf = isTypeOf; + return finish(node); + } + + // @api + function updateImportTypeNode( + node: AstImportTypeNode, + argument: AstTypeNode, + attributes: AstImportAttributes | undefined, + qualifier: AstEntityName | undefined, + typeArguments: AstNodeArrayLike | undefined, + isTypeOf: boolean = node.data.isTypeOf, + ): AstImportTypeNode { + return node.data.argument !== argument + || node.data.attributes !== attributes + || node.data.qualifier !== qualifier + || !sameNodeArray(node.data.typeArguments, typeArguments) + || node.data.isTypeOf !== isTypeOf + ? update(createImportTypeNode(argument, attributes, qualifier, typeArguments, isTypeOf), node) + : node; + } + + // @api + function createParenthesizedType(type: AstTypeNode) { + const node = AstNode.ParenthesizedTypeNode(); + node.data.type = type; + return finish(node); + } + + // @api + function updateParenthesizedType(node: AstParenthesizedTypeNode, type: AstTypeNode) { + return node.data.type !== type + ? update(createParenthesizedType(type), node) + : node; + } + + // @api + function createThisTypeNode() { + const node = AstNode.ThisTypeNode(); + return finish(node); + } + + // @api + function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: AstTypeNode): AstTypeOperatorNode { + const node = AstNode.TypeOperatorNode(); + node.data.operator = operator; + node.data.type = operator === SyntaxKind.ReadonlyKeyword ? + parenthesizerRules().parenthesizeOperandOfReadonlyTypeOperator(type) : + parenthesizerRules().parenthesizeOperandOfTypeOperator(type); + return finish(node); + } + + // @api + function updateTypeOperatorNode(node: AstTypeOperatorNode, type: AstTypeNode) { + return node.data.type !== type + ? update(createTypeOperatorNode(node.data.operator, type), node) + : node; + } + + // @api + function createIndexedAccessTypeNode(objectType: AstTypeNode, indexType: AstTypeNode) { + const node = AstNode.IndexedAccessTypeNode(); + node.data.objectType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(objectType); + node.data.indexType = indexType; + return finish(node); + } + + // @api + function updateIndexedAccessTypeNode(node: AstIndexedAccessTypeNode, objectType: AstTypeNode, indexType: AstTypeNode) { + return node.data.objectType !== objectType + || node.data.indexType !== indexType + ? update(createIndexedAccessTypeNode(objectType, indexType), node) + : node; + } + + // @api + function createMappedTypeNode(readonlyToken: AstReadonlyKeyword | AstPlusToken | AstMinusToken | undefined, typeParameter: AstTypeParameterDeclaration, nameType: AstTypeNode | undefined, questionToken: AstQuestionToken | AstPlusToken | AstMinusToken | undefined, type: AstTypeNode | undefined, members: AstNodeArrayLike | undefined): AstMappedTypeNode { + const node = AstNode.MappedTypeNode(); + node.data.readonlyToken = readonlyToken; + node.data.typeParameter = typeParameter; + node.data.nameType = nameType; + node.data.questionToken = questionToken; + node.data.type = type; + node.data.members = members && createNodeArray(members); + return finish(node); + } + + // @api + function updateMappedTypeNode(node: AstMappedTypeNode, readonlyToken: AstReadonlyKeyword | AstPlusToken | AstMinusToken | undefined, typeParameter: AstTypeParameterDeclaration, nameType: AstTypeNode | undefined, questionToken: AstQuestionToken | AstPlusToken | AstMinusToken | undefined, type: AstTypeNode | undefined, members: AstNodeArrayLike | undefined): AstMappedTypeNode { + return node.data.readonlyToken !== readonlyToken + || node.data.typeParameter !== typeParameter + || node.data.nameType !== nameType + || node.data.questionToken !== questionToken + || node.data.type !== type + || !sameNodeArray(node.data.members, members) + ? update(createMappedTypeNode(readonlyToken, typeParameter, nameType, questionToken, type, members), node) + : node; + } + + // @api + function createLiteralTypeNode(literal: AstLiteralTypeNode["data"]["literal"]) { + const node = AstNode.LiteralTypeNode(); + node.data.literal = literal; + return finish(node); + } + + // @api + function updateLiteralTypeNode(node: AstLiteralTypeNode, literal: AstLiteralTypeNode["data"]["literal"]) { + return node.data.literal !== literal + ? update(createLiteralTypeNode(literal), node) + : node; + } + + // + // Binding Patterns + // + + // @api + function createObjectBindingPattern(elements: AstNodeArrayLike) { + const node = AstNode.ObjectBindingPattern(); + node.data.elements = createNodeArray(elements); + return finish(node); + } + + // @api + function updateObjectBindingPattern(node: AstObjectBindingPattern, elements: AstNodeArrayLike) { + return !sameNodeArray(node.data.elements, elements) + ? update(createObjectBindingPattern(elements), node) + : node; + } + + // @api + function createArrayBindingPattern(elements: AstNodeArrayLike) { + const node = AstNode.ArrayBindingPattern(); + node.data.elements = createNodeArray(elements); + return finish(node); + } + + // @api + function updateArrayBindingPattern(node: AstArrayBindingPattern, elements: AstNodeArrayLike) { + return !sameNodeArray(node.data.elements, elements) + ? update(createArrayBindingPattern(elements), node) + : node; + } + + // @api + function createBindingElement(dotDotDotToken: AstDotDotDotToken | undefined, propertyName: string | AstPropertyName | undefined, name: string | AstBindingName, initializer?: AstExpression) { + const node = AstNode.BindingElement(); + node.data.dotDotDotToken = dotDotDotToken; + node.data.propertyName = asName(propertyName); + node.data.name = asName(name); + node.data.initializer = asInitializer(initializer); + return finish(node); + } + + // @api + function updateBindingElement(node: AstBindingElement, dotDotDotToken: AstDotDotDotToken | undefined, propertyName: AstPropertyName | undefined, name: AstBindingName, initializer: AstExpression | undefined) { + return node.data.propertyName !== propertyName + || node.data.dotDotDotToken !== dotDotDotToken + || node.data.name !== name + || node.data.initializer !== initializer + ? update(createBindingElement(dotDotDotToken, propertyName, name, initializer), node) + : node; + } + + // + // Expression + // + + // @api + function createArrayLiteralExpression(elements?: AstNodeArrayLike, multiLine?: boolean) { + const node = AstNode.ArrayLiteralExpression(); + // Ensure we add a trailing comma for something like `[NumericLiteral(1), NumericLiteral(2), OmittedExpresion]` so that + // we end up with `[1, 2, ,]` instead of `[1, 2, ]` otherwise the `OmittedExpression` will just end up being treated like + // a trailing comma. + const lastElement = elements && lastOrUndefined(arrayItems(elements)); + const elementsArray = createNodeArray(elements, lastElement && isAstOmittedExpression(lastElement) ? true : undefined); + node.data.elements = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(elementsArray); + node.data.multiLine = multiLine; + return finish(node); + } + + // @api + function updateArrayLiteralExpression(node: AstArrayLiteralExpression, elements: AstNodeArrayLike) { + return !sameNodeArray(node.data.elements, elements) + ? update(createArrayLiteralExpression(elements, node.data.multiLine), node) + : node; + } + + // @api + function createObjectLiteralExpression(properties?: AstNodeArrayLike, multiLine?: boolean) { + const node = AstNode.ObjectLiteralExpression(); + node.data.properties = createNodeArray(properties); + node.data.multiLine = multiLine; + return finish(node); + } + + // @api + function updateObjectLiteralExpression(node: AstObjectLiteralExpression, properties: AstNodeArrayLike) { + return !sameNodeArray(node.data.properties, properties) + ? update(createObjectLiteralExpression(properties, node.data.multiLine), node) + : node; + } + + function createPropertyAccessExpressionWorker(expression: AstExpression, name: string | AstIdentifier | AstPrivateIdentifier) { + const node = AstNode.PropertyAccessExpression(); + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); + node.data.name = asName(name); + return finish(node); + } + + // @api + function createPropertyAccessExpression(expression: AstExpression, name: string | AstIdentifier | AstPrivateIdentifier) { + const node = createPropertyAccessExpressionWorker(expression, name); + if (flags & NodeFactoryFlags.NoIndentationOnFreshPropertyAccess) { + setEmitFlags(node, EmitFlags.NoIndentation); + } + return node; + } + + // @api + function updatePropertyAccessExpression(node: AstPropertyAccessExpression, expression: AstExpression, name: AstIdentifier | AstPrivateIdentifier) { + if (isAstPropertyAccessChain(node)) { + return updatePropertyAccessChain(node, expression, node.data.questionDotToken, cast(name, isAstIdentifier)); + } + return node.data.expression !== expression + || node.data.name !== name + ? update(createPropertyAccessExpressionWorker(expression, name), node) + : node; + } + + function createPropertyAccessChainWorker(expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, name: string | AstIdentifier | AstPrivateIdentifier) { + const node = AstNode.PropertyAccessChain(); + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true); + node.data.questionDotToken = questionDotToken; + node.data.name = asName(name); + return finish(node); + } + + // @api + function createPropertyAccessChain(expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, name: string | AstIdentifier | AstPrivateIdentifier) { + const node = createPropertyAccessChainWorker(expression, questionDotToken, name); + if (flags & NodeFactoryFlags.NoIndentationOnFreshPropertyAccess) { + setEmitFlags(node, EmitFlags.NoIndentation); + } + return node; + } + + // @api + function updatePropertyAccessChain(node: AstPropertyAccessChain, expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, name: AstIdentifier | AstPrivateIdentifier) { + Debug.assert(!!(node.flags & NodeFlags.OptionalChain), "Cannot update a PropertyAccessExpression using updatePropertyAccessChain. Use updatePropertyAccess instead."); + // Because we are updating an existing PropertyAccessChain we want to inherit its emitFlags + // instead of using the default from createPropertyAccess + return node.data.expression !== expression + || node.data.questionDotToken !== questionDotToken + || node.data.name !== name + ? update(createPropertyAccessChainWorker(expression, questionDotToken, name), node) + : node; + } + + // @api + function createElementAccessExpression(expression: AstExpression, index: number | AstExpression) { + const node = AstNode.ElementAccessExpression(); + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); + node.data.argumentExpression = asExpression(index); + return finish(node); + } + + // @api + function updateElementAccessExpression(node: AstElementAccessExpression, expression: AstExpression, argumentExpression: AstExpression) { + if (isAstElementAccessChain(node)) { + return updateElementAccessChain(node, expression, node.data.questionDotToken, argumentExpression); + } + return node.data.expression !== expression + || node.data.argumentExpression !== argumentExpression + ? update(createElementAccessExpression(expression, argumentExpression), node) + : node; + } + + // @api + function createElementAccessChain(expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, index: number | AstExpression) { + const node = AstNode.ElementAccessChain(); + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true); + node.data.questionDotToken = questionDotToken; + node.data.argumentExpression = asExpression(index); + return finish(node); + } + + // @api + function updateElementAccessChain(node: AstElementAccessChain, expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, argumentExpression: AstExpression) { + Debug.assert(!!(node.flags & NodeFlags.OptionalChain), "Cannot update a ElementAccessExpression using updateElementAccessChain. Use updateElementAccess instead."); + // Because we are updating an existing ElementAccessChain we want to inherit its emitFlags + // instead of using the default from createElementAccess + return node.data.expression !== expression + || node.data.questionDotToken !== questionDotToken + || node.data.argumentExpression !== argumentExpression + ? update(createElementAccessChain(expression, questionDotToken, argumentExpression), node) + : node; + } + // @api + function createCallExpression(expression: AstExpression, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike | undefined) { + const node = AstNode.CallExpression(); + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); + node.data.typeArguments = asNodeArray(typeArguments); + node.data.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray)); + return finish(node); + } + + // @api + function updateCallExpression(node: AstCallExpression, expression: AstExpression, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike) { + if (isAstCallChain(node)) { + return updateCallChain(node, expression, node.data.questionDotToken, typeArguments, argumentsArray); + } + return node.data.expression !== expression + || !sameNodeArray(node.data.typeArguments, typeArguments) + || !sameNodeArray(node.data.arguments, argumentsArray) + ? update(createCallExpression(expression, typeArguments, argumentsArray), node) + : node; + } + + // @api + function createCallChain(expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike | undefined) { + const node = AstNode.CallChain(); + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true); + node.data.questionDotToken = questionDotToken; + node.data.typeArguments = asNodeArray(typeArguments); + node.data.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray)); + return finish(node); + } + + // @api + function updateCallChain(node: AstCallChain, expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike) { + Debug.assert(!!(node.flags & NodeFlags.OptionalChain), "Cannot update a CallExpression using updateCallChain. Use updateCall instead."); + return node.data.expression !== expression + || node.data.questionDotToken !== questionDotToken + || !sameNodeArray(node.data.typeArguments, typeArguments) + || !sameNodeArray(node.data.arguments, argumentsArray) + ? update(createCallChain(expression, questionDotToken, typeArguments, argumentsArray), node) + : node; + } + + // @api + function createNewExpression(expression: AstExpression, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike | undefined) { + const node = AstNode.NewExpression(); + node.data.expression = parenthesizerRules().parenthesizeExpressionOfNew(expression); + node.data.typeArguments = asNodeArray(typeArguments); + node.data.arguments = argumentsArray ? parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(argumentsArray) : undefined; + return finish(node); + } + + // @api + function updateNewExpression(node: AstNewExpression, expression: AstExpression, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike | undefined) { + return node.data.expression !== expression + || !sameNodeArray(node.data.typeArguments, typeArguments) + || !sameNodeArray(node.data.arguments, argumentsArray) + ? update(createNewExpression(expression, typeArguments, argumentsArray), node) + : node; + } + + // @api + function createTaggedTemplateExpression(tag: AstExpression, typeArguments: AstNodeArrayLike | undefined, template: AstTemplateLiteral) { + const node = AstNode.TaggedTemplateExpression(); + node.data.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag, /*optionalChain*/ false); + node.data.typeArguments = asNodeArray(typeArguments); + node.data.template = template; + return finish(node); + } + + // @api + function updateTaggedTemplateExpression(node: AstTaggedTemplateExpression, tag: AstExpression, typeArguments: AstNodeArrayLike | undefined, template: AstTemplateLiteral) { + return node.data.tag !== tag + || !sameNodeArray(node.data.typeArguments, typeArguments) + || node.data.template !== template + ? update(createTaggedTemplateExpression(tag, typeArguments, template), node) + : node; + } + + // @api + function createTypeAssertion(type: AstTypeNode, expression: AstExpression) { + const node = AstNode.TypeAssertion(); + node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + node.data.type = type; + return finish(node); + } + + // @api + function updateTypeAssertion(node: AstTypeAssertion, type: AstTypeNode, expression: AstExpression) { + return node.data.type !== type + || node.data.expression !== expression + ? update(createTypeAssertion(type, expression), node) + : node; + } + + // @api + function createParenthesizedExpression(expression: AstExpression) { + const node = AstNode.ParenthesizedExpression(); + node.data.expression = expression; + return finish(node); + } + + // @api + function updateParenthesizedExpression(node: AstParenthesizedExpression, expression: AstExpression) { + return node.data.expression !== expression + ? update(createParenthesizedExpression(expression), node) + : node; + } + + // @api + function createFunctionExpression( + modifiers: AstNodeArrayLike | undefined, + asteriskToken: AstAsteriskToken | undefined, + name: string | AstIdentifier | undefined, + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike | undefined, + type: AstTypeNode | undefined, + body: AstBlock, + ) { + const node = AstNode.FunctionExpression(); + node.data.modifiers = asNodeArray(modifiers); + node.data.asteriskToken = asteriskToken; + node.data.name = asName(name); + node.data.typeParameters = asNodeArray(typeParameters); + node.data.parameters = createNodeArray(parameters); + node.data.type = type; + node.data.body = body; + return finish(node); + } + + // @api + function updateFunctionExpression( + node: AstFunctionExpression, + modifiers: AstNodeArrayLike | undefined, + asteriskToken: AstAsteriskToken | undefined, + name: AstIdentifier | undefined, + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + body: AstBlock, + ) { + return node.data.name !== name + || !sameNodeArray(node.data.modifiers, modifiers) + || node.data.asteriskToken !== asteriskToken + || !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + || node.data.body !== body + ? finishUpdateBaseSignatureDeclaration(createFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, type, body), node) + : node; + } + + // @api + function createArrowFunction( + modifiers: AstNodeArrayLike | undefined, + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + equalsGreaterThanToken: AstEqualsGreaterThanToken | undefined, + body: AstConciseBody, + ) { + const node = AstNode.ArrowFunction(); + node.data.modifiers = asNodeArray(modifiers); + node.data.typeParameters = asNodeArray(typeParameters); + node.data.parameters = createNodeArray(parameters); + node.data.type = type; + node.data.equalsGreaterThanToken = equalsGreaterThanToken ?? createToken(SyntaxKind.EqualsGreaterThanToken); + node.data.body = parenthesizerRules().parenthesizeConciseBodyOfArrowFunction(body); + return finish(node); + } + + // @api + function updateArrowFunction( + node: AstArrowFunction, + modifiers: AstNodeArrayLike | undefined, + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + equalsGreaterThanToken: AstEqualsGreaterThanToken, + body: AstConciseBody, + ): AstArrowFunction { + return !sameNodeArray(node.data.modifiers, modifiers) + || !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + || node.data.equalsGreaterThanToken !== equalsGreaterThanToken + || node.data.body !== body + ? finishUpdateBaseSignatureDeclaration(createArrowFunction(modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body), node) + : node; + } + + // @api + function createDeleteExpression(expression: AstExpression) { + const node = AstNode.DeleteExpression(); + node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + return finish(node); + } + + // @api + function updateDeleteExpression(node: AstDeleteExpression, expression: AstExpression) { + return node.data.expression !== expression + ? update(createDeleteExpression(expression), node) + : node; + } + + // @api + function createTypeOfExpression(expression: AstExpression) { + const node = AstNode.TypeOfExpression(); + node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + return finish(node); + } + + // @api + function updateTypeOfExpression(node: AstTypeOfExpression, expression: AstExpression) { + return node.data.expression !== expression + ? update(createTypeOfExpression(expression), node) + : node; + } + + // @api + function createVoidExpression(expression: AstExpression) { + const node = AstNode.VoidExpression(); + node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + return finish(node); + } + + // @api + function updateVoidExpression(node: AstVoidExpression, expression: AstExpression) { + return node.data.expression !== expression + ? update(createVoidExpression(expression), node) + : node; + } + + // @api + function createAwaitExpression(expression: AstExpression) { + const node = AstNode.AwaitExpression(); + node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + return finish(node); + } + + // @api + function updateAwaitExpression(node: AstAwaitExpression, expression: AstExpression) { + return node.data.expression !== expression + ? update(createAwaitExpression(expression), node) + : node; + } + + // @api + function createPrefixUnaryExpression(operator: PrefixUnaryOperator, operand: AstExpression) { + const node = AstNode.PrefixUnaryExpression(); + node.data.operator = operator; + node.data.operand = parenthesizerRules().parenthesizeOperandOfPrefixUnary(operand); + return finish(node); + } + + // @api + function updatePrefixUnaryExpression(node: AstPrefixUnaryExpression, operand: AstExpression) { + return node.data.operand !== operand + ? update(createPrefixUnaryExpression(node.data.operator, operand), node) + : node; + } + + // @api + function createPostfixUnaryExpression(operand: AstExpression, operator: PostfixUnaryOperator) { + const node = AstNode.PostfixUnaryExpression(); + node.data.operator = operator; + node.data.operand = parenthesizerRules().parenthesizeOperandOfPostfixUnary(operand); + return finish(node); + } + + // @api + function updatePostfixUnaryExpression(node: AstPostfixUnaryExpression, operand: AstExpression) { + return node.data.operand !== operand + ? update(createPostfixUnaryExpression(operand, node.data.operator), node) + : node; + } + + // @api + function createBinaryExpression(left: AstExpression, operator: BinaryOperator | AstBinaryOperatorToken, right: AstExpression) { + const node = AstNode.BinaryExpression(); + const operatorToken = asToken(operator); + const operatorKind = operatorToken.kind; + node.data.left = parenthesizerRules().parenthesizeLeftSideOfBinary(operatorKind, left); + node.data.operatorToken = operatorToken; + node.data.right = parenthesizerRules().parenthesizeRightSideOfBinary(operatorKind, node.data.left, right); + void node.transformFlags; // precompute to avoid deep call stack for excessively nested binary expresions + return finish(node); + } + + // @api + function updateBinaryExpression(node: AstBinaryExpression, left: AstExpression, operator: AstBinaryOperatorToken, right: AstExpression) { + return node.data.left !== left + || node.data.operatorToken !== operator + || node.data.right !== right + ? update(createBinaryExpression(left, operator, right), node) + : node; + } + + // @api + function createConditionalExpression(condition: AstExpression, questionToken: AstQuestionToken | undefined, whenTrue: AstExpression, colonToken: AstColonToken | undefined, whenFalse: AstExpression) { + const node = AstNode.ConditionalExpression(); + node.data.condition = parenthesizerRules().parenthesizeConditionOfConditionalExpression(condition); + node.data.questionToken = questionToken ?? createToken(SyntaxKind.QuestionToken); + node.data.whenTrue = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenTrue); + node.data.colonToken = colonToken ?? createToken(SyntaxKind.ColonToken); + node.data.whenFalse = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenFalse); + return finish(node); + } + + // @api + function updateConditionalExpression( + node: AstConditionalExpression, + condition: AstExpression, + questionToken: AstQuestionToken, + whenTrue: AstExpression, + colonToken: AstColonToken, + whenFalse: AstExpression, + ): AstConditionalExpression { + return node.data.condition !== condition + || node.data.questionToken !== questionToken + || node.data.whenTrue !== whenTrue + || node.data.colonToken !== colonToken + || node.data.whenFalse !== whenFalse + ? update(createConditionalExpression(condition, questionToken, whenTrue, colonToken, whenFalse), node) + : node; + } + + // @api + function createTemplateExpression(head: AstTemplateHead, templateSpans: AstNodeArrayLike) { + const node = AstNode.TemplateExpression(); + node.data.head = head; + node.data.templateSpans = createNodeArray(templateSpans); + return finish(node); + } + + // @api + function updateTemplateExpression(node: AstTemplateExpression, head: AstTemplateHead, templateSpans: AstNodeArrayLike) { + return node.data.head !== head + || !sameNodeArray(node.data.templateSpans, templateSpans) + ? update(createTemplateExpression(head, templateSpans), node) + : node; + } + + function checkTemplateLiteralLikeNode(kind: AstTemplateLiteralToken["kind"], text: string | undefined, rawText: string | undefined, templateFlags = TokenFlags.None) { + Debug.assert(!(templateFlags & ~TokenFlags.TemplateLiteralLikeFlags), "Unsupported template flags."); + // NOTE: without the assignment to `undefined`, we don't narrow the initial type of `cooked`. + // eslint-disable-next-line no-undef-init + let cooked: string | object | undefined = undefined; + if (rawText !== undefined && rawText !== text) { + cooked = getCookedText(kind, rawText); + if (typeof cooked === "object") { + return Debug.fail("Invalid raw text"); + } + } + if (text === undefined) { + if (cooked === undefined) { + return Debug.fail("Arguments 'text' and 'rawText' may not both be undefined."); + } + text = cooked; + } + else if (cooked !== undefined) { + Debug.assert(text === cooked, "Expected argument 'text' to be the normalized (i.e. 'cooked') version of argument 'rawText'."); + } + return text; + } + + // @api + function createTemplateLiteralLikeNode(kind: AstTemplateLiteralToken["kind"], text: string, rawText: string | undefined, templateFlags: TokenFlags | undefined) { + switch (kind) { + case SyntaxKind.NoSubstitutionTemplateLiteral: + return createNoSubstitutionTemplateLiteralUnchecked(text, rawText, templateFlags); + case SyntaxKind.TemplateHead: + return createTemplateHeadUnchecked(text, rawText, templateFlags); + case SyntaxKind.TemplateMiddle: + return createTemplateMiddleUnchecked(text, rawText, templateFlags); + case SyntaxKind.TemplateTail: + return createTemplateTailUnchecked(text, rawText, templateFlags); + default: + Debug.assertNever(kind); + } + } + + // @api + function createTemplateHead(text: string | undefined, rawText?: string, templateFlags?: TokenFlags) { + text = checkTemplateLiteralLikeNode(SyntaxKind.TemplateHead, text, rawText, templateFlags); + return createTemplateHeadUnchecked(text, rawText, templateFlags) as AstTemplateHead; + } + + function createTemplateHeadUnchecked(text: string, rawText?: string, templateFlags?: TokenFlags) { + const node = AstNode.TemplateHead(); + node.data.text = text; + node.data.rawText = rawText; + node.data.templateFlags = templateFlags! & TokenFlags.TemplateLiteralLikeFlags; + return finish(node); + } + + // @api + function createTemplateMiddle(text: string | undefined, rawText?: string, templateFlags?: TokenFlags) { + text = checkTemplateLiteralLikeNode(SyntaxKind.TemplateHead, text, rawText, templateFlags); + return createTemplateMiddleUnchecked(text, rawText, templateFlags) as AstTemplateMiddle; + } + + function createTemplateMiddleUnchecked(text: string, rawText?: string, templateFlags?: TokenFlags) { + const node = AstNode.TemplateMiddle(); + node.data.text = text; + node.data.rawText = rawText; + node.data.templateFlags = templateFlags! & TokenFlags.TemplateLiteralLikeFlags; + return finish(node); + } + + // @api + function createTemplateTail(text: string | undefined, rawText?: string, templateFlags?: TokenFlags) { + text = checkTemplateLiteralLikeNode(SyntaxKind.TemplateHead, text, rawText, templateFlags); + return createTemplateTailUnchecked(text, rawText, templateFlags) as AstTemplateTail; + } + + function createTemplateTailUnchecked(text: string, rawText?: string, templateFlags?: TokenFlags) { + const node = AstNode.TemplateTail(); + node.data.text = text; + node.data.rawText = rawText; + node.data.templateFlags = templateFlags! & TokenFlags.TemplateLiteralLikeFlags; + return finish(node); + } + + // @api + function createNoSubstitutionTemplateLiteral(text: string | undefined, rawText?: string, templateFlags?: TokenFlags) { + text = checkTemplateLiteralLikeNode(SyntaxKind.TemplateHead, text, rawText, templateFlags); + return createNoSubstitutionTemplateLiteralUnchecked(text, rawText, templateFlags) as AstNoSubstitutionTemplateLiteral; + } + + function createNoSubstitutionTemplateLiteralUnchecked(text: string, rawText?: string, templateFlags?: TokenFlags) { + const node = AstNode.NoSubstitutionTemplateLiteral(); + node.data.text = text; + node.data.rawText = rawText; + node.data.templateFlags = templateFlags! & TokenFlags.TemplateLiteralLikeFlags; + return finish(node); + } + + // @api + function createYieldExpression(asteriskToken: AstAsteriskToken | undefined, expression: AstExpression | undefined): AstYieldExpression { + Debug.assert(!asteriskToken || !!expression, "A `YieldExpression` with an asteriskToken must have an expression."); + const node = AstNode.YieldExpression(); + node.data.expression = expression && parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + node.data.asteriskToken = asteriskToken; + return finish(node); + } + + // @api + function updateYieldExpression(node: AstYieldExpression, asteriskToken: AstAsteriskToken | undefined, expression: AstExpression) { + return node.data.expression !== expression + || node.data.asteriskToken !== asteriskToken + ? update(createYieldExpression(asteriskToken, expression), node) + : node; + } + + // @api + function createSpreadElement(expression: AstExpression) { + const node = AstNode.SpreadElement(); + node.data.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + return finish(node); + } + + // @api + function updateSpreadElement(node: AstSpreadElement, expression: AstExpression) { + return node.data.expression !== expression + ? update(createSpreadElement(expression), node) + : node; + } + + // @api + function createClassExpression( + modifiers: AstNodeArrayLike | undefined, + name: string | AstIdentifier | undefined, + typeParameters: AstNodeArrayLike | undefined, + heritageClauses: AstNodeArrayLike | undefined, + members: AstNodeArrayLike, + ) { + const node = AstNode.ClassExpression(); + node.data.modifiers = asNodeArray(modifiers); + node.data.name = asName(name); + node.data.typeParameters = asNodeArray(typeParameters); + node.data.heritageClauses = asNodeArray(heritageClauses); + node.data.members = createNodeArray(members); + return finish(node); + } + + // @api + function updateClassExpression( + node: AstClassExpression, + modifiers: AstNodeArrayLike | undefined, + name: AstIdentifier | undefined, + typeParameters: AstNodeArrayLike | undefined, + heritageClauses: AstNodeArrayLike | undefined, + members: AstNodeArrayLike, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.name !== name + || !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.heritageClauses, heritageClauses) + || !sameNodeArray(node.data.members, members) + ? update(createClassExpression(modifiers, name, typeParameters, heritageClauses, members), node) + : node; + } + + // @api + function createOmittedExpression() { + return finish(AstNode.OmittedExpression()); + } + + // @api + function createExpressionWithTypeArguments(expression: AstExpression, typeArguments: AstNodeArrayLike | undefined) { + const node = AstNode.ExpressionWithTypeArguments(); + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); + node.data.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); + return finish(node); + } + + // @api + function updateExpressionWithTypeArguments(node: AstExpressionWithTypeArguments, expression: AstExpression, typeArguments: AstNodeArrayLike | undefined) { + return node.data.expression !== expression + || !sameNodeArray(node.data.typeArguments, typeArguments) + ? update(createExpressionWithTypeArguments(expression, typeArguments), node) + : node; + } + + // @api + function createAsExpression(expression: AstExpression, type: AstTypeNode) { + const node = AstNode.AsExpression(); + node.data.expression = expression; + node.data.type = type; + return finish(node); + } + + // @api + function updateAsExpression(node: AstAsExpression, expression: AstExpression, type: AstTypeNode) { + return node.data.expression !== expression + || node.data.type !== type + ? update(createAsExpression(expression, type), node) + : node; + } + + // @api + function createNonNullExpression(expression: AstExpression) { + const node = AstNode.NonNullExpression(); + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); + return finish(node); + } + + // @api + function updateNonNullExpression(node: AstNonNullExpression, expression: AstExpression) { + if (isAstNonNullChain(node)) { + return updateNonNullChain(node, expression); + } + return node.data.expression !== expression + ? update(createNonNullExpression(expression), node) + : node; + } + + // @api + function createSatisfiesExpression(expression: AstExpression, type: AstTypeNode) { + const node = AstNode.SatisfiesExpression(); + node.data.expression = expression; + node.data.type = type; + return finish(node); + } + + // @api + function updateSatisfiesExpression(node: AstSatisfiesExpression, expression: AstExpression, type: AstTypeNode) { + return node.data.expression !== expression + || node.data.type !== type + ? update(createSatisfiesExpression(expression, type), node) + : node; + } + + // @api + function createNonNullChain(expression: AstExpression) { + const node = AstNode.NonNullChain(); + node.flags |= NodeFlags.OptionalChain; + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true); + return finish(node); + } + + // @api + function updateNonNullChain(node: AstNonNullChain, expression: AstExpression) { + Debug.assert(!!(node.flags & NodeFlags.OptionalChain), "Cannot update a NonNullExpression using updateNonNullChain. Use updateNonNullExpression instead."); + return node.data.expression !== expression + ? update(createNonNullChain(expression), node) + : node; + } + + // @api + function createMetaProperty(keywordToken: AstMetaProperty["data"]["keywordToken"], name: AstIdentifier) { + const node = AstNode.MetaProperty(); + node.data.keywordToken = keywordToken; + node.data.name = name; + return finish(node); + } + + // @api + function updateMetaProperty(node: AstMetaProperty, name: AstIdentifier) { + return node.data.name !== name + ? update(createMetaProperty(node.data.keywordToken, name), node) + : node; + } + + // + // Misc + // + + // @api + function createTemplateSpan(expression: AstExpression, literal: AstTemplateMiddle | AstTemplateTail) { + const node = AstNode.TemplateSpan(); + node.data.expression = expression; + node.data.literal = literal; + return finish(node); + } + + // @api + function updateTemplateSpan(node: AstTemplateSpan, expression: AstExpression, literal: AstTemplateMiddle | AstTemplateTail) { + return node.data.expression !== expression + || node.data.literal !== literal + ? update(createTemplateSpan(expression, literal), node) + : node; + } + + // @api + function createSemicolonClassElement() { + const node = AstNode.SemicolonClassElement(); + return finish(node); + } + + // + // Element + // + + // @api + function createBlock(statements: AstNodeArrayLike, multiLine?: boolean): AstBlock { + const node = AstNode.Block(); + node.data.statements = createNodeArray(statements); + node.data.multiLine = multiLine; + return finish(node); + } + + // @api + function updateBlock(node: AstBlock, statements: AstNodeArrayLike) { + return !sameNodeArray(node.data.statements, statements) + ? update(createBlock(statements, node.data.multiLine), node) + : node; + } + + // @api + function createVariableStatement(modifiers: AstNodeArrayLike | undefined, declarationList: AstVariableDeclarationList | AstNodeArrayLike) { + const node = AstNode.VariableStatement(); + node.data.modifiers = asNodeArray(modifiers); + node.data.declarationList = declarationList instanceof AstNode ? declarationList : createVariableDeclarationList(declarationList); + return finish(node); + } + + // @api + function updateVariableStatement(node: AstVariableStatement, modifiers: AstNodeArrayLike | undefined, declarationList: AstVariableDeclarationList) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.declarationList !== declarationList + ? update(createVariableStatement(modifiers, declarationList), node) + : node; + } + + // @api + function createEmptyStatement() { + const node = AstNode.EmptyStatement(); + return finish(node); + } + + // @api + function createExpressionStatement(expression: AstExpression): AstExpressionStatement { + const node = AstNode.ExpressionStatement(); + node.data.expression = parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression); + return finish(node); + } + + // @api + function updateExpressionStatement(node: AstExpressionStatement, expression: AstExpression) { + return node.data.expression !== expression + ? update(createExpressionStatement(expression), node) + : node; + } + + // @api + function createIfStatement(expression: AstExpression, thenStatement: AstStatement, elseStatement?: AstStatement) { + const node = AstNode.IfStatement(); + node.data.expression = expression; + node.data.thenStatement = asEmbeddedStatement(thenStatement); + node.data.elseStatement = asEmbeddedStatement(elseStatement); + return finish(node); + } + + // @api + function updateIfStatement(node: AstIfStatement, expression: AstExpression, thenStatement: AstStatement, elseStatement: AstStatement | undefined) { + return node.data.expression !== expression + || node.data.thenStatement !== thenStatement + || node.data.elseStatement !== elseStatement + ? update(createIfStatement(expression, thenStatement, elseStatement), node) + : node; + } + + // @api + function createDoStatement(statement: AstStatement, expression: AstExpression) { + const node = AstNode.DoStatement(); + node.data.statement = asEmbeddedStatement(statement); + node.data.expression = expression; + return finish(node); + } + + // @api + function updateDoStatement(node: AstDoStatement, statement: AstStatement, expression: AstExpression) { + return node.data.statement !== statement + || node.data.expression !== expression + ? update(createDoStatement(statement, expression), node) + : node; + } + + // @api + function createWhileStatement(expression: AstExpression, statement: AstStatement) { + const node = AstNode.WhileStatement(); + node.data.expression = expression; + node.data.statement = asEmbeddedStatement(statement); + return finish(node); + } + + // @api + function updateWhileStatement(node: AstWhileStatement, expression: AstExpression, statement: AstStatement) { + return node.data.expression !== expression + || node.data.statement !== statement + ? update(createWhileStatement(expression, statement), node) + : node; + } + + // @api + function createForStatement(initializer: AstForInitializer | undefined, condition: AstExpression | undefined, incrementor: AstExpression | undefined, statement: AstStatement) { + const node = AstNode.ForStatement(); + node.data.initializer = initializer; + node.data.condition = condition; + node.data.incrementor = incrementor; + node.data.statement = asEmbeddedStatement(statement); + return finish(node); + } + + // @api + function updateForStatement(node: AstForStatement, initializer: AstForInitializer | undefined, condition: AstExpression | undefined, incrementor: AstExpression | undefined, statement: AstStatement) { + return node.data.initializer !== initializer + || node.data.condition !== condition + || node.data.incrementor !== incrementor + || node.data.statement !== statement + ? update(createForStatement(initializer, condition, incrementor, statement), node) + : node; + } + + // @api + function createForInStatement(initializer: AstForInitializer, expression: AstExpression, statement: AstStatement) { + const node = AstNode.ForInStatement(); + node.data.initializer = initializer; + node.data.expression = expression; + node.data.statement = asEmbeddedStatement(statement); + return finish(node); + } + + // @api + function updateForInStatement(node: AstForInStatement, initializer: AstForInitializer, expression: AstExpression, statement: AstStatement) { + return node.data.initializer !== initializer + || node.data.expression !== expression + || node.data.statement !== statement + ? update(createForInStatement(initializer, expression, statement), node) + : node; + } + + // @api + function createForOfStatement(awaitModifier: AstAwaitKeyword | undefined, initializer: AstForInitializer, expression: AstExpression, statement: AstStatement) { + const node = AstNode.ForOfStatement(); + node.data.awaitModifier = awaitModifier; + node.data.initializer = initializer; + node.data.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + node.data.statement = asEmbeddedStatement(statement); + return finish(node); + } + + // @api + function updateForOfStatement(node: AstForOfStatement, awaitModifier: AstAwaitKeyword | undefined, initializer: AstForInitializer, expression: AstExpression, statement: AstStatement) { + return node.data.awaitModifier !== awaitModifier + || node.data.initializer !== initializer + || node.data.expression !== expression + || node.data.statement !== statement + ? update(createForOfStatement(awaitModifier, initializer, expression, statement), node) + : node; + } + + // @api + function createContinueStatement(label?: string | AstIdentifier): AstContinueStatement { + const node = AstNode.ContinueStatement(); + node.data.label = asName(label); + return finish(node); + } + + // @api + function updateContinueStatement(node: AstContinueStatement, label: AstIdentifier | undefined) { + return node.data.label !== label + ? update(createContinueStatement(label), node) + : node; + } + + // @api + function createBreakStatement(label?: string | AstIdentifier): AstBreakStatement { + const node = AstNode.BreakStatement(); + node.data.label = asName(label); + return finish(node); + } + + // @api + function updateBreakStatement(node: AstBreakStatement, label: AstIdentifier | undefined) { + return node.data.label !== label + ? update(createBreakStatement(label), node) + : node; + } + + // @api + function createReturnStatement(expression?: AstExpression): AstReturnStatement { + const node = AstNode.ReturnStatement(); + node.data.expression = expression; + return finish(node); + } + + // @api + function updateReturnStatement(node: AstReturnStatement, expression: AstExpression | undefined) { + return node.data.expression !== expression + ? update(createReturnStatement(expression), node) + : node; + } + + // @api + function createWithStatement(expression: AstExpression, statement: AstStatement) { + const node = AstNode.WithStatement(); + node.data.expression = expression; + node.data.statement = asEmbeddedStatement(statement); + return finish(node); + } + + // @api + function updateWithStatement(node: AstWithStatement, expression: AstExpression, statement: AstStatement) { + return node.data.expression !== expression + || node.data.statement !== statement + ? update(createWithStatement(expression, statement), node) + : node; + } + + // @api + function createSwitchStatement(expression: AstExpression, caseBlock: AstCaseBlock): AstSwitchStatement { + const node = AstNode.SwitchStatement(); + node.data.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + node.data.caseBlock = caseBlock; + node.data.possiblyExhaustive = false; // initialized by binder + return finish(node); + } + + // @api + function updateSwitchStatement(node: AstSwitchStatement, expression: AstExpression, caseBlock: AstCaseBlock) { + return node.data.expression !== expression + || node.data.caseBlock !== caseBlock + ? update(createSwitchStatement(expression, caseBlock), node) + : node; + } + + // @api + function createLabeledStatement(label: string | AstIdentifier, statement: AstStatement) { + const node = AstNode.LabeledStatement(); + node.data.label = asName(label); + node.data.statement = asEmbeddedStatement(statement); + return finish(node); + } + + // @api + function updateLabeledStatement(node: AstLabeledStatement, label: AstIdentifier, statement: AstStatement) { + return node.data.label !== label + || node.data.statement !== statement + ? update(createLabeledStatement(label, statement), node) + : node; + } + + // @api + function createThrowStatement(expression: AstExpression) { + const node = AstNode.ThrowStatement(); + node.data.expression = expression; + return finish(node); + } + + // @api + function updateThrowStatement(node: AstThrowStatement, expression: AstExpression) { + return node.data.expression !== expression + ? update(createThrowStatement(expression), node) + : node; + } + + // @api + function createTryStatement(tryBlock: AstBlock, catchClause: AstCatchClause | undefined, finallyBlock: AstBlock | undefined) { + const node = AstNode.TryStatement(); + node.data.tryBlock = tryBlock; + node.data.catchClause = catchClause; + node.data.finallyBlock = finallyBlock; + return finish(node); + } + + // @api + function updateTryStatement(node: AstTryStatement, tryBlock: AstBlock, catchClause: AstCatchClause | undefined, finallyBlock: AstBlock | undefined) { + return node.data.tryBlock !== tryBlock + || node.data.catchClause !== catchClause + || node.data.finallyBlock !== finallyBlock + ? update(createTryStatement(tryBlock, catchClause, finallyBlock), node) + : node; + } + + // @api + function createDebuggerStatement() { + const node = AstNode.DebuggerStatement(); + return finish(node); + } + + // @api + function createVariableDeclaration(name: string | AstBindingName, exclamationToken: AstExclamationToken | undefined, type: AstTypeNode | undefined, initializer: AstExpression | undefined) { + const node = AstNode.VariableDeclaration(); + node.data.name = asName(name); + node.data.exclamationToken = exclamationToken; + node.data.type = type; + node.data.initializer = asInitializer(initializer); + return finish(node); + } + + // @api + function updateVariableDeclaration(node: AstVariableDeclaration, name: AstBindingName, exclamationToken: AstExclamationToken | undefined, type: AstTypeNode | undefined, initializer: AstExpression | undefined) { + return node.data.name !== name + || node.data.type !== type + || node.data.exclamationToken !== exclamationToken + || node.data.initializer !== initializer + ? update(createVariableDeclaration(name, exclamationToken, type, initializer), node) + : node; + } + + // @api + function createVariableDeclarationList(declarations: AstNodeArrayLike, flags = NodeFlags.None) { + const node = AstNode.VariableDeclarationList(); + node.flags |= flags & NodeFlags.BlockScoped; + node.data.declarations = createNodeArray(declarations); + return finish(node); + } + + // @api + function updateVariableDeclarationList(node: AstVariableDeclarationList, declarations: AstNodeArrayLike) { + return !sameNodeArray(node.data.declarations, declarations) + ? update(createVariableDeclarationList(declarations, node.flags), node) + : node; + } + + // @api + function createFunctionDeclaration( + modifiers: AstNodeArrayLike | undefined, + asteriskToken: AstAsteriskToken | undefined, + name: string | AstIdentifier | undefined, + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + body: AstBlock | undefined, + ) { + const node = AstNode.FunctionDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.asteriskToken = asteriskToken; + node.data.name = asName(name); + node.data.typeParameters = asNodeArray(typeParameters); + node.data.parameters = createNodeArray(parameters); + node.data.type = type; + node.data.body = body; + return finish(node); + } + + // @api + function updateFunctionDeclaration( + node: AstFunctionDeclaration, + modifiers: AstNodeArrayLike | undefined, + asteriskToken: AstAsteriskToken | undefined, + name: AstIdentifier | undefined, + typeParameters: AstNodeArrayLike | undefined, + parameters: AstNodeArrayLike, + type: AstTypeNode | undefined, + body: AstBlock | undefined, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.asteriskToken !== asteriskToken + || node.data.name !== name + || !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + || node.data.body !== body + ? finishUpdateBaseSignatureDeclaration(createFunctionDeclaration(modifiers, asteriskToken, name, typeParameters, parameters, type, body), node) + : node; + } + + // @api + function createClassDeclaration( + modifiers: AstNodeArrayLike | undefined, + name: string | AstIdentifier | undefined, + typeParameters: AstNodeArrayLike | undefined, + heritageClauses: AstNodeArrayLike | undefined, + members: AstNodeArrayLike, + ) { + const node = AstNode.ClassDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.name = asName(name); + node.data.typeParameters = asNodeArray(typeParameters); + node.data.heritageClauses = asNodeArray(heritageClauses); + node.data.members = createNodeArray(members); + return finish(node); + } + + // @api + function updateClassDeclaration( + node: AstClassDeclaration, + modifiers: AstNodeArrayLike | undefined, + name: AstIdentifier | undefined, + typeParameters: AstNodeArrayLike | undefined, + heritageClauses: AstNodeArrayLike | undefined, + members: AstNodeArrayLike, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.name !== name + || !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.heritageClauses, heritageClauses) + || !sameNodeArray(node.data.members, members) + ? update(createClassDeclaration(modifiers, name, typeParameters, heritageClauses, members), node) + : node; + } + + // @api + function createInterfaceDeclaration( + modifiers: AstNodeArrayLike | undefined, + name: string | AstIdentifier, + typeParameters: AstNodeArrayLike | undefined, + heritageClauses: AstNodeArrayLike | undefined, + members: AstNodeArrayLike, + ) { + const node = AstNode.InterfaceDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.name = asName(name); + node.data.typeParameters = asNodeArray(typeParameters); + node.data.heritageClauses = asNodeArray(heritageClauses); + node.data.members = createNodeArray(members); + return finish(node); + } + + // @api + function updateInterfaceDeclaration( + node: AstInterfaceDeclaration, + modifiers: AstNodeArrayLike | undefined, + name: AstIdentifier, + typeParameters: AstNodeArrayLike | undefined, + heritageClauses: AstNodeArrayLike | undefined, + members: AstNodeArrayLike, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.name !== name + || !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.heritageClauses, heritageClauses) + || !sameNodeArray(node.data.members, members) + ? update(createInterfaceDeclaration(modifiers, name, typeParameters, heritageClauses, members), node) + : node; + } + + // @api + function createTypeAliasDeclaration( + modifiers: AstNodeArrayLike | undefined, + name: string | AstIdentifier, + typeParameters: AstNodeArrayLike | undefined, + type: AstTypeNode, + ) { + const node = AstNode.TypeAliasDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.name = asName(name); + node.data.typeParameters = asNodeArray(typeParameters); + node.data.type = type; + return finish(node); + } + + // @api + function updateTypeAliasDeclaration( + node: AstTypeAliasDeclaration, + modifiers: AstNodeArrayLike | undefined, + name: AstIdentifier, + typeParameters: AstNodeArrayLike | undefined, + type: AstTypeNode, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.name !== name + || !sameNodeArray(node.data.typeParameters, typeParameters) + || node.data.type !== type + ? update(createTypeAliasDeclaration(modifiers, name, typeParameters, type), node) + : node; + } + + // @api + function createEnumDeclaration( + modifiers: AstNodeArrayLike | undefined, + name: string | AstIdentifier, + members: AstNodeArrayLike, + ) { + const node = AstNode.EnumDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.name = asName(name); + node.data.members = createNodeArray(members); + return finish(node); + } + + // @api + function updateEnumDeclaration( + node: AstEnumDeclaration, + modifiers: AstNodeArrayLike | undefined, + name: AstIdentifier, + members: AstNodeArrayLike, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.name !== name + || !sameNodeArray(node.data.members, members) + ? update(createEnumDeclaration(modifiers, name, members), node) + : node; + } + + // @api + function createModuleDeclaration( + modifiers: AstNodeArrayLike | undefined, + name: AstModuleName, + body: AstModuleBody | undefined, + flags = NodeFlags.None, + ) { + const node = AstNode.ModuleDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.flags |= flags & (NodeFlags.Namespace | NodeFlags.NestedNamespace | NodeFlags.GlobalAugmentation); + node.data.name = name; + node.data.body = body; + return finish(node); + } + + // @api + function updateModuleDeclaration( + node: AstModuleDeclaration, + modifiers: AstNodeArrayLike | undefined, + name: AstModuleName, + body: AstModuleBody | undefined, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.name !== name + || node.data.body !== body + ? update(createModuleDeclaration(modifiers, name, body, node.flags), node) + : node; + } + + // @api + function createModuleBlock(statements: AstNodeArrayLike) { + const node = AstNode.ModuleBlock(); + node.data.statements = createNodeArray(statements); + return finish(node); + } + + // @api + function updateModuleBlock(node: AstModuleBlock, statements: AstNodeArrayLike) { + return !sameNodeArray(node.data.statements, statements) + ? update(createModuleBlock(statements), node) + : node; + } + + // @api + function createCaseBlock(clauses: AstNodeArrayLike): AstCaseBlock { + const node = AstNode.CaseBlock(); + node.data.clauses = createNodeArray(clauses); + return finish(node); + } + + // @api + function updateCaseBlock(node: AstCaseBlock, clauses: AstNodeArrayLike) { + return !sameNodeArray(node.data.clauses, clauses) + ? update(createCaseBlock(clauses), node) + : node; + } + + // @api + function createNamespaceExportDeclaration(name: string | AstIdentifier) { + const node = AstNode.NamespaceExportDeclaration(); + node.data.name = asName(name); + return finish(node); + } + + // @api + function updateNamespaceExportDeclaration(node: AstNamespaceExportDeclaration, name: AstIdentifier) { + return node.data.name !== name + ? finishUpdateNamespaceExportDeclaration(createNamespaceExportDeclaration(name), node) + : node; + } + + function finishUpdateNamespaceExportDeclaration(updated: AstNamespaceExportDeclaration, original: AstNamespaceExportDeclaration) { + if (updated !== original) { + // copy children used only for error reporting + updated.data.modifiers = original.data.modifiers; + } + return update(updated, original); + } + + // @api + function createImportEqualsDeclaration( + modifiers: AstNodeArrayLike | undefined, + isTypeOnly: boolean, + name: string | AstIdentifier, + moduleReference: AstModuleReference, + ) { + const node = AstNode.ImportEqualsDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.name = asName(name); + node.data.isTypeOnly = isTypeOnly; + node.data.moduleReference = moduleReference; + return finish(node); + } + + // @api + function updateImportEqualsDeclaration( + node: AstImportEqualsDeclaration, + modifiers: AstNodeArrayLike | undefined, + isTypeOnly: boolean, + name: AstIdentifier, + moduleReference: AstModuleReference, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.isTypeOnly !== isTypeOnly + || node.data.name !== name + || node.data.moduleReference !== moduleReference + ? update(createImportEqualsDeclaration(modifiers, isTypeOnly, name, moduleReference), node) + : node; + } + + // @api + function createImportDeclaration( + modifiers: AstNodeArrayLike | undefined, + importClause: AstImportClause | undefined, + moduleSpecifier: AstExpression, + attributes: AstImportAttributes | undefined, + ): AstImportDeclaration { + const node = AstNode.ImportDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.importClause = importClause; + node.data.moduleSpecifier = moduleSpecifier; + node.data.attributes = attributes; + return finish(node); + } + + // @api + function updateImportDeclaration( + node: AstImportDeclaration, + modifiers: AstNodeArrayLike | undefined, + importClause: AstImportClause | undefined, + moduleSpecifier: AstExpression, + attributes: AstImportAttributes | undefined, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.importClause !== importClause + || node.data.moduleSpecifier !== moduleSpecifier + || node.data.attributes !== attributes + ? update(createImportDeclaration(modifiers, importClause, moduleSpecifier, attributes), node) + : node; + } + + // @api + function createImportClause(isTypeOnly: boolean, name: AstIdentifier | undefined, namedBindings: AstNamedImportBindings | undefined): AstImportClause { + const node = AstNode.ImportClause(); + node.data.isTypeOnly = isTypeOnly; + node.data.name = name; + node.data.namedBindings = namedBindings; + // node.transformFlags |= propagateChildFlags(node.name) | + // propagateChildFlags(node.namedBindings); + // if (isTypeOnly) { + // node.transformFlags |= TransformFlags.ContainsTypeScript; + // } + // node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context + return finish(node); + } + + // @api + function updateImportClause(node: AstImportClause, isTypeOnly: boolean, name: AstIdentifier | undefined, namedBindings: AstNamedImportBindings | undefined) { + return node.data.isTypeOnly !== isTypeOnly + || node.data.name !== name + || node.data.namedBindings !== namedBindings + ? update(createImportClause(isTypeOnly, name, namedBindings), node) + : node; + } + + // @api + function createAssertClause(elements: AstNodeArrayLike, multiLine?: boolean): AstAssertClause { + const node = AstNode.ImportAttributes(); + node.data.elements = createNodeArray(elements); + node.data.multiLine = multiLine; + node.data.token = SyntaxKind.AssertKeyword; + return finish(node); + } + + // @api + function updateAssertClause(node: AstAssertClause, elements: AstNodeArrayLike, multiLine?: boolean): AstAssertClause { + return !sameNodeArray(node.data.elements, elements) + || node.data.multiLine !== multiLine + ? update(createAssertClause(elements, multiLine), node) + : node; + } + + // @api + function createAssertEntry(name: AstAssertionKey, value: AstExpression): AstImportAttribute { + const node = AstNode.ImportAttribute(); + node.data.name = name; + node.data.value = value; + return finish(node); + } + + // @api + function updateAssertEntry(node: AstImportAttribute, name: AstAssertionKey, value: AstExpression): AstImportAttribute { + return node.data.name !== name + || node.data.value !== value + ? update(createAssertEntry(name, value), node) + : node; + } + + // @api + function createImportTypeAssertionContainer(clause: AstAssertClause, multiLine = false): AstImportTypeAssertionContainer { + const node = AstNode.ImportTypeAssertionContainer(); + node.data.assertClause = clause; + node.data.multiLine = multiLine; + return finish(node); + } + + // @api + function updateImportTypeAssertionContainer(node: AstImportTypeAssertionContainer, clause: AstAssertClause, multiLine?: boolean): AstImportTypeAssertionContainer { + return node.data.assertClause !== clause + || node.data.multiLine !== multiLine + ? update(createImportTypeAssertionContainer(clause, multiLine), node) + : node; + } + + // @api + function createImportAttributes(elements: AstNodeArrayLike, multiLine?: boolean): AstImportAttributes; + function createImportAttributes(elements: AstNodeArrayLike, multiLine?: boolean, token?: AstImportAttributes["data"]["token"]): AstImportAttributes; + function createImportAttributes(elements: AstNodeArrayLike, multiLine?: boolean, token?: AstImportAttributes["data"]["token"]): AstImportAttributes { + const node = AstNode.ImportAttributes(); + node.data.token = token ?? SyntaxKind.WithKeyword; + node.data.elements = createNodeArray(elements); + node.data.multiLine = multiLine; + return finish(node); + } + + // @api + function updateImportAttributes(node: AstImportAttributes, elements: AstNodeArrayLike, multiLine?: boolean): AstImportAttributes { + return !sameNodeArray(node.data.elements, elements) + || node.data.multiLine !== multiLine + ? update(createImportAttributes(elements, multiLine, node.data.token), node) + : node; + } + + // @api + function createImportAttribute(name: AstImportAttributeName, value: AstExpression): AstImportAttribute { + const node = AstNode.ImportAttribute(); + node.data.name = name; + node.data.value = value; + return finish(node); + } + + // @api + function updateImportAttribute(node: AstImportAttribute, name: AstImportAttributeName, value: AstExpression): AstImportAttribute { + return node.data.name !== name + || node.data.value !== value + ? update(createImportAttribute(name, value), node) + : node; + } + + // @api + function createNamespaceImport(name: AstIdentifier): AstNamespaceImport { + const node = AstNode.NamespaceImport(); + node.data.name = name; + return finish(node); + } + + // @api + function updateNamespaceImport(node: AstNamespaceImport, name: AstIdentifier) { + return node.data.name !== name + ? update(createNamespaceImport(name), node) + : node; + } + + // @api + function createNamespaceExport(name: AstModuleExportName): AstNamespaceExport { + const node = AstNode.NamespaceExport(); + node.data.name = name; + return finish(node); + } + + // @api + function updateNamespaceExport(node: AstNamespaceExport, name: AstModuleExportName) { + return node.data.name !== name + ? update(createNamespaceExport(name), node) + : node; + } + + // @api + function createNamedImports(elements: AstNodeArrayLike): AstNamedImports { + const node = AstNode.NamedImports(); + node.data.elements = createNodeArray(elements); + return finish(node); + } + + // @api + function updateNamedImports(node: AstNamedImports, elements: AstNodeArrayLike) { + return !sameNodeArray(node.data.elements, elements) + ? update(createNamedImports(elements), node) + : node; + } + + // @api + function createImportSpecifier(isTypeOnly: boolean, propertyName: AstModuleExportName | undefined, name: AstIdentifier) { + const node = AstNode.ImportSpecifier(); + node.data.isTypeOnly = isTypeOnly; + node.data.propertyName = propertyName; + node.data.name = name; + return finish(node); + } + + // @api + function updateImportSpecifier(node: AstImportSpecifier, isTypeOnly: boolean, propertyName: AstModuleExportName | undefined, name: AstIdentifier) { + return node.data.isTypeOnly !== isTypeOnly + || node.data.propertyName !== propertyName + || node.data.name !== name + ? update(createImportSpecifier(isTypeOnly, propertyName, name), node) + : node; + } + + // @api + function createExportAssignment( + modifiers: AstNodeArrayLike | undefined, + isExportEquals: boolean | undefined, + expression: AstExpression, + ) { + const node = AstNode.ExportAssignment(); + node.data.modifiers = asNodeArray(modifiers); + node.data.isExportEquals = isExportEquals; + node.data.expression = isExportEquals + ? parenthesizerRules().parenthesizeRightSideOfBinary(SyntaxKind.EqualsToken, /*leftSide*/ undefined, expression) + : parenthesizerRules().parenthesizeExpressionOfExportDefault(expression); + return finish(node); + } + + // @api + function updateExportAssignment( + node: AstExportAssignment, + modifiers: AstNodeArrayLike | undefined, + expression: AstExpression, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.expression !== expression + ? update(createExportAssignment(modifiers, node.data.isExportEquals, expression), node) + : node; + } + + // @api + function createExportDeclaration( + modifiers: AstNodeArrayLike | undefined, + isTypeOnly: boolean, + exportClause: AstNamedExportBindings | undefined, + moduleSpecifier?: AstExpression, + attributes?: AstImportAttributes, + ) { + const node = AstNode.ExportDeclaration(); + node.data.modifiers = asNodeArray(modifiers); + node.data.isTypeOnly = isTypeOnly; + node.data.exportClause = exportClause; + node.data.moduleSpecifier = moduleSpecifier; + node.data.attributes = attributes; + return finish(node); + } + + // @api + function updateExportDeclaration( + node: AstExportDeclaration, + modifiers: AstNodeArrayLike | undefined, + isTypeOnly: boolean, + exportClause: AstNamedExportBindings | undefined, + moduleSpecifier: AstExpression | undefined, + attributes: AstImportAttributes | undefined, + ) { + return !sameNodeArray(node.data.modifiers, modifiers) + || node.data.isTypeOnly !== isTypeOnly + || node.data.exportClause !== exportClause + || node.data.moduleSpecifier !== moduleSpecifier + || node.data.attributes !== attributes + ? update(createExportDeclaration(modifiers, isTypeOnly, exportClause, moduleSpecifier, attributes), node) + : node; + } + + // @api + function createNamedExports(elements: AstNodeArrayLike) { + const node = AstNode.NamedExports(); + node.data.elements = createNodeArray(elements); + return finish(node); + } + + // @api + function updateNamedExports(node: AstNamedExports, elements: AstNodeArrayLike) { + return !sameNodeArray(node.data.elements, elements) + ? update(createNamedExports(elements), node) + : node; + } + + // @api + function createExportSpecifier(isTypeOnly: boolean, propertyName: string | AstModuleExportName | undefined, name: string | AstModuleExportName) { + const node = AstNode.ExportSpecifier(); + node.data.isTypeOnly = isTypeOnly; + node.data.propertyName = asName(propertyName); + node.data.name = asName(name); + return finish(node); + } + + // @api + function updateExportSpecifier(node: AstExportSpecifier, isTypeOnly: boolean, propertyName: AstModuleExportName | undefined, name: AstModuleExportName) { + return node.data.isTypeOnly !== isTypeOnly + || node.data.propertyName !== propertyName + || node.data.name !== name + ? update(createExportSpecifier(isTypeOnly, propertyName, name), node) + : node; + } + + // @api + function createMissingDeclaration(): AstMissingDeclaration { + const node = AstNode.MissingDeclaration(); + return finish(node); + } + + // + // Module references + // + + // @api + function createExternalModuleReference(expression: AstExpression) { + const node = AstNode.ExternalModuleReference(); + node.data.expression = expression; + return finish(node); + } + + // @api + function updateExternalModuleReference(node: AstExternalModuleReference, expression: AstExpression) { + return node.data.expression !== expression + ? update(createExternalModuleReference(expression), node) + : node; + } + + // + // JSDoc + // + + // @api + function createJSDocAllType() { + return finish(AstNode.JSDocAllType()); + } + + // @api + function createJSDocUnknownType() { + return finish(AstNode.JSDocUnknownType()); + } + + // @api + function createJSDocNonNullableType(type: AstTypeNode, postfix = false): AstJSDocNonNullableType { + const node = AstNode.JSDocNonNullableType(); + node.data.type = postfix ? type && parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(type) : type; + node.data.postfix = postfix; + return finish(node); + } + + // @api + function updateJSDocNonNullableType(node: AstJSDocNonNullableType, type: AstTypeNode): AstJSDocNonNullableType { + return node.data.type !== type + ? update(createJSDocNonNullableType(type, node.data.postfix), node) + : node; + } + + // @api + function createJSDocNullableType(type: AstTypeNode, postfix = false): AstJSDocNullableType { + const node = AstNode.JSDocNullableType(); + node.data.type = postfix ? type && parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(type) : type; + node.data.postfix = postfix; + return finish(node); + } + + // @api + function updateJSDocNullableType(node: AstJSDocNullableType, type: AstTypeNode): AstJSDocNullableType { + return node.data.type !== type + ? update(createJSDocNullableType(type, node.data.postfix), node) + : node; + } + + // @api + function createJSDocOptionalType(type: AstTypeNode): AstJSDocOptionalType { + const node = AstNode.JSDocOptionalType(); + node.data.type = type; + return finish(node); + } + + // @api + function updateJSDocOptionalType(node: AstJSDocOptionalType, type: AstTypeNode): AstJSDocOptionalType { + return node.data.type !== type + ? update(createJSDocOptionalType(type), node) + : node; + } + + // @api + function createJSDocVariadicType(type: AstTypeNode): AstJSDocVariadicType { + const node = AstNode.JSDocVariadicType(); + node.data.type = type; + return finish(node); + } + + // @api + function updateJSDocVariadicType(node: AstJSDocVariadicType, type: AstTypeNode): AstJSDocVariadicType { + return node.data.type !== type + ? update(createJSDocVariadicType(type), node) + : node; + } + + // @api + function createJSDocNamepathType(type: AstTypeNode): AstJSDocNamepathType { + const node = AstNode.JSDocNamepathType(); + node.data.type = type; + return finish(node); + } + + // @api + function updateJSDocNamepathType(node: AstJSDocNamepathType, type: AstTypeNode): AstJSDocNamepathType { + return node.data.type !== type + ? update(createJSDocNamepathType(type), node) + : node; + } + + // @api + function createJSDocFunctionType(parameters: AstNodeArrayLike, type: AstTypeNode | undefined): AstJSDocFunctionType { + const node = AstNode.JSDocFunctionType(); + node.data.parameters = asNodeArray(parameters); + node.data.type = type; + return finish(node); + } + + // @api + function updateJSDocFunctionType(node: AstJSDocFunctionType, parameters: AstNodeArrayLike, type: AstTypeNode | undefined): AstJSDocFunctionType { + return !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + ? update(createJSDocFunctionType(parameters, type), node) + : node; + } + + // @api + function createJSDocTypeLiteral(propertyTags?: AstNodeArrayLike, isArrayType = false): AstJSDocTypeLiteral { + const node = AstNode.JSDocTypeLiteral(); + node.data.jsDocPropertyTags = asNodeArray(propertyTags); + node.data.isArrayType = isArrayType; + return finish(node); + } + + // @api + function updateJSDocTypeLiteral(node: AstJSDocTypeLiteral, propertyTags: AstNodeArrayLike | undefined, isArrayType: boolean): AstJSDocTypeLiteral { + return !sameNodeArray(node.data.jsDocPropertyTags, propertyTags) + || node.data.isArrayType !== isArrayType + ? update(createJSDocTypeLiteral(propertyTags, isArrayType), node) + : node; + } + + // @api + function createJSDocTypeExpression(type: AstTypeNode): AstJSDocTypeExpression { + const node = AstNode.JSDocTypeExpression(); + node.data.type = type; + return finish(node); + } + + // @api + function updateJSDocTypeExpression(node: AstJSDocTypeExpression, type: AstTypeNode): AstJSDocTypeExpression { + return node.data.type !== type + ? update(createJSDocTypeExpression(type), node) + : node; + } + + // @api + function createJSDocSignature(typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type?: AstJSDocReturnTag): AstJSDocSignature { + const node = AstNode.JSDocSignature(); + node.data.typeParameters = asNodeArray(typeParameters); + node.data.parameters = createNodeArray(parameters); + node.data.type = type; + return finish(node); + } + + // @api + function updateJSDocSignature(node: AstJSDocSignature, typeParameters: AstNodeArrayLike | undefined, parameters: AstNodeArrayLike, type: AstJSDocReturnTag | undefined): AstJSDocSignature { + return !sameNodeArray(node.data.typeParameters, typeParameters) + || !sameNodeArray(node.data.parameters, parameters) + || node.data.type !== type + ? update(createJSDocSignature(typeParameters, parameters, type), node) + : node; + } + + function getDefaultTagName(node: AstJSDocTag) { + const defaultTagName = getDefaultTagNameForKind(node.kind); + return node.data.tagName.data.escapedText === escapeLeadingUnderscores(defaultTagName) + ? node.data.tagName + : createIdentifier(defaultTagName); + } + + // @api + function createJSDocTemplateTag(tagName: AstIdentifier | undefined, constraint: AstJSDocTypeExpression | undefined, typeParameters: AstNodeArrayLike, comment?: string | AstNodeArray): AstJSDocTemplateTag { + const node = AstNode.JSDocTemplateTag(); + node.data.tagName = tagName ?? createIdentifier("template"); + node.data.comment = comment; + node.data.constraint = constraint; + node.data.typeParameters = createNodeArray(typeParameters); + return finish(node); + } + + // @api + function updateJSDocTemplateTag(node: AstJSDocTemplateTag, tagName: AstIdentifier = getDefaultTagName(node), constraint: AstJSDocTypeExpression | undefined, typeParameters: AstNodeArrayLike, comment: string | AstNodeArray | undefined): AstJSDocTemplateTag { + return node.data.tagName !== tagName + || node.data.constraint !== constraint + || !sameNodeArray(node.data.typeParameters, typeParameters) + || node.data.comment !== comment + ? update(createJSDocTemplateTag(tagName, constraint, typeParameters, comment), node) + : node; + } + + // @api + function createJSDocTypedefTag(tagName: AstIdentifier | undefined, typeExpression?: AstJSDocTypeExpression, fullName?: AstIdentifier | AstJSDocNamespaceDeclaration, comment?: string | AstNodeArray): AstJSDocTypedefTag { + const node = AstNode.JSDocTypedefTag(); + node.data.tagName = tagName ?? createIdentifier("typedef"); + node.data.comment = comment; + node.data.typeExpression = typeExpression; + node.data.fullName = fullName; + node.data.name = getJSDocTypeAliasName(fullName); + return finish(node); + } + + // @api + function updateJSDocTypedefTag(node: AstJSDocTypedefTag, tagName: AstIdentifier = getDefaultTagName(node), typeExpression: AstJSDocTypeExpression | undefined, fullName: AstIdentifier | AstJSDocNamespaceDeclaration | undefined, comment: string | AstNodeArray | undefined): AstJSDocTypedefTag { + return node.data.tagName !== tagName + || node.data.typeExpression !== typeExpression + || node.data.fullName !== fullName + || node.data.comment !== comment + ? update(createJSDocTypedefTag(tagName, typeExpression, fullName, comment), node) + : node; + } + + // @api + function createJSDocParameterTag(tagName: AstIdentifier | undefined, name: AstEntityName, isBracketed: boolean, typeExpression?: AstJSDocTypeExpression, isNameFirst?: boolean, comment?: string | AstNodeArray): AstJSDocParameterTag { + const node = AstNode.JSDocParameterTag(); + node.data.tagName = tagName ?? createIdentifier("param"); + node.data.comment = comment; + node.data.typeExpression = typeExpression; + node.data.name = name; + node.data.isNameFirst = !!isNameFirst; + node.data.isBracketed = isBracketed; + return finish(node); + } + + // @api + function updateJSDocParameterTag(node: AstJSDocParameterTag, tagName: AstIdentifier = getDefaultTagName(node), name: AstEntityName, isBracketed: boolean, typeExpression: AstJSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | AstNodeArray | undefined): AstJSDocParameterTag { + return node.data.tagName !== tagName + || node.data.name !== name + || node.data.isBracketed !== isBracketed + || node.data.typeExpression !== typeExpression + || node.data.isNameFirst !== isNameFirst + || node.data.comment !== comment + ? update(createJSDocParameterTag(tagName, name, isBracketed, typeExpression, isNameFirst, comment), node) + : node; + } + + // @api + function createJSDocPropertyTag(tagName: AstIdentifier | undefined, name: AstEntityName, isBracketed: boolean, typeExpression?: AstJSDocTypeExpression, isNameFirst?: boolean, comment?: string | AstNodeArray): AstJSDocPropertyTag { + const node = AstNode.JSDocPropertyTag(); + node.data.tagName = tagName ?? createIdentifier("prop"); + node.data.comment = comment; + node.data.typeExpression = typeExpression; + node.data.name = name; + node.data.isNameFirst = !!isNameFirst; + node.data.isBracketed = isBracketed; + return finish(node); + } + + // @api + function updateJSDocPropertyTag(node: AstJSDocPropertyTag, tagName: AstIdentifier = getDefaultTagName(node), name: AstEntityName, isBracketed: boolean, typeExpression: AstJSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | AstNodeArray | undefined): AstJSDocPropertyTag { + return node.data.tagName !== tagName + || node.data.name !== name + || node.data.isBracketed !== isBracketed + || node.data.typeExpression !== typeExpression + || node.data.isNameFirst !== isNameFirst + || node.data.comment !== comment + ? update(createJSDocPropertyTag(tagName, name, isBracketed, typeExpression, isNameFirst, comment), node) + : node; + } + + // @api + function createJSDocCallbackTag(tagName: AstIdentifier | undefined, typeExpression: AstJSDocSignature, fullName?: AstIdentifier | AstJSDocNamespaceDeclaration, comment?: string | AstNodeArray): AstJSDocCallbackTag { + const node = AstNode.JSDocCallbackTag(); + node.data.tagName = tagName ?? createIdentifier("callback"); + node.data.comment = comment; + node.data.typeExpression = typeExpression; + node.data.fullName = fullName; + node.data.name = getJSDocTypeAliasName(fullName); + + // node.locals = undefined; // initialized by binder (LocalsContainer) + // node.nextContainer = undefined; // initialized by binder (LocalsContainer) + return finish(node); + } + + // @api + function updateJSDocCallbackTag(node: AstJSDocCallbackTag, tagName: AstIdentifier = getDefaultTagName(node), typeExpression: AstJSDocSignature, fullName: AstIdentifier | AstJSDocNamespaceDeclaration | undefined, comment: string | AstNodeArray | undefined): AstJSDocCallbackTag { + return node.data.tagName !== tagName + || node.data.typeExpression !== typeExpression + || node.data.fullName !== fullName + || node.data.comment !== comment + ? update(createJSDocCallbackTag(tagName, typeExpression, fullName, comment), node) + : node; + } + + // @api + function createJSDocOverloadTag(tagName: AstIdentifier | undefined, typeExpression: AstJSDocSignature, comment?: string | AstNodeArray): AstJSDocOverloadTag { + const node = AstNode.JSDocOverloadTag(); + node.data.tagName = tagName ?? createIdentifier("overload"); + node.data.comment = comment; + node.data.typeExpression = typeExpression; + return finish(node); + } + + // @api + function updateJSDocOverloadTag(node: AstJSDocOverloadTag, tagName: AstIdentifier = getDefaultTagName(node), typeExpression: AstJSDocSignature, comment: string | AstNodeArray | undefined): AstJSDocOverloadTag { + return node.data.tagName !== tagName + || node.data.typeExpression !== typeExpression + || node.data.comment !== comment + ? update(createJSDocOverloadTag(tagName, typeExpression, comment), node) + : node; + } + + // @api + function createJSDocAugmentsTag(tagName: AstIdentifier | undefined, className: AstJSDocAugmentsTag["data"]["class"], comment?: string | AstNodeArray): AstJSDocAugmentsTag { + const node = AstNode.JSDocAugmentsTag(); + node.data.tagName = tagName ?? createIdentifier("augments"); + node.data.comment = comment; + node.data.class = className; + return finish(node); + } + + // @api + function updateJSDocAugmentsTag(node: AstJSDocAugmentsTag, tagName: AstIdentifier = getDefaultTagName(node), className: AstJSDocAugmentsTag["data"]["class"], comment: string | AstNodeArray | undefined): AstJSDocAugmentsTag { + return node.data.tagName !== tagName + || node.data.class !== className + || node.data.comment !== comment + ? update(createJSDocAugmentsTag(tagName, className, comment), node) + : node; + } + + // @api + function createJSDocImplementsTag(tagName: AstIdentifier | undefined, className: AstJSDocImplementsTag["data"]["class"], comment?: string | AstNodeArray): AstJSDocImplementsTag { + const node = AstNode.JSDocImplementsTag(); + node.data.tagName = tagName ?? createIdentifier("implements"); + node.data.comment = comment; + node.data.class = className; + return finish(node); + } + + // @api + function createJSDocSeeTag(tagName: AstIdentifier | undefined, name: AstJSDocNameReference | undefined, comment?: string | AstNodeArray): AstJSDocSeeTag { + const node = AstNode.JSDocSeeTag(); + node.data.tagName = tagName ?? createIdentifier("see"); + node.data.comment = comment; + node.data.name = name; + return finish(node); + } + + // @api + function updateJSDocSeeTag(node: AstJSDocSeeTag, tagName: AstIdentifier | undefined, name: AstJSDocNameReference | undefined, comment?: string | AstNodeArray): AstJSDocSeeTag { + return node.data.tagName !== tagName + || node.data.name !== name + || node.data.comment !== comment + ? update(createJSDocSeeTag(tagName, name, comment), node) + : node; + } + + // @api + function createJSDocNameReference(name: AstEntityName | AstJSDocMemberName): AstJSDocNameReference { + const node = AstNode.JSDocNameReference(); + node.data.name = name; + return finish(node); + } + + // @api + function updateJSDocNameReference(node: AstJSDocNameReference, name: AstEntityName | AstJSDocMemberName): AstJSDocNameReference { + return node.data.name !== name + ? update(createJSDocNameReference(name), node) + : node; + } + + // @api + function createJSDocMemberName(left: AstEntityName | AstJSDocMemberName, right: AstIdentifier) { + const node = AstNode.JSDocMemberName(); + node.data.left = left; + node.data.right = right; + return finish(node); + } + + // @api + function updateJSDocMemberName(node: AstJSDocMemberName, left: AstEntityName | AstJSDocMemberName, right: AstIdentifier) { + return node.data.left !== left + || node.data.right !== right + ? update(createJSDocMemberName(left, right), node) + : node; + } + + // @api + function createJSDocLink(name: AstEntityName | AstJSDocMemberName | undefined, text: string): AstJSDocLink { + const node = AstNode.JSDocLink(); + node.data.name = name; + node.data.text = text; + return finish(node); + } + + // @api + function updateJSDocLink(node: AstJSDocLink, name: AstEntityName | AstJSDocMemberName | undefined, text: string): AstJSDocLink { + return node.data.name !== name + ? update(createJSDocLink(name, text), node) + : node; + } + + // @api + function createJSDocLinkCode(name: AstEntityName | AstJSDocMemberName | undefined, text: string): AstJSDocLinkCode { + const node = AstNode.JSDocLinkCode(); + node.data.name = name; + node.data.text = text; + return finish(node); + } + + // @api + function updateJSDocLinkCode(node: AstJSDocLinkCode, name: AstEntityName | AstJSDocMemberName | undefined, text: string): AstJSDocLinkCode { + return node.data.name !== name + ? update(createJSDocLinkCode(name, text), node) + : node; + } + + // @api + function createJSDocLinkPlain(name: AstEntityName | AstJSDocMemberName | undefined, text: string): AstJSDocLinkPlain { + const node = AstNode.JSDocLinkPlain(); + node.data.name = name; + node.data.text = text; + return finish(node); + } + + // @api + function updateJSDocLinkPlain(node: AstJSDocLinkPlain, name: AstEntityName | AstJSDocMemberName | undefined, text: string): AstJSDocLinkPlain { + return node.data.name !== name + ? update(createJSDocLinkPlain(name, text), node) + : node; + } + + // @api + function updateJSDocImplementsTag(node: AstJSDocImplementsTag, tagName: AstIdentifier = getDefaultTagName(node), className: AstJSDocImplementsTag["data"]["class"], comment: string | AstNodeArray | undefined): AstJSDocImplementsTag { + return node.data.tagName !== tagName + || node.data.class !== className + || node.data.comment !== comment + ? update(createJSDocImplementsTag(tagName, className, comment), node) + : node; + } + + + // @api + // createJSDocAuthorTag + // createJSDocClassTag + // createJSDocPublicTag + // createJSDocPrivateTag + // createJSDocProtectedTag + // createJSDocReadonlyTag + // createJSDocDeprecatedTag + function createJSDocSimpleTag(makeTag: () => T, tagName: AstIdentifier | undefined, comment?: string | AstNodeArray) { + const node = makeTag(); + node.data.tagName = tagName ?? createIdentifier(getDefaultTagNameForKind(node.kind)); + node.data.comment = comment; + return finish(node); + } + + // @api + // updateJSDocAuthorTag + // updateJSDocClassTag + // updateJSDocPublicTag + // updateJSDocPrivateTag + // updateJSDocProtectedTag + // updateJSDocReadonlyTag + // updateJSDocDeprecatedTag + function updateJSDocSimpleTag(makeTag: () => T, node: T, tagName: AstIdentifier = getDefaultTagName(node), comment: string | AstNodeArray | undefined) { + return node.data.tagName !== tagName + || node.data.comment !== comment + ? update(createJSDocSimpleTag(makeTag, tagName, comment), node) : + node; + } + + // @api + // createJSDocTypeTag + // createJSDocReturnTag + // createJSDocThisTag + // createJSDocEnumTag + // createJSDocSatisfiesTag + function createJSDocTypeLikeTag(makeTag: () => T, tagName: AstIdentifier | undefined, typeExpression?: AstJSDocTypeExpression, comment?: string | AstNodeArray) { + const node = createJSDocSimpleTag(makeTag, tagName, comment); + node.data.typeExpression = typeExpression; + return finish(node); + } + + // @api + // updateJSDocTypeTag + // updateJSDocReturnTag + // updateJSDocThisTag + // updateJSDocEnumTag + // updateJSDocSatisfiesTag + function updateJSDocTypeLikeTag(makeTag: () => T, node: T, tagName: AstIdentifier = getDefaultTagName(node), typeExpression: AstJSDocTypeExpression | undefined, comment: string | AstNodeArray | undefined) { + return node.data.tagName !== tagName + || node.data.typeExpression !== typeExpression + || node.data.comment !== comment + ? update(createJSDocTypeLikeTag(makeTag, tagName, typeExpression, comment), node) + : node; + } + + // @api + function createJSDocUnknownTag(tagName: AstIdentifier, comment?: string | AstNodeArray): AstJSDocUnknownTag { + const node = createJSDocSimpleTag(AstNode.JSDocUnknownTag, tagName, comment); + return finish(node); + } + + // @api + function updateJSDocUnknownTag(node: AstJSDocUnknownTag, tagName: AstIdentifier, comment: string | AstNodeArray | undefined): AstJSDocUnknownTag { + return node.data.tagName !== tagName + || node.data.comment !== comment + ? update(createJSDocUnknownTag(tagName, comment), node) + : node; + } + + // @api + function createJSDocEnumTag(tagName: AstIdentifier | undefined, typeExpression: AstJSDocTypeExpression, comment?: string | AstNodeArray) { + const node = createJSDocSimpleTag(AstNode.JSDocEnumTag, tagName ?? createIdentifier(getDefaultTagNameForKind(SyntaxKind.JSDocEnumTag)), comment); + node.data.typeExpression = typeExpression; + return finish(node); + } + + // @api + function updateJSDocEnumTag(node: AstJSDocEnumTag, tagName: AstIdentifier = getDefaultTagName(node), typeExpression: AstJSDocTypeExpression, comment: string | AstNodeArray | undefined) { + return node.data.tagName !== tagName + || node.data.typeExpression !== typeExpression + || node.data.comment !== comment + ? update(createJSDocEnumTag(tagName, typeExpression, comment), node) + : node; + } + + // @api + function createJSDocImportTag(tagName: AstIdentifier | undefined, importClause: AstImportClause | undefined, moduleSpecifier: AstExpression, attributes?: AstImportAttributes, comment?: string | AstNodeArray): AstJSDocImportTag { + const node = AstNode.JSDocImportTag(); + node.data.tagName = tagName ?? createIdentifier("import"); + node.data.comment = comment; + node.data.importClause = importClause; + node.data.moduleSpecifier = moduleSpecifier; + node.data.attributes = attributes; + node.data.comment = comment; + return finish(node); + } + + function updateJSDocImportTag(node: AstJSDocImportTag, tagName: AstIdentifier | undefined, importClause: AstImportClause | undefined, moduleSpecifier: AstExpression, attributes: AstImportAttributes | undefined, comment: string | AstNodeArray | undefined): AstJSDocImportTag { + return node.data.tagName !== tagName + || node.data.comment !== comment + || node.data.importClause !== importClause + || node.data.moduleSpecifier !== moduleSpecifier + || node.data.attributes !== attributes + ? update(createJSDocImportTag(tagName, importClause, moduleSpecifier, attributes, comment), node) + : node; + } + + // @api + function createJSDocText(text: string): AstJSDocText { + const node = AstNode.JSDocText(); + node.data.text = text; + return finish(node); + } + + // @api + function updateJSDocText(node: AstJSDocText, text: string): AstJSDocText { + return node.data.text !== text + ? update(createJSDocText(text), node) + : node; + } + + // @api + function createJSDocComment(comment?: string | AstNodeArray | undefined, tags?: AstNodeArrayLike | undefined) { + const node = AstNode.JSDocNode(); + node.data.comment = comment; + node.data.tags = asNodeArray(tags); + return finish(node); + } + + // @api + function updateJSDocComment(node: AstJSDocNode, comment: string | AstNodeArray | undefined, tags: AstNodeArrayLike | undefined) { + return node.data.comment !== comment + || !sameNodeArray(node.data.tags, tags) + ? update(createJSDocComment(comment, tags), node) + : node; + } + + // + // JSX + // + + // @api + function createJsxElement(openingElement: AstJsxOpeningElement, children: AstNodeArrayLike, closingElement: AstJsxClosingElement) { + const node = AstNode.JsxElement(); + node.data.openingElement = openingElement; + node.data.children = createNodeArray(children); + node.data.closingElement = closingElement; + return finish(node); + } + + // @api + function updateJsxElement(node: AstJsxElement, openingElement: AstJsxOpeningElement, children: AstNodeArrayLike, closingElement: AstJsxClosingElement) { + return node.data.openingElement !== openingElement + || node.data.children !== children + || node.data.closingElement !== closingElement + ? update(createJsxElement(openingElement, children, closingElement), node) + : node; + } + + // @api + function createJsxSelfClosingElement(tagName: AstJsxTagNameExpression, typeArguments: AstNodeArrayLike | undefined, attributes: AstJsxAttributes) { + const node = AstNode.JsxSelfClosingElement(); + node.data.tagName = tagName; + node.data.typeArguments = asNodeArray(typeArguments); + node.data.attributes = attributes; + return finish(node); + } + + // @api + function updateJsxSelfClosingElement(node: AstJsxSelfClosingElement, tagName: AstJsxTagNameExpression, typeArguments: AstNodeArrayLike | undefined, attributes: AstJsxAttributes) { + return node.data.tagName !== tagName + || !sameNodeArray(node.data.typeArguments, typeArguments) + || node.data.attributes !== attributes + ? update(createJsxSelfClosingElement(tagName, typeArguments, attributes), node) + : node; + } + + // @api + function createJsxOpeningElement(tagName: AstJsxTagNameExpression, typeArguments: AstNodeArrayLike | undefined, attributes: AstJsxAttributes) { + const node = AstNode.JsxOpeningElement(); + node.data.tagName = tagName; + node.data.typeArguments = asNodeArray(typeArguments); + node.data.attributes = attributes; + return finish(node); + } + + // @api + function updateJsxOpeningElement(node: AstJsxOpeningElement, tagName: AstJsxTagNameExpression, typeArguments: AstNodeArrayLike | undefined, attributes: AstJsxAttributes) { + return node.data.tagName !== tagName + || !sameNodeArray(node.data.typeArguments, typeArguments) + || node.data.attributes !== attributes + ? update(createJsxOpeningElement(tagName, typeArguments, attributes), node) + : node; + } + + // @api + function createJsxClosingElement(tagName: AstJsxTagNameExpression) { + const node = AstNode.JsxClosingElement(); + node.data.tagName = tagName; + return finish(node); + } + + // @api + function updateJsxClosingElement(node: AstJsxClosingElement, tagName: AstJsxTagNameExpression) { + return node.data.tagName !== tagName + ? update(createJsxClosingElement(tagName), node) + : node; + } + + // @api + function createJsxFragment(openingFragment: AstJsxOpeningFragment, children: AstNodeArrayLike, closingFragment: AstJsxClosingFragment) { + const node = AstNode.JsxFragment(); + node.data.openingFragment = openingFragment; + node.data.children = createNodeArray(children); + node.data.closingFragment = closingFragment; + return finish(node); + } + + // @api + function updateJsxFragment(node: AstJsxFragment, openingFragment: AstJsxOpeningFragment, children: AstNodeArrayLike, closingFragment: AstJsxClosingFragment) { + return node.data.openingFragment !== openingFragment + || node.data.children !== children + || node.data.closingFragment !== closingFragment + ? update(createJsxFragment(openingFragment, children, closingFragment), node) + : node; + } + + // @api + function createJsxText(text: string, containsOnlyTriviaWhiteSpaces?: boolean) { + const node = AstNode.JsxText(); + node.data.text = text; + node.data.containsOnlyTriviaWhiteSpaces = !!containsOnlyTriviaWhiteSpaces; + return finish(node); + } + + // @api + function updateJsxText(node: AstJsxText, text: string, containsOnlyTriviaWhiteSpaces?: boolean) { + return node.data.text !== text + || node.data.containsOnlyTriviaWhiteSpaces !== containsOnlyTriviaWhiteSpaces + ? update(createJsxText(text, containsOnlyTriviaWhiteSpaces), node) + : node; + } + + // @api + function createJsxOpeningFragment() { + const node = AstNode.JsxOpeningFragment(); + return finish(node); + } + + // @api + function createJsxClosingFragment() { + const node = AstNode.JsxClosingFragment(); + return finish(node); + } + + // @api + function createJsxAttribute(name: AstJsxAttributeName, initializer: AstJsxAttributeValue | undefined) { + const node = AstNode.JsxAttribute(); + node.data.name = name; + node.data.initializer = initializer; + return finish(node); + } + + // @api + function updateJsxAttribute(node: AstJsxAttribute, name: AstJsxAttributeName, initializer: AstJsxAttributeValue | undefined) { + return node.data.name !== name + || node.data.initializer !== initializer + ? update(createJsxAttribute(name, initializer), node) + : node; + } + + // @api + function createJsxAttributes(properties: AstNodeArrayLike) { + const node = AstNode.JsxAttributes(); + node.data.properties = createNodeArray(properties); + return finish(node); + } + + // @api + function updateJsxAttributes(node: AstJsxAttributes, properties: AstNodeArrayLike) { + return !sameNodeArray(node.data.properties, properties) + ? update(createJsxAttributes(properties), node) + : node; + } + + // @api + function createJsxSpreadAttribute(expression: AstExpression) { + const node = AstNode.JsxSpreadAttribute(); + node.data.expression = expression; + return finish(node); + } + + // @api + function updateJsxSpreadAttribute(node: AstJsxSpreadAttribute, expression: AstExpression) { + return node.data.expression !== expression + ? update(createJsxSpreadAttribute(expression), node) + : node; + } + + // @api + function createJsxExpression(dotDotDotToken: AstDotDotDotToken | undefined, expression: AstExpression | undefined) { + const node = AstNode.JsxExpression(); + node.data.dotDotDotToken = dotDotDotToken; + node.data.expression = expression; + return finish(node); + } + + // @api + function updateJsxExpression(node: AstJsxExpression, expression: AstExpression | undefined) { + return node.data.expression !== expression + ? update(createJsxExpression(node.data.dotDotDotToken, expression), node) + : node; + } + + // @api + function createJsxNamespacedName(namespace: AstIdentifier, name: AstIdentifier) { + const node = AstNode.JsxNamespacedName(); + node.data.namespace = namespace; + node.data.name = name; + return finish(node); + } + + // @api + function updateJsxNamespacedName(node: AstJsxNamespacedName, namespace: AstIdentifier, name: AstIdentifier) { + return node.data.namespace !== namespace + || node.data.name !== name + ? update(createJsxNamespacedName(namespace, name), node) + : node; + } + + // + // Clauses + // + + // @api + function createCaseClause(expression: AstExpression, statements: AstNodeArrayLike) { + const node = AstNode.CaseClause(); + node.data.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + node.data.statements = createNodeArray(statements); + return finish(node); + } + + // @api + function updateCaseClause(node: AstCaseClause, expression: AstExpression, statements: AstNodeArrayLike) { + return node.data.expression !== expression + || !sameNodeArray(node.data.statements, statements) + ? update(createCaseClause(expression, statements), node) + : node; + } + + // @api + function createDefaultClause(statements: AstNodeArrayLike) { + const node = AstNode.DefaultClause(); + node.data.statements = createNodeArray(statements); + return finish(node); + } + + // @api + function updateDefaultClause(node: AstDefaultClause, statements: AstNodeArrayLike) { + return !sameNodeArray(node.data.statements, statements) + ? update(createDefaultClause(statements), node) + : node; + } + + // @api + function createHeritageClause(token: AstHeritageClause["data"]["token"], types: AstNodeArrayLike) { + const node = AstNode.HeritageClause(); + node.data.token = token; + node.data.types = createNodeArray(types); + return finish(node); + } + + // @api + function updateHeritageClause(node: AstHeritageClause, types: AstNodeArrayLike) { + return !sameNodeArray(node.data.types, types) + ? update(createHeritageClause(node.data.token, types), node) + : node; + } + + // @api + function createCatchClause(variableDeclaration: string | AstBindingName | AstVariableDeclaration | undefined, block: AstBlock) { + const node = AstNode.CatchClause(); + node.data.variableDeclaration = asVariableDeclaration(variableDeclaration); + node.data.block = block; + return finish(node); + } + + // @api + function updateCatchClause(node: AstCatchClause, variableDeclaration: AstVariableDeclaration | undefined, block: AstBlock) { + return node.data.variableDeclaration !== variableDeclaration + || node.data.block !== block + ? update(createCatchClause(variableDeclaration, block), node) + : node; + } + + // + // Property assignments + // + + // @api + function createPropertyAssignment(name: string | AstPropertyName, initializer: AstExpression) { + const node = AstNode.PropertyAssignment(); + node.data.name = asName(name); + node.data.initializer = parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer); + return finish(node); + } + + // @api + function updatePropertyAssignment(node: AstPropertyAssignment, name: AstPropertyName, initializer: AstExpression) { + return node.data.name !== name + || node.data.initializer !== initializer + ? finishUpdatePropertyAssignment(createPropertyAssignment(name, initializer), node) + : node; + } + + function finishUpdatePropertyAssignment(updated: AstPropertyAssignment, original: AstPropertyAssignment) { + // copy children used only for error reporting + if (updated !== original) { + // copy children used only for error reporting + updated.data.modifiers = original.data.modifiers; + updated.data.questionToken = original.data.questionToken; + updated.data.exclamationToken = original.data.exclamationToken; + } + return update(updated, original); + } + + // @api + function createShorthandPropertyAssignment(name: string | AstIdentifier, objectAssignmentInitializer?: AstExpression) { + const node = AstNode.ShorthandPropertyAssignment(); + node.data.name = asName(name); + node.data.objectAssignmentInitializer = objectAssignmentInitializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(objectAssignmentInitializer); + return finish(node); + } + + // @api + function updateShorthandPropertyAssignment(node: AstShorthandPropertyAssignment, name: AstIdentifier, objectAssignmentInitializer: AstExpression | undefined) { + return node.data.name !== name + || node.data.objectAssignmentInitializer !== objectAssignmentInitializer + ? finishUpdateShorthandPropertyAssignment(createShorthandPropertyAssignment(name, objectAssignmentInitializer), node) + : node; + } + + function finishUpdateShorthandPropertyAssignment(updated: AstShorthandPropertyAssignment, original: AstShorthandPropertyAssignment) { + if (updated !== original) { + // copy children used only for error reporting + updated.data.modifiers = original.data.modifiers; + updated.data.questionToken = original.data.questionToken; + updated.data.exclamationToken = original.data.exclamationToken; + updated.data.equalsToken = original.data.equalsToken; + } + return update(updated, original); + } + + // @api + function createSpreadAssignment(expression: AstExpression) { + const node = AstNode.SpreadAssignment(); + node.data.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + return finish(node); + } + + // @api + function updateSpreadAssignment(node: AstSpreadAssignment, expression: AstExpression) { + return node.data.expression !== expression + ? update(createSpreadAssignment(expression), node) + : node; + } + + // + // Enum + // + + // @api + function createEnumMember(name: string | AstPropertyName, initializer?: AstExpression) { + const node = AstNode.EnumMember(); + node.data.name = asName(name); + node.data.initializer = initializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer); + return finish(node); + } + + // @api + function updateEnumMember(node: AstEnumMember, name: AstPropertyName, initializer: AstExpression | undefined) { + return node.data.name !== name + || node.data.initializer !== initializer + ? update(createEnumMember(name, initializer), node) + : node; + } + + // + // Top-level nodes + // + + // @api + function createSourceFile( + statements: AstNodeArrayLike, + endOfFileToken: AstEndOfFileToken, + flags: NodeFlags, + ) { + const node = AstNode.SourceFile(); + node.data.statements = createNodeArray(statements); + node.data.endOfFileToken = endOfFileToken; + node.flags |= flags; + return finish(node); + } + + function createRedirectedSourceFile(redirectInfo: RedirectInfo) { + Debug.assert(redirectInfo.redirectTarget instanceof SourceFile); + const source = redirectInfo.redirectTarget.ast; + const node = source.shadow() as AstSourceFile; + node.data.redirectInfo = redirectInfo; + node.flags &= ~NodeFlags.Synthesized; + return finish(node); + } + + function cloneSourceFileWithChanges( + source: AstSourceFile, + statements: AstNodeArrayLike, + isDeclarationFile: boolean, + referencedFiles: readonly FileReference[], + typeReferences: readonly FileReference[], + hasNoDefaultLib: boolean, + libReferences: readonly FileReference[], + ) { + const node = cloneNodeWorker(source); + node.data.statements = createNodeArray(statements); + node.data.isDeclarationFile = isDeclarationFile; + node.data.referencedFiles = referencedFiles; + node.data.typeReferenceDirectives = typeReferences; + node.data.hasNoDefaultLib = hasNoDefaultLib; + node.data.libReferenceDirectives = libReferences; + node.extra.transformFlags = undefined; + return finish(node); + } + + // @api + function updateSourceFile( + node: AstSourceFile, + statements: AstNodeArrayLike, + isDeclarationFile = node.data.isDeclarationFile, + referencedFiles = node.data.referencedFiles, + typeReferenceDirectives = node.data.typeReferenceDirectives, + hasNoDefaultLib = node.data.hasNoDefaultLib, + libReferenceDirectives = node.data.libReferenceDirectives, + ) { + return !sameNodeArray(node.data.statements, statements) + || node.data.isDeclarationFile !== isDeclarationFile + || node.data.referencedFiles !== referencedFiles + || node.data.typeReferenceDirectives !== typeReferenceDirectives + || node.data.hasNoDefaultLib !== hasNoDefaultLib + || node.data.libReferenceDirectives !== libReferenceDirectives + ? update(cloneSourceFileWithChanges(node, statements, isDeclarationFile, referencedFiles, typeReferenceDirectives, hasNoDefaultLib, libReferenceDirectives), node) + : node; + } + + // @api + function createBundle(sourceFiles: readonly SourceFile[]) { + const node = AstNode.Bundle(); + node.data.sourceFiles = sourceFiles; + return finish(node); + } + + // @api + function updateBundle(node: AstBundle, sourceFiles: readonly SourceFile[]) { + return node.data.sourceFiles !== sourceFiles + ? update(createBundle(sourceFiles), node) + : node; + } + + // + // Synthetic Nodes (used by checker) + // + + // @api + function createSyntheticExpression(type: Type, isSpread = false, tupleNameSource?: AstParameterDeclaration | AstNamedTupleMember) { + const node = AstNode.SyntheticExpression(); + node.data.type = type; + node.data.isSpread = isSpread; + node.data.tupleNameSource = tupleNameSource; + return finish(node); + } + + // @api + function createSyntaxList(children: readonly Node[]) { + const node = AstNode.SyntaxList(); + node.data._children = children; + return finish(node); + } + + // + // Transformation nodes + // + + /** + * Creates a synthetic statement to act as a placeholder for a not-emitted statement in + * order to preserve comments. + * + * @param original The original statement. + */ + // @api + function createNotEmittedStatement(original: AstNode) { + const node = AstNode.NotEmittedStatement(); + node.original = original; + setTextRange(node, original); + return finish(node); + } + + /** + * Creates a synthetic expression to act as a placeholder for a not-emitted expression in + * order to preserve comments or sourcemap positions. + * + * @param expression The inner expression to emit. + * @param original The original outer expression. + */ + // @api + function createPartiallyEmittedExpression(expression: AstExpression, original?: AstNode) { + const node = AstNode.PartiallyEmittedExpression(); + node.data.expression = expression; + node.original = original; + // node.transformFlags |= propagateChildFlags(node.expression) | + // TransformFlags.ContainsTypeScript; + setTextRange(node, original); + return finish(node); + } + + // @api + function updatePartiallyEmittedExpression(node: AstPartiallyEmittedExpression, expression: AstExpression) { + return node.data.expression !== expression + ? update(createPartiallyEmittedExpression(expression, node.original), node) + : node; + } + + // @api + function createNotEmittedTypeElement() { + return finish(AstNode.NotEmittedTypeElement()); + } + + function flattenCommaElements(node: AstExpression): AstExpression | readonly AstExpression[] { + if (nodeIsSynthesized(node) && !isParseTreeNode(node) && !node.original && !node.emitNode && !node.id) { + if (isAstCommaListExpression(node)) { + return node.data.elements.items; + } + if (isAstBinaryExpression(node) && isAstCommaToken(node.data.operatorToken)) { + return [node.data.left, node.data.right]; + } + } + return node; + } + + // @api + function createCommaListExpression(elements: AstNodeArrayLike) { + const node = AstNode.CommaListExpression(); + elements = asNodeArray(elements); + const result = sameFlatMap(elements.items, flattenCommaElements); + if (result !== elements.items) { + elements = createNodeArray(result); + } + node.data.elements = createNodeArray(elements); + return finish(node); + } + + // @api + function updateCommaListExpression(node: AstCommaListExpression, elements: AstNodeArrayLike) { + return !sameNodeArray(node.data.elements, elements) + ? update(createCommaListExpression(elements), node) + : node; + } + + // @api + function createSyntheticReferenceExpression(expression: AstExpression, thisArg: AstExpression) { + const node = AstNode.SyntheticReferenceExpression(); + node.data.expression = expression; + node.data.thisArg = thisArg; + return finish(node); + } + + // @api + function updateSyntheticReferenceExpression(node: AstSyntheticReferenceExpression, expression: AstExpression, thisArg: AstExpression) { + return node.data.expression !== expression + || node.data.thisArg !== thisArg + ? update(createSyntheticReferenceExpression(expression, thisArg), node) + : node; + } + + function cloneNodeWorker(node: T): T { + // We don't use "clone" from core.ts here, as we need to preserve the prototype chain of + // the original node. We also need to exclude specific properties and only include own- + // properties (to skip members already defined on the shared prototype). + + const clone = node.clone(); + clone.flags &= ~NodeFlags.Synthesized; + clone.transformFlags = node.transformFlags; + clone.emitNode = undefined; + setOriginal(clone, node); + + if (isAstIdentifier(node)) { + Debug.assert(isAstIdentifier(clone)); + + const typeArguments = getIdentifierTypeArguments(node); + if (typeArguments) setIdentifierTypeArguments(clone, typeArguments); + + const autoGenerate = getIdentifierAutoGenerate(node); + if (autoGenerate) setIdentifierAutoGenerate(clone, { ...autoGenerate }); + } + else if (isAstPrivateIdentifier(node)) { + Debug.assert(isAstPrivateIdentifier(clone)); + + const autoGenerate = getIdentifierAutoGenerate(node); + if (autoGenerate) setIdentifierAutoGenerate(clone, { ...autoGenerate }); + } + + return clone as T; + } + + function cloneNode(node: T): T { + return finish(cloneNodeWorker(node)); + } + + function updateOuterExpression(outerExpression: AstOuterExpression, expression: AstExpression) { + switch (outerExpression.kind) { + case SyntaxKind.ParenthesizedExpression: + return updateParenthesizedExpression(outerExpression, expression); + case SyntaxKind.TypeAssertionExpression: + return updateTypeAssertion(outerExpression, outerExpression.data.type, expression); + case SyntaxKind.AsExpression: + return updateAsExpression(outerExpression, expression, outerExpression.data.type); + case SyntaxKind.SatisfiesExpression: + return updateSatisfiesExpression(outerExpression, expression, outerExpression.data.type); + case SyntaxKind.NonNullExpression: + return updateNonNullExpression(outerExpression, expression); + case SyntaxKind.ExpressionWithTypeArguments: + return updateExpressionWithTypeArguments(outerExpression, expression, outerExpression.data.typeArguments); + case SyntaxKind.PartiallyEmittedExpression: + return updatePartiallyEmittedExpression(outerExpression, expression); + } + } + + /** + * Determines whether a node is a parenthesized expression that can be ignored when recreating outer expressions. + * + * A parenthesized expression can be ignored when all of the following are true: + * + * - It's `pos` and `end` are not -1 + * - It does not have a custom source map range + * - It does not have a custom comment range + * - It does not have synthetic leading or trailing comments + * + * If an outermost parenthesized expression is ignored, but the containing expression requires a parentheses around + * the expression to maintain precedence, a new parenthesized expression should be created automatically when + * the containing expression is created/updated. + */ + function isIgnorableParen(node: AstExpression) { + return isAstParenthesizedExpression(node) + && nodeIsSynthesized(node) + && nodeIsSynthesized(getSourceMapRange(node)) + && nodeIsSynthesized(getCommentRange(node)) + && !some(getSyntheticLeadingComments(node)) + && !some(getSyntheticTrailingComments(node)); + } + + function restoreOuterExpressions(outerExpression: AstExpression | undefined, innerExpression: AstExpression, kinds = OuterExpressionKinds.All): AstExpression { + if (outerExpression && isAstOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) { + return updateOuterExpression( + outerExpression, + restoreOuterExpressions(outerExpression.data.expression, innerExpression), + ); + } + return innerExpression; + } + + function asNodeArray(array: AstNodeArrayLike): AstNodeArray; + function asNodeArray(array: AstNodeArrayLike | undefined): AstNodeArray | undefined; + function asNodeArray(array: AstNodeArrayLike | undefined): AstNodeArray | undefined { + return array ? createNodeArray(array) : undefined; + } + + function asName(name: string | T): T | AstIdentifier { + return typeof name === "string" ? createIdentifier(name) : + name; + } + + function asExpression(value: string | number | boolean | T): T | AstStringLiteral | AstNumericLiteral | AstBooleanLiteral { + return typeof value === "string" ? createStringLiteral(value) : + typeof value === "number" ? createNumericLiteral(value) : + typeof value === "boolean" ? value ? createTrue() : createFalse() : + value; + } + + function asInitializer(node: AstExpression | undefined) { + return node && parenthesizerRules().parenthesizeExpressionForDisallowedComma(node); + } + + function asToken(value: TKind | AstToken): AstToken { + return typeof value === "number" ? createToken(value) : value; + } + + function asEmbeddedStatement(statement: T): T | AstEmptyStatement; + function asEmbeddedStatement(statement: T | undefined): T | AstEmptyStatement | undefined; + function asEmbeddedStatement(statement: T | undefined): T | AstEmptyStatement | undefined { + return statement && isAstNotEmittedStatement(statement) ? setTextRange(setOriginal(createEmptyStatement(), statement), statement) : statement; + } + + function asVariableDeclaration(variableDeclaration: string | AstBindingName | AstVariableDeclaration | undefined) { + if (typeof variableDeclaration === "string" || variableDeclaration && !isAstVariableDeclaration(variableDeclaration)) { + return createVariableDeclaration( + variableDeclaration, + /*exclamationToken*/ undefined, + /*type*/ undefined, + /*initializer*/ undefined, + ); + } + return variableDeclaration; + } + + function update(updated: T, original: T): T { + if (updated !== original) { + setOriginal(updated, original); + setTextRange(updated, original); + } + return updated; + } + + function finish(node: T): T { + if (flags & NodeFactoryFlags.Synthesized) { + node.flags |= NodeFlags.Synthesized; + } + else { + node.flags &= ~NodeFlags.Synthesized; + } + // void node.transformFlags; // precompute transform flags + onFinishNode?.(node); + return node; + } +} + +function getDefaultTagNameForKind(kind: AstJSDocTag["kind"]): string { + switch (kind) { + case SyntaxKind.JSDocTypeTag: + return "type"; + case SyntaxKind.JSDocReturnTag: + return "returns"; + case SyntaxKind.JSDocThisTag: + return "this"; + case SyntaxKind.JSDocEnumTag: + return "enum"; + case SyntaxKind.JSDocAuthorTag: + return "author"; + case SyntaxKind.JSDocClassTag: + return "class"; + case SyntaxKind.JSDocPublicTag: + return "public"; + case SyntaxKind.JSDocPrivateTag: + return "private"; + case SyntaxKind.JSDocProtectedTag: + return "protected"; + case SyntaxKind.JSDocReadonlyTag: + return "readonly"; + case SyntaxKind.JSDocOverrideTag: + return "override"; + case SyntaxKind.JSDocTemplateTag: + return "template"; + case SyntaxKind.JSDocTypedefTag: + return "typedef"; + case SyntaxKind.JSDocParameterTag: + return "param"; + case SyntaxKind.JSDocPropertyTag: + return "prop"; + case SyntaxKind.JSDocCallbackTag: + return "callback"; + case SyntaxKind.JSDocOverloadTag: + return "overload"; + case SyntaxKind.JSDocAugmentsTag: + return "augments"; + case SyntaxKind.JSDocImplementsTag: + return "implements"; + case SyntaxKind.JSDocImportTag: + return "import"; + default: + return Debug.fail(`Unsupported kind: ${Debug.formatSyntaxKind(kind)}`); + } +} + +let rawTextScanner: Scanner | undefined; +const invalidValueSentinel: object = {}; + +function getCookedText(kind: AstTemplateLiteralToken["kind"], rawText: string) { + if (!rawTextScanner) { + rawTextScanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false, LanguageVariant.Standard); + } + switch (kind) { + case SyntaxKind.NoSubstitutionTemplateLiteral: + rawTextScanner.setText("`" + rawText + "`"); + break; + case SyntaxKind.TemplateHead: + rawTextScanner.setText("`" + rawText + "${"); + break; + case SyntaxKind.TemplateMiddle: + rawTextScanner.setText("}" + rawText + "${"); + break; + case SyntaxKind.TemplateTail: + rawTextScanner.setText("}" + rawText + "`"); + break; + } + + let token = rawTextScanner.scan(); + if (token === SyntaxKind.CloseBraceToken) { + token = rawTextScanner.reScanTemplateToken(/*isTaggedTemplate*/ false); + } + + if (rawTextScanner.isUnterminated()) { + rawTextScanner.setText(undefined); + return invalidValueSentinel; + } + + let tokenValue: string | undefined; + switch (token) { + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.TemplateHead: + case SyntaxKind.TemplateMiddle: + case SyntaxKind.TemplateTail: + tokenValue = rawTextScanner.getTokenValue(); + break; + } + + if (tokenValue === undefined || rawTextScanner.scan() !== SyntaxKind.EndOfFileToken) { + rawTextScanner.setText(undefined); + return invalidValueSentinel; + } + + rawTextScanner.setText(undefined); + return tokenValue; +} + +function setOriginalNode(node: T, original: AstNode | undefined): T { + if (node.original !== original) { + node.original = original; + if (original) { + const emitNode = original.emitNode; + if (emitNode) node.emitNode = mergeEmitNode(emitNode, node.emitNode); + } + } + return node; +} + +function arrayItems(array: AstNodeArrayLike) { + return array instanceof AstNodeArray ? array.items : array; +} + +function sameNodeArray(left: (readonly T[]) | AstNodeArray | undefined, right: (readonly T[]) | AstNodeArray | undefined) { + if (left === right) return true; + if (left === undefined || right === undefined) return false; + if (left instanceof AstNodeArray) return left.items === right; + if (right instanceof AstNodeArray) return right.items === left; + return false; +} + +// copied from utilities.ts +function getJSDocTypeAliasName(fullName: AstJSDocNamespaceBody | undefined) { + if (fullName) { + let rightNode = fullName; + while (true) { + if (isAstIdentifier(rightNode) || !rightNode.data.body) { + return isAstIdentifier(rightNode) ? rightNode : rightNode.data.name; + } + rightNode = rightNode.data.body; + } + } +} diff --git a/src/compiler/factory/astNodeTests.ts b/src/compiler/factory/astNodeTests.ts new file mode 100644 index 0000000000000..f28cf8d701a23 --- /dev/null +++ b/src/compiler/factory/astNodeTests.ts @@ -0,0 +1,1475 @@ +import { + AbstractKeyword, + AccessorKeyword, + ArrayBindingPattern, + ArrayLiteralExpression, + ArrayTypeNode, + ArrowFunction, + AsExpression, + AssertClause, + AssertEntry, + AssertsKeyword, + AstCallChain, + AstElementAccessChain, + AsteriskToken, + AstNode, + AstNonNullChain, + AstOptionalChainRoot, + AstPropertyAccessChain, + AstPropertyName, + AsyncKeyword, + AwaitExpression, + AwaitKeyword, + BigIntLiteral, + BinaryExpression, + BindingElement, + Block, + BreakStatement, + Bundle, + CallExpression, + CallSignatureDeclaration, + CaseBlock, + CaseClause, + CaseKeyword, + CatchClause, + ClassDeclaration, + ClassExpression, + ClassStaticBlockDeclaration, + ColonToken, + CommaListExpression, + ComputedPropertyName, + ConditionalExpression, + ConditionalTypeNode, + ConstructorDeclaration, + ConstructorTypeNode, + ConstructSignatureDeclaration, + ContinueStatement, + DebuggerStatement, + Decorator, + DefaultClause, + DefaultKeyword, + DeleteExpression, + DoStatement, + DotDotDotToken, + ElementAccessExpression, + EmptyStatement, + EnumDeclaration, + EnumMember, + EqualsGreaterThanToken, + ExclamationToken, + ExportAssignment, + ExportDeclaration, + ExportKeyword, + ExportSpecifier, + ExpressionStatement, + ExpressionWithTypeArguments, + ExternalModuleReference, + ForInStatement, + ForOfStatement, + ForStatement, + FunctionDeclaration, + FunctionExpression, + FunctionTypeNode, + GetAccessorDeclaration, + HeritageClause, + Identifier, + IfStatement, + ImportAttribute, + ImportAttributes, + ImportClause, + ImportDeclaration, + ImportEqualsDeclaration, + ImportExpression, + ImportSpecifier, + ImportTypeAssertionContainer, + ImportTypeNode, + IndexedAccessTypeNode, + IndexSignatureDeclaration, + InferTypeNode, + InterfaceDeclaration, + IntersectionTypeNode, + JSDocAllType, + JSDocAugmentsTag, + JSDocAuthorTag, + JSDocCallbackTag, + JSDocClassTag, + JSDocDeprecatedTag, + JSDocEnumTag, + JSDocFunctionType, + JSDocImplementsTag, + JSDocImportTag, + JSDocLink, + JSDocLinkCode, + JSDocLinkPlain, + JSDocMemberName, + JSDocNamepathType, + JSDocNameReference, + JSDocNode, + JSDocNonNullableType, + JSDocNullableType, + JSDocOptionalType, + JSDocOverloadTag, + JSDocOverrideTag, + JSDocParameterTag, + JSDocPrivateTag, + JSDocPropertyTag, + JSDocProtectedTag, + JSDocPublicTag, + JSDocReadonlyTag, + JSDocReturnTag, + JSDocSatisfiesTag, + JSDocSeeTag, + JSDocSignature, + JSDocTemplateTag, + JSDocThisTag, + JSDocThrowsTag, + JSDocTypedefTag, + JSDocTypeExpression, + JSDocTypeLiteral, + JSDocTypeTag, + JSDocUnknownTag, + JSDocUnknownType, + JSDocVariadicType, + JsxAttribute, + JsxAttributes, + JsxClosingElement, + JsxClosingFragment, + JsxElement, + JsxExpression, + JsxFragment, + JsxNamespacedName, + JsxOpeningElement, + JsxOpeningFragment, + JsxSelfClosingElement, + JsxSpreadAttribute, + JsxText, + LabeledStatement, + LiteralTypeNode, + MappedTypeNode, + MetaProperty, + MethodDeclaration, + MethodSignature, + MinusToken, + MissingDeclaration, + ModuleBlock, + ModuleDeclaration, + ModuleExportName, + NamedExports, + NamedImports, + NamedTupleMember, + NamespaceExport, + NamespaceExportDeclaration, + NamespaceImport, + NewExpression, + Node, + NonNullExpression, + NoSubstitutionTemplateLiteral, + NotEmittedStatement, + NumericLiteral, + ObjectBindingPattern, + ObjectLiteralExpression, + OmittedExpression, + OptionalTypeNode, + OverrideKeyword, + ParameterDeclaration, + ParenthesizedExpression, + ParenthesizedTypeNode, + PartiallyEmittedExpression, + PlusToken, + PostfixUnaryExpression, + PrefixUnaryExpression, + PrivateIdentifier, + PropertyAccessExpression, + PropertyAssignment, + PropertyDeclaration, + PropertySignature, + QualifiedName, + QuestionDotToken, + QuestionToken, + ReadonlyKeyword, + RegularExpressionLiteral, + RestTypeNode, + ReturnStatement, + SatisfiesExpression, + SemicolonClassElement, + SetAccessorDeclaration, + ShorthandPropertyAssignment, + SourceFile, + SpreadAssignment, + SpreadElement, + StaticKeyword, + StringLiteral, + SuperExpression, + SwitchStatement, + SyntaxList, + SyntheticExpression, + SyntheticReferenceExpression, + TaggedTemplateExpression, + TemplateExpression, + TemplateHead, + TemplateLiteralTypeNode, + TemplateLiteralTypeSpan, + TemplateMiddle, + TemplateSpan, + TemplateTail, + ThisTypeNode, + ThrowStatement, + Token, + TryStatement, + TupleTypeNode, + TypeAliasDeclaration, + TypeAssertion, + TypeLiteralNode, + TypeOfExpression, + TypeOperatorNode, + TypeParameterDeclaration, + TypePredicateNode, + TypeQueryNode, + TypeReferenceNode, + UnionTypeNode, + VariableDeclaration, + VariableDeclarationList, + VariableStatement, + VoidExpression, + WhileStatement, + WithStatement, + YieldExpression, +} from "../_namespaces/ts.ast.js"; +import { + NodeFlags, + SyntaxKind, +} from "../_namespaces/ts.js"; + +// Literals + +/** @internal */ +export function isAstNumericLiteral(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.NumericLiteral; +} + +/** @internal */ +export function isAstBigIntLiteral(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.BigIntLiteral; +} + +/** @internal */ +export function isAstStringLiteral(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.StringLiteral; +} + +/** @internal */ +export function isAstJsxText(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxText; +} + +/** @internal */ +export function isAstRegularExpressionLiteral(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.RegularExpressionLiteral; +} + +/** @internal */ +export function isAstNoSubstitutionTemplateLiteral(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.NoSubstitutionTemplateLiteral; +} + +// Pseudo-literals + +/** @internal */ +export function isAstTemplateHead(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TemplateHead; +} + +/** @internal */ +export function isAstTemplateMiddle(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TemplateMiddle; +} + +/** @internal */ +export function isAstTemplateTail(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TemplateTail; +} + +// Punctuation + +/** @internal */ +export function isAstDotDotDotToken(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.DotDotDotToken; +} + +/** @internal */ +export function isAstCommaToken(node: AstNode): node is AstNode> { + return node.kind === SyntaxKind.CommaToken; +} + +/** @internal */ +export function isAstPlusToken(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.PlusToken; +} + +/** @internal */ +export function isAstMinusToken(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.MinusToken; +} + +/** @internal */ +export function isAstAsteriskToken(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.AsteriskToken; +} + +/** @internal */ +export function isAstExclamationToken(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ExclamationToken; +} + +/** @internal */ +export function isAstQuestionToken(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.QuestionToken; +} + +/** @internal */ +export function isAstColonToken(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ColonToken; +} + +/** @internal */ +export function isAstQuestionDotToken(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.QuestionDotToken; +} + +/** @internal */ +export function isAstEqualsGreaterThanToken(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.EqualsGreaterThanToken; +} + +// Identifiers + +/** @internal */ +export function isAstIdentifier(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.Identifier; +} + +/** @internal */ +export function isAstPrivateIdentifier(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.PrivateIdentifier; +} + +// Reserved Words + +/** @internal */ +export function isAstExportModifier(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ExportKeyword; +} + +/** @internal */ +export function isAstDefaultModifier(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.DefaultKeyword; +} + +/** @internal */ +export function isAstAsyncModifier(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.AsyncKeyword; +} + +/** @internal */ +export function isAstAssertsKeyword(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.AssertsKeyword; +} + +/** @internal */ +export function isAstAwaitKeyword(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.AwaitKeyword; +} + +/** @internal */ +export function isAstReadonlyKeyword(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ReadonlyKeyword; +} + +/** @internal */ +export function isAstStaticModifier(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.StaticKeyword; +} + +/** @internal */ +export function isAstAbstractModifier(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.AbstractKeyword; +} + +/** @internal */ +export function isAstOverrideModifier(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.OverrideKeyword; +} + +/** @internal */ +export function isAstAccessorModifier(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.AccessorKeyword; +} + +/** @internal */ +export function isAstSuperKeyword(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.SuperKeyword; +} + +/** @internal */ +export function isAstImportKeyword(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ImportKeyword; +} + +/** @internal */ +export function isAstCaseKeyword(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.CaseKeyword; +} + +// Names + +/** @internal */ +export function isAstQualifiedName(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.QualifiedName; +} + +/** @internal */ +export function isAstComputedPropertyName(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ComputedPropertyName; +} + +// Signature elements + +/** @internal */ +export function isAstTypeParameterDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TypeParameter; +} + + +/** @internal */// TODO(rbuckton): Rename to 'isParameterDeclaration' +export function isAstParameter(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.Parameter; +} + +/** @internal */ +export function isAstDecorator(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.Decorator; +} + +// TypeMember + +/** @internal */ +export function isAstPropertySignature(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.PropertySignature; +} + +/** @internal */ +export function isAstPropertyDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.PropertyDeclaration; +} + +/** @internal */ +export function isAstMethodSignature(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.MethodSignature; +} + +/** @internal */ +export function isAstMethodDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.MethodDeclaration; +} + +/** @internal */ +export function isAstClassStaticBlockDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ClassStaticBlockDeclaration; +} + +/** @internal */ +export function isAstConstructorDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.Constructor; +} + +/** @internal */ +export function isAstGetAccessorDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.GetAccessor; +} + +/** @internal */ +export function isAstSetAccessorDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.SetAccessor; +} + +/** @internal */ +export function isAstCallSignatureDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.CallSignature; +} + +/** @internal */ +export function isAstConstructSignatureDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ConstructSignature; +} + +/** @internal */ +export function isAstIndexSignatureDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.IndexSignature; +} + +// Type + +/** @internal */ +export function isAstTypePredicateNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TypePredicate; +} + +/** @internal */ +export function isAstTypeReferenceNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TypeReference; +} + +/** @internal */ +export function isAstFunctionTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.FunctionType; +} + +/** @internal */ +export function isAstConstructorTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ConstructorType; +} + +/** @internal */ +export function isAstTypeQueryNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TypeQuery; +} + +/** @internal */ +export function isAstTypeLiteralNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TypeLiteral; +} + +/** @internal */ +export function isAstArrayTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ArrayType; +} + +/** @internal */ +export function isAstTupleTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TupleType; +} + +/** @internal */ +export function isAstNamedTupleMember(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.NamedTupleMember; +} + +/** @internal */ +export function isAstOptionalTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.OptionalType; +} + +/** @internal */ +export function isAstRestTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.RestType; +} + +/** @internal */ +export function isAstUnionTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.UnionType; +} + +/** @internal */ +export function isAstIntersectionTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.IntersectionType; +} + +/** @internal */ +export function isAstConditionalTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ConditionalType; +} + +/** @internal */ +export function isAstInferTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.InferType; +} + +/** @internal */ +export function isAstParenthesizedTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ParenthesizedType; +} + +/** @internal */ +export function isAstThisTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ThisType; +} + +/** @internal */ +export function isAstTypeOperatorNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TypeOperator; +} + +/** @internal */ +export function isAstIndexedAccessTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.IndexedAccessType; +} + +/** @internal */ +export function isAstMappedTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.MappedType; +} + +/** @internal */ +export function isAstLiteralTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.LiteralType; +} + +/** @internal */ +export function isAstImportTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ImportType; +} + +/** @internal */ +export function isAstTemplateLiteralTypeSpan(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TemplateLiteralTypeSpan; +} + +/** @internal */ +export function isAstTemplateLiteralTypeNode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TemplateLiteralType; +} + +// Binding patterns + +/** @internal */ +export function isAstObjectBindingPattern(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ObjectBindingPattern; +} + +/** @internal */ +export function isAstArrayBindingPattern(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ArrayBindingPattern; +} + +/** @internal */ +export function isAstBindingElement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.BindingElement; +} + +// Expression + +/** @internal */ +export function isAstArrayLiteralExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ArrayLiteralExpression; +} + +/** @internal */ +export function isAstObjectLiteralExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ObjectLiteralExpression; +} + +/** @internal */ +export function isAstPropertyAccessExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.PropertyAccessExpression; +} + +/** @internal */ +export function isAstElementAccessExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ElementAccessExpression; +} + +/** @internal */ +export function isAstCallExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.CallExpression; +} + +/** @internal */ +export function isAstNewExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.NewExpression; +} + +/** @internal */ +export function isAstTaggedTemplateExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TaggedTemplateExpression; +} + +/** @internal */ +export function isAstTypeAssertionExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TypeAssertionExpression; +} + +/** @internal */ +export function isAstParenthesizedExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ParenthesizedExpression; +} + +/** @internal */ +export function isAstFunctionExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.FunctionExpression; +} + +/** @internal */ +export function isAstArrowFunction(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ArrowFunction; +} + +/** @internal */ +export function isAstDeleteExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.DeleteExpression; +} + +/** @internal */ +export function isAstTypeOfExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TypeOfExpression; +} + +/** @internal */ +export function isAstVoidExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.VoidExpression; +} + +/** @internal */ +export function isAstAwaitExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.AwaitExpression; +} + +/** @internal */ +export function isAstPrefixUnaryExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.PrefixUnaryExpression; +} + +/** @internal */ +export function isAstPostfixUnaryExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.PostfixUnaryExpression; +} + +/** @internal */ +export function isAstBinaryExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.BinaryExpression; +} + +/** @internal */ +export function isAstConditionalExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ConditionalExpression; +} + +/** @internal */ +export function isAstTemplateExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TemplateExpression; +} + +/** @internal */ +export function isAstYieldExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.YieldExpression; +} + +/** @internal */ +export function isAstSpreadElement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.SpreadElement; +} + +/** @internal */ +export function isAstClassExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ClassExpression; +} + +/** @internal */ +export function isAstOmittedExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.OmittedExpression; +} + +/** @internal */ +export function isAstExpressionWithTypeArguments(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ExpressionWithTypeArguments; +} + +/** @internal */ +export function isAstAsExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.AsExpression; +} + +/** @internal */ +export function isAstSatisfiesExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.SatisfiesExpression; +} + +/** @internal */ +export function isAstNonNullExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.NonNullExpression; +} + +/** @internal */ +export function isAstMetaProperty(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.MetaProperty; +} + +/** @internal */ +export function isAstSyntheticExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.SyntheticExpression; +} + +/** @internal */ +export function isAstPartiallyEmittedExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.PartiallyEmittedExpression; +} + +/** @internal */ +export function isAstCommaListExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.CommaListExpression; +} + +// Misc + +/** @internal */ +export function isAstTemplateSpan(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TemplateSpan; +} + +/** @internal */ +export function isAstSemicolonClassElement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.SemicolonClassElement; +} + +// Elements + +/** @internal */ +export function isAstBlock(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.Block; +} + +/** @internal */ +export function isAstVariableStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.VariableStatement; +} + +/** @internal */ +export function isAstEmptyStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.EmptyStatement; +} + +/** @internal */ +export function isAstExpressionStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ExpressionStatement; +} + +/** @internal */ +export function isAstIfStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.IfStatement; +} + +/** @internal */ +export function isAstDoStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.DoStatement; +} + +/** @internal */ +export function isAstWhileStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.WhileStatement; +} + +/** @internal */ +export function isAstForStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ForStatement; +} + +/** @internal */ +export function isAstForInStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ForInStatement; +} + +/** @internal */ +export function isAstForOfStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ForOfStatement; +} + +/** @internal */ +export function isAstContinueStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ContinueStatement; +} + +/** @internal */ +export function isAstBreakStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.BreakStatement; +} + +/** @internal */ +export function isAstReturnStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ReturnStatement; +} + +/** @internal */ +export function isAstWithStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.WithStatement; +} + +/** @internal */ +export function isAstSwitchStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.SwitchStatement; +} + +/** @internal */ +export function isAstLabeledStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.LabeledStatement; +} + +/** @internal */ +export function isAstThrowStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ThrowStatement; +} + +/** @internal */ +export function isAstTryStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TryStatement; +} + +/** @internal */ +export function isAstDebuggerStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.DebuggerStatement; +} + +/** @internal */ +export function isAstVariableDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.VariableDeclaration; +} + +/** @internal */ +export function isAstVariableDeclarationList(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.VariableDeclarationList; +} + +/** @internal */ +export function isAstFunctionDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.FunctionDeclaration; +} + +/** @internal */ +export function isAstClassDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ClassDeclaration; +} + +/** @internal */ +export function isAstInterfaceDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.InterfaceDeclaration; +} + +/** @internal */ +export function isAstTypeAliasDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.TypeAliasDeclaration; +} + +/** @internal */ +export function isAstEnumDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.EnumDeclaration; +} + +/** @internal */ +export function isAstModuleDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ModuleDeclaration; +} + +/** @internal */ +export function isAstModuleBlock(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ModuleBlock; +} + +/** @internal */ +export function isAstCaseBlock(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.CaseBlock; +} + +/** @internal */ +export function isAstNamespaceExportDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.NamespaceExportDeclaration; +} + +/** @internal */ +export function isAstImportEqualsDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ImportEqualsDeclaration; +} + +/** @internal */ +export function isAstImportDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ImportDeclaration; +} + +/** @internal */ +export function isAstImportClause(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ImportClause; +} + +/** @internal */ +export function isAstImportTypeAssertionContainer(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ImportTypeAssertionContainer; +} + +/** + * @deprecated + * @internal + */ +export function isAstAssertClause(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.AssertClause; +} + +/** + * @deprecated + * @internal + */ +export function isAstAssertEntry(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.AssertEntry; +} + +/** @internal */ +export function isAstImportAttributes(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ImportAttributes; +} + +/** @internal */ +export function isAstImportAttribute(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ImportAttribute; +} + +/** @internal */ +export function isAstNamespaceImport(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.NamespaceImport; +} + +/** @internal */ +export function isAstNamespaceExport(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.NamespaceExport; +} + +/** @internal */ +export function isAstNamedImports(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.NamedImports; +} + +/** @internal */ +export function isAstImportSpecifier(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ImportSpecifier; +} + +/** @internal */ +export function isAstExportAssignment(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ExportAssignment; +} + +/** @internal */ +export function isAstExportDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ExportDeclaration; +} + +/** @internal */ +export function isAstNamedExports(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.NamedExports; +} + +/** @internal */ +export function isAstExportSpecifier(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ExportSpecifier; +} + +/** @internal */ +export function isAstModuleExportName(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral; +} + +/** @internal */ +export function isAstMissingDeclaration(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.MissingDeclaration; +} + +/** @internal */ +export function isAstNotEmittedStatement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.NotEmittedStatement; +} + +/** @internal */ +export function isAstSyntheticReference(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.SyntheticReferenceExpression; +} + +// Module References + +/** @internal */ +export function isAstExternalModuleReference(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ExternalModuleReference; +} + +// JSX + +/** @internal */ +export function isAstJsxElement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxElement; +} + +/** @internal */ +export function isAstJsxSelfClosingElement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxSelfClosingElement; +} + +/** @internal */ +export function isAstJsxOpeningElement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxOpeningElement; +} + +/** @internal */ +export function isAstJsxClosingElement(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxClosingElement; +} + +/** @internal */ +export function isAstJsxFragment(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxFragment; +} + +/** @internal */ +export function isAstJsxOpeningFragment(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxOpeningFragment; +} + +/** @internal */ +export function isAstJsxClosingFragment(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxClosingFragment; +} + +/** @internal */ +export function isAstJsxAttribute(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxAttribute; +} + +/** @internal */ +export function isAstJsxAttributes(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxAttributes; +} + +/** @internal */ +export function isAstJsxSpreadAttribute(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxSpreadAttribute; +} + +/** @internal */ +export function isAstJsxExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxExpression; +} + +/** @internal */ +export function isAstJsxNamespacedName(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JsxNamespacedName; +} + +// Clauses + +/** @internal */ +export function isAstCaseClause(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.CaseClause; +} + +/** @internal */ +export function isAstDefaultClause(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.DefaultClause; +} + +/** @internal */ +export function isAstHeritageClause(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.HeritageClause; +} + +/** @internal */ +export function isAstCatchClause(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.CatchClause; +} + +// Property assignments + +/** @internal */ +export function isAstPropertyAssignment(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.PropertyAssignment; +} + +/** @internal */ +export function isAstShorthandPropertyAssignment(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.ShorthandPropertyAssignment; +} + +/** @internal */ +export function isAstSpreadAssignment(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.SpreadAssignment; +} + +// Enum + +/** @internal */ +export function isAstEnumMember(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.EnumMember; +} + + +/** @internal */// Top-level nodes +export function isAstSourceFile(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.SourceFile; +} + +/** @internal */ +export function isAstBundle(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.Bundle; +} + +// TODO(rbuckton): isInputFiles + +// JSDoc Elements + +/** @internal */ +export function isAstJSDocTypeExpression(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocTypeExpression; +} + +/** @internal */ +export function isAstJSDocNameReference(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocNameReference; +} + +/** @internal */ +export function isAstJSDocMemberName(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocMemberName; +} + +/** @internal */ +export function isAstJSDocLink(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocLink; +} + +/** @internal */ +export function isAstJSDocLinkCode(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocLinkCode; +} + +/** @internal */ +export function isAstJSDocLinkPlain(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocLinkPlain; +} + +/** @internal */ +export function isAstJSDocAllType(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocAllType; +} + +/** @internal */ +export function isAstJSDocUnknownType(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocUnknownType; +} + +/** @internal */ +export function isAstJSDocNullableType(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocNullableType; +} + +/** @internal */ +export function isAstJSDocNonNullableType(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocNonNullableType; +} + +/** @internal */ +export function isAstJSDocOptionalType(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocOptionalType; +} + +/** @internal */ +export function isAstJSDocFunctionType(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocFunctionType; +} + +/** @internal */ +export function isAstJSDocVariadicType(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocVariadicType; +} + +/** @internal */ +export function isAstJSDocNamepathType(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocNamepathType; +} + +/** @internal */ +export function isAstJSDoc(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDoc; +} + +/** @internal */ +export function isAstJSDocTypeLiteral(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocTypeLiteral; +} + +/** @internal */ +export function isAstJSDocSignature(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocSignature; +} + +// JSDoc Tags + +/** @internal */ +export function isAstJSDocAugmentsTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocAugmentsTag; +} + +/** @internal */ +export function isAstJSDocAuthorTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocAuthorTag; +} + +/** @internal */ +export function isAstJSDocClassTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocClassTag; +} + +/** @internal */ +export function isAstJSDocCallbackTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocCallbackTag; +} + +/** @internal */ +export function isAstJSDocPublicTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocPublicTag; +} + +/** @internal */ +export function isAstJSDocPrivateTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocPrivateTag; +} + +/** @internal */ +export function isAstJSDocProtectedTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocProtectedTag; +} + +/** @internal */ +export function isAstJSDocReadonlyTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocReadonlyTag; +} + +/** @internal */ +export function isAstJSDocOverrideTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocOverrideTag; +} + +/** @internal */ +export function isAstJSDocOverloadTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocOverloadTag; +} + +/** @internal */ +export function isAstJSDocDeprecatedTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocDeprecatedTag; +} + +/** @internal */ +export function isAstJSDocSeeTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocSeeTag; +} + +/** @internal */ +export function isAstJSDocEnumTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocEnumTag; +} + +/** @internal */ +export function isAstJSDocParameterTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocParameterTag; +} + +/** @internal */ +export function isAstJSDocReturnTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocReturnTag; +} + +/** @internal */ +export function isAstJSDocThisTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocThisTag; +} + +/** @internal */ +export function isAstJSDocTypeTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocTypeTag; +} + +/** @internal */ +export function isAstJSDocTemplateTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocTemplateTag; +} + +/** @internal */ +export function isAstJSDocTypedefTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocTypedefTag; +} + +/** @internal */ +export function isAstJSDocUnknownTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocTag; +} + +/** @internal */ +export function isAstJSDocPropertyTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocPropertyTag; +} + +/** @internal */ +export function isAstJSDocImplementsTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocImplementsTag; +} + +/** @internal */ +export function isAstJSDocSatisfiesTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocSatisfiesTag; +} + +/** @internal */ +export function isAstJSDocThrowsTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocThrowsTag; +} + +/** @internal */ +export function isAstJSDocImportTag(node: AstNode): node is AstNode { + return node.kind === SyntaxKind.JSDocImportTag; +} + +// Synthesized list + +/** @internal */ +export function isAstSyntaxList(n: Node): n is SyntaxList { + return n.kind === SyntaxKind.SyntaxList; +} + +// Unions + +/** @internal */ +export function isAstPropertyName(node: AstNode): node is AstPropertyName { + const kind = node.kind; + return kind === SyntaxKind.Identifier + || kind === SyntaxKind.PrivateIdentifier + || kind === SyntaxKind.StringLiteral + || kind === SyntaxKind.NumericLiteral + || kind === SyntaxKind.ComputedPropertyName; +} + +/** @internal */ +export function isAstPropertyAccessChain(node: AstNode): node is AstPropertyAccessChain { + return isAstPropertyAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +} + +/** @internal */ +export function isAstElementAccessChain(node: AstNode): node is AstElementAccessChain { + return isAstElementAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +} + +/** @internal */ +export function isAstCallChain(node: AstNode): node is AstCallChain { + return isAstCallExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +} + +/** @internal */ +export function isAstNonNullChain(node: AstNode): node is AstNonNullChain { + return isAstNonNullExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +} + +/** @internal */ +export function isAstOptionalChain(node: AstNode): node is AstPropertyAccessChain | AstElementAccessChain | AstCallChain | AstNonNullChain { + const kind = node.kind; + return !!(node.flags & NodeFlags.OptionalChain) && + (kind === SyntaxKind.PropertyAccessExpression + || kind === SyntaxKind.ElementAccessExpression + || kind === SyntaxKind.CallExpression + || kind === SyntaxKind.NonNullExpression); +} + +/** @internal */ +export function isAstOptionalChainRoot(node: AstNode): node is AstOptionalChainRoot { + return isAstOptionalChain(node) && !isAstNonNullExpression(node) && !!node.data.questionDotToken; +} diff --git a/src/compiler/factory/astParenthesizerRules.ts b/src/compiler/factory/astParenthesizerRules.ts new file mode 100644 index 0000000000000..a6033c6773a72 --- /dev/null +++ b/src/compiler/factory/astParenthesizerRules.ts @@ -0,0 +1,821 @@ +import { + AstAsExpression, + AstBinaryExpression, + AstCallExpression, + AstConciseBody, + AstConditionalExpression, + AstElementAccessExpression, + AstExpression, + AstLeftHandSideExpression, + AstNamedTupleMember, + AstNewExpression, + AstNode, + AstNodeArray, + AstNodeArrayLike, + AstNodeFactory, + AstNonNullExpression, + AstPartiallyEmittedExpression, + AstPostfixUnaryExpression, + AstPropertyAccessExpression, + AstSatisfiesExpression, + AstTaggedTemplateExpression, + AstTypeNode, + AstUnaryExpression, + isAstBinaryExpression, + isAstBlock, + isAstCallExpression, + isAstCommaListExpression, + isAstConditionalTypeNode, + isAstConstructorTypeNode, + isAstFunctionTypeNode, + isAstInferTypeNode, + isAstIntersectionTypeNode, + isAstJSDocNullableType, + isAstNamedTupleMember, + isAstOptionalChain, + isAstTypeOperatorNode, + isAstUnionTypeNode, + skipAstOuterExpressions, +} from "../_namespaces/ts.ast.js"; +import { + Associativity, + ast, + BinaryOperator, + compareValues, + Comparison, + Debug, + getExpressionAssociativity, + getExpressionPrecedence, + getOperatorAssociativity, + getOperatorPrecedence, + identity, + isLeftHandSideExpressionKind, + isLiteralKind, + isUnaryExpressionKind, + last, + OperatorPrecedence, + OuterExpressionKinds, + sameMap, + setTextRange, + SyntaxKind, + TextRange +} from "../_namespaces/ts.js"; + +/** @internal */ +export interface AstParenthesizerRules { + getParenthesizeLeftSideOfBinaryForOperator(binaryOperator: SyntaxKind): (leftSide: AstExpression) => AstExpression; + getParenthesizeRightSideOfBinaryForOperator(binaryOperator: SyntaxKind): (rightSide: AstExpression) => AstExpression; + parenthesizeLeftSideOfBinary(binaryOperator: SyntaxKind, + leftSide: AstExpression): AstExpression; + parenthesizeRightSideOfBinary(binaryOperator: SyntaxKind, leftSide: AstExpression | undefined, rightSide: AstExpression): AstExpression; + parenthesizeExpressionOfComputedPropertyName(expression: AstExpression): AstExpression; + parenthesizeConditionOfConditionalExpression(condition: AstExpression): AstExpression; + parenthesizeBranchOfConditionalExpression(branch: AstExpression): AstExpression; + parenthesizeExpressionOfExportDefault(expression: AstExpression): AstExpression; + parenthesizeExpressionOfNew(expression: AstExpression): AstLeftHandSideExpression; + parenthesizeLeftSideOfAccess(expression: AstExpression, optionalChain?: boolean): AstLeftHandSideExpression; + parenthesizeOperandOfPostfixUnary(operand: AstExpression): AstLeftHandSideExpression; + parenthesizeOperandOfPrefixUnary(operand: AstExpression): AstUnaryExpression; + parenthesizeExpressionsOfCommaDelimitedList(elements: AstNodeArrayLike): AstNodeArray; + parenthesizeExpressionForDisallowedComma(expression: AstExpression): AstExpression; + parenthesizeExpressionOfExpressionStatement(expression: AstExpression): AstExpression; + parenthesizeConciseBodyOfArrowFunction(body: AstExpression): AstExpression; + parenthesizeConciseBodyOfArrowFunction(body: AstConciseBody): AstConciseBody; + parenthesizeCheckTypeOfConditionalType(type: AstTypeNode): AstTypeNode; + parenthesizeExtendsTypeOfConditionalType(type: AstTypeNode): AstTypeNode; + parenthesizeOperandOfTypeOperator(type: AstTypeNode): AstTypeNode; + parenthesizeOperandOfReadonlyTypeOperator(type: AstTypeNode): AstTypeNode; + parenthesizeNonArrayTypeOfPostfixType(type: AstTypeNode): AstTypeNode; + parenthesizeElementTypesOfTupleType(types: AstNodeArrayLike): AstNodeArray; + parenthesizeElementTypeOfTupleType(type: AstTypeNode | AstNamedTupleMember): AstTypeNode | AstNamedTupleMember; + parenthesizeTypeOfOptionalType(type: AstTypeNode): AstTypeNode; + parenthesizeConstituentTypeOfUnionType(type: AstTypeNode): AstTypeNode; + parenthesizeConstituentTypesOfUnionType(constituents: AstNodeArrayLike): AstNodeArray; + parenthesizeConstituentTypeOfIntersectionType(type: AstTypeNode): AstTypeNode; + parenthesizeConstituentTypesOfIntersectionType(constituents: AstNodeArrayLike): AstNodeArray; + parenthesizeLeadingTypeArgument(typeNode: AstTypeNode): AstTypeNode; + parenthesizeTypeArguments(typeParameters: AstNodeArrayLike | undefined): AstNodeArray | undefined; +} + +/** @internal */ +export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenthesizerRules { + let binaryLeftOperandParenthesizerCache: Map AstExpression> | undefined; + let binaryRightOperandParenthesizerCache: Map AstExpression> | undefined; + + return { + getParenthesizeLeftSideOfBinaryForOperator, + getParenthesizeRightSideOfBinaryForOperator, + parenthesizeLeftSideOfBinary, + parenthesizeRightSideOfBinary, + parenthesizeExpressionOfComputedPropertyName, + parenthesizeConditionOfConditionalExpression, + parenthesizeBranchOfConditionalExpression, + parenthesizeExpressionOfExportDefault, + parenthesizeExpressionOfNew, + parenthesizeLeftSideOfAccess, + parenthesizeOperandOfPostfixUnary, + parenthesizeOperandOfPrefixUnary, + parenthesizeExpressionsOfCommaDelimitedList, + parenthesizeExpressionForDisallowedComma, + parenthesizeExpressionOfExpressionStatement, + parenthesizeConciseBodyOfArrowFunction, + parenthesizeCheckTypeOfConditionalType, + parenthesizeExtendsTypeOfConditionalType, + parenthesizeConstituentTypesOfUnionType, + parenthesizeConstituentTypeOfUnionType, + parenthesizeConstituentTypesOfIntersectionType, + parenthesizeConstituentTypeOfIntersectionType, + parenthesizeOperandOfTypeOperator, + parenthesizeOperandOfReadonlyTypeOperator, + parenthesizeNonArrayTypeOfPostfixType, + parenthesizeElementTypesOfTupleType, + parenthesizeElementTypeOfTupleType, + parenthesizeTypeOfOptionalType, + parenthesizeTypeArguments, + parenthesizeLeadingTypeArgument, + }; + + function getParenthesizeLeftSideOfBinaryForOperator(operatorKind: BinaryOperator) { + binaryLeftOperandParenthesizerCache ||= new Map(); + let parenthesizerRule = binaryLeftOperandParenthesizerCache.get(operatorKind); + if (!parenthesizerRule) { + parenthesizerRule = node => parenthesizeLeftSideOfBinary(operatorKind, node); + binaryLeftOperandParenthesizerCache.set(operatorKind, parenthesizerRule); + } + return parenthesizerRule; + } + + function getParenthesizeRightSideOfBinaryForOperator(operatorKind: BinaryOperator) { + binaryRightOperandParenthesizerCache ||= new Map(); + let parenthesizerRule = binaryRightOperandParenthesizerCache.get(operatorKind); + if (!parenthesizerRule) { + parenthesizerRule = node => parenthesizeRightSideOfBinary(operatorKind, /*leftSide*/ undefined, node); + binaryRightOperandParenthesizerCache.set(operatorKind, parenthesizerRule); + } + return parenthesizerRule; + } + + /** + * Determines whether the operand to a BinaryExpression needs to be parenthesized. + * + * @param binaryOperator The operator for the BinaryExpression. + * @param operand The operand for the BinaryExpression. + * @param isLeftSideOfBinary A value indicating whether the operand is the left side of the + * BinaryExpression. + */ + function binaryOperandNeedsParentheses(binaryOperator: SyntaxKind, operand: AstExpression, isLeftSideOfBinary: boolean, leftOperand: AstExpression | undefined) { + // If the operand has lower precedence, then it needs to be parenthesized to preserve the + // intent of the expression. For example, if the operand is `a + b` and the operator is + // `*`, then we need to parenthesize the operand to preserve the intended order of + // operations: `(a + b) * x`. + // + // If the operand has higher precedence, then it does not need to be parenthesized. For + // example, if the operand is `a * b` and the operator is `+`, then we do not need to + // parenthesize to preserve the intended order of operations: `a * b + x`. + // + // If the operand has the same precedence, then we need to check the associativity of + // the operator based on whether this is the left or right operand of the expression. + // + // For example, if `a / d` is on the right of operator `*`, we need to parenthesize + // to preserve the intended order of operations: `x * (a / d)` + // + // If `a ** d` is on the left of operator `**`, we need to parenthesize to preserve + // the intended order of operations: `(a ** b) ** c` + const binaryOperatorPrecedence = getOperatorPrecedence(SyntaxKind.BinaryExpression, binaryOperator); + const binaryOperatorAssociativity = getOperatorAssociativity(SyntaxKind.BinaryExpression, binaryOperator); + const emittedOperand = skipAstOuterExpressions(operand, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + if (!isLeftSideOfBinary && operand.kind === SyntaxKind.ArrowFunction && binaryOperatorPrecedence > OperatorPrecedence.Assignment) { + // We need to parenthesize arrow functions on the right side to avoid it being + // parsed as parenthesized expression: `a && (() => {})` + return true; + } + const operandPrecedence = getExpressionPrecedence(emittedOperand); + switch (compareValues(operandPrecedence, binaryOperatorPrecedence)) { + case Comparison.LessThan: + // If the operand is the right side of a right-associative binary operation + // and is a yield expression, then we do not need parentheses. + if ( + !isLeftSideOfBinary + && binaryOperatorAssociativity === Associativity.Right + && operand.kind === SyntaxKind.YieldExpression + ) { + return false; + } + + return true; + + case Comparison.GreaterThan: + return false; + + case Comparison.EqualTo: + if (isLeftSideOfBinary) { + // No need to parenthesize the left operand when the binary operator is + // left associative: + // (a*b)/x -> a*b/x + // (a**b)/x -> a**b/x + // + // Parentheses are needed for the left operand when the binary operator is + // right associative: + // (a/b)**x -> (a/b)**x + // (a**b)**x -> (a**b)**x + return binaryOperatorAssociativity === Associativity.Right; + } + else { + if ( + isAstBinaryExpression(emittedOperand) + && emittedOperand.data.operatorToken.kind === binaryOperator + ) { + // No need to parenthesize the right operand when the binary operator and + // operand are the same and one of the following: + // x*(a*b) => x*a*b + // x|(a|b) => x|a|b + // x&(a&b) => x&a&b + // x^(a^b) => x^a^b + if (operatorHasAssociativeProperty(binaryOperator)) { + return false; + } + + // No need to parenthesize the right operand when the binary operator + // is plus (+) if both the left and right operands consist solely of either + // literals of the same kind or binary plus (+) expressions for literals of + // the same kind (recursively). + // "a"+(1+2) => "a"+(1+2) + // "a"+("b"+"c") => "a"+"b"+"c" + if (binaryOperator === SyntaxKind.PlusToken) { + const leftKind = leftOperand ? getLiteralKindOfBinaryPlusOperand(leftOperand) : SyntaxKind.Unknown; + if (isLiteralKind(leftKind) && leftKind === getLiteralKindOfBinaryPlusOperand(emittedOperand)) { + return false; + } + } + } + + // No need to parenthesize the right operand when the operand is right + // associative: + // x/(a**b) -> x/a**b + // x**(a**b) -> x**a**b + // + // Parentheses are needed for the right operand when the operand is left + // associative: + // x/(a*b) -> x/(a*b) + // x**(a/b) -> x**(a/b) + const operandAssociativity = getExpressionAssociativity(emittedOperand); + return operandAssociativity === Associativity.Left; + } + } + } + + /** + * Determines whether a binary operator is mathematically associative. + * + * @param binaryOperator The binary operator. + */ + function operatorHasAssociativeProperty(binaryOperator: SyntaxKind) { + // The following operators are associative in JavaScript: + // (a*b)*c -> a*(b*c) -> a*b*c + // (a|b)|c -> a|(b|c) -> a|b|c + // (a&b)&c -> a&(b&c) -> a&b&c + // (a^b)^c -> a^(b^c) -> a^b^c + // (a,b),c -> a,(b,c) -> a,b,c + // + // While addition is associative in mathematics, JavaScript's `+` is not + // guaranteed to be associative as it is overloaded with string concatenation. + return binaryOperator === SyntaxKind.AsteriskToken + || binaryOperator === SyntaxKind.BarToken + || binaryOperator === SyntaxKind.AmpersandToken + || binaryOperator === SyntaxKind.CaretToken + || binaryOperator === SyntaxKind.CommaToken; + } + + /** + * This function determines whether an expression consists of a homogeneous set of + * literal expressions or binary plus expressions that all share the same literal kind. + * It is used to determine whether the right-hand operand of a binary plus expression can be + * emitted without parentheses. + */ + function getLiteralKindOfBinaryPlusOperand(node: AstExpression): SyntaxKind { + node = skipAstOuterExpressions(node, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + + if (isLiteralKind(node.kind)) { + return node.kind; + } + + if (isAstBinaryExpression(node) && (node as AstBinaryExpression).data.operatorToken.kind === SyntaxKind.PlusToken) { + if (node.data.cachedLiteralKind !== undefined) { + return node.data.cachedLiteralKind; + } + + const leftKind = getLiteralKindOfBinaryPlusOperand((node as AstBinaryExpression).data.left); + const literalKind = isLiteralKind(leftKind) + && leftKind === getLiteralKindOfBinaryPlusOperand((node as AstBinaryExpression).data.right) + ? leftKind + : SyntaxKind.Unknown; + + node.data.cachedLiteralKind = literalKind; + return literalKind; + } + + return SyntaxKind.Unknown; + } + + /** + * Wraps the operand to a BinaryExpression in parentheses if they are needed to preserve the intended + * order of operations. + * + * @param binaryOperator The operator for the BinaryExpression. + * @param operand The operand for the BinaryExpression. + * @param isLeftSideOfBinary A value indicating whether the operand is the left side of the + * BinaryExpression. + */ + function parenthesizeBinaryOperand(binaryOperator: SyntaxKind, operand: AstExpression, isLeftSideOfBinary: boolean, leftOperand?: AstExpression) { + const skipped = skipAstOuterExpressions(operand, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + + // If the resulting expression is already parenthesized, we do not need to do any further processing. + if (skipped.kind === SyntaxKind.ParenthesizedExpression) { + return operand; + } + + return binaryOperandNeedsParentheses(binaryOperator, operand, isLeftSideOfBinary, leftOperand) + ? factory.createParenthesizedExpression(operand) + : operand; + } + + function parenthesizeLeftSideOfBinary(binaryOperator: SyntaxKind, leftSide: AstExpression): AstExpression { + return parenthesizeBinaryOperand(binaryOperator, leftSide, /*isLeftSideOfBinary*/ true); + } + + function parenthesizeRightSideOfBinary(binaryOperator: SyntaxKind, leftSide: AstExpression | undefined, rightSide: AstExpression): AstExpression { + return parenthesizeBinaryOperand(binaryOperator, rightSide, /*isLeftSideOfBinary*/ false, leftSide); + } + + function parenthesizeExpressionOfComputedPropertyName(expression: AstExpression): AstExpression { + return isCommaSequence(expression) ? factory.createParenthesizedExpression(expression) : expression; + } + + function parenthesizeConditionOfConditionalExpression(condition: AstExpression): AstExpression { + const conditionalPrecedence = getOperatorPrecedence(SyntaxKind.ConditionalExpression, SyntaxKind.QuestionToken); + const emittedCondition = skipAstOuterExpressions(condition, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + const conditionPrecedence = getExpressionPrecedence(emittedCondition); + if (compareValues(conditionPrecedence, conditionalPrecedence) !== Comparison.GreaterThan) { + return factory.createParenthesizedExpression(condition); + } + return condition; + } + + function isCommaSequence(expression: AstExpression): boolean { + return isAstCommaListExpression(expression) || isAstBinaryExpression(expression) && expression.node.data.operatorToken.kind === SyntaxKind.CommaToken; + } + + function parenthesizeBranchOfConditionalExpression(branch: AstExpression): AstExpression { + // per ES grammar both 'whenTrue' and 'whenFalse' parts of conditional expression are assignment expressions + // so in case when comma expression is introduced as a part of previous transformations + // if should be wrapped in parens since comma operator has the lowest precedence + const emittedExpression = skipAstOuterExpressions(branch, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + return isCommaSequence(emittedExpression) + ? factory.createParenthesizedExpression(branch) + : branch; + } + + /** + * [Per the spec](https://tc39.github.io/ecma262/#prod-ExportDeclaration), `export default` accepts _AssigmentExpression_ but + * has a lookahead restriction for `function`, `async function`, and `class`. + * + * Basically, that means we need to parenthesize in the following cases: + * + * - BinaryExpression of CommaToken + * - CommaList (synthetic list of multiple comma expressions) + * - FunctionExpression + * - ClassExpression + */ + function parenthesizeExpressionOfExportDefault(expression: AstExpression): AstExpression { + const check = skipAstOuterExpressions(expression, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + let needsParens = isCommaSequence(check); + if (!needsParens) { + switch (getLeftmostExpression(check, /*stopAtCallExpressions*/ false).kind) { + case SyntaxKind.ClassExpression: + case SyntaxKind.FunctionExpression: + needsParens = true; + } + } + return needsParens ? factory.createParenthesizedExpression(expression) : expression; + } + + /** + * Wraps an expression in parentheses if it is needed in order to use the expression + * as the expression of a `NewExpression` node. + */ + function parenthesizeExpressionOfNew(expression: AstExpression): AstLeftHandSideExpression { + const leftmostExpr = getLeftmostExpression(expression, /*stopAtCallExpressions*/ true); + switch (leftmostExpr.kind) { + case SyntaxKind.CallExpression: + return factory.createParenthesizedExpression(expression); + + case SyntaxKind.NewExpression: + return !(leftmostExpr as AstNewExpression).data.arguments + ? factory.createParenthesizedExpression(expression) + : expression as AstLeftHandSideExpression; // TODO(rbuckton): Verify this assertion holds + } + + return parenthesizeLeftSideOfAccess(expression); + } + + /** + * Wraps an expression in parentheses if it is needed in order to use the expression for + * property or element access. + */ + function parenthesizeLeftSideOfAccess(expression: AstExpression, optionalChain?: boolean): AstLeftHandSideExpression { + // isLeftHandSideExpression is almost the correct criterion for when it is not necessary + // to parenthesize the expression before a dot. The known exception is: + // + // NewExpression: + // new C.x -> not the same as (new C).x + // + const emittedExpression = skipAstOuterExpressions(expression, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + if ( + isLeftHandSideExpressionKind(skipAstOuterExpressions(emittedExpression, OuterExpressionKinds.PartiallyEmittedExpressions).kind) + && (emittedExpression.kind !== SyntaxKind.NewExpression || (emittedExpression as AstNewExpression).data.arguments) + && (optionalChain || !isAstOptionalChain(emittedExpression)) + ) { + // TODO(rbuckton): Verify whether this assertion holds. + return expression as AstLeftHandSideExpression; + } + + // TODO(rbuckton): Verifiy whether `setTextRange` is needed. + return setTextRange(factory.createParenthesizedExpression(expression), expression); + } + + function parenthesizeOperandOfPostfixUnary(operand: AstExpression): AstLeftHandSideExpression { + // TODO(rbuckton): Verifiy whether `setTextRange` is needed. + return isLeftHandSideExpressionKind(skipAstOuterExpressions(operand, OuterExpressionKinds.PartiallyEmittedExpressions).kind) ? operand as AstLeftHandSideExpression : setTextRange(factory.createParenthesizedExpression(operand), operand); + } + + function parenthesizeOperandOfPrefixUnary(operand: AstExpression): AstUnaryExpression { + // TODO(rbuckton): Verifiy whether `setTextRange` is needed. + return isUnaryExpressionKind(skipAstOuterExpressions(operand, OuterExpressionKinds.PartiallyEmittedExpressions).kind) ? operand as AstUnaryExpression : setTextRange(factory.createParenthesizedExpression(operand), operand); + } + + function parenthesizeExpressionsOfCommaDelimitedList(elements: AstNodeArrayLike): AstNodeArray { + let hasTrailingComma = false; + let range: TextRange | undefined; + let items: readonly AstExpression[]; + if (elements instanceof AstNodeArray) { + hasTrailingComma = elements.hasTrailingComma; + items = elements.items; + range = elements; + } + else { + items = elements; + } + const result = sameMap(items, parenthesizeExpressionForDisallowedComma); + return setTextRange(factory.createNodeArray(result, hasTrailingComma), range); + } + + function parenthesizeExpressionForDisallowedComma(expression: AstExpression): AstExpression { + const emittedExpression = skipAstOuterExpressions(expression, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + const expressionPrecedence = getExpressionPrecedence(emittedExpression); + const commaPrecedence = getOperatorPrecedence(SyntaxKind.BinaryExpression, SyntaxKind.CommaToken); + // TODO(rbuckton): Verifiy whether `setTextRange` is needed. + return expressionPrecedence > commaPrecedence ? expression : setTextRange(factory.createParenthesizedExpression(expression), expression); + } + + function parenthesizeExpressionOfExpressionStatement(expression: AstExpression): AstExpression { + const emittedExpression = skipAstOuterExpressions(expression, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + if (isAstCallExpression(emittedExpression)) { + const callee = emittedExpression.data.expression; + const kind = skipAstOuterExpressions(callee, OuterExpressionKinds.PartiallyEmittedExpressions).kind; + if (kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction) { + // TODO(rbuckton): Verifiy whether `setTextRange` is needed. + const updated = factory.updateCallExpression( + emittedExpression, + setTextRange(factory.createParenthesizedExpression(callee), callee), + emittedExpression.data.typeArguments, + emittedExpression.data.arguments!, + ); + return factory.restoreOuterExpressions(expression, updated, OuterExpressionKinds.PartiallyEmittedExpressions); + } + } + + const leftmostExpressionKind = getLeftmostExpression(emittedExpression, /*stopAtCallExpressions*/ false).kind; + if (leftmostExpressionKind === SyntaxKind.ObjectLiteralExpression || leftmostExpressionKind === SyntaxKind.FunctionExpression) { + // TODO(rbuckton): Verifiy whether `setTextRange` is needed. + return setTextRange(factory.createParenthesizedExpression(expression), expression); + } + + return expression; + } + + function parenthesizeConciseBodyOfArrowFunction(body: AstExpression): AstExpression; + function parenthesizeConciseBodyOfArrowFunction(body: AstConciseBody): AstConciseBody; + function parenthesizeConciseBodyOfArrowFunction(body: AstConciseBody): AstConciseBody { + if (!isAstBlock(body) && (isCommaSequence(body) || getLeftmostExpression(body, /*stopAtCallExpressions*/ false).kind === SyntaxKind.ObjectLiteralExpression)) { + // TODO(rbuckton): Verifiy whether `setTextRange` is needed. + return setTextRange(factory.createParenthesizedExpression(body), body); + } + return body; + } + + // Type[Extends] : + // FunctionOrConstructorType + // ConditionalType[?Extends] + + // ConditionalType[Extends] : + // UnionType[?Extends] + // [~Extends] UnionType[~Extends] `extends` Type[+Extends] `?` Type[~Extends] `:` Type[~Extends] + // + // - The check type (the `UnionType`, above) does not allow function, constructor, or conditional types (they must be parenthesized) + // - The extends type (the first `Type`, above) does not allow conditional types (they must be parenthesized). Function and constructor types are fine. + // - The true and false branch types (the second and third `Type` non-terminals, above) allow any type + function parenthesizeCheckTypeOfConditionalType(checkType: AstTypeNode): AstTypeNode { + switch (checkType.kind) { + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + case SyntaxKind.ConditionalType: + return factory.createParenthesizedType(checkType); + } + return checkType; + } + + function parenthesizeExtendsTypeOfConditionalType(extendsType: AstTypeNode): AstTypeNode { + switch (extendsType.kind) { + case SyntaxKind.ConditionalType: + return factory.createParenthesizedType(extendsType); + } + return extendsType; + } + + // UnionType[Extends] : + // `|`? IntersectionType[?Extends] + // UnionType[?Extends] `|` IntersectionType[?Extends] + // + // - A union type constituent has the same precedence as the check type of a conditional type + function parenthesizeConstituentTypeOfUnionType(type: AstTypeNode) { + switch (type.kind) { + case SyntaxKind.UnionType: // Not strictly necessary, but a union containing a union should have been flattened + case SyntaxKind.IntersectionType: // Not strictly necessary, but makes generated output more readable and avoids breaks in DT tests + return factory.createParenthesizedType(type); + } + return parenthesizeCheckTypeOfConditionalType(type); + } + + function parenthesizeConstituentTypesOfUnionType(members:AstNodeArrayLike): AstNodeArray { + return factory.createNodeArray(sameMap(items(members), parenthesizeConstituentTypeOfUnionType)); + } + + // IntersectionType[Extends] : + // `&`? TypeOperator[?Extends] + // IntersectionType[?Extends] `&` TypeOperator[?Extends] + // + // - An intersection type constituent does not allow function, constructor, conditional, or union types (they must be parenthesized) + function parenthesizeConstituentTypeOfIntersectionType(type: AstTypeNode) { + switch (type.kind) { + case SyntaxKind.UnionType: + case SyntaxKind.IntersectionType: // Not strictly necessary, but an intersection containing an intersection should have been flattened + return factory.createParenthesizedType(type); + } + return parenthesizeConstituentTypeOfUnionType(type); + } + + function parenthesizeConstituentTypesOfIntersectionType(members: AstNodeArrayLike): AstNodeArray { + return factory.createNodeArray(sameMap(items(members), parenthesizeConstituentTypeOfIntersectionType)); + } + + // TypeOperator[Extends] : + // PostfixType + // InferType[?Extends] + // `keyof` TypeOperator[?Extends] + // `unique` TypeOperator[?Extends] + // `readonly` TypeOperator[?Extends] + // + function parenthesizeOperandOfTypeOperator(type: AstTypeNode) { + switch (type.kind) { + case SyntaxKind.IntersectionType: + return factory.createParenthesizedType(type); + } + return parenthesizeConstituentTypeOfIntersectionType(type); + } + + function parenthesizeOperandOfReadonlyTypeOperator(type: AstTypeNode) { + switch (type.kind) { + case SyntaxKind.TypeOperator: + return factory.createParenthesizedType(type); + } + return parenthesizeOperandOfTypeOperator(type); + } + + // PostfixType : + // NonArrayType + // NonArrayType [no LineTerminator here] `!` // JSDoc + // NonArrayType [no LineTerminator here] `?` // JSDoc + // IndexedAccessType + // ArrayType + // + // IndexedAccessType : + // NonArrayType `[` Type[~Extends] `]` + // + // ArrayType : + // NonArrayType `[` `]` + // + function parenthesizeNonArrayTypeOfPostfixType(type: AstTypeNode) { + switch (type.kind) { + case SyntaxKind.InferType: + case SyntaxKind.TypeOperator: + case SyntaxKind.TypeQuery: // Not strictly necessary, but makes generated output more readable and avoids breaks in DT tests + return factory.createParenthesizedType(type); + } + return parenthesizeOperandOfTypeOperator(type); + } + + // TupleType : + // `[` Elision? `]` + // `[` NamedTupleElementTypes `]` + // `[` NamedTupleElementTypes `,` Elision? `]` + // `[` TupleElementTypes `]` + // `[` TupleElementTypes `,` Elision? `]` + // + // NamedTupleElementTypes : + // Elision? NamedTupleMember + // NamedTupleElementTypes `,` Elision? NamedTupleMember + // + // NamedTupleMember : + // Identifier `?`? `:` Type[~Extends] + // `...` Identifier `:` Type[~Extends] + // + // TupleElementTypes : + // Elision? TupleElementType + // TupleElementTypes `,` Elision? TupleElementType + // + // TupleElementType : + // Type[~Extends] // NOTE: Needs cover grammar to disallow JSDoc postfix-optional + // OptionalType + // RestType + // + // OptionalType : + // Type[~Extends] `?` // NOTE: Needs cover grammar to disallow JSDoc postfix-optional + // + // RestType : + // `...` Type[~Extends] + // + function parenthesizeElementTypesOfTupleType(types: AstNodeArrayLike): AstNodeArray { + return factory.createNodeArray(sameMap(items(types), parenthesizeElementTypeOfTupleType)); + } + + function parenthesizeElementTypeOfTupleType(type: AstTypeNode | AstNamedTupleMember): AstTypeNode { + if (hasJSDocPostfixQuestion(type)) return factory.createParenthesizedType(type); + return type; + } + + function hasJSDocPostfixQuestion(type: AstTypeNode | AstNamedTupleMember): boolean { + if (isAstJSDocNullableType(type)) return type.data.postfix; + if (isAstNamedTupleMember(type)) return hasJSDocPostfixQuestion(type.data.type); + if (isAstFunctionTypeNode(type) || isAstConstructorTypeNode(type) || isAstTypeOperatorNode(type)) return hasJSDocPostfixQuestion(type.data.type); + if (isAstConditionalTypeNode(type)) return hasJSDocPostfixQuestion(type.data.falseType); + if (isAstUnionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types!.items)); + if (isAstIntersectionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types!.items)); + if (isAstInferTypeNode(type)) return !!type.data.typeParameter.data.constraint && hasJSDocPostfixQuestion(type.data.typeParameter.data.constraint); + return false; + } + + function parenthesizeTypeOfOptionalType(type: AstTypeNode): AstTypeNode { + if (hasJSDocPostfixQuestion(type)) return factory.createParenthesizedType(type); + return parenthesizeNonArrayTypeOfPostfixType(type); + } + + // function parenthesizeMemberOfElementType(member: AstTypeNode): AstTypeNode { + // switch (member.kind) { + // case SyntaxKind.UnionType: + // case SyntaxKind.IntersectionType: + // case SyntaxKind.FunctionType: + // case SyntaxKind.ConstructorType: + // return factory.createParenthesizedType(member); + // } + // return parenthesizeMemberOfConditionalType(member); + // } + + // function parenthesizeElementTypeOfArrayType(member: AstTypeNode): AstTypeNode { + // switch (member.kind) { + // case SyntaxKind.TypeQuery: + // case SyntaxKind.TypeOperator: + // case SyntaxKind.InferType: + // return factory.createParenthesizedType(member); + // } + // return parenthesizeMemberOfElementType(member); + // } + + function parenthesizeLeadingTypeArgument(node: AstTypeNode) { + return (isAstFunctionTypeNode(node) || isAstConstructorTypeNode(node)) && node.data.typeParameters ? factory.createParenthesizedType(node) : node; + } + + function parenthesizeOrdinalTypeArgument(node: AstTypeNode, i: number) { + return i === 0 ? parenthesizeLeadingTypeArgument(node) : node; + } + + function parenthesizeTypeArguments(typeArguments: AstNodeArrayLike | undefined): AstNodeArray | undefined { + if (items(typeArguments)?.length) { + return factory.createNodeArray(sameMap(items(typeArguments), parenthesizeOrdinalTypeArgument)); + } + } +} + +/** @internal */ +export const nullAstParenthesizerRules: AstParenthesizerRules = { + getParenthesizeLeftSideOfBinaryForOperator: _ => identity, + getParenthesizeRightSideOfBinaryForOperator: _ => identity, + parenthesizeLeftSideOfBinary: (_binaryOperator, leftSide) => leftSide, + parenthesizeRightSideOfBinary: (_binaryOperator, _leftSide, rightSide) => rightSide, + parenthesizeExpressionOfComputedPropertyName: identity, + parenthesizeConditionOfConditionalExpression: identity, + parenthesizeBranchOfConditionalExpression: identity, + parenthesizeExpressionOfExportDefault: identity, + parenthesizeExpressionOfNew: expression => { + Debug.assert(isLeftHandSideExpressionKind(expression.kind)); + return expression as AstLeftHandSideExpression; + }, + parenthesizeLeftSideOfAccess: expression => { + Debug.assert(isLeftHandSideExpressionKind(expression.kind)); + return expression as AstLeftHandSideExpression; + }, + parenthesizeOperandOfPostfixUnary: operand => { + Debug.assert(isLeftHandSideExpressionKind(operand.kind)); + return operand as AstLeftHandSideExpression; + }, + parenthesizeOperandOfPrefixUnary: operand => { + Debug.assert(isUnaryExpressionKind(operand.kind)); + return operand as AstUnaryExpression; + }, + parenthesizeExpressionsOfCommaDelimitedList: nodes => { + Debug.assert(nodes instanceof AstNodeArray); + return nodes; + }, + parenthesizeExpressionForDisallowedComma: identity, + parenthesizeExpressionOfExpressionStatement: identity, + parenthesizeConciseBodyOfArrowFunction: identity, + parenthesizeCheckTypeOfConditionalType: identity, + parenthesizeExtendsTypeOfConditionalType: identity, + parenthesizeConstituentTypesOfUnionType: nodes => { + Debug.assert(nodes instanceof AstNodeArray); + return nodes; + }, + parenthesizeConstituentTypeOfUnionType: identity, + parenthesizeConstituentTypesOfIntersectionType: nodes => { + Debug.assert(nodes instanceof AstNodeArray); + return nodes; + }, + parenthesizeConstituentTypeOfIntersectionType: identity, + parenthesizeOperandOfTypeOperator: identity, + parenthesizeOperandOfReadonlyTypeOperator: identity, + parenthesizeNonArrayTypeOfPostfixType: identity, + parenthesizeElementTypesOfTupleType: nodes => { + Debug.assert(nodes instanceof AstNodeArray); + return nodes; + }, + parenthesizeElementTypeOfTupleType: identity, + parenthesizeTypeOfOptionalType: identity, + parenthesizeTypeArguments: nodes => { + Debug.assert(!nodes || nodes instanceof AstNodeArray); + return nodes; + }, + parenthesizeLeadingTypeArgument: identity, +}; + +function getLeftmostExpression(node: AstExpression, stopAtCallExpressions: boolean) { + while (true) { + switch (node.kind) { + case SyntaxKind.PostfixUnaryExpression: + node = (node as AstPostfixUnaryExpression).data.operand; + continue; + + case SyntaxKind.BinaryExpression: + node = (node as AstBinaryExpression).data.left; + continue; + + case SyntaxKind.ConditionalExpression: + node = (node as AstConditionalExpression).data.condition; + continue; + + case SyntaxKind.TaggedTemplateExpression: + node = (node as AstTaggedTemplateExpression).data.tag; + continue; + + case SyntaxKind.CallExpression: + if (stopAtCallExpressions) { + return node; + } + // falls through + case SyntaxKind.AsExpression: + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.NonNullExpression: + case SyntaxKind.PartiallyEmittedExpression: + case SyntaxKind.SatisfiesExpression: + node = (node as AstCallExpression | AstPropertyAccessExpression | AstElementAccessExpression | AstAsExpression | AstNonNullExpression | AstPartiallyEmittedExpression | AstSatisfiesExpression).data.expression; + continue; + } + + return node; + } +} + +function items(nodes: AstNodeArrayLike): readonly T[]; +function items(nodes: AstNodeArrayLike | undefined): readonly T[] | undefined; +function items(nodes: AstNodeArrayLike | undefined): readonly T[] | undefined { + return nodes instanceof AstNodeArray ? nodes.items : nodes; +} diff --git a/src/compiler/factory/baseNodeFactory.ts b/src/compiler/factory/baseNodeFactory.ts deleted file mode 100644 index 4043f1a8931a1..0000000000000 --- a/src/compiler/factory/baseNodeFactory.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { - Node, - objectAllocator, - SyntaxKind, -} from "../_namespaces/ts.js"; - -/** - * A `BaseNodeFactory` is an abstraction over an `ObjectAllocator` that handles caching `Node` constructors - * and allocating `Node` instances based on a set of predefined types. - * - * @internal - */ -export interface BaseNodeFactory { - createBaseSourceFileNode(kind: SyntaxKind.SourceFile): Node; - createBaseIdentifierNode(kind: SyntaxKind.Identifier): Node; - createBasePrivateIdentifierNode(kind: SyntaxKind.PrivateIdentifier): Node; - createBaseTokenNode(kind: SyntaxKind): Node; - createBaseNode(kind: SyntaxKind): Node; -} - -/** - * Creates a `BaseNodeFactory` which can be used to create `Node` instances from the constructors provided by the object allocator. - * - * @internal - */ -export function createBaseNodeFactory(): BaseNodeFactory { - let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; - let TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; - let IdentifierConstructor: new (kind: SyntaxKind.Identifier, pos: number, end: number) => Node; - let PrivateIdentifierConstructor: new (kind: SyntaxKind.PrivateIdentifier, pos: number, end: number) => Node; - let SourceFileConstructor: new (kind: SyntaxKind.SourceFile, pos: number, end: number) => Node; - - return { - createBaseSourceFileNode, - createBaseIdentifierNode, - createBasePrivateIdentifierNode, - createBaseTokenNode, - createBaseNode, - }; - - function createBaseSourceFileNode(kind: SyntaxKind.SourceFile): Node { - return new (SourceFileConstructor || (SourceFileConstructor = objectAllocator.getSourceFileConstructor()))(kind, /*pos*/ -1, /*end*/ -1); - } - - function createBaseIdentifierNode(kind: SyntaxKind.Identifier): Node { - return new (IdentifierConstructor || (IdentifierConstructor = objectAllocator.getIdentifierConstructor()))(kind, /*pos*/ -1, /*end*/ -1); - } - - function createBasePrivateIdentifierNode(kind: SyntaxKind.PrivateIdentifier): Node { - return new (PrivateIdentifierConstructor || (PrivateIdentifierConstructor = objectAllocator.getPrivateIdentifierConstructor()))(kind, /*pos*/ -1, /*end*/ -1); - } - - function createBaseTokenNode(kind: SyntaxKind): Node { - return new (TokenConstructor || (TokenConstructor = objectAllocator.getTokenConstructor()))(kind, /*pos*/ -1, /*end*/ -1); - } - - function createBaseNode(kind: SyntaxKind): Node { - return new (NodeConstructor || (NodeConstructor = objectAllocator.getNodeConstructor()))(kind, /*pos*/ -1, /*end*/ -1); - } -} diff --git a/src/compiler/factory/emitNode.ts b/src/compiler/factory/emitNode.ts index 5b90c578148d1..c7048875ea61e 100644 --- a/src/compiler/factory/emitNode.ts +++ b/src/compiler/factory/emitNode.ts @@ -2,6 +2,7 @@ import { AccessExpression, append, appendIfUnique, + ast, AutoGenerateInfo, Debug, EmitFlags, @@ -33,7 +34,7 @@ import { * various transient transformation properties. * @internal */ -export function getOrCreateEmitNode(node: Node): EmitNode { +export function getOrCreateEmitNode(node: Node | ast.AstNode): EmitNode { if (!node.emitNode) { if (isParseTreeNode(node)) { // To avoid holding onto transformation artifacts, we keep track of any @@ -43,8 +44,14 @@ export function getOrCreateEmitNode(node: Node): EmitNode { return node.emitNode = { annotatedNodes: [node] } as EmitNode; } - const sourceFile = getSourceFileOfNode(getParseTreeNode(getSourceFileOfNode(node))) ?? Debug.fail("Could not determine parsed source file."); - getOrCreateEmitNode(sourceFile).annotatedNodes!.push(node); + if (node instanceof ast.AstNode) { + const sourceFile = ast.getAstSourceFileNodeOfNode(ast.getAstParseTreeNode(ast.getAstSourceFileNodeOfNode(node))) ?? Debug.fail("Could not determine parsed source file."); + getOrCreateEmitNode(sourceFile).annotatedNodes!.push(node.node); + } + else { + const sourceFile = getSourceFileOfNode(getParseTreeNode(getSourceFileOfNode(node))) ?? Debug.fail("Could not determine parsed source file."); + getOrCreateEmitNode(sourceFile).annotatedNodes!.push(node); + } } node.emitNode = {} as EmitNode; @@ -89,7 +96,10 @@ export function removeAllComments(node: T): T { /** * Sets flags that control emit behavior of a node. */ -export function setEmitFlags(node: T, emitFlags: EmitFlags) { +export function setEmitFlags(node: T, emitFlags: EmitFlags): T; +/** @internal */ +export function setEmitFlags>(node: T, emitFlags: EmitFlags): T; +export function setEmitFlags>(node: T, emitFlags: EmitFlags) { getOrCreateEmitNode(node).flags = emitFlags; return node; } @@ -129,7 +139,10 @@ export function addInternalEmitFlags(node: T, emitFlags: Interna /** * Gets a custom text range to use when emitting source maps. */ -export function getSourceMapRange(node: Node): SourceMapRange { +export function getSourceMapRange(node: Node): SourceMapRange; +/** @internal */ +export function getSourceMapRange(node: Node | ast.AstNode): SourceMapRange; // eslint-disable-line @typescript-eslint/unified-signatures +export function getSourceMapRange(node: Node | ast.AstNode): SourceMapRange { return node.emitNode?.sourceMapRange ?? node; } @@ -180,7 +193,10 @@ export function setStartsOnNewLine(node: T, newLine: boolean) { /** * Gets a custom text range to use when emitting comments. */ -export function getCommentRange(node: Node): TextRange { +export function getCommentRange(node: Node): TextRange; +/** @internal */ +export function getCommentRange(node: Node | ast.AstNode): TextRange; // eslint-disable-line @typescript-eslint/unified-signatures +export function getCommentRange(node: Node | ast.AstNode): TextRange { return node.emitNode?.commentRange ?? node; } @@ -192,7 +208,10 @@ export function setCommentRange(node: T, range: TextRange) { return node; } -export function getSyntheticLeadingComments(node: Node): SynthesizedComment[] | undefined { +export function getSyntheticLeadingComments(node: Node): SynthesizedComment[] | undefined; +/** @internal */ +export function getSyntheticLeadingComments(node: Node | ast.AstNode): SynthesizedComment[] | undefined; // eslint-disable-line @typescript-eslint/unified-signatures +export function getSyntheticLeadingComments(node: Node | ast.AstNode): SynthesizedComment[] | undefined { return node.emitNode?.leadingComments; } @@ -205,7 +224,10 @@ export function addSyntheticLeadingComment(node: T, kind: Syntax return setSyntheticLeadingComments(node, append(getSyntheticLeadingComments(node), { kind, pos: -1, end: -1, hasTrailingNewLine, text })); } -export function getSyntheticTrailingComments(node: Node): SynthesizedComment[] | undefined { +export function getSyntheticTrailingComments(node: Node): SynthesizedComment[] | undefined; +/** @internal */ +export function getSyntheticTrailingComments(node: Node | ast.AstNode): SynthesizedComment[] | undefined; // eslint-disable-line @typescript-eslint/unified-signatures +export function getSyntheticTrailingComments(node: Node | ast.AstNode): SynthesizedComment[] | undefined { return node.emitNode?.trailingComments; } @@ -348,24 +370,24 @@ export function getTypeNode(node: T): TypeNode | undefined { } /** @internal */ -export function setIdentifierTypeArguments(node: T, typeArguments: NodeArray | undefined) { +export function setIdentifierTypeArguments(node: T, typeArguments: NodeArray | undefined) { getOrCreateEmitNode(node).identifierTypeArguments = typeArguments; return node; } /** @internal */ -export function getIdentifierTypeArguments(node: Identifier): NodeArray | undefined { +export function getIdentifierTypeArguments(node: Identifier | ast.AstIdentifier): NodeArray | undefined { return node.emitNode?.identifierTypeArguments; } /** @internal */ -export function setIdentifierAutoGenerate(node: T, autoGenerate: AutoGenerateInfo | undefined) { +export function setIdentifierAutoGenerate(node: T, autoGenerate: AutoGenerateInfo | undefined) { getOrCreateEmitNode(node).autoGenerate = autoGenerate; return node; } /** @internal @knipignore */ -export function getIdentifierAutoGenerate(node: Identifier | PrivateIdentifier): AutoGenerateInfo | undefined { +export function getIdentifierAutoGenerate(node: Identifier | PrivateIdentifier | ast.AstIdentifier | ast.AstPrivateIdentifier): AutoGenerateInfo | undefined { return node.emitNode?.autoGenerate; } diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 9c26d5dcfff51..21a95aab1dcb8 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -1,5 +1,4 @@ import { - __String, AccessorDeclaration, addRange, append, @@ -14,20 +13,16 @@ import { AssertEntry, AssertionKey, AssertsKeyword, - AssignmentPattern, AsteriskToken, AwaitExpression, AwaitKeyword, - BaseNodeFactory, BigIntLiteral, BinaryExpression, BinaryOperator, BinaryOperatorToken, BindingElement, BindingName, - BindingPattern, Block, - BooleanLiteral, BreakStatement, Bundle, CallBinding, @@ -37,9 +32,7 @@ import { CaseBlock, CaseClause, CaseOrDefaultClause, - cast, CatchClause, - CharacterCodes, ClassDeclaration, ClassElement, ClassExpression, @@ -53,12 +46,9 @@ import { ConstructorDeclaration, ConstructorTypeNode, ConstructSignatureDeclaration, - containsObjectRestOrSpread, ContinueStatement, - createBaseNodeFactory, createNodeConverters, createParenthesizerRules, - createScanner, Debug, DebuggerStatement, Declaration, @@ -72,14 +62,12 @@ import { ElementAccessExpression, EmitFlags, EmitNode, - emptyArray, EmptyStatement, EndOfFileToken, EntityName, EnumDeclaration, EnumMember, EqualsGreaterThanToken, - escapeLeadingUnderscores, every, ExclamationToken, ExportAssignment, @@ -90,7 +78,6 @@ import { ExpressionWithTypeArguments, ExternalModuleReference, FalseLiteral, - FileReference, findUseStrictPrologue, forEach, ForInitializer, @@ -108,8 +95,6 @@ import { GetAccessorDeclaration, getCommentRange, getEmitFlags, - getIdentifierTypeArguments, - getJSDocTypeAliasName, getNameOfDeclaration, getNodeId, getNonAssignedNameOfDeclaration, @@ -118,13 +103,10 @@ import { getSyntheticTrailingComments, getTextOfIdentifierOrLiteral, HasDecorators, - hasInvalidEscape, HasModifiers, - hasProperty, hasSyntacticModifier, HeritageClause, Identifier, - identity, idText, IfStatement, ImmediatelyInvokedArrowFunction, @@ -145,72 +127,47 @@ import { InternalEmitFlags, IntersectionTypeNode, isArray, - isArrayLiteralExpression, isArrowFunction, - isBinaryExpression, isCallChain, isClassDeclaration, isClassExpression, - isCommaListExpression, - isCommaToken, - isComputedPropertyName, isConstructorDeclaration, isConstructorTypeNode, isCustomPrologue, - isElementAccessChain, isElementAccessExpression, isEnumDeclaration, - isExclamationToken, isExportAssignment, isExportDeclaration, - isExternalModuleReference, isFunctionDeclaration, isFunctionExpression, isGeneratedIdentifier, - isGeneratedPrivateIdentifier, isGetAccessorDeclaration, isHoistedFunction, isHoistedVariableStatement, isIdentifier, isImportDeclaration, isImportEqualsDeclaration, - isImportKeyword, isIndexSignatureDeclaration, isInterfaceDeclaration, isLabeledStatement, - isLocalName, - isLogicalOrCoalescingAssignmentOperator, isMemberName, isMethodDeclaration, isMethodSignature, isModuleDeclaration, - isNamedDeclaration, isNodeArray, - isNodeKind, - isNonNullChain, - isNotEmittedStatement, - isObjectLiteralExpression, - isOmittedExpression, isOuterExpression, isParameter, isParenthesizedExpression, - isParseTreeNode, - isPrivateIdentifier, isPrologueDirective, - isPropertyAccessChain, isPropertyAccessExpression, isPropertyDeclaration, - isPropertyName, isPropertySignature, - isQuestionToken, isSetAccessorDeclaration, - isSourceFile, isStatement, isStatementOrBlock, isStringLiteral, isSuperKeyword, isSuperProperty, - isThisIdentifier, isTypeAliasDeclaration, isTypeParameterDeclaration, isVariableDeclaration, @@ -220,6 +177,7 @@ import { JSDocAugmentsTag, JSDocAuthorTag, JSDocCallbackTag, + JSDocClassReference, JSDocClassTag, JSDocComment, JSDocDeprecatedTag, @@ -255,7 +213,6 @@ import { JSDocText, JSDocThisTag, JSDocThrowsTag, - JSDocType, JSDocTypedefTag, JSDocTypeExpression, JSDocTypeLiteral, @@ -286,13 +243,11 @@ import { KeywordTypeNode, KeywordTypeSyntaxKind, LabeledStatement, - LanguageVariant, - lastOrUndefined, LeftHandSideExpression, + LiteralExpression, LiteralToken, LiteralTypeNode, MappedTypeNode, - MemberName, memoize, memoizeOne, MetaProperty, @@ -303,7 +258,6 @@ import { Modifier, ModifierFlags, ModifierLike, - modifiersToFlags, ModifierSyntaxKind, ModifierToken, ModuleBlock, @@ -312,8 +266,6 @@ import { ModuleExportName, ModuleName, ModuleReference, - Mutable, - MutableNodeArray, NamedExportBindings, NamedExports, NamedImportBindings, @@ -339,6 +291,7 @@ import { NumericLiteral, objectAllocator, ObjectBindingPattern, + ObjectLiteralElement, ObjectLiteralElementLike, ObjectLiteralExpression, OmittedExpression, @@ -349,7 +302,6 @@ import { ParenthesizedExpression, ParenthesizedTypeNode, PartiallyEmittedExpression, - Path, PlusToken, PostfixUnaryExpression, PostfixUnaryOperator, @@ -367,7 +319,6 @@ import { PropertyNameLiteral, PropertySignature, PseudoBigInt, - pseudoBigIntToString, PunctuationSyntaxKind, PunctuationToken, QualifiedName, @@ -380,19 +331,15 @@ import { RestTypeNode, ReturnStatement, returnTrue, - sameFlatMap, SatisfiesExpression, - Scanner, ScriptTarget, SemicolonClassElement, SetAccessorDeclaration, setEmitFlags, setIdentifierAutoGenerate, - setIdentifierTypeArguments, setParent, setTextRange, ShorthandPropertyAssignment, - SignatureDeclarationBase, singleOrUndefined, skipOuterExpressions, skipParentheses, @@ -405,7 +352,6 @@ import { startsWith, Statement, StringLiteral, - stringToToken, SuperExpression, SwitchStatement, SyntaxKind, @@ -416,7 +362,6 @@ import { TemplateExpression, TemplateHead, TemplateLiteral, - TemplateLiteralLikeNode, TemplateLiteralToken, TemplateLiteralTypeNode, TemplateLiteralTypeSpan, @@ -429,6 +374,7 @@ import { ThrowStatement, Token, TokenFlags, + TokenSyntaxKind, TransformFlags, TrueLiteral, TryStatement, @@ -446,7 +392,6 @@ import { TypePredicateNode, TypeQueryNode, TypeReferenceNode, - UnionOrIntersectionTypeNode, UnionTypeNode, VariableDeclaration, VariableDeclarationList, @@ -458,6 +403,7 @@ import { WithStatement, YieldExpression, } from "../_namespaces/ts.js"; +import * as ast from "../_namespaces/ts.ast.js"; let nextAutoGenerateId = 0; @@ -472,6 +418,8 @@ export const enum NodeFactoryFlags { NoIndentationOnFreshPropertyAccess = 1 << 2, // Do not set an `original` pointer when updating a node. NoOriginalNode = 1 << 3, + // Mark nodes as synthetic + Synthesized = 1 << 4, } const nodeFactoryPatchers: ((factory: NodeFactory) => void)[] = []; @@ -484,12 +432,11 @@ export function addNodeFactoryPatcher(fn: (factory: NodeFactory) => void) { /** * Creates a `NodeFactory` that can be used to create and update a syntax tree. * @param flags Flags that control factory behavior. - * @param baseFactory A `BaseNodeFactory` used to create the base `Node` objects. * * @internal */ -export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNodeFactory): NodeFactory { - const setOriginal = flags & NodeFactoryFlags.NoOriginalNode ? identity : setOriginalNode; +export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: Node) => void): NodeFactory { + const astFactory = ast.createAstNodeFactory(flags, onFinishNode && (ast => onFinishNode(ast.node))); // Lazily load the parenthesizer, node converters, and some factory methods until they are used. const parenthesizerRules = memoize(() => flags & NodeFactoryFlags.NoParenthesizerRules ? nullParenthesizerRules : createParenthesizerRules(factory)); @@ -499,15 +446,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const getBinaryCreateFunction = memoizeOne((operator: BinaryOperator) => (left: Expression, right: Expression) => createBinaryExpression(left, operator, right)); const getPrefixUnaryCreateFunction = memoizeOne((operator: PrefixUnaryOperator) => (operand: Expression) => createPrefixUnaryExpression(operator, operand)); const getPostfixUnaryCreateFunction = memoizeOne((operator: PostfixUnaryOperator) => (operand: Expression) => createPostfixUnaryExpression(operand, operator)); - const getJSDocPrimaryTypeCreateFunction = memoizeOne((kind: T["kind"]) => () => createJSDocPrimaryTypeWorker(kind)); - const getJSDocUnaryTypeCreateFunction = memoizeOne((kind: T["kind"]) => (type: T["type"]) => createJSDocUnaryTypeWorker(kind, type)); - const getJSDocUnaryTypeUpdateFunction = memoizeOne((kind: T["kind"]) => (node: T, type: T["type"]) => updateJSDocUnaryTypeWorker(kind, node, type)); - const getJSDocPrePostfixUnaryTypeCreateFunction = memoizeOne((kind: T["kind"]) => (type: T["type"], postfix?: boolean) => createJSDocPrePostfixUnaryTypeWorker(kind, type, postfix)); - const getJSDocPrePostfixUnaryTypeUpdateFunction = memoizeOne((kind: T["kind"]) => (node: T, type: T["type"]) => updateJSDocPrePostfixUnaryTypeWorker(kind, node, type)); - const getJSDocSimpleTagCreateFunction = memoizeOne((kind: T["kind"]) => (tagName: Identifier | undefined, comment?: NodeArray) => createJSDocSimpleTagWorker(kind, tagName, comment)); - const getJSDocSimpleTagUpdateFunction = memoizeOne((kind: T["kind"]) => (node: T, tagName: Identifier | undefined, comment?: NodeArray) => updateJSDocSimpleTagWorker(kind, node, tagName, comment)); - const getJSDocTypeLikeTagCreateFunction = memoizeOne((kind: T["kind"]) => (tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: NodeArray) => createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment)); - const getJSDocTypeLikeTagUpdateFunction = memoizeOne((kind: T["kind"]) => (node: T, tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: NodeArray) => updateJSDocTypeLikeTagWorker(kind, node, tagName, typeExpression, comment)); const factory: NodeFactory = { get parenthesizer() { @@ -516,7 +454,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode get converters() { return converters(); }, - baseFactory, + astFactory, flags, createNodeArray, createNumericLiteral, @@ -631,13 +569,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode updateArrayLiteralExpression, createObjectLiteralExpression, updateObjectLiteralExpression, - createPropertyAccessExpression: flags & NodeFactoryFlags.NoIndentationOnFreshPropertyAccess ? - (expression, name) => setEmitFlags(createPropertyAccessExpression(expression, name), EmitFlags.NoIndentation) : - createPropertyAccessExpression, + createPropertyAccessExpression, updatePropertyAccessExpression, - createPropertyAccessChain: flags & NodeFactoryFlags.NoIndentationOnFreshPropertyAccess ? - (expression, questionDotToken, name: string) => setEmitFlags(createPropertyAccessChain(expression, questionDotToken, name), EmitFlags.NoIndentation) : - createPropertyAccessChain, + createPropertyAccessChain, updatePropertyAccessChain, createElementAccessExpression, updateElementAccessExpression, @@ -798,42 +732,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode createExternalModuleReference, updateExternalModuleReference, // lazily load factory members for JSDoc types with similar structure - get createJSDocAllType() { - return getJSDocPrimaryTypeCreateFunction(SyntaxKind.JSDocAllType); - }, - get createJSDocUnknownType() { - return getJSDocPrimaryTypeCreateFunction(SyntaxKind.JSDocUnknownType); - }, - get createJSDocNonNullableType() { - return getJSDocPrePostfixUnaryTypeCreateFunction(SyntaxKind.JSDocNonNullableType); - }, - get updateJSDocNonNullableType() { - return getJSDocPrePostfixUnaryTypeUpdateFunction(SyntaxKind.JSDocNonNullableType); - }, - get createJSDocNullableType() { - return getJSDocPrePostfixUnaryTypeCreateFunction(SyntaxKind.JSDocNullableType); - }, - get updateJSDocNullableType() { - return getJSDocPrePostfixUnaryTypeUpdateFunction(SyntaxKind.JSDocNullableType); - }, - get createJSDocOptionalType() { - return getJSDocUnaryTypeCreateFunction(SyntaxKind.JSDocOptionalType); - }, - get updateJSDocOptionalType() { - return getJSDocUnaryTypeUpdateFunction(SyntaxKind.JSDocOptionalType); - }, - get createJSDocVariadicType() { - return getJSDocUnaryTypeCreateFunction(SyntaxKind.JSDocVariadicType); - }, - get updateJSDocVariadicType() { - return getJSDocUnaryTypeUpdateFunction(SyntaxKind.JSDocVariadicType); - }, - get createJSDocNamepathType() { - return getJSDocUnaryTypeCreateFunction(SyntaxKind.JSDocNamepathType); - }, - get updateJSDocNamepathType() { - return getJSDocUnaryTypeUpdateFunction(SyntaxKind.JSDocNamepathType); - }, + createJSDocAllType, + createJSDocUnknownType, + createJSDocNonNullableType, + updateJSDocNonNullableType, + createJSDocNullableType, + updateJSDocNullableType, + createJSDocOptionalType, + updateJSDocOptionalType, + createJSDocVariadicType, + updateJSDocVariadicType, + createJSDocNamepathType, + updateJSDocNamepathType, createJSDocFunctionType, updateJSDocFunctionType, createJSDocTypeLiteral, @@ -872,86 +782,32 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode updateJSDocLinkCode, createJSDocLinkPlain, updateJSDocLinkPlain, - // lazily load factory members for JSDoc tags with similar structure - get createJSDocTypeTag() { - return getJSDocTypeLikeTagCreateFunction(SyntaxKind.JSDocTypeTag); - }, - get updateJSDocTypeTag() { - return getJSDocTypeLikeTagUpdateFunction(SyntaxKind.JSDocTypeTag); - }, - get createJSDocReturnTag() { - return getJSDocTypeLikeTagCreateFunction(SyntaxKind.JSDocReturnTag); - }, - get updateJSDocReturnTag() { - return getJSDocTypeLikeTagUpdateFunction(SyntaxKind.JSDocReturnTag); - }, - get createJSDocThisTag() { - return getJSDocTypeLikeTagCreateFunction(SyntaxKind.JSDocThisTag); - }, - get updateJSDocThisTag() { - return getJSDocTypeLikeTagUpdateFunction(SyntaxKind.JSDocThisTag); - }, - get createJSDocAuthorTag() { - return getJSDocSimpleTagCreateFunction(SyntaxKind.JSDocAuthorTag); - }, - get updateJSDocAuthorTag() { - return getJSDocSimpleTagUpdateFunction(SyntaxKind.JSDocAuthorTag); - }, - get createJSDocClassTag() { - return getJSDocSimpleTagCreateFunction(SyntaxKind.JSDocClassTag); - }, - get updateJSDocClassTag() { - return getJSDocSimpleTagUpdateFunction(SyntaxKind.JSDocClassTag); - }, - get createJSDocPublicTag() { - return getJSDocSimpleTagCreateFunction(SyntaxKind.JSDocPublicTag); - }, - get updateJSDocPublicTag() { - return getJSDocSimpleTagUpdateFunction(SyntaxKind.JSDocPublicTag); - }, - get createJSDocPrivateTag() { - return getJSDocSimpleTagCreateFunction(SyntaxKind.JSDocPrivateTag); - }, - get updateJSDocPrivateTag() { - return getJSDocSimpleTagUpdateFunction(SyntaxKind.JSDocPrivateTag); - }, - get createJSDocProtectedTag() { - return getJSDocSimpleTagCreateFunction(SyntaxKind.JSDocProtectedTag); - }, - get updateJSDocProtectedTag() { - return getJSDocSimpleTagUpdateFunction(SyntaxKind.JSDocProtectedTag); - }, - get createJSDocReadonlyTag() { - return getJSDocSimpleTagCreateFunction(SyntaxKind.JSDocReadonlyTag); - }, - get updateJSDocReadonlyTag() { - return getJSDocSimpleTagUpdateFunction(SyntaxKind.JSDocReadonlyTag); - }, - get createJSDocOverrideTag() { - return getJSDocSimpleTagCreateFunction(SyntaxKind.JSDocOverrideTag); - }, - get updateJSDocOverrideTag() { - return getJSDocSimpleTagUpdateFunction(SyntaxKind.JSDocOverrideTag); - }, - get createJSDocDeprecatedTag() { - return getJSDocSimpleTagCreateFunction(SyntaxKind.JSDocDeprecatedTag); - }, - get updateJSDocDeprecatedTag() { - return getJSDocSimpleTagUpdateFunction(SyntaxKind.JSDocDeprecatedTag); - }, - get createJSDocThrowsTag() { - return getJSDocTypeLikeTagCreateFunction(SyntaxKind.JSDocThrowsTag); - }, - get updateJSDocThrowsTag() { - return getJSDocTypeLikeTagUpdateFunction(SyntaxKind.JSDocThrowsTag); - }, - get createJSDocSatisfiesTag() { - return getJSDocTypeLikeTagCreateFunction(SyntaxKind.JSDocSatisfiesTag); - }, - get updateJSDocSatisfiesTag() { - return getJSDocTypeLikeTagUpdateFunction(SyntaxKind.JSDocSatisfiesTag); - }, - + createJSDocTypeTag, + updateJSDocTypeTag, + createJSDocReturnTag, + updateJSDocReturnTag, + createJSDocThisTag, + updateJSDocThisTag, + createJSDocAuthorTag, + updateJSDocAuthorTag, + createJSDocClassTag, + updateJSDocClassTag, + createJSDocPublicTag, + updateJSDocPublicTag, + createJSDocPrivateTag, + updateJSDocPrivateTag, + createJSDocProtectedTag, + updateJSDocProtectedTag, + createJSDocReadonlyTag, + updateJSDocReadonlyTag, + createJSDocOverrideTag, + updateJSDocOverrideTag, + createJSDocDeprecatedTag, + updateJSDocDeprecatedTag, + createJSDocThrowsTag, + updateJSDocThrowsTag, + createJSDocSatisfiesTag, + updateJSDocSatisfiesTag, createJSDocEnumTag, updateJSDocEnumTag, createJSDocUnknownTag, @@ -972,7 +828,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode createJsxText, updateJsxText, createJsxOpeningFragment, - createJsxJsxClosingFragment, + /** @deprecated */ createJsxJsxClosingFragment: createJsxClosingFragment, + createJsxClosingFragment, updateJsxFragment, createJsxAttribute, updateJsxAttribute, @@ -1166,62 +1023,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNodeArray(elements?: readonly T[], hasTrailingComma?: boolean): NodeArray { - if (elements === undefined || elements === emptyArray) { - elements = []; + if (elements instanceof ast.NodeArray) { + return elements; } - else if (isNodeArray(elements)) { - if (hasTrailingComma === undefined || elements.hasTrailingComma === hasTrailingComma) { - // Ensure the transform flags have been aggregated for this NodeArray - if (elements.transformFlags === undefined) { - aggregateChildrenFlags(elements as MutableNodeArray); - } - Debug.attachNodeArrayDebugInfo(elements); - return elements; - } - // This *was* a `NodeArray`, but the `hasTrailingComma` option differs. Recreate the - // array with the same elements, text range, and transform flags but with the updated - // value for `hasTrailingComma` - const array = elements.slice() as MutableNodeArray; - array.pos = elements.pos; - array.end = elements.end; - array.hasTrailingComma = hasTrailingComma; - array.transformFlags = elements.transformFlags; - Debug.attachNodeArrayDebugInfo(array); - return array; - } - - // Since the element list of a node array is typically created by starting with an empty array and - // repeatedly calling push(), the list may not have the optimal memory layout. We invoke slice() for - // small arrays (1 to 4 elements) to give the VM a chance to allocate an optimal representation. - const length = elements.length; - const array = (length >= 1 && length <= 4 ? elements.slice() : elements) as MutableNodeArray; - array.pos = -1; - array.end = -1; - array.hasTrailingComma = !!hasTrailingComma; - array.transformFlags = TransformFlags.None; - aggregateChildrenFlags(array); - Debug.attachNodeArrayDebugInfo(array); - return array; - } - - function createBaseNode(kind: T["kind"]) { - return baseFactory.createBaseNode(kind) as Mutable; - } - - function createBaseDeclaration(kind: T["kind"]) { - const node = createBaseNode(kind); - node.symbol = undefined!; // initialized by binder - node.localSymbol = undefined; // initialized by binder - return node; - } - - function finishUpdateBaseSignatureDeclaration(updated: Mutable, original: T) { - if (updated !== original) { - // copy children used for quick info - updated.typeArguments = original.typeArguments; - } - return update(updated, original); + return new ast.AstNodeArray(elements?.map(element => (element as Node as ast.Node).ast) ?? [], hasTrailingComma).nodes as readonly Node[] as NodeArray; } // @@ -1230,50 +1036,29 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNumericLiteral(value: string | number, numericLiteralFlags: TokenFlags = TokenFlags.None): NumericLiteral { - const text = typeof value === "number" ? value + "" : value; - Debug.assert(text.charCodeAt(0) !== CharacterCodes.minus, "Negative numbers should be created in combination with createPrefixUnaryExpression"); - const node = createBaseDeclaration(SyntaxKind.NumericLiteral); - node.text = text; - node.numericLiteralFlags = numericLiteralFlags; - if (numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier) node.transformFlags |= TransformFlags.ContainsES2015; - return node; + return astFactory.createNumericLiteral(value, numericLiteralFlags).node; } // @api function createBigIntLiteral(value: string | PseudoBigInt): BigIntLiteral { - const node = createBaseToken(SyntaxKind.BigIntLiteral); - node.text = typeof value === "string" ? value : pseudoBigIntToString(value) + "n"; - node.transformFlags |= TransformFlags.ContainsES2020; - return node; - } - - function createBaseStringLiteral(text: string, isSingleQuote?: boolean) { - const node = createBaseDeclaration(SyntaxKind.StringLiteral); - node.text = text; - node.singleQuote = isSingleQuote; - return node; + return astFactory.createBigIntLiteral(value).node; } // @api function createStringLiteral(text: string, isSingleQuote?: boolean, hasExtendedUnicodeEscape?: boolean): StringLiteral { - const node = createBaseStringLiteral(text, isSingleQuote); - node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape; - if (hasExtendedUnicodeEscape) node.transformFlags |= TransformFlags.ContainsES2015; - return node; + return astFactory.createStringLiteral(text, isSingleQuote, hasExtendedUnicodeEscape).node; } // @api function createStringLiteralFromNode(sourceNode: PropertyNameLiteral | PrivateIdentifier): StringLiteral { - const node = createBaseStringLiteral(getTextOfIdentifierOrLiteral(sourceNode), /*isSingleQuote*/ undefined); - node.textSourceNode = sourceNode; + const node = astFactory.createStringLiteral(getTextOfIdentifierOrLiteral(sourceNode), /*isSingleQuote*/ undefined).node; + node.textSourceNode = sourceNode as ast.PropertyNameLiteral | ast.PrivateIdentifier; return node; } // @api function createRegularExpressionLiteral(text: string): RegularExpressionLiteral { - const node = createBaseToken(SyntaxKind.RegularExpressionLiteral); - node.text = text; - return node; + return astFactory.createRegularExpressionLiteral(text).node; } // @api @@ -1300,55 +1085,28 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // Identifiers // - function createBaseIdentifier(escapedText: __String) { - const node = baseFactory.createBaseIdentifierNode(SyntaxKind.Identifier) as Mutable; - node.escapedText = escapedText; - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - node.symbol = undefined!; // initialized by checker - return node; + // @api + function createIdentifier(text: string, _originalKeywordKind?: SyntaxKind, hasExtendedUnicodeEscape?: boolean): Identifier { + return astFactory.createIdentifier(text, hasExtendedUnicodeEscape).node; } - function createBaseGeneratedIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags, prefix: string | GeneratedNamePart | undefined, suffix: string | undefined) { - const node = createBaseIdentifier(escapeLeadingUnderscores(text)) as Mutable; - setIdentifierAutoGenerate(node, { + function createGeneratedIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags, prefix: string | GeneratedNamePart | undefined, suffix: string | undefined) { + const astNode = astFactory.createIdentifier(text); + setIdentifierAutoGenerate(astNode, { flags: autoGenerateFlags, id: nextAutoGenerateId, prefix, suffix, }); nextAutoGenerateId++; - return node; - } - - // @api - function createIdentifier(text: string, originalKeywordKind?: SyntaxKind, hasExtendedUnicodeEscape?: boolean): Identifier { - if (originalKeywordKind === undefined && text) { - originalKeywordKind = stringToToken(text); - } - if (originalKeywordKind === SyntaxKind.Identifier) { - originalKeywordKind = undefined; - } - - const node = createBaseIdentifier(escapeLeadingUnderscores(text)); - if (hasExtendedUnicodeEscape) node.flags |= NodeFlags.IdentifierHasExtendedUnicodeEscape; - - // NOTE: we do not include transform flags of typeArguments in an identifier as they do not contribute to transformations - if (node.escapedText === "await") { - node.transformFlags |= TransformFlags.ContainsPossibleTopLevelAwait; - } - if (node.flags & NodeFlags.IdentifierHasExtendedUnicodeEscape) { - node.transformFlags |= TransformFlags.ContainsES2015; - } - - return node; + return astNode.node as GeneratedIdentifier; } // @api function createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined, reservedInNestedScopes?: boolean, prefix?: string | GeneratedNamePart, suffix?: string): GeneratedIdentifier { let flags = GeneratedIdentifierFlags.Auto; if (reservedInNestedScopes) flags |= GeneratedIdentifierFlags.ReservedInNestedScopes; - const name = createBaseGeneratedIdentifier("", flags, prefix, suffix); + const name = createGeneratedIdentifier("", flags, prefix, suffix); if (recordTempVariable) { recordTempVariable(name); } @@ -1360,7 +1118,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createLoopVariable(reservedInNestedScopes?: boolean): Identifier { let flags = GeneratedIdentifierFlags.Loop; if (reservedInNestedScopes) flags |= GeneratedIdentifierFlags.ReservedInNestedScopes; - return createBaseGeneratedIdentifier("", flags, /*prefix*/ undefined, /*suffix*/ undefined); + return createGeneratedIdentifier("", flags, /*prefix*/ undefined, /*suffix*/ undefined); } /** Create a unique name based on the supplied text. */ @@ -1368,7 +1126,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createUniqueName(text: string, flags: GeneratedIdentifierFlags = GeneratedIdentifierFlags.None, prefix?: string | GeneratedNamePart, suffix?: string): Identifier { Debug.assert(!(flags & GeneratedIdentifierFlags.KindMask), "Argument out of range: flags"); Debug.assert((flags & (GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.FileLevel)) !== GeneratedIdentifierFlags.FileLevel, "GeneratedIdentifierFlags.FileLevel cannot be set without also setting GeneratedIdentifierFlags.Optimistic"); - return createBaseGeneratedIdentifier(text, GeneratedIdentifierFlags.Unique | flags, prefix, suffix); + return createGeneratedIdentifier(text, GeneratedIdentifierFlags.Unique | flags, prefix, suffix); } /** Create a unique name generated for a node. */ @@ -1379,34 +1137,26 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode isMemberName(node) ? formatGeneratedName(/*privateName*/ false, prefix, node, suffix, idText) : `generated@${getNodeId(node)}`; if (prefix || suffix) flags |= GeneratedIdentifierFlags.Optimistic; - const name = createBaseGeneratedIdentifier(text, GeneratedIdentifierFlags.Node | flags, prefix, suffix); + const name = createGeneratedIdentifier(text, GeneratedIdentifierFlags.Node | flags, prefix, suffix); name.original = node; return name; } - function createBasePrivateIdentifier(escapedText: __String) { - const node = baseFactory.createBasePrivateIdentifierNode(SyntaxKind.PrivateIdentifier) as Mutable; - node.escapedText = escapedText; - node.transformFlags |= TransformFlags.ContainsClassFields; - return node; - } - // @api function createPrivateIdentifier(text: string): PrivateIdentifier { - if (!startsWith(text, "#")) Debug.fail("First character of private identifier must be #: " + text); - return createBasePrivateIdentifier(escapeLeadingUnderscores(text)); + return astFactory.createPrivateIdentifier(text).node; } - function createBaseGeneratedPrivateIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags, prefix: string | GeneratedNamePart | undefined, suffix: string | undefined) { - const node = createBasePrivateIdentifier(escapeLeadingUnderscores(text)); - setIdentifierAutoGenerate(node, { + function createGeneratedPrivateIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags, prefix: string | GeneratedNamePart | undefined, suffix: string | undefined) { + const astNode = astFactory.createPrivateIdentifier(text); + setIdentifierAutoGenerate(astNode, { flags: autoGenerateFlags, id: nextAutoGenerateId, prefix, suffix, }); nextAutoGenerateId++; - return node; + return astNode.node as GeneratedPrivateIdentifier; } /** Create a unique name based on the supplied text. */ @@ -1415,7 +1165,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode if (text && !startsWith(text, "#")) Debug.fail("First character of private identifier must be #: " + text); const autoGenerateFlags = GeneratedIdentifierFlags.ReservedInNestedScopes | (text ? GeneratedIdentifierFlags.Unique : GeneratedIdentifierFlags.Auto); - return createBaseGeneratedPrivateIdentifier(text ?? "", autoGenerateFlags, prefix, suffix); + return createGeneratedPrivateIdentifier(text ?? "", autoGenerateFlags, prefix, suffix); } // @api @@ -1423,7 +1173,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const text = isMemberName(node) ? formatGeneratedName(/*privateName*/ true, prefix, node, suffix, idText) : `#generated@${getNodeId(node)}`; const flags = prefix || suffix ? GeneratedIdentifierFlags.Optimistic : GeneratedIdentifierFlags.None; - const name = createBaseGeneratedPrivateIdentifier(text, GeneratedIdentifierFlags.Node | flags, prefix, suffix); + const name = createGeneratedPrivateIdentifier(text, GeneratedIdentifierFlags.Node | flags, prefix, suffix); name.original = node; return name; } @@ -1432,10 +1182,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // Punctuation // - function createBaseToken(kind: T["kind"]) { - return baseFactory.createBaseTokenNode(kind) as Mutable; - } - // @api function createToken(token: SyntaxKind.SuperKeyword): SuperExpression; function createToken(token: SyntaxKind.ThisKeyword): ThisExpression; @@ -1448,68 +1194,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createToken(token: TKind): KeywordTypeNode; function createToken(token: TKind): ModifierToken; function createToken(token: TKind): KeywordToken; - function createToken(token: TKind): Token; - function createToken(token: TKind) { - Debug.assert(token >= SyntaxKind.FirstToken && token <= SyntaxKind.LastToken, "Invalid token"); - Debug.assert(token <= SyntaxKind.FirstTemplateToken || token >= SyntaxKind.LastTemplateToken, "Invalid token. Use 'createTemplateLiteralLikeNode' to create template literals."); - Debug.assert(token <= SyntaxKind.FirstLiteralToken || token >= SyntaxKind.LastLiteralToken, "Invalid token. Use 'createLiteralLikeNode' to create literals."); - Debug.assert(token !== SyntaxKind.Identifier, "Invalid token. Use 'createIdentifier' to create identifiers"); - const node = createBaseToken>(token); - let transformFlags = TransformFlags.None; - switch (token) { - case SyntaxKind.AsyncKeyword: - // 'async' modifier is ES2017 (async functions) or ES2018 (async generators) - transformFlags = TransformFlags.ContainsES2017 | - TransformFlags.ContainsES2018; - break; - - case SyntaxKind.UsingKeyword: - transformFlags = TransformFlags.ContainsESNext; - break; - - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - case SyntaxKind.ReadonlyKeyword: - case SyntaxKind.AbstractKeyword: - case SyntaxKind.DeclareKeyword: - case SyntaxKind.ConstKeyword: - case SyntaxKind.AnyKeyword: - case SyntaxKind.NumberKeyword: - case SyntaxKind.BigIntKeyword: - case SyntaxKind.NeverKeyword: - case SyntaxKind.ObjectKeyword: - case SyntaxKind.InKeyword: - case SyntaxKind.OutKeyword: - case SyntaxKind.OverrideKeyword: - case SyntaxKind.StringKeyword: - case SyntaxKind.BooleanKeyword: - case SyntaxKind.SymbolKeyword: - case SyntaxKind.VoidKeyword: - case SyntaxKind.UnknownKeyword: - case SyntaxKind.UndefinedKeyword: // `undefined` is an Identifier in the expression case. - transformFlags = TransformFlags.ContainsTypeScript; - break; - case SyntaxKind.SuperKeyword: - transformFlags = TransformFlags.ContainsES2015 | TransformFlags.ContainsLexicalSuper; - (node as Mutable> as Mutable).flowNode = undefined; // initialized by binder (FlowContainer) - break; - case SyntaxKind.StaticKeyword: - transformFlags = TransformFlags.ContainsES2015; - break; - case SyntaxKind.AccessorKeyword: - transformFlags = TransformFlags.ContainsClassFields; - break; - case SyntaxKind.ThisKeyword: - // 'this' indicates a lexical 'this' - transformFlags = TransformFlags.ContainsLexicalThis; - (node as Mutable> as Mutable).flowNode = undefined; // initialized by binder (FlowContainer) - break; - } - if (transformFlags) { - node.transformFlags |= transformFlags; - } - return node; + function createToken(token: TKind): Token; + function createToken(token: TKind): Token { + return astFactory.createToken(token).node; } // @@ -1576,40 +1263,23 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // // @api - function createQualifiedName(left: EntityName, right: string | Identifier) { - const node = createBaseNode(SyntaxKind.QualifiedName); - node.left = left; - node.right = asName(right); - node.transformFlags |= propagateChildFlags(node.left) | - propagateIdentifierNameFlags(node.right); - - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createQualifiedName(left: EntityName, right: string | Identifier): QualifiedName { + return astFactory.createQualifiedName(asNode(left).ast, typeof right === "string" ? right : asNode(right).ast).node; } // @api - function updateQualifiedName(node: QualifiedName, left: EntityName, right: Identifier) { - return node.left !== left - || node.right !== right - ? update(createQualifiedName(left, right), node) - : node; + function updateQualifiedName(node: QualifiedName, left: EntityName, right: Identifier): QualifiedName { + return astFactory.updateQualifiedName(asNode(node).ast, asNode(left).ast, asNode(right).ast).node; } // @api - function createComputedPropertyName(expression: Expression) { - const node = createBaseNode(SyntaxKind.ComputedPropertyName); - node.expression = parenthesizerRules().parenthesizeExpressionOfComputedPropertyName(expression); - node.transformFlags |= propagateChildFlags(node.expression) | - TransformFlags.ContainsES2015 | - TransformFlags.ContainsComputedPropertyName; - return node; + function createComputedPropertyName(expression: Expression): ComputedPropertyName { + return astFactory.createComputedPropertyName(asNode(expression).ast).node; } // @api - function updateComputedPropertyName(node: ComputedPropertyName, expression: Expression) { - return node.expression !== expression - ? update(createComputedPropertyName(expression), node) - : node; + function updateComputedPropertyName(node: ComputedPropertyName, expression: Expression): ComputedPropertyName { + return astFactory.updateComputedPropertyName(asNode(node).ast, asNode(expression).ast).node; } // @@ -1618,26 +1288,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeParameterDeclaration(modifiers: readonly Modifier[] | undefined, name: string | Identifier, constraint?: TypeNode, defaultType?: TypeNode): TypeParameterDeclaration { - const node = createBaseDeclaration(SyntaxKind.TypeParameter); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.constraint = constraint; - node.default = defaultType; - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.expression = undefined; // initialized by parser to report grammar errors - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + return astFactory.createTypeParameterDeclaration(asNodeArray(modifiers)?.ast, asName(name).ast, asNode(constraint)?.ast, asNode(defaultType)?.ast).node; } // @api function updateTypeParameterDeclaration(node: TypeParameterDeclaration, modifiers: readonly Modifier[] | undefined, name: Identifier, constraint: TypeNode | undefined, defaultType: TypeNode | undefined): TypeParameterDeclaration { - return node.modifiers !== modifiers - || node.name !== name - || node.constraint !== constraint - || node.default !== defaultType - ? update(createTypeParameterDeclaration(modifiers, name, constraint, defaultType), node) - : node; + return astFactory.updateTypeParameterDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNode(constraint)?.ast, asNode(defaultType)?.ast).node; } // @api @@ -1648,31 +1304,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionToken?: QuestionToken, type?: TypeNode, initializer?: Expression, - ) { - const node = createBaseDeclaration(SyntaxKind.Parameter); - node.modifiers = asNodeArray(modifiers); - node.dotDotDotToken = dotDotDotToken; - node.name = asName(name); - node.questionToken = questionToken; - node.type = type; - node.initializer = asInitializer(initializer); - - if (isThisIdentifier(node.name)) { - node.transformFlags = TransformFlags.ContainsTypeScript; - } - else { - node.transformFlags = propagateChildrenFlags(node.modifiers) | - propagateChildFlags(node.dotDotDotToken) | - propagateNameFlags(node.name) | - propagateChildFlags(node.questionToken) | - propagateChildFlags(node.initializer) | - (node.questionToken ?? node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | - (node.dotDotDotToken ?? node.initializer ? TransformFlags.ContainsES2015 : TransformFlags.None) | - (modifiersToFlags(node.modifiers) & ModifierFlags.ParameterPropertyModifier ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None); - } - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + ): ParameterDeclaration { + // NOTE: JSDoc parameters don't have names and we currently passed `undefined!` + return astFactory.createParameterDeclaration(asNodeArray(modifiers)?.ast, asNode(dotDotDotToken)?.ast, asName(name)?.ast, asNode(questionToken)?.ast, asNode(type)?.ast, asNode(initializer)?.ast).node; } // @api @@ -1684,33 +1318,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined, - ) { - return node.modifiers !== modifiers - || node.dotDotDotToken !== dotDotDotToken - || node.name !== name - || node.questionToken !== questionToken - || node.type !== type - || node.initializer !== initializer - ? update(createParameterDeclaration(modifiers, dotDotDotToken, name, questionToken, type, initializer), node) - : node; - } - - // @api - function createDecorator(expression: Expression) { - const node = createBaseNode(SyntaxKind.Decorator); - node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); - node.transformFlags |= propagateChildFlags(node.expression) | - TransformFlags.ContainsTypeScript | - TransformFlags.ContainsTypeScriptClassSyntax | - TransformFlags.ContainsDecorators; - return node; + ): ParameterDeclaration { + return astFactory.updateParameterDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(dotDotDotToken)?.ast, asName(name)?.ast, asNode(questionToken)?.ast, asNode(type)?.ast, asNode(initializer)?.ast).node; } // @api - function updateDecorator(node: Decorator, expression: Expression) { - return node.expression !== expression - ? update(createDecorator(expression), node) - : node; + function createDecorator(expression: Expression): Decorator { + return astFactory.createDecorator(asNode(expression).ast).node; + } + + // @api + function updateDecorator(node: Decorator, expression: Expression): Decorator { + return astFactory.updateDecorator((node as ast.Decorator).ast, asNode(expression).ast).node; } // @@ -1724,16 +1343,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionToken: QuestionToken | undefined, type: TypeNode | undefined, ): PropertySignature { - const node = createBaseDeclaration(SyntaxKind.PropertySignature); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.type = type; - node.questionToken = questionToken; - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.initializer = undefined; // initialized by parser to report grammar errors - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + return astFactory.createPropertySignature(asNodeArray(modifiers)?.ast, asName(name).ast, asNode(questionToken)?.ast, asNode(type)?.ast).node; } // @api @@ -1743,21 +1353,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: PropertyName, questionToken: QuestionToken | undefined, type: TypeNode | undefined, - ) { - return node.modifiers !== modifiers - || node.name !== name - || node.questionToken !== questionToken - || node.type !== type - ? finishUpdatePropertySignature(createPropertySignature(modifiers, name, questionToken, type), node) - : node; - } - - function finishUpdatePropertySignature(updated: Mutable, original: PropertySignature) { - if (updated !== original) { - // copy children used only for error reporting - updated.initializer = original.initializer; - } - return update(updated, original); + ): PropertySignature { + return astFactory.updatePropertySignature(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNode(questionToken)?.ast, asNode(type)?.ast).node; } // @api @@ -1767,26 +1364,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionOrExclamationToken: QuestionToken | ExclamationToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined, - ) { - const node = createBaseDeclaration(SyntaxKind.PropertyDeclaration); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.questionToken = questionOrExclamationToken && isQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined; - node.exclamationToken = questionOrExclamationToken && isExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined; - node.type = type; - node.initializer = asInitializer(initializer); - - const isAmbient = node.flags & NodeFlags.Ambient || modifiersToFlags(node.modifiers) & ModifierFlags.Ambient; - - node.transformFlags = propagateChildrenFlags(node.modifiers) | - propagateNameFlags(node.name) | - propagateChildFlags(node.initializer) | - (isAmbient || node.questionToken || node.exclamationToken || node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | - (isComputedPropertyName(node.name) || modifiersToFlags(node.modifiers) & ModifierFlags.Static && node.initializer ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None) | - TransformFlags.ContainsClassFields; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + ): PropertyDeclaration { + return astFactory.createPropertyDeclaration(asNodeArray(modifiers)?.ast, asName(name).ast, asNode(questionOrExclamationToken)?.ast, asNode(type)?.ast, asNode(initializer)?.ast).node; } // @api @@ -1797,15 +1376,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionOrExclamationToken: QuestionToken | ExclamationToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined, - ) { - return node.modifiers !== modifiers - || node.name !== name - || node.questionToken !== (questionOrExclamationToken !== undefined && isQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined) - || node.exclamationToken !== (questionOrExclamationToken !== undefined && isExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined) - || node.type !== type - || node.initializer !== initializer - ? update(createPropertyDeclaration(modifiers, name, questionOrExclamationToken, type, initializer), node) - : node; + ): PropertyDeclaration { + return astFactory.updatePropertyDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asName(name).ast, asNode(questionOrExclamationToken)?.ast, asNode(type)?.ast, asNode(initializer)?.ast).node; } // @api @@ -1816,21 +1388,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: readonly TypeParameterDeclaration[] | undefined, parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, - ) { - const node = createBaseDeclaration(SyntaxKind.MethodSignature); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.questionToken = questionToken; - node.typeParameters = asNodeArray(typeParameters); - node.parameters = asNodeArray(parameters); - node.type = type; - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.typeArguments = undefined; // used in quick info - return node; + ): MethodSignature { + return astFactory.createMethodSignature(asNodeArray(modifiers)?.ast, asName(name).ast, asNode(questionToken)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; } // @api @@ -1842,15 +1401,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: NodeArray | undefined, parameters: NodeArray, type: TypeNode | undefined, - ) { - return node.modifiers !== modifiers - || node.name !== name - || node.questionToken !== questionToken - || node.typeParameters !== typeParameters - || node.parameters !== parameters - || node.type !== type - ? finishUpdateBaseSignatureDeclaration(createMethodSignature(modifiers, name, questionToken, typeParameters, parameters, type), node) - : node; + ): MethodSignature { + return astFactory.updateMethodSignature(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNode(questionToken)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; } // @api @@ -1863,50 +1415,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, body: Block | undefined, - ) { - const node = createBaseDeclaration(SyntaxKind.MethodDeclaration); - node.modifiers = asNodeArray(modifiers); - node.asteriskToken = asteriskToken; - node.name = asName(name); - node.questionToken = questionToken; - node.exclamationToken = undefined; // initialized by parser for grammar errors - node.typeParameters = asNodeArray(typeParameters); - node.parameters = createNodeArray(parameters); - node.type = type; - node.body = body; - - if (!node.body) { - node.transformFlags = TransformFlags.ContainsTypeScript; - } - else { - const isAsync = modifiersToFlags(node.modifiers) & ModifierFlags.Async; - const isGenerator = !!node.asteriskToken; - const isAsyncGenerator = isAsync && isGenerator; - - node.transformFlags = propagateChildrenFlags(node.modifiers) | - propagateChildFlags(node.asteriskToken) | - propagateNameFlags(node.name) | - propagateChildFlags(node.questionToken) | - propagateChildrenFlags(node.typeParameters) | - propagateChildrenFlags(node.parameters) | - propagateChildFlags(node.type) | - (propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | - (isAsyncGenerator ? TransformFlags.ContainsES2018 : - isAsync ? TransformFlags.ContainsES2017 : - isGenerator ? TransformFlags.ContainsGenerator : - TransformFlags.None) | - (node.questionToken || node.typeParameters || node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | - TransformFlags.ContainsES2015; - } - - node.typeArguments = undefined; // used in quick info - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - node.endFlowNode = undefined; - node.returnFlowNode = undefined; - return node; + ): MethodDeclaration { + return astFactory.createMethodDeclaration(asNodeArray(modifiers)?.ast, asNode(asteriskToken)?.ast, asName(name).ast, asNode(questionToken)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body)?.ast).node; } // @api @@ -1920,42 +1430,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, body: Block | undefined, - ) { - return node.modifiers !== modifiers - || node.asteriskToken !== asteriskToken - || node.name !== name - || node.questionToken !== questionToken - || node.typeParameters !== typeParameters - || node.parameters !== parameters - || node.type !== type - || node.body !== body - ? finishUpdateMethodDeclaration(createMethodDeclaration(modifiers, asteriskToken, name, questionToken, typeParameters, parameters, type, body), node) - : node; - } - - function finishUpdateMethodDeclaration(updated: Mutable, original: MethodDeclaration) { - if (updated !== original) { - // copy children used only for error reporting - updated.exclamationToken = original.exclamationToken; - } - return update(updated, original); + ): MethodDeclaration { + return astFactory.updateMethodDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(asteriskToken)?.ast, asNode(name).ast, asNode(questionToken)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body)?.ast).node; } // @api function createClassStaticBlockDeclaration( body: Block, ): ClassStaticBlockDeclaration { - const node = createBaseDeclaration(SyntaxKind.ClassStaticBlockDeclaration); - node.body = body; - node.transformFlags = propagateChildFlags(body) | TransformFlags.ContainsClassFields; - - node.modifiers = undefined; // initialized by parser for grammar errors - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.endFlowNode = undefined; - node.returnFlowNode = undefined; - return node; + return astFactory.createClassStaticBlockDeclaration(asNode(body).ast).node; } // @api @@ -1963,17 +1446,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node: ClassStaticBlockDeclaration, body: Block, ): ClassStaticBlockDeclaration { - return node.body !== body - ? finishUpdateClassStaticBlockDeclaration(createClassStaticBlockDeclaration(body), node) - : node; - } - - function finishUpdateClassStaticBlockDeclaration(updated: Mutable, original: ClassStaticBlockDeclaration) { - if (updated !== original) { - // copy children used only for error reporting - updated.modifiers = original.modifiers; - } - return update(updated, original); + return astFactory.updateClassStaticBlockDeclaration(asNode(node).ast, asNode(body).ast).node; } // @api @@ -1981,31 +1454,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode modifiers: readonly ModifierLike[] | undefined, parameters: readonly ParameterDeclaration[], body: Block | undefined, - ) { - const node = createBaseDeclaration(SyntaxKind.Constructor); - node.modifiers = asNodeArray(modifiers); - node.parameters = createNodeArray(parameters); - node.body = body; - - if (!node.body) { - node.transformFlags = TransformFlags.ContainsTypeScript; - } - else { - node.transformFlags = propagateChildrenFlags(node.modifiers) | - propagateChildrenFlags(node.parameters) | - (propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | - TransformFlags.ContainsES2015; - } - - node.typeParameters = undefined; // initialized by parser for grammar errors - node.type = undefined; // initialized by parser for grammar errors - node.typeArguments = undefined; // used in quick info - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.endFlowNode = undefined; - node.returnFlowNode = undefined; - return node; + ): ConstructorDeclaration { + return astFactory.createConstructorDeclaration(asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, asNode(body)?.ast).node; } // @api @@ -2014,20 +1464,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode modifiers: readonly ModifierLike[] | undefined, parameters: readonly ParameterDeclaration[], body: Block | undefined, - ) { - return node.modifiers !== modifiers - || node.parameters !== parameters - || node.body !== body - ? finishUpdateConstructorDeclaration(createConstructorDeclaration(modifiers, parameters, body), node) - : node; - } - - function finishUpdateConstructorDeclaration(updated: Mutable, original: ConstructorDeclaration) { - if (updated !== original) { - updated.typeParameters = original.typeParameters; - updated.type = original.type; - } - return finishUpdateBaseSignatureDeclaration(updated, original); + ): ConstructorDeclaration { + return astFactory.updateConstructorDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, asNode(body)?.ast).node; } // @api @@ -2037,35 +1475,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, body: Block | undefined, - ) { - const node = createBaseDeclaration(SyntaxKind.GetAccessor); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.parameters = createNodeArray(parameters); - node.type = type; - node.body = body; - - if (!node.body) { - node.transformFlags = TransformFlags.ContainsTypeScript; - } - else { - node.transformFlags = propagateChildrenFlags(node.modifiers) | - propagateNameFlags(node.name) | - propagateChildrenFlags(node.parameters) | - propagateChildFlags(node.type) | - (propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | - (node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); - } - - node.typeArguments = undefined; // used in quick info - node.typeParameters = undefined; // initialized by parser for grammar errors - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - node.endFlowNode = undefined; - node.returnFlowNode = undefined; - return node; + ): GetAccessorDeclaration { + return astFactory.createGetAccessorDeclaration(asNodeArray(modifiers)?.ast, asName(name)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body)?.ast).node; } // @api @@ -2076,22 +1487,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, body: Block | undefined, - ) { - return node.modifiers !== modifiers - || node.name !== name - || node.parameters !== parameters - || node.type !== type - || node.body !== body - ? finishUpdateGetAccessorDeclaration(createGetAccessorDeclaration(modifiers, name, parameters, type, body), node) - : node; - } - - function finishUpdateGetAccessorDeclaration(updated: Mutable, original: GetAccessorDeclaration) { - if (updated !== original) { - // copy children used only for error reporting - updated.typeParameters = original.typeParameters; - } - return finishUpdateBaseSignatureDeclaration(updated, original); + ): GetAccessorDeclaration { + return astFactory.updateGetAccessorDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body)?.ast).node; } // @api @@ -2100,34 +1497,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: string | PropertyName, parameters: readonly ParameterDeclaration[], body: Block | undefined, - ) { - const node = createBaseDeclaration(SyntaxKind.SetAccessor); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.parameters = createNodeArray(parameters); - node.body = body; - - if (!node.body) { - node.transformFlags = TransformFlags.ContainsTypeScript; - } - else { - node.transformFlags = propagateChildrenFlags(node.modifiers) | - propagateNameFlags(node.name) | - propagateChildrenFlags(node.parameters) | - (propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | - (node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); - } - - node.typeArguments = undefined; // used in quick info - node.typeParameters = undefined; // initialized by parser for grammar errors - node.type = undefined; // initialized by parser for grammar errors - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - node.endFlowNode = undefined; - node.returnFlowNode = undefined; - return node; + ): SetAccessorDeclaration { + return astFactory.createSetAccessorDeclaration(asNodeArray(modifiers)?.ast, asName(name)?.ast, asNodeArray(parameters).ast, asNode(body)?.ast).node; } // @api @@ -2137,22 +1508,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: PropertyName, parameters: readonly ParameterDeclaration[], body: Block | undefined, - ) { - return node.modifiers !== modifiers - || node.name !== name - || node.parameters !== parameters - || node.body !== body - ? finishUpdateSetAccessorDeclaration(createSetAccessorDeclaration(modifiers, name, parameters, body), node) - : node; - } - - function finishUpdateSetAccessorDeclaration(updated: Mutable, original: SetAccessorDeclaration) { - if (updated !== original) { - // copy children used only for error reporting - updated.typeParameters = original.typeParameters; - updated.type = original.type; - } - return finishUpdateBaseSignatureDeclaration(updated, original); + ): SetAccessorDeclaration { + return astFactory.updateSetAccessorDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNodeArray(parameters).ast, asNode(body)?.ast).node; } // @api @@ -2161,17 +1518,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, ): CallSignatureDeclaration { - const node = createBaseDeclaration(SyntaxKind.CallSignature); - node.typeParameters = asNodeArray(typeParameters); - node.parameters = asNodeArray(parameters); - node.type = type; - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.typeArguments = undefined; // used in quick info - return node; + return astFactory.createCallSignature(asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; } // @api @@ -2180,12 +1527,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: NodeArray | undefined, parameters: NodeArray, type: TypeNode | undefined, - ) { - return node.typeParameters !== typeParameters - || node.parameters !== parameters - || node.type !== type - ? finishUpdateBaseSignatureDeclaration(createCallSignature(typeParameters, parameters, type), node) - : node; + ): CallSignatureDeclaration { + return astFactory.updateCallSignature(asNode(node).ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; } // @api @@ -2194,17 +1537,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, ): ConstructSignatureDeclaration { - const node = createBaseDeclaration(SyntaxKind.ConstructSignature); - node.typeParameters = asNodeArray(typeParameters); - node.parameters = asNodeArray(parameters); - node.type = type; - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.typeArguments = undefined; // used in quick info - return node; + return astFactory.createConstructSignature(asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; } // @api @@ -2213,12 +1546,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: NodeArray | undefined, parameters: NodeArray, type: TypeNode | undefined, - ) { - return node.typeParameters !== typeParameters - || node.parameters !== parameters - || node.type !== type - ? finishUpdateBaseSignatureDeclaration(createConstructSignature(typeParameters, parameters, type), node) - : node; + ): ConstructSignatureDeclaration { + return astFactory.updateConstructSignature(asNode(node).ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; } // @api @@ -2227,17 +1556,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, ): IndexSignatureDeclaration { - const node = createBaseDeclaration(SyntaxKind.IndexSignature); - node.modifiers = asNodeArray(modifiers); - node.parameters = asNodeArray(parameters); - node.type = type!; // TODO(rbuckton): We mark this as required in IndexSignatureDeclaration, but it looks like the parser allows it to be elided. - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.typeArguments = undefined; // used in quick info - return node; + return astFactory.createIndexSignature(asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node } // @api @@ -2246,29 +1565,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode modifiers: readonly ModifierLike[] | undefined, parameters: readonly ParameterDeclaration[], type: TypeNode, - ) { - return node.parameters !== parameters - || node.type !== type - || node.modifiers !== modifiers - ? finishUpdateBaseSignatureDeclaration(createIndexSignature(modifiers, parameters, type), node) - : node; + ): IndexSignatureDeclaration { + return astFactory.updateIndexSignature(asNode(node).ast, asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, asNode(type).ast).node; } // @api - function createTemplateLiteralTypeSpan(type: TypeNode, literal: TemplateMiddle | TemplateTail) { - const node = createBaseNode(SyntaxKind.TemplateLiteralTypeSpan); - node.type = type; - node.literal = literal; - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createTemplateLiteralTypeSpan(type: TypeNode, literal: TemplateMiddle | TemplateTail): TemplateLiteralTypeSpan { + return astFactory.createTemplateLiteralTypeSpan(asNode(type).ast, asNode(literal).ast).node; } // @api - function updateTemplateLiteralTypeSpan(node: TemplateLiteralTypeSpan, type: TypeNode, literal: TemplateMiddle | TemplateTail) { - return node.type !== type - || node.literal !== literal - ? update(createTemplateLiteralTypeSpan(type, literal), node) - : node; + function updateTemplateLiteralTypeSpan(node: TemplateLiteralTypeSpan, type: TypeNode, literal: TemplateMiddle | TemplateTail): TemplateLiteralTypeSpan { + return astFactory.updateTemplateLiteralTypeSpan(asNode(node).ast, asNode(type).ast, asNode(literal).ast).node; } // @@ -2281,39 +1589,23 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function createTypePredicateNode(assertsModifier: AssertsKeyword | undefined, parameterName: Identifier | ThisTypeNode | string, type: TypeNode | undefined) { - const node = createBaseNode(SyntaxKind.TypePredicate); - node.assertsModifier = assertsModifier; - node.parameterName = asName(parameterName); - node.type = type; - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createTypePredicateNode(assertsModifier: AssertsKeyword | undefined, parameterName: Identifier | ThisTypeNode | string, type: TypeNode | undefined): TypePredicateNode { + return astFactory.createTypePredicateNode(asNode(assertsModifier)?.ast, asName(parameterName).ast, asNode(type)?.ast).node; } // @api - function updateTypePredicateNode(node: TypePredicateNode, assertsModifier: AssertsKeyword | undefined, parameterName: Identifier | ThisTypeNode, type: TypeNode | undefined) { - return node.assertsModifier !== assertsModifier - || node.parameterName !== parameterName - || node.type !== type - ? update(createTypePredicateNode(assertsModifier, parameterName, type), node) - : node; + function updateTypePredicateNode(node: TypePredicateNode, assertsModifier: AssertsKeyword | undefined, parameterName: Identifier | ThisTypeNode, type: TypeNode | undefined): TypePredicateNode { + return astFactory.updateTypePredicateNode(asNode(node).ast, asNode(assertsModifier)?.ast, asName(parameterName).ast, asNode(type)?.ast).node; } // @api - function createTypeReferenceNode(typeName: string | EntityName, typeArguments: readonly TypeNode[] | undefined) { - const node = createBaseNode(SyntaxKind.TypeReference); - node.typeName = asName(typeName); - node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(createNodeArray(typeArguments)); - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createTypeReferenceNode(typeName: string | EntityName, typeArguments: readonly TypeNode[] | undefined): TypeReferenceNode { + return astFactory.createTypeReferenceNode(asName(typeName).ast, asNodeArray(typeArguments)?.ast).node; } // @api - function updateTypeReferenceNode(node: TypeReferenceNode, typeName: EntityName, typeArguments: NodeArray | undefined) { - return node.typeName !== typeName - || node.typeArguments !== typeArguments - ? update(createTypeReferenceNode(typeName, typeArguments), node) - : node; + function updateTypeReferenceNode(node: TypeReferenceNode, typeName: EntityName, typeArguments: NodeArray | undefined): TypeReferenceNode { + return astFactory.updateTypeReferenceNode(asNode(node).ast, asNode(typeName).ast, asNodeArray(typeArguments)?.ast).node; } // @api @@ -2322,18 +1614,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[], type: TypeNode, ): FunctionTypeNode { - const node = createBaseDeclaration(SyntaxKind.FunctionType); - node.typeParameters = asNodeArray(typeParameters); - node.parameters = asNodeArray(parameters); - node.type = type; - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.modifiers = undefined; // initialized by parser for grammar errors - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.typeArguments = undefined; // used in quick info - return node; + return astFactory.createFunctionTypeNode(asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type).ast).node; } // @api @@ -2342,20 +1623,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: NodeArray | undefined, parameters: NodeArray, type: TypeNode, - ) { - return node.typeParameters !== typeParameters - || node.parameters !== parameters - || node.type !== type - ? finishUpdateFunctionTypeNode(createFunctionTypeNode(typeParameters, parameters, type), node) - : node; - } - - function finishUpdateFunctionTypeNode(updated: Mutable, original: FunctionTypeNode) { - if (updated !== original) { - // copy children used only for error reporting - updated.modifiers = original.modifiers; - } - return finishUpdateBaseSignatureDeclaration(updated, original); + ): FunctionTypeNode { + return astFactory.updateFunctionTypeNode(asNode(node).ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type).ast).node; } // @api @@ -2371,18 +1640,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[], type: TypeNode, ): ConstructorTypeNode { - const node = createBaseDeclaration(SyntaxKind.ConstructorType); - node.modifiers = asNodeArray(modifiers); - node.typeParameters = asNodeArray(typeParameters); - node.parameters = asNodeArray(parameters); - node.type = type; - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.typeArguments = undefined; // used in quick info - return node; + return astFactory.createConstructorTypeNode(asNodeArray(modifiers)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type).ast).node; } /** @deprecated */ @@ -2407,13 +1665,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: NodeArray | undefined, parameters: NodeArray, type: TypeNode, - ) { - return node.modifiers !== modifiers - || node.typeParameters !== typeParameters - || node.parameters !== parameters - || node.type !== type - ? finishUpdateBaseSignatureDeclaration(createConstructorTypeNode(modifiers, typeParameters, parameters, type), node) - : node; + ): ConstructorTypeNode { + return astFactory.updateConstructorTypeNode(asNode(node).ast, asNodeArray(modifiers)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type).ast).node; } /** @deprecated */ @@ -2427,207 +1680,123 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function createTypeQueryNode(exprName: EntityName, typeArguments?: readonly TypeNode[]) { - const node = createBaseNode(SyntaxKind.TypeQuery); - node.exprName = exprName; - node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createTypeQueryNode(exprName: EntityName, typeArguments?: readonly TypeNode[]): TypeQueryNode { + return astFactory.createTypeQueryNode(asNode(exprName).ast, asNodeArray(typeArguments)?.ast).node; } // @api - function updateTypeQueryNode(node: TypeQueryNode, exprName: EntityName, typeArguments?: readonly TypeNode[]) { - return node.exprName !== exprName - || node.typeArguments !== typeArguments - ? update(createTypeQueryNode(exprName, typeArguments), node) - : node; + function updateTypeQueryNode(node: TypeQueryNode, exprName: EntityName, typeArguments?: readonly TypeNode[]): TypeQueryNode { + return astFactory.updateTypeQueryNode(asNode(node).ast, asNode(exprName).ast, asNodeArray(typeArguments)?.ast).node; } // @api - function createTypeLiteralNode(members: readonly TypeElement[] | undefined) { - const node = createBaseDeclaration(SyntaxKind.TypeLiteral); - node.members = createNodeArray(members); - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createTypeLiteralNode(members: readonly TypeElement[] | undefined): TypeLiteralNode { + return astFactory.createTypeLiteralNode(asNodeArray(members)?.ast).node; } // @api - function updateTypeLiteralNode(node: TypeLiteralNode, members: NodeArray) { - return node.members !== members - ? update(createTypeLiteralNode(members), node) - : node; + function updateTypeLiteralNode(node: TypeLiteralNode, members: NodeArray): TypeLiteralNode { + return astFactory.updateTypeLiteralNode(asNode(node).ast, asNodeArray(members).ast).node; } // @api - function createArrayTypeNode(elementType: TypeNode) { - const node = createBaseNode(SyntaxKind.ArrayType); - node.elementType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(elementType); - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createArrayTypeNode(elementType: TypeNode): ArrayTypeNode { + return astFactory.createArrayTypeNode(asNode(elementType).ast).node; } // @api function updateArrayTypeNode(node: ArrayTypeNode, elementType: TypeNode): ArrayTypeNode { - return node.elementType !== elementType - ? update(createArrayTypeNode(elementType), node) - : node; + return astFactory.updateArrayTypeNode(asNode(node).ast, asNode(elementType).ast).node; } // @api - function createTupleTypeNode(elements: readonly (TypeNode | NamedTupleMember)[]) { - const node = createBaseNode(SyntaxKind.TupleType); - node.elements = createNodeArray(parenthesizerRules().parenthesizeElementTypesOfTupleType(elements)); - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createTupleTypeNode(elements: readonly (TypeNode | NamedTupleMember)[]): TupleTypeNode { + return astFactory.createTupleTypeNode(asNodeArray(elements).ast).node; } // @api - function updateTupleTypeNode(node: TupleTypeNode, elements: readonly (TypeNode | NamedTupleMember)[]) { - return node.elements !== elements - ? update(createTupleTypeNode(elements), node) - : node; + function updateTupleTypeNode(node: TupleTypeNode, elements: readonly (TypeNode | NamedTupleMember)[]): TupleTypeNode { + return astFactory.updateTupleTypeNode(asNode(node).ast, asNodeArray(elements).ast).node; } // @api - function createNamedTupleMember(dotDotDotToken: DotDotDotToken | undefined, name: Identifier, questionToken: QuestionToken | undefined, type: TypeNode) { - const node = createBaseDeclaration(SyntaxKind.NamedTupleMember); - node.dotDotDotToken = dotDotDotToken; - node.name = name; - node.questionToken = questionToken; - node.type = type; - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + function createNamedTupleMember(dotDotDotToken: DotDotDotToken | undefined, name: Identifier, questionToken: QuestionToken | undefined, type: TypeNode): NamedTupleMember { + return astFactory.createNamedTupleMember(asNode(dotDotDotToken)?.ast, asNode(name).ast, asNode(questionToken)?.ast, asNode(type).ast).node; } // @api - function updateNamedTupleMember(node: NamedTupleMember, dotDotDotToken: DotDotDotToken | undefined, name: Identifier, questionToken: QuestionToken | undefined, type: TypeNode) { - return node.dotDotDotToken !== dotDotDotToken - || node.name !== name - || node.questionToken !== questionToken - || node.type !== type - ? update(createNamedTupleMember(dotDotDotToken, name, questionToken, type), node) - : node; + function updateNamedTupleMember(node: NamedTupleMember, dotDotDotToken: DotDotDotToken | undefined, name: Identifier, questionToken: QuestionToken | undefined, type: TypeNode): NamedTupleMember { + return astFactory.updateNamedTupleMember(asNode(node).ast, asNode(dotDotDotToken)?.ast, asNode(name).ast, asNode(questionToken)?.ast, asNode(type).ast).node; } // @api - function createOptionalTypeNode(type: TypeNode) { - const node = createBaseNode(SyntaxKind.OptionalType); - node.type = parenthesizerRules().parenthesizeTypeOfOptionalType(type); - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createOptionalTypeNode(type: TypeNode): OptionalTypeNode { + return astFactory.createOptionalTypeNode(asNode(type).ast).node; } // @api function updateOptionalTypeNode(node: OptionalTypeNode, type: TypeNode): OptionalTypeNode { - return node.type !== type - ? update(createOptionalTypeNode(type), node) - : node; + return astFactory.updateOptionalTypeNode(asNode(node).ast, asNode(type).ast).node; } // @api - function createRestTypeNode(type: TypeNode) { - const node = createBaseNode(SyntaxKind.RestType); - node.type = type; - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createRestTypeNode(type: TypeNode): RestTypeNode { + return astFactory.createRestTypeNode(asNode(type).ast).node; } // @api function updateRestTypeNode(node: RestTypeNode, type: TypeNode): RestTypeNode { - return node.type !== type - ? update(createRestTypeNode(type), node) - : node; - } - - function createUnionOrIntersectionTypeNode(kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType, types: readonly TypeNode[], parenthesize: (nodes: readonly TypeNode[]) => readonly TypeNode[]) { - const node = createBaseNode(kind); - node.types = factory.createNodeArray(parenthesize(types)); - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; - } - - function updateUnionOrIntersectionTypeNode(node: T, types: NodeArray, parenthesize: (nodes: readonly TypeNode[]) => readonly TypeNode[]): T { - return node.types !== types - ? update(createUnionOrIntersectionTypeNode(node.kind, types, parenthesize) as T, node) - : node; + return astFactory.updateRestTypeNode(asNode(node).ast, asNode(type).ast).node; } // @api function createUnionTypeNode(types: readonly TypeNode[]): UnionTypeNode { - return createUnionOrIntersectionTypeNode(SyntaxKind.UnionType, types, parenthesizerRules().parenthesizeConstituentTypesOfUnionType) as UnionTypeNode; + return astFactory.createUnionTypeNode(asNodeArray(types).ast).node; } // @api - function updateUnionTypeNode(node: UnionTypeNode, types: NodeArray) { - return updateUnionOrIntersectionTypeNode(node, types, parenthesizerRules().parenthesizeConstituentTypesOfUnionType); + function updateUnionTypeNode(node: UnionTypeNode, types: NodeArray): UnionTypeNode { + return astFactory.updateUnionTypeNode(asNode(node).ast, asNodeArray(types).ast).node; } // @api function createIntersectionTypeNode(types: readonly TypeNode[]): IntersectionTypeNode { - return createUnionOrIntersectionTypeNode(SyntaxKind.IntersectionType, types, parenthesizerRules().parenthesizeConstituentTypesOfIntersectionType) as IntersectionTypeNode; + return astFactory.createIntersectionTypeNode(asNodeArray(types).ast).node; } // @api - function updateIntersectionTypeNode(node: IntersectionTypeNode, types: NodeArray) { - return updateUnionOrIntersectionTypeNode(node, types, parenthesizerRules().parenthesizeConstituentTypesOfIntersectionType); + function updateIntersectionTypeNode(node: IntersectionTypeNode, types: NodeArray): IntersectionTypeNode { + return astFactory.updateIntersectionTypeNode(asNode(node).ast, asNodeArray(types).ast).node; } // @api - function createConditionalTypeNode(checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode) { - const node = createBaseNode(SyntaxKind.ConditionalType); - node.checkType = parenthesizerRules().parenthesizeCheckTypeOfConditionalType(checkType); - node.extendsType = parenthesizerRules().parenthesizeExtendsTypeOfConditionalType(extendsType); - node.trueType = trueType; - node.falseType = falseType; - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - return node; + function createConditionalTypeNode(checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode { + return astFactory.createConditionalTypeNode(asNode(checkType).ast, asNode(extendsType).ast, asNode(trueType).ast, asNode(falseType).ast).node; } // @api - function updateConditionalTypeNode(node: ConditionalTypeNode, checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode) { - return node.checkType !== checkType - || node.extendsType !== extendsType - || node.trueType !== trueType - || node.falseType !== falseType - ? update(createConditionalTypeNode(checkType, extendsType, trueType, falseType), node) - : node; + function updateConditionalTypeNode(node: ConditionalTypeNode, checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode { + return astFactory.updateConditionalTypeNode(asNode(node).ast, asNode(checkType).ast, asNode(extendsType).ast, asNode(trueType).ast, asNode(falseType).ast).node; } // @api - function createInferTypeNode(typeParameter: TypeParameterDeclaration) { - const node = createBaseNode(SyntaxKind.InferType); - node.typeParameter = typeParameter; - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createInferTypeNode(typeParameter: TypeParameterDeclaration): InferTypeNode { + return astFactory.createInferTypeNode(asNode(typeParameter).ast).node; } // @api - function updateInferTypeNode(node: InferTypeNode, typeParameter: TypeParameterDeclaration) { - return node.typeParameter !== typeParameter - ? update(createInferTypeNode(typeParameter), node) - : node; + function updateInferTypeNode(node: InferTypeNode, typeParameter: TypeParameterDeclaration): InferTypeNode { + return astFactory.updateInferTypeNode(asNode(node).ast, asNode(typeParameter).ast).node; } // @api - function createTemplateLiteralType(head: TemplateHead, templateSpans: readonly TemplateLiteralTypeSpan[]) { - const node = createBaseNode(SyntaxKind.TemplateLiteralType); - node.head = head; - node.templateSpans = createNodeArray(templateSpans); - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createTemplateLiteralType(head: TemplateHead, templateSpans: readonly TemplateLiteralTypeSpan[]): TemplateLiteralTypeNode { + return astFactory.createTemplateLiteralType(asNode(head).ast, asNodeArray(templateSpans).ast).node; } // @api - function updateTemplateLiteralType(node: TemplateLiteralTypeNode, head: TemplateHead, templateSpans: readonly TemplateLiteralTypeSpan[]) { - return node.head !== head - || node.templateSpans !== templateSpans - ? update(createTemplateLiteralType(head, templateSpans), node) - : node; + function updateTemplateLiteralType(node: TemplateLiteralTypeNode, head: TemplateHead, templateSpans: readonly TemplateLiteralTypeSpan[]): TemplateLiteralTypeNode { + return astFactory.updateTemplateLiteralType(asNode(node).ast, asNode(head).ast, asNodeArray(templateSpans).ast).node; } // @api @@ -2638,17 +1807,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeArguments?: readonly TypeNode[], isTypeOf = false, ): ImportTypeNode { - const node = createBaseNode(SyntaxKind.ImportType); - node.argument = argument; - node.attributes = attributes; - if (node.assertions && node.assertions.assertClause && node.attributes) { - (node.assertions as Mutable).assertClause = node.attributes; - } - node.qualifier = qualifier; - node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); - node.isTypeOf = isTypeOf; - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + return astFactory.createImportTypeNode(asNode(argument).ast, asNode(attributes)?.ast, asNode(qualifier)?.ast, asNodeArray(typeArguments)?.ast, isTypeOf).node; } // @api @@ -2660,113 +1819,62 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeArguments: readonly TypeNode[] | undefined, isTypeOf: boolean = node.isTypeOf, ): ImportTypeNode { - return node.argument !== argument - || node.attributes !== attributes - || node.qualifier !== qualifier - || node.typeArguments !== typeArguments - || node.isTypeOf !== isTypeOf - ? update(createImportTypeNode(argument, attributes, qualifier, typeArguments, isTypeOf), node) - : node; + return astFactory.updateImportTypeNode(asNode(node).ast, asNode(argument).ast, asNode(attributes)?.ast, asNode(qualifier)?.ast, asNodeArray(typeArguments)?.ast, isTypeOf).node; } // @api - function createParenthesizedType(type: TypeNode) { - const node = createBaseNode(SyntaxKind.ParenthesizedType); - node.type = type; - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createParenthesizedType(type: TypeNode): ParenthesizedTypeNode { + return astFactory.createParenthesizedType(asNode(type).ast).node; } // @api - function updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode) { - return node.type !== type - ? update(createParenthesizedType(type), node) - : node; + function updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode { + return astFactory.updateParenthesizedType(asNode(node).ast, asNode(type).ast).node; } // @api function createThisTypeNode() { - const node = createBaseNode(SyntaxKind.ThisType); - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + return astFactory.createThisTypeNode().node; } // @api function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: TypeNode): TypeOperatorNode { - const node = createBaseNode(SyntaxKind.TypeOperator); - node.operator = operator; - node.type = operator === SyntaxKind.ReadonlyKeyword ? - parenthesizerRules().parenthesizeOperandOfReadonlyTypeOperator(type) : - parenthesizerRules().parenthesizeOperandOfTypeOperator(type); - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + return astFactory.createTypeOperatorNode(operator, asNode(type).ast).node; } // @api - function updateTypeOperatorNode(node: TypeOperatorNode, type: TypeNode) { - return node.type !== type - ? update(createTypeOperatorNode(node.operator, type), node) - : node; + function updateTypeOperatorNode(node: TypeOperatorNode, type: TypeNode): TypeOperatorNode { + return astFactory.updateTypeOperatorNode(asNode(node).ast, asNode(type).ast).node; } // @api - function createIndexedAccessTypeNode(objectType: TypeNode, indexType: TypeNode) { - const node = createBaseNode(SyntaxKind.IndexedAccessType); - node.objectType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(objectType); - node.indexType = indexType; - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createIndexedAccessTypeNode(objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode { + return astFactory.createIndexedAccessTypeNode(asNode(objectType).ast, asNode(indexType).ast).node; } // @api - function updateIndexedAccessTypeNode(node: IndexedAccessTypeNode, objectType: TypeNode, indexType: TypeNode) { - return node.objectType !== objectType - || node.indexType !== indexType - ? update(createIndexedAccessTypeNode(objectType, indexType), node) - : node; + function updateIndexedAccessTypeNode(node: IndexedAccessTypeNode, objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode { + return astFactory.updateIndexedAccessTypeNode(asNode(node).ast, asNode(objectType).ast, asNode(indexType).ast).node; } // @api function createMappedTypeNode(readonlyToken: ReadonlyKeyword | PlusToken | MinusToken | undefined, typeParameter: TypeParameterDeclaration, nameType: TypeNode | undefined, questionToken: QuestionToken | PlusToken | MinusToken | undefined, type: TypeNode | undefined, members: readonly TypeElement[] | undefined): MappedTypeNode { - const node = createBaseDeclaration(SyntaxKind.MappedType); - node.readonlyToken = readonlyToken; - node.typeParameter = typeParameter; - node.nameType = nameType; - node.questionToken = questionToken; - node.type = type; - node.members = members && createNodeArray(members); - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - return node; + return astFactory.createMappedTypeNode(asNode(readonlyToken)?.ast, asNode(typeParameter).ast, asNode(nameType)?.ast, asNode(questionToken)?.ast, asNode(type)?.ast, asNodeArray(members)?.ast).node; } // @api function updateMappedTypeNode(node: MappedTypeNode, readonlyToken: ReadonlyKeyword | PlusToken | MinusToken | undefined, typeParameter: TypeParameterDeclaration, nameType: TypeNode | undefined, questionToken: QuestionToken | PlusToken | MinusToken | undefined, type: TypeNode | undefined, members: readonly TypeElement[] | undefined): MappedTypeNode { - return node.readonlyToken !== readonlyToken - || node.typeParameter !== typeParameter - || node.nameType !== nameType - || node.questionToken !== questionToken - || node.type !== type - || node.members !== members - ? update(createMappedTypeNode(readonlyToken, typeParameter, nameType, questionToken, type, members), node) - : node; + return astFactory.updateMappedTypeNode(asNode(node).ast, asNode(readonlyToken)?.ast, asNode(typeParameter).ast, asNode(nameType)?.ast, asNode(questionToken)?.ast, asNode(type)?.ast, asNodeArray(members)?.ast).node; } // @api - function createLiteralTypeNode(literal: LiteralTypeNode["literal"]) { - const node = createBaseNode(SyntaxKind.LiteralType); - node.literal = literal; - node.transformFlags = TransformFlags.ContainsTypeScript; - return node; + function createLiteralTypeNode(literal: LiteralTypeNode["literal"]): LiteralTypeNode { + return astFactory.createLiteralTypeNode(asNode(literal).ast).node; } // @api - function updateLiteralTypeNode(node: LiteralTypeNode, literal: LiteralTypeNode["literal"]) { - return node.literal !== literal - ? update(createLiteralTypeNode(literal), node) - : node; + function updateLiteralTypeNode(node: LiteralTypeNode, literal: LiteralTypeNode["literal"]): LiteralTypeNode { + return astFactory.updateLiteralTypeNode(asNode(node).ast, asNode(literal).ast).node; } // @@ -2774,69 +1882,33 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // // @api - function createObjectBindingPattern(elements: readonly BindingElement[]) { - const node = createBaseNode(SyntaxKind.ObjectBindingPattern); - node.elements = createNodeArray(elements); - node.transformFlags |= propagateChildrenFlags(node.elements) | - TransformFlags.ContainsES2015 | - TransformFlags.ContainsBindingPattern; - if (node.transformFlags & TransformFlags.ContainsRestOrSpread) { - node.transformFlags |= TransformFlags.ContainsES2018 | - TransformFlags.ContainsObjectRestOrSpread; - } - return node; + function createObjectBindingPattern(elements: readonly BindingElement[]): ObjectBindingPattern { + return astFactory.createObjectBindingPattern(asNodeArray(elements).ast).node; } // @api - function updateObjectBindingPattern(node: ObjectBindingPattern, elements: readonly BindingElement[]) { - return node.elements !== elements - ? update(createObjectBindingPattern(elements), node) - : node; + function updateObjectBindingPattern(node: ObjectBindingPattern, elements: readonly BindingElement[]): ObjectBindingPattern { + return astFactory.updateObjectBindingPattern(asNode(node).ast, asNodeArray(elements).ast).node; } // @api - function createArrayBindingPattern(elements: readonly ArrayBindingElement[]) { - const node = createBaseNode(SyntaxKind.ArrayBindingPattern); - node.elements = createNodeArray(elements); - node.transformFlags |= propagateChildrenFlags(node.elements) | - TransformFlags.ContainsES2015 | - TransformFlags.ContainsBindingPattern; - return node; + function createArrayBindingPattern(elements: readonly ArrayBindingElement[]): ArrayBindingPattern { + return astFactory.createArrayBindingPattern(asNodeArray(elements).ast).node; } // @api - function updateArrayBindingPattern(node: ArrayBindingPattern, elements: readonly ArrayBindingElement[]) { - return node.elements !== elements - ? update(createArrayBindingPattern(elements), node) - : node; + function updateArrayBindingPattern(node: ArrayBindingPattern, elements: readonly ArrayBindingElement[]): ArrayBindingPattern { + return astFactory.updateArrayBindingPattern(asNode(node).ast, asNodeArray(elements).ast).node; } // @api - function createBindingElement(dotDotDotToken: DotDotDotToken | undefined, propertyName: string | PropertyName | undefined, name: string | BindingName, initializer?: Expression) { - const node = createBaseDeclaration(SyntaxKind.BindingElement); - node.dotDotDotToken = dotDotDotToken; - node.propertyName = asName(propertyName); - node.name = asName(name); - node.initializer = asInitializer(initializer); - node.transformFlags |= propagateChildFlags(node.dotDotDotToken) | - propagateNameFlags(node.propertyName) | - propagateNameFlags(node.name) | - propagateChildFlags(node.initializer) | - (node.dotDotDotToken ? TransformFlags.ContainsRestOrSpread : TransformFlags.None) | - TransformFlags.ContainsES2015; - - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createBindingElement(dotDotDotToken: DotDotDotToken | undefined, propertyName: string | PropertyName | undefined, name: string | BindingName, initializer?: Expression): BindingElement { + return astFactory.createBindingElement(asNode(dotDotDotToken)?.ast, asName(propertyName)?.ast, asName(name).ast, asNode(initializer)?.ast).node; } // @api - function updateBindingElement(node: BindingElement, dotDotDotToken: DotDotDotToken | undefined, propertyName: PropertyName | undefined, name: BindingName, initializer: Expression | undefined) { - return node.propertyName !== propertyName - || node.dotDotDotToken !== dotDotDotToken - || node.name !== name - || node.initializer !== initializer - ? update(createBindingElement(dotDotDotToken, propertyName, name, initializer), node) - : node; + function updateBindingElement(node: BindingElement, dotDotDotToken: DotDotDotToken | undefined, propertyName: PropertyName | undefined, name: BindingName, initializer: Expression | undefined): BindingElement { + return astFactory.updateBindingElement(asNode(node).ast, asNode(dotDotDotToken)?.ast, asNode(propertyName)?.ast, asNode(name).ast, asNode(initializer)?.ast).node; } // @@ -2844,332 +1916,123 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // // @api - function createArrayLiteralExpression(elements?: readonly Expression[], multiLine?: boolean) { - const node = createBaseNode(SyntaxKind.ArrayLiteralExpression); - // Ensure we add a trailing comma for something like `[NumericLiteral(1), NumericLiteral(2), OmittedExpresion]` so that - // we end up with `[1, 2, ,]` instead of `[1, 2, ]` otherwise the `OmittedExpression` will just end up being treated like - // a trailing comma. - const lastElement = elements && lastOrUndefined(elements); - const elementsArray = createNodeArray(elements, lastElement && isOmittedExpression(lastElement) ? true : undefined); - node.elements = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(elementsArray); - node.multiLine = multiLine; - node.transformFlags |= propagateChildrenFlags(node.elements); - return node; + function createArrayLiteralExpression(elements?: readonly Expression[], multiLine?: boolean): ArrayLiteralExpression { + return astFactory.createArrayLiteralExpression(asNodeArray(elements)?.ast, multiLine).node; } // @api - function updateArrayLiteralExpression(node: ArrayLiteralExpression, elements: readonly Expression[]) { - return node.elements !== elements - ? update(createArrayLiteralExpression(elements, node.multiLine), node) - : node; + function updateArrayLiteralExpression(node: ArrayLiteralExpression, elements: readonly Expression[]): ArrayLiteralExpression { + return astFactory.updateArrayLiteralExpression(asNode(node).ast, asNodeArray(elements).ast).node; } // @api - function createObjectLiteralExpression(properties?: readonly ObjectLiteralElementLike[], multiLine?: boolean) { - const node = createBaseDeclaration(SyntaxKind.ObjectLiteralExpression); - node.properties = createNodeArray(properties); - node.multiLine = multiLine; - node.transformFlags |= propagateChildrenFlags(node.properties); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + function createObjectLiteralExpression(properties?: readonly ObjectLiteralElementLike[], multiLine?: boolean): ObjectLiteralExpression { + return astFactory.createObjectLiteralExpression(asNodeArray(properties)?.ast, multiLine).node; } // @api - function updateObjectLiteralExpression(node: ObjectLiteralExpression, properties: readonly ObjectLiteralElementLike[]) { - return node.properties !== properties - ? update(createObjectLiteralExpression(properties, node.multiLine), node) - : node; - } - - function createBasePropertyAccessExpression(expression: LeftHandSideExpression, questionDotToken: QuestionDotToken | undefined, name: MemberName) { - const node = createBaseDeclaration(SyntaxKind.PropertyAccessExpression); - node.expression = expression; - node.questionDotToken = questionDotToken; - node.name = name; - node.transformFlags = propagateChildFlags(node.expression) | - propagateChildFlags(node.questionDotToken) | - (isIdentifier(node.name) ? - propagateIdentifierNameFlags(node.name) : - propagateChildFlags(node.name) | TransformFlags.ContainsPrivateIdentifierInExpression); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function updateObjectLiteralExpression(node: ObjectLiteralExpression, properties: readonly ObjectLiteralElementLike[]): ObjectLiteralExpression { + return astFactory.updateObjectLiteralExpression(asNode(node).ast, asNodeArray(properties).ast).node; } // @api - function createPropertyAccessExpression(expression: Expression, name: string | Identifier | PrivateIdentifier) { - const node = createBasePropertyAccessExpression( - parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false), - /*questionDotToken*/ undefined, - asName(name), - ); - if (isSuperKeyword(expression)) { - // super method calls require a lexical 'this' - // super method calls require 'super' hoisting in ES2017 and ES2018 async functions and async generators - node.transformFlags |= TransformFlags.ContainsES2017 | - TransformFlags.ContainsES2018; - } - return node; + function createPropertyAccessExpression(expression: Expression, name: string | Identifier | PrivateIdentifier): PropertyAccessExpression { + return astFactory.createPropertyAccessExpression(asNode(expression).ast, asName(name).ast).node; } // @api - function updatePropertyAccessExpression(node: PropertyAccessExpression, expression: Expression, name: Identifier | PrivateIdentifier) { - if (isPropertyAccessChain(node)) { - return updatePropertyAccessChain(node, expression, node.questionDotToken, cast(name, isIdentifier)); - } - return node.expression !== expression - || node.name !== name - ? update(createPropertyAccessExpression(expression, name), node) - : node; + function updatePropertyAccessExpression(node: PropertyAccessExpression, expression: Expression, name: Identifier | PrivateIdentifier): PropertyAccessExpression { + return astFactory.updatePropertyAccessExpression(asNode(node).ast, asNode(expression).ast, asNode(name).ast).node; } // @api - function createPropertyAccessChain(expression: Expression, questionDotToken: QuestionDotToken | undefined, name: string | Identifier | PrivateIdentifier) { - const node = createBasePropertyAccessExpression( - parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true), - questionDotToken, - asName(name), - ) as Mutable; - node.flags |= NodeFlags.OptionalChain; - node.transformFlags |= TransformFlags.ContainsES2020; - return node; + function createPropertyAccessChain(expression: Expression, questionDotToken: QuestionDotToken | undefined, name: string | Identifier | PrivateIdentifier): PropertyAccessChain { + return astFactory.createPropertyAccessChain(asNode(expression).ast, asNode(questionDotToken)?.ast, asName(name).ast).node; } // @api - function updatePropertyAccessChain(node: PropertyAccessChain, expression: Expression, questionDotToken: QuestionDotToken | undefined, name: Identifier | PrivateIdentifier) { - Debug.assert(!!(node.flags & NodeFlags.OptionalChain), "Cannot update a PropertyAccessExpression using updatePropertyAccessChain. Use updatePropertyAccess instead."); - // Because we are updating an existing PropertyAccessChain we want to inherit its emitFlags - // instead of using the default from createPropertyAccess - return node.expression !== expression - || node.questionDotToken !== questionDotToken - || node.name !== name - ? update(createPropertyAccessChain(expression, questionDotToken, name), node) - : node; + function updatePropertyAccessChain(node: PropertyAccessChain, expression: Expression, questionDotToken: QuestionDotToken | undefined, name: Identifier | PrivateIdentifier): PropertyAccessChain { + return astFactory.updatePropertyAccessChain(asNode(node).ast, asNode(expression).ast, asNode(questionDotToken)?.ast, asNode(name).ast).node; } - function createBaseElementAccessExpression(expression: LeftHandSideExpression, questionDotToken: QuestionDotToken | undefined, argumentExpression: Expression) { - const node = createBaseDeclaration(SyntaxKind.ElementAccessExpression); - node.expression = expression; - node.questionDotToken = questionDotToken; - node.argumentExpression = argumentExpression; - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildFlags(node.questionDotToken) | - propagateChildFlags(node.argumentExpression); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + // @api + function createElementAccessExpression(expression: Expression, index: number | Expression): ElementAccessExpression { + return astFactory.createElementAccessExpression(asNode(expression).ast, asExpression(index).ast).node; } // @api - function createElementAccessExpression(expression: Expression, index: number | Expression) { - const node = createBaseElementAccessExpression( - parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false), - /*questionDotToken*/ undefined, - asExpression(index), - ); - if (isSuperKeyword(expression)) { - // super method calls require a lexical 'this' - // super method calls require 'super' hoisting in ES2017 and ES2018 async functions and async generators - node.transformFlags |= TransformFlags.ContainsES2017 | - TransformFlags.ContainsES2018; - } - return node; + function updateElementAccessExpression(node: ElementAccessExpression, expression: Expression, argumentExpression: Expression): ElementAccessExpression { + return astFactory.updateElementAccessExpression(asNode(node).ast, asNode(expression).ast, asNode(argumentExpression).ast).node; } // @api - function updateElementAccessExpression(node: ElementAccessExpression, expression: Expression, argumentExpression: Expression) { - if (isElementAccessChain(node)) { - return updateElementAccessChain(node, expression, node.questionDotToken, argumentExpression); - } - return node.expression !== expression - || node.argumentExpression !== argumentExpression - ? update(createElementAccessExpression(expression, argumentExpression), node) - : node; + function createElementAccessChain(expression: Expression, questionDotToken: QuestionDotToken | undefined, index: number | Expression): ElementAccessChain { + return astFactory.createElementAccessChain(asNode(expression).ast, asNode(questionDotToken)?.ast, asExpression(index).ast).node; } // @api - function createElementAccessChain(expression: Expression, questionDotToken: QuestionDotToken | undefined, index: number | Expression) { - const node = createBaseElementAccessExpression( - parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true), - questionDotToken, - asExpression(index), - ) as Mutable; - node.flags |= NodeFlags.OptionalChain; - node.transformFlags |= TransformFlags.ContainsES2020; - return node; + function updateElementAccessChain(node: ElementAccessChain, expression: Expression, questionDotToken: QuestionDotToken | undefined, argumentExpression: Expression): ElementAccessChain { + return astFactory.updateElementAccessChain(asNode(node).ast, asNode(expression).ast, asNode(questionDotToken)?.ast, asNode(argumentExpression).ast).node; } // @api - function updateElementAccessChain(node: ElementAccessChain, expression: Expression, questionDotToken: QuestionDotToken | undefined, argumentExpression: Expression) { - Debug.assert(!!(node.flags & NodeFlags.OptionalChain), "Cannot update a ElementAccessExpression using updateElementAccessChain. Use updateElementAccess instead."); - // Because we are updating an existing ElementAccessChain we want to inherit its emitFlags - // instead of using the default from createElementAccess - return node.expression !== expression - || node.questionDotToken !== questionDotToken - || node.argumentExpression !== argumentExpression - ? update(createElementAccessChain(expression, questionDotToken, argumentExpression), node) - : node; - } - - function createBaseCallExpression(expression: LeftHandSideExpression, questionDotToken: QuestionDotToken | undefined, typeArguments: NodeArray | undefined, argumentsArray: NodeArray) { - const node = createBaseDeclaration(SyntaxKind.CallExpression); - node.expression = expression; - node.questionDotToken = questionDotToken; - node.typeArguments = typeArguments; - node.arguments = argumentsArray; - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildFlags(node.questionDotToken) | - propagateChildrenFlags(node.typeArguments) | - propagateChildrenFlags(node.arguments); - if (node.typeArguments) { - node.transformFlags |= TransformFlags.ContainsTypeScript; - } - if (isSuperProperty(node.expression)) { - node.transformFlags |= TransformFlags.ContainsLexicalThis; - } - return node; + function createCallExpression(expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined): CallExpression { + return astFactory.createCallExpression(asNode(expression).ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray)?.ast).node; } // @api - function createCallExpression(expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined) { - const node = createBaseCallExpression( - parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false), - /*questionDotToken*/ undefined, - asNodeArray(typeArguments), - parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray)), - ); - if (isImportKeyword(node.expression)) { - node.transformFlags |= TransformFlags.ContainsDynamicImport; - } - return node; + function updateCallExpression(node: CallExpression, expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[]): CallExpression { + return astFactory.updateCallExpression(asNode(node).ast, asNode(expression).ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray).ast).node; } // @api - function updateCallExpression(node: CallExpression, expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[]) { - if (isCallChain(node)) { - return updateCallChain(node, expression, node.questionDotToken, typeArguments, argumentsArray); - } - return node.expression !== expression - || node.typeArguments !== typeArguments - || node.arguments !== argumentsArray - ? update(createCallExpression(expression, typeArguments, argumentsArray), node) - : node; - } - - // @api - function createCallChain(expression: Expression, questionDotToken: QuestionDotToken | undefined, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined) { - const node = createBaseCallExpression( - parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true), - questionDotToken, - asNodeArray(typeArguments), - parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray)), - ) as Mutable; - node.flags |= NodeFlags.OptionalChain; - node.transformFlags |= TransformFlags.ContainsES2020; - return node; + function createCallChain(expression: Expression, questionDotToken: QuestionDotToken | undefined, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined): CallChain { + return astFactory.createCallChain(asNode(expression).ast, asNode(questionDotToken)?.ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray)?.ast).node; } // @api - function updateCallChain(node: CallChain, expression: Expression, questionDotToken: QuestionDotToken | undefined, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[]) { - Debug.assert(!!(node.flags & NodeFlags.OptionalChain), "Cannot update a CallExpression using updateCallChain. Use updateCall instead."); - return node.expression !== expression - || node.questionDotToken !== questionDotToken - || node.typeArguments !== typeArguments - || node.arguments !== argumentsArray - ? update(createCallChain(expression, questionDotToken, typeArguments, argumentsArray), node) - : node; + function updateCallChain(node: CallChain, expression: Expression, questionDotToken: QuestionDotToken | undefined, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[]): CallChain { + return astFactory.updateCallChain(asNode(node).ast, asNode(expression).ast, asNode(questionDotToken)?.ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray).ast).node; } // @api - function createNewExpression(expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined) { - const node = createBaseDeclaration(SyntaxKind.NewExpression); - node.expression = parenthesizerRules().parenthesizeExpressionOfNew(expression); - node.typeArguments = asNodeArray(typeArguments); - node.arguments = argumentsArray ? parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(argumentsArray) : undefined; - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildrenFlags(node.typeArguments) | - propagateChildrenFlags(node.arguments) | - TransformFlags.ContainsES2020; - if (node.typeArguments) { - node.transformFlags |= TransformFlags.ContainsTypeScript; - } - return node; + function createNewExpression(expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined): NewExpression { + return astFactory.createNewExpression(asNode(expression).ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray)?.ast).node; } // @api - function updateNewExpression(node: NewExpression, expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined) { - return node.expression !== expression - || node.typeArguments !== typeArguments - || node.arguments !== argumentsArray - ? update(createNewExpression(expression, typeArguments, argumentsArray), node) - : node; + function updateNewExpression(node: NewExpression, expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined): NewExpression { + return astFactory.updateNewExpression(asNode(node).ast, asNode(expression).ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray)?.ast).node; } // @api - function createTaggedTemplateExpression(tag: Expression, typeArguments: readonly TypeNode[] | undefined, template: TemplateLiteral) { - const node = createBaseNode(SyntaxKind.TaggedTemplateExpression); - node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag, /*optionalChain*/ false); - node.typeArguments = asNodeArray(typeArguments); - node.template = template; - node.transformFlags |= propagateChildFlags(node.tag) | - propagateChildrenFlags(node.typeArguments) | - propagateChildFlags(node.template) | - TransformFlags.ContainsES2015; - if (node.typeArguments) { - node.transformFlags |= TransformFlags.ContainsTypeScript; - } - if (hasInvalidEscape(node.template)) { - node.transformFlags |= TransformFlags.ContainsES2018; - } - return node; + function createTaggedTemplateExpression(tag: Expression, typeArguments: readonly TypeNode[] | undefined, template: TemplateLiteral): TaggedTemplateExpression { + return astFactory.createTaggedTemplateExpression(asNode(tag).ast, asNodeArray(typeArguments)?.ast, asNode(template).ast).node; } // @api - function updateTaggedTemplateExpression(node: TaggedTemplateExpression, tag: Expression, typeArguments: readonly TypeNode[] | undefined, template: TemplateLiteral) { - return node.tag !== tag - || node.typeArguments !== typeArguments - || node.template !== template - ? update(createTaggedTemplateExpression(tag, typeArguments, template), node) - : node; + function updateTaggedTemplateExpression(node: TaggedTemplateExpression, tag: Expression, typeArguments: readonly TypeNode[] | undefined, template: TemplateLiteral): TaggedTemplateExpression { + return astFactory.updateTaggedTemplateExpression(asNode(node).ast, asNode(tag).ast, asNodeArray(typeArguments)?.ast, asNode(template).ast).node; } // @api - function createTypeAssertion(type: TypeNode, expression: Expression) { - const node = createBaseNode(SyntaxKind.TypeAssertionExpression); - node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); - node.type = type; - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildFlags(node.type) | - TransformFlags.ContainsTypeScript; - return node; + function createTypeAssertion(type: TypeNode, expression: Expression): TypeAssertion { + return astFactory.createTypeAssertion(asNode(type).ast, asNode(expression).ast).node; } // @api - function updateTypeAssertion(node: TypeAssertion, type: TypeNode, expression: Expression) { - return node.type !== type - || node.expression !== expression - ? update(createTypeAssertion(type, expression), node) - : node; + function updateTypeAssertion(node: TypeAssertion, type: TypeNode, expression: Expression): TypeAssertion { + return astFactory.updateTypeAssertion(asNode(node).ast, asNode(type).ast, asNode(expression).ast).node; } // @api - function createParenthesizedExpression(expression: Expression) { - const node = createBaseNode(SyntaxKind.ParenthesizedExpression); - node.expression = expression; - node.transformFlags = propagateChildFlags(node.expression); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + function createParenthesizedExpression(expression: Expression): ParenthesizedExpression { + return astFactory.createParenthesizedExpression(asNode(expression).ast).node; } // @api - function updateParenthesizedExpression(node: ParenthesizedExpression, expression: Expression) { - return node.expression !== expression - ? update(createParenthesizedExpression(expression), node) - : node; + function updateParenthesizedExpression(node: ParenthesizedExpression, expression: Expression): ParenthesizedExpression { + return astFactory.updateParenthesizedExpression(asNode(node).ast, asNode(expression).ast).node; } // @api @@ -3181,42 +2044,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[] | undefined, type: TypeNode | undefined, body: Block, - ) { - const node = createBaseDeclaration(SyntaxKind.FunctionExpression); - node.modifiers = asNodeArray(modifiers); - node.asteriskToken = asteriskToken; - node.name = asName(name); - node.typeParameters = asNodeArray(typeParameters); - node.parameters = createNodeArray(parameters); - node.type = type; - node.body = body; - - const isAsync = modifiersToFlags(node.modifiers) & ModifierFlags.Async; - const isGenerator = !!node.asteriskToken; - const isAsyncGenerator = isAsync && isGenerator; - - node.transformFlags = propagateChildrenFlags(node.modifiers) | - propagateChildFlags(node.asteriskToken) | - propagateNameFlags(node.name) | - propagateChildrenFlags(node.typeParameters) | - propagateChildrenFlags(node.parameters) | - propagateChildFlags(node.type) | - (propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | - (isAsyncGenerator ? TransformFlags.ContainsES2018 : - isAsync ? TransformFlags.ContainsES2017 : - isGenerator ? TransformFlags.ContainsGenerator : - TransformFlags.None) | - (node.typeParameters || node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | - TransformFlags.ContainsHoistedDeclarationOrCompletion; - - node.typeArguments = undefined; // used in quick info - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - node.endFlowNode = undefined; - node.returnFlowNode = undefined; - return node; + ): FunctionExpression { + return astFactory.createFunctionExpression(asNodeArray(modifiers)?.ast, asNode(asteriskToken)?.ast, asName(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters)?.ast, asNode(type)?.ast, asNode(body).ast).node; } // @api @@ -3229,16 +2058,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, body: Block, - ) { - return node.name !== name - || node.modifiers !== modifiers - || node.asteriskToken !== asteriskToken - || node.typeParameters !== typeParameters - || node.parameters !== parameters - || node.type !== type - || node.body !== body - ? finishUpdateBaseSignatureDeclaration(createFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, type, body), node) - : node; + ): FunctionExpression { + return astFactory.updateFunctionExpression(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(asteriskToken)?.ast, asNode(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body).ast).node; } // @api @@ -3249,35 +2070,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode | undefined, equalsGreaterThanToken: EqualsGreaterThanToken | undefined, body: ConciseBody, - ) { - const node = createBaseDeclaration(SyntaxKind.ArrowFunction); - node.modifiers = asNodeArray(modifiers); - node.typeParameters = asNodeArray(typeParameters); - node.parameters = createNodeArray(parameters); - node.type = type; - node.equalsGreaterThanToken = equalsGreaterThanToken ?? createToken(SyntaxKind.EqualsGreaterThanToken); - node.body = parenthesizerRules().parenthesizeConciseBodyOfArrowFunction(body); - - const isAsync = modifiersToFlags(node.modifiers) & ModifierFlags.Async; - - node.transformFlags = propagateChildrenFlags(node.modifiers) | - propagateChildrenFlags(node.typeParameters) | - propagateChildrenFlags(node.parameters) | - propagateChildFlags(node.type) | - propagateChildFlags(node.equalsGreaterThanToken) | - (propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | - (node.typeParameters || node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | - (isAsync ? TransformFlags.ContainsES2017 | TransformFlags.ContainsLexicalThis : TransformFlags.None) | - TransformFlags.ContainsES2015; - - node.typeArguments = undefined; // used in quick info - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - node.endFlowNode = undefined; - node.returnFlowNode = undefined; - return node; + ): ArrowFunction { + return astFactory.createArrowFunction(asNodeArray(modifiers)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(equalsGreaterThanToken)?.ast, asNode(body).ast).node; } // @api @@ -3290,198 +2084,82 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode equalsGreaterThanToken: EqualsGreaterThanToken, body: ConciseBody, ): ArrowFunction { - return node.modifiers !== modifiers - || node.typeParameters !== typeParameters - || node.parameters !== parameters - || node.type !== type - || node.equalsGreaterThanToken !== equalsGreaterThanToken - || node.body !== body - ? finishUpdateBaseSignatureDeclaration(createArrowFunction(modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body), node) - : node; + return astFactory.updateArrowFunction(asNode(node).ast, asNodeArray(modifiers)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(equalsGreaterThanToken).ast, asNode(body).ast).node; } // @api - function createDeleteExpression(expression: Expression) { - const node = createBaseNode(SyntaxKind.DeleteExpression); - node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); - node.transformFlags |= propagateChildFlags(node.expression); - return node; + function createDeleteExpression(expression: Expression): DeleteExpression { + return astFactory.createDeleteExpression(asNode(expression).ast).node; } // @api - function updateDeleteExpression(node: DeleteExpression, expression: Expression) { - return node.expression !== expression - ? update(createDeleteExpression(expression), node) - : node; + function updateDeleteExpression(node: DeleteExpression, expression: Expression): DeleteExpression { + return astFactory.updateDeleteExpression(asNode(node).ast, asNode(expression).ast).node; } // @api - function createTypeOfExpression(expression: Expression) { - const node = createBaseNode(SyntaxKind.TypeOfExpression); - node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); - node.transformFlags |= propagateChildFlags(node.expression); - return node; + function createTypeOfExpression(expression: Expression): TypeOfExpression { + return astFactory.createTypeOfExpression(asNode(expression).ast).node; } // @api - function updateTypeOfExpression(node: TypeOfExpression, expression: Expression) { - return node.expression !== expression - ? update(createTypeOfExpression(expression), node) - : node; + function updateTypeOfExpression(node: TypeOfExpression, expression: Expression): TypeOfExpression { + return astFactory.updateTypeOfExpression(asNode(node).ast, asNode(expression).ast).node; } // @api - function createVoidExpression(expression: Expression) { - const node = createBaseNode(SyntaxKind.VoidExpression); - node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); - node.transformFlags |= propagateChildFlags(node.expression); - return node; + function createVoidExpression(expression: Expression): VoidExpression { + return astFactory.createVoidExpression(asNode(expression).ast).node; } // @api - function updateVoidExpression(node: VoidExpression, expression: Expression) { - return node.expression !== expression - ? update(createVoidExpression(expression), node) - : node; + function updateVoidExpression(node: VoidExpression, expression: Expression): VoidExpression { + return astFactory.updateVoidExpression(asNode(node).ast, asNode(expression).ast).node; } // @api - function createAwaitExpression(expression: Expression) { - const node = createBaseNode(SyntaxKind.AwaitExpression); - node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); - node.transformFlags |= propagateChildFlags(node.expression) | - TransformFlags.ContainsES2017 | - TransformFlags.ContainsES2018 | - TransformFlags.ContainsAwait; - return node; + function createAwaitExpression(expression: Expression): AwaitExpression { + return astFactory.createAwaitExpression(asNode(expression).ast).node; } // @api - function updateAwaitExpression(node: AwaitExpression, expression: Expression) { - return node.expression !== expression - ? update(createAwaitExpression(expression), node) - : node; + function updateAwaitExpression(node: AwaitExpression, expression: Expression): AwaitExpression { + return astFactory.updateAwaitExpression(asNode(node).ast, asNode(expression).ast).node; } // @api - function createPrefixUnaryExpression(operator: PrefixUnaryOperator, operand: Expression) { - const node = createBaseNode(SyntaxKind.PrefixUnaryExpression); - node.operator = operator; - node.operand = parenthesizerRules().parenthesizeOperandOfPrefixUnary(operand); - node.transformFlags |= propagateChildFlags(node.operand); - // Only set this flag for non-generated identifiers and non-"local" names. See the - // comment in `visitPreOrPostfixUnaryExpression` in module.ts - if ( - (operator === SyntaxKind.PlusPlusToken || operator === SyntaxKind.MinusMinusToken) && - isIdentifier(node.operand) && - !isGeneratedIdentifier(node.operand) && - !isLocalName(node.operand) - ) { - node.transformFlags |= TransformFlags.ContainsUpdateExpressionForIdentifier; - } - return node; + function createPrefixUnaryExpression(operator: PrefixUnaryOperator, operand: Expression): PrefixUnaryExpression { + return astFactory.createPrefixUnaryExpression(operator, asNode(operand).ast).node; } // @api - function updatePrefixUnaryExpression(node: PrefixUnaryExpression, operand: Expression) { - return node.operand !== operand - ? update(createPrefixUnaryExpression(node.operator, operand), node) - : node; + function updatePrefixUnaryExpression(node: PrefixUnaryExpression, operand: Expression): PrefixUnaryExpression { + return astFactory.updatePrefixUnaryExpression(asNode(node).ast, asNode(operand).ast).node; } // @api - function createPostfixUnaryExpression(operand: Expression, operator: PostfixUnaryOperator) { - const node = createBaseNode(SyntaxKind.PostfixUnaryExpression); - node.operator = operator; - node.operand = parenthesizerRules().parenthesizeOperandOfPostfixUnary(operand); - node.transformFlags |= propagateChildFlags(node.operand); - // Only set this flag for non-generated identifiers and non-"local" names. See the - // comment in `visitPreOrPostfixUnaryExpression` in module.ts - if ( - isIdentifier(node.operand) && - !isGeneratedIdentifier(node.operand) && - !isLocalName(node.operand) - ) { - node.transformFlags |= TransformFlags.ContainsUpdateExpressionForIdentifier; - } - return node; + function createPostfixUnaryExpression(operand: Expression, operator: PostfixUnaryOperator): PostfixUnaryExpression { + return astFactory.createPostfixUnaryExpression(asNode(operand).ast, operator).node; } // @api - function updatePostfixUnaryExpression(node: PostfixUnaryExpression, operand: Expression) { - return node.operand !== operand - ? update(createPostfixUnaryExpression(operand, node.operator), node) - : node; + function updatePostfixUnaryExpression(node: PostfixUnaryExpression, operand: Expression): PostfixUnaryExpression { + return astFactory.updatePostfixUnaryExpression(asNode(node).ast, asNode(operand).ast).node; } // @api - function createBinaryExpression(left: Expression, operator: BinaryOperator | BinaryOperatorToken, right: Expression) { - const node = createBaseDeclaration(SyntaxKind.BinaryExpression); - const operatorToken = asToken(operator); - const operatorKind = operatorToken.kind; - node.left = parenthesizerRules().parenthesizeLeftSideOfBinary(operatorKind, left); - node.operatorToken = operatorToken; - node.right = parenthesizerRules().parenthesizeRightSideOfBinary(operatorKind, node.left, right); - node.transformFlags |= propagateChildFlags(node.left) | - propagateChildFlags(node.operatorToken) | - propagateChildFlags(node.right); - if (operatorKind === SyntaxKind.QuestionQuestionToken) { - node.transformFlags |= TransformFlags.ContainsES2020; - } - else if (operatorKind === SyntaxKind.EqualsToken) { - if (isObjectLiteralExpression(node.left)) { - node.transformFlags |= TransformFlags.ContainsES2015 | - TransformFlags.ContainsES2018 | - TransformFlags.ContainsDestructuringAssignment | - propagateAssignmentPatternFlags(node.left); - } - else if (isArrayLiteralExpression(node.left)) { - node.transformFlags |= TransformFlags.ContainsES2015 | - TransformFlags.ContainsDestructuringAssignment | - propagateAssignmentPatternFlags(node.left); - } - } - else if (operatorKind === SyntaxKind.AsteriskAsteriskToken || operatorKind === SyntaxKind.AsteriskAsteriskEqualsToken) { - node.transformFlags |= TransformFlags.ContainsES2016; - } - else if (isLogicalOrCoalescingAssignmentOperator(operatorKind)) { - node.transformFlags |= TransformFlags.ContainsES2021; - } - if (operatorKind === SyntaxKind.InKeyword && isPrivateIdentifier(node.left)) { - node.transformFlags |= TransformFlags.ContainsPrivateIdentifierInExpression; - } - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; - } - - function propagateAssignmentPatternFlags(node: AssignmentPattern): TransformFlags { - return containsObjectRestOrSpread(node) ? TransformFlags.ContainsObjectRestOrSpread : TransformFlags.None; + function createBinaryExpression(left: Expression, operator: BinaryOperator | BinaryOperatorToken, right: Expression): BinaryExpression { + return astFactory.createBinaryExpression(asNode(left).ast, asToken(operator).ast, asNode(right).ast).node; } // @api - function updateBinaryExpression(node: BinaryExpression, left: Expression, operator: BinaryOperatorToken, right: Expression) { - return node.left !== left - || node.operatorToken !== operator - || node.right !== right - ? update(createBinaryExpression(left, operator, right), node) - : node; + function updateBinaryExpression(node: BinaryExpression, left: Expression, operator: BinaryOperatorToken, right: Expression): BinaryExpression { + return astFactory.updateBinaryExpression(asNode(node).ast, asNode(left).ast, asNode(operator).ast, asNode(right).ast).node; } // @api - function createConditionalExpression(condition: Expression, questionToken: QuestionToken | undefined, whenTrue: Expression, colonToken: ColonToken | undefined, whenFalse: Expression) { - const node = createBaseNode(SyntaxKind.ConditionalExpression); - node.condition = parenthesizerRules().parenthesizeConditionOfConditionalExpression(condition); - node.questionToken = questionToken ?? createToken(SyntaxKind.QuestionToken); - node.whenTrue = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenTrue); - node.colonToken = colonToken ?? createToken(SyntaxKind.ColonToken); - node.whenFalse = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenFalse); - node.transformFlags |= propagateChildFlags(node.condition) | - propagateChildFlags(node.questionToken) | - propagateChildFlags(node.whenTrue) | - propagateChildFlags(node.colonToken) | - propagateChildFlags(node.whenFalse); - return node; + function createConditionalExpression(condition: Expression, questionToken: QuestionToken | undefined, whenTrue: Expression, colonToken: ColonToken | undefined, whenFalse: Expression): ConditionalExpression { + return astFactory.createConditionalExpression(asNode(condition).ast, asNode(questionToken)?.ast, asNode(whenTrue).ast, asNode(colonToken)?.ast, asNode(whenFalse).ast).node; } // @api @@ -3493,155 +2171,62 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode colonToken: Token, whenFalse: Expression, ): ConditionalExpression { - return node.condition !== condition - || node.questionToken !== questionToken - || node.whenTrue !== whenTrue - || node.colonToken !== colonToken - || node.whenFalse !== whenFalse - ? update(createConditionalExpression(condition, questionToken, whenTrue, colonToken, whenFalse), node) - : node; - } - - // @api - function createTemplateExpression(head: TemplateHead, templateSpans: readonly TemplateSpan[]) { - const node = createBaseNode(SyntaxKind.TemplateExpression); - node.head = head; - node.templateSpans = createNodeArray(templateSpans); - node.transformFlags |= propagateChildFlags(node.head) | - propagateChildrenFlags(node.templateSpans) | - TransformFlags.ContainsES2015; - return node; + return astFactory.updateConditionalExpression(asNode(node).ast, asNode(condition).ast, asNode(questionToken).ast, asNode(whenTrue).ast, asNode(colonToken).ast, asNode(whenFalse).ast).node; } // @api - function updateTemplateExpression(node: TemplateExpression, head: TemplateHead, templateSpans: readonly TemplateSpan[]) { - return node.head !== head - || node.templateSpans !== templateSpans - ? update(createTemplateExpression(head, templateSpans), node) - : node; - } - - function checkTemplateLiteralLikeNode(kind: TemplateLiteralToken["kind"], text: string | undefined, rawText: string | undefined, templateFlags = TokenFlags.None) { - Debug.assert(!(templateFlags & ~TokenFlags.TemplateLiteralLikeFlags), "Unsupported template flags."); - // NOTE: without the assignment to `undefined`, we don't narrow the initial type of `cooked`. - // eslint-disable-next-line no-undef-init - let cooked: string | object | undefined = undefined; - if (rawText !== undefined && rawText !== text) { - cooked = getCookedText(kind, rawText); - if (typeof cooked === "object") { - return Debug.fail("Invalid raw text"); - } - } - if (text === undefined) { - if (cooked === undefined) { - return Debug.fail("Arguments 'text' and 'rawText' may not both be undefined."); - } - text = cooked; - } - else if (cooked !== undefined) { - Debug.assert(text === cooked, "Expected argument 'text' to be the normalized (i.e. 'cooked') version of argument 'rawText'."); - } - return text; + function createTemplateExpression(head: TemplateHead, templateSpans: readonly TemplateSpan[]): TemplateExpression { + return astFactory.createTemplateExpression(asNode(head).ast, asNodeArray(templateSpans).ast).node; } - function getTransformFlagsOfTemplateLiteralLike(templateFlags: TokenFlags) { - let transformFlags = TransformFlags.ContainsES2015; - if (templateFlags) { - transformFlags |= TransformFlags.ContainsES2018; - } - return transformFlags; - } - - // NOTE: `createTemplateLiteralLikeToken` and `createTemplateLiteralLikeDeclaration` are identical except for - // the underlying nodes they create. To avoid polymorphism due to two different node shapes, these - // functions are intentionally duplicated. - function createTemplateLiteralLikeToken(kind: TemplateLiteralToken["kind"], text: string, rawText: string | undefined, templateFlags: TokenFlags | undefined) { - const node = createBaseToken(kind); - node.text = text; - node.rawText = rawText; - node.templateFlags = templateFlags! & TokenFlags.TemplateLiteralLikeFlags; - node.transformFlags = getTransformFlagsOfTemplateLiteralLike(node.templateFlags); - return node; - } - - function createTemplateLiteralLikeDeclaration(kind: SyntaxKind.NoSubstitutionTemplateLiteral, text: string, rawText: string | undefined, templateFlags: TokenFlags | undefined) { - const node = createBaseDeclaration(kind); - node.text = text; - node.rawText = rawText; - node.templateFlags = templateFlags! & TokenFlags.TemplateLiteralLikeFlags; - node.transformFlags = getTransformFlagsOfTemplateLiteralLike(node.templateFlags); - return node; + // @api + function updateTemplateExpression(node: TemplateExpression, head: TemplateHead, templateSpans: readonly TemplateSpan[]): TemplateExpression { + return astFactory.updateTemplateExpression(asNode(node).ast, asNode(head).ast, asNodeArray(templateSpans).ast).node; } // @api - function createTemplateLiteralLikeNode(kind: TemplateLiteralToken["kind"], text: string, rawText: string | undefined, templateFlags: TokenFlags | undefined) { - if (kind === SyntaxKind.NoSubstitutionTemplateLiteral) { - return createTemplateLiteralLikeDeclaration(kind, text, rawText, templateFlags); - } - return createTemplateLiteralLikeToken(kind, text, rawText, templateFlags); + function createTemplateLiteralLikeNode(kind: TemplateLiteralToken["kind"], text: string, rawText: string | undefined, templateFlags: TokenFlags | undefined): TemplateLiteralToken { + return astFactory.createTemplateLiteralLikeNode(kind, text, rawText, templateFlags).node; } // @api function createTemplateHead(text: string | undefined, rawText?: string, templateFlags?: TokenFlags) { - text = checkTemplateLiteralLikeNode(SyntaxKind.TemplateHead, text, rawText, templateFlags); - return createTemplateLiteralLikeNode(SyntaxKind.TemplateHead, text, rawText, templateFlags) as TemplateHead; + return astFactory.createTemplateHead(text, rawText!, templateFlags).node; } // @api function createTemplateMiddle(text: string | undefined, rawText?: string, templateFlags?: TokenFlags) { - text = checkTemplateLiteralLikeNode(SyntaxKind.TemplateHead, text, rawText, templateFlags); - return createTemplateLiteralLikeNode(SyntaxKind.TemplateMiddle, text, rawText, templateFlags) as TemplateMiddle; + return astFactory.createTemplateMiddle(text, rawText!, templateFlags).node; } // @api function createTemplateTail(text: string | undefined, rawText?: string, templateFlags?: TokenFlags) { - text = checkTemplateLiteralLikeNode(SyntaxKind.TemplateHead, text, rawText, templateFlags); - return createTemplateLiteralLikeNode(SyntaxKind.TemplateTail, text, rawText, templateFlags) as TemplateTail; + return astFactory.createTemplateTail(text, rawText!, templateFlags).node; } // @api - function createNoSubstitutionTemplateLiteral(text: string | undefined, rawText?: string, templateFlags?: TokenFlags) { - text = checkTemplateLiteralLikeNode(SyntaxKind.TemplateHead, text, rawText, templateFlags); - return createTemplateLiteralLikeDeclaration(SyntaxKind.NoSubstitutionTemplateLiteral, text, rawText, templateFlags) as NoSubstitutionTemplateLiteral; + function createNoSubstitutionTemplateLiteral(text: string | undefined, rawText?: string) { + return astFactory.createNoSubstitutionTemplateLiteral(text, rawText!).node; } // @api function createYieldExpression(asteriskToken: AsteriskToken | undefined, expression: Expression | undefined): YieldExpression { - Debug.assert(!asteriskToken || !!expression, "A `YieldExpression` with an asteriskToken must have an expression."); - const node = createBaseNode(SyntaxKind.YieldExpression); - node.expression = expression && parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); - node.asteriskToken = asteriskToken; - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildFlags(node.asteriskToken) | - TransformFlags.ContainsES2015 | - TransformFlags.ContainsES2018 | - TransformFlags.ContainsYield; - return node; + return astFactory.createYieldExpression(asNode(asteriskToken)?.ast, asNode(expression)?.ast).node; } // @api - function updateYieldExpression(node: YieldExpression, asteriskToken: AsteriskToken | undefined, expression: Expression) { - return node.expression !== expression - || node.asteriskToken !== asteriskToken - ? update(createYieldExpression(asteriskToken, expression), node) - : node; + function updateYieldExpression(node: YieldExpression, asteriskToken: AsteriskToken | undefined, expression: Expression | undefined): YieldExpression { + return astFactory.updateYieldExpression(asNode(node).ast, asNode(asteriskToken)?.ast, asNode(expression)?.ast).node; } // @api - function createSpreadElement(expression: Expression) { - const node = createBaseNode(SyntaxKind.SpreadElement); - node.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); - node.transformFlags |= propagateChildFlags(node.expression) | - TransformFlags.ContainsES2015 | - TransformFlags.ContainsRestOrSpread; - return node; + function createSpreadElement(expression: Expression): SpreadElement { + return astFactory.createSpreadElement(asNode(expression).ast).node; } // @api - function updateSpreadElement(node: SpreadElement, expression: Expression) { - return node.expression !== expression - ? update(createSpreadElement(expression), node) - : node; + function updateSpreadElement(node: SpreadElement, expression: Expression): SpreadElement { + return astFactory.updateSpreadElement(asNode(node).ast, asNode(expression).ast).node; } // @api @@ -3651,23 +2236,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: readonly TypeParameterDeclaration[] | undefined, heritageClauses: readonly HeritageClause[] | undefined, members: readonly ClassElement[], - ) { - const node = createBaseDeclaration(SyntaxKind.ClassExpression); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.typeParameters = asNodeArray(typeParameters); - node.heritageClauses = asNodeArray(heritageClauses); - node.members = createNodeArray(members); - node.transformFlags |= propagateChildrenFlags(node.modifiers) | - propagateNameFlags(node.name) | - propagateChildrenFlags(node.typeParameters) | - propagateChildrenFlags(node.heritageClauses) | - propagateChildrenFlags(node.members) | - (node.typeParameters ? TransformFlags.ContainsTypeScript : TransformFlags.None) | - TransformFlags.ContainsES2015; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + ): ClassExpression { + return astFactory.createClassExpression(asNodeArray(modifiers)?.ast, asName(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(heritageClauses)?.ast, asNodeArray(members).ast).node; } // @api @@ -3678,141 +2248,73 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: readonly TypeParameterDeclaration[] | undefined, heritageClauses: readonly HeritageClause[] | undefined, members: readonly ClassElement[], - ) { - return node.modifiers !== modifiers - || node.name !== name - || node.typeParameters !== typeParameters - || node.heritageClauses !== heritageClauses - || node.members !== members - ? update(createClassExpression(modifiers, name, typeParameters, heritageClauses, members), node) - : node; + ): ClassExpression { + return astFactory.updateClassExpression(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(heritageClauses)?.ast, asNodeArray(members).ast).node; } // @api - function createOmittedExpression() { - return createBaseNode(SyntaxKind.OmittedExpression); + function createOmittedExpression(): OmittedExpression { + return astFactory.createOmittedExpression().node; } // @api - function createExpressionWithTypeArguments(expression: Expression, typeArguments: readonly TypeNode[] | undefined) { - const node = createBaseNode(SyntaxKind.ExpressionWithTypeArguments); - node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); - node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildrenFlags(node.typeArguments) | - TransformFlags.ContainsES2015; - return node; + function createExpressionWithTypeArguments(expression: Expression, typeArguments: readonly TypeNode[] | undefined): ExpressionWithTypeArguments { + return astFactory.createExpressionWithTypeArguments(asNode(expression).ast, asNodeArray(typeArguments)?.ast).node; } // @api - function updateExpressionWithTypeArguments(node: ExpressionWithTypeArguments, expression: Expression, typeArguments: readonly TypeNode[] | undefined) { - return node.expression !== expression - || node.typeArguments !== typeArguments - ? update(createExpressionWithTypeArguments(expression, typeArguments), node) - : node; + function updateExpressionWithTypeArguments(node: ExpressionWithTypeArguments, expression: Expression, typeArguments: readonly TypeNode[] | undefined): ExpressionWithTypeArguments { + return astFactory.updateExpressionWithTypeArguments(asNode(node).ast, asNode(expression).ast, asNodeArray(typeArguments)?.ast).node; } // @api - function createAsExpression(expression: Expression, type: TypeNode) { - const node = createBaseNode(SyntaxKind.AsExpression); - node.expression = expression; - node.type = type; - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildFlags(node.type) | - TransformFlags.ContainsTypeScript; - return node; + function createAsExpression(expression: Expression, type: TypeNode): AsExpression { + return astFactory.createAsExpression(asNode(expression).ast, asNode(type).ast).node; } // @api - function updateAsExpression(node: AsExpression, expression: Expression, type: TypeNode) { - return node.expression !== expression - || node.type !== type - ? update(createAsExpression(expression, type), node) - : node; + function updateAsExpression(node: AsExpression, expression: Expression, type: TypeNode): AsExpression { + return astFactory.updateAsExpression(asNode(node).ast, asNode(expression).ast, asNode(type).ast).node; } // @api - function createNonNullExpression(expression: Expression) { - const node = createBaseNode(SyntaxKind.NonNullExpression); - node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); - node.transformFlags |= propagateChildFlags(node.expression) | - TransformFlags.ContainsTypeScript; - return node; + function createNonNullExpression(expression: Expression): NonNullExpression { + return astFactory.createNonNullExpression(asNode(expression).ast).node; } // @api - function updateNonNullExpression(node: NonNullExpression, expression: Expression) { - if (isNonNullChain(node)) { - return updateNonNullChain(node, expression); - } - return node.expression !== expression - ? update(createNonNullExpression(expression), node) - : node; + function updateNonNullExpression(node: NonNullExpression, expression: Expression): NonNullExpression { + return astFactory.updateNonNullExpression(asNode(node).ast, asNode(expression).ast).node; } // @api - function createSatisfiesExpression(expression: Expression, type: TypeNode) { - const node = createBaseNode(SyntaxKind.SatisfiesExpression); - node.expression = expression; - node.type = type; - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildFlags(node.type) | - TransformFlags.ContainsTypeScript; - return node; + function createSatisfiesExpression(expression: Expression, type: TypeNode): SatisfiesExpression { + return astFactory.createSatisfiesExpression(asNode(expression).ast, asNode(type).ast).node; } // @api - function updateSatisfiesExpression(node: SatisfiesExpression, expression: Expression, type: TypeNode) { - return node.expression !== expression - || node.type !== type - ? update(createSatisfiesExpression(expression, type), node) - : node; + function updateSatisfiesExpression(node: SatisfiesExpression, expression: Expression, type: TypeNode): SatisfiesExpression { + return astFactory.updateSatisfiesExpression(asNode(node).ast, asNode(expression).ast, asNode(type).ast).node; } // @api - function createNonNullChain(expression: Expression) { - const node = createBaseNode(SyntaxKind.NonNullExpression); - node.flags |= NodeFlags.OptionalChain; - node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true); - node.transformFlags |= propagateChildFlags(node.expression) | - TransformFlags.ContainsTypeScript; - return node; + function createNonNullChain(expression: Expression): NonNullChain { + return astFactory.createNonNullChain(asNode(expression).ast).node; } // @api - function updateNonNullChain(node: NonNullChain, expression: Expression) { - Debug.assert(!!(node.flags & NodeFlags.OptionalChain), "Cannot update a NonNullExpression using updateNonNullChain. Use updateNonNullExpression instead."); - return node.expression !== expression - ? update(createNonNullChain(expression), node) - : node; + function updateNonNullChain(node: NonNullChain, expression: Expression): NonNullChain { + return astFactory.updateNonNullChain(asNode(node).ast, asNode(expression).ast).node; } // @api - function createMetaProperty(keywordToken: MetaProperty["keywordToken"], name: Identifier) { - const node = createBaseNode(SyntaxKind.MetaProperty); - node.keywordToken = keywordToken; - node.name = name; - node.transformFlags |= propagateChildFlags(node.name); - switch (keywordToken) { - case SyntaxKind.NewKeyword: - node.transformFlags |= TransformFlags.ContainsES2015; - break; - case SyntaxKind.ImportKeyword: - node.transformFlags |= TransformFlags.ContainsES2020; - break; - default: - return Debug.assertNever(keywordToken); - } - - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createMetaProperty(keywordToken: MetaProperty["keywordToken"], name: Identifier): MetaProperty { + return astFactory.createMetaProperty(keywordToken, asNode(name).ast).node; } // @api - function updateMetaProperty(node: MetaProperty, name: Identifier) { - return node.name !== name - ? update(createMetaProperty(node.keywordToken, name), node) - : node; + function updateMetaProperty(node: MetaProperty, name: Identifier): MetaProperty { + return astFactory.updateMetaProperty(asNode(node).ast, asNode(name).ast).node; } // @@ -3820,29 +2322,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // // @api - function createTemplateSpan(expression: Expression, literal: TemplateMiddle | TemplateTail) { - const node = createBaseNode(SyntaxKind.TemplateSpan); - node.expression = expression; - node.literal = literal; - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildFlags(node.literal) | - TransformFlags.ContainsES2015; - return node; + function createTemplateSpan(expression: Expression, literal: TemplateMiddle | TemplateTail): TemplateSpan { + return astFactory.createTemplateSpan(asNode(expression).ast, asNode(literal).ast).node; } // @api - function updateTemplateSpan(node: TemplateSpan, expression: Expression, literal: TemplateMiddle | TemplateTail) { - return node.expression !== expression - || node.literal !== literal - ? update(createTemplateSpan(expression, literal), node) - : node; + function updateTemplateSpan(node: TemplateSpan, expression: Expression, literal: TemplateMiddle | TemplateTail): TemplateSpan { + return astFactory.updateTemplateSpan(asNode(node).ast, asNode(expression).ast, asNode(literal).ast).node; } // @api - function createSemicolonClassElement() { - const node = createBaseNode(SyntaxKind.SemicolonClassElement); - node.transformFlags |= TransformFlags.ContainsES2015; - return node; + function createSemicolonClassElement(): SemicolonClassElement { + return astFactory.createSemicolonClassElement().node; } // @@ -3851,446 +2342,202 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBlock(statements: readonly Statement[], multiLine?: boolean): Block { - const node = createBaseNode(SyntaxKind.Block); - node.statements = createNodeArray(statements); - node.multiLine = multiLine; - node.transformFlags |= propagateChildrenFlags(node.statements); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - return node; + return astFactory.createBlock(asNodeArray(statements).ast, multiLine).node; } // @api - function updateBlock(node: Block, statements: readonly Statement[]) { - return node.statements !== statements - ? update(createBlock(statements, node.multiLine), node) - : node; + function updateBlock(node: Block, statements: readonly Statement[]): Block { + return astFactory.updateBlock(asNode(node).ast, asNodeArray(statements).ast).node; } // @api - function createVariableStatement(modifiers: readonly ModifierLike[] | undefined, declarationList: VariableDeclarationList | readonly VariableDeclaration[]) { - const node = createBaseNode(SyntaxKind.VariableStatement); - node.modifiers = asNodeArray(modifiers); - node.declarationList = isArray(declarationList) ? createVariableDeclarationList(declarationList) : declarationList; - node.transformFlags |= propagateChildrenFlags(node.modifiers) | - propagateChildFlags(node.declarationList); - if (modifiersToFlags(node.modifiers) & ModifierFlags.Ambient) { - node.transformFlags = TransformFlags.ContainsTypeScript; - } - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createVariableStatement(modifiers: readonly ModifierLike[] | undefined, declarationList: VariableDeclarationList | readonly VariableDeclaration[]): VariableStatement { + return astFactory.createVariableStatement(asNodeArray(modifiers)?.ast, isArray(declarationList) ? asNodeArray(declarationList).ast : asNode(declarationList).ast).node; } // @api - function updateVariableStatement(node: VariableStatement, modifiers: readonly ModifierLike[] | undefined, declarationList: VariableDeclarationList) { - return node.modifiers !== modifiers - || node.declarationList !== declarationList - ? update(createVariableStatement(modifiers, declarationList), node) - : node; + function updateVariableStatement(node: VariableStatement, modifiers: readonly ModifierLike[] | undefined, declarationList: VariableDeclarationList): VariableStatement { + return astFactory.updateVariableStatement(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(declarationList).ast).node; } // @api - function createEmptyStatement() { - const node = createBaseNode(SyntaxKind.EmptyStatement); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + function createEmptyStatement(): EmptyStatement { + return astFactory.createEmptyStatement().node; } // @api function createExpressionStatement(expression: Expression): ExpressionStatement { - const node = createBaseNode(SyntaxKind.ExpressionStatement); - node.expression = parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression); - node.transformFlags |= propagateChildFlags(node.expression); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + return astFactory.createExpressionStatement(asNode(expression).ast).node; } // @api - function updateExpressionStatement(node: ExpressionStatement, expression: Expression) { - return node.expression !== expression - ? update(createExpressionStatement(expression), node) - : node; + function updateExpressionStatement(node: ExpressionStatement, expression: Expression): ExpressionStatement { + return astFactory.updateExpressionStatement(asNode(node).ast, asNode(expression).ast).node; } // @api - function createIfStatement(expression: Expression, thenStatement: Statement, elseStatement?: Statement) { - const node = createBaseNode(SyntaxKind.IfStatement); - node.expression = expression; - node.thenStatement = asEmbeddedStatement(thenStatement); - node.elseStatement = asEmbeddedStatement(elseStatement); - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildFlags(node.thenStatement) | - propagateChildFlags(node.elseStatement); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createIfStatement(expression: Expression, thenStatement: Statement, elseStatement?: Statement): IfStatement { + return astFactory.createIfStatement(asNode(expression).ast, asNode(thenStatement).ast, asNode(elseStatement)?.ast).node; } // @api - function updateIfStatement(node: IfStatement, expression: Expression, thenStatement: Statement, elseStatement: Statement | undefined) { - return node.expression !== expression - || node.thenStatement !== thenStatement - || node.elseStatement !== elseStatement - ? update(createIfStatement(expression, thenStatement, elseStatement), node) - : node; + function updateIfStatement(node: IfStatement, expression: Expression, thenStatement: Statement, elseStatement: Statement | undefined): IfStatement { + return astFactory.updateIfStatement(asNode(node).ast, asNode(expression).ast, asNode(thenStatement).ast, asNode(elseStatement)?.ast).node; } // @api - function createDoStatement(statement: Statement, expression: Expression) { - const node = createBaseNode(SyntaxKind.DoStatement); - node.statement = asEmbeddedStatement(statement); - node.expression = expression; - node.transformFlags |= propagateChildFlags(node.statement) | - propagateChildFlags(node.expression); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createDoStatement(statement: Statement, expression: Expression): DoStatement { + return astFactory.createDoStatement(asNode(statement).ast, asNode(expression).ast).node; } // @api - function updateDoStatement(node: DoStatement, statement: Statement, expression: Expression) { - return node.statement !== statement - || node.expression !== expression - ? update(createDoStatement(statement, expression), node) - : node; + function updateDoStatement(node: DoStatement, statement: Statement, expression: Expression): DoStatement { + return astFactory.updateDoStatement(asNode(node).ast, asNode(statement).ast, asNode(expression).ast).node; } // @api - function createWhileStatement(expression: Expression, statement: Statement) { - const node = createBaseNode(SyntaxKind.WhileStatement); - node.expression = expression; - node.statement = asEmbeddedStatement(statement); - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildFlags(node.statement); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createWhileStatement(expression: Expression, statement: Statement): WhileStatement { + return astFactory.createWhileStatement(asNode(expression).ast, asNode(statement).ast).node; } // @api - function updateWhileStatement(node: WhileStatement, expression: Expression, statement: Statement) { - return node.expression !== expression - || node.statement !== statement - ? update(createWhileStatement(expression, statement), node) - : node; + function updateWhileStatement(node: WhileStatement, expression: Expression, statement: Statement): WhileStatement { + return astFactory.updateWhileStatement(asNode(node).ast, asNode(expression).ast, asNode(statement).ast).node; } // @api - function createForStatement(initializer: ForInitializer | undefined, condition: Expression | undefined, incrementor: Expression | undefined, statement: Statement) { - const node = createBaseNode(SyntaxKind.ForStatement); - node.initializer = initializer; - node.condition = condition; - node.incrementor = incrementor; - node.statement = asEmbeddedStatement(statement); - node.transformFlags |= propagateChildFlags(node.initializer) | - propagateChildFlags(node.condition) | - propagateChildFlags(node.incrementor) | - propagateChildFlags(node.statement); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createForStatement(initializer: ForInitializer | undefined, condition: Expression | undefined, incrementor: Expression | undefined, statement: Statement): ForStatement { + return astFactory.createForStatement(asNode(initializer)?.ast, asNode(condition)?.ast, asNode(incrementor)?.ast, asNode(statement).ast).node; } // @api - function updateForStatement(node: ForStatement, initializer: ForInitializer | undefined, condition: Expression | undefined, incrementor: Expression | undefined, statement: Statement) { - return node.initializer !== initializer - || node.condition !== condition - || node.incrementor !== incrementor - || node.statement !== statement - ? update(createForStatement(initializer, condition, incrementor, statement), node) - : node; + function updateForStatement(node: ForStatement, initializer: ForInitializer | undefined, condition: Expression | undefined, incrementor: Expression | undefined, statement: Statement): ForStatement { + return astFactory.updateForStatement(asNode(node).ast, asNode(initializer)?.ast, asNode(condition)?.ast, asNode(incrementor)?.ast, asNode(statement).ast).node; } // @api - function createForInStatement(initializer: ForInitializer, expression: Expression, statement: Statement) { - const node = createBaseNode(SyntaxKind.ForInStatement); - node.initializer = initializer; - node.expression = expression; - node.statement = asEmbeddedStatement(statement); - node.transformFlags |= propagateChildFlags(node.initializer) | - propagateChildFlags(node.expression) | - propagateChildFlags(node.statement); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createForInStatement(initializer: ForInitializer, expression: Expression, statement: Statement): ForInStatement { + return astFactory.createForInStatement(asNode(initializer).ast, asNode(expression).ast, asNode(statement).ast).node; } // @api - function updateForInStatement(node: ForInStatement, initializer: ForInitializer, expression: Expression, statement: Statement) { - return node.initializer !== initializer - || node.expression !== expression - || node.statement !== statement - ? update(createForInStatement(initializer, expression, statement), node) - : node; + function updateForInStatement(node: ForInStatement, initializer: ForInitializer, expression: Expression, statement: Statement): ForInStatement { + return astFactory.updateForInStatement(asNode(node).ast, asNode(initializer).ast, asNode(expression).ast, asNode(statement).ast).node; } // @api - function createForOfStatement(awaitModifier: AwaitKeyword | undefined, initializer: ForInitializer, expression: Expression, statement: Statement) { - const node = createBaseNode(SyntaxKind.ForOfStatement); - node.awaitModifier = awaitModifier; - node.initializer = initializer; - node.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); - node.statement = asEmbeddedStatement(statement); - node.transformFlags |= propagateChildFlags(node.awaitModifier) | - propagateChildFlags(node.initializer) | - propagateChildFlags(node.expression) | - propagateChildFlags(node.statement) | - TransformFlags.ContainsES2015; - if (awaitModifier) node.transformFlags |= TransformFlags.ContainsES2018; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createForOfStatement(awaitModifier: AwaitKeyword | undefined, initializer: ForInitializer, expression: Expression, statement: Statement): ForOfStatement { + return astFactory.createForOfStatement(asNode(awaitModifier)?.ast, asNode(initializer).ast, asNode(expression).ast, asNode(statement).ast).node; } // @api - function updateForOfStatement(node: ForOfStatement, awaitModifier: AwaitKeyword | undefined, initializer: ForInitializer, expression: Expression, statement: Statement) { - return node.awaitModifier !== awaitModifier - || node.initializer !== initializer - || node.expression !== expression - || node.statement !== statement - ? update(createForOfStatement(awaitModifier, initializer, expression, statement), node) - : node; + function updateForOfStatement(node: ForOfStatement, awaitModifier: AwaitKeyword | undefined, initializer: ForInitializer, expression: Expression, statement: Statement): ForOfStatement { + return astFactory.updateForOfStatement(asNode(node).ast, asNode(awaitModifier)?.ast, asNode(initializer).ast, asNode(expression).ast, asNode(statement).ast).node; } // @api function createContinueStatement(label?: string | Identifier): ContinueStatement { - const node = createBaseNode(SyntaxKind.ContinueStatement); - node.label = asName(label); - node.transformFlags |= propagateChildFlags(node.label) | - TransformFlags.ContainsHoistedDeclarationOrCompletion; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + return astFactory.createContinueStatement(asName(label)?.ast).node; } // @api - function updateContinueStatement(node: ContinueStatement, label: Identifier | undefined) { - return node.label !== label - ? update(createContinueStatement(label), node) - : node; + function updateContinueStatement(node: ContinueStatement, label: Identifier | undefined): ContinueStatement { + return astFactory.updateContinueStatement(asNode(node).ast, asNode(label)?.ast).node; } // @api function createBreakStatement(label?: string | Identifier): BreakStatement { - const node = createBaseNode(SyntaxKind.BreakStatement); - node.label = asName(label); - node.transformFlags |= propagateChildFlags(node.label) | - TransformFlags.ContainsHoistedDeclarationOrCompletion; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + return astFactory.createBreakStatement(asName(label)?.ast).node; } // @api - function updateBreakStatement(node: BreakStatement, label: Identifier | undefined) { - return node.label !== label - ? update(createBreakStatement(label), node) - : node; + function updateBreakStatement(node: BreakStatement, label: Identifier | undefined): BreakStatement { + return astFactory.updateBreakStatement(asNode(node).ast, asNode(label)?.ast).node; } // @api function createReturnStatement(expression?: Expression): ReturnStatement { - const node = createBaseNode(SyntaxKind.ReturnStatement); - node.expression = expression; - // return in an ES2018 async generator must be awaited - node.transformFlags |= propagateChildFlags(node.expression) | - TransformFlags.ContainsES2018 | - TransformFlags.ContainsHoistedDeclarationOrCompletion; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + return astFactory.createReturnStatement(asNode(expression)?.ast).node; } // @api - function updateReturnStatement(node: ReturnStatement, expression: Expression | undefined) { - return node.expression !== expression - ? update(createReturnStatement(expression), node) - : node; + function updateReturnStatement(node: ReturnStatement, expression: Expression | undefined): ReturnStatement { + return astFactory.updateReturnStatement(asNode(node).ast, asNode(expression)?.ast).node; } // @api - function createWithStatement(expression: Expression, statement: Statement) { - const node = createBaseNode(SyntaxKind.WithStatement); - node.expression = expression; - node.statement = asEmbeddedStatement(statement); - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildFlags(node.statement); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createWithStatement(expression: Expression, statement: Statement): WithStatement { + return astFactory.createWithStatement(asNode(expression).ast, asNode(statement).ast).node; } // @api - function updateWithStatement(node: WithStatement, expression: Expression, statement: Statement) { - return node.expression !== expression - || node.statement !== statement - ? update(createWithStatement(expression, statement), node) - : node; + function updateWithStatement(node: WithStatement, expression: Expression, statement: Statement): WithStatement { + return astFactory.updateWithStatement(asNode(node).ast, asNode(expression).ast, asNode(statement).ast).node; } // @api function createSwitchStatement(expression: Expression, caseBlock: CaseBlock): SwitchStatement { - const node = createBaseNode(SyntaxKind.SwitchStatement); - node.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); - node.caseBlock = caseBlock; - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildFlags(node.caseBlock); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - node.possiblyExhaustive = false; // initialized by binder - return node; + return astFactory.createSwitchStatement(asNode(expression).ast, asNode(caseBlock).ast).node; } // @api - function updateSwitchStatement(node: SwitchStatement, expression: Expression, caseBlock: CaseBlock) { - return node.expression !== expression - || node.caseBlock !== caseBlock - ? update(createSwitchStatement(expression, caseBlock), node) - : node; + function updateSwitchStatement(node: SwitchStatement, expression: Expression, caseBlock: CaseBlock): SwitchStatement { + return astFactory.updateSwitchStatement(asNode(node).ast, asNode(expression).ast, asNode(caseBlock).ast).node; } // @api - function createLabeledStatement(label: string | Identifier, statement: Statement) { - const node = createBaseNode(SyntaxKind.LabeledStatement); - node.label = asName(label); - node.statement = asEmbeddedStatement(statement); - node.transformFlags |= propagateChildFlags(node.label) | - propagateChildFlags(node.statement); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createLabeledStatement(label: string | Identifier, statement: Statement): LabeledStatement { + return astFactory.createLabeledStatement(asName(label).ast, asNode(statement).ast).node; } // @api - function updateLabeledStatement(node: LabeledStatement, label: Identifier, statement: Statement) { - return node.label !== label - || node.statement !== statement - ? update(createLabeledStatement(label, statement), node) - : node; + function updateLabeledStatement(node: LabeledStatement, label: Identifier, statement: Statement): LabeledStatement { + return astFactory.updateLabeledStatement(asNode(node).ast, asNode(label).ast, asNode(statement).ast).node; } // @api - function createThrowStatement(expression: Expression) { - const node = createBaseNode(SyntaxKind.ThrowStatement); - node.expression = expression; - node.transformFlags |= propagateChildFlags(node.expression); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createThrowStatement(expression: Expression): ThrowStatement { + return astFactory.createThrowStatement(asNode(expression).ast).node; } // @api - function updateThrowStatement(node: ThrowStatement, expression: Expression) { - return node.expression !== expression - ? update(createThrowStatement(expression), node) - : node; + function updateThrowStatement(node: ThrowStatement, expression: Expression): ThrowStatement { + return astFactory.updateThrowStatement(asNode(node).ast, asNode(expression).ast).node; } // @api - function createTryStatement(tryBlock: Block, catchClause: CatchClause | undefined, finallyBlock: Block | undefined) { - const node = createBaseNode(SyntaxKind.TryStatement); - node.tryBlock = tryBlock; - node.catchClause = catchClause; - node.finallyBlock = finallyBlock; - node.transformFlags |= propagateChildFlags(node.tryBlock) | - propagateChildFlags(node.catchClause) | - propagateChildFlags(node.finallyBlock); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createTryStatement(tryBlock: Block, catchClause: CatchClause | undefined, finallyBlock: Block | undefined): TryStatement { + return astFactory.createTryStatement(asNode(tryBlock).ast, asNode(catchClause)?.ast, asNode(finallyBlock)?.ast).node; } // @api - function updateTryStatement(node: TryStatement, tryBlock: Block, catchClause: CatchClause | undefined, finallyBlock: Block | undefined) { - return node.tryBlock !== tryBlock - || node.catchClause !== catchClause - || node.finallyBlock !== finallyBlock - ? update(createTryStatement(tryBlock, catchClause, finallyBlock), node) - : node; + function updateTryStatement(node: TryStatement, tryBlock: Block, catchClause: CatchClause | undefined, finallyBlock: Block | undefined): TryStatement { + return astFactory.updateTryStatement(asNode(node).ast, asNode(tryBlock).ast, asNode(catchClause)?.ast, asNode(finallyBlock)?.ast).node; } // @api - function createDebuggerStatement() { - const node = createBaseNode(SyntaxKind.DebuggerStatement); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - return node; + function createDebuggerStatement(): DebuggerStatement { + return astFactory.createDebuggerStatement().node; } // @api - function createVariableDeclaration(name: string | BindingName, exclamationToken: ExclamationToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined) { - const node = createBaseDeclaration(SyntaxKind.VariableDeclaration); - node.name = asName(name); - node.exclamationToken = exclamationToken; - node.type = type; - node.initializer = asInitializer(initializer); - node.transformFlags |= propagateNameFlags(node.name) | - propagateChildFlags(node.initializer) | - (node.exclamationToken ?? node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + function createVariableDeclaration(name: string | BindingName, exclamationToken: ExclamationToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): VariableDeclaration { + return astFactory.createVariableDeclaration(asName(name).ast, asNode(exclamationToken)?.ast, asNode(type)?.ast, asNode(initializer)?.ast).node; } // @api - function updateVariableDeclaration(node: VariableDeclaration, name: BindingName, exclamationToken: ExclamationToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined) { - return node.name !== name - || node.type !== type - || node.exclamationToken !== exclamationToken - || node.initializer !== initializer - ? update(createVariableDeclaration(name, exclamationToken, type, initializer), node) - : node; + function updateVariableDeclaration(node: VariableDeclaration, name: BindingName, exclamationToken: ExclamationToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): VariableDeclaration { + return astFactory.updateVariableDeclaration(asNode(node).ast, asNode(name).ast, asNode(exclamationToken)?.ast, asNode(type)?.ast, asNode(initializer)?.ast).node; } // @api - function createVariableDeclarationList(declarations: readonly VariableDeclaration[], flags = NodeFlags.None) { - const node = createBaseNode(SyntaxKind.VariableDeclarationList); - node.flags |= flags & NodeFlags.BlockScoped; - node.declarations = createNodeArray(declarations); - node.transformFlags |= propagateChildrenFlags(node.declarations) | - TransformFlags.ContainsHoistedDeclarationOrCompletion; - if (flags & NodeFlags.BlockScoped) { - node.transformFlags |= TransformFlags.ContainsES2015 | - TransformFlags.ContainsBlockScopedBinding; - } - if (flags & NodeFlags.Using) { - node.transformFlags |= TransformFlags.ContainsESNext; - } - return node; + function createVariableDeclarationList(declarations: readonly VariableDeclaration[], flags = NodeFlags.None): VariableDeclarationList { + return astFactory.createVariableDeclarationList(asNodeArray(declarations).ast, flags).node; } // @api - function updateVariableDeclarationList(node: VariableDeclarationList, declarations: readonly VariableDeclaration[]) { - return node.declarations !== declarations - ? update(createVariableDeclarationList(declarations, node.flags), node) - : node; + function updateVariableDeclarationList(node: VariableDeclarationList, declarations: readonly VariableDeclaration[]): VariableDeclarationList { + return astFactory.updateVariableDeclarationList(asNode(node).ast, asNodeArray(declarations).ast).node; } // @api @@ -4302,46 +2549,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, body: Block | undefined, - ) { - const node = createBaseDeclaration(SyntaxKind.FunctionDeclaration); - node.modifiers = asNodeArray(modifiers); - node.asteriskToken = asteriskToken; - node.name = asName(name); - node.typeParameters = asNodeArray(typeParameters); - node.parameters = createNodeArray(parameters); - node.type = type; - node.body = body; - - if (!node.body || modifiersToFlags(node.modifiers) & ModifierFlags.Ambient) { - node.transformFlags = TransformFlags.ContainsTypeScript; - } - else { - const isAsync = modifiersToFlags(node.modifiers) & ModifierFlags.Async; - const isGenerator = !!node.asteriskToken; - const isAsyncGenerator = isAsync && isGenerator; - - node.transformFlags = propagateChildrenFlags(node.modifiers) | - propagateChildFlags(node.asteriskToken) | - propagateNameFlags(node.name) | - propagateChildrenFlags(node.typeParameters) | - propagateChildrenFlags(node.parameters) | - propagateChildFlags(node.type) | - (propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | - (isAsyncGenerator ? TransformFlags.ContainsES2018 : - isAsync ? TransformFlags.ContainsES2017 : - isGenerator ? TransformFlags.ContainsGenerator : - TransformFlags.None) | - (node.typeParameters || node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | - TransformFlags.ContainsHoistedDeclarationOrCompletion; - } - - node.typeArguments = undefined; // used in quick info - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.endFlowNode = undefined; - node.returnFlowNode = undefined; - return node; + ): FunctionDeclaration { + return astFactory.createFunctionDeclaration(asNodeArray(modifiers)?.ast, asNode(asteriskToken)?.ast, asName(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body)?.ast).node; } // @api @@ -4354,26 +2563,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, body: Block | undefined, - ) { - return node.modifiers !== modifiers - || node.asteriskToken !== asteriskToken - || node.name !== name - || node.typeParameters !== typeParameters - || node.parameters !== parameters - || node.type !== type - || node.body !== body - ? finishUpdateFunctionDeclaration(createFunctionDeclaration(modifiers, asteriskToken, name, typeParameters, parameters, type, body), node) - : node; - } - - function finishUpdateFunctionDeclaration(updated: Mutable, original: FunctionDeclaration) { - if (updated !== original) { - // copy children used only for error reporting - if (updated.modifiers === original.modifiers) { - updated.modifiers = original.modifiers; - } - } - return finishUpdateBaseSignatureDeclaration(updated, original); + ): FunctionDeclaration { + return astFactory.updateFunctionDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(asteriskToken)?.ast, asNode(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body)?.ast).node; } // @api @@ -4383,32 +2574,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: readonly TypeParameterDeclaration[] | undefined, heritageClauses: readonly HeritageClause[] | undefined, members: readonly ClassElement[], - ) { - const node = createBaseDeclaration(SyntaxKind.ClassDeclaration); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.typeParameters = asNodeArray(typeParameters); - node.heritageClauses = asNodeArray(heritageClauses); - node.members = createNodeArray(members); - - if (modifiersToFlags(node.modifiers) & ModifierFlags.Ambient) { - node.transformFlags = TransformFlags.ContainsTypeScript; - } - else { - node.transformFlags |= propagateChildrenFlags(node.modifiers) | - propagateNameFlags(node.name) | - propagateChildrenFlags(node.typeParameters) | - propagateChildrenFlags(node.heritageClauses) | - propagateChildrenFlags(node.members) | - (node.typeParameters ? TransformFlags.ContainsTypeScript : TransformFlags.None) | - TransformFlags.ContainsES2015; - if (node.transformFlags & TransformFlags.ContainsTypeScriptClassSyntax) { - node.transformFlags |= TransformFlags.ContainsTypeScript; - } - } - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + ): ClassDeclaration { + return astFactory.createClassDeclaration(asNodeArray(modifiers)?.ast, asName(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(heritageClauses)?.ast, asNodeArray(members).ast).node; } // @api @@ -4419,14 +2586,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: readonly TypeParameterDeclaration[] | undefined, heritageClauses: readonly HeritageClause[] | undefined, members: readonly ClassElement[], - ) { - return node.modifiers !== modifiers - || node.name !== name - || node.typeParameters !== typeParameters - || node.heritageClauses !== heritageClauses - || node.members !== members - ? update(createClassDeclaration(modifiers, name, typeParameters, heritageClauses, members), node) - : node; + ): ClassDeclaration { + return astFactory.updateClassDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(heritageClauses)?.ast, asNodeArray(members).ast).node; } // @api @@ -4436,17 +2597,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: readonly TypeParameterDeclaration[] | undefined, heritageClauses: readonly HeritageClause[] | undefined, members: readonly TypeElement[], - ) { - const node = createBaseDeclaration(SyntaxKind.InterfaceDeclaration); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.typeParameters = asNodeArray(typeParameters); - node.heritageClauses = asNodeArray(heritageClauses); - node.members = createNodeArray(members); - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + ): InterfaceDeclaration { + return astFactory.createInterfaceDeclaration(asNodeArray(modifiers)?.ast, asName(name).ast, asNodeArray(typeParameters)?.ast, asNodeArray(heritageClauses)?.ast, asNodeArray(members).ast).node; } // @api @@ -4457,14 +2609,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: readonly TypeParameterDeclaration[] | undefined, heritageClauses: readonly HeritageClause[] | undefined, members: readonly TypeElement[], - ) { - return node.modifiers !== modifiers - || node.name !== name - || node.typeParameters !== typeParameters - || node.heritageClauses !== heritageClauses - || node.members !== members - ? update(createInterfaceDeclaration(modifiers, name, typeParameters, heritageClauses, members), node) - : node; + ): InterfaceDeclaration { + return astFactory.updateInterfaceDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNodeArray(typeParameters)?.ast, asNodeArray(heritageClauses)?.ast, asNodeArray(members).ast).node; } // @api @@ -4473,18 +2619,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: string | Identifier, typeParameters: readonly TypeParameterDeclaration[] | undefined, type: TypeNode, - ) { - const node = createBaseDeclaration(SyntaxKind.TypeAliasDeclaration); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.typeParameters = asNodeArray(typeParameters); - node.type = type; - node.transformFlags = TransformFlags.ContainsTypeScript; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - return node; + ): TypeAliasDeclaration { + return astFactory.createTypeAliasDeclaration(asNodeArray(modifiers)?.ast, asName(name).ast, asNodeArray(typeParameters)?.ast, asNode(type).ast).node; } // @api @@ -4494,13 +2630,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: Identifier, typeParameters: readonly TypeParameterDeclaration[] | undefined, type: TypeNode, - ) { - return node.modifiers !== modifiers - || node.name !== name - || node.typeParameters !== typeParameters - || node.type !== type - ? update(createTypeAliasDeclaration(modifiers, name, typeParameters, type), node) - : node; + ): TypeAliasDeclaration { + return astFactory.updateTypeAliasDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNodeArray(typeParameters)?.ast, asNode(type).ast).node; } // @api @@ -4508,19 +2639,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode modifiers: readonly ModifierLike[] | undefined, name: string | Identifier, members: readonly EnumMember[], - ) { - const node = createBaseDeclaration(SyntaxKind.EnumDeclaration); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.members = createNodeArray(members); - node.transformFlags |= propagateChildrenFlags(node.modifiers) | - propagateChildFlags(node.name) | - propagateChildrenFlags(node.members) | - TransformFlags.ContainsTypeScript; - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Enum declarations cannot contain `await` - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + ): EnumDeclaration { + return astFactory.createEnumDeclaration(asNodeArray(modifiers)?.ast, asName(name).ast, asNodeArray(members).ast).node; } // @api @@ -4529,12 +2649,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode modifiers: readonly ModifierLike[] | undefined, name: Identifier, members: readonly EnumMember[], - ) { - return node.modifiers !== modifiers - || node.name !== name - || node.members !== members - ? update(createEnumDeclaration(modifiers, name, members), node) - : node; + ): EnumDeclaration { + return astFactory.updateEnumDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNodeArray(members).ast).node; } // @api @@ -4543,27 +2659,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: ModuleName, body: ModuleBody | undefined, flags = NodeFlags.None, - ) { - const node = createBaseDeclaration(SyntaxKind.ModuleDeclaration); - node.modifiers = asNodeArray(modifiers); - node.flags |= flags & (NodeFlags.Namespace | NodeFlags.NestedNamespace | NodeFlags.GlobalAugmentation); - node.name = name; - node.body = body; - if (modifiersToFlags(node.modifiers) & ModifierFlags.Ambient) { - node.transformFlags = TransformFlags.ContainsTypeScript; - } - else { - node.transformFlags |= propagateChildrenFlags(node.modifiers) | - propagateChildFlags(node.name) | - propagateChildFlags(node.body) | - TransformFlags.ContainsTypeScript; - } - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Module declarations cannot contain `await`. - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - return node; + ): ModuleDeclaration { + return astFactory.createModuleDeclaration(asNodeArray(modifiers)?.ast, asNode(name).ast, asNode(body)?.ast, flags).node; } // @api @@ -4572,74 +2669,38 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode modifiers: readonly ModifierLike[] | undefined, name: ModuleName, body: ModuleBody | undefined, - ) { - return node.modifiers !== modifiers - || node.name !== name - || node.body !== body - ? update(createModuleDeclaration(modifiers, name, body, node.flags), node) - : node; + ): ModuleDeclaration { + return astFactory.updateModuleDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNode(body)?.ast).node; } // @api - function createModuleBlock(statements: readonly Statement[]) { - const node = createBaseNode(SyntaxKind.ModuleBlock); - node.statements = createNodeArray(statements); - node.transformFlags |= propagateChildrenFlags(node.statements); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + function createModuleBlock(statements: readonly Statement[]): ModuleBlock { + return astFactory.createModuleBlock(asNodeArray(statements).ast).node; } // @api function updateModuleBlock(node: ModuleBlock, statements: readonly Statement[]) { - return node.statements !== statements - ? update(createModuleBlock(statements), node) - : node; + return astFactory.updateModuleBlock(asNode(node).ast, asNodeArray(statements).ast).node; } // @api function createCaseBlock(clauses: readonly CaseOrDefaultClause[]): CaseBlock { - const node = createBaseNode(SyntaxKind.CaseBlock); - node.clauses = createNodeArray(clauses); - node.transformFlags |= propagateChildrenFlags(node.clauses); - - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - return node; + return astFactory.createCaseBlock(asNodeArray(clauses).ast).node; } // @api - function updateCaseBlock(node: CaseBlock, clauses: readonly CaseOrDefaultClause[]) { - return node.clauses !== clauses - ? update(createCaseBlock(clauses), node) - : node; + function updateCaseBlock(node: CaseBlock, clauses: readonly CaseOrDefaultClause[]): CaseBlock { + return astFactory.updateCaseBlock(asNode(node).ast, asNodeArray(clauses).ast).node; } // @api - function createNamespaceExportDeclaration(name: string | Identifier) { - const node = createBaseDeclaration(SyntaxKind.NamespaceExportDeclaration); - node.name = asName(name); - node.transformFlags |= propagateIdentifierNameFlags(node.name) | - TransformFlags.ContainsTypeScript; - - node.modifiers = undefined; // initialized by parser to report grammar errors - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + function createNamespaceExportDeclaration(name: string | Identifier): NamespaceExportDeclaration { + return astFactory.createNamespaceExportDeclaration(asName(name).ast).node; } // @api - function updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier) { - return node.name !== name - ? finishUpdateNamespaceExportDeclaration(createNamespaceExportDeclaration(name), node) - : node; - } - - function finishUpdateNamespaceExportDeclaration(updated: Mutable, original: NamespaceExportDeclaration) { - if (updated !== original) { - // copy children used only for error reporting - updated.modifiers = original.modifiers; - } - return update(updated, original); + function updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration { + return astFactory.updateNamespaceExportDeclaration(asNode(node).ast, asNode(name).ast).node; } // @api @@ -4648,24 +2709,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode isTypeOnly: boolean, name: string | Identifier, moduleReference: ModuleReference, - ) { - const node = createBaseDeclaration(SyntaxKind.ImportEqualsDeclaration); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.isTypeOnly = isTypeOnly; - node.moduleReference = moduleReference; - node.transformFlags |= propagateChildrenFlags(node.modifiers) | - propagateIdentifierNameFlags(node.name) | - propagateChildFlags(node.moduleReference); - - if (!isExternalModuleReference(node.moduleReference)) { - node.transformFlags |= TransformFlags.ContainsTypeScript; - } - - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Import= declaration is always parsed in an Await context - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + ): ImportEqualsDeclaration { + return astFactory.createImportEqualsDeclaration(asNodeArray(modifiers)?.ast, isTypeOnly, asName(name).ast, asNode(moduleReference).ast).node; } // @api @@ -4675,13 +2720,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference, - ) { - return node.modifiers !== modifiers - || node.isTypeOnly !== isTypeOnly - || node.name !== name - || node.moduleReference !== moduleReference - ? update(createImportEqualsDeclaration(modifiers, isTypeOnly, name, moduleReference), node) - : node; + ): ImportEqualsDeclaration { + return astFactory.updateImportEqualsDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, isTypeOnly, asNode(name).ast, asNode(moduleReference).ast).node; } // @api @@ -4691,17 +2731,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode moduleSpecifier: Expression, attributes: ImportAttributes | undefined, ): ImportDeclaration { - const node = createBaseNode(SyntaxKind.ImportDeclaration); - node.modifiers = asNodeArray(modifiers); - node.importClause = importClause; - node.moduleSpecifier = moduleSpecifier; - node.attributes = node.assertClause = attributes; - node.transformFlags |= propagateChildFlags(node.importClause) | - propagateChildFlags(node.moduleSpecifier); - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + return astFactory.createImportDeclaration(asNodeArray(modifiers)?.ast, asNode(importClause)?.ast, asNode(moduleSpecifier).ast, asNode(attributes)?.ast).node; } // @api @@ -4711,195 +2741,110 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes: ImportAttributes | undefined, - ) { - return node.modifiers !== modifiers - || node.importClause !== importClause - || node.moduleSpecifier !== moduleSpecifier - || node.attributes !== attributes - ? update(createImportDeclaration(modifiers, importClause, moduleSpecifier, attributes), node) - : node; + ): ImportDeclaration { + return astFactory.updateImportDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(importClause)?.ast, asNode(moduleSpecifier).ast, asNode(attributes)?.ast).node; } // @api function createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause { - const node = createBaseDeclaration(SyntaxKind.ImportClause); - node.isTypeOnly = isTypeOnly; - node.name = name; - node.namedBindings = namedBindings; - node.transformFlags |= propagateChildFlags(node.name) | - propagateChildFlags(node.namedBindings); - if (isTypeOnly) { - node.transformFlags |= TransformFlags.ContainsTypeScript; - } - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - return node; + return astFactory.createImportClause(isTypeOnly, asNode(name)?.ast, asNode(namedBindings)?.ast).node; } // @api - function updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined) { - return node.isTypeOnly !== isTypeOnly - || node.name !== name - || node.namedBindings !== namedBindings - ? update(createImportClause(isTypeOnly, name, namedBindings), node) - : node; + function updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause { + return astFactory.updateImportClause(asNode(node).ast, isTypeOnly, asNode(name)?.ast, asNode(namedBindings)?.ast).node; } // @api function createAssertClause(elements: readonly AssertEntry[], multiLine?: boolean): AssertClause { - const node = createBaseNode(SyntaxKind.AssertClause); - node.elements = createNodeArray(elements); - node.multiLine = multiLine; - node.token = SyntaxKind.AssertKeyword; - node.transformFlags |= TransformFlags.ContainsESNext; - return node; + return astFactory.createAssertClause(asNodeArray(elements).ast, multiLine).node; } // @api function updateAssertClause(node: AssertClause, elements: readonly AssertEntry[], multiLine?: boolean): AssertClause { - return node.elements !== elements - || node.multiLine !== multiLine - ? update(createAssertClause(elements, multiLine), node) - : node; + return astFactory.updateAssertClause(asNode(node).ast, asNodeArray(elements).ast, multiLine).node; } // @api - function createAssertEntry(name: AssertionKey, value: Expression): AssertEntry { - const node = createBaseNode(SyntaxKind.AssertEntry); - node.name = name; - node.value = value; - node.transformFlags |= TransformFlags.ContainsESNext; - return node; + function createAssertEntry(name: AssertionKey, value: Expression) { + return astFactory.createAssertEntry(asNode(name).ast, asNode(value).ast).node; } // @api - function updateAssertEntry(node: AssertEntry, name: AssertionKey, value: Expression): AssertEntry { - return node.name !== name - || node.value !== value - ? update(createAssertEntry(name, value), node) - : node; + function updateAssertEntry(node: AssertEntry, name: AssertionKey, value: Expression) { + return astFactory.updateAssertEntry(asNode(node).ast, asNode(name).ast, asNode(value).ast).node; } // @api function createImportTypeAssertionContainer(clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer { - const node = createBaseNode(SyntaxKind.ImportTypeAssertionContainer); - node.assertClause = clause; - node.multiLine = multiLine; - return node; + return astFactory.createImportTypeAssertionContainer(asNode(clause).ast, multiLine).node; } // @api function updateImportTypeAssertionContainer(node: ImportTypeAssertionContainer, clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer { - return node.assertClause !== clause - || node.multiLine !== multiLine - ? update(createImportTypeAssertionContainer(clause, multiLine), node) - : node; + return astFactory.updateImportTypeAssertionContainer(asNode(node).ast, asNode(clause).ast, multiLine).node; } // @api function createImportAttributes(elements: readonly ImportAttribute[], multiLine?: boolean): ImportAttributes; function createImportAttributes(elements: readonly ImportAttribute[], multiLine?: boolean, token?: ImportAttributes["token"]): ImportAttributes; - function createImportAttributes(elements: readonly ImportAttribute[], multiLine?: boolean, token?: ImportAttributes["token"]): ImportAttributes { - const node = createBaseNode(SyntaxKind.ImportAttributes); - node.token = token ?? SyntaxKind.WithKeyword; - node.elements = createNodeArray(elements); - node.multiLine = multiLine; - node.transformFlags |= TransformFlags.ContainsESNext; - return node; + function createImportAttributes(elements: readonly ImportAttribute[], multiLine?: boolean, token?: ImportAttributes["token"]) { + return astFactory.createImportAttributes(asNodeArray(elements).ast, multiLine, token).node; } // @api function updateImportAttributes(node: ImportAttributes, elements: readonly ImportAttribute[], multiLine?: boolean): ImportAttributes { - return node.elements !== elements - || node.multiLine !== multiLine - ? update(createImportAttributes(elements, multiLine, node.token), node) - : node; + return astFactory.updateImportAttributes(asNode(node).ast, asNodeArray(elements).ast, multiLine).node; } // @api - function createImportAttribute(name: ImportAttributeName, value: Expression): ImportAttribute { - const node = createBaseNode(SyntaxKind.ImportAttribute); - node.name = name; - node.value = value; - node.transformFlags |= TransformFlags.ContainsESNext; - return node; + function createImportAttribute(name: ImportAttributeName, value: Expression) { + return astFactory.createImportAttribute(asNode(name).ast, asNode(value).ast).node; } // @api - function updateImportAttribute(node: ImportAttribute, name: ImportAttributeName, value: Expression): ImportAttribute { - return node.name !== name - || node.value !== value - ? update(createImportAttribute(name, value), node) - : node; + function updateImportAttribute(node: ImportAttribute, name: ImportAttributeName, value: Expression) { + return astFactory.updateImportAttribute(asNode(node).ast, asNode(name).ast, asNode(value).ast).node; } // @api function createNamespaceImport(name: Identifier): NamespaceImport { - const node = createBaseDeclaration(SyntaxKind.NamespaceImport); - node.name = name; - node.transformFlags |= propagateChildFlags(node.name); - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - return node; + return astFactory.createNamespaceImport(asNode(name).ast).node; } // @api - function updateNamespaceImport(node: NamespaceImport, name: Identifier) { - return node.name !== name - ? update(createNamespaceImport(name), node) - : node; + function updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport { + return astFactory.updateNamespaceImport(asNode(node).ast, asNode(name).ast).node; } // @api function createNamespaceExport(name: ModuleExportName): NamespaceExport { - const node = createBaseDeclaration(SyntaxKind.NamespaceExport); - node.name = name; - node.transformFlags |= propagateChildFlags(node.name) | - TransformFlags.ContainsES2020; - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - return node; + return astFactory.createNamespaceExport(asNode(name).ast).node; } // @api - function updateNamespaceExport(node: NamespaceExport, name: ModuleExportName) { - return node.name !== name - ? update(createNamespaceExport(name), node) - : node; + function updateNamespaceExport(node: NamespaceExport, name: ModuleExportName): NamespaceExport { + return astFactory.updateNamespaceExport(asNode(node).ast, asNode(name).ast).node; } // @api function createNamedImports(elements: readonly ImportSpecifier[]): NamedImports { - const node = createBaseNode(SyntaxKind.NamedImports); - node.elements = createNodeArray(elements); - node.transformFlags |= propagateChildrenFlags(node.elements); - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - return node; + return astFactory.createNamedImports(asNodeArray(elements).ast).node; } // @api - function updateNamedImports(node: NamedImports, elements: readonly ImportSpecifier[]) { - return node.elements !== elements - ? update(createNamedImports(elements), node) - : node; + function updateNamedImports(node: NamedImports, elements: readonly ImportSpecifier[]): NamedImports { + return astFactory.updateNamedImports(asNode(node).ast, asNodeArray(elements).ast).node; } // @api - function createImportSpecifier(isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier) { - const node = createBaseDeclaration(SyntaxKind.ImportSpecifier); - node.isTypeOnly = isTypeOnly; - node.propertyName = propertyName; - node.name = name; - node.transformFlags |= propagateChildFlags(node.propertyName) | - propagateChildFlags(node.name); - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - return node; + function createImportSpecifier(isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier): ImportSpecifier { + return astFactory.createImportSpecifier(isTypeOnly, asNode(propertyName)?.ast, asNode(name).ast).node; } // @api - function updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier) { - return node.isTypeOnly !== isTypeOnly - || node.propertyName !== propertyName - || node.name !== name - ? update(createImportSpecifier(isTypeOnly, propertyName, name), node) - : node; + function updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier): ImportSpecifier { + return astFactory.updateImportSpecifier(asNode(node).ast, isTypeOnly, asNode(propertyName)?.ast, asNode(name).ast).node; } // @api @@ -4907,18 +2852,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode modifiers: readonly ModifierLike[] | undefined, isExportEquals: boolean | undefined, expression: Expression, - ) { - const node = createBaseDeclaration(SyntaxKind.ExportAssignment); - node.modifiers = asNodeArray(modifiers); - node.isExportEquals = isExportEquals; - node.expression = isExportEquals - ? parenthesizerRules().parenthesizeRightSideOfBinary(SyntaxKind.EqualsToken, /*leftSide*/ undefined, expression) - : parenthesizerRules().parenthesizeExpressionOfExportDefault(expression); - node.transformFlags |= propagateChildrenFlags(node.modifiers) | propagateChildFlags(node.expression); - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + ): ExportAssignment { + return astFactory.createExportAssignment(asNodeArray(modifiers)?.ast, isExportEquals, asNode(expression).ast).node; } // @api @@ -4926,11 +2861,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node: ExportAssignment, modifiers: readonly ModifierLike[] | undefined, expression: Expression, - ) { - return node.modifiers !== modifiers - || node.expression !== expression - ? update(createExportAssignment(modifiers, node.isExportEquals, expression), node) - : node; + ): ExportAssignment { + return astFactory.updateExportAssignment(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(expression).ast).node; } // @api @@ -4940,20 +2872,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, attributes?: ImportAttributes, - ) { - const node = createBaseDeclaration(SyntaxKind.ExportDeclaration); - node.modifiers = asNodeArray(modifiers); - node.isTypeOnly = isTypeOnly; - node.exportClause = exportClause; - node.moduleSpecifier = moduleSpecifier; - node.attributes = node.assertClause = attributes; - node.transformFlags |= propagateChildrenFlags(node.modifiers) | - propagateChildFlags(node.exportClause) | - propagateChildFlags(node.moduleSpecifier); - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + ): ExportDeclaration { + return astFactory.createExportDeclaration(asNodeArray(modifiers)?.ast, isTypeOnly, asNode(exportClause)?.ast, asNode(moduleSpecifier)?.ast, asNode(attributes)?.ast).node; } // @api @@ -4964,71 +2884,33 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, attributes: ImportAttributes | undefined, - ) { - return node.modifiers !== modifiers - || node.isTypeOnly !== isTypeOnly - || node.exportClause !== exportClause - || node.moduleSpecifier !== moduleSpecifier - || node.attributes !== attributes - ? finishUpdateExportDeclaration(createExportDeclaration(modifiers, isTypeOnly, exportClause, moduleSpecifier, attributes), node) - : node; - } - - function finishUpdateExportDeclaration(updated: Mutable, original: ExportDeclaration) { - if (updated !== original) { - // copy children used only for error reporting - if (updated.modifiers === original.modifiers) { - updated.modifiers = original.modifiers; - } - } - return update(updated, original); + ): ExportDeclaration { + return astFactory.updateExportDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, isTypeOnly, asNode(exportClause)?.ast, asNode(moduleSpecifier)?.ast, asNode(attributes)?.ast).node; } // @api - function createNamedExports(elements: readonly ExportSpecifier[]) { - const node = createBaseNode(SyntaxKind.NamedExports); - node.elements = createNodeArray(elements); - node.transformFlags |= propagateChildrenFlags(node.elements); - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - return node; + function createNamedExports(elements: readonly ExportSpecifier[]): NamedExports { + return astFactory.createNamedExports(asNodeArray(elements).ast).node; } // @api - function updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]) { - return node.elements !== elements - ? update(createNamedExports(elements), node) - : node; + function updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports { + return astFactory.updateNamedExports(asNode(node).ast, asNodeArray(elements).ast).node; } // @api - function createExportSpecifier(isTypeOnly: boolean, propertyName: string | ModuleExportName | undefined, name: string | ModuleExportName) { - const node = createBaseNode(SyntaxKind.ExportSpecifier); - node.isTypeOnly = isTypeOnly; - node.propertyName = asName(propertyName); - node.name = asName(name); - node.transformFlags |= propagateChildFlags(node.propertyName) | - propagateChildFlags(node.name); - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + function createExportSpecifier(isTypeOnly: boolean, propertyName: string | ModuleExportName | undefined, name: string | ModuleExportName): ExportSpecifier { + return astFactory.createExportSpecifier(isTypeOnly, asName(propertyName)?.ast, asName(name).ast).node; } // @api - function updateExportSpecifier(node: ExportSpecifier, isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: ModuleExportName) { - return node.isTypeOnly !== isTypeOnly - || node.propertyName !== propertyName - || node.name !== name - ? update(createExportSpecifier(isTypeOnly, propertyName, name), node) - : node; + function updateExportSpecifier(node: ExportSpecifier, isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: ModuleExportName): ExportSpecifier { + return astFactory.updateExportSpecifier(asNode(node).ast, isTypeOnly, asNode(propertyName)?.ast, asNode(name).ast).node; } // @api function createMissingDeclaration(): MissingDeclaration { - const node = createBaseDeclaration(SyntaxKind.MissingDeclaration); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + return astFactory.createMissingDeclaration().node; } // @@ -5036,19 +2918,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // // @api - function createExternalModuleReference(expression: Expression) { - const node = createBaseNode(SyntaxKind.ExternalModuleReference); - node.expression = expression; - node.transformFlags |= propagateChildFlags(node.expression); - node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - return node; + function createExternalModuleReference(expression: Expression): ExternalModuleReference { + return astFactory.createExternalModuleReference(asNode(expression).ast).node; } // @api - function updateExternalModuleReference(node: ExternalModuleReference, expression: Expression) { - return node.expression !== expression - ? update(createExternalModuleReference(expression), node) - : node; + function updateExternalModuleReference(node: ExternalModuleReference, expression: Expression): ExternalModuleReference { + return astFactory.updateExternalModuleReference(asNode(node).ast, asNode(expression).ast).node; } // @@ -5056,946 +2932,626 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // // @api - // createJSDocAllType - // createJSDocUnknownType - function createJSDocPrimaryTypeWorker(kind: T["kind"]) { - return createBaseNode(kind); + function createJSDocAllType(): JSDocAllType { + return astFactory.createJSDocAllType().node; + } + + // @api + function createJSDocUnknownType(): JSDocUnknownType { + return astFactory.createJSDocUnknownType().node; + } + + // @api + function createJSDocNonNullableType(type: TypeNode, postfix = false): JSDocNonNullableType { + return astFactory.createJSDocNonNullableType(asNode(type).ast, postfix).node; + } + + // @api + function updateJSDocNonNullableType(node: JSDocNonNullableType, type: TypeNode): JSDocNonNullableType { + return astFactory.updateJSDocNonNullableType(asNode(node).ast, asNode(type).ast).node; + } + + // @api + function createJSDocNullableType(type: TypeNode, postfix = false): JSDocNullableType { + return astFactory.createJSDocNullableType(asNode(type).ast, postfix).node; + } + + // @api + function updateJSDocNullableType(node: JSDocNullableType, type: TypeNode): JSDocNullableType { + return astFactory.updateJSDocNullableType(asNode(node).ast, asNode(type).ast).node; + } + + // @api + function createJSDocOptionalType(type: TypeNode): JSDocOptionalType { + return astFactory.createJSDocOptionalType(asNode(type).ast).node; + } + + // @api + function updateJSDocOptionalType(node: JSDocOptionalType, type: TypeNode): JSDocOptionalType { + return astFactory.updateJSDocOptionalType(asNode(node).ast, asNode(type).ast).node; } // @api - // createJSDocNullableType - // createJSDocNonNullableType - function createJSDocPrePostfixUnaryTypeWorker(kind: T["kind"], type: T["type"], postfix = false): T { - const node = createJSDocUnaryTypeWorker( - kind, - postfix ? type && parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(type) : type, - ) as Mutable; - node.postfix = postfix; - return node; + function createJSDocVariadicType(type: TypeNode): JSDocVariadicType { + return astFactory.createJSDocVariadicType(asNode(type).ast).node; } // @api - // createJSDocOptionalType - // createJSDocVariadicType - // createJSDocNamepathType - function createJSDocUnaryTypeWorker(kind: T["kind"], type: T["type"]): T { - const node = createBaseNode(kind); - node.type = type; - return node; + function updateJSDocVariadicType(node: JSDocVariadicType, type: TypeNode): JSDocVariadicType { + return astFactory.updateJSDocVariadicType(asNode(node).ast, asNode(type).ast).node; } // @api - // updateJSDocNonNullableType - // updateJSDocNullableType - function updateJSDocPrePostfixUnaryTypeWorker(kind: T["kind"], node: T, type: T["type"]): T { - return node.type !== type - ? update(createJSDocPrePostfixUnaryTypeWorker(kind, type, node.postfix), node) - : node; + function createJSDocNamepathType(type: TypeNode): JSDocNamepathType { + // NOTE: 'type' can be undefined when this is called by parser. + return astFactory.createJSDocNamepathType(asNode(type)?.ast).node; } // @api - // updateJSDocOptionalType - // updateJSDocVariadicType - // updateJSDocNamepathType - function updateJSDocUnaryTypeWorker(kind: T["kind"], node: T, type: T["type"]): T { - return node.type !== type - ? update(createJSDocUnaryTypeWorker(kind, type), node) - : node; + function updateJSDocNamepathType(node: JSDocNamepathType, type: TypeNode): JSDocNamepathType { + return astFactory.updateJSDocNamepathType(asNode(node).ast, asNode(type).ast).node; } // @api function createJSDocFunctionType(parameters: readonly ParameterDeclaration[], type: TypeNode | undefined): JSDocFunctionType { - const node = createBaseDeclaration(SyntaxKind.JSDocFunctionType); - node.parameters = asNodeArray(parameters); - node.type = type; - node.transformFlags = propagateChildrenFlags(node.parameters) | - (node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.typeArguments = undefined; // used in quick info - return node; + return astFactory.createJSDocFunctionType(asNodeArray(parameters).ast, asNode(type)?.ast).node; } // @api function updateJSDocFunctionType(node: JSDocFunctionType, parameters: readonly ParameterDeclaration[], type: TypeNode | undefined): JSDocFunctionType { - return node.parameters !== parameters - || node.type !== type - ? update(createJSDocFunctionType(parameters, type), node) - : node; + return astFactory.updateJSDocFunctionType(asNode(node).ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; } // @api function createJSDocTypeLiteral(propertyTags?: readonly JSDocPropertyLikeTag[], isArrayType = false): JSDocTypeLiteral { - const node = createBaseDeclaration(SyntaxKind.JSDocTypeLiteral); - node.jsDocPropertyTags = asNodeArray(propertyTags); - node.isArrayType = isArrayType; - return node; + return astFactory.createJSDocTypeLiteral(asNodeArray(propertyTags)?.ast, isArrayType).node; } // @api function updateJSDocTypeLiteral(node: JSDocTypeLiteral, propertyTags: readonly JSDocPropertyLikeTag[] | undefined, isArrayType: boolean): JSDocTypeLiteral { - return node.jsDocPropertyTags !== propertyTags - || node.isArrayType !== isArrayType - ? update(createJSDocTypeLiteral(propertyTags, isArrayType), node) - : node; + return astFactory.updateJSDocTypeLiteral(asNode(node).ast, asNodeArray(propertyTags)?.ast, isArrayType).node; } // @api function createJSDocTypeExpression(type: TypeNode): JSDocTypeExpression { - const node = createBaseNode(SyntaxKind.JSDocTypeExpression); - node.type = type; - return node; + return astFactory.createJSDocTypeExpression(asNode(type).ast).node; } // @api function updateJSDocTypeExpression(node: JSDocTypeExpression, type: TypeNode): JSDocTypeExpression { - return node.type !== type - ? update(createJSDocTypeExpression(type), node) - : node; + return astFactory.updateJSDocTypeExpression(asNode(node).ast, asNode(type).ast).node; } // @api function createJSDocSignature(typeParameters: readonly JSDocTemplateTag[] | undefined, parameters: readonly JSDocParameterTag[], type?: JSDocReturnTag): JSDocSignature { - const node = createBaseDeclaration(SyntaxKind.JSDocSignature); - node.typeParameters = asNodeArray(typeParameters); - node.parameters = createNodeArray(parameters); - node.type = type; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - return node; + return astFactory.createJSDocSignature(asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; } // @api function updateJSDocSignature(node: JSDocSignature, typeParameters: readonly JSDocTemplateTag[] | undefined, parameters: readonly JSDocParameterTag[], type: JSDocReturnTag | undefined): JSDocSignature { - return node.typeParameters !== typeParameters - || node.parameters !== parameters - || node.type !== type - ? update(createJSDocSignature(typeParameters, parameters, type), node) - : node; - } - - function getDefaultTagName(node: JSDocTag) { - const defaultTagName = getDefaultTagNameForKind(node.kind); - return node.tagName.escapedText === escapeLeadingUnderscores(defaultTagName) - ? node.tagName - : createIdentifier(defaultTagName); - } - - // @api - function createBaseJSDocTag(kind: T["kind"], tagName: Identifier, comment: string | NodeArray | undefined) { - const node = createBaseNode(kind); - node.tagName = tagName; - node.comment = comment; - return node; - } - - function createBaseJSDocTagDeclaration(kind: T["kind"], tagName: Identifier, comment: string | NodeArray | undefined) { - const node = createBaseDeclaration(kind); - node.tagName = tagName; - node.comment = comment; - return node; + return astFactory.updateJSDocSignature(asNode(node).ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; } // @api function createJSDocTemplateTag(tagName: Identifier | undefined, constraint: JSDocTypeExpression | undefined, typeParameters: readonly TypeParameterDeclaration[], comment?: string | NodeArray): JSDocTemplateTag { - const node = createBaseJSDocTag(SyntaxKind.JSDocTemplateTag, tagName ?? createIdentifier("template"), comment); - node.constraint = constraint; - node.typeParameters = createNodeArray(typeParameters); - return node; + return astFactory.createJSDocTemplateTag(asNode(tagName)?.ast, asNode(constraint)?.ast, asNodeArray(typeParameters).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJSDocTemplateTag(node: JSDocTemplateTag, tagName: Identifier = getDefaultTagName(node), constraint: JSDocTypeExpression | undefined, typeParameters: readonly TypeParameterDeclaration[], comment: string | NodeArray | undefined): JSDocTemplateTag { - return node.tagName !== tagName - || node.constraint !== constraint - || node.typeParameters !== typeParameters - || node.comment !== comment - ? update(createJSDocTemplateTag(tagName, constraint, typeParameters, comment), node) - : node; + function updateJSDocTemplateTag(node: JSDocTemplateTag, tagName: Identifier | undefined, constraint: JSDocTypeExpression | undefined, typeParameters: readonly TypeParameterDeclaration[], comment: string | NodeArray | undefined): JSDocTemplateTag { + return astFactory.updateJSDocTemplateTag(asNode(node).ast, asNode(tagName)?.ast, asNode(constraint)?.ast, asNodeArray(typeParameters).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocTypedefTag(tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, fullName?: Identifier | JSDocNamespaceDeclaration, comment?: string | NodeArray): JSDocTypedefTag { - const node = createBaseJSDocTagDeclaration(SyntaxKind.JSDocTypedefTag, tagName ?? createIdentifier("typedef"), comment); - node.typeExpression = typeExpression; - node.fullName = fullName; - node.name = getJSDocTypeAliasName(fullName); - - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - return node; + return astFactory.createJSDocTypedefTag(asNode(tagName)?.ast, asNode(typeExpression)?.ast, asNode(fullName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJSDocTypedefTag(node: JSDocTypedefTag, tagName: Identifier = getDefaultTagName(node), typeExpression: JSDocTypeExpression | undefined, fullName: Identifier | JSDocNamespaceDeclaration | undefined, comment: string | NodeArray | undefined): JSDocTypedefTag { - return node.tagName !== tagName - || node.typeExpression !== typeExpression - || node.fullName !== fullName - || node.comment !== comment - ? update(createJSDocTypedefTag(tagName, typeExpression, fullName, comment), node) - : node; + function updateJSDocTypedefTag(node: JSDocTypedefTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, fullName: Identifier | JSDocNamespaceDeclaration | undefined, comment: string | NodeArray | undefined): JSDocTypedefTag { + return astFactory.updateJSDocTypedefTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression)?.ast, asNode(fullName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocParameterTag(tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression?: JSDocTypeExpression, isNameFirst?: boolean, comment?: string | NodeArray): JSDocParameterTag { - const node = createBaseJSDocTagDeclaration(SyntaxKind.JSDocParameterTag, tagName ?? createIdentifier("param"), comment); - node.typeExpression = typeExpression; - node.name = name; - node.isNameFirst = !!isNameFirst; - node.isBracketed = isBracketed; - return node; + return astFactory.createJSDocParameterTag(asNode(tagName)?.ast, asNode(name).ast, isBracketed, asNode(typeExpression)?.ast, isNameFirst, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJSDocParameterTag(node: JSDocParameterTag, tagName: Identifier = getDefaultTagName(node), name: EntityName, isBracketed: boolean, typeExpression: JSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | NodeArray | undefined): JSDocParameterTag { - return node.tagName !== tagName - || node.name !== name - || node.isBracketed !== isBracketed - || node.typeExpression !== typeExpression - || node.isNameFirst !== isNameFirst - || node.comment !== comment - ? update(createJSDocParameterTag(tagName, name, isBracketed, typeExpression, isNameFirst, comment), node) - : node; + function updateJSDocParameterTag(node: JSDocParameterTag, tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression: JSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | NodeArray | undefined): JSDocParameterTag { + return astFactory.updateJSDocParameterTag(asNode(node).ast, asNode(tagName)?.ast, asNode(name).ast, isBracketed, asNode(typeExpression)?.ast, isNameFirst, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocPropertyTag(tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression?: JSDocTypeExpression, isNameFirst?: boolean, comment?: string | NodeArray): JSDocPropertyTag { - const node = createBaseJSDocTagDeclaration(SyntaxKind.JSDocPropertyTag, tagName ?? createIdentifier("prop"), comment); - node.typeExpression = typeExpression; - node.name = name; - node.isNameFirst = !!isNameFirst; - node.isBracketed = isBracketed; - return node; + return astFactory.createJSDocPropertyTag(asNode(tagName)?.ast, asNode(name).ast, isBracketed, asNode(typeExpression)?.ast, isNameFirst, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJSDocPropertyTag(node: JSDocPropertyTag, tagName: Identifier = getDefaultTagName(node), name: EntityName, isBracketed: boolean, typeExpression: JSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | NodeArray | undefined): JSDocPropertyTag { - return node.tagName !== tagName - || node.name !== name - || node.isBracketed !== isBracketed - || node.typeExpression !== typeExpression - || node.isNameFirst !== isNameFirst - || node.comment !== comment - ? update(createJSDocPropertyTag(tagName, name, isBracketed, typeExpression, isNameFirst, comment), node) - : node; + function updateJSDocPropertyTag(node: JSDocPropertyTag, tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression: JSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | NodeArray | undefined): JSDocPropertyTag { + return astFactory.updateJSDocPropertyTag(asNode(node).ast, asNode(tagName)?.ast, asNode(name).ast, isBracketed, asNode(typeExpression)?.ast, isNameFirst, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocCallbackTag(tagName: Identifier | undefined, typeExpression: JSDocSignature, fullName?: Identifier | JSDocNamespaceDeclaration, comment?: string | NodeArray): JSDocCallbackTag { - const node = createBaseJSDocTagDeclaration(SyntaxKind.JSDocCallbackTag, tagName ?? createIdentifier("callback"), comment); - node.typeExpression = typeExpression; - node.fullName = fullName; - node.name = getJSDocTypeAliasName(fullName); - - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - return node; + return astFactory.createJSDocCallbackTag(asNode(tagName)?.ast, asNode(typeExpression).ast, asNode(fullName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJSDocCallbackTag(node: JSDocCallbackTag, tagName: Identifier = getDefaultTagName(node), typeExpression: JSDocSignature, fullName: Identifier | JSDocNamespaceDeclaration | undefined, comment: string | NodeArray | undefined): JSDocCallbackTag { - return node.tagName !== tagName - || node.typeExpression !== typeExpression - || node.fullName !== fullName - || node.comment !== comment - ? update(createJSDocCallbackTag(tagName, typeExpression, fullName, comment), node) - : node; + function updateJSDocCallbackTag(node: JSDocCallbackTag, tagName: Identifier | undefined, typeExpression: JSDocSignature, fullName: Identifier | JSDocNamespaceDeclaration | undefined, comment: string | NodeArray | undefined): JSDocCallbackTag { + return astFactory.updateJSDocCallbackTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression).ast, asNode(fullName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocOverloadTag(tagName: Identifier | undefined, typeExpression: JSDocSignature, comment?: string | NodeArray): JSDocOverloadTag { - const node = createBaseJSDocTag(SyntaxKind.JSDocOverloadTag, tagName ?? createIdentifier("overload"), comment); - node.typeExpression = typeExpression; - return node; + return astFactory.createJSDocOverloadTag(asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJSDocOverloadTag(node: JSDocOverloadTag, tagName: Identifier = getDefaultTagName(node), typeExpression: JSDocSignature, comment: string | NodeArray | undefined): JSDocOverloadTag { - return node.tagName !== tagName - || node.typeExpression !== typeExpression - || node.comment !== comment - ? update(createJSDocOverloadTag(tagName, typeExpression, comment), node) - : node; + function updateJSDocOverloadTag(node: JSDocOverloadTag, tagName: Identifier | undefined, typeExpression: JSDocSignature, comment: string | NodeArray | undefined): JSDocOverloadTag { + return astFactory.updateJSDocOverloadTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function createJSDocAugmentsTag(tagName: Identifier | undefined, className: JSDocAugmentsTag["class"], comment?: string | NodeArray): JSDocAugmentsTag { - const node = createBaseJSDocTag(SyntaxKind.JSDocAugmentsTag, tagName ?? createIdentifier("augments"), comment); - node.class = className; - return node; + function createJSDocAugmentsTag(tagName: Identifier | undefined, className: JSDocClassReference, comment?: string | NodeArray): JSDocAugmentsTag { + return astFactory.createJSDocAugmentsTag(asNode(tagName)?.ast, asNode(className).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJSDocAugmentsTag(node: JSDocAugmentsTag, tagName: Identifier = getDefaultTagName(node), className: JSDocAugmentsTag["class"], comment: string | NodeArray | undefined): JSDocAugmentsTag { - return node.tagName !== tagName - || node.class !== className - || node.comment !== comment - ? update(createJSDocAugmentsTag(tagName, className, comment), node) - : node; + function updateJSDocAugmentsTag(node: JSDocAugmentsTag, tagName: Identifier | undefined, className: JSDocClassReference, comment: string | NodeArray | undefined): JSDocAugmentsTag { + return astFactory.updateJSDocAugmentsTag(asNode(node).ast, asNode(tagName)?.ast, asNode(className).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function createJSDocImplementsTag(tagName: Identifier | undefined, className: JSDocImplementsTag["class"], comment?: string | NodeArray): JSDocImplementsTag { - const node = createBaseJSDocTag(SyntaxKind.JSDocImplementsTag, tagName ?? createIdentifier("implements"), comment); - node.class = className; - return node; + function createJSDocImplementsTag(tagName: Identifier | undefined, className: JSDocClassReference, comment?: string | NodeArray): JSDocImplementsTag { + return astFactory.createJSDocImplementsTag(asNode(tagName)?.ast, asNode(className).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocSeeTag(tagName: Identifier | undefined, name: JSDocNameReference | undefined, comment?: string | NodeArray): JSDocSeeTag { - const node = createBaseJSDocTag(SyntaxKind.JSDocSeeTag, tagName ?? createIdentifier("see"), comment); - node.name = name; - return node; + return astFactory.createJSDocSeeTag(asNode(tagName)?.ast, asNode(name)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocSeeTag(node: JSDocSeeTag, tagName: Identifier | undefined, name: JSDocNameReference | undefined, comment?: string | NodeArray): JSDocSeeTag { - return node.tagName !== tagName - || node.name !== name - || node.comment !== comment - ? update(createJSDocSeeTag(tagName, name, comment), node) - : node; + return astFactory.updateJSDocSeeTag(asNode(node).ast, asNode(tagName)?.ast, asNode(name)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocNameReference(name: EntityName | JSDocMemberName): JSDocNameReference { - const node = createBaseNode(SyntaxKind.JSDocNameReference); - node.name = name; - return node; + return astFactory.createJSDocNameReference(asNode(name).ast).node; } // @api function updateJSDocNameReference(node: JSDocNameReference, name: EntityName | JSDocMemberName): JSDocNameReference { - return node.name !== name - ? update(createJSDocNameReference(name), node) - : node; + return astFactory.updateJSDocNameReference(asNode(node).ast, asNode(name).ast).node; } // @api - function createJSDocMemberName(left: EntityName | JSDocMemberName, right: Identifier) { - const node = createBaseNode(SyntaxKind.JSDocMemberName); - node.left = left; - node.right = right; - node.transformFlags |= propagateChildFlags(node.left) | - propagateChildFlags(node.right); - return node; + function createJSDocMemberName(left: EntityName | JSDocMemberName, right: Identifier): JSDocMemberName { + return astFactory.createJSDocMemberName(asNode(left).ast, asNode(right).ast).node; } // @api - function updateJSDocMemberName(node: JSDocMemberName, left: EntityName | JSDocMemberName, right: Identifier) { - return node.left !== left - || node.right !== right - ? update(createJSDocMemberName(left, right), node) - : node; + function updateJSDocMemberName(node: JSDocMemberName, left: EntityName | JSDocMemberName, right: Identifier): JSDocMemberName { + return astFactory.updateJSDocMemberName(asNode(node).ast, asNode(left).ast, asNode(right).ast).node; } // @api function createJSDocLink(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLink { - const node = createBaseNode(SyntaxKind.JSDocLink); - node.name = name; - node.text = text; - return node; + return astFactory.createJSDocLink(asNode(name)?.ast, text).node; } // @api function updateJSDocLink(node: JSDocLink, name: EntityName | JSDocMemberName | undefined, text: string): JSDocLink { - return node.name !== name - ? update(createJSDocLink(name, text), node) - : node; + return astFactory.updateJSDocLink(asNode(node).ast, asNode(name)?.ast, text).node; } // @api function createJSDocLinkCode(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkCode { - const node = createBaseNode(SyntaxKind.JSDocLinkCode); - node.name = name; - node.text = text; - return node; + return astFactory.createJSDocLinkCode(asNode(name)?.ast, text).node; } // @api function updateJSDocLinkCode(node: JSDocLinkCode, name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkCode { - return node.name !== name - ? update(createJSDocLinkCode(name, text), node) - : node; + return astFactory.updateJSDocLinkCode(asNode(node).ast, asNode(name)?.ast, text).node; } // @api function createJSDocLinkPlain(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkPlain { - const node = createBaseNode(SyntaxKind.JSDocLinkPlain); - node.name = name; - node.text = text; - return node; + return astFactory.createJSDocLinkPlain(asNode(name)?.ast, text).node; } // @api function updateJSDocLinkPlain(node: JSDocLinkPlain, name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkPlain { - return node.name !== name - ? update(createJSDocLinkPlain(name, text), node) - : node; + return astFactory.updateJSDocLinkPlain(asNode(node).ast, asNode(name)?.ast, text).node; } // @api - function updateJSDocImplementsTag(node: JSDocImplementsTag, tagName: Identifier = getDefaultTagName(node), className: JSDocImplementsTag["class"], comment: string | NodeArray | undefined): JSDocImplementsTag { - return node.tagName !== tagName - || node.class !== className - || node.comment !== comment - ? update(createJSDocImplementsTag(tagName, className, comment), node) - : node; + function updateJSDocImplementsTag(node: JSDocImplementsTag, tagName: Identifier | undefined, className: JSDocClassReference, comment: string | NodeArray | undefined): JSDocImplementsTag { + return astFactory.updateJSDocImplementsTag(asNode(node).ast, asNode(tagName)?.ast, asNode(className).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - // createJSDocAuthorTag - // createJSDocClassTag - // createJSDocPublicTag - // createJSDocPrivateTag - // createJSDocProtectedTag - // createJSDocReadonlyTag - // createJSDocDeprecatedTag - function createJSDocSimpleTagWorker(kind: T["kind"], tagName: Identifier | undefined, comment?: string | NodeArray) { - const node = createBaseJSDocTag(kind, tagName ?? createIdentifier(getDefaultTagNameForKind(kind)), comment); - return node; + function createJSDocAuthorTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocAuthorTag { + return astFactory.createJSDocAuthorTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - // updateJSDocAuthorTag - // updateJSDocClassTag - // updateJSDocPublicTag - // updateJSDocPrivateTag - // updateJSDocProtectedTag - // updateJSDocReadonlyTag - // updateJSDocDeprecatedTag - function updateJSDocSimpleTagWorker(kind: T["kind"], node: T, tagName: Identifier = getDefaultTagName(node), comment: string | NodeArray | undefined) { - return node.tagName !== tagName - || node.comment !== comment - ? update(createJSDocSimpleTagWorker(kind, tagName, comment), node) : - node; + function updateJSDocAuthorTag(node: JSDocAuthorTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocAuthorTag { + return astFactory.updateJSDocAuthorTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - // createJSDocTypeTag - // createJSDocReturnTag - // createJSDocThisTag - // createJSDocEnumTag - // createJSDocSatisfiesTag - function createJSDocTypeLikeTagWorker(kind: T["kind"], tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: string | NodeArray) { - const node = createBaseJSDocTag(kind, tagName ?? createIdentifier(getDefaultTagNameForKind(kind)), comment); - node.typeExpression = typeExpression; - return node; + function createJSDocClassTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocClassTag { + return astFactory.createJSDocClassTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - // updateJSDocTypeTag - // updateJSDocReturnTag - // updateJSDocThisTag - // updateJSDocEnumTag - // updateJSDocSatisfiesTag - function updateJSDocTypeLikeTagWorker(kind: T["kind"], node: T, tagName: Identifier = getDefaultTagName(node), typeExpression: JSDocTypeExpression | undefined, comment: string | NodeArray | undefined) { - return node.tagName !== tagName - || node.typeExpression !== typeExpression - || node.comment !== comment - ? update(createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment), node) - : node; + function updateJSDocClassTag(node: JSDocClassTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocClassTag { + return astFactory.updateJSDocClassTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function createJSDocUnknownTag(tagName: Identifier, comment?: string | NodeArray): JSDocUnknownTag { - const node = createBaseJSDocTag(SyntaxKind.JSDocTag, tagName, comment); - return node; + function createJSDocPublicTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocPublicTag { + return astFactory.createJSDocPublicTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJSDocUnknownTag(node: JSDocUnknownTag, tagName: Identifier, comment: string | NodeArray | undefined): JSDocUnknownTag { - return node.tagName !== tagName - || node.comment !== comment - ? update(createJSDocUnknownTag(tagName, comment), node) - : node; + function updateJSDocPublicTag(node: JSDocPublicTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocPublicTag { + return astFactory.updateJSDocPublicTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function createJSDocEnumTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string | NodeArray) { - const node = createBaseJSDocTagDeclaration(SyntaxKind.JSDocEnumTag, tagName ?? createIdentifier(getDefaultTagNameForKind(SyntaxKind.JSDocEnumTag)), comment); - node.typeExpression = typeExpression; + function createJSDocPrivateTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocPrivateTag { + return astFactory.createJSDocPrivateTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + } - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - return node; + // @api + function updateJSDocPrivateTag(node: JSDocPrivateTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocPrivateTag { + return astFactory.updateJSDocPrivateTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + } + + // @api + function createJSDocProtectedTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocProtectedTag { + return astFactory.createJSDocProtectedTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + } + + // @api + function updateJSDocProtectedTag(node: JSDocProtectedTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocProtectedTag { + return astFactory.updateJSDocProtectedTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + } + + // @api + function createJSDocReadonlyTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocReadonlyTag { + return astFactory.createJSDocReadonlyTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + } + + // @api + function updateJSDocReadonlyTag(node: JSDocReadonlyTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocReadonlyTag { + return astFactory.updateJSDocReadonlyTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + } + + // @api + function createJSDocOverrideTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocOverrideTag { + return astFactory.createJSDocOverrideTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + } + + // @api + function updateJSDocOverrideTag(node: JSDocOverrideTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocOverrideTag { + return astFactory.updateJSDocOverrideTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + } + + // @api + function createJSDocDeprecatedTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocDeprecatedTag { + return astFactory.createJSDocDeprecatedTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + } + + // @api + function updateJSDocDeprecatedTag(node: JSDocDeprecatedTag, tagName: Identifier | undefined, comment?: string | NodeArray): JSDocDeprecatedTag { + return astFactory.updateJSDocDeprecatedTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJSDocEnumTag(node: JSDocEnumTag, tagName: Identifier = getDefaultTagName(node), typeExpression: JSDocTypeExpression, comment: string | NodeArray | undefined) { - return node.tagName !== tagName - || node.typeExpression !== typeExpression - || node.comment !== comment - ? update(createJSDocEnumTag(tagName, typeExpression, comment), node) - : node; + function createJSDocUnknownTag(tagName: Identifier, comment?: string | NodeArray): JSDocUnknownTag { + return astFactory.createJSDocUnknownTag(asNode(tagName).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + } + + // @api + function updateJSDocUnknownTag(node: JSDocUnknownTag, tagName: Identifier, comment: string | NodeArray | undefined): JSDocUnknownTag { + return astFactory.updateJSDocUnknownTag(asNode(node).ast, asNode(tagName).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocImportTag(tagName: Identifier | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes?: ImportAttributes, comment?: string | NodeArray): JSDocImportTag { - const node = createBaseJSDocTag(SyntaxKind.JSDocImportTag, tagName ?? createIdentifier("import"), comment); - node.importClause = importClause; - node.moduleSpecifier = moduleSpecifier; - node.attributes = attributes; - node.comment = comment; - return node; + return astFactory.createJSDocImportTag(asNode(tagName)?.ast, asNode(importClause)?.ast, asNode(moduleSpecifier).ast, asNode(attributes)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } function updateJSDocImportTag(node: JSDocImportTag, tagName: Identifier | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes: ImportAttributes | undefined, comment: string | NodeArray | undefined): JSDocImportTag { - return node.tagName !== tagName - || node.comment !== comment - || node.importClause !== importClause - || node.moduleSpecifier !== moduleSpecifier - || node.attributes !== attributes - ? update(createJSDocImportTag(tagName, importClause, moduleSpecifier, attributes, comment), node) - : node; + return astFactory.updateJSDocImportTag(asNode(node).ast, asNode(tagName)?.ast, asNode(importClause)?.ast, asNode(moduleSpecifier).ast, asNode(attributes)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocText(text: string): JSDocText { - const node = createBaseNode(SyntaxKind.JSDocText); - node.text = text; - return node; + return astFactory.createJSDocText(text).node; } // @api function updateJSDocText(node: JSDocText, text: string): JSDocText { - return node.text !== text - ? update(createJSDocText(text), node) - : node; + return astFactory.updateJSDocText(asNode(node).ast, text).node; } // @api - function createJSDocComment(comment?: string | NodeArray | undefined, tags?: readonly JSDocTag[] | undefined) { - const node = createBaseNode(SyntaxKind.JSDoc); - node.comment = comment; - node.tags = asNodeArray(tags); - return node; + function createJSDocComment(comment?: string | NodeArray | undefined, tags?: readonly JSDocTag[] | undefined): JSDoc { + return astFactory.createJSDocComment(typeof comment === "string" ? comment : asNodeArray(comment)?.ast, asNodeArray(tags)?.ast).node; } // @api - function updateJSDocComment(node: JSDoc, comment: string | NodeArray | undefined, tags: readonly JSDocTag[] | undefined) { - return node.comment !== comment - || node.tags !== tags - ? update(createJSDocComment(comment, tags), node) - : node; + function updateJSDocComment(node: JSDoc, comment: string | NodeArray | undefined, tags: readonly JSDocTag[] | undefined): JSDoc { + return astFactory.updateJSDocComment(asNode(node).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast, asNodeArray(tags)?.ast).node; } - // - // JSX - // - // @api - function createJsxElement(openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement) { - const node = createBaseNode(SyntaxKind.JsxElement); - node.openingElement = openingElement; - node.children = createNodeArray(children); - node.closingElement = closingElement; - node.transformFlags |= propagateChildFlags(node.openingElement) | - propagateChildrenFlags(node.children) | - propagateChildFlags(node.closingElement) | - TransformFlags.ContainsJsx; - return node; + function createJSDocTypeTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string | NodeArray): JSDocTypeTag { + return astFactory.createJSDocTypeTag(asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJsxElement(node: JsxElement, openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement) { - return node.openingElement !== openingElement - || node.children !== children - || node.closingElement !== closingElement - ? update(createJsxElement(openingElement, children, closingElement), node) - : node; + function updateJSDocTypeTag(node: JSDocTypeTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment: string | NodeArray | undefined): JSDocTypeTag { + return astFactory.updateJSDocTypeTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function createJsxSelfClosingElement(tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes) { - const node = createBaseNode(SyntaxKind.JsxSelfClosingElement); - node.tagName = tagName; - node.typeArguments = asNodeArray(typeArguments); - node.attributes = attributes; - node.transformFlags |= propagateChildFlags(node.tagName) | - propagateChildrenFlags(node.typeArguments) | - propagateChildFlags(node.attributes) | - TransformFlags.ContainsJsx; - if (node.typeArguments) { - node.transformFlags |= TransformFlags.ContainsTypeScript; - } - return node; + function createJSDocReturnTag(tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: string | NodeArray): JSDocReturnTag { + return astFactory.createJSDocReturnTag(asNode(tagName)?.ast, asNode(typeExpression)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJsxSelfClosingElement(node: JsxSelfClosingElement, tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes) { - return node.tagName !== tagName - || node.typeArguments !== typeArguments - || node.attributes !== attributes - ? update(createJsxSelfClosingElement(tagName, typeArguments, attributes), node) - : node; + function updateJSDocReturnTag(node: JSDocReturnTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, comment: string | NodeArray | undefined): JSDocReturnTag { + return astFactory.updateJSDocReturnTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function createJsxOpeningElement(tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes) { - const node = createBaseNode(SyntaxKind.JsxOpeningElement); - node.tagName = tagName; - node.typeArguments = asNodeArray(typeArguments); - node.attributes = attributes; - node.transformFlags |= propagateChildFlags(node.tagName) | - propagateChildrenFlags(node.typeArguments) | - propagateChildFlags(node.attributes) | - TransformFlags.ContainsJsx; - if (typeArguments) { - node.transformFlags |= TransformFlags.ContainsTypeScript; - } - return node; + function createJSDocThisTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string | NodeArray): JSDocThisTag { + return astFactory.createJSDocThisTag(asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJsxOpeningElement(node: JsxOpeningElement, tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes) { - return node.tagName !== tagName - || node.typeArguments !== typeArguments - || node.attributes !== attributes - ? update(createJsxOpeningElement(tagName, typeArguments, attributes), node) - : node; + function updateJSDocThisTag(node: JSDocThisTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, comment: string | NodeArray | undefined): JSDocThisTag { + return astFactory.updateJSDocThisTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function createJsxClosingElement(tagName: JsxTagNameExpression) { - const node = createBaseNode(SyntaxKind.JsxClosingElement); - node.tagName = tagName; - node.transformFlags |= propagateChildFlags(node.tagName) | - TransformFlags.ContainsJsx; - return node; + function createJSDocThrowsTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, comment?: string | NodeArray): JSDocThrowsTag { + return astFactory.createJSDocThrowsTag(asNode(tagName)?.ast, asNode(typeExpression)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJsxClosingElement(node: JsxClosingElement, tagName: JsxTagNameExpression) { - return node.tagName !== tagName - ? update(createJsxClosingElement(tagName), node) - : node; + function updateJSDocThrowsTag(node: JSDocThrowsTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, comment: string | NodeArray | undefined): JSDocThrowsTag { + return astFactory.updateJSDocThrowsTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function createJsxFragment(openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment) { - const node = createBaseNode(SyntaxKind.JsxFragment); - node.openingFragment = openingFragment; - node.children = createNodeArray(children); - node.closingFragment = closingFragment; - node.transformFlags |= propagateChildFlags(node.openingFragment) | - propagateChildrenFlags(node.children) | - propagateChildFlags(node.closingFragment) | - TransformFlags.ContainsJsx; - return node; + function createJSDocEnumTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string | NodeArray) { + return astFactory.createJSDocEnumTag(asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment) { - return node.openingFragment !== openingFragment - || node.children !== children - || node.closingFragment !== closingFragment - ? update(createJsxFragment(openingFragment, children, closingFragment), node) - : node; + function updateJSDocEnumTag(node: JSDocEnumTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment: string | NodeArray | undefined) { + return astFactory.updateJSDocEnumTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function createJsxText(text: string, containsOnlyTriviaWhiteSpaces?: boolean) { - const node = createBaseNode(SyntaxKind.JsxText); - node.text = text; - node.containsOnlyTriviaWhiteSpaces = !!containsOnlyTriviaWhiteSpaces; - node.transformFlags |= TransformFlags.ContainsJsx; - return node; + function createJSDocSatisfiesTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string | NodeArray) { + return astFactory.createJSDocSatisfiesTag(asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api - function updateJsxText(node: JsxText, text: string, containsOnlyTriviaWhiteSpaces?: boolean) { - return node.text !== text - || node.containsOnlyTriviaWhiteSpaces !== containsOnlyTriviaWhiteSpaces - ? update(createJsxText(text, containsOnlyTriviaWhiteSpaces), node) - : node; + function updateJSDocSatisfiesTag(node: JSDocSatisfiesTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment: string | NodeArray | undefined) { + return astFactory.updateJSDocSatisfiesTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } + + // + // JSX + // + // @api - function createJsxOpeningFragment() { - const node = createBaseNode(SyntaxKind.JsxOpeningFragment); - node.transformFlags |= TransformFlags.ContainsJsx; - return node; + function createJsxElement(openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement): JsxElement { + return astFactory.createJsxElement(asNode(openingElement).ast, asNodeArray(children).ast, asNode(closingElement).ast).node; } // @api - function createJsxJsxClosingFragment() { - const node = createBaseNode(SyntaxKind.JsxClosingFragment); - node.transformFlags |= TransformFlags.ContainsJsx; - return node; + function updateJsxElement(node: JsxElement, openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement): JsxElement { + return astFactory.updateJsxElement(asNode(node).ast, asNode(openingElement).ast, asNodeArray(children).ast, asNode(closingElement).ast).node; } // @api - function createJsxAttribute(name: JsxAttributeName, initializer: JsxAttributeValue | undefined) { - const node = createBaseDeclaration(SyntaxKind.JsxAttribute); - node.name = name; - node.initializer = initializer; - node.transformFlags |= propagateChildFlags(node.name) | - propagateChildFlags(node.initializer) | - TransformFlags.ContainsJsx; - return node; + function createJsxSelfClosingElement(tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes): JsxSelfClosingElement { + return astFactory.createJsxSelfClosingElement(asNode(tagName).ast, asNodeArray(typeArguments)?.ast, asNode(attributes).ast).node; } // @api - function updateJsxAttribute(node: JsxAttribute, name: JsxAttributeName, initializer: JsxAttributeValue | undefined) { - return node.name !== name - || node.initializer !== initializer - ? update(createJsxAttribute(name, initializer), node) - : node; + function updateJsxSelfClosingElement(node: JsxSelfClosingElement, tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes): JsxSelfClosingElement { + return astFactory.updateJsxSelfClosingElement(asNode(node).ast, asNode(tagName).ast, asNodeArray(typeArguments)?.ast, asNode(attributes).ast).node; } // @api - function createJsxAttributes(properties: readonly JsxAttributeLike[]) { - const node = createBaseDeclaration(SyntaxKind.JsxAttributes); - node.properties = createNodeArray(properties); - node.transformFlags |= propagateChildrenFlags(node.properties) | - TransformFlags.ContainsJsx; - return node; + function createJsxOpeningElement(tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes): JsxOpeningElement { + return astFactory.createJsxOpeningElement(asNode(tagName).ast, asNodeArray(typeArguments)?.ast, asNode(attributes).ast).node; } // @api - function updateJsxAttributes(node: JsxAttributes, properties: readonly JsxAttributeLike[]) { - return node.properties !== properties - ? update(createJsxAttributes(properties), node) - : node; + function updateJsxOpeningElement(node: JsxOpeningElement, tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes): JsxOpeningElement { + return astFactory.updateJsxOpeningElement(asNode(node).ast, asNode(tagName).ast, asNodeArray(typeArguments)?.ast, asNode(attributes).ast).node; } // @api - function createJsxSpreadAttribute(expression: Expression) { - const node = createBaseNode(SyntaxKind.JsxSpreadAttribute); - node.expression = expression; - node.transformFlags |= propagateChildFlags(node.expression) | - TransformFlags.ContainsJsx; - return node; + function createJsxClosingElement(tagName: JsxTagNameExpression): JsxClosingElement { + return astFactory.createJsxClosingElement(asNode(tagName).ast).node; } // @api - function updateJsxSpreadAttribute(node: JsxSpreadAttribute, expression: Expression) { - return node.expression !== expression - ? update(createJsxSpreadAttribute(expression), node) - : node; + function updateJsxClosingElement(node: JsxClosingElement, tagName: JsxTagNameExpression): JsxClosingElement { + return astFactory.updateJsxClosingElement(asNode(node).ast, asNode(tagName).ast).node; } // @api - function createJsxExpression(dotDotDotToken: DotDotDotToken | undefined, expression: Expression | undefined) { - const node = createBaseNode(SyntaxKind.JsxExpression); - node.dotDotDotToken = dotDotDotToken; - node.expression = expression; - node.transformFlags |= propagateChildFlags(node.dotDotDotToken) | - propagateChildFlags(node.expression) | - TransformFlags.ContainsJsx; - return node; + function createJsxFragment(openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment): JsxFragment { + return astFactory.createJsxFragment(asNode(openingFragment).ast, asNodeArray(children).ast, asNode(closingFragment).ast).node; } // @api - function updateJsxExpression(node: JsxExpression, expression: Expression | undefined) { - return node.expression !== expression - ? update(createJsxExpression(node.dotDotDotToken, expression), node) - : node; + function updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment): JsxFragment { + return astFactory.updateJsxFragment(asNode(node).ast, asNode(openingFragment).ast, asNodeArray(children).ast, asNode(closingFragment).ast).node; } // @api - function createJsxNamespacedName(namespace: Identifier, name: Identifier) { - const node = createBaseNode(SyntaxKind.JsxNamespacedName); - node.namespace = namespace; - node.name = name; - node.transformFlags |= propagateChildFlags(node.namespace) | - propagateChildFlags(node.name) | - TransformFlags.ContainsJsx; - return node; + function createJsxText(text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText { + return astFactory.createJsxText(text, containsOnlyTriviaWhiteSpaces).node; } // @api - function updateJsxNamespacedName(node: JsxNamespacedName, namespace: Identifier, name: Identifier) { - return node.namespace !== namespace - || node.name !== name - ? update(createJsxNamespacedName(namespace, name), node) - : node; + function updateJsxText(node: JsxText, text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText { + return astFactory.updateJsxText(asNode(node).ast, text, containsOnlyTriviaWhiteSpaces).node; } - // - // Clauses - // + // @api + function createJsxOpeningFragment(): JsxOpeningFragment { + return astFactory.createJsxOpeningFragment().node; + } // @api - function createCaseClause(expression: Expression, statements: readonly Statement[]) { - const node = createBaseNode(SyntaxKind.CaseClause); - node.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); - node.statements = createNodeArray(statements); - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildrenFlags(node.statements); + function createJsxClosingFragment(): JsxClosingFragment { + return astFactory.createJsxClosingFragment().node; + } - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + // @api + function createJsxAttribute(name: JsxAttributeName, initializer: JsxAttributeValue | undefined): JsxAttribute { + return astFactory.createJsxAttribute(asNode(name).ast, asNode(initializer)?.ast).node; } // @api - function updateCaseClause(node: CaseClause, expression: Expression, statements: readonly Statement[]) { - return node.expression !== expression - || node.statements !== statements - ? update(createCaseClause(expression, statements), node) - : node; + function updateJsxAttribute(node: JsxAttribute, name: JsxAttributeName, initializer: JsxAttributeValue | undefined): JsxAttribute { + return astFactory.updateJsxAttribute(asNode(node).ast, asNode(name).ast, asNode(initializer)?.ast).node; } // @api - function createDefaultClause(statements: readonly Statement[]) { - const node = createBaseNode(SyntaxKind.DefaultClause); - node.statements = createNodeArray(statements); - node.transformFlags = propagateChildrenFlags(node.statements); - return node; + function createJsxAttributes(properties: readonly JsxAttributeLike[]): JsxAttributes { + return astFactory.createJsxAttributes(asNodeArray(properties).ast).node; } // @api - function updateDefaultClause(node: DefaultClause, statements: readonly Statement[]) { - return node.statements !== statements - ? update(createDefaultClause(statements), node) - : node; + function updateJsxAttributes(node: JsxAttributes, properties: readonly JsxAttributeLike[]): JsxAttributes { + return astFactory.updateJsxAttributes(asNode(node).ast, asNodeArray(properties).ast).node; } // @api - function createHeritageClause(token: HeritageClause["token"], types: readonly ExpressionWithTypeArguments[]) { - const node = createBaseNode(SyntaxKind.HeritageClause); - node.token = token; - node.types = createNodeArray(types); - node.transformFlags |= propagateChildrenFlags(node.types); - switch (token) { - case SyntaxKind.ExtendsKeyword: - node.transformFlags |= TransformFlags.ContainsES2015; - break; - case SyntaxKind.ImplementsKeyword: - node.transformFlags |= TransformFlags.ContainsTypeScript; - break; - default: - return Debug.assertNever(token); - } - return node; + function createJsxSpreadAttribute(expression: Expression): JsxSpreadAttribute { + return astFactory.createJsxSpreadAttribute(asNode(expression).ast).node; } // @api - function updateHeritageClause(node: HeritageClause, types: readonly ExpressionWithTypeArguments[]) { - return node.types !== types - ? update(createHeritageClause(node.token, types), node) - : node; + function updateJsxSpreadAttribute(node: JsxSpreadAttribute, expression: Expression): JsxSpreadAttribute { + return astFactory.updateJsxSpreadAttribute(asNode(node).ast, asNode(expression).ast).node; } // @api - function createCatchClause(variableDeclaration: string | BindingName | VariableDeclaration | undefined, block: Block) { - const node = createBaseNode(SyntaxKind.CatchClause); - node.variableDeclaration = asVariableDeclaration(variableDeclaration); - node.block = block; + function createJsxExpression(dotDotDotToken: DotDotDotToken | undefined, expression: Expression | undefined): JsxExpression { + return astFactory.createJsxExpression(asNode(dotDotDotToken)?.ast, asNode(expression)?.ast).node; + } - node.transformFlags |= propagateChildFlags(node.variableDeclaration) | - propagateChildFlags(node.block) | - (!variableDeclaration ? TransformFlags.ContainsES2019 : TransformFlags.None); + // @api + function updateJsxExpression(node: JsxExpression, expression: Expression | undefined): JsxExpression { + return astFactory.updateJsxExpression(asNode(node).ast, asNode(expression)?.ast).node; + } - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - return node; + // @api + function createJsxNamespacedName(namespace: Identifier, name: Identifier): JsxNamespacedName { + return astFactory.createJsxNamespacedName(asNode(namespace).ast, asNode(name).ast).node; } // @api - function updateCatchClause(node: CatchClause, variableDeclaration: VariableDeclaration | undefined, block: Block) { - return node.variableDeclaration !== variableDeclaration - || node.block !== block - ? update(createCatchClause(variableDeclaration, block), node) - : node; + function updateJsxNamespacedName(node: JsxNamespacedName, namespace: Identifier, name: Identifier): JsxNamespacedName { + return astFactory.updateJsxNamespacedName(asNode(node).ast, asNode(namespace).ast, asNode(name).ast).node; } // - // Property assignments + // Clauses // // @api - function createPropertyAssignment(name: string | PropertyName, initializer: Expression) { - const node = createBaseDeclaration(SyntaxKind.PropertyAssignment); - node.name = asName(name); - node.initializer = parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer); - node.transformFlags |= propagateNameFlags(node.name) | - propagateChildFlags(node.initializer); + function createCaseClause(expression: Expression, statements: readonly Statement[]): CaseClause { + return astFactory.createCaseClause(asNode(expression).ast, asNodeArray(statements).ast).node; + } - node.modifiers = undefined; // initialized by parser to report grammar errors - node.questionToken = undefined; // initialized by parser to report grammar errors - node.exclamationToken = undefined; // initialized by parser to report grammar errors - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + // @api + function updateCaseClause(node: CaseClause, expression: Expression, statements: readonly Statement[]): CaseClause { + return astFactory.updateCaseClause(asNode(node).ast, asNode(expression).ast, asNodeArray(statements).ast).node; } // @api - function updatePropertyAssignment(node: PropertyAssignment, name: PropertyName, initializer: Expression) { - return node.name !== name - || node.initializer !== initializer - ? finishUpdatePropertyAssignment(createPropertyAssignment(name, initializer), node) - : node; + function createDefaultClause(statements: readonly Statement[]): DefaultClause { + return astFactory.createDefaultClause(asNodeArray(statements).ast).node; } - function finishUpdatePropertyAssignment(updated: Mutable, original: PropertyAssignment) { - // copy children used only for error reporting - if (updated !== original) { - // copy children used only for error reporting - updated.modifiers = original.modifiers; - updated.questionToken = original.questionToken; - updated.exclamationToken = original.exclamationToken; - } - return update(updated, original); + // @api + function updateDefaultClause(node: DefaultClause, statements: readonly Statement[]): DefaultClause { + return astFactory.updateDefaultClause(asNode(node).ast, asNodeArray(statements).ast).node; } // @api - function createShorthandPropertyAssignment(name: string | Identifier, objectAssignmentInitializer?: Expression) { - const node = createBaseDeclaration(SyntaxKind.ShorthandPropertyAssignment); - node.name = asName(name); - node.objectAssignmentInitializer = objectAssignmentInitializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(objectAssignmentInitializer); - node.transformFlags |= propagateIdentifierNameFlags(node.name) | - propagateChildFlags(node.objectAssignmentInitializer) | - TransformFlags.ContainsES2015; + function createHeritageClause(token: HeritageClause["token"], types: readonly ExpressionWithTypeArguments[]): HeritageClause { + return astFactory.createHeritageClause(token, asNodeArray(types).ast).node; + } - node.equalsToken = undefined; // initialized by parser to report grammar errors - node.modifiers = undefined; // initialized by parser to report grammar errors - node.questionToken = undefined; // initialized by parser to report grammar errors - node.exclamationToken = undefined; // initialized by parser to report grammar errors - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + // @api + function updateHeritageClause(node: HeritageClause, types: readonly ExpressionWithTypeArguments[]): HeritageClause { + return astFactory.updateHeritageClause(asNode(node).ast, asNodeArray(types).ast).node; } // @api - function updateShorthandPropertyAssignment(node: ShorthandPropertyAssignment, name: Identifier, objectAssignmentInitializer: Expression | undefined) { - return node.name !== name - || node.objectAssignmentInitializer !== objectAssignmentInitializer - ? finishUpdateShorthandPropertyAssignment(createShorthandPropertyAssignment(name, objectAssignmentInitializer), node) - : node; + function createCatchClause(variableDeclaration: string | BindingName | VariableDeclaration | undefined, block: Block): CatchClause { + return astFactory.createCatchClause(asVariableDeclaration(variableDeclaration)?.ast, asNode(block).ast).node; } - function finishUpdateShorthandPropertyAssignment(updated: Mutable, original: ShorthandPropertyAssignment) { - if (updated !== original) { - // copy children used only for error reporting - updated.modifiers = original.modifiers; - updated.questionToken = original.questionToken; - updated.exclamationToken = original.exclamationToken; - updated.equalsToken = original.equalsToken; - } - return update(updated, original); + // @api + function updateCatchClause(node: CatchClause, variableDeclaration: VariableDeclaration | undefined, block: Block): CatchClause { + return astFactory.updateCatchClause(asNode(node).ast, asNode(variableDeclaration)?.ast, asNode(block).ast).node; } + // + // Property assignments + // + // @api - function createSpreadAssignment(expression: Expression) { - const node = createBaseDeclaration(SyntaxKind.SpreadAssignment); - node.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); - node.transformFlags |= propagateChildFlags(node.expression) | - TransformFlags.ContainsES2018 | - TransformFlags.ContainsObjectRestOrSpread; + function createPropertyAssignment(name: string | PropertyName, initializer: Expression): PropertyAssignment { + return astFactory.createPropertyAssignment(asName(name)?.ast, asNode(initializer).ast).node; + } - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + // @api + function updatePropertyAssignment(node: PropertyAssignment, name: PropertyName, initializer: Expression): PropertyAssignment { + return astFactory.updatePropertyAssignment(asNode(node).ast, asNode(name).ast, asNode(initializer).ast).node; + } + + // @api + function createShorthandPropertyAssignment(name: string | Identifier, objectAssignmentInitializer?: Expression): ShorthandPropertyAssignment { + return astFactory.createShorthandPropertyAssignment(asName(name).ast, asNode(objectAssignmentInitializer)?.ast).node; + } + + // @api + function updateShorthandPropertyAssignment(node: ShorthandPropertyAssignment, name: Identifier, objectAssignmentInitializer: Expression | undefined): ShorthandPropertyAssignment { + return astFactory.updateShorthandPropertyAssignment(asNode(node).ast, asNode(name).ast, asNode(objectAssignmentInitializer)?.ast).node; + } + + // @api + function createSpreadAssignment(expression: Expression): SpreadAssignment { + return astFactory.createSpreadAssignment(asNode(expression).ast).node; } // @api - function updateSpreadAssignment(node: SpreadAssignment, expression: Expression) { - return node.expression !== expression - ? update(createSpreadAssignment(expression), node) - : node; + function updateSpreadAssignment(node: SpreadAssignment, expression: Expression): SpreadAssignment { + return astFactory.updateSpreadAssignment(asNode(node).ast, asNode(expression).ast).node; } // @@ -6003,24 +3559,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // // @api - function createEnumMember(name: string | PropertyName, initializer?: Expression) { - const node = createBaseDeclaration(SyntaxKind.EnumMember); - node.name = asName(name); - node.initializer = initializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer); - node.transformFlags |= propagateChildFlags(node.name) | - propagateChildFlags(node.initializer) | - TransformFlags.ContainsTypeScript; - - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - return node; + function createEnumMember(name: string | PropertyName, initializer?: Expression): EnumMember { + return astFactory.createEnumMember(asName(name).ast, asNode(initializer)?.ast).node; } // @api - function updateEnumMember(node: EnumMember, name: PropertyName, initializer: Expression | undefined) { - return node.name !== name - || node.initializer !== initializer - ? update(createEnumMember(name, initializer), node) - : node; + function updateEnumMember(node: EnumMember, name: PropertyName, initializer: Expression | undefined): EnumMember { + return astFactory.updateEnumMember(asNode(node).ast, asNode(name).ast, asNode(initializer)?.ast).node; } // @@ -6032,136 +3577,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode statements: readonly Statement[], endOfFileToken: EndOfFileToken, flags: NodeFlags, - ) { - const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as Mutable; - node.statements = createNodeArray(statements); - node.endOfFileToken = endOfFileToken; - node.flags |= flags; - node.text = ""; - node.fileName = ""; - node.path = "" as Path; - node.resolvedPath = "" as Path; - node.originalFileName = ""; - node.languageVersion = ScriptTarget.ES5; - node.languageVariant = 0; - node.scriptKind = 0; - node.isDeclarationFile = false; - node.hasNoDefaultLib = false; - - node.transformFlags |= propagateChildrenFlags(node.statements) | - propagateChildFlags(node.endOfFileToken); - - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) - node.endFlowNode = undefined; - - node.nodeCount = 0; - node.identifierCount = 0; - node.symbolCount = 0; - node.parseDiagnostics = undefined!; - node.bindDiagnostics = undefined!; - node.bindSuggestionDiagnostics = undefined; - node.lineMap = undefined!; - node.externalModuleIndicator = undefined; - node.setExternalModuleIndicator = undefined; - node.pragmas = undefined!; - node.checkJsDirective = undefined; - node.referencedFiles = undefined!; - node.typeReferenceDirectives = undefined!; - node.libReferenceDirectives = undefined!; - node.amdDependencies = undefined!; - node.commentDirectives = undefined; - node.identifiers = undefined!; - node.packageJsonLocations = undefined; - node.packageJsonScope = undefined; - node.imports = undefined!; - node.moduleAugmentations = undefined!; - node.ambientModuleNames = undefined!; - node.classifiableNames = undefined; - node.impliedNodeFormat = undefined; - return node; - } - - function createRedirectedSourceFile(redirectInfo: RedirectInfo) { - const node: SourceFile = Object.create(redirectInfo.redirectTarget); - Object.defineProperties(node, { - id: { - get(this: SourceFile) { - return this.redirectInfo!.redirectTarget.id; - }, - set(this: SourceFile, value: SourceFile["id"]) { - this.redirectInfo!.redirectTarget.id = value; - }, - }, - symbol: { - get(this: SourceFile) { - return this.redirectInfo!.redirectTarget.symbol; - }, - set(this: SourceFile, value: SourceFile["symbol"]) { - this.redirectInfo!.redirectTarget.symbol = value; - }, - }, - }); - node.redirectInfo = redirectInfo; - return node; - } - - function cloneRedirectedSourceFile(source: SourceFile) { - const node = createRedirectedSourceFile(source.redirectInfo!) as Mutable; - node.flags |= source.flags & ~NodeFlags.Synthesized; - node.fileName = source.fileName; - node.path = source.path; - node.resolvedPath = source.resolvedPath; - node.originalFileName = source.originalFileName; - node.packageJsonLocations = source.packageJsonLocations; - node.packageJsonScope = source.packageJsonScope; - node.emitNode = undefined; - return node; - } - - function cloneSourceFileWorker(source: SourceFile) { - // TODO: This mechanism for cloning results in megamorphic property reads and writes. In future perf-related - // work, we should consider switching explicit property assignments instead of using `for..in`. - const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as Mutable; - node.flags |= source.flags & ~NodeFlags.Synthesized; - for (const p in source) { - if (hasProperty(node, p) || !hasProperty(source, p)) { - continue; - } - if (p === "emitNode") { - node.emitNode = undefined; - continue; - } - (node as any)[p] = (source as any)[p]; - } - return node; - } - - function cloneSourceFile(source: SourceFile) { - const node = source.redirectInfo ? cloneRedirectedSourceFile(source) : cloneSourceFileWorker(source); - setOriginal(node, source); - return node; + ): SourceFile { + return astFactory.createSourceFile(asNodeArray(statements).ast, asNode(endOfFileToken).ast, flags).node; } - function cloneSourceFileWithChanges( - source: SourceFile, - statements: readonly Statement[], - isDeclarationFile: boolean, - referencedFiles: readonly FileReference[], - typeReferences: readonly FileReference[], - hasNoDefaultLib: boolean, - libReferences: readonly FileReference[], - ) { - const node = cloneSourceFile(source); - node.statements = createNodeArray(statements); - node.isDeclarationFile = isDeclarationFile; - node.referencedFiles = referencedFiles; - node.typeReferenceDirectives = typeReferences; - node.hasNoDefaultLib = hasNoDefaultLib; - node.libReferenceDirectives = libReferences; - node.transformFlags = propagateChildrenFlags(node.statements) | - propagateChildFlags(node.endOfFileToken); - return node; + // @api + function createRedirectedSourceFile(redirectInfo: RedirectInfo): SourceFile { + return astFactory.createRedirectedSourceFile(redirectInfo).node; } // @api @@ -6173,33 +3595,26 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeReferenceDirectives = node.typeReferenceDirectives, hasNoDefaultLib = node.hasNoDefaultLib, libReferenceDirectives = node.libReferenceDirectives, - ) { - return node.statements !== statements - || node.isDeclarationFile !== isDeclarationFile - || node.referencedFiles !== referencedFiles - || node.typeReferenceDirectives !== typeReferenceDirectives - || node.hasNoDefaultLib !== hasNoDefaultLib - || node.libReferenceDirectives !== libReferenceDirectives - ? update(cloneSourceFileWithChanges(node, statements, isDeclarationFile, referencedFiles, typeReferenceDirectives, hasNoDefaultLib, libReferenceDirectives), node) - : node; - } - - // @api - function createBundle(sourceFiles: readonly SourceFile[]) { - const node = createBaseNode(SyntaxKind.Bundle); - node.sourceFiles = sourceFiles; - node.syntheticFileReferences = undefined; - node.syntheticTypeReferences = undefined; - node.syntheticLibReferences = undefined; - node.hasNoDefaultLib = undefined; - return node; + ): SourceFile { + return astFactory.updateSourceFile( + asNode(node).ast, + asNodeArray(statements).ast, + isDeclarationFile, + referencedFiles, + typeReferenceDirectives, + hasNoDefaultLib, + libReferenceDirectives, + ).node; + } + + // @api + function createBundle(sourceFiles: readonly SourceFile[]): Bundle { + return astFactory.createBundle(sourceFiles as readonly ast.SourceFile[]).node; } // @api - function updateBundle(node: Bundle, sourceFiles: readonly SourceFile[]) { - return node.sourceFiles !== sourceFiles - ? update(createBundle(sourceFiles), node) - : node; + function updateBundle(node: Bundle, sourceFiles: readonly SourceFile[]): Bundle { + return astFactory.updateBundle(asNode(node).ast, sourceFiles as readonly ast.SourceFile[]).node; } // @@ -6207,19 +3622,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // // @api - function createSyntheticExpression(type: Type, isSpread = false, tupleNameSource?: ParameterDeclaration | NamedTupleMember) { - const node = createBaseNode(SyntaxKind.SyntheticExpression); - node.type = type; - node.isSpread = isSpread; - node.tupleNameSource = tupleNameSource; - return node; + function createSyntheticExpression(type: Type, isSpread = false, tupleNameSource?: ParameterDeclaration | NamedTupleMember): SyntheticExpression { + return astFactory.createSyntheticExpression(type, isSpread, asNode(tupleNameSource)?.ast).node; } // @api - function createSyntaxList(children: readonly Node[]) { - const node = createBaseNode(SyntaxKind.SyntaxList); - node._children = children; - return node; + function createSyntaxList(children: readonly Node[]): SyntaxList { + return astFactory.createSyntaxList(children as readonly ast.Node[]).node; } // @@ -6233,11 +3642,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode * @param original The original statement. */ // @api - function createNotEmittedStatement(original: Node) { - const node = createBaseNode(SyntaxKind.NotEmittedStatement); - node.original = original; - setTextRange(node, original); - return node; + function createNotEmittedStatement(original: Node): NotEmittedStatement { + return astFactory.createNotEmittedStatement(asNode(original).ast).node; } /** @@ -6248,155 +3654,44 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode * @param original The original outer expression. */ // @api - function createPartiallyEmittedExpression(expression: Expression, original?: Node) { - const node = createBaseNode(SyntaxKind.PartiallyEmittedExpression); - node.expression = expression; - node.original = original; - node.transformFlags |= propagateChildFlags(node.expression) | - TransformFlags.ContainsTypeScript; - setTextRange(node, original); - return node; + function createPartiallyEmittedExpression(expression: Expression, original?: Node): PartiallyEmittedExpression { + return astFactory.createPartiallyEmittedExpression(asNode(expression).ast, asNode(original)?.ast).node; } // @api - function updatePartiallyEmittedExpression(node: PartiallyEmittedExpression, expression: Expression) { - return node.expression !== expression - ? update(createPartiallyEmittedExpression(expression, node.original), node) - : node; + function updatePartiallyEmittedExpression(node: PartiallyEmittedExpression, expression: Expression): PartiallyEmittedExpression { + return astFactory.updatePartiallyEmittedExpression(asNode(node).ast, asNode(expression).ast).node; } // @api - function createNotEmittedTypeElement() { - return createBaseNode(SyntaxKind.NotEmittedTypeElement); - } - - function flattenCommaElements(node: Expression): Expression | readonly Expression[] { - if (nodeIsSynthesized(node) && !isParseTreeNode(node) && !node.original && !node.emitNode && !node.id) { - if (isCommaListExpression(node)) { - return node.elements; - } - if (isBinaryExpression(node) && isCommaToken(node.operatorToken)) { - return [node.left, node.right]; - } - } - return node; + function createNotEmittedTypeElement(): NotEmittedTypeElement { + return astFactory.createNotEmittedTypeElement().node; } // @api - function createCommaListExpression(elements: readonly Expression[]) { - const node = createBaseNode(SyntaxKind.CommaListExpression); - node.elements = createNodeArray(sameFlatMap(elements, flattenCommaElements)); - node.transformFlags |= propagateChildrenFlags(node.elements); - return node; + function createCommaListExpression(elements: readonly Expression[]): CommaListExpression { + return astFactory.createCommaListExpression(asNodeArray(elements).ast).node; } // @api - function updateCommaListExpression(node: CommaListExpression, elements: readonly Expression[]) { - return node.elements !== elements - ? update(createCommaListExpression(elements), node) - : node; + function updateCommaListExpression(node: CommaListExpression, elements: readonly Expression[]): CommaListExpression { + return astFactory.updateCommaListExpression(asNode(node).ast, asNodeArray(elements).ast).node; } // @api - function createSyntheticReferenceExpression(expression: Expression, thisArg: Expression) { - const node = createBaseNode(SyntaxKind.SyntheticReferenceExpression); - node.expression = expression; - node.thisArg = thisArg; - node.transformFlags |= propagateChildFlags(node.expression) | - propagateChildFlags(node.thisArg); - return node; + function createSyntheticReferenceExpression(expression: Expression, thisArg: Expression): SyntheticReferenceExpression { + return astFactory.createSyntheticReferenceExpression(asNode(expression).ast, asNode(thisArg).ast).node; } // @api - function updateSyntheticReferenceExpression(node: SyntheticReferenceExpression, expression: Expression, thisArg: Expression) { - return node.expression !== expression - || node.thisArg !== thisArg - ? update(createSyntheticReferenceExpression(expression, thisArg), node) - : node; - } - - function cloneGeneratedIdentifier(node: GeneratedIdentifier): GeneratedIdentifier { - const clone = createBaseIdentifier(node.escapedText) as Mutable; - clone.flags |= node.flags & ~NodeFlags.Synthesized; - clone.transformFlags = node.transformFlags; - setOriginal(clone, node); - setIdentifierAutoGenerate(clone, { ...node.emitNode.autoGenerate }); - return clone; - } - - function cloneIdentifier(node: Identifier): Identifier { - const clone = createBaseIdentifier(node.escapedText); - clone.flags |= node.flags & ~NodeFlags.Synthesized; - clone.jsDoc = node.jsDoc; - clone.flowNode = node.flowNode; - clone.symbol = node.symbol; - clone.transformFlags = node.transformFlags; - setOriginal(clone, node); - - // clone type arguments for emitter/typeWriter - const typeArguments = getIdentifierTypeArguments(node); - if (typeArguments) setIdentifierTypeArguments(clone, typeArguments); - return clone; - } - - function cloneGeneratedPrivateIdentifier(node: GeneratedPrivateIdentifier): GeneratedPrivateIdentifier { - const clone = createBasePrivateIdentifier(node.escapedText) as Mutable; - clone.flags |= node.flags & ~NodeFlags.Synthesized; - clone.transformFlags = node.transformFlags; - setOriginal(clone, node); - setIdentifierAutoGenerate(clone, { ...node.emitNode.autoGenerate }); - return clone; - } - - function clonePrivateIdentifier(node: PrivateIdentifier): PrivateIdentifier { - const clone = createBasePrivateIdentifier(node.escapedText); - clone.flags |= node.flags & ~NodeFlags.Synthesized; - clone.transformFlags = node.transformFlags; - setOriginal(clone, node); - return clone; + function updateSyntheticReferenceExpression(node: SyntheticReferenceExpression, expression: Expression, thisArg: Expression): SyntheticReferenceExpression { + return astFactory.updateSyntheticReferenceExpression(asNode(node).ast, asNode(expression).ast, asNode(thisArg).ast).node; } // @api function cloneNode(node: T): T; - function cloneNode(node: T) { - // We don't use "clone" from core.ts here, as we need to preserve the prototype chain of - // the original node. We also need to exclude specific properties and only include own- - // properties (to skip members already defined on the shared prototype). - if (node === undefined) { - return node; - } - if (isSourceFile(node)) { - return cloneSourceFile(node) as T & SourceFile; - } - if (isGeneratedIdentifier(node)) { - return cloneGeneratedIdentifier(node) as T & GeneratedIdentifier; - } - if (isIdentifier(node)) { - return cloneIdentifier(node) as T & Identifier; - } - if (isGeneratedPrivateIdentifier(node)) { - return cloneGeneratedPrivateIdentifier(node) as T & GeneratedPrivateIdentifier; - } - if (isPrivateIdentifier(node)) { - return clonePrivateIdentifier(node) as T & PrivateIdentifier; - } - - const clone = !isNodeKind(node.kind) ? baseFactory.createBaseTokenNode(node.kind) as T : - baseFactory.createBaseNode(node.kind) as T; - - (clone as Mutable).flags |= node.flags & ~NodeFlags.Synthesized; - (clone as Mutable).transformFlags = node.transformFlags; - setOriginal(clone, node); - - for (const key in node) { - if (hasProperty(clone, key) || !hasProperty(node, key)) { - continue; - } - - clone[key] = node[key]; - } - - return clone; + function cloneNode(node: Node | undefined) { + return node && astFactory.cloneNode(asNode(node).ast).node as Node | undefined; } // compound nodes @@ -7124,36 +4419,55 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } } - function asNodeArray(array: readonly T[]): NodeArray; - function asNodeArray(array: readonly T[] | undefined): NodeArray | undefined; - function asNodeArray(array: readonly T[] | undefined): NodeArray | undefined { - return array ? createNodeArray(array) : undefined; - } + type ToNode = + Expression extends T ? ast.Expression : + Statement extends T ? ast.Statement : + TypeNode extends T ? ast.TypeNode : + TypeElement extends T ? ast.TypeElement : + ClassElement extends T ? ast.ClassElement : + ObjectLiteralElement extends T ? ast.ObjectLiteralElement : + PropertyAccessChain extends T ? ast.PropertyAccessChain : + ElementAccessChain extends T ? ast.ElementAccessChain : + CallChain extends T ? ast.CallChain : + NonNullChain extends T ? ast.NonNullChain : + ModuleBody extends T ? ast.ModuleBody : + LiteralExpression extends T ? ast.LiteralExpression : + JSDocNamespaceDeclaration extends T ? ast.JSDocNamespaceDeclaration : + JSDocPropertyLikeTag extends T ? ast.JSDocPropertyLikeTag : + JSDocClassReference extends T ? ast.JSDocClassReference : + JsxNamespacedName extends T ? ast.JsxNamespacedName : + ast.NodeType[T["kind"]]; - function asName(name: string | T): T | Identifier { - return typeof name === "string" ? createIdentifier(name) : - name; + function asNode(node: T): ToNode; + function asNode(node: T | undefined): ToNode | undefined; + function asNode(node: Node | undefined): ast.Node | undefined { + return node as ast.Node | undefined; } - function asExpression(value: string | number | boolean | T): T | StringLiteral | NumericLiteral | BooleanLiteral { - return typeof value === "string" ? createStringLiteral(value) : - typeof value === "number" ? createNumericLiteral(value) : - typeof value === "boolean" ? value ? createTrue() : createFalse() : - value; + function asNodeArray(array: readonly T[]): ast.NodeArray>; + function asNodeArray(array: readonly T[] | undefined): ast.NodeArray> | undefined; + function asNodeArray(array: readonly Node[] | undefined): ast.NodeArray | undefined { + return array ? createNodeArray(array) as ast.NodeArray : undefined; } - function asInitializer(node: Expression | undefined) { - return node && parenthesizerRules().parenthesizeExpressionForDisallowedComma(node); + function asName(name: string | T): ToNode | ast.Identifier; + function asName(name: string | T | undefined): ToNode | ast.Identifier | undefined; + function asName(name: string | DeclarationName | Identifier | BindingName | PropertyName | NoSubstitutionTemplateLiteral | EntityName | ThisTypeNode | undefined) { + return typeof name === "string" ? createIdentifier(name) as ast.Identifier : + name as Node as ast.Node as ToNode; } - function asToken(value: TKind | Token): Token { - return typeof value === "number" ? createToken(value) : value; + function asExpression(value: string | number | boolean | T): ToNode | ast.StringLiteral | ast.NumericLiteral | ast.BooleanLiteral; + function asExpression(value: string | number | boolean | T | undefined): ToNode | ast.StringLiteral | ast.NumericLiteral | ast.BooleanLiteral | undefined; + function asExpression(value: string | number | boolean | Expression | undefined): ast.Expression | undefined | ast.StringLiteral | ast.NumericLiteral | ast.BooleanLiteral | undefined { + return typeof value === "string" ? createStringLiteral(value) as ast.StringLiteral : + typeof value === "number" ? createNumericLiteral(value) as ast.NumericLiteral : + typeof value === "boolean" ? value ? createTrue() as ast.TrueLiteral : createFalse() as ast.FalseLiteral : + value as ast.Expression; } - function asEmbeddedStatement(statement: T): T | EmptyStatement; - function asEmbeddedStatement(statement: T | undefined): T | EmptyStatement | undefined; - function asEmbeddedStatement(statement: T | undefined): T | EmptyStatement | undefined { - return statement && isNotEmittedStatement(statement) ? setTextRange(setOriginal(createEmptyStatement(), statement), statement) : statement; + function asToken(value: TKind | Token): ast.Token { + return (typeof value === "number" ? createToken(value) : value) as ast.Token; } function asVariableDeclaration(variableDeclaration: string | BindingName | VariableDeclaration | undefined) { @@ -7163,153 +4477,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode /*exclamationToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined, - ); + ) as ast.VariableDeclaration; } - return variableDeclaration; - } - - function update(updated: Mutable, original: T): T { - if (updated !== original) { - setOriginal(updated, original); - setTextRange(updated, original); - } - return updated; - } -} - -function getDefaultTagNameForKind(kind: JSDocTag["kind"]): string { - switch (kind) { - case SyntaxKind.JSDocTypeTag: - return "type"; - case SyntaxKind.JSDocReturnTag: - return "returns"; - case SyntaxKind.JSDocThisTag: - return "this"; - case SyntaxKind.JSDocEnumTag: - return "enum"; - case SyntaxKind.JSDocAuthorTag: - return "author"; - case SyntaxKind.JSDocClassTag: - return "class"; - case SyntaxKind.JSDocPublicTag: - return "public"; - case SyntaxKind.JSDocPrivateTag: - return "private"; - case SyntaxKind.JSDocProtectedTag: - return "protected"; - case SyntaxKind.JSDocReadonlyTag: - return "readonly"; - case SyntaxKind.JSDocOverrideTag: - return "override"; - case SyntaxKind.JSDocTemplateTag: - return "template"; - case SyntaxKind.JSDocTypedefTag: - return "typedef"; - case SyntaxKind.JSDocParameterTag: - return "param"; - case SyntaxKind.JSDocPropertyTag: - return "prop"; - case SyntaxKind.JSDocCallbackTag: - return "callback"; - case SyntaxKind.JSDocOverloadTag: - return "overload"; - case SyntaxKind.JSDocAugmentsTag: - return "augments"; - case SyntaxKind.JSDocImplementsTag: - return "implements"; - case SyntaxKind.JSDocImportTag: - return "import"; - default: - return Debug.fail(`Unsupported kind: ${Debug.formatSyntaxKind(kind)}`); - } -} - -let rawTextScanner: Scanner | undefined; -const invalidValueSentinel: object = {}; - -function getCookedText(kind: TemplateLiteralToken["kind"], rawText: string) { - if (!rawTextScanner) { - rawTextScanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false, LanguageVariant.Standard); - } - switch (kind) { - case SyntaxKind.NoSubstitutionTemplateLiteral: - rawTextScanner.setText("`" + rawText + "`"); - break; - case SyntaxKind.TemplateHead: - rawTextScanner.setText("`" + rawText + "${"); - break; - case SyntaxKind.TemplateMiddle: - rawTextScanner.setText("}" + rawText + "${"); - break; - case SyntaxKind.TemplateTail: - rawTextScanner.setText("}" + rawText + "`"); - break; - } - - let token = rawTextScanner.scan(); - if (token === SyntaxKind.CloseBraceToken) { - token = rawTextScanner.reScanTemplateToken(/*isTaggedTemplate*/ false); - } - - if (rawTextScanner.isUnterminated()) { - rawTextScanner.setText(undefined); - return invalidValueSentinel; - } - - let tokenValue: string | undefined; - switch (token) { - case SyntaxKind.NoSubstitutionTemplateLiteral: - case SyntaxKind.TemplateHead: - case SyntaxKind.TemplateMiddle: - case SyntaxKind.TemplateTail: - tokenValue = rawTextScanner.getTokenValue(); - break; - } - - if (tokenValue === undefined || rawTextScanner.scan() !== SyntaxKind.EndOfFileToken) { - rawTextScanner.setText(undefined); - return invalidValueSentinel; - } - - rawTextScanner.setText(undefined); - return tokenValue; -} - -function propagateNameFlags(node: PropertyName | BindingPattern | NoSubstitutionTemplateLiteral | undefined) { - return node && isIdentifier(node) ? propagateIdentifierNameFlags(node) : propagateChildFlags(node); -} - -function propagateIdentifierNameFlags(node: Identifier) { - // An IdentifierName is allowed to be `await` - return propagateChildFlags(node) & ~TransformFlags.ContainsPossibleTopLevelAwait; -} - -function propagatePropertyNameFlagsOfChild(node: PropertyName, transformFlags: TransformFlags) { - return transformFlags | (node.transformFlags & TransformFlags.PropertyNamePropagatingFlags); -} - -function propagateChildFlags(child: Node | undefined): TransformFlags { - if (!child) return TransformFlags.None; - const childFlags = child.transformFlags & ~getTransformFlagsSubtreeExclusions(child.kind); - return isNamedDeclaration(child) && isPropertyName(child.name) ? propagatePropertyNameFlagsOfChild(child.name, childFlags) : childFlags; -} - -function propagateChildrenFlags(children: NodeArray | undefined): TransformFlags { - return children ? children.transformFlags : TransformFlags.None; -} - -function aggregateChildrenFlags(children: MutableNodeArray) { - let subtreeFlags = TransformFlags.None; - for (const child of children) { - subtreeFlags |= propagateChildFlags(child); + return variableDeclaration as ast.BindingName | ast.VariableDeclaration | undefined; } - children.transformFlags = subtreeFlags; } /** * Gets the transform flags to exclude when unioning the transform flags of a subtree. + * @internal */ -function getTransformFlagsSubtreeExclusions(kind: SyntaxKind) { +export function getTransformFlagsSubtreeExclusions(kind: SyntaxKind) { if (kind >= SyntaxKind.FirstTypeNode && kind <= SyntaxKind.LastTypeNode) { return TransformFlags.TypeExcludes; } @@ -7381,22 +4559,7 @@ function getTransformFlagsSubtreeExclusions(kind: SyntaxKind) { } } -const baseFactory = createBaseNodeFactory(); - -function makeSynthetic(node: Node) { - (node as Mutable).flags |= NodeFlags.Synthesized; - return node; -} - -const syntheticFactory: BaseNodeFactory = { - createBaseSourceFileNode: kind => makeSynthetic(baseFactory.createBaseSourceFileNode(kind)), - createBaseIdentifierNode: kind => makeSynthetic(baseFactory.createBaseIdentifierNode(kind)), - createBasePrivateIdentifierNode: kind => makeSynthetic(baseFactory.createBasePrivateIdentifierNode(kind)), - createBaseTokenNode: kind => makeSynthetic(baseFactory.createBaseTokenNode(kind)), - createBaseNode: kind => makeSynthetic(baseFactory.createBaseNode(kind)), -}; - -export const factory = createNodeFactory(NodeFactoryFlags.NoIndentationOnFreshPropertyAccess, syntheticFactory); +export const factory = createNodeFactory(NodeFactoryFlags.NoIndentationOnFreshPropertyAccess | NodeFactoryFlags.Synthesized); let SourceMapSource: new (fileName: string, text: string, skipTrivia?: (pos: number) => number) => SourceMapSource; @@ -7420,7 +4583,8 @@ export function setOriginalNode(node: T, original: Node | undefi return node; } -function mergeEmitNode(sourceEmitNode: EmitNode, destEmitNode: EmitNode | undefined) { +/** @internal */ +export function mergeEmitNode(sourceEmitNode: EmitNode, destEmitNode: EmitNode | undefined) { const { flags, internalFlags, diff --git a/src/compiler/factory/parenthesizerRules.ts b/src/compiler/factory/parenthesizerRules.ts index 3a67604847438..a39efee11a950 100644 --- a/src/compiler/factory/parenthesizerRules.ts +++ b/src/compiler/factory/parenthesizerRules.ts @@ -1,60 +1,41 @@ import { - Associativity, - BinaryExpression, + ast, BinaryOperator, + CallChain, cast, - compareValues, - Comparison, + ClassElement, ConciseBody, + ElementAccessChain, Expression, - getExpressionAssociativity, - getExpressionPrecedence, - getLeftmostExpression, - getOperatorAssociativity, - getOperatorPrecedence, identity, - isBinaryExpression, - isBlock, - isCallExpression, - isCommaSequence, - isConditionalTypeNode, - isConstructorTypeNode, - isFunctionOrConstructorTypeNode, - isFunctionTypeNode, - isInferTypeNode, - isIntersectionTypeNode, - isJSDocNullableType, isLeftHandSideExpression, - isLiteralKind, - isNamedTupleMember, isNodeArray, - isOptionalChain, - isTypeOperatorNode, isUnaryExpression, - isUnionTypeNode, - last, + JSDocClassReference, + JSDocNamespaceDeclaration, + JSDocPropertyLikeTag, + JsxNamespacedName, LeftHandSideExpression, + LiteralExpression, + ModuleBody, NamedTupleMember, - NewExpression, + Node, NodeArray, NodeFactory, - OperatorPrecedence, - OuterExpressionKinds, + NonNullChain, + ObjectLiteralElement, ParenthesizerRules, - sameMap, - setTextRange, - skipPartiallyEmittedExpressions, - some, + PropertyAccessChain, + Statement, SyntaxKind, + TypeElement, TypeNode, - UnaryExpression, + UnaryExpression } from "../_namespaces/ts.js"; /** @internal */ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRules { - interface BinaryPlusExpression extends BinaryExpression { - cachedLiteralKind: SyntaxKind; - } + const astRules = factory.astFactory.parenthesizer; let binaryLeftOperandParenthesizerCache: Map Expression> | undefined; let binaryRightOperandParenthesizerCache: Map Expression> | undefined; @@ -112,549 +93,149 @@ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRul return parenthesizerRule; } - /** - * Determines whether the operand to a BinaryExpression needs to be parenthesized. - * - * @param binaryOperator The operator for the BinaryExpression. - * @param operand The operand for the BinaryExpression. - * @param isLeftSideOfBinary A value indicating whether the operand is the left side of the - * BinaryExpression. - */ - function binaryOperandNeedsParentheses(binaryOperator: SyntaxKind, operand: Expression, isLeftSideOfBinary: boolean, leftOperand: Expression | undefined) { - // If the operand has lower precedence, then it needs to be parenthesized to preserve the - // intent of the expression. For example, if the operand is `a + b` and the operator is - // `*`, then we need to parenthesize the operand to preserve the intended order of - // operations: `(a + b) * x`. - // - // If the operand has higher precedence, then it does not need to be parenthesized. For - // example, if the operand is `a * b` and the operator is `+`, then we do not need to - // parenthesize to preserve the intended order of operations: `a * b + x`. - // - // If the operand has the same precedence, then we need to check the associativity of - // the operator based on whether this is the left or right operand of the expression. - // - // For example, if `a / d` is on the right of operator `*`, we need to parenthesize - // to preserve the intended order of operations: `x * (a / d)` - // - // If `a ** d` is on the left of operator `**`, we need to parenthesize to preserve - // the intended order of operations: `(a ** b) ** c` - const binaryOperatorPrecedence = getOperatorPrecedence(SyntaxKind.BinaryExpression, binaryOperator); - const binaryOperatorAssociativity = getOperatorAssociativity(SyntaxKind.BinaryExpression, binaryOperator); - const emittedOperand = skipPartiallyEmittedExpressions(operand); - if (!isLeftSideOfBinary && operand.kind === SyntaxKind.ArrowFunction && binaryOperatorPrecedence > OperatorPrecedence.Assignment) { - // We need to parenthesize arrow functions on the right side to avoid it being - // parsed as parenthesized expression: `a && (() => {})` - return true; - } - const operandPrecedence = getExpressionPrecedence(emittedOperand); - switch (compareValues(operandPrecedence, binaryOperatorPrecedence)) { - case Comparison.LessThan: - // If the operand is the right side of a right-associative binary operation - // and is a yield expression, then we do not need parentheses. - if ( - !isLeftSideOfBinary - && binaryOperatorAssociativity === Associativity.Right - && operand.kind === SyntaxKind.YieldExpression - ) { - return false; - } - - return true; - - case Comparison.GreaterThan: - return false; - - case Comparison.EqualTo: - if (isLeftSideOfBinary) { - // No need to parenthesize the left operand when the binary operator is - // left associative: - // (a*b)/x -> a*b/x - // (a**b)/x -> a**b/x - // - // Parentheses are needed for the left operand when the binary operator is - // right associative: - // (a/b)**x -> (a/b)**x - // (a**b)**x -> (a**b)**x - return binaryOperatorAssociativity === Associativity.Right; - } - else { - if ( - isBinaryExpression(emittedOperand) - && emittedOperand.operatorToken.kind === binaryOperator - ) { - // No need to parenthesize the right operand when the binary operator and - // operand are the same and one of the following: - // x*(a*b) => x*a*b - // x|(a|b) => x|a|b - // x&(a&b) => x&a&b - // x^(a^b) => x^a^b - if (operatorHasAssociativeProperty(binaryOperator)) { - return false; - } - - // No need to parenthesize the right operand when the binary operator - // is plus (+) if both the left and right operands consist solely of either - // literals of the same kind or binary plus (+) expressions for literals of - // the same kind (recursively). - // "a"+(1+2) => "a"+(1+2) - // "a"+("b"+"c") => "a"+"b"+"c" - if (binaryOperator === SyntaxKind.PlusToken) { - const leftKind = leftOperand ? getLiteralKindOfBinaryPlusOperand(leftOperand) : SyntaxKind.Unknown; - if (isLiteralKind(leftKind) && leftKind === getLiteralKindOfBinaryPlusOperand(emittedOperand)) { - return false; - } - } - } - - // No need to parenthesize the right operand when the operand is right - // associative: - // x/(a**b) -> x/a**b - // x**(a**b) -> x**a**b - // - // Parentheses are needed for the right operand when the operand is left - // associative: - // x/(a*b) -> x/(a*b) - // x**(a/b) -> x**(a/b) - const operandAssociativity = getExpressionAssociativity(emittedOperand); - return operandAssociativity === Associativity.Left; - } - } - } - - /** - * Determines whether a binary operator is mathematically associative. - * - * @param binaryOperator The binary operator. - */ - function operatorHasAssociativeProperty(binaryOperator: SyntaxKind) { - // The following operators are associative in JavaScript: - // (a*b)*c -> a*(b*c) -> a*b*c - // (a|b)|c -> a|(b|c) -> a|b|c - // (a&b)&c -> a&(b&c) -> a&b&c - // (a^b)^c -> a^(b^c) -> a^b^c - // (a,b),c -> a,(b,c) -> a,b,c - // - // While addition is associative in mathematics, JavaScript's `+` is not - // guaranteed to be associative as it is overloaded with string concatenation. - return binaryOperator === SyntaxKind.AsteriskToken - || binaryOperator === SyntaxKind.BarToken - || binaryOperator === SyntaxKind.AmpersandToken - || binaryOperator === SyntaxKind.CaretToken - || binaryOperator === SyntaxKind.CommaToken; - } - - /** - * This function determines whether an expression consists of a homogeneous set of - * literal expressions or binary plus expressions that all share the same literal kind. - * It is used to determine whether the right-hand operand of a binary plus expression can be - * emitted without parentheses. - */ - function getLiteralKindOfBinaryPlusOperand(node: Expression): SyntaxKind { - node = skipPartiallyEmittedExpressions(node); - - if (isLiteralKind(node.kind)) { - return node.kind; - } - - if (node.kind === SyntaxKind.BinaryExpression && (node as BinaryExpression).operatorToken.kind === SyntaxKind.PlusToken) { - if ((node as BinaryPlusExpression).cachedLiteralKind !== undefined) { - return (node as BinaryPlusExpression).cachedLiteralKind; - } - - const leftKind = getLiteralKindOfBinaryPlusOperand((node as BinaryExpression).left); - const literalKind = isLiteralKind(leftKind) - && leftKind === getLiteralKindOfBinaryPlusOperand((node as BinaryExpression).right) - ? leftKind - : SyntaxKind.Unknown; - - (node as BinaryPlusExpression).cachedLiteralKind = literalKind; - return literalKind; - } - - return SyntaxKind.Unknown; - } - - /** - * Wraps the operand to a BinaryExpression in parentheses if they are needed to preserve the intended - * order of operations. - * - * @param binaryOperator The operator for the BinaryExpression. - * @param operand The operand for the BinaryExpression. - * @param isLeftSideOfBinary A value indicating whether the operand is the left side of the - * BinaryExpression. - */ - function parenthesizeBinaryOperand(binaryOperator: SyntaxKind, operand: Expression, isLeftSideOfBinary: boolean, leftOperand?: Expression) { - const skipped = skipPartiallyEmittedExpressions(operand); - - // If the resulting expression is already parenthesized, we do not need to do any further processing. - if (skipped.kind === SyntaxKind.ParenthesizedExpression) { - return operand; - } - - return binaryOperandNeedsParentheses(binaryOperator, operand, isLeftSideOfBinary, leftOperand) - ? factory.createParenthesizedExpression(operand) - : operand; - } - function parenthesizeLeftSideOfBinary(binaryOperator: SyntaxKind, leftSide: Expression): Expression { - return parenthesizeBinaryOperand(binaryOperator, leftSide, /*isLeftSideOfBinary*/ true); + return astRules.parenthesizeLeftSideOfBinary(binaryOperator, asNode(leftSide).ast).node; } function parenthesizeRightSideOfBinary(binaryOperator: SyntaxKind, leftSide: Expression | undefined, rightSide: Expression): Expression { - return parenthesizeBinaryOperand(binaryOperator, rightSide, /*isLeftSideOfBinary*/ false, leftSide); + return astRules.parenthesizeRightSideOfBinary(binaryOperator, asNode(leftSide)?.ast, asNode(rightSide).ast).node; } function parenthesizeExpressionOfComputedPropertyName(expression: Expression): Expression { - return isCommaSequence(expression) ? factory.createParenthesizedExpression(expression) : expression; + return astRules.parenthesizeExpressionOfComputedPropertyName(asNode(expression).ast).node; } function parenthesizeConditionOfConditionalExpression(condition: Expression): Expression { - const conditionalPrecedence = getOperatorPrecedence(SyntaxKind.ConditionalExpression, SyntaxKind.QuestionToken); - const emittedCondition = skipPartiallyEmittedExpressions(condition); - const conditionPrecedence = getExpressionPrecedence(emittedCondition); - if (compareValues(conditionPrecedence, conditionalPrecedence) !== Comparison.GreaterThan) { - return factory.createParenthesizedExpression(condition); - } - return condition; + return astRules.parenthesizeConditionOfConditionalExpression(asNode(condition).ast).node; } function parenthesizeBranchOfConditionalExpression(branch: Expression): Expression { - // per ES grammar both 'whenTrue' and 'whenFalse' parts of conditional expression are assignment expressions - // so in case when comma expression is introduced as a part of previous transformations - // if should be wrapped in parens since comma operator has the lowest precedence - const emittedExpression = skipPartiallyEmittedExpressions(branch); - return isCommaSequence(emittedExpression) - ? factory.createParenthesizedExpression(branch) - : branch; - } - - /** - * [Per the spec](https://tc39.github.io/ecma262/#prod-ExportDeclaration), `export default` accepts _AssigmentExpression_ but - * has a lookahead restriction for `function`, `async function`, and `class`. - * - * Basically, that means we need to parenthesize in the following cases: - * - * - BinaryExpression of CommaToken - * - CommaList (synthetic list of multiple comma expressions) - * - FunctionExpression - * - ClassExpression - */ + return astRules.parenthesizeBranchOfConditionalExpression(asNode(branch).ast).node; + } + function parenthesizeExpressionOfExportDefault(expression: Expression): Expression { - const check = skipPartiallyEmittedExpressions(expression); - let needsParens = isCommaSequence(check); - if (!needsParens) { - switch (getLeftmostExpression(check, /*stopAtCallExpressions*/ false).kind) { - case SyntaxKind.ClassExpression: - case SyntaxKind.FunctionExpression: - needsParens = true; - } - } - return needsParens ? factory.createParenthesizedExpression(expression) : expression; + return astRules.parenthesizeExpressionOfExportDefault(asNode(expression).ast).node; } - /** - * Wraps an expression in parentheses if it is needed in order to use the expression - * as the expression of a `NewExpression` node. - */ function parenthesizeExpressionOfNew(expression: Expression): LeftHandSideExpression { - const leftmostExpr = getLeftmostExpression(expression, /*stopAtCallExpressions*/ true); - switch (leftmostExpr.kind) { - case SyntaxKind.CallExpression: - return factory.createParenthesizedExpression(expression); - - case SyntaxKind.NewExpression: - return !(leftmostExpr as NewExpression).arguments - ? factory.createParenthesizedExpression(expression) - : expression as LeftHandSideExpression; // TODO(rbuckton): Verify this assertion holds - } - - return parenthesizeLeftSideOfAccess(expression); + return astRules.parenthesizeExpressionOfNew(asNode(expression).ast).node; } - /** - * Wraps an expression in parentheses if it is needed in order to use the expression for - * property or element access. - */ function parenthesizeLeftSideOfAccess(expression: Expression, optionalChain?: boolean): LeftHandSideExpression { - // isLeftHandSideExpression is almost the correct criterion for when it is not necessary - // to parenthesize the expression before a dot. The known exception is: - // - // NewExpression: - // new C.x -> not the same as (new C).x - // - const emittedExpression = skipPartiallyEmittedExpressions(expression); - if ( - isLeftHandSideExpression(emittedExpression) - && (emittedExpression.kind !== SyntaxKind.NewExpression || (emittedExpression as NewExpression).arguments) - && (optionalChain || !isOptionalChain(emittedExpression)) - ) { - // TODO(rbuckton): Verify whether this assertion holds. - return expression as LeftHandSideExpression; - } - - // TODO(rbuckton): Verifiy whether `setTextRange` is needed. - return setTextRange(factory.createParenthesizedExpression(expression), expression); + return astRules.parenthesizeLeftSideOfAccess(asNode(expression).ast, optionalChain).node; } function parenthesizeOperandOfPostfixUnary(operand: Expression): LeftHandSideExpression { - // TODO(rbuckton): Verifiy whether `setTextRange` is needed. - return isLeftHandSideExpression(operand) ? operand : setTextRange(factory.createParenthesizedExpression(operand), operand); + return astRules.parenthesizeOperandOfPostfixUnary(asNode(operand).ast).node; } function parenthesizeOperandOfPrefixUnary(operand: Expression): UnaryExpression { - // TODO(rbuckton): Verifiy whether `setTextRange` is needed. - return isUnaryExpression(operand) ? operand : setTextRange(factory.createParenthesizedExpression(operand), operand); + return astRules.parenthesizeOperandOfPrefixUnary(asNode(operand).ast).node; } function parenthesizeExpressionsOfCommaDelimitedList(elements: NodeArray): NodeArray { - const result = sameMap(elements, parenthesizeExpressionForDisallowedComma); - return setTextRange(factory.createNodeArray(result, elements.hasTrailingComma), elements); + return astRules.parenthesizeExpressionsOfCommaDelimitedList(asNodeArray(elements).ast).nodes; } function parenthesizeExpressionForDisallowedComma(expression: Expression): Expression { - const emittedExpression = skipPartiallyEmittedExpressions(expression); - const expressionPrecedence = getExpressionPrecedence(emittedExpression); - const commaPrecedence = getOperatorPrecedence(SyntaxKind.BinaryExpression, SyntaxKind.CommaToken); - // TODO(rbuckton): Verifiy whether `setTextRange` is needed. - return expressionPrecedence > commaPrecedence ? expression : setTextRange(factory.createParenthesizedExpression(expression), expression); + return astRules.parenthesizeExpressionForDisallowedComma(asNode(expression).ast).node; } function parenthesizeExpressionOfExpressionStatement(expression: Expression): Expression { - const emittedExpression = skipPartiallyEmittedExpressions(expression); - if (isCallExpression(emittedExpression)) { - const callee = emittedExpression.expression; - const kind = skipPartiallyEmittedExpressions(callee).kind; - if (kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction) { - // TODO(rbuckton): Verifiy whether `setTextRange` is needed. - const updated = factory.updateCallExpression( - emittedExpression, - setTextRange(factory.createParenthesizedExpression(callee), callee), - emittedExpression.typeArguments, - emittedExpression.arguments, - ); - return factory.restoreOuterExpressions(expression, updated, OuterExpressionKinds.PartiallyEmittedExpressions); - } - } - - const leftmostExpressionKind = getLeftmostExpression(emittedExpression, /*stopAtCallExpressions*/ false).kind; - if (leftmostExpressionKind === SyntaxKind.ObjectLiteralExpression || leftmostExpressionKind === SyntaxKind.FunctionExpression) { - // TODO(rbuckton): Verifiy whether `setTextRange` is needed. - return setTextRange(factory.createParenthesizedExpression(expression), expression); - } - - return expression; + return astRules.parenthesizeExpressionOfExpressionStatement(asNode(expression).ast).node; } function parenthesizeConciseBodyOfArrowFunction(body: Expression): Expression; function parenthesizeConciseBodyOfArrowFunction(body: ConciseBody): ConciseBody; function parenthesizeConciseBodyOfArrowFunction(body: ConciseBody): ConciseBody { - if (!isBlock(body) && (isCommaSequence(body) || getLeftmostExpression(body, /*stopAtCallExpressions*/ false).kind === SyntaxKind.ObjectLiteralExpression)) { - // TODO(rbuckton): Verifiy whether `setTextRange` is needed. - return setTextRange(factory.createParenthesizedExpression(body), body); - } - - return body; + return astRules.parenthesizeConciseBodyOfArrowFunction(asNode(body).ast).node; } - // Type[Extends] : - // FunctionOrConstructorType - // ConditionalType[?Extends] - - // ConditionalType[Extends] : - // UnionType[?Extends] - // [~Extends] UnionType[~Extends] `extends` Type[+Extends] `?` Type[~Extends] `:` Type[~Extends] - // - // - The check type (the `UnionType`, above) does not allow function, constructor, or conditional types (they must be parenthesized) - // - The extends type (the first `Type`, above) does not allow conditional types (they must be parenthesized). Function and constructor types are fine. - // - The true and false branch types (the second and third `Type` non-terminals, above) allow any type function parenthesizeCheckTypeOfConditionalType(checkType: TypeNode): TypeNode { - switch (checkType.kind) { - case SyntaxKind.FunctionType: - case SyntaxKind.ConstructorType: - case SyntaxKind.ConditionalType: - return factory.createParenthesizedType(checkType); - } - return checkType; + return astRules.parenthesizeCheckTypeOfConditionalType(asNode(checkType).ast).node; } function parenthesizeExtendsTypeOfConditionalType(extendsType: TypeNode): TypeNode { - switch (extendsType.kind) { - case SyntaxKind.ConditionalType: - return factory.createParenthesizedType(extendsType); - } - return extendsType; - } - - // UnionType[Extends] : - // `|`? IntersectionType[?Extends] - // UnionType[?Extends] `|` IntersectionType[?Extends] - // - // - A union type constituent has the same precedence as the check type of a conditional type - function parenthesizeConstituentTypeOfUnionType(type: TypeNode) { - switch (type.kind) { - case SyntaxKind.UnionType: // Not strictly necessary, but a union containing a union should have been flattened - case SyntaxKind.IntersectionType: // Not strictly necessary, but makes generated output more readable and avoids breaks in DT tests - return factory.createParenthesizedType(type); - } - return parenthesizeCheckTypeOfConditionalType(type); + return astRules.parenthesizeExtendsTypeOfConditionalType(asNode(extendsType).ast).node; + } + + function parenthesizeConstituentTypeOfUnionType(type: TypeNode): TypeNode { + return astRules.parenthesizeConstituentTypeOfUnionType(asNode(type).ast).node; } function parenthesizeConstituentTypesOfUnionType(members: readonly TypeNode[]): NodeArray { - return factory.createNodeArray(sameMap(members, parenthesizeConstituentTypeOfUnionType)); - } - - // IntersectionType[Extends] : - // `&`? TypeOperator[?Extends] - // IntersectionType[?Extends] `&` TypeOperator[?Extends] - // - // - An intersection type constituent does not allow function, constructor, conditional, or union types (they must be parenthesized) - function parenthesizeConstituentTypeOfIntersectionType(type: TypeNode) { - switch (type.kind) { - case SyntaxKind.UnionType: - case SyntaxKind.IntersectionType: // Not strictly necessary, but an intersection containing an intersection should have been flattened - return factory.createParenthesizedType(type); - } - return parenthesizeConstituentTypeOfUnionType(type); + return astRules.parenthesizeConstituentTypesOfUnionType(asNodeArray(members).ast).nodes; + } + + function parenthesizeConstituentTypeOfIntersectionType(type: TypeNode): TypeNode { + return astRules.parenthesizeConstituentTypeOfIntersectionType(asNode(type).ast).node; } function parenthesizeConstituentTypesOfIntersectionType(members: readonly TypeNode[]): NodeArray { - return factory.createNodeArray(sameMap(members, parenthesizeConstituentTypeOfIntersectionType)); + return astRules.parenthesizeConstituentTypesOfIntersectionType(asNodeArray(members).ast).nodes; } - // TypeOperator[Extends] : - // PostfixType - // InferType[?Extends] - // `keyof` TypeOperator[?Extends] - // `unique` TypeOperator[?Extends] - // `readonly` TypeOperator[?Extends] - // function parenthesizeOperandOfTypeOperator(type: TypeNode) { - switch (type.kind) { - case SyntaxKind.IntersectionType: - return factory.createParenthesizedType(type); - } - return parenthesizeConstituentTypeOfIntersectionType(type); + return astRules.parenthesizeOperandOfTypeOperator(asNode(type).ast).node; } function parenthesizeOperandOfReadonlyTypeOperator(type: TypeNode) { - switch (type.kind) { - case SyntaxKind.TypeOperator: - return factory.createParenthesizedType(type); - } - return parenthesizeOperandOfTypeOperator(type); - } - - // PostfixType : - // NonArrayType - // NonArrayType [no LineTerminator here] `!` // JSDoc - // NonArrayType [no LineTerminator here] `?` // JSDoc - // IndexedAccessType - // ArrayType - // - // IndexedAccessType : - // NonArrayType `[` Type[~Extends] `]` - // - // ArrayType : - // NonArrayType `[` `]` - // + return astRules.parenthesizeOperandOfReadonlyTypeOperator(asNode(type).ast).node; + } + function parenthesizeNonArrayTypeOfPostfixType(type: TypeNode) { - switch (type.kind) { - case SyntaxKind.InferType: - case SyntaxKind.TypeOperator: - case SyntaxKind.TypeQuery: // Not strictly necessary, but makes generated output more readable and avoids breaks in DT tests - return factory.createParenthesizedType(type); - } - return parenthesizeOperandOfTypeOperator(type); - } - - // TupleType : - // `[` Elision? `]` - // `[` NamedTupleElementTypes `]` - // `[` NamedTupleElementTypes `,` Elision? `]` - // `[` TupleElementTypes `]` - // `[` TupleElementTypes `,` Elision? `]` - // - // NamedTupleElementTypes : - // Elision? NamedTupleMember - // NamedTupleElementTypes `,` Elision? NamedTupleMember - // - // NamedTupleMember : - // Identifier `?`? `:` Type[~Extends] - // `...` Identifier `:` Type[~Extends] - // - // TupleElementTypes : - // Elision? TupleElementType - // TupleElementTypes `,` Elision? TupleElementType - // - // TupleElementType : - // Type[~Extends] // NOTE: Needs cover grammar to disallow JSDoc postfix-optional - // OptionalType - // RestType - // - // OptionalType : - // Type[~Extends] `?` // NOTE: Needs cover grammar to disallow JSDoc postfix-optional - // - // RestType : - // `...` Type[~Extends] - // - function parenthesizeElementTypesOfTupleType(types: readonly (TypeNode | NamedTupleMember)[]): NodeArray { - return factory.createNodeArray(sameMap(types, parenthesizeElementTypeOfTupleType)); + return astRules.parenthesizeNonArrayTypeOfPostfixType(asNode(type).ast).node; } - function parenthesizeElementTypeOfTupleType(type: TypeNode | NamedTupleMember): TypeNode { - if (hasJSDocPostfixQuestion(type)) return factory.createParenthesizedType(type); - return type; + function parenthesizeElementTypesOfTupleType(types: readonly (TypeNode | NamedTupleMember)[]): NodeArray { + return astRules.parenthesizeElementTypesOfTupleType(asNodeArray(types).ast).nodes; } - function hasJSDocPostfixQuestion(type: TypeNode | NamedTupleMember): boolean { - if (isJSDocNullableType(type)) return type.postfix; - if (isNamedTupleMember(type)) return hasJSDocPostfixQuestion(type.type); - if (isFunctionTypeNode(type) || isConstructorTypeNode(type) || isTypeOperatorNode(type)) return hasJSDocPostfixQuestion(type.type); - if (isConditionalTypeNode(type)) return hasJSDocPostfixQuestion(type.falseType); - if (isUnionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.types)); - if (isIntersectionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.types)); - if (isInferTypeNode(type)) return !!type.typeParameter.constraint && hasJSDocPostfixQuestion(type.typeParameter.constraint); - return false; + function parenthesizeElementTypeOfTupleType(type: TypeNode | NamedTupleMember): TypeNode { + return astRules.parenthesizeElementTypeOfTupleType(asNode(type).ast).node; } function parenthesizeTypeOfOptionalType(type: TypeNode): TypeNode { - if (hasJSDocPostfixQuestion(type)) return factory.createParenthesizedType(type); - return parenthesizeNonArrayTypeOfPostfixType(type); - } - - // function parenthesizeMemberOfElementType(member: TypeNode): TypeNode { - // switch (member.kind) { - // case SyntaxKind.UnionType: - // case SyntaxKind.IntersectionType: - // case SyntaxKind.FunctionType: - // case SyntaxKind.ConstructorType: - // return factory.createParenthesizedType(member); - // } - // return parenthesizeMemberOfConditionalType(member); - // } - - // function parenthesizeElementTypeOfArrayType(member: TypeNode): TypeNode { - // switch (member.kind) { - // case SyntaxKind.TypeQuery: - // case SyntaxKind.TypeOperator: - // case SyntaxKind.InferType: - // return factory.createParenthesizedType(member); - // } - // return parenthesizeMemberOfElementType(member); - // } - - function parenthesizeLeadingTypeArgument(node: TypeNode) { - return isFunctionOrConstructorTypeNode(node) && node.typeParameters ? factory.createParenthesizedType(node) : node; + return astRules.parenthesizeTypeOfOptionalType(asNode(type).ast).node; } - function parenthesizeOrdinalTypeArgument(node: TypeNode, i: number) { - return i === 0 ? parenthesizeLeadingTypeArgument(node) : node; + function parenthesizeLeadingTypeArgument(node: TypeNode) { + return astRules.parenthesizeLeadingTypeArgument(asNode(node).ast).node; } function parenthesizeTypeArguments(typeArguments: NodeArray | undefined): NodeArray | undefined { - if (some(typeArguments)) { - return factory.createNodeArray(sameMap(typeArguments, parenthesizeOrdinalTypeArgument)); - } + return astRules.parenthesizeTypeArguments(asNodeArray(typeArguments)?.ast)?.nodes; + } + + type ToNode = + Expression extends T ? ast.Expression : + Statement extends T ? ast.Statement : + TypeNode extends T ? ast.TypeNode : + TypeElement extends T ? ast.TypeElement : + ClassElement extends T ? ast.ClassElement : + ObjectLiteralElement extends T ? ast.ObjectLiteralElement : + PropertyAccessChain extends T ? ast.PropertyAccessChain : + ElementAccessChain extends T ? ast.ElementAccessChain : + CallChain extends T ? ast.CallChain : + NonNullChain extends T ? ast.NonNullChain : + ModuleBody extends T ? ast.ModuleBody : + LiteralExpression extends T ? ast.LiteralExpression : + JSDocNamespaceDeclaration extends T ? ast.JSDocNamespaceDeclaration : + JSDocPropertyLikeTag extends T ? ast.JSDocPropertyLikeTag : + JSDocClassReference extends T ? ast.JSDocClassReference : + JsxNamespacedName extends T ? ast.JsxNamespacedName : + ast.NodeType[T["kind"]]; + + function asNode(node: T): ToNode; + function asNode(node: T | undefined): ToNode | undefined; + function asNode(node: Node | undefined): ast.Node | undefined { + return node as ast.Node | undefined; + } + + function asNodeArray(array: readonly T[]): ast.NodeArray>; + function asNodeArray(array: readonly T[] | undefined): ast.NodeArray> | undefined; + function asNodeArray(array: readonly Node[] | undefined): ast.NodeArray | undefined { + return array ? factory.createNodeArray(array) as ast.NodeArray : undefined; } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c95c4759b9c12..84c71cd90fc0f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -13,7 +13,6 @@ import { AsteriskToken, attachFileToDiagnostics, AwaitExpression, - BaseNodeFactory, BigIntLiteral, BinaryExpression, BinaryOperatorToken, @@ -283,7 +282,6 @@ import { NoSubstitutionTemplateLiteral, NullLiteral, NumericLiteral, - objectAllocator, ObjectBindingPattern, ObjectLiteralElementLike, ObjectLiteralExpression, @@ -416,28 +414,8 @@ const enum SpeculationKind { Reparse, } -let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; -let TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; -let IdentifierConstructor: new (kind: SyntaxKind.Identifier, pos: number, end: number) => Node; -let PrivateIdentifierConstructor: new (kind: SyntaxKind.PrivateIdentifier, pos: number, end: number) => Node; -let SourceFileConstructor: new (kind: SyntaxKind.SourceFile, pos: number, end: number) => Node; - -/** - * NOTE: You should not use this, it is only exported to support `createNode` in `~/src/deprecatedCompat/deprecations.ts`. - * - * @internal - * @knipignore - */ -export const parseBaseNodeFactory: BaseNodeFactory = { - createBaseSourceFileNode: kind => new (SourceFileConstructor || (SourceFileConstructor = objectAllocator.getSourceFileConstructor()))(kind, -1, -1), - createBaseIdentifierNode: kind => new (IdentifierConstructor || (IdentifierConstructor = objectAllocator.getIdentifierConstructor()))(kind, -1, -1), - createBasePrivateIdentifierNode: kind => new (PrivateIdentifierConstructor || (PrivateIdentifierConstructor = objectAllocator.getPrivateIdentifierConstructor()))(kind, -1, -1), - createBaseTokenNode: kind => new (TokenConstructor || (TokenConstructor = objectAllocator.getTokenConstructor()))(kind, -1, -1), - createBaseNode: kind => new (NodeConstructor || (NodeConstructor = objectAllocator.getNodeConstructor()))(kind, -1, -1), -}; - /** @internal */ -export const parseNodeFactory: NodeFactory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules, parseBaseNodeFactory); +export const parseNodeFactory: NodeFactory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules); function visitNode(cbNode: (node: Node) => T, node: Node | undefined): T | undefined { return node && cbNode(node); @@ -1435,29 +1413,7 @@ namespace Parser { var disallowInAndDecoratorContext = NodeFlags.DisallowInContext | NodeFlags.DecoratorContext; - // capture constructors in 'initializeState' to avoid null checks - var NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; - var TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; - var IdentifierConstructor: new (kind: SyntaxKind.Identifier, pos: number, end: number) => Identifier; - var PrivateIdentifierConstructor: new (kind: SyntaxKind.PrivateIdentifier, pos: number, end: number) => PrivateIdentifier; - var SourceFileConstructor: new (kind: SyntaxKind.SourceFile, pos: number, end: number) => SourceFile; - - function countNode(node: Node) { - nodeCount++; - return node; - } - - // Rather than using `createBaseNodeFactory` here, we establish a `BaseNodeFactory` that closes over the - // constructors above, which are reset each time `initializeState` is called. - var baseNodeFactory: BaseNodeFactory = { - createBaseSourceFileNode: kind => countNode(new SourceFileConstructor(kind, /*pos*/ 0, /*end*/ 0)), - createBaseIdentifierNode: kind => countNode(new IdentifierConstructor(kind, /*pos*/ 0, /*end*/ 0)), - createBasePrivateIdentifierNode: kind => countNode(new PrivateIdentifierConstructor(kind, /*pos*/ 0, /*end*/ 0)), - createBaseTokenNode: kind => countNode(new TokenConstructor(kind, /*pos*/ 0, /*end*/ 0)), - createBaseNode: kind => countNode(new NodeConstructor(kind, /*pos*/ 0, /*end*/ 0)), - }; - - var factory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules | NodeFactoryFlags.NoNodeConverters | NodeFactoryFlags.NoOriginalNode, baseNodeFactory); + var factory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules | NodeFactoryFlags.NoNodeConverters | NodeFactoryFlags.NoOriginalNode, _ => { nodeCount++; }); var { createNodeArray: factoryCreateNodeArray, @@ -1588,6 +1544,8 @@ namespace Parser { // Note: any errors at the end of the file that do not precede a regular node, should get // attached to the EOF token. var parseErrorBeforeNextFinishedNode = false; + + var missingLists: Set>; /* eslint-enable no-var */ export function parseSourceFile( @@ -1723,12 +1681,6 @@ namespace Parser { } function initializeState(_fileName: string, _sourceText: string, _languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor | undefined, _scriptKind: ScriptKind, _jsDocParsingMode: JSDocParsingMode) { - NodeConstructor = objectAllocator.getNodeConstructor(); - TokenConstructor = objectAllocator.getTokenConstructor(); - IdentifierConstructor = objectAllocator.getIdentifierConstructor(); - PrivateIdentifierConstructor = objectAllocator.getPrivateIdentifierConstructor(); - SourceFileConstructor = objectAllocator.getSourceFileConstructor(); - fileName = normalizePath(_fileName); sourceText = _sourceText; languageVersion = _languageVersion; @@ -1739,6 +1691,7 @@ namespace Parser { parseDiagnostics = []; parsingContext = 0; identifiers = new Map(); + missingLists = new Set(); identifierCount = 0; nodeCount = 0; sourceFlags = 0; @@ -1786,6 +1739,7 @@ namespace Parser { jsDocDiagnostics = undefined!; parsingContext = 0; identifiers = undefined!; + missingLists = undefined!; notParenthesizedArrow = undefined; topLevel = true; } @@ -3545,18 +3499,14 @@ namespace Parser { return kind === ParsingContext.EnumMembers ? Diagnostics.An_enum_member_name_must_be_followed_by_a_or : undefined; } - interface MissingList extends NodeArray { - isMissingList: true; - } - - function createMissingList(): MissingList { - const list = createNodeArray([], getNodePos()) as MissingList; - list.isMissingList = true; + function createMissingList(): NodeArray { + const list = createNodeArray([], getNodePos()); + missingLists.add(list); return list; } function isMissingList(arr: NodeArray): boolean { - return !!(arr as MissingList).isMissingList; + return missingLists.has(arr); } function parseBracketedList(kind: ParsingContext, parseElement: () => T, open: PunctuationSyntaxKind, close: PunctuationSyntaxKind): NodeArray { diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 5b29d34da9387..8d87fa4e255d4 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -4733,6 +4733,9 @@ export function transformES2015(context: TransformationContext): (x: SourceFile } function visitSpanOfNonSpreads(chunk: Expression[], multiLine: boolean, hasTrailingComma: boolean): SpreadSegment { + if (last(chunk).kind === SyntaxKind.OmittedExpression) { + hasTrailingComma = true; + } const expression = factory.createArrayLiteralExpression( visitNodes(factory.createNodeArray(chunk, hasTrailingComma), visitor, isExpression), multiLine, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 65d12a87cf2c3..c5118e59d1df6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1,5 +1,5 @@ import { - BaseNodeFactory, + ast, CreateSourceFileOptions, EmitHelperFactory, GetCanonicalFileName, @@ -741,6 +741,7 @@ export type TokenSyntaxKind = | PseudoLiteralSyntaxKind | PunctuationSyntaxKind | SyntaxKind.Identifier + | SyntaxKind.PrivateIdentifier | KeywordSyntaxKind; export type JsxTokenSyntaxKind = @@ -940,10 +941,10 @@ export interface Node extends ReadonlyTextRange { readonly flags: NodeFlags; /** @internal */ modifierFlagsCache: ModifierFlags; /** @internal */ readonly transformFlags: TransformFlags; // Flags for transforms - /** @internal */ id?: NodeId; // Unique id (used to look up NodeLinks) + /** @internal */ id?: NodeId | undefined; // Unique id (used to look up NodeLinks) readonly parent: Node; // Parent node (initialized by binding) - /** @internal */ original?: Node; // The original node if this is an updated node. - /** @internal */ emitNode?: EmitNode; // Associated EmitNode (initialized by transforms) + /** @internal */ original?: Node | undefined; // The original node if this is an updated node. + /** @internal */ emitNode?: EmitNode | undefined; // Associated EmitNode (initialized by transforms) // NOTE: `symbol` and `localSymbol` have been moved to `Declaration` // `locals` and `nextContainer` have been moved to `LocalsContainer` // `flowNode` has been moved to `FlowContainer` @@ -952,7 +953,7 @@ export interface Node extends ReadonlyTextRange { export interface JSDocContainer extends Node { _jsdocContainerBrand: any; - /** @internal */ jsDoc?: JSDocArray; // JSDoc that directly precedes this node + /** @internal */ jsDoc?: JSDocArray | undefined; // JSDoc that directly precedes this node } /** @internal */ @@ -962,13 +963,13 @@ export interface JSDocArray extends Array { export interface LocalsContainer extends Node { _localsContainerBrand: any; - /** @internal */ locals?: SymbolTable; // Locals associated with node (initialized by binding) - /** @internal */ nextContainer?: HasLocals; // Next container in declaration order (initialized by binding) + /** @internal */ locals?: SymbolTable | undefined; // Locals associated with node (initialized by binding) + /** @internal */ nextContainer?: HasLocals | undefined; // Next container in declaration order (initialized by binding) } export interface FlowContainer extends Node { _flowContainerBrand: any; - /** @internal */ flowNode?: FlowNode; // Associated FlowNode (initialized by binding) + /** @internal */ flowNode?: FlowNode | undefined; // Associated FlowNode (initialized by binding) } /** @internal */ @@ -1592,7 +1593,9 @@ export interface Token extends Node { readonly kind: TKind; } -export type EndOfFileToken = Token & JSDocContainer; +export interface EndOfFileToken extends Token, JSDocContainer { + readonly kind: SyntaxKind.EndOfFileToken; +} // Punctuation export interface PunctuationToken extends Token { @@ -1752,11 +1755,11 @@ export type DeclarationName = export interface Declaration extends Node { _declarationBrand: any; /** @internal */ symbol: Symbol; // Symbol declared by node (initialized by binding) - /** @internal */ localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes) + /** @internal */ localSymbol?: Symbol | undefined; // Local symbol declared by node (initialized by binding only for exported nodes) } export interface NamedDeclaration extends Declaration { - readonly name?: DeclarationName; + readonly name?: DeclarationName | undefined; } /** @internal */ @@ -1786,7 +1789,7 @@ export interface LateBoundElementAccessExpression extends ElementAccessExpressio } export interface DeclarationStatement extends NamedDeclaration, Statement { - readonly name?: Identifier | StringLiteral | NumericLiteral; + readonly name?: Identifier | StringLiteral | NumericLiteral | undefined; } export interface ComputedPropertyName extends Node { @@ -1823,23 +1826,23 @@ export interface Decorator extends Node { export interface TypeParameterDeclaration extends NamedDeclaration, JSDocContainer { readonly kind: SyntaxKind.TypeParameter; readonly parent: DeclarationWithTypeParameterChildren | InferTypeNode; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: Identifier; /** Note: Consider calling `getEffectiveConstraintOfTypeParameter` */ - readonly constraint?: TypeNode; - readonly default?: TypeNode; + readonly constraint?: TypeNode | undefined; + readonly default?: TypeNode | undefined; // For error recovery purposes (see `isGrammarError` in utilities.ts). - expression?: Expression; + expression?: Expression | undefined; } export interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { readonly kind: SignatureDeclaration["kind"]; - readonly name?: PropertyName; + readonly name?: PropertyName | undefined; readonly typeParameters?: NodeArray | undefined; readonly parameters: NodeArray; readonly type?: TypeNode | undefined; - /** @internal */ typeArguments?: NodeArray; // Used for quick info, replaces typeParameters for instantiated signatures + /** @internal */ typeArguments?: NodeArray | undefined; // Used for quick info, replaces typeParameters for instantiated signatures } export type SignatureDeclaration = @@ -1871,10 +1874,10 @@ export type BindingName = Identifier | BindingPattern; export interface VariableDeclaration extends NamedDeclaration, JSDocContainer { readonly kind: SyntaxKind.VariableDeclaration; readonly parent: VariableDeclarationList | CatchClause; - readonly name: BindingName; // Declared variable name - readonly exclamationToken?: ExclamationToken; // Optional definite assignment assertion - readonly type?: TypeNode; // Optional type annotation - readonly initializer?: Expression; // Optional initializer + readonly name: BindingName; // Declared variable name + readonly exclamationToken?: ExclamationToken | undefined; // Optional definite assignment assertion + readonly type?: TypeNode | undefined; // Optional type annotation + readonly initializer?: Expression | undefined; // Optional initializer } /** @internal */ @@ -1890,22 +1893,22 @@ export interface VariableDeclarationList extends Node { export interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { readonly kind: SyntaxKind.Parameter; readonly parent: SignatureDeclaration; - readonly modifiers?: NodeArray; - readonly dotDotDotToken?: DotDotDotToken; // Present on rest parameter - readonly name: BindingName; // Declared parameter name. - readonly questionToken?: QuestionToken; // Present on optional parameter - readonly type?: TypeNode; // Optional type annotation - readonly initializer?: Expression; // Optional initializer + readonly modifiers?: NodeArray | undefined; + readonly dotDotDotToken?: DotDotDotToken | undefined; // Present on rest parameter + readonly name: BindingName; // Declared parameter name. + readonly questionToken?: QuestionToken | undefined; // Present on optional parameter + readonly type?: TypeNode | undefined; // Optional type annotation + readonly initializer?: Expression | undefined; // Optional initializer } // dprint-ignore export interface BindingElement extends NamedDeclaration, FlowContainer { readonly kind: SyntaxKind.BindingElement; readonly parent: BindingPattern; - readonly propertyName?: PropertyName; // Binding property name (in object binding pattern) - readonly dotDotDotToken?: DotDotDotToken; // Present on rest element (in object binding pattern) - readonly name: BindingName; // Declared binding element name - readonly initializer?: Expression; // Optional initializer + readonly propertyName?: PropertyName | undefined; // Binding property name (in object binding pattern) + readonly dotDotDotToken?: DotDotDotToken | undefined; // Present on rest element (in object binding pattern) + readonly name: BindingName; // Declared binding element name + readonly initializer?: Expression | undefined; // Optional initializer } /** @internal */ @@ -1915,10 +1918,10 @@ export type BindingElementGrandparent = BindingElement["parent"]["parent"]; export interface PropertySignature extends TypeElement, JSDocContainer { readonly kind: SyntaxKind.PropertySignature; readonly parent: TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray; - readonly name: PropertyName; // Declared property name - readonly questionToken?: QuestionToken; // Present on optional property - readonly type?: TypeNode; // Optional type annotation + readonly modifiers?: NodeArray | undefined; + readonly name: PropertyName; // Declared property name + readonly questionToken?: QuestionToken | undefined; // Present on optional property + readonly type?: TypeNode | undefined; // Optional type annotation // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) /** @internal */ readonly initializer?: Expression | undefined; // A property signature cannot have an initializer @@ -1928,12 +1931,12 @@ export interface PropertySignature extends TypeElement, JSDocContainer { export interface PropertyDeclaration extends ClassElement, JSDocContainer { readonly kind: SyntaxKind.PropertyDeclaration; readonly parent: ClassLikeDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: PropertyName; - readonly questionToken?: QuestionToken; // Present for use with reporting a grammar error for auto-accessors (see `isGrammarError` in utilities.ts) - readonly exclamationToken?: ExclamationToken; - readonly type?: TypeNode; - readonly initializer?: Expression; // Optional initializer + readonly questionToken?: QuestionToken | undefined; // Present for use with reporting a grammar error for auto-accessors (see `isGrammarError` in utilities.ts) + readonly exclamationToken?: ExclamationToken | undefined; + readonly type?: TypeNode | undefined; + readonly initializer?: Expression | undefined; // Optional initializer } export interface AutoAccessorPropertyDeclaration extends PropertyDeclaration { @@ -1975,7 +1978,7 @@ export type InitializedPropertyDeclaration = PropertyDeclaration & { readonly in export interface ObjectLiteralElement extends NamedDeclaration { _objectLiteralBrand: any; - readonly name?: PropertyName; + readonly name?: PropertyName | undefined; } /** Unlike ObjectLiteralElement, excludes JSXAttribute and JSXSpreadAttribute. */ @@ -2004,8 +2007,8 @@ export interface ShorthandPropertyAssignment extends ObjectLiteralElement, JSDoc readonly name: Identifier; // used when ObjectLiteralExpression is used in ObjectAssignmentPattern // it is a grammar error to appear in actual object initializer (see `isGrammarError` in utilities.ts): - readonly equalsToken?: EqualsToken; - readonly objectAssignmentInitializer?: Expression; + readonly equalsToken?: EqualsToken | undefined; + readonly objectAssignmentInitializer?: Expression | undefined; // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) /** @internal */ readonly modifiers?: NodeArray | undefined; // shorthand property assignment cannot have decorators or modifiers @@ -2063,8 +2066,8 @@ export interface FunctionLikeDeclarationBase extends SignatureDeclarationBase { readonly questionToken?: QuestionToken | undefined; readonly exclamationToken?: ExclamationToken | undefined; readonly body?: Block | Expression | undefined; - /** @internal */ endFlowNode?: FlowNode; - /** @internal */ returnFlowNode?: FlowNode; + /** @internal */ endFlowNode?: FlowNode | undefined; + /** @internal */ returnFlowNode?: FlowNode | undefined; } export type FunctionLikeDeclaration = @@ -2080,15 +2083,15 @@ export type FunctionLike = SignatureDeclaration; export interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement, LocalsContainer { readonly kind: SyntaxKind.FunctionDeclaration; - readonly modifiers?: NodeArray; - readonly name?: Identifier; - readonly body?: FunctionBody; + readonly modifiers?: NodeArray | undefined; + readonly name?: Identifier | undefined; + readonly body?: FunctionBody | undefined; } export interface MethodSignature extends SignatureDeclarationBase, TypeElement, LocalsContainer { readonly kind: SyntaxKind.MethodSignature; readonly parent: TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: PropertyName; } @@ -2119,8 +2122,8 @@ export interface ConstructorDeclaration extends FunctionLikeDeclarationBase, Cla readonly body?: FunctionBody | undefined; // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) - /** @internal */ readonly typeParameters?: NodeArray; // A constructor cannot have type parameters - /** @internal */ readonly type?: TypeNode; // A constructor cannot have a return type annotation + /** @internal */ readonly typeParameters?: NodeArray | undefined; // A constructor cannot have type parameters + /** @internal */ readonly type?: TypeNode | undefined; // A constructor cannot have a return type annotation } /** For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. */ @@ -2134,9 +2137,9 @@ export interface SemicolonClassElement extends ClassElement, JSDocContainer { export interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { readonly kind: SyntaxKind.GetAccessor; readonly parent: ClassLikeDeclaration | ObjectLiteralExpression | TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: PropertyName; - readonly body?: FunctionBody; + readonly body?: FunctionBody | undefined; // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) /** @internal */ readonly typeParameters?: NodeArray | undefined; // A get accessor cannot have type parameters @@ -2147,9 +2150,9 @@ export interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, Cla export interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { readonly kind: SyntaxKind.SetAccessor; readonly parent: ClassLikeDeclaration | ObjectLiteralExpression | TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: PropertyName; - readonly body?: FunctionBody; + readonly body?: FunctionBody | undefined; // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) /** @internal */ readonly typeParameters?: NodeArray | undefined; // A set accessor cannot have type parameters @@ -2161,7 +2164,7 @@ export type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaratio export interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement, LocalsContainer { readonly kind: SyntaxKind.IndexSignature; readonly parent: ObjectTypeDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly type: TypeNode; } @@ -2170,8 +2173,8 @@ export interface ClassStaticBlockDeclaration extends ClassElement, JSDocContaine readonly parent: ClassDeclaration | ClassExpression; readonly body: Block; - /** @internal */ endFlowNode?: FlowNode; - /** @internal */ returnFlowNode?: FlowNode; + /** @internal */ endFlowNode?: FlowNode | undefined; + /** @internal */ returnFlowNode?: FlowNode | undefined; // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) /** @internal */ readonly modifiers?: NodeArray | undefined; @@ -2195,16 +2198,16 @@ export interface ImportTypeAssertionContainer extends Node { readonly kind: SyntaxKind.ImportTypeAssertionContainer; readonly parent: ImportTypeNode; /** @deprecated */ readonly assertClause: AssertClause; - readonly multiLine?: boolean; + readonly multiLine?: boolean | undefined; } export interface ImportTypeNode extends NodeWithTypeArguments { readonly kind: SyntaxKind.ImportType; readonly isTypeOf: boolean; readonly argument: TypeNode; - /** @deprecated */ readonly assertions?: ImportTypeAssertionContainer; - readonly attributes?: ImportAttributes; - readonly qualifier?: EntityName; + /** @deprecated */ readonly assertions?: ImportTypeAssertionContainer | undefined; + readonly attributes?: ImportAttributes | undefined; + readonly qualifier?: EntityName | undefined; } /** @internal */ @@ -2225,16 +2228,16 @@ export interface FunctionTypeNode extends FunctionOrConstructorTypeNodeBase, Loc readonly kind: SyntaxKind.FunctionType; // A function type cannot have modifiers - /** @internal */ readonly modifiers?: undefined; + /** @internal */ readonly modifiers?: NodeArray | undefined; } export interface ConstructorTypeNode extends FunctionOrConstructorTypeNodeBase, LocalsContainer { readonly kind: SyntaxKind.ConstructorType; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; } export interface NodeWithTypeArguments extends TypeNode { - readonly typeArguments?: NodeArray; + readonly typeArguments?: NodeArray | undefined; } export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; @@ -2247,9 +2250,9 @@ export interface TypeReferenceNode extends NodeWithTypeArguments { export interface TypePredicateNode extends TypeNode { readonly kind: SyntaxKind.TypePredicate; readonly parent: SignatureDeclaration | JSDocTypeExpression; - readonly assertsModifier?: AssertsKeyword; + readonly assertsModifier?: AssertsKeyword | undefined; readonly parameterName: Identifier | ThisTypeNode; - readonly type?: TypeNode; + readonly type?: TypeNode | undefined; } export interface TypeQueryNode extends NodeWithTypeArguments { @@ -2275,9 +2278,9 @@ export interface TupleTypeNode extends TypeNode { export interface NamedTupleMember extends TypeNode, Declaration, JSDocContainer { readonly kind: SyntaxKind.NamedTupleMember; - readonly dotDotDotToken?: Token; + readonly dotDotDotToken?: DotDotDotToken | undefined; readonly name: Identifier; - readonly questionToken?: Token; + readonly questionToken?: QuestionToken | undefined; readonly type: TypeNode; } @@ -2340,13 +2343,13 @@ export interface IndexedAccessTypeNode extends TypeNode { export interface MappedTypeNode extends TypeNode, Declaration, LocalsContainer { readonly kind: SyntaxKind.MappedType; - readonly readonlyToken?: ReadonlyKeyword | PlusToken | MinusToken; + readonly readonlyToken?: ReadonlyKeyword | PlusToken | MinusToken | undefined; readonly typeParameter: TypeParameterDeclaration; - readonly nameType?: TypeNode; - readonly questionToken?: QuestionToken | PlusToken | MinusToken; - readonly type?: TypeNode; + readonly nameType?: TypeNode | undefined; + readonly questionToken?: QuestionToken | PlusToken | MinusToken | undefined; + readonly type?: TypeNode | undefined; /** Used only to produce grammar errors */ - readonly members?: NodeArray; + readonly members?: NodeArray | undefined; } export interface LiteralTypeNode extends TypeNode { @@ -2357,20 +2360,20 @@ export interface LiteralTypeNode extends TypeNode { export interface StringLiteral extends LiteralExpression, Declaration { readonly kind: SyntaxKind.StringLiteral; /** @internal */ - readonly textSourceNode?: Identifier | StringLiteralLike | NumericLiteral | PrivateIdentifier | JsxNamespacedName | BigIntLiteral; // Allows a StringLiteral to get its text from another node (used by transforms). + readonly textSourceNode?: Identifier | StringLiteralLike | NumericLiteral | PrivateIdentifier | JsxNamespacedName | BigIntLiteral | undefined; // Allows a StringLiteral to get its text from another node (used by transforms). /** * Note: this is only set when synthesizing a node, not during parsing. * * @internal */ - readonly singleQuote?: boolean; + readonly singleQuote?: boolean | undefined; } export type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral; export type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral | JsxNamespacedName | BigIntLiteral; export interface TemplateLiteralTypeNode extends TypeNode { - kind: SyntaxKind.TemplateLiteralType; + readonly kind: SyntaxKind.TemplateLiteralType; readonly head: TemplateHead; readonly templateSpans: NodeArray; } @@ -2501,15 +2504,15 @@ export interface AwaitExpression extends UnaryExpression { export interface YieldExpression extends Expression { readonly kind: SyntaxKind.YieldExpression; - readonly asteriskToken?: AsteriskToken; - readonly expression?: Expression; + readonly asteriskToken?: AsteriskToken | undefined; + readonly expression?: Expression | undefined; } export interface SyntheticExpression extends Expression { readonly kind: SyntaxKind.SyntheticExpression; readonly isSpread: boolean; readonly type: Type; - readonly tupleNameSource?: ParameterDeclaration | NamedTupleMember; + readonly tupleNameSource?: ParameterDeclaration | NamedTupleMember | undefined; } // see: https://tc39.github.io/ecma262/#prod-ExponentiationExpression @@ -2742,14 +2745,14 @@ export type ConciseBody = FunctionBody | Expression; export interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer, LocalsContainer, FlowContainer { readonly kind: SyntaxKind.FunctionExpression; - readonly modifiers?: NodeArray; - readonly name?: Identifier; + readonly modifiers?: NodeArray | undefined; + readonly name?: Identifier | undefined; readonly body: FunctionBody; // Required, whereas the member inherited from FunctionDeclaration is optional } export interface ArrowFunction extends Expression, FunctionLikeDeclarationBase, JSDocContainer, LocalsContainer, FlowContainer { readonly kind: SyntaxKind.ArrowFunction; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly equalsGreaterThanToken: EqualsGreaterThanToken; readonly body: ConciseBody; readonly name: never; @@ -2760,14 +2763,14 @@ export interface ArrowFunction extends Expression, FunctionLikeDeclarationBase, // For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1". export interface LiteralLikeNode extends Node { text: string; - isUnterminated?: boolean; - hasExtendedUnicodeEscape?: boolean; + isUnterminated?: boolean | undefined; + hasExtendedUnicodeEscape?: boolean | undefined; } export interface TemplateLiteralLikeNode extends LiteralLikeNode { - rawText?: string; + rawText?: string | undefined; /** @internal */ - templateFlags?: TokenFlags; + templateFlags?: TokenFlags | undefined; } // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, @@ -2800,7 +2803,7 @@ export const enum RegularExpressionFlags { export interface NoSubstitutionTemplateLiteral extends LiteralExpression, TemplateLiteralLikeNode, Declaration { readonly kind: SyntaxKind.NoSubstitutionTemplateLiteral; /** @internal */ - templateFlags?: TokenFlags; + templateFlags?: TokenFlags | undefined; } // dprint-ignore @@ -2869,21 +2872,21 @@ export interface TemplateHead extends TemplateLiteralLikeNode { readonly kind: SyntaxKind.TemplateHead; readonly parent: TemplateExpression | TemplateLiteralTypeNode; /** @internal */ - templateFlags?: TokenFlags; + templateFlags?: TokenFlags | undefined; } export interface TemplateMiddle extends TemplateLiteralLikeNode { readonly kind: SyntaxKind.TemplateMiddle; readonly parent: TemplateSpan | TemplateLiteralTypeSpan; /** @internal */ - templateFlags?: TokenFlags; + templateFlags?: TokenFlags | undefined; } export interface TemplateTail extends TemplateLiteralLikeNode { readonly kind: SyntaxKind.TemplateTail; readonly parent: TemplateSpan | TemplateLiteralTypeSpan; /** @internal */ - templateFlags?: TokenFlags; + templateFlags?: TokenFlags | undefined; } export type PseudoLiteralToken = @@ -2928,7 +2931,7 @@ export interface ArrayLiteralExpression extends PrimaryExpression { readonly kind: SyntaxKind.ArrayLiteralExpression; readonly elements: NodeArray; /** @internal */ - multiLine?: boolean; + multiLine?: boolean | undefined; } export interface SpreadElement extends Expression { @@ -2951,7 +2954,7 @@ export interface ObjectLiteralExpressionBase ext export interface ObjectLiteralExpression extends ObjectLiteralExpressionBase, JSDocContainer { readonly kind: SyntaxKind.ObjectLiteralExpression; /** @internal */ - multiLine?: boolean; + multiLine?: boolean | undefined; } export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression; @@ -2961,7 +2964,7 @@ export type AccessExpression = PropertyAccessExpression | ElementAccessExpressio export interface PropertyAccessExpression extends MemberExpression, NamedDeclaration, JSDocContainer, FlowContainer { readonly kind: SyntaxKind.PropertyAccessExpression; readonly expression: LeftHandSideExpression; - readonly questionDotToken?: QuestionDotToken; + readonly questionDotToken?: QuestionDotToken | undefined; readonly name: MemberName; } @@ -2994,7 +2997,7 @@ export interface PropertyAccessEntityNameExpression extends PropertyAccessExpres export interface ElementAccessExpression extends MemberExpression, Declaration, JSDocContainer, FlowContainer { readonly kind: SyntaxKind.ElementAccessExpression; readonly expression: LeftHandSideExpression; - readonly questionDotToken?: QuestionDotToken; + readonly questionDotToken?: QuestionDotToken | undefined; readonly argumentExpression: Expression; } @@ -3017,8 +3020,8 @@ export type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessEx export interface CallExpression extends LeftHandSideExpression, Declaration { readonly kind: SyntaxKind.CallExpression; readonly expression: LeftHandSideExpression; - readonly questionDotToken?: QuestionDotToken; - readonly typeArguments?: NodeArray; + readonly questionDotToken?: QuestionDotToken | undefined; + readonly typeArguments?: NodeArray | undefined; readonly arguments: NodeArray; } @@ -3105,16 +3108,16 @@ export interface ExpressionWithTypeArguments extends MemberExpression, NodeWithT export interface NewExpression extends PrimaryExpression, Declaration { readonly kind: SyntaxKind.NewExpression; readonly expression: LeftHandSideExpression; - readonly typeArguments?: NodeArray; - readonly arguments?: NodeArray; + readonly typeArguments?: NodeArray | undefined; + readonly arguments?: NodeArray | undefined; } export interface TaggedTemplateExpression extends MemberExpression { readonly kind: SyntaxKind.TaggedTemplateExpression; readonly tag: LeftHandSideExpression; - readonly typeArguments?: NodeArray; + readonly typeArguments?: NodeArray | undefined; readonly template: TemplateLiteral; - /** @internal */ questionDotToken?: QuestionDotToken; // NOTE: Invalid syntax, only used to report a grammar error. + /** @internal */ questionDotToken?: QuestionDotToken | undefined; // NOTE: Invalid syntax, only used to report a grammar error. } export interface InstanceofExpression extends BinaryExpression { @@ -3206,8 +3209,8 @@ export interface JsxTagNamePropertyAccess extends PropertyAccessExpression { } export interface JsxAttributes extends PrimaryExpression, Declaration { - readonly properties: NodeArray; readonly kind: SyntaxKind.JsxAttributes; + readonly properties: NodeArray; readonly parent: JsxOpeningLikeElement; } @@ -3222,7 +3225,7 @@ export interface JsxOpeningElement extends Expression { readonly kind: SyntaxKind.JsxOpeningElement; readonly parent: JsxElement; readonly tagName: JsxTagNameExpression; - readonly typeArguments?: NodeArray; + readonly typeArguments?: NodeArray | undefined; readonly attributes: JsxAttributes; } @@ -3230,7 +3233,7 @@ export interface JsxOpeningElement extends Expression { export interface JsxSelfClosingElement extends PrimaryExpression { readonly kind: SyntaxKind.JsxSelfClosingElement; readonly tagName: JsxTagNameExpression; - readonly typeArguments?: NodeArray; + readonly typeArguments?: NodeArray | undefined; readonly attributes: JsxAttributes; } @@ -3259,7 +3262,7 @@ export interface JsxAttribute extends Declaration { readonly parent: JsxAttributes; readonly name: JsxAttributeName; /// JSX attribute initializers are optional; is sugar for - readonly initializer?: JsxAttributeValue; + readonly initializer?: JsxAttributeValue | undefined; } export type JsxAttributeValue = @@ -3284,8 +3287,8 @@ export interface JsxClosingElement extends Node { export interface JsxExpression extends Expression { readonly kind: SyntaxKind.JsxExpression; readonly parent: JsxElement | JsxFragment | JsxAttributeLike; - readonly dotDotDotToken?: Token; - readonly expression?: Expression; + readonly dotDotDotToken?: Token | undefined; + readonly expression?: Expression | undefined; } export interface JsxText extends LiteralLikeNode { @@ -3340,7 +3343,7 @@ export interface DebuggerStatement extends Statement, FlowContainer { export interface MissingDeclaration extends DeclarationStatement, PrimaryExpression { readonly kind: SyntaxKind.MissingDeclaration; - readonly name?: Identifier; + readonly name?: Identifier | undefined; // The following properties are used only to report grammar errors /** @internal */ readonly modifiers?: NodeArray | undefined; @@ -3355,12 +3358,12 @@ export type BlockLike = export interface Block extends Statement, LocalsContainer { readonly kind: SyntaxKind.Block; readonly statements: NodeArray; - /** @internal */ multiLine?: boolean; + /** @internal */ multiLine?: boolean | undefined; } export interface VariableStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.VariableStatement; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly declarationList: VariableDeclarationList; } @@ -3378,7 +3381,7 @@ export interface IfStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.IfStatement; readonly expression: Expression; readonly thenStatement: Statement; - readonly elseStatement?: Statement; + readonly elseStatement?: Statement | undefined; } export interface IterationStatement extends Statement { @@ -3401,9 +3404,9 @@ export type ForInitializer = export interface ForStatement extends IterationStatement, LocalsContainer, FlowContainer { readonly kind: SyntaxKind.ForStatement; - readonly initializer?: ForInitializer; - readonly condition?: Expression; - readonly incrementor?: Expression; + readonly initializer?: ForInitializer | undefined; + readonly condition?: Expression | undefined; + readonly incrementor?: Expression | undefined; } export type ForInOrOfStatement = @@ -3418,19 +3421,19 @@ export interface ForInStatement extends IterationStatement, LocalsContainer, Flo export interface ForOfStatement extends IterationStatement, LocalsContainer, FlowContainer { readonly kind: SyntaxKind.ForOfStatement; - readonly awaitModifier?: AwaitKeyword; + readonly awaitModifier?: AwaitKeyword | undefined; readonly initializer: ForInitializer; readonly expression: Expression; } export interface BreakStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.BreakStatement; - readonly label?: Identifier; + readonly label?: Identifier | undefined; } export interface ContinueStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.ContinueStatement; - readonly label?: Identifier; + readonly label?: Identifier | undefined; } export type BreakOrContinueStatement = @@ -3439,7 +3442,7 @@ export type BreakOrContinueStatement = export interface ReturnStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.ReturnStatement; - readonly expression?: Expression; + readonly expression?: Expression | undefined; } export interface WithStatement extends Statement, FlowContainer { @@ -3452,7 +3455,7 @@ export interface SwitchStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.SwitchStatement; readonly expression: Expression; readonly caseBlock: CaseBlock; - possiblyExhaustive?: boolean; // initialized by binding + possiblyExhaustive?: boolean | undefined; // initialized by binding } export interface CaseBlock extends Node, LocalsContainer { @@ -3466,14 +3469,14 @@ export interface CaseClause extends Node, JSDocContainer { readonly parent: CaseBlock; readonly expression: Expression; readonly statements: NodeArray; - /** @internal */ fallthroughFlowNode?: FlowNode; + /** @internal */ fallthroughFlowNode?: FlowNode | undefined; } export interface DefaultClause extends Node { readonly kind: SyntaxKind.DefaultClause; readonly parent: CaseBlock; readonly statements: NodeArray; - /** @internal */ fallthroughFlowNode?: FlowNode; + /** @internal */ fallthroughFlowNode?: FlowNode | undefined; } export type CaseOrDefaultClause = @@ -3494,14 +3497,14 @@ export interface ThrowStatement extends Statement, FlowContainer { export interface TryStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.TryStatement; readonly tryBlock: Block; - readonly catchClause?: CatchClause; - readonly finallyBlock?: Block; + readonly catchClause?: CatchClause | undefined; + readonly finallyBlock?: Block | undefined; } export interface CatchClause extends Node, LocalsContainer { readonly kind: SyntaxKind.CatchClause; readonly parent: TryStatement; - readonly variableDeclaration?: VariableDeclaration; + readonly variableDeclaration?: VariableDeclaration | undefined; readonly block: Block; } @@ -3525,22 +3528,22 @@ export type DeclarationWithTypeParameterChildren = export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { readonly kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; - readonly name?: Identifier; - readonly typeParameters?: NodeArray; - readonly heritageClauses?: NodeArray; + readonly name?: Identifier | undefined; + readonly typeParameters?: NodeArray | undefined; + readonly heritageClauses?: NodeArray | undefined; readonly members: NodeArray; } export interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatement { readonly kind: SyntaxKind.ClassDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; /** May be undefined in `export default class { ... }`. */ - readonly name?: Identifier; + readonly name?: Identifier | undefined; } export interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpression { readonly kind: SyntaxKind.ClassExpression; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; } export type ClassLikeDeclaration = @@ -3549,21 +3552,21 @@ export type ClassLikeDeclaration = export interface ClassElement extends NamedDeclaration { _classElementBrand: any; - readonly name?: PropertyName; + readonly name?: PropertyName | undefined; } export interface TypeElement extends NamedDeclaration { _typeElementBrand: any; - readonly name?: PropertyName; + readonly name?: PropertyName | undefined; readonly questionToken?: QuestionToken | undefined; } export interface InterfaceDeclaration extends DeclarationStatement, JSDocContainer { readonly kind: SyntaxKind.InterfaceDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: Identifier; - readonly typeParameters?: NodeArray; - readonly heritageClauses?: NodeArray; + readonly typeParameters?: NodeArray | undefined; + readonly heritageClauses?: NodeArray | undefined; readonly members: NodeArray; } @@ -3576,9 +3579,9 @@ export interface HeritageClause extends Node { export interface TypeAliasDeclaration extends DeclarationStatement, JSDocContainer, LocalsContainer { readonly kind: SyntaxKind.TypeAliasDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: Identifier; - readonly typeParameters?: NodeArray; + readonly typeParameters?: NodeArray | undefined; readonly type: TypeNode; } @@ -3588,12 +3591,12 @@ export interface EnumMember extends NamedDeclaration, JSDocContainer { // This does include ComputedPropertyName, but the parser will give an error // if it parses a ComputedPropertyName in an EnumMember readonly name: PropertyName; - readonly initializer?: Expression; + readonly initializer?: Expression | undefined; } export interface EnumDeclaration extends DeclarationStatement, JSDocContainer { readonly kind: SyntaxKind.EnumDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: Identifier; readonly members: NodeArray; } @@ -3608,15 +3611,15 @@ export type ModuleBody = /** @internal */ export interface AmbientModuleDeclaration extends ModuleDeclaration { - readonly body?: ModuleBlock; + readonly body?: ModuleBlock | undefined; } export interface ModuleDeclaration extends DeclarationStatement, JSDocContainer, LocalsContainer { readonly kind: SyntaxKind.ModuleDeclaration; readonly parent: ModuleBody | SourceFile; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: ModuleName; - readonly body?: ModuleBody | JSDocNamespaceDeclaration; + readonly body?: ModuleBody | JSDocNamespaceDeclaration | undefined; } export type NamespaceBody = @@ -3634,7 +3637,7 @@ export type JSDocNamespaceBody = export interface JSDocNamespaceDeclaration extends ModuleDeclaration { readonly name: Identifier; - readonly body?: JSDocNamespaceBody; + readonly body?: JSDocNamespaceBody | undefined; } export interface ModuleBlock extends Node, Statement { @@ -3655,7 +3658,7 @@ export type ModuleReference = export interface ImportEqualsDeclaration extends DeclarationStatement, JSDocContainer { readonly kind: SyntaxKind.ImportEqualsDeclaration; readonly parent: SourceFile | ModuleBlock; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: Identifier; readonly isTypeOnly: boolean; @@ -3677,12 +3680,12 @@ export interface ExternalModuleReference extends Node { export interface ImportDeclaration extends Statement { readonly kind: SyntaxKind.ImportDeclaration; readonly parent: SourceFile | ModuleBlock; - readonly modifiers?: NodeArray; - readonly importClause?: ImportClause; + readonly modifiers?: NodeArray | undefined; + readonly importClause?: ImportClause | undefined; /** If this is not a StringLiteral it will be a grammar error. */ readonly moduleSpecifier: Expression; - /** @deprecated */ readonly assertClause?: AssertClause; - readonly attributes?: ImportAttributes; + /** @deprecated */ readonly assertClause?: AssertClause | undefined; + readonly attributes?: ImportAttributes | undefined; } export type NamedImportBindings = @@ -3703,8 +3706,8 @@ export interface ImportClause extends NamedDeclaration { readonly kind: SyntaxKind.ImportClause; readonly parent: ImportDeclaration | JSDocImportTag; readonly isTypeOnly: boolean; - readonly name?: Identifier; // Default binding - readonly namedBindings?: NamedImportBindings; + readonly name?: Identifier | undefined; // Default binding + readonly namedBindings?: NamedImportBindings | undefined; } /** @deprecated */ @@ -3726,11 +3729,11 @@ export interface ImportAttribute extends Node { } export interface ImportAttributes extends Node { - readonly token: SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword; readonly kind: SyntaxKind.ImportAttributes; + readonly token: SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword; readonly parent: ImportDeclaration | ExportDeclaration; readonly elements: NodeArray; - readonly multiLine?: boolean; + readonly multiLine?: boolean | undefined; } export interface NamespaceImport extends NamedDeclaration { @@ -3756,14 +3759,14 @@ export interface NamespaceExportDeclaration extends DeclarationStatement, JSDocC export interface ExportDeclaration extends DeclarationStatement, JSDocContainer { readonly kind: SyntaxKind.ExportDeclaration; readonly parent: SourceFile | ModuleBlock; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly isTypeOnly: boolean; /** Will not be assigned in the case of `export * from "foo";` */ - readonly exportClause?: NamedExportBindings; + readonly exportClause?: NamedExportBindings | undefined; /** If this is not a StringLiteral it will be a grammar error. */ - readonly moduleSpecifier?: Expression; - /** @deprecated */ readonly assertClause?: AssertClause; - readonly attributes?: ImportAttributes; + readonly moduleSpecifier?: Expression | undefined; + /** @deprecated */ readonly assertClause?: AssertClause | undefined; + readonly attributes?: ImportAttributes | undefined; } export interface NamedImports extends Node { @@ -3783,7 +3786,7 @@ export type NamedImportsOrExports = NamedImports | NamedExports; export interface ImportSpecifier extends NamedDeclaration { readonly kind: SyntaxKind.ImportSpecifier; readonly parent: NamedImports; - readonly propertyName?: ModuleExportName; // Name preceding "as" keyword (or undefined when "as" is absent) + readonly propertyName?: ModuleExportName | undefined; // Name preceding "as" keyword (or undefined when "as" is absent) readonly name: Identifier; // Declared name readonly isTypeOnly: boolean; } @@ -3792,7 +3795,7 @@ export interface ExportSpecifier extends NamedDeclaration, JSDocContainer { readonly kind: SyntaxKind.ExportSpecifier; readonly parent: NamedExports; readonly isTypeOnly: boolean; - readonly propertyName?: ModuleExportName; // Name preceding "as" keyword (or undefined when "as" is absent) + readonly propertyName?: ModuleExportName | undefined; // Name preceding "as" keyword (or undefined when "as" is absent) readonly name: ModuleExportName; // Declared name } @@ -3831,8 +3834,8 @@ export type TypeOnlyAliasDeclaration = TypeOnlyImportDeclaration | TypeOnlyExpor export interface ExportAssignment extends DeclarationStatement, JSDocContainer { readonly kind: SyntaxKind.ExportAssignment; readonly parent: SourceFile; - readonly modifiers?: NodeArray; - readonly isExportEquals?: boolean; + readonly modifiers?: NodeArray | undefined; + readonly isExportEquals?: boolean | undefined; readonly expression: Expression; } @@ -3930,31 +3933,31 @@ export type JSDocTypeReferencingNode = export interface JSDoc extends Node { readonly kind: SyntaxKind.JSDoc; readonly parent: HasJSDoc; - readonly tags?: NodeArray; - readonly comment?: string | NodeArray; + readonly tags?: NodeArray | undefined; + readonly comment?: string | NodeArray | undefined; } export interface JSDocTag extends Node { readonly parent: JSDoc | JSDocTypeLiteral; readonly tagName: Identifier; - readonly comment?: string | NodeArray; + readonly comment?: string | NodeArray | undefined; } export interface JSDocLink extends Node { readonly kind: SyntaxKind.JSDocLink; - readonly name?: EntityName | JSDocMemberName; + readonly name?: EntityName | JSDocMemberName | undefined; text: string; } export interface JSDocLinkCode extends Node { readonly kind: SyntaxKind.JSDocLinkCode; - readonly name?: EntityName | JSDocMemberName; + readonly name?: EntityName | JSDocMemberName | undefined; text: string; } export interface JSDocLinkPlain extends Node { readonly kind: SyntaxKind.JSDocLinkPlain; - readonly name?: EntityName | JSDocMemberName; + readonly name?: EntityName | JSDocMemberName | undefined; text: string; } @@ -3969,18 +3972,22 @@ export interface JSDocUnknownTag extends JSDocTag { readonly kind: SyntaxKind.JSDocTag; } +export interface JSDocClassReference extends ExpressionWithTypeArguments { + readonly expression: Identifier | PropertyAccessEntityNameExpression; +} + /** * Note that `@extends` is a synonym of `@augments`. * Both tags are represented by this interface. */ export interface JSDocAugmentsTag extends JSDocTag { readonly kind: SyntaxKind.JSDocAugmentsTag; - readonly class: ExpressionWithTypeArguments & { readonly expression: Identifier | PropertyAccessEntityNameExpression; }; + readonly class: JSDocClassReference; } export interface JSDocImplementsTag extends JSDocTag { readonly kind: SyntaxKind.JSDocImplementsTag; - readonly class: ExpressionWithTypeArguments & { readonly expression: Identifier | PropertyAccessEntityNameExpression; }; + readonly class: JSDocClassReference; } export interface JSDocAuthorTag extends JSDocTag { @@ -3988,7 +3995,7 @@ export interface JSDocAuthorTag extends JSDocTag { } export interface JSDocDeprecatedTag extends JSDocTag { - kind: SyntaxKind.JSDocDeprecatedTag; + readonly kind: SyntaxKind.JSDocDeprecatedTag; } export interface JSDocClassTag extends JSDocTag { @@ -4034,12 +4041,12 @@ export interface JSDocTemplateTag extends JSDocTag { export interface JSDocSeeTag extends JSDocTag { readonly kind: SyntaxKind.JSDocSeeTag; - readonly name?: JSDocNameReference; + readonly name?: JSDocNameReference | undefined; } export interface JSDocReturnTag extends JSDocTag { readonly kind: SyntaxKind.JSDocReturnTag; - readonly typeExpression?: JSDocTypeExpression; + readonly typeExpression?: JSDocTypeExpression | undefined; } export interface JSDocTypeTag extends JSDocTag { @@ -4050,16 +4057,16 @@ export interface JSDocTypeTag extends JSDocTag { export interface JSDocTypedefTag extends JSDocTag, NamedDeclaration, LocalsContainer { readonly kind: SyntaxKind.JSDocTypedefTag; readonly parent: JSDoc; - readonly fullName?: JSDocNamespaceDeclaration | Identifier; - readonly name?: Identifier; - readonly typeExpression?: JSDocTypeExpression | JSDocTypeLiteral; + readonly fullName?: JSDocNamespaceDeclaration | Identifier | undefined; + readonly name?: Identifier | undefined; + readonly typeExpression?: JSDocTypeExpression | JSDocTypeLiteral | undefined; } export interface JSDocCallbackTag extends JSDocTag, NamedDeclaration, LocalsContainer { readonly kind: SyntaxKind.JSDocCallbackTag; readonly parent: JSDoc; - readonly fullName?: JSDocNamespaceDeclaration | Identifier; - readonly name?: Identifier; + readonly fullName?: JSDocNamespaceDeclaration | Identifier | undefined; + readonly name?: Identifier | undefined; readonly typeExpression: JSDocSignature; } @@ -4071,12 +4078,12 @@ export interface JSDocOverloadTag extends JSDocTag { export interface JSDocThrowsTag extends JSDocTag { readonly kind: SyntaxKind.JSDocThrowsTag; - readonly typeExpression?: JSDocTypeExpression; + readonly typeExpression?: JSDocTypeExpression | undefined; } export interface JSDocSignature extends JSDocType, Declaration, JSDocContainer, LocalsContainer { readonly kind: SyntaxKind.JSDocSignature; - readonly typeParameters?: readonly JSDocTemplateTag[]; + readonly typeParameters?: readonly JSDocTemplateTag[] | undefined; readonly parameters: readonly JSDocParameterTag[]; readonly type: JSDocReturnTag | undefined; } @@ -4084,7 +4091,7 @@ export interface JSDocSignature extends JSDocType, Declaration, JSDocContainer, export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { readonly parent: JSDoc; readonly name: EntityName; - readonly typeExpression?: JSDocTypeExpression; + readonly typeExpression?: JSDocTypeExpression | undefined; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ readonly isNameFirst: boolean; readonly isBracketed: boolean; @@ -4100,7 +4107,7 @@ export interface JSDocParameterTag extends JSDocPropertyLikeTag { export interface JSDocTypeLiteral extends JSDocType, Declaration { readonly kind: SyntaxKind.JSDocTypeLiteral; - readonly jsDocPropertyTags?: readonly JSDocPropertyLikeTag[]; + readonly jsDocPropertyTags?: readonly JSDocPropertyLikeTag[] | undefined; /** If true, then this type literal represents an *array* of its type. */ readonly isArrayType: boolean; } @@ -4118,9 +4125,9 @@ export interface JSDocSatisfiesExpression extends ParenthesizedExpression { export interface JSDocImportTag extends JSDocTag { readonly kind: SyntaxKind.JSDocImportTag; readonly parent: JSDoc; - readonly importClause?: ImportClause; + readonly importClause?: ImportClause | undefined; readonly moduleSpecifier: Expression; - readonly attributes?: ImportAttributes; + readonly attributes?: ImportAttributes | undefined; } // NOTE: Ensure this is up-to-date with src/debug/debug.ts @@ -4265,7 +4272,7 @@ export interface AmdDependency { export interface SourceFileLike { readonly text: string; /** @internal */ - lineMap?: readonly number[]; + lineMap?: readonly number[] | undefined; /** @internal */ getPositionOfLineAndCharacter?(line: number, character: number, allowEdits?: true): number; } @@ -4274,8 +4281,8 @@ export interface SourceFileLike { export interface FutureSourceFile { readonly path: Path; readonly fileName: string; - readonly impliedNodeFormat?: ResolutionMode; - readonly packageJsonScope?: PackageJsonInfo; + readonly impliedNodeFormat?: ResolutionMode | undefined; + readonly packageJsonScope?: PackageJsonInfo | undefined; readonly externalModuleIndicator?: true | undefined; readonly commonJsModuleIndicator?: true | undefined; readonly statements: readonly never[]; @@ -4328,10 +4335,10 @@ export interface SourceFile extends Declaration, LocalsContainer { * * @internal */ - redirectInfo?: RedirectInfo; + redirectInfo?: RedirectInfo | undefined; amdDependencies: readonly AmdDependency[]; - moduleName?: string; + moduleName?: string | undefined; referencedFiles: readonly FileReference[]; typeReferenceDirectives: readonly FileReference[]; libReferenceDirectives: readonly FileReference[]; @@ -4340,7 +4347,7 @@ export interface SourceFile extends Declaration, LocalsContainer { // this map is used by transpiler to supply alternative names for dependencies (i.e. in case of bundling) /** @internal */ - renamedDependencies?: ReadonlyMap; + renamedDependencies?: ReadonlyMap | undefined; /** * lib.d.ts should have a reference comment like @@ -4371,9 +4378,9 @@ export interface SourceFile extends Declaration, LocalsContainer { * of `node`). If so, this field will be unset and source files will be considered to be * CommonJS-output-format by the node module transformer and type checker, regardless of extension or context. */ - impliedNodeFormat?: ResolutionMode; - /** @internal */ packageJsonLocations?: readonly string[]; - /** @internal */ packageJsonScope?: PackageJsonInfo; + impliedNodeFormat?: ResolutionMode | undefined; + /** @internal */ packageJsonLocations?: readonly string[] | undefined; + /** @internal */ packageJsonScope?: PackageJsonInfo | undefined; /** @internal */ scriptKind: ScriptKind; @@ -4384,7 +4391,7 @@ export interface SourceFile extends Declaration, LocalsContainer { * * @internal */ - externalModuleIndicator?: Node | true; + externalModuleIndicator?: Node | true | undefined; /** * The callback used to set the external module indicator - this is saved to * be later reused during incremental reparsing, which otherwise lacks the information @@ -4392,11 +4399,11 @@ export interface SourceFile extends Declaration, LocalsContainer { * * @internal */ - setExternalModuleIndicator?: (file: SourceFile) => void; + setExternalModuleIndicator?: ((file: SourceFile) => void) | undefined; // The first node that causes this file to be a CommonJS module - /** @internal */ commonJsModuleIndicator?: Node; + /** @internal */ commonJsModuleIndicator?: Node | undefined; // JS identifier-declarations that are intended to merge with globals - /** @internal */ jsGlobalAugmentations?: SymbolTable; + /** @internal */ jsGlobalAugmentations?: SymbolTable | undefined; /** @internal */ identifiers: ReadonlyMap; // Map from a string to an interned string /** @internal */ nodeCount: number; @@ -4409,49 +4416,49 @@ export interface SourceFile extends Declaration, LocalsContainer { // File-level diagnostics reported by the binder. /** @internal */ bindDiagnostics: DiagnosticWithLocation[]; - /** @internal */ bindSuggestionDiagnostics?: DiagnosticWithLocation[]; + /** @internal */ bindSuggestionDiagnostics?: DiagnosticWithLocation[] | undefined; // File-level JSDoc diagnostics reported by the JSDoc parser - /** @internal */ jsDocDiagnostics?: DiagnosticWithLocation[]; + /** @internal */ jsDocDiagnostics?: DiagnosticWithLocation[] | undefined; // Stores additional file-level diagnostics reported by the program - /** @internal */ additionalSyntacticDiagnostics?: readonly DiagnosticWithLocation[]; + /** @internal */ additionalSyntacticDiagnostics?: readonly DiagnosticWithLocation[] | undefined; // Stores a line map for the file. // This field should never be used directly to obtain line map, use getLineMap function instead. /** @internal */ lineMap: readonly number[]; - /** @internal */ classifiableNames?: ReadonlySet<__String>; + /** @internal */ classifiableNames?: ReadonlySet<__String> | undefined; // Comments containing @ts-* directives, in order. - /** @internal */ commentDirectives?: CommentDirective[]; + /** @internal */ commentDirectives?: CommentDirective[] | undefined; /** @internal */ imports: readonly StringLiteralLike[]; // Identifier only if `declare global` /** @internal */ moduleAugmentations: readonly (StringLiteral | Identifier)[]; - /** @internal */ patternAmbientModules?: PatternAmbientModule[]; + /** @internal */ patternAmbientModules?: PatternAmbientModule[] | undefined; /** @internal */ ambientModuleNames: readonly string[]; - /** @internal */ checkJsDirective?: CheckJsDirective; + /** @internal */ checkJsDirective?: CheckJsDirective | undefined; /** @internal */ version: string; /** @internal */ pragmas: ReadonlyPragmaMap; - /** @internal */ localJsxNamespace?: __String; - /** @internal */ localJsxFragmentNamespace?: __String; - /** @internal */ localJsxFactory?: EntityName; - /** @internal */ localJsxFragmentFactory?: EntityName; + /** @internal */ localJsxNamespace?: __String | undefined; + /** @internal */ localJsxFragmentNamespace?: __String | undefined; + /** @internal */ localJsxFactory?: EntityName | undefined; + /** @internal */ localJsxFragmentFactory?: EntityName | undefined; - /** @internal */ endFlowNode?: FlowNode; + /** @internal */ endFlowNode?: FlowNode | undefined; - /** @internal */ jsDocParsingMode?: JSDocParsingMode; + /** @internal */ jsDocParsingMode?: JSDocParsingMode | undefined; } /** @internal */ export interface ReadonlyPragmaContext { languageVersion: ScriptTarget; - pragmas?: ReadonlyPragmaMap; - checkJsDirective?: CheckJsDirective; + pragmas?: ReadonlyPragmaMap | undefined; + checkJsDirective?: CheckJsDirective | undefined; referencedFiles: readonly FileReference[]; typeReferenceDirectives: readonly FileReference[]; libReferenceDirectives: readonly FileReference[]; amdDependencies: readonly AmdDependency[]; - hasNoDefaultLib?: boolean; - moduleName?: string; + hasNoDefaultLib?: boolean | undefined; + moduleName?: string | undefined; } /** @internal */ @@ -4481,10 +4488,10 @@ export const enum CommentDirectiveType { export interface Bundle extends Node { readonly kind: SyntaxKind.Bundle; readonly sourceFiles: readonly SourceFile[]; - /** @internal */ syntheticFileReferences?: readonly FileReference[]; - /** @internal */ syntheticTypeReferences?: readonly FileReference[]; - /** @internal */ syntheticLibReferences?: readonly FileReference[]; - /** @internal */ hasNoDefaultLib?: boolean; + /** @internal */ syntheticFileReferences?: readonly FileReference[] | undefined; + /** @internal */ syntheticTypeReferences?: readonly FileReference[] | undefined; + /** @internal */ syntheticLibReferences?: readonly FileReference[] | undefined; + /** @internal */ hasNoDefaultLib?: boolean | undefined; } export interface JsonSourceFile extends SourceFile { @@ -4497,7 +4504,6 @@ export interface TsConfigSourceFile extends JsonSourceFile { } export interface JsonMinusNumericLiteral extends PrefixUnaryExpression { - readonly kind: SyntaxKind.PrefixUnaryExpression; readonly operator: SyntaxKind.MinusToken; readonly operand: NumericLiteral; } @@ -8605,8 +8611,8 @@ export type ImmediatelyInvokedArrowFunction = CallExpression & { readonly expres export interface NodeFactory { /** @internal */ readonly parenthesizer: ParenthesizerRules; /** @internal */ readonly converters: NodeConverters; - /** @internal */ readonly baseFactory: BaseNodeFactory; /** @internal */ readonly flags: NodeFactoryFlags; + /** @internal */ readonly astFactory: ast.AstNodeFactory; createNodeArray(elements?: readonly T[], hasTrailingComma?: boolean): NodeArray; @@ -9107,7 +9113,8 @@ export interface NodeFactory { createJsxText(text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText; updateJsxText(node: JsxText, text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText; createJsxOpeningFragment(): JsxOpeningFragment; - createJsxJsxClosingFragment(): JsxClosingFragment; + createJsxClosingFragment(): JsxClosingFragment; + /** @deprecated*/ createJsxJsxClosingFragment(): JsxClosingFragment; updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment): JsxFragment; createJsxAttribute(name: JsxAttributeName, initializer: JsxAttributeValue | undefined): JsxAttribute; updateJsxAttribute(node: JsxAttribute, name: JsxAttributeName, initializer: JsxAttributeValue | undefined): JsxAttribute; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 673c0b38c156d..d6db8f59c172b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -24,6 +24,7 @@ import { AssignmentDeclarationKind, AssignmentExpression, AssignmentOperatorToken, + ast, BarBarEqualsToken, BinaryExpression, binarySearch, @@ -5467,9 +5468,9 @@ export const enum Associativity { } /** @internal */ -export function getExpressionAssociativity(expression: Expression) { +export function getExpressionAssociativity(expression: Expression | ast.AstExpression) { const operator = getOperator(expression); - const hasArguments = expression.kind === SyntaxKind.NewExpression && (expression as NewExpression).arguments !== undefined; + const hasArguments = expression.kind === SyntaxKind.NewExpression && (expression instanceof ast.AstNode ? (expression as ast.AstNewExpression).data.arguments !== undefined : (expression as NewExpression).arguments !== undefined); return getOperatorAssociativity(expression.kind, operator, hasArguments); } @@ -5514,18 +5515,18 @@ export function getOperatorAssociativity(kind: SyntaxKind, operator: SyntaxKind, } /** @internal */ -export function getExpressionPrecedence(expression: Expression) { +export function getExpressionPrecedence(expression: Expression | ast.AstExpression) { const operator = getOperator(expression); - const hasArguments = expression.kind === SyntaxKind.NewExpression && (expression as NewExpression).arguments !== undefined; + const hasArguments = expression.kind === SyntaxKind.NewExpression && (expression instanceof ast.AstNode ? (expression as ast.AstNewExpression).data.arguments !== undefined : (expression as NewExpression).arguments !== undefined); return getOperatorPrecedence(expression.kind, operator, hasArguments); } -function getOperator(expression: Expression): SyntaxKind { +function getOperator(expression: Expression | ast.AstExpression): SyntaxKind { if (expression.kind === SyntaxKind.BinaryExpression) { - return (expression as BinaryExpression).operatorToken.kind; + return expression instanceof ast.AstNode ? (expression as ast.AstBinaryExpression).data.operatorToken.kind : (expression as BinaryExpression).operatorToken.kind; } else if (expression.kind === SyntaxKind.PrefixUnaryExpression || expression.kind === SyntaxKind.PostfixUnaryExpression) { - return (expression as PrefixUnaryExpression | PostfixUnaryExpression).operator; + return expression instanceof ast.AstNode ? (expression as ast.AstPrefixUnaryExpression | ast.AstPostfixUnaryExpression).data.operator : (expression as PrefixUnaryExpression | PostfixUnaryExpression).operator; } else { return expression.kind; @@ -8246,11 +8247,6 @@ export function getLeftmostExpression(node: Expression, stopAtCallExpressions: b /** @internal */ export interface ObjectAllocator { - getNodeConstructor(): new (kind: SyntaxKind, pos: number, end: number) => Node; - getTokenConstructor(): new (kind: TKind, pos: number, end: number) => Token; - getIdentifierConstructor(): new (kind: SyntaxKind.Identifier, pos: number, end: number) => Identifier; - getPrivateIdentifierConstructor(): new (kind: SyntaxKind.PrivateIdentifier, pos: number, end: number) => PrivateIdentifier; - getSourceFileConstructor(): new (kind: SyntaxKind.SourceFile, pos: number, end: number) => SourceFile; getSymbolConstructor(): new (flags: SymbolFlags, name: __String) => Symbol; getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type; getSignatureConstructor(): new (checker: TypeChecker, flags: SignatureFlags) => Signature; @@ -8291,45 +8287,6 @@ function Signature(this: Signature, checker: TypeChecker, flags: SignatureFlags) } } -function Node(this: Mutable, kind: SyntaxKind, pos: number, end: number) { - // Note: if modifying this, be sure to update NodeObject in src/services/services.ts - this.pos = pos; - this.end = end; - this.kind = kind; - this.id = 0; - this.flags = NodeFlags.None; - this.modifierFlagsCache = ModifierFlags.None; - this.transformFlags = TransformFlags.None; - this.parent = undefined!; - this.original = undefined; - this.emitNode = undefined; -} - -function Token(this: Mutable, kind: SyntaxKind, pos: number, end: number) { - // Note: if modifying this, be sure to update TokenOrIdentifierObject in src/services/services.ts - this.pos = pos; - this.end = end; - this.kind = kind; - this.id = 0; - this.flags = NodeFlags.None; - this.transformFlags = TransformFlags.None; - this.parent = undefined!; - this.emitNode = undefined; -} - -function Identifier(this: Mutable, kind: SyntaxKind, pos: number, end: number) { - // Note: if modifying this, be sure to update TokenOrIdentifierObject in src/services/services.ts - this.pos = pos; - this.end = end; - this.kind = kind; - this.id = 0; - this.flags = NodeFlags.None; - this.transformFlags = TransformFlags.None; - this.parent = undefined!; - this.original = undefined; - this.emitNode = undefined; -} - function SourceMapSource(this: SourceMapSource, fileName: string, text: string, skipTrivia?: (pos: number) => number) { // Note: if modifying this, be sure to update SourceMapSourceObject in src/services/services.ts this.fileName = fileName; @@ -8339,11 +8296,6 @@ function SourceMapSource(this: SourceMapSource, fileName: string, text: string, /** @internal */ export const objectAllocator: ObjectAllocator = { - getNodeConstructor: () => Node as any, - getTokenConstructor: () => Token as any, - getIdentifierConstructor: () => Identifier as any, - getPrivateIdentifierConstructor: () => Node as any, - getSourceFileConstructor: () => Node as any, getSymbolConstructor: () => Symbol as any, getTypeConstructor: () => Type as any, getSignatureConstructor: () => Signature as any, diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 65d1482263d17..8b89fffbe3775 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -290,6 +290,7 @@ import { TypeReferenceType, UnaryExpression, VariableDeclaration, + ast, } from "./_namespaces/ts.js"; export function isExternalModuleNameRelative(moduleName: string): boolean { @@ -795,7 +796,10 @@ export function findAncestor(node: Node | undefined, callback: (element: Node) = * * @param node The node to test. */ -export function isParseTreeNode(node: Node): boolean { +export function isParseTreeNode(node: Node): boolean; +/** @internal */ +export function isParseTreeNode(node: Node | ast.AstNode): boolean; // eslint-disable-line @typescript-eslint/unified-signatures +export function isParseTreeNode(node: Node | ast.AstNode): boolean { return (node.flags & NodeFlags.Synthesized) === 0; } @@ -1476,7 +1480,7 @@ export function isToken(n: Node): boolean { /** @internal */ export function isNodeArray(array: readonly T[]): array is NodeArray { - return hasProperty(array, "pos") && hasProperty(array, "end"); + return hasProperty(array, "pos") && hasProperty(array, "end") || array instanceof ast.NodeArray; } // Literals @@ -1979,7 +1983,8 @@ export function isLeftHandSideExpression(node: Node): node is LeftHandSideExpres return isLeftHandSideExpressionKind(skipPartiallyEmittedExpressions(node).kind); } -function isLeftHandSideExpressionKind(kind: SyntaxKind): boolean { +/** @internal */ +export function isLeftHandSideExpressionKind(kind: SyntaxKind): boolean { switch (kind) { case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ElementAccessExpression: @@ -2023,7 +2028,8 @@ export function isUnaryExpression(node: Node): node is UnaryExpression { return isUnaryExpressionKind(skipPartiallyEmittedExpressions(node).kind); } -function isUnaryExpressionKind(kind: SyntaxKind): boolean { +/** @internal */ +export function isUnaryExpressionKind(kind: SyntaxKind): boolean { switch (kind) { case SyntaxKind.PrefixUnaryExpression: case SyntaxKind.PostfixUnaryExpression: diff --git a/src/harness/harnessUtils.ts b/src/harness/harnessUtils.ts index 372202d08e443..8bd4140da3964 100644 --- a/src/harness/harnessUtils.ts +++ b/src/harness/harnessUtils.ts @@ -132,7 +132,11 @@ export function assertInvariants(node: ts.Node | undefined, parent: ts.Node | un childName === "illegalQuestionToken" || childName === "illegalExclamationToken" || childName === "illegalTypeParameters" || - childName === "illegalType" + childName === "illegalType" || + childName === "ast" || + childName === "data" || + childName === "_node" || + childName === "loc" ) { continue; } @@ -164,7 +168,12 @@ function convertDiagnostic(diagnostic: ts.Diagnostic) { } export function sourceFileToJSON(file: ts.Node): string { - return JSON.stringify(file, (_, v) => isNodeOrArray(v) ? serializeNode(v) : v, " "); + const s = JSON.stringify(file, (_, v) => { + if (v instanceof ts.ast.AstNode) v = v.node; + if (v instanceof ts.ast.AstNodeArray) v = v.nodes; + return isNodeOrArray(v) ? serializeNode(v) : v; + }, " "); + return s; function getKindName(k: number | string | undefined): string | undefined { if (k === undefined || ts.isString(k)) { @@ -177,13 +186,12 @@ export function sourceFileToJSON(file: ts.Node): string { return ts.Debug.formatNodeFlags(f); } - function serializeNode(n: ts.Node): any { - const o: any = { kind: getKindName(n.kind) }; - if (ts.containsParseError(n)) { - o.containsParseError = true; - } + function serializeProperties(o: any, n: ts.Node | undefined, obj: any, propertyNames: Iterable) { + for (const propertyName of propertyNames) { + if (ts.hasProperty(o, propertyName)) { + continue; + } - for (const propertyName of Object.getOwnPropertyNames(n) as readonly (keyof ts.SourceFile | keyof ts.Identifier | keyof ts.StringLiteral)[]) { switch (propertyName) { case "parent": case "symbol": @@ -196,12 +204,15 @@ export function sourceFileToJSON(file: ts.Node): string { case "identifierCount": case "scriptSnapshot": case "emitNode": + case "ast": // Blocklist of items we never put in the baseline file. break; case "hasExtendedUnicodeEscape": - if ((n as any).hasExtendedUnicodeEscape) { - o.hasExtendedUnicodeEscape = true; + case "isUnterminated": + case "isTypeOnly": + if (obj[propertyName]) { + o[propertyName] = true; } break; @@ -209,8 +220,8 @@ export function sourceFileToJSON(file: ts.Node): string { // Clear the flags that are produced by aggregating child values. That is ephemeral // data we don't care about in the dump. We only care what the parser set directly // on the AST. - let flags = n.flags & ~(ts.NodeFlags.JavaScriptFile | ts.NodeFlags.HasAggregatedChildData); - if (ts.isIdentifier(n)) { + let flags = obj.flags & ~(ts.NodeFlags.JavaScriptFile | ts.NodeFlags.HasAggregatedChildData); + if (n && ts.isIdentifier(n)) { if (flags & ts.NodeFlags.IdentifierHasExtendedUnicodeEscape) { o.hasExtendedUnicodeEscape = true; flags &= ~ts.NodeFlags.IdentifierHasExtendedUnicodeEscape; @@ -219,30 +230,67 @@ export function sourceFileToJSON(file: ts.Node): string { if (flags) { o[propertyName] = getNodeFlagName(flags); } - break; + break; case "parseDiagnostics": - o[propertyName] = convertDiagnostics((n as any)[propertyName]); + o[propertyName] = convertDiagnostics(obj[propertyName]); break; case "nextContainer": - if ((n as ts.HasLocals).nextContainer) { - o[propertyName] = { kind: (n as ts.HasLocals).nextContainer!.kind, pos: (n as ts.HasLocals).nextContainer!.pos, end: (n as ts.HasLocals).nextContainer!.end }; + if ((obj as ts.HasLocals).nextContainer) { + o[propertyName] = { + kind: (obj as ts.HasLocals).nextContainer!.kind, + pos: (obj as ts.HasLocals).nextContainer!.pos, + end: (obj as ts.HasLocals).nextContainer!.end + }; } break; case "text": // Include 'text' field for identifiers/literals, but not for source files. - if (n.kind !== ts.SyntaxKind.SourceFile) { - o[propertyName] = (n as any)[propertyName]; + if (!n || n.kind !== ts.SyntaxKind.SourceFile) { + o[propertyName] = obj[propertyName]; + } + break; + + case "modifierFlagsCache": + if (!n || ts.isNodeKind(n.kind) || ts.isLiteralKind(n.kind)) { + o[propertyName] = obj[propertyName]; } break; - default: - o[propertyName] = (n as any)[propertyName]; + default: { + let value = obj[propertyName]; + if (value instanceof ts.ast.AstNode) value = value.node; + if (value instanceof ts.ast.AstNodeArray) value = value.nodes; + o[propertyName] = value; + } } } + } + + function serializeNode(n: ts.Node | ts.NodeArray): any { + const o: any = {}; + if ("kind" in n) { // eslint-disable-line local/no-in-operator + o.kind = getKindName(n.kind); + if (ts.containsParseError(n)) { + o.containsParseError = true; + } + if (n instanceof ts.ast.Node) { + serializeProperties(o, n, n, ["pos", "end", "flags", "modifierFlagsCache", "transformFlags"]); + serializeProperties(o, n, n.ast.data, Object.getOwnPropertyNames(n.ast.data)); + } + else { + serializeProperties(o, n, n, Object.getOwnPropertyNames(n)); + } + } + else { + serializeProperties(o, /*n*/ undefined, n, Object.getOwnPropertyNames(n)); + if (n instanceof ts.ast.NodeArray) { + serializeProperties(o, /*n*/ undefined, n, ["pos", "end", "hasTrailingComma", "transformFlags"]); + } + } return o; } } @@ -274,51 +322,61 @@ export function assertDiagnosticsEquals(array1: readonly ts.Diagnostic[], array2 } export function assertStructuralEquals(node1: ts.Node, node2: ts.Node) { + assertStructuralEqualsWorker(node1, node2, ""); +} + +function assertStructuralEqualsWorker(node1: ts.Node, node2: ts.Node, path: string) { if (node1 === node2) { return; } - assert(node1, "node1"); - assert(node2, "node2"); - assert.equal(node1.pos, node2.pos, "node1.pos !== node2.pos"); - assert.equal(node1.end, node2.end, "node1.end !== node2.end"); - assert.equal(node1.kind, node2.kind, "node1.kind !== node2.kind"); + assert(node1, `node1 is missing. path: ${path}`); + assert(node2, `node2 is missing. path: ${path}`); + assert.equal(node1.pos, node2.pos, `node1.pos !== node2.pos. path: ${path}`); + assert.equal(node1.end, node2.end, `node1.end !== node2.end. path: ${path}`); + assert.equal(node1.kind, node2.kind, `node1.kind !== node2.kind. path: ${path}`); // call this on both nodes to ensure all propagated flags have been set (and thus can be // compared). - assert.equal(ts.containsParseError(node1), ts.containsParseError(node2)); - assert.equal(node1.flags & ~ts.NodeFlags.ReachabilityAndEmitFlags, node2.flags & ~ts.NodeFlags.ReachabilityAndEmitFlags, "node1.flags !== node2.flags"); + assert.equal(ts.containsParseError(node1), ts.containsParseError(node2), `containsParseError(node1) !== containsParseError(node2): path: ${path}`); + assert.equal(node1.flags & ~ts.NodeFlags.ReachabilityAndEmitFlags, node2.flags & ~ts.NodeFlags.ReachabilityAndEmitFlags, `node1.flags !== node2.flags. path: ${path}`); ts.forEachChild(node1, child1 => { const childName = findChildName(node1, child1); const child2: ts.Node = (node2 as any)[childName]; - assertStructuralEquals(child1, child2); + assertStructuralEqualsWorker(child1, child2, `${path}.${childName}`); }, array1 => { const childName = findChildName(node1, array1); const array2: ts.NodeArray = (node2 as any)[childName]; - assertArrayStructuralEquals(array1, array2); + assertArrayStructuralEquals(array1, array2, `${path}.${childName}`); }); } -function assertArrayStructuralEquals(array1: ts.NodeArray, array2: ts.NodeArray) { +function assertArrayStructuralEquals(array1: ts.NodeArray, array2: ts.NodeArray, path: string) { if (array1 === array2) { return; } - assert(array1, "array1"); - assert(array2, "array2"); - assert.equal(array1.pos, array2.pos, "array1.pos !== array2.pos"); - assert.equal(array1.end, array2.end, "array1.end !== array2.end"); - assert.equal(array1.length, array2.length, "array1.length !== array2.length"); + assert(array1, `array1 is missing. path: ${path}`); + assert(array2, `array2 is missing. path: ${path}`); + assert.equal(array1.pos, array2.pos, `array1.pos !== array2.pos. path: ${path}`); + assert.equal(array1.end, array2.end, `array1.end !== array2.end. path: ${path}`); + assert.equal(array1.length, array2.length, `array1.length !== array2.length. path: ${path}`); for (let i = 0; i < array1.length; i++) { - assertStructuralEquals(array1[i], array2[i]); + assertStructuralEqualsWorker(array1[i], array2[i], `${path}[${i}]`); } } function findChildName(parent: any, child: any) { + if (parent instanceof ts.ast.Node) { + parent = parent.ast.data; + } + if (child instanceof ts.ast.Node || child instanceof ts.ast.NodeArray) { + child = child.ast; + } for (const name in parent) { if (ts.hasProperty(parent, name) && parent[name] === child) { return name; diff --git a/src/harness/typeWriter.ts b/src/harness/typeWriter.ts index 6bee2b5fe9f25..fb13856fedde7 100644 --- a/src/harness/typeWriter.ts +++ b/src/harness/typeWriter.ts @@ -180,6 +180,7 @@ export class TypeWriterWalker { currentSourceFile!: ts.SourceFile; private checker: ts.TypeChecker; + private symbolTestOutputCache = new Map(); constructor(private program: ts.Program, private hadErrorBaseline: boolean) { // Consider getting both the diagnostics checker and the non-diagnostics checker to verify @@ -314,8 +315,9 @@ export class TypeWriterWalker { } count++; symbolString += ", "; - if ((declaration as any).__symbolTestOutputCache) { - symbolString += (declaration as any).__symbolTestOutputCache; + const symbolTestOutputCacheEntry = this.symbolTestOutputCache.get(declaration); + if (symbolTestOutputCacheEntry) { + symbolString += symbolTestOutputCacheEntry; continue; } const declSourceFile = declaration.getSourceFile(); @@ -324,7 +326,7 @@ export class TypeWriterWalker { const isLibFile = /lib.*\.d\.ts/i.test(fileName); const declText = `Decl(${fileName}, ${isLibFile ? "--" : declLineAndCharacter.line}, ${isLibFile ? "--" : declLineAndCharacter.character})`; symbolString += declText; - (declaration as any).__symbolTestOutputCache = declText; + this.symbolTestOutputCache.set(declaration, declText); } } symbolString += ")"; diff --git a/src/services/services.ts b/src/services/services.ts index 116bda8a27e75..04e205a83f707 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2,9 +2,7 @@ import { __String, ApplicableRefactorInfo, ApplyCodeActionCommandResult, - AssignmentDeclarationKind, BaseType, - BinaryExpression, BlockLike, BreakpointResolver, CallHierarchy, @@ -15,7 +13,6 @@ import { canIncludeBindAndCheckDiagnostics, changeCompilerHostLikeToUseCache, CharacterCodes, - CheckJsDirective, Classifications, ClassifiedSpan, ClassifiedSpan2020, @@ -33,12 +30,10 @@ import { CompletionEntryDetails, CompletionInfo, Completions, - computePositionOfLineAndCharacter, computeSuggestionDiagnostics, containsParseError, createDocumentRegistry, createGetCanonicalFileName, - createMultiMap, createProgram, CreateProgramOptions, createSourceFile, @@ -61,20 +56,14 @@ import { EditorOptions, EditorSettings, ElementAccessExpression, - EmitNode, EmitTextWriter, emptyArray, emptyOptions, - EndOfFileToken, - EntityName, equateValues, - ExportDeclaration, Extension, extensionFromPath, - FileReference, FileTextChanges, filter, - find, FindAllReferences, findAncestor, findChildOfKind, @@ -89,10 +78,8 @@ import { FormatCodeOptions, FormatCodeSettings, formatting, - FunctionLikeDeclaration, getAdjustedRenameLocation, getAllSuperTypeNodes, - getAssignmentDeclarationKind, getBaseFileName, GetCompletionsAtPositionOptions, getContainerNode, @@ -105,22 +92,17 @@ import { getImpliedNodeFormatForFile, getJSDocTags, getLineAndCharacterOfPosition, - getLineStarts, getMappedDocumentSpan, getNameFromPropertyName, getNewLineCharacter, getNewLineOrDefaultFromHost, - getNodeChildren, - getNonAssignedNameOfDeclaration, getNormalizedAbsolutePath, getObjectFlags, getQuotePreference, getScriptKind, getSetExternalModuleIndicator, getSnapshotText, - getSourceFileOfNode, getSourceMapper, - getTokenPosOfNode, getTouchingPropertyName, getTouchingToken, GoToDefinition, @@ -128,16 +110,11 @@ import { hasJSDocNodes, hasProperty, hasStaticModifier, - hasSyntacticModifier, - hasTabstop, HostCancellationToken, hostGetCanonicalFileName, hostUsesCaseSensitiveFileNames, - Identifier, identity, - idText, ImplementationLocation, - ImportDeclaration, IndexKind, IndexType, InlayHint, @@ -148,10 +125,8 @@ import { InterfaceType, IntersectionType, isArray, - isBindingPattern, isBlockLike, isClassLike, - isComputedPropertyName, isConstTypeReference, IScriptSnapshot, isDeclarationName, @@ -165,7 +140,6 @@ import { isInString, isInTemplateString, isIntrinsicJsxName, - isJSDocCommentContainingNode, isJsxAttributes, isJsxClosingElement, isJsxElement, @@ -176,17 +150,13 @@ import { isJsxText, isLabelName, isLiteralComputedPropertyDeclarationName, - isNamedExports, isNamedTupleMember, isNameOfModuleDeclaration, isNewExpression, - isNodeKind, isObjectLiteralElement, isObjectLiteralExpression, isPrivateIdentifier, isProgramUptoDate, - isPropertyAccessExpression, - isPropertyName, isRightSideOfPropertyAccess, isRightSideOfQualifiedName, isSetAccessor, @@ -197,9 +167,7 @@ import { isTextWhiteSpaceLike, isThisTypeParameter, isTransientSymbol, - JSDoc, JsDoc, - JSDocContainer, JSDocParsingMode, JSDocTagInfo, JsonSourceFile, @@ -211,8 +179,6 @@ import { LanguageService, LanguageServiceHost, LanguageServiceMode, - LanguageVariant, - lastOrUndefined, length, LineAndCharacter, lineBreakPart, @@ -225,13 +191,11 @@ import { mapOneOrMany, maybeBind, maybeSetLocalizedDiagnosticMessages, - ModifierFlags, ModuleDeclaration, NavigateToItem, NavigationBarItem, NavigationTree, Node, - NodeArray, NodeFlags, noop, normalizePath, @@ -255,10 +219,7 @@ import { pasteEdits, PasteEditsArgs, Path, - positionIsSynthesized, PossibleProgramFileInfo, - PragmaMap, - PrivateIdentifier, Program, PropertyName, PropertySignature, @@ -276,14 +237,12 @@ import { RenameLocation, ResolvedProjectReference, returnFalse, - scanner, ScriptElementKind, ScriptElementKindModifier, ScriptKind, ScriptTarget, SelectionRange, SemanticClassificationFormat, - setNodeChildren, setObjectAllocator, Signature, SignatureDeclaration, @@ -298,11 +257,8 @@ import { some, SortedArray, SourceFile, - SourceFileLike, SourceMapSource, startsWith, - Statement, - StringLiteral, StringLiteralLike, StringLiteralType, Symbol, @@ -313,7 +269,6 @@ import { symbolName, SymbolTable, SyntaxKind, - SyntaxList, sys, tagNamesAreEquivalent, TextChange, @@ -328,14 +283,11 @@ import { timestamp, TodoComment, TodoCommentDescriptor, - Token, toPath, tracing, - TransformFlags, Type, TypeChecker, TypeFlags, - TypeNode, TypeParameter, TypePredicate, TypeReference, @@ -343,9 +295,7 @@ import { UnionOrIntersectionType, UnionType, updateSourceFile, - UserPreferences, - VariableDeclaration, -} from "./_namespaces/ts.js"; + UserPreferences} from "./_namespaces/ts.js"; import * as NavigateTo from "./_namespaces/ts.NavigateTo.js"; import * as NavigationBar from "./_namespaces/ts.NavigationBar.js"; import { @@ -359,298 +309,6 @@ import * as classifier2020 from "./classifier2020.js"; /** The version of the language service API */ export const servicesVersion = "0.8"; -function createNode(kind: TKind, pos: number, end: number, parent: Node): NodeObject | TokenObject | IdentifierObject | PrivateIdentifierObject { - const node = isNodeKind(kind) ? new NodeObject(kind, pos, end) : - kind === SyntaxKind.Identifier ? new IdentifierObject(SyntaxKind.Identifier, pos, end) : - kind === SyntaxKind.PrivateIdentifier ? new PrivateIdentifierObject(SyntaxKind.PrivateIdentifier, pos, end) : - new TokenObject(kind, pos, end); - node.parent = parent; - node.flags = parent.flags & NodeFlags.ContextFlags; - return node; -} - -class NodeObject implements Node { - public kind: TKind; - public pos: number; - public end: number; - public flags: NodeFlags; - public modifierFlagsCache: ModifierFlags; - public transformFlags: TransformFlags; - public parent: Node; - public symbol!: Symbol; // Actually optional, but it was too annoying to access `node.symbol!` everywhere since in many cases we know it must be defined - public jsDoc?: JSDoc[]; - public original?: Node; - public id?: number; - public emitNode?: EmitNode; - - constructor(kind: TKind, pos: number, end: number) { - // Note: if modifying this, be sure to update Node in src/compiler/utilities.ts - this.pos = pos; - this.end = end; - this.kind = kind; - this.id = 0; - this.flags = NodeFlags.None; - this.modifierFlagsCache = ModifierFlags.None; - this.transformFlags = TransformFlags.None; - this.parent = undefined!; - this.original = undefined; - this.emitNode = undefined; - } - - private assertHasRealPosition(message?: string) { - // eslint-disable-next-line local/debug-assert - Debug.assert(!positionIsSynthesized(this.pos) && !positionIsSynthesized(this.end), message || "Node must have a real position for this operation"); - } - - public getSourceFile(): SourceFile { - return getSourceFileOfNode(this); - } - - public getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number { - this.assertHasRealPosition(); - return getTokenPosOfNode(this, sourceFile, includeJsDocComment); - } - - public getFullStart(): number { - this.assertHasRealPosition(); - return this.pos; - } - - public getEnd(): number { - this.assertHasRealPosition(); - return this.end; - } - - public getWidth(sourceFile?: SourceFile): number { - this.assertHasRealPosition(); - return this.getEnd() - this.getStart(sourceFile); - } - - public getFullWidth(): number { - this.assertHasRealPosition(); - return this.end - this.pos; - } - - public getLeadingTriviaWidth(sourceFile?: SourceFile): number { - this.assertHasRealPosition(); - return this.getStart(sourceFile) - this.pos; - } - - public getFullText(sourceFile?: SourceFile): string { - this.assertHasRealPosition(); - return (sourceFile || this.getSourceFile()).text.substring(this.pos, this.end); - } - - public getText(sourceFile?: SourceFile): string { - this.assertHasRealPosition(); - if (!sourceFile) { - sourceFile = this.getSourceFile(); - } - return sourceFile.text.substring(this.getStart(sourceFile), this.getEnd()); - } - - public getChildCount(sourceFile?: SourceFile): number { - return this.getChildren(sourceFile).length; - } - - public getChildAt(index: number, sourceFile?: SourceFile): Node { - return this.getChildren(sourceFile)[index]; - } - - public getChildren(sourceFile: SourceFileLike = getSourceFileOfNode(this)): readonly Node[] { - this.assertHasRealPosition("Node without a real position cannot be scanned and thus has no token nodes - use forEachChild and collect the result if that's fine"); - return getNodeChildren(this, sourceFile) ?? setNodeChildren(this, sourceFile, createChildren(this, sourceFile)); - } - - public getFirstToken(sourceFile?: SourceFileLike): Node | undefined { - this.assertHasRealPosition(); - const children = this.getChildren(sourceFile); - if (!children.length) { - return undefined; - } - - const child = find(children, kid => kid.kind < SyntaxKind.FirstJSDocNode || kid.kind > SyntaxKind.LastJSDocNode)!; - return child.kind < SyntaxKind.FirstNode ? - child : - child.getFirstToken(sourceFile); - } - - public getLastToken(sourceFile?: SourceFileLike): Node | undefined { - this.assertHasRealPosition(); - const children = this.getChildren(sourceFile); - - const child = lastOrUndefined(children); - if (!child) { - return undefined; - } - - return child.kind < SyntaxKind.FirstNode ? child : child.getLastToken(sourceFile); - } - - public forEachChild(cbNode: (node: Node) => T, cbNodeArray?: (nodes: NodeArray) => T): T | undefined { - return forEachChild(this, cbNode, cbNodeArray); - } -} - -function createChildren(node: Node, sourceFile: SourceFileLike | undefined): readonly Node[] { - const children: Node[] = []; - - if (isJSDocCommentContainingNode(node)) { - /** Don't add trivia for "tokens" since this is in a comment. */ - node.forEachChild(child => { - children.push(child); - }); - return children; - } - - scanner.setText((sourceFile || node.getSourceFile()).text); - let pos = node.pos; - const processNode = (child: Node) => { - addSyntheticNodes(children, pos, child.pos, node); - children.push(child); - pos = child.end; - }; - const processNodes = (nodes: NodeArray) => { - addSyntheticNodes(children, pos, nodes.pos, node); - children.push(createSyntaxList(nodes, node)); - pos = nodes.end; - }; - // jsDocComments need to be the first children - forEach((node as JSDocContainer).jsDoc, processNode); - // For syntactic classifications, all trivia are classified together, including jsdoc comments. - // For that to work, the jsdoc comments should still be the leading trivia of the first child. - // Restoring the scanner position ensures that. - pos = node.pos; - node.forEachChild(processNode, processNodes); - addSyntheticNodes(children, pos, node.end, node); - scanner.setText(undefined); - return children; -} - -function addSyntheticNodes(nodes: Node[], pos: number, end: number, parent: Node): void { - scanner.resetTokenState(pos); - while (pos < end) { - const token = scanner.scan(); - const textPos = scanner.getTokenEnd(); - if (textPos <= end) { - if (token === SyntaxKind.Identifier) { - if (hasTabstop(parent)) { - continue; - } - Debug.fail(`Did not expect ${Debug.formatSyntaxKind(parent.kind)} to have an Identifier in its trivia`); - } - nodes.push(createNode(token, pos, textPos, parent)); - } - pos = textPos; - if (token === SyntaxKind.EndOfFileToken) { - break; - } - } -} - -function createSyntaxList(nodes: NodeArray, parent: Node): Node { - const list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, parent) as any as SyntaxList; - const children: Node[] = []; - let pos = nodes.pos; - for (const node of nodes) { - addSyntheticNodes(children, pos, node.pos, parent); - children.push(node); - pos = node.end; - } - addSyntheticNodes(children, pos, nodes.end, parent); - list._children = children; - return list; -} - -class TokenOrIdentifierObject implements Node { - public kind: TKind; - public pos: number; - public end: number; - public flags: NodeFlags; - public modifierFlagsCache!: ModifierFlags; - public transformFlags: TransformFlags; - public parent: Node; - public symbol!: Symbol; - public jsDocComments?: JSDoc[]; - public id?: number; - public emitNode?: EmitNode | undefined; - - constructor(kind: TKind, pos: number, end: number) { - // Note: if modifying this, be sure to update Token and Identifier in src/compiler/utilities.ts - this.pos = pos; - this.end = end; - this.kind = kind; - this.id = 0; - this.flags = NodeFlags.None; - this.transformFlags = TransformFlags.None; - this.parent = undefined!; - this.emitNode = undefined; - } - - public getSourceFile(): SourceFile { - return getSourceFileOfNode(this); - } - - public getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number { - return getTokenPosOfNode(this, sourceFile, includeJsDocComment); - } - - public getFullStart(): number { - return this.pos; - } - - public getEnd(): number { - return this.end; - } - - public getWidth(sourceFile?: SourceFile): number { - return this.getEnd() - this.getStart(sourceFile); - } - - public getFullWidth(): number { - return this.end - this.pos; - } - - public getLeadingTriviaWidth(sourceFile?: SourceFile): number { - return this.getStart(sourceFile) - this.pos; - } - - public getFullText(sourceFile?: SourceFile): string { - return (sourceFile || this.getSourceFile()).text.substring(this.pos, this.end); - } - - public getText(sourceFile?: SourceFile): string { - if (!sourceFile) { - sourceFile = this.getSourceFile(); - } - return sourceFile.text.substring(this.getStart(sourceFile), this.getEnd()); - } - - public getChildCount(): number { - return this.getChildren().length; - } - - public getChildAt(index: number): Node { - return this.getChildren()[index]; - } - - public getChildren(): Node[] { - return this.kind === SyntaxKind.EndOfFileToken ? (this as Node as EndOfFileToken).jsDoc || emptyArray : emptyArray; - } - - public getFirstToken(): Node | undefined { - return undefined; - } - - public getLastToken(): Node | undefined { - return undefined; - } - - public forEachChild(): T | undefined { - return undefined; - } -} - class SymbolObject implements Symbol { flags: SymbolFlags; escapedName: __String; @@ -785,50 +443,6 @@ class SymbolObject implements Symbol { } } -class TokenObject extends TokenOrIdentifierObject implements Token { - constructor(kind: TKind, pos: number, end: number) { - super(kind, pos, end); - } -} - -class IdentifierObject extends TokenOrIdentifierObject implements Identifier { - public escapedText!: __String; - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - typeArguments!: NodeArray; - constructor(kind: SyntaxKind.Identifier, pos: number, end: number) { - super(kind, pos, end); - } - - get text(): string { - return idText(this); - } -} - -class PrivateIdentifierObject extends TokenOrIdentifierObject implements PrivateIdentifier { - public escapedText!: __String; - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - constructor(kind: SyntaxKind.PrivateIdentifier, pos: number, end: number) { - super(kind, pos, end); - } - - get text(): string { - return idText(this); - } -} - class TypeObject implements Type { checker: TypeChecker; flags: TypeFlags; @@ -1051,250 +665,6 @@ function findBaseOfDeclaration(checker: TypeChecker, declaration: Declaration }); } -class SourceFileObject extends NodeObject implements SourceFile { - declare _declarationBrand: any; - declare _localsContainerBrand: any; - public fileName!: string; - public path!: Path; - public resolvedPath!: Path; - public originalFileName!: string; - public text!: string; - public scriptSnapshot!: IScriptSnapshot; - public lineMap!: readonly number[]; - - public statements!: NodeArray; - public endOfFileToken!: Token; - - public amdDependencies!: { name: string; path: string; }[]; - public moduleName!: string; - public referencedFiles!: FileReference[]; - public typeReferenceDirectives!: FileReference[]; - public libReferenceDirectives!: FileReference[]; - - public syntacticDiagnostics!: DiagnosticWithLocation[]; - public parseDiagnostics!: DiagnosticWithLocation[]; - public bindDiagnostics!: DiagnosticWithLocation[]; - public bindSuggestionDiagnostics?: DiagnosticWithLocation[]; - - public isDeclarationFile!: boolean; - public isDefaultLib!: boolean; - public hasNoDefaultLib!: boolean; - public externalModuleIndicator!: Node; // The first node that causes this file to be an external module - public commonJsModuleIndicator!: Node; // The first node that causes this file to be a CommonJS module - public nodeCount!: number; - public identifierCount!: number; - public symbolCount!: number; - public version!: string; - public scriptKind!: ScriptKind; - public languageVersion!: ScriptTarget; - public languageVariant!: LanguageVariant; - public identifiers!: Map; - public nameTable: Map<__String, number> | undefined; - public imports!: readonly StringLiteralLike[]; - public moduleAugmentations!: StringLiteral[]; - private namedDeclarations: Map | undefined; - public ambientModuleNames!: string[]; - public checkJsDirective: CheckJsDirective | undefined; - public errorExpectations: TextRange[] | undefined; - public possiblyContainDynamicImport?: boolean; - public pragmas!: PragmaMap; - public localJsxFactory: EntityName | undefined; - public localJsxNamespace: __String | undefined; - - constructor(kind: SyntaxKind.SourceFile, pos: number, end: number) { - super(kind, pos, end); - } - - public update(newText: string, textChangeRange: TextChangeRange): SourceFile { - return updateSourceFile(this, newText, textChangeRange); - } - - public getLineAndCharacterOfPosition(position: number): LineAndCharacter { - return getLineAndCharacterOfPosition(this, position); - } - - public getLineStarts(): readonly number[] { - return getLineStarts(this); - } - - public getPositionOfLineAndCharacter(line: number, character: number, allowEdits?: true): number { - return computePositionOfLineAndCharacter(getLineStarts(this), line, character, this.text, allowEdits); - } - - public getLineEndOfPosition(pos: number): number { - const { line } = this.getLineAndCharacterOfPosition(pos); - const lineStarts = this.getLineStarts(); - - let lastCharPos: number | undefined; - if (line + 1 >= lineStarts.length) { - lastCharPos = this.getEnd(); - } - if (!lastCharPos) { - lastCharPos = lineStarts[line + 1] - 1; - } - - const fullText = this.getFullText(); - // if the new line is "\r\n", we should return the last non-new-line-character position - return fullText[lastCharPos] === "\n" && fullText[lastCharPos - 1] === "\r" ? lastCharPos - 1 : lastCharPos; - } - - public getNamedDeclarations(): Map { - if (!this.namedDeclarations) { - this.namedDeclarations = this.computeNamedDeclarations(); - } - - return this.namedDeclarations; - } - - private computeNamedDeclarations(): Map { - const result = createMultiMap(); - - this.forEachChild(visit); - - return result; - - function addDeclaration(declaration: Declaration) { - const name = getDeclarationName(declaration); - if (name) { - result.add(name, declaration); - } - } - - function getDeclarations(name: string) { - let declarations = result.get(name); - if (!declarations) { - result.set(name, declarations = []); - } - return declarations; - } - - function getDeclarationName(declaration: Declaration) { - const name = getNonAssignedNameOfDeclaration(declaration); - return name && (isComputedPropertyName(name) && isPropertyAccessExpression(name.expression) ? name.expression.name.text - : isPropertyName(name) ? getNameFromPropertyName(name) : undefined); - } - - function visit(node: Node): void { - switch (node.kind) { - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.FunctionExpression: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - const functionDeclaration = node as FunctionLikeDeclaration; - const declarationName = getDeclarationName(functionDeclaration); - - if (declarationName) { - const declarations = getDeclarations(declarationName); - const lastDeclaration = lastOrUndefined(declarations); - - // Check whether this declaration belongs to an "overload group". - if (lastDeclaration && functionDeclaration.parent === lastDeclaration.parent && functionDeclaration.symbol === lastDeclaration.symbol) { - // Overwrite the last declaration if it was an overload - // and this one is an implementation. - if (functionDeclaration.body && !(lastDeclaration as FunctionLikeDeclaration).body) { - declarations[declarations.length - 1] = functionDeclaration; - } - } - else { - declarations.push(functionDeclaration); - } - } - forEachChild(node, visit); - break; - - case SyntaxKind.ClassDeclaration: - case SyntaxKind.ClassExpression: - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.TypeAliasDeclaration: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.ModuleDeclaration: - case SyntaxKind.ImportEqualsDeclaration: - case SyntaxKind.ExportSpecifier: - case SyntaxKind.ImportSpecifier: - case SyntaxKind.ImportClause: - case SyntaxKind.NamespaceImport: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.TypeLiteral: - addDeclaration(node as Declaration); - forEachChild(node, visit); - break; - - case SyntaxKind.Parameter: - // Only consider parameter properties - if (!hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) { - break; - } - // falls through - - case SyntaxKind.VariableDeclaration: - case SyntaxKind.BindingElement: { - const decl = node as VariableDeclaration; - if (isBindingPattern(decl.name)) { - forEachChild(decl.name, visit); - break; - } - if (decl.initializer) { - visit(decl.initializer); - } - } - // falls through - case SyntaxKind.EnumMember: - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - addDeclaration(node as Declaration); - break; - - case SyntaxKind.ExportDeclaration: - // Handle named exports case e.g.: - // export {a, b as B} from "mod"; - const exportDeclaration = node as ExportDeclaration; - if (exportDeclaration.exportClause) { - if (isNamedExports(exportDeclaration.exportClause)) { - forEach(exportDeclaration.exportClause.elements, visit); - } - else { - visit(exportDeclaration.exportClause.name); - } - } - break; - - case SyntaxKind.ImportDeclaration: - const importClause = (node as ImportDeclaration).importClause; - if (importClause) { - // Handle default import case e.g.: - // import d from "mod"; - if (importClause.name) { - addDeclaration(importClause.name); - } - - // Handle named bindings in imports e.g.: - // import * as NS from "mod"; - // import {a, b as B} from "mod"; - if (importClause.namedBindings) { - if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - addDeclaration(importClause.namedBindings); - } - else { - forEach(importClause.namedBindings.elements, visit); - } - } - } - break; - - case SyntaxKind.BinaryExpression: - if (getAssignmentDeclarationKind(node as BinaryExpression) !== AssignmentDeclarationKind.None) { - addDeclaration(node as BinaryExpression); - } - // falls through - - default: - forEachChild(node, visit); - } - } - } -} - class SourceMapSourceObject implements SourceMapSource { fileName: string; text: string; @@ -1315,12 +685,6 @@ class SourceMapSourceObject implements SourceMapSource { function getServicesObjectAllocator(): ObjectAllocator { return { - getNodeConstructor: () => NodeObject, - getTokenConstructor: () => TokenObject, - - getIdentifierConstructor: () => IdentifierObject, - getPrivateIdentifierConstructor: () => PrivateIdentifierObject, - getSourceFileConstructor: () => SourceFileObject, getSymbolConstructor: () => SymbolObject, getTypeConstructor: () => TypeObject, getSignatureConstructor: () => SignatureObject, diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index b02caba811bc0..7a38b4d63c4cb 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -1,6 +1,7 @@ import { addToSeen, ArrowFunction, + ast, BindingElement, CharacterCodes, ClassElement, @@ -1376,7 +1377,6 @@ const textChangesTransformationContext: TransformationContext = { ...nullTransformationContext, factory: createNodeFactory( nullTransformationContext.factory.flags | NodeFactoryFlags.NoParenthesizerRules, - nullTransformationContext.factory.baseFactory, ), }; @@ -1384,7 +1384,7 @@ const textChangesTransformationContext: TransformationContext = { export function assignPositionsToNode(node: Node): Node { const visited = visitEachChild(node, assignPositionsToNode, textChangesTransformationContext, assignPositionsToNodeArray, assignPositionsToNode); // create proxy node for non synthesized nodes - const newNode = nodeIsSynthesized(visited) ? visited : Object.create(visited) as Node; + const newNode = nodeIsSynthesized(visited) ? visited : (visited as ast.Node).ast.shadow().node; setTextRangePosEnd(newNode, getPos(node), getEnd(node)); return newNode; } diff --git a/src/testRunner/unittests/helpers.ts b/src/testRunner/unittests/helpers.ts index 026fdf7df5428..87dfc99133ec9 100644 --- a/src/testRunner/unittests/helpers.ts +++ b/src/testRunner/unittests/helpers.ts @@ -97,7 +97,8 @@ export class SourceText implements ts.IScriptSnapshot { } function createSourceFileWithText(fileName: string, sourceText: SourceText, target: ts.ScriptTarget) { - const file = ts.createSourceFile(fileName, sourceText.getFullText(), target) as SourceFileWithText; + // TODO: Avoid introducing a new V8 map here + const file = Object.create(ts.createSourceFile(fileName, sourceText.getFullText(), target)) as SourceFileWithText; file.sourceText = sourceText; file.version = "" + sourceText.getVersion(); return file; diff --git a/src/testRunner/unittests/jsDocParsing.ts b/src/testRunner/unittests/jsDocParsing.ts index 546bffaa777e1..de5810e7f3dff 100644 --- a/src/testRunner/unittests/jsDocParsing.ts +++ b/src/testRunner/unittests/jsDocParsing.ts @@ -98,7 +98,7 @@ describe("unittests:: JSDocParsing", () => { ts.Debug.fail("Comment has at least one diagnostic: " + comment.diagnostics[0].messageText); } - Harness.Baseline.runBaseline("JSDocParsing/DocComments.parsesCorrectly." + name + ".json", JSON.stringify(comment.jsDoc, (_, v) => v && v.pos !== undefined ? JSON.parse(Utils.sourceFileToJSON(v)) : v, 4)); + Harness.Baseline.runBaseline("JSDocParsing/DocComments.parsesCorrectly." + name + ".json", Utils.sourceFileToJSON(comment.jsDoc)); }); } diff --git a/src/testRunner/unittests/transform.ts b/src/testRunner/unittests/transform.ts index 4c4f84790ea63..ca7a051cd2a32 100644 --- a/src/testRunner/unittests/transform.ts +++ b/src/testRunner/unittests/transform.ts @@ -264,7 +264,7 @@ describe("unittests:: TransformAPI", () => { const result = ts.factory.updateSourceFile( sourceFile, ts.factory.createNodeArray([ - ts.factory.createClassDeclaration(/*modifiers*/ undefined, "Foo", /*typeParameters*/ undefined, /*heritageClauses*/ undefined, /*members*/ undefined!), // TODO: GH#18217 + ts.factory.createClassDeclaration(/*modifiers*/ undefined, "Foo", /*typeParameters*/ undefined, /*heritageClauses*/ undefined, []), ts.factory.createModuleDeclaration(/*modifiers*/ undefined, ts.factory.createIdentifier("Foo"), ts.factory.createModuleBlock([ts.factory.createEmptyStatement()])), ]), ); diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@@ does not start a new tag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@@ does not start a new tag.json index 43eda754b033f..b78beedf6118c 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@@ does not start a new tag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@@ does not start a new tag.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 7, "end": 52, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 8, "end": 13, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -24,6 +26,7 @@ "kind": "Identifier", "pos": 14, "end": 18, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "this" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@link tags.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@link tags.json index 3c8c7deed7ca5..0b04453b8c865 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@link tags.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@link tags.json @@ -10,6 +10,7 @@ "kind": "JSDocText", "pos": 0, "end": 7, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "" @@ -18,12 +19,14 @@ "kind": "JSDocLink", "pos": 7, "end": 21, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "name": { "kind": "Identifier", "pos": 14, "end": 19, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "first" }, @@ -33,6 +36,7 @@ "kind": "JSDocText", "pos": 21, "end": 32, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "\nInside " @@ -41,12 +45,14 @@ "kind": "JSDocLink", "pos": 32, "end": 49, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "name": { "kind": "Identifier", "pos": 39, "end": 43, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "link" }, @@ -56,6 +62,7 @@ "kind": "JSDocText", "pos": 49, "end": 59, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": " thing" @@ -71,12 +78,14 @@ "kind": "JSDocParameterTag", "pos": 59, "end": 102, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 60, "end": 65, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -85,6 +94,7 @@ "kind": "JSDocText", "pos": 70, "end": 79, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "See also " @@ -93,18 +103,21 @@ "kind": "JSDocLink", "pos": 79, "end": 98, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "name": { "kind": "QualifiedName", "pos": 86, "end": 97, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "left": { "kind": "Identifier", "pos": 86, "end": 87, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "A" }, @@ -112,6 +125,7 @@ "kind": "Identifier", "pos": 88, "end": 97, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "Reference" } @@ -128,6 +142,7 @@ "kind": "Identifier", "pos": 66, "end": 69, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "foo" }, @@ -138,12 +153,14 @@ "kind": "JSDocParameterTag", "pos": 102, "end": 589, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 103, "end": 108, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -152,6 +169,7 @@ "kind": "JSDocText", "pos": 113, "end": 120, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "Or see " @@ -160,12 +178,14 @@ "kind": "JSDocLink", "pos": 120, "end": 152, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "name": { "kind": "Identifier", "pos": 127, "end": 131, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "http" }, @@ -175,6 +195,7 @@ "kind": "JSDocText", "pos": 152, "end": 156, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "\n" @@ -183,18 +204,21 @@ "kind": "JSDocLink", "pos": 156, "end": 183, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "name": { "kind": "QualifiedName", "pos": 163, "end": 181, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "left": { "kind": "Identifier", "pos": 163, "end": 173, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "Standalone" }, @@ -202,6 +226,7 @@ "kind": "Identifier", "pos": 174, "end": 181, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "Complex" } @@ -212,6 +237,7 @@ "kind": "JSDocText", "pos": 183, "end": 203, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "\nThis empty one: " @@ -220,6 +246,7 @@ "kind": "JSDocLink", "pos": 203, "end": 210, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "" @@ -228,6 +255,7 @@ "kind": "JSDocText", "pos": 210, "end": 244, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": " is OK.\nThis double-space one: " @@ -236,12 +264,14 @@ "kind": "JSDocLink", "pos": 244, "end": 262, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "name": { "kind": "Identifier", "pos": 252, "end": 259, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "doubled" }, @@ -251,6 +281,7 @@ "kind": "JSDocText", "pos": 262, "end": 326, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": " is OK too.\nThis should work, despite being badly formatted: " @@ -259,18 +290,21 @@ "kind": "JSDocLink", "pos": 326, "end": 340, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "name": { "kind": "QualifiedName", "pos": 333, "end": 338, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "left": { "kind": "Identifier", "pos": 333, "end": 335, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "oh" }, @@ -278,6 +312,7 @@ "kind": "Identifier", "pos": 336, "end": 338, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "no" } @@ -288,6 +323,7 @@ "kind": "JSDocText", "pos": 340, "end": 369, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "\nForgot to close this one " @@ -296,12 +332,14 @@ "kind": "JSDocLink", "pos": 369, "end": 403, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "name": { "kind": "Identifier", "pos": 376, "end": 381, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "https" }, @@ -311,6 +349,7 @@ "kind": "JSDocText", "pos": 403, "end": 526, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": " * But it's still OK.\nAlthough it skips the newline so parses the asterisks in the wrong state.\nThis shouldn't work: " @@ -319,6 +358,7 @@ "kind": "JSDocLink", "pos": 526, "end": 541, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "* nope" @@ -327,6 +367,7 @@ "kind": "JSDocText", "pos": 541, "end": 589, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": " * }, because of the intermediate asterisks." @@ -341,6 +382,7 @@ "kind": "Identifier", "pos": 109, "end": 112, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "bar" }, @@ -351,12 +393,14 @@ "kind": "JSDocAuthorTag", "pos": 589, "end": 672, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 590, "end": 596, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -365,6 +409,7 @@ "kind": "JSDocText", "pos": 597, "end": 624, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "Alfa Romero " @@ -373,6 +418,7 @@ "kind": "JSDocText", "pos": 624, "end": 643, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": " See my home page: " @@ -381,12 +427,14 @@ "kind": "JSDocLink", "pos": 643, "end": 670, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "name": { "kind": "Identifier", "pos": 650, "end": 655, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "https" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Chained tags, no leading whitespace.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Chained tags, no leading whitespace.json index 63235aa838560..61e6dcc589004 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Chained tags, no leading whitespace.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Chained tags, no leading whitespace.json @@ -10,12 +10,14 @@ "kind": "JSDocTag", "pos": 3, "end": 6, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 4, "end": 5, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "a" } @@ -24,12 +26,14 @@ "kind": "JSDocTag", "pos": 6, "end": 9, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 7, "end": 8, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "b" } @@ -38,12 +42,14 @@ "kind": "JSDocTag", "pos": 9, "end": 11, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 10, "end": 11, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "c" } @@ -52,12 +58,14 @@ "kind": "JSDocTag", "pos": 11, "end": 13, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 12, "end": 13, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "d" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star space is not a tag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star space is not a tag.json index 894e629dcec29..2b6d8ffdf1fd1 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star space is not a tag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star space is not a tag.json @@ -11,12 +11,14 @@ "kind": "JSDocTag", "pos": 5, "end": 7, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 6, "end": 7, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "a" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Nested @param tags.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Nested @param tags.json index 841f9518ce91b..bfddae2b4aab4 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Nested @param tags.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Nested @param tags.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 6, "end": 64, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 7, "end": 12, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -24,12 +26,14 @@ "kind": "JSDocTypeExpression", "pos": 34, "end": 64, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "JSDocTypeLiteral", "pos": 34, "end": 64, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "jsDocPropertyTags": { @@ -37,12 +41,14 @@ "kind": "JSDocParameterTag", "pos": 34, "end": 64, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 35, "end": 40, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -51,12 +57,14 @@ "kind": "JSDocTypeExpression", "pos": 41, "end": 49, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "StringKeyword", "pos": 42, "end": 48, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -64,12 +72,14 @@ "kind": "QualifiedName", "pos": 50, "end": 53, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "left": { "kind": "Identifier", "pos": 50, "end": 51, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "o" }, @@ -77,6 +87,7 @@ "kind": "Identifier", "pos": 52, "end": 53, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "f" } @@ -97,6 +108,7 @@ "kind": "Identifier", "pos": 22, "end": 23, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "o" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.argSynonymForParamTag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.argSynonymForParamTag.json index 43a7e2c42cea4..8200b565586f4 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.argSynonymForParamTag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.argSynonymForParamTag.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 8, "end": 42, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 12, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "arg" }, @@ -24,12 +26,14 @@ "kind": "JSDocTypeExpression", "pos": 13, "end": 21, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 14, "end": 20, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -37,6 +41,7 @@ "kind": "Identifier", "pos": 22, "end": 27, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name1" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.argumentSynonymForParamTag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.argumentSynonymForParamTag.json index ea59b9c0597a4..28865907023f8 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.argumentSynonymForParamTag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.argumentSynonymForParamTag.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 8, "end": 47, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 17, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "argument" }, @@ -24,12 +26,14 @@ "kind": "JSDocTypeExpression", "pos": 18, "end": 26, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 19, "end": 25, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -37,6 +41,7 @@ "kind": "Identifier", "pos": 27, "end": 32, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name1" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.asteriskAfterPreamble.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.asteriskAfterPreamble.json index 1339748599cc5..47e5da8327af9 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.asteriskAfterPreamble.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.asteriskAfterPreamble.json @@ -11,12 +11,14 @@ "kind": "JSDocTypeTag", "pos": 6, "end": 21, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 7, "end": 11, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "type" }, @@ -24,12 +26,14 @@ "kind": "JSDocTypeExpression", "pos": 12, "end": 20, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 13, "end": 19, + "flags": "JSDoc", "transformFlags": 1 } } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.authorTag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.authorTag.json index 535a5d4eda7e1..ff56dc4ecb864 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.authorTag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.authorTag.json @@ -10,12 +10,14 @@ "kind": "JSDocAuthorTag", "pos": 7, "end": 50, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 8, "end": 14, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -24,6 +26,7 @@ "kind": "JSDocText", "pos": 15, "end": 50, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "John Doe " @@ -39,12 +42,14 @@ "kind": "JSDocAuthorTag", "pos": 50, "end": 112, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 51, "end": 57, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -54,12 +59,14 @@ "kind": "JSDocAuthorTag", "pos": 112, "end": 170, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 113, "end": 119, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -69,12 +76,14 @@ "kind": "JSDocAuthorTag", "pos": 170, "end": 227, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 171, "end": 177, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -83,6 +92,7 @@ "kind": "JSDocText", "pos": 178, "end": 227, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "Multiple Ats " @@ -98,12 +108,14 @@ "kind": "JSDocAuthorTag", "pos": 227, "end": 272, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 228, "end": 234, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -112,6 +124,7 @@ "kind": "JSDocText", "pos": 235, "end": 272, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "Multiple Open Carets " @@ -127,12 +140,14 @@ "kind": "JSDocAuthorTag", "pos": 272, "end": 338, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 273, "end": 279, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -142,12 +157,14 @@ "kind": "JSDocAuthorTag", "pos": 338, "end": 381, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 339, "end": 345, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -156,6 +173,7 @@ "kind": "JSDocText", "pos": 346, "end": 381, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "Unclosed Carets " @@ -229,12 +253,14 @@ "kind": "JSDocAuthorTag", "pos": 429, "end": 445, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 430, "end": 436, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -243,6 +269,7 @@ "kind": "JSDocText", "pos": 437, "end": 445, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "Line" @@ -258,12 +285,14 @@ "kind": "JSDocAuthorTag", "pos": 445, "end": 453, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 446, "end": 452, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -272,6 +301,7 @@ "kind": "JSDocText", "pos": 453, "end": 453, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "" @@ -287,12 +317,14 @@ "kind": "JSDocAuthorTag", "pos": 453, "end": 461, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 454, "end": 460, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -301,6 +333,7 @@ "kind": "JSDocText", "pos": 461, "end": 461, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "" @@ -316,12 +349,14 @@ "kind": "JSDocAuthorTag", "pos": 461, "end": 486, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 462, "end": 468, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -330,6 +365,7 @@ "kind": "JSDocText", "pos": 469, "end": 486, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "Empty authors" @@ -345,12 +381,14 @@ "kind": "JSDocAuthorTag", "pos": 486, "end": 497, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 487, "end": 493, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -359,6 +397,7 @@ "kind": "JSDocText", "pos": 497, "end": 497, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "" @@ -374,12 +413,14 @@ "kind": "JSDocAuthorTag", "pos": 497, "end": 522, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 498, "end": 504, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -388,6 +429,7 @@ "kind": "JSDocText", "pos": 510, "end": 522, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "Comments" @@ -403,12 +445,14 @@ "kind": "JSDocAuthorTag", "pos": 522, "end": 559, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 523, "end": 529, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -417,6 +461,7 @@ "kind": "JSDocText", "pos": 530, "end": 559, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "Early Close Caret > " @@ -432,12 +477,14 @@ "kind": "JSDocAuthorTag", "pos": 559, "end": 599, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 560, "end": 566, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, @@ -447,12 +494,14 @@ "kind": "JSDocTag", "pos": 599, "end": 646, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 600, "end": 607, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "address" }, @@ -462,12 +511,14 @@ "kind": "JSDocAuthorTag", "pos": 646, "end": 737, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 647, "end": 653, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "author" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.consecutive newline tokens.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.consecutive newline tokens.json index 33f14ebd36287..8323451a29e13 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.consecutive newline tokens.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.consecutive newline tokens.json @@ -10,12 +10,14 @@ "kind": "JSDocTag", "pos": 7, "end": 53, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 8, "end": 15, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "example" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.exceptionTag1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.exceptionTag1.json index 8793504cc40a5..f12f0328098fe 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.exceptionTag1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.exceptionTag1.json @@ -10,12 +10,14 @@ "kind": "JSDocThrowsTag", "pos": 8, "end": 29, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 18, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "exception" }, @@ -23,18 +25,21 @@ "kind": "JSDocTypeExpression", "pos": 19, "end": 26, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "TypeReference", "pos": 20, "end": 25, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "typeName": { "kind": "Identifier", "pos": 20, "end": 25, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "Error" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.exceptionTag2.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.exceptionTag2.json index 0226b44843ac7..aeb24ee8eed84 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.exceptionTag2.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.exceptionTag2.json @@ -10,12 +10,14 @@ "kind": "JSDocThrowsTag", "pos": 8, "end": 43, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 18, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "exception" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.exceptionTag3.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.exceptionTag3.json index a13a8a64c3548..2b3d7ff83e7d4 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.exceptionTag3.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.exceptionTag3.json @@ -10,12 +10,14 @@ "kind": "JSDocThrowsTag", "pos": 8, "end": 41, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 18, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "exception" }, @@ -24,18 +26,21 @@ "kind": "JSDocTypeExpression", "pos": 19, "end": 26, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "TypeReference", "pos": 20, "end": 25, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "typeName": { "kind": "Identifier", "pos": 20, "end": 25, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "Error" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag1.json index 817598cb1e86e..601d38bc49459 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag1.json @@ -10,12 +10,14 @@ "kind": "JSDocImportTag", "pos": 8, "end": 30, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 15, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "import" }, @@ -23,6 +25,7 @@ "kind": "ImportClause", "pos": 16, "end": 19, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "isTypeOnly": true, @@ -30,6 +33,7 @@ "kind": "Identifier", "pos": 16, "end": 19, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "foo" } @@ -38,6 +42,7 @@ "kind": "StringLiteral", "pos": 24, "end": 30, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "foo" diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag2.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag2.json index d11fa4eb24320..30194e2cd1393 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag2.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag2.json @@ -10,12 +10,14 @@ "kind": "JSDocImportTag", "pos": 8, "end": 34, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 15, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "import" }, @@ -23,6 +25,7 @@ "kind": "ImportClause", "pos": 16, "end": 23, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "isTypeOnly": true, @@ -30,6 +33,7 @@ "kind": "NamedImports", "pos": 16, "end": 23, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "elements": { @@ -37,13 +41,14 @@ "kind": "ImportSpecifier", "pos": 17, "end": 21, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, - "isTypeOnly": false, "name": { "kind": "Identifier", "pos": 17, "end": 21, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "foo" } @@ -60,6 +65,7 @@ "kind": "StringLiteral", "pos": 28, "end": 34, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "foo" diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag3.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag3.json index a34c07e9983a9..839d5f7513514 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag3.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag3.json @@ -10,12 +10,14 @@ "kind": "JSDocImportTag", "pos": 8, "end": 37, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 15, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "import" }, @@ -23,6 +25,7 @@ "kind": "ImportClause", "pos": 16, "end": 26, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "isTypeOnly": true, @@ -30,12 +33,14 @@ "kind": "NamespaceImport", "pos": 16, "end": 26, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "name": { "kind": "Identifier", "pos": 20, "end": 26, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "types" } @@ -45,6 +50,7 @@ "kind": "StringLiteral", "pos": 31, "end": 37, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "foo" diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag4.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag4.json index e60e392ffb8eb..7abd3315ba179 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag4.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag4.json @@ -10,12 +10,14 @@ "kind": "JSDocImportTag", "pos": 8, "end": 53, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 15, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "import" }, @@ -24,6 +26,7 @@ "kind": "ImportClause", "pos": 16, "end": 26, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "isTypeOnly": true, @@ -31,12 +34,14 @@ "kind": "NamespaceImport", "pos": 16, "end": 26, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "name": { "kind": "Identifier", "pos": 20, "end": 26, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "types" } @@ -46,6 +51,7 @@ "kind": "StringLiteral", "pos": 31, "end": 37, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "text": "foo" diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.leadingAsterisk.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.leadingAsterisk.json index 97a20f5e74726..1518325672db4 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.leadingAsterisk.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.leadingAsterisk.json @@ -10,12 +10,14 @@ "kind": "JSDocTypeTag", "pos": 8, "end": 25, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 13, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "type" }, @@ -23,12 +25,14 @@ "kind": "JSDocTypeExpression", "pos": 14, "end": 22, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 15, "end": 21, + "flags": "JSDoc", "transformFlags": 1 } } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.less-than and greater-than characters.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.less-than and greater-than characters.json index a78806d2b35f3..381586eac5829 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.less-than and greater-than characters.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.less-than and greater-than characters.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 7, "end": 59, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 8, "end": 13, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -24,6 +26,7 @@ "kind": "Identifier", "pos": 14, "end": 15, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "x" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.no space before @ is not a new tag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.no space before @ is not a new tag.json index 59070fd2c0fdc..088129ebd040a 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.no space before @ is not a new tag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.no space before @ is not a new tag.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 7, "end": 29, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 8, "end": 13, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -24,6 +26,7 @@ "kind": "Identifier", "pos": 14, "end": 18, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "this" }, @@ -34,12 +37,14 @@ "kind": "JSDocParameterTag", "pos": 29, "end": 50, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 30, "end": 35, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -48,6 +53,7 @@ "kind": "Identifier", "pos": 36, "end": 40, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "fine" }, @@ -58,12 +64,14 @@ "kind": "JSDocTag", "pos": 50, "end": 62, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 51, "end": 60, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "zerowidth" } @@ -72,12 +80,14 @@ "kind": "JSDocTag", "pos": 62, "end": 89, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 63, "end": 73, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "singlestar" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noLeadingAsterisk.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noLeadingAsterisk.json index 97a20f5e74726..1518325672db4 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noLeadingAsterisk.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noLeadingAsterisk.json @@ -10,12 +10,14 @@ "kind": "JSDocTypeTag", "pos": 8, "end": 25, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 13, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "type" }, @@ -23,12 +25,14 @@ "kind": "JSDocTypeExpression", "pos": 14, "end": 22, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 15, "end": 21, + "flags": "JSDoc", "transformFlags": 1 } } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noReturnType.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noReturnType.json index 018ca969d65ef..0d73fee6627c5 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noReturnType.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noReturnType.json @@ -10,12 +10,14 @@ "kind": "JSDocReturnTag", "pos": 8, "end": 18, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 15, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "return" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.oneParamTag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.oneParamTag.json index 25d525efd7f8a..34064ad8c7087 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.oneParamTag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.oneParamTag.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 8, "end": 32, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 14, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -23,12 +25,14 @@ "kind": "JSDocTypeExpression", "pos": 15, "end": 23, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 16, "end": 22, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -36,6 +40,7 @@ "kind": "Identifier", "pos": 24, "end": 29, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name1" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTag1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTag1.json index 734e99b221f30..e8a9913fcdd34 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTag1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTag1.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 8, "end": 57, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 14, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -24,12 +26,14 @@ "kind": "JSDocTypeExpression", "pos": 15, "end": 23, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 16, "end": 22, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -37,6 +41,7 @@ "kind": "Identifier", "pos": 24, "end": 29, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name1" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagBracketedName1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagBracketedName1.json index 8a9e7fb352a3f..db8b881a2aa6e 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagBracketedName1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagBracketedName1.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 8, "end": 59, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 14, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -24,12 +26,14 @@ "kind": "JSDocTypeExpression", "pos": 15, "end": 23, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 16, "end": 22, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -37,6 +41,7 @@ "kind": "Identifier", "pos": 25, "end": 30, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name1" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagBracketedName2.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagBracketedName2.json index 020b0d9437b72..2ebed7bb87c2f 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagBracketedName2.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagBracketedName2.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 8, "end": 64, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 14, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -24,12 +26,14 @@ "kind": "JSDocTypeExpression", "pos": 15, "end": 23, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 16, "end": 22, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -37,6 +41,7 @@ "kind": "Identifier", "pos": 26, "end": 31, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name1" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType1.json index a4ae7884303dc..cde9783cb7368 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType1.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 8, "end": 32, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 14, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -23,12 +25,14 @@ "kind": "JSDocTypeExpression", "pos": 21, "end": 29, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 22, "end": 28, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -36,6 +40,7 @@ "kind": "Identifier", "pos": 15, "end": 20, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name1" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType2.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType2.json index 29ed1f1a29aba..b4f717f759512 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType2.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType2.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 8, "end": 44, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 14, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -24,12 +26,14 @@ "kind": "JSDocTypeExpression", "pos": 21, "end": 29, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 22, "end": 28, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -37,6 +41,7 @@ "kind": "Identifier", "pos": 15, "end": 20, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name1" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramWithoutType.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramWithoutType.json index 132a4ef44e978..dd9700106866a 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramWithoutType.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramWithoutType.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 8, "end": 21, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 14, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -23,6 +25,7 @@ "kind": "Identifier", "pos": 15, "end": 18, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "foo" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnTag1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnTag1.json index d3951a55fac41..a9a6faa366604 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnTag1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnTag1.json @@ -10,12 +10,14 @@ "kind": "JSDocReturnTag", "pos": 8, "end": 27, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 15, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "return" }, @@ -23,12 +25,14 @@ "kind": "JSDocTypeExpression", "pos": 16, "end": 24, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 17, "end": 23, + "flags": "JSDoc", "transformFlags": 1 } } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnTag2.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnTag2.json index 5e7639ebc993c..8a189235b0b5a 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnTag2.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnTag2.json @@ -10,12 +10,14 @@ "kind": "JSDocReturnTag", "pos": 8, "end": 52, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 15, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "return" }, @@ -24,12 +26,14 @@ "kind": "JSDocTypeExpression", "pos": 16, "end": 24, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 17, "end": 23, + "flags": "JSDoc", "transformFlags": 1 } } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnsTag1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnsTag1.json index b405df418d610..d2f134d37aef2 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnsTag1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnsTag1.json @@ -10,12 +10,14 @@ "kind": "JSDocReturnTag", "pos": 8, "end": 28, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 16, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "returns" }, @@ -23,12 +25,14 @@ "kind": "JSDocTypeExpression", "pos": 17, "end": 25, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 18, "end": 24, + "flags": "JSDoc", "transformFlags": 1 } } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.satisfiesTag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.satisfiesTag.json index 5a5a5dfa77084..7c620d604e4a0 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.satisfiesTag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.satisfiesTag.json @@ -10,12 +10,14 @@ "kind": "JSDocSatisfiesTag", "pos": 8, "end": 30, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 18, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "satisfies" }, @@ -23,12 +25,14 @@ "kind": "JSDocTypeExpression", "pos": 19, "end": 27, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 20, "end": 26, + "flags": "JSDoc", "transformFlags": 1 } } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag.json index 468ab95cf8113..5ff0a60449a9b 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag.json @@ -10,12 +10,14 @@ "kind": "JSDocTemplateTag", "pos": 8, "end": 22, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 17, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "template" }, @@ -24,12 +26,14 @@ "kind": "TypeParameter", "pos": 18, "end": 19, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "name": { "kind": "Identifier", "pos": 18, "end": 19, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "T" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag2.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag2.json index 814468541c5d4..113b578faa210 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag2.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag2.json @@ -10,12 +10,14 @@ "kind": "JSDocTemplateTag", "pos": 8, "end": 24, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 17, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "template" }, @@ -24,12 +26,14 @@ "kind": "TypeParameter", "pos": 18, "end": 19, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "name": { "kind": "Identifier", "pos": 18, "end": 19, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "K" } @@ -38,12 +42,14 @@ "kind": "TypeParameter", "pos": 20, "end": 21, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "name": { "kind": "Identifier", "pos": 20, "end": 21, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "V" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag3.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag3.json index c8d415e13ed27..bbae96dd051fc 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag3.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag3.json @@ -10,12 +10,14 @@ "kind": "JSDocTemplateTag", "pos": 8, "end": 25, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 17, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "template" }, @@ -24,12 +26,14 @@ "kind": "TypeParameter", "pos": 18, "end": 19, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "name": { "kind": "Identifier", "pos": 18, "end": 19, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "K" } @@ -38,12 +42,14 @@ "kind": "TypeParameter", "pos": 21, "end": 22, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "name": { "kind": "Identifier", "pos": 21, "end": 22, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "V" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag4.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag4.json index c8d415e13ed27..bbae96dd051fc 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag4.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag4.json @@ -10,12 +10,14 @@ "kind": "JSDocTemplateTag", "pos": 8, "end": 25, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 17, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "template" }, @@ -24,12 +26,14 @@ "kind": "TypeParameter", "pos": 18, "end": 19, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "name": { "kind": "Identifier", "pos": 18, "end": 19, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "K" } @@ -38,12 +42,14 @@ "kind": "TypeParameter", "pos": 21, "end": 22, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "name": { "kind": "Identifier", "pos": 21, "end": 22, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "V" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag5.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag5.json index 516c270f81ae7..f83f14b0d777d 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag5.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag5.json @@ -10,12 +10,14 @@ "kind": "JSDocTemplateTag", "pos": 8, "end": 26, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 17, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "template" }, @@ -24,12 +26,14 @@ "kind": "TypeParameter", "pos": 18, "end": 19, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "name": { "kind": "Identifier", "pos": 18, "end": 19, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "K" } @@ -38,12 +42,14 @@ "kind": "TypeParameter", "pos": 22, "end": 23, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "name": { "kind": "Identifier", "pos": 22, "end": 23, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "V" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag6.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag6.json index 754b96d70281d..73e1139d00570 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag6.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag6.json @@ -10,12 +10,14 @@ "kind": "JSDocTemplateTag", "pos": 8, "end": 58, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 17, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "template" }, @@ -25,12 +27,14 @@ "kind": "TypeParameter", "pos": 18, "end": 19, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "name": { "kind": "Identifier", "pos": 18, "end": 19, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "K" } @@ -39,12 +43,14 @@ "kind": "TypeParameter", "pos": 22, "end": 23, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "name": { "kind": "Identifier", "pos": 22, "end": 23, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "V" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.throwsTag1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.throwsTag1.json index f1e04949611cd..6c836fbb879dc 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.throwsTag1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.throwsTag1.json @@ -10,12 +10,14 @@ "kind": "JSDocThrowsTag", "pos": 8, "end": 26, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 15, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "throws" }, @@ -23,18 +25,21 @@ "kind": "JSDocTypeExpression", "pos": 16, "end": 23, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "TypeReference", "pos": 17, "end": 22, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "typeName": { "kind": "Identifier", "pos": 17, "end": 22, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "Error" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.throwsTag2.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.throwsTag2.json index c57a789553db3..aa8e0fae177ee 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.throwsTag2.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.throwsTag2.json @@ -10,12 +10,14 @@ "kind": "JSDocThrowsTag", "pos": 8, "end": 40, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 15, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "throws" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.throwsTag3.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.throwsTag3.json index dc6e605dc95b1..d62a7dff93874 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.throwsTag3.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.throwsTag3.json @@ -10,12 +10,14 @@ "kind": "JSDocThrowsTag", "pos": 8, "end": 38, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 15, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "throws" }, @@ -24,18 +26,21 @@ "kind": "JSDocTypeExpression", "pos": 16, "end": 23, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "TypeReference", "pos": 17, "end": 22, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 1, "typeName": { "kind": "Identifier", "pos": 17, "end": 22, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "Error" } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTag2.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTag2.json index bb16558e5f9e6..61f545a36335e 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTag2.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTag2.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 8, "end": 34, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 14, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -23,12 +25,14 @@ "kind": "JSDocTypeExpression", "pos": 15, "end": 23, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 16, "end": 22, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -36,6 +40,7 @@ "kind": "Identifier", "pos": 24, "end": 29, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name1" }, @@ -46,12 +51,14 @@ "kind": "JSDocParameterTag", "pos": 34, "end": 58, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 35, "end": 40, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -59,12 +66,14 @@ "kind": "JSDocTypeExpression", "pos": 41, "end": 49, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 42, "end": 48, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -72,6 +81,7 @@ "kind": "Identifier", "pos": 50, "end": 55, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name2" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTagOnSameLine.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTagOnSameLine.json index a3b5ddaca61cc..7241cb09d2ca8 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTagOnSameLine.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTagOnSameLine.json @@ -10,12 +10,14 @@ "kind": "JSDocParameterTag", "pos": 8, "end": 30, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 14, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -23,12 +25,14 @@ "kind": "JSDocTypeExpression", "pos": 15, "end": 23, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 16, "end": 22, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -36,6 +40,7 @@ "kind": "Identifier", "pos": 24, "end": 29, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name1" }, @@ -46,12 +51,14 @@ "kind": "JSDocParameterTag", "pos": 30, "end": 54, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 31, "end": 36, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "param" }, @@ -59,12 +66,14 @@ "kind": "JSDocTypeExpression", "pos": 37, "end": 45, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 38, "end": 44, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -72,6 +81,7 @@ "kind": "Identifier", "pos": 46, "end": 51, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name2" }, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typeTag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typeTag.json index 97a20f5e74726..1518325672db4 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typeTag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typeTag.json @@ -10,12 +10,14 @@ "kind": "JSDocTypeTag", "pos": 8, "end": 25, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 13, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "type" }, @@ -23,12 +25,14 @@ "kind": "JSDocTypeExpression", "pos": 14, "end": 22, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 15, "end": 21, + "flags": "JSDoc", "transformFlags": 1 } } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typedefTagWithChildrenTags.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typedefTagWithChildrenTags.json index dff2bb63fa7c4..fbd6b938ca484 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typedefTagWithChildrenTags.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typedefTagWithChildrenTags.json @@ -10,12 +10,14 @@ "kind": "JSDocTypedefTag", "pos": 8, "end": 100, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 9, "end": 16, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "typedef" }, @@ -23,6 +25,7 @@ "kind": "JSDocTypeLiteral", "pos": 8, "end": 100, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "jsDocPropertyTags": { @@ -30,12 +33,14 @@ "kind": "JSDocPropertyTag", "pos": 47, "end": 74, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 48, "end": 56, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "property" }, @@ -43,12 +48,14 @@ "kind": "JSDocTypeExpression", "pos": 57, "end": 65, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "NumberKeyword", "pos": 58, "end": 64, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -56,6 +63,7 @@ "kind": "Identifier", "pos": 66, "end": 69, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "age" }, @@ -66,12 +74,14 @@ "kind": "JSDocPropertyTag", "pos": 74, "end": 100, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "tagName": { "kind": "Identifier", "pos": 75, "end": 83, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "property" }, @@ -79,12 +89,14 @@ "kind": "JSDocTypeExpression", "pos": 84, "end": 92, + "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, "type": { "kind": "StringKeyword", "pos": 85, "end": 91, + "flags": "JSDoc", "transformFlags": 1 } }, @@ -92,6 +104,7 @@ "kind": "Identifier", "pos": 93, "end": 97, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "name" }, @@ -110,6 +123,7 @@ "kind": "Identifier", "pos": 17, "end": 23, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "People" }, @@ -117,6 +131,7 @@ "kind": "Identifier", "pos": 17, "end": 23, + "flags": "JSDoc", "transformFlags": 0, "escapedText": "People" } diff --git a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionReturnType1.json b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionReturnType1.json index 3ec8a590dcdeb..3dd7042a82bc7 100644 --- a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionReturnType1.json +++ b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionReturnType1.json @@ -4,7 +4,7 @@ "end": 26, "flags": "JSDoc", "modifierFlagsCache": 0, - "transformFlags": 1, + "transformFlags": 0, "parameters": { "0": { "kind": "Parameter", diff --git a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionType2.json b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionType2.json index 3ec8a590dcdeb..3dd7042a82bc7 100644 --- a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionType2.json +++ b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionType2.json @@ -4,7 +4,7 @@ "end": 26, "flags": "JSDoc", "modifierFlagsCache": 0, - "transformFlags": 1, + "transformFlags": 0, "parameters": { "0": { "kind": "Parameter", diff --git a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionTypeWithTrailingComma.json b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionTypeWithTrailingComma.json index 9ee95f4db14bc..8bc259e9fa799 100644 --- a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionTypeWithTrailingComma.json +++ b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.functionTypeWithTrailingComma.json @@ -4,7 +4,7 @@ "end": 13, "flags": "JSDoc", "modifierFlagsCache": 0, - "transformFlags": 1, + "transformFlags": 0, "parameters": { "0": { "kind": "Parameter", diff --git a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.newType1.json b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.newType1.json index a2f84428ced0e..2cbcf1bbabafb 100644 --- a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.newType1.json +++ b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.newType1.json @@ -4,7 +4,7 @@ "end": 18, "flags": "JSDoc", "modifierFlagsCache": 0, - "transformFlags": 1, + "transformFlags": 0, "parameters": { "0": { "kind": "Parameter", diff --git a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.thisType1.json b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.thisType1.json index ddb591f737c63..ada67ee03ee18 100644 --- a/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.thisType1.json +++ b/tests/baselines/reference/JSDocParsing/TypeExpressions.parsesCorrectly.thisType1.json @@ -4,7 +4,7 @@ "end": 19, "flags": "JSDoc", "modifierFlagsCache": 0, - "transformFlags": 1, + "transformFlags": 0, "parameters": { "0": { "kind": "Parameter", diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index c8589f0b8ae9f..c67e9ea5a5260 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4169,7 +4169,7 @@ declare namespace ts { | SyntaxKind.YieldKeyword; type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AccessorKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.InKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OutKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.StaticKeyword; type KeywordTypeSyntaxKind = SyntaxKind.AnyKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VoidKeyword; - type TokenSyntaxKind = SyntaxKind.Unknown | SyntaxKind.EndOfFileToken | TriviaSyntaxKind | LiteralSyntaxKind | PseudoLiteralSyntaxKind | PunctuationSyntaxKind | SyntaxKind.Identifier | KeywordSyntaxKind; + type TokenSyntaxKind = SyntaxKind.Unknown | SyntaxKind.EndOfFileToken | TriviaSyntaxKind | LiteralSyntaxKind | PseudoLiteralSyntaxKind | PunctuationSyntaxKind | SyntaxKind.Identifier | SyntaxKind.PrivateIdentifier | KeywordSyntaxKind; type JsxTokenSyntaxKind = SyntaxKind.LessThanSlashToken | SyntaxKind.EndOfFileToken | SyntaxKind.ConflictMarkerTrivia | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.OpenBraceToken | SyntaxKind.LessThanToken; type JSDocSyntaxKind = SyntaxKind.EndOfFileToken | SyntaxKind.WhitespaceTrivia | SyntaxKind.AtToken | SyntaxKind.NewLineTrivia | SyntaxKind.AsteriskToken | SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.LessThanToken | SyntaxKind.GreaterThanToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.OpenParenToken | SyntaxKind.CloseParenToken | SyntaxKind.EqualsToken | SyntaxKind.CommaToken | SyntaxKind.DotToken | SyntaxKind.Identifier | SyntaxKind.BacktickToken | SyntaxKind.HashToken | SyntaxKind.Unknown | KeywordSyntaxKind; enum NodeFlags { @@ -4351,7 +4351,9 @@ declare namespace ts { interface Token extends Node { readonly kind: TKind; } - type EndOfFileToken = Token & JSDocContainer; + interface EndOfFileToken extends Token, JSDocContainer { + readonly kind: SyntaxKind.EndOfFileToken; + } interface PunctuationToken extends Token { } type DotToken = PunctuationToken; @@ -4431,10 +4433,10 @@ declare namespace ts { _declarationBrand: any; } interface NamedDeclaration extends Declaration { - readonly name?: DeclarationName; + readonly name?: DeclarationName | undefined; } interface DeclarationStatement extends NamedDeclaration, Statement { - readonly name?: Identifier | StringLiteral | NumericLiteral; + readonly name?: Identifier | StringLiteral | NumericLiteral | undefined; } interface ComputedPropertyName extends Node { readonly kind: SyntaxKind.ComputedPropertyName; @@ -4456,16 +4458,16 @@ declare namespace ts { interface TypeParameterDeclaration extends NamedDeclaration, JSDocContainer { readonly kind: SyntaxKind.TypeParameter; readonly parent: DeclarationWithTypeParameterChildren | InferTypeNode; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: Identifier; /** Note: Consider calling `getEffectiveConstraintOfTypeParameter` */ - readonly constraint?: TypeNode; - readonly default?: TypeNode; - expression?: Expression; + readonly constraint?: TypeNode | undefined; + readonly default?: TypeNode | undefined; + expression?: Expression | undefined; } interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { readonly kind: SignatureDeclaration["kind"]; - readonly name?: PropertyName; + readonly name?: PropertyName | undefined; readonly typeParameters?: NodeArray | undefined; readonly parameters: NodeArray; readonly type?: TypeNode | undefined; @@ -4482,9 +4484,9 @@ declare namespace ts { readonly kind: SyntaxKind.VariableDeclaration; readonly parent: VariableDeclarationList | CatchClause; readonly name: BindingName; - readonly exclamationToken?: ExclamationToken; - readonly type?: TypeNode; - readonly initializer?: Expression; + readonly exclamationToken?: ExclamationToken | undefined; + readonly type?: TypeNode | undefined; + readonly initializer?: Expression | undefined; } interface VariableDeclarationList extends Node { readonly kind: SyntaxKind.VariableDeclarationList; @@ -4494,45 +4496,45 @@ declare namespace ts { interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { readonly kind: SyntaxKind.Parameter; readonly parent: SignatureDeclaration; - readonly modifiers?: NodeArray; - readonly dotDotDotToken?: DotDotDotToken; + readonly modifiers?: NodeArray | undefined; + readonly dotDotDotToken?: DotDotDotToken | undefined; readonly name: BindingName; - readonly questionToken?: QuestionToken; - readonly type?: TypeNode; - readonly initializer?: Expression; + readonly questionToken?: QuestionToken | undefined; + readonly type?: TypeNode | undefined; + readonly initializer?: Expression | undefined; } interface BindingElement extends NamedDeclaration, FlowContainer { readonly kind: SyntaxKind.BindingElement; readonly parent: BindingPattern; - readonly propertyName?: PropertyName; - readonly dotDotDotToken?: DotDotDotToken; + readonly propertyName?: PropertyName | undefined; + readonly dotDotDotToken?: DotDotDotToken | undefined; readonly name: BindingName; - readonly initializer?: Expression; + readonly initializer?: Expression | undefined; } interface PropertySignature extends TypeElement, JSDocContainer { readonly kind: SyntaxKind.PropertySignature; readonly parent: TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: PropertyName; - readonly questionToken?: QuestionToken; - readonly type?: TypeNode; + readonly questionToken?: QuestionToken | undefined; + readonly type?: TypeNode | undefined; } interface PropertyDeclaration extends ClassElement, JSDocContainer { readonly kind: SyntaxKind.PropertyDeclaration; readonly parent: ClassLikeDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: PropertyName; - readonly questionToken?: QuestionToken; - readonly exclamationToken?: ExclamationToken; - readonly type?: TypeNode; - readonly initializer?: Expression; + readonly questionToken?: QuestionToken | undefined; + readonly exclamationToken?: ExclamationToken | undefined; + readonly type?: TypeNode | undefined; + readonly initializer?: Expression | undefined; } interface AutoAccessorPropertyDeclaration extends PropertyDeclaration { _autoAccessorBrand: any; } interface ObjectLiteralElement extends NamedDeclaration { _objectLiteralBrand: any; - readonly name?: PropertyName; + readonly name?: PropertyName | undefined; } /** Unlike ObjectLiteralElement, excludes JSXAttribute and JSXSpreadAttribute. */ type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment | MethodDeclaration | AccessorDeclaration; @@ -4546,8 +4548,8 @@ declare namespace ts { readonly kind: SyntaxKind.ShorthandPropertyAssignment; readonly parent: ObjectLiteralExpression; readonly name: Identifier; - readonly equalsToken?: EqualsToken; - readonly objectAssignmentInitializer?: Expression; + readonly equalsToken?: EqualsToken | undefined; + readonly objectAssignmentInitializer?: Expression | undefined; } interface SpreadAssignment extends ObjectLiteralElement, JSDocContainer { readonly kind: SyntaxKind.SpreadAssignment; @@ -4587,14 +4589,14 @@ declare namespace ts { type FunctionLike = SignatureDeclaration; interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement, LocalsContainer { readonly kind: SyntaxKind.FunctionDeclaration; - readonly modifiers?: NodeArray; - readonly name?: Identifier; - readonly body?: FunctionBody; + readonly modifiers?: NodeArray | undefined; + readonly name?: Identifier | undefined; + readonly body?: FunctionBody | undefined; } interface MethodSignature extends SignatureDeclarationBase, TypeElement, LocalsContainer { readonly kind: SyntaxKind.MethodSignature; readonly parent: TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: PropertyName; } interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { @@ -4618,22 +4620,22 @@ declare namespace ts { interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { readonly kind: SyntaxKind.GetAccessor; readonly parent: ClassLikeDeclaration | ObjectLiteralExpression | TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: PropertyName; - readonly body?: FunctionBody; + readonly body?: FunctionBody | undefined; } interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { readonly kind: SyntaxKind.SetAccessor; readonly parent: ClassLikeDeclaration | ObjectLiteralExpression | TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: PropertyName; - readonly body?: FunctionBody; + readonly body?: FunctionBody | undefined; } type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement, LocalsContainer { readonly kind: SyntaxKind.IndexSignature; readonly parent: ObjectTypeDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly type: TypeNode; } interface ClassStaticBlockDeclaration extends ClassElement, JSDocContainer, LocalsContainer { @@ -4652,15 +4654,15 @@ declare namespace ts { readonly kind: SyntaxKind.ImportTypeAssertionContainer; readonly parent: ImportTypeNode; /** @deprecated */ readonly assertClause: AssertClause; - readonly multiLine?: boolean; + readonly multiLine?: boolean | undefined; } interface ImportTypeNode extends NodeWithTypeArguments { readonly kind: SyntaxKind.ImportType; readonly isTypeOf: boolean; readonly argument: TypeNode; - /** @deprecated */ readonly assertions?: ImportTypeAssertionContainer; - readonly attributes?: ImportAttributes; - readonly qualifier?: EntityName; + /** @deprecated */ readonly assertions?: ImportTypeAssertionContainer | undefined; + readonly attributes?: ImportAttributes | undefined; + readonly qualifier?: EntityName | undefined; } interface ThisTypeNode extends TypeNode { readonly kind: SyntaxKind.ThisType; @@ -4675,10 +4677,10 @@ declare namespace ts { } interface ConstructorTypeNode extends FunctionOrConstructorTypeNodeBase, LocalsContainer { readonly kind: SyntaxKind.ConstructorType; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; } interface NodeWithTypeArguments extends TypeNode { - readonly typeArguments?: NodeArray; + readonly typeArguments?: NodeArray | undefined; } type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; interface TypeReferenceNode extends NodeWithTypeArguments { @@ -4688,9 +4690,9 @@ declare namespace ts { interface TypePredicateNode extends TypeNode { readonly kind: SyntaxKind.TypePredicate; readonly parent: SignatureDeclaration | JSDocTypeExpression; - readonly assertsModifier?: AssertsKeyword; + readonly assertsModifier?: AssertsKeyword | undefined; readonly parameterName: Identifier | ThisTypeNode; - readonly type?: TypeNode; + readonly type?: TypeNode | undefined; } interface TypeQueryNode extends NodeWithTypeArguments { readonly kind: SyntaxKind.TypeQuery; @@ -4710,9 +4712,9 @@ declare namespace ts { } interface NamedTupleMember extends TypeNode, Declaration, JSDocContainer { readonly kind: SyntaxKind.NamedTupleMember; - readonly dotDotDotToken?: Token; + readonly dotDotDotToken?: DotDotDotToken | undefined; readonly name: Identifier; - readonly questionToken?: Token; + readonly questionToken?: QuestionToken | undefined; readonly type: TypeNode; } interface OptionalTypeNode extends TypeNode { @@ -4759,13 +4761,13 @@ declare namespace ts { } interface MappedTypeNode extends TypeNode, Declaration, LocalsContainer { readonly kind: SyntaxKind.MappedType; - readonly readonlyToken?: ReadonlyKeyword | PlusToken | MinusToken; + readonly readonlyToken?: ReadonlyKeyword | PlusToken | MinusToken | undefined; readonly typeParameter: TypeParameterDeclaration; - readonly nameType?: TypeNode; - readonly questionToken?: QuestionToken | PlusToken | MinusToken; - readonly type?: TypeNode; + readonly nameType?: TypeNode | undefined; + readonly questionToken?: QuestionToken | PlusToken | MinusToken | undefined; + readonly type?: TypeNode | undefined; /** Used only to produce grammar errors */ - readonly members?: NodeArray; + readonly members?: NodeArray | undefined; } interface LiteralTypeNode extends TypeNode { readonly kind: SyntaxKind.LiteralType; @@ -4777,7 +4779,7 @@ declare namespace ts { type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral; type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral | JsxNamespacedName | BigIntLiteral; interface TemplateLiteralTypeNode extends TypeNode { - kind: SyntaxKind.TemplateLiteralType; + readonly kind: SyntaxKind.TemplateLiteralType; readonly head: TemplateHead; readonly templateSpans: NodeArray; } @@ -4863,14 +4865,14 @@ declare namespace ts { } interface YieldExpression extends Expression { readonly kind: SyntaxKind.YieldExpression; - readonly asteriskToken?: AsteriskToken; - readonly expression?: Expression; + readonly asteriskToken?: AsteriskToken | undefined; + readonly expression?: Expression | undefined; } interface SyntheticExpression extends Expression { readonly kind: SyntaxKind.SyntheticExpression; readonly isSpread: boolean; readonly type: Type; - readonly tupleNameSource?: ParameterDeclaration | NamedTupleMember; + readonly tupleNameSource?: ParameterDeclaration | NamedTupleMember | undefined; } type ExponentiationOperator = SyntaxKind.AsteriskAsteriskToken; type MultiplicativeOperator = SyntaxKind.AsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken; @@ -4932,24 +4934,24 @@ declare namespace ts { type ConciseBody = FunctionBody | Expression; interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer, LocalsContainer, FlowContainer { readonly kind: SyntaxKind.FunctionExpression; - readonly modifiers?: NodeArray; - readonly name?: Identifier; + readonly modifiers?: NodeArray | undefined; + readonly name?: Identifier | undefined; readonly body: FunctionBody; } interface ArrowFunction extends Expression, FunctionLikeDeclarationBase, JSDocContainer, LocalsContainer, FlowContainer { readonly kind: SyntaxKind.ArrowFunction; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly equalsGreaterThanToken: EqualsGreaterThanToken; readonly body: ConciseBody; readonly name: never; } interface LiteralLikeNode extends Node { text: string; - isUnterminated?: boolean; - hasExtendedUnicodeEscape?: boolean; + isUnterminated?: boolean | undefined; + hasExtendedUnicodeEscape?: boolean | undefined; } interface TemplateLiteralLikeNode extends LiteralLikeNode { - rawText?: string; + rawText?: string | undefined; } interface LiteralExpression extends LiteralLikeNode, PrimaryExpression { _literalExpressionBrand: any; @@ -5032,7 +5034,7 @@ declare namespace ts { interface PropertyAccessExpression extends MemberExpression, NamedDeclaration, JSDocContainer, FlowContainer { readonly kind: SyntaxKind.PropertyAccessExpression; readonly expression: LeftHandSideExpression; - readonly questionDotToken?: QuestionDotToken; + readonly questionDotToken?: QuestionDotToken | undefined; readonly name: MemberName; } interface PropertyAccessChain extends PropertyAccessExpression { @@ -5051,7 +5053,7 @@ declare namespace ts { interface ElementAccessExpression extends MemberExpression, Declaration, JSDocContainer, FlowContainer { readonly kind: SyntaxKind.ElementAccessExpression; readonly expression: LeftHandSideExpression; - readonly questionDotToken?: QuestionDotToken; + readonly questionDotToken?: QuestionDotToken | undefined; readonly argumentExpression: Expression; } interface ElementAccessChain extends ElementAccessExpression { @@ -5064,8 +5066,8 @@ declare namespace ts { interface CallExpression extends LeftHandSideExpression, Declaration { readonly kind: SyntaxKind.CallExpression; readonly expression: LeftHandSideExpression; - readonly questionDotToken?: QuestionDotToken; - readonly typeArguments?: NodeArray; + readonly questionDotToken?: QuestionDotToken | undefined; + readonly typeArguments?: NodeArray | undefined; readonly arguments: NodeArray; } interface CallChain extends CallExpression { @@ -5085,13 +5087,13 @@ declare namespace ts { interface NewExpression extends PrimaryExpression, Declaration { readonly kind: SyntaxKind.NewExpression; readonly expression: LeftHandSideExpression; - readonly typeArguments?: NodeArray; - readonly arguments?: NodeArray; + readonly typeArguments?: NodeArray | undefined; + readonly arguments?: NodeArray | undefined; } interface TaggedTemplateExpression extends MemberExpression { readonly kind: SyntaxKind.TaggedTemplateExpression; readonly tag: LeftHandSideExpression; - readonly typeArguments?: NodeArray; + readonly typeArguments?: NodeArray | undefined; readonly template: TemplateLiteral; } interface InstanceofExpression extends BinaryExpression { @@ -5140,8 +5142,8 @@ declare namespace ts { readonly expression: Identifier | ThisExpression | JsxTagNamePropertyAccess; } interface JsxAttributes extends PrimaryExpression, Declaration { - readonly properties: NodeArray; readonly kind: SyntaxKind.JsxAttributes; + readonly properties: NodeArray; readonly parent: JsxOpeningLikeElement; } interface JsxNamespacedName extends Node { @@ -5153,13 +5155,13 @@ declare namespace ts { readonly kind: SyntaxKind.JsxOpeningElement; readonly parent: JsxElement; readonly tagName: JsxTagNameExpression; - readonly typeArguments?: NodeArray; + readonly typeArguments?: NodeArray | undefined; readonly attributes: JsxAttributes; } interface JsxSelfClosingElement extends PrimaryExpression { readonly kind: SyntaxKind.JsxSelfClosingElement; readonly tagName: JsxTagNameExpression; - readonly typeArguments?: NodeArray; + readonly typeArguments?: NodeArray | undefined; readonly attributes: JsxAttributes; } interface JsxFragment extends PrimaryExpression { @@ -5180,7 +5182,7 @@ declare namespace ts { readonly kind: SyntaxKind.JsxAttribute; readonly parent: JsxAttributes; readonly name: JsxAttributeName; - readonly initializer?: JsxAttributeValue; + readonly initializer?: JsxAttributeValue | undefined; } type JsxAttributeValue = StringLiteral | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment; interface JsxSpreadAttribute extends ObjectLiteralElement { @@ -5196,8 +5198,8 @@ declare namespace ts { interface JsxExpression extends Expression { readonly kind: SyntaxKind.JsxExpression; readonly parent: JsxElement | JsxFragment | JsxAttributeLike; - readonly dotDotDotToken?: Token; - readonly expression?: Expression; + readonly dotDotDotToken?: Token | undefined; + readonly expression?: Expression | undefined; } interface JsxText extends LiteralLikeNode { readonly kind: SyntaxKind.JsxText; @@ -5229,7 +5231,7 @@ declare namespace ts { } interface MissingDeclaration extends DeclarationStatement, PrimaryExpression { readonly kind: SyntaxKind.MissingDeclaration; - readonly name?: Identifier; + readonly name?: Identifier | undefined; } type BlockLike = SourceFile | Block | ModuleBlock | CaseOrDefaultClause; interface Block extends Statement, LocalsContainer { @@ -5238,7 +5240,7 @@ declare namespace ts { } interface VariableStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.VariableStatement; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly declarationList: VariableDeclarationList; } interface ExpressionStatement extends Statement, FlowContainer { @@ -5249,7 +5251,7 @@ declare namespace ts { readonly kind: SyntaxKind.IfStatement; readonly expression: Expression; readonly thenStatement: Statement; - readonly elseStatement?: Statement; + readonly elseStatement?: Statement | undefined; } interface IterationStatement extends Statement { readonly statement: Statement; @@ -5265,9 +5267,9 @@ declare namespace ts { type ForInitializer = VariableDeclarationList | Expression; interface ForStatement extends IterationStatement, LocalsContainer, FlowContainer { readonly kind: SyntaxKind.ForStatement; - readonly initializer?: ForInitializer; - readonly condition?: Expression; - readonly incrementor?: Expression; + readonly initializer?: ForInitializer | undefined; + readonly condition?: Expression | undefined; + readonly incrementor?: Expression | undefined; } type ForInOrOfStatement = ForInStatement | ForOfStatement; interface ForInStatement extends IterationStatement, LocalsContainer, FlowContainer { @@ -5277,22 +5279,22 @@ declare namespace ts { } interface ForOfStatement extends IterationStatement, LocalsContainer, FlowContainer { readonly kind: SyntaxKind.ForOfStatement; - readonly awaitModifier?: AwaitKeyword; + readonly awaitModifier?: AwaitKeyword | undefined; readonly initializer: ForInitializer; readonly expression: Expression; } interface BreakStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.BreakStatement; - readonly label?: Identifier; + readonly label?: Identifier | undefined; } interface ContinueStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.ContinueStatement; - readonly label?: Identifier; + readonly label?: Identifier | undefined; } type BreakOrContinueStatement = BreakStatement | ContinueStatement; interface ReturnStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.ReturnStatement; - readonly expression?: Expression; + readonly expression?: Expression | undefined; } interface WithStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.WithStatement; @@ -5303,7 +5305,7 @@ declare namespace ts { readonly kind: SyntaxKind.SwitchStatement; readonly expression: Expression; readonly caseBlock: CaseBlock; - possiblyExhaustive?: boolean; + possiblyExhaustive?: boolean | undefined; } interface CaseBlock extends Node, LocalsContainer { readonly kind: SyntaxKind.CaseBlock; @@ -5334,13 +5336,13 @@ declare namespace ts { interface TryStatement extends Statement, FlowContainer { readonly kind: SyntaxKind.TryStatement; readonly tryBlock: Block; - readonly catchClause?: CatchClause; - readonly finallyBlock?: Block; + readonly catchClause?: CatchClause | undefined; + readonly finallyBlock?: Block | undefined; } interface CatchClause extends Node, LocalsContainer { readonly kind: SyntaxKind.CatchClause; readonly parent: TryStatement; - readonly variableDeclaration?: VariableDeclaration; + readonly variableDeclaration?: VariableDeclaration | undefined; readonly block: Block; } type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode; @@ -5348,37 +5350,37 @@ declare namespace ts { type DeclarationWithTypeParameterChildren = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { readonly kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; - readonly name?: Identifier; - readonly typeParameters?: NodeArray; - readonly heritageClauses?: NodeArray; + readonly name?: Identifier | undefined; + readonly typeParameters?: NodeArray | undefined; + readonly heritageClauses?: NodeArray | undefined; readonly members: NodeArray; } interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatement { readonly kind: SyntaxKind.ClassDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; /** May be undefined in `export default class { ... }`. */ - readonly name?: Identifier; + readonly name?: Identifier | undefined; } interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpression { readonly kind: SyntaxKind.ClassExpression; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; } type ClassLikeDeclaration = ClassDeclaration | ClassExpression; interface ClassElement extends NamedDeclaration { _classElementBrand: any; - readonly name?: PropertyName; + readonly name?: PropertyName | undefined; } interface TypeElement extends NamedDeclaration { _typeElementBrand: any; - readonly name?: PropertyName; + readonly name?: PropertyName | undefined; readonly questionToken?: QuestionToken | undefined; } interface InterfaceDeclaration extends DeclarationStatement, JSDocContainer { readonly kind: SyntaxKind.InterfaceDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: Identifier; - readonly typeParameters?: NodeArray; - readonly heritageClauses?: NodeArray; + readonly typeParameters?: NodeArray | undefined; + readonly heritageClauses?: NodeArray | undefined; readonly members: NodeArray; } interface HeritageClause extends Node { @@ -5389,20 +5391,20 @@ declare namespace ts { } interface TypeAliasDeclaration extends DeclarationStatement, JSDocContainer, LocalsContainer { readonly kind: SyntaxKind.TypeAliasDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: Identifier; - readonly typeParameters?: NodeArray; + readonly typeParameters?: NodeArray | undefined; readonly type: TypeNode; } interface EnumMember extends NamedDeclaration, JSDocContainer { readonly kind: SyntaxKind.EnumMember; readonly parent: EnumDeclaration; readonly name: PropertyName; - readonly initializer?: Expression; + readonly initializer?: Expression | undefined; } interface EnumDeclaration extends DeclarationStatement, JSDocContainer { readonly kind: SyntaxKind.EnumDeclaration; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: Identifier; readonly members: NodeArray; } @@ -5411,9 +5413,9 @@ declare namespace ts { interface ModuleDeclaration extends DeclarationStatement, JSDocContainer, LocalsContainer { readonly kind: SyntaxKind.ModuleDeclaration; readonly parent: ModuleBody | SourceFile; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: ModuleName; - readonly body?: ModuleBody | JSDocNamespaceDeclaration; + readonly body?: ModuleBody | JSDocNamespaceDeclaration | undefined; } type NamespaceBody = ModuleBlock | NamespaceDeclaration; interface NamespaceDeclaration extends ModuleDeclaration { @@ -5423,7 +5425,7 @@ declare namespace ts { type JSDocNamespaceBody = Identifier | JSDocNamespaceDeclaration; interface JSDocNamespaceDeclaration extends ModuleDeclaration { readonly name: Identifier; - readonly body?: JSDocNamespaceBody; + readonly body?: JSDocNamespaceBody | undefined; } interface ModuleBlock extends Node, Statement { readonly kind: SyntaxKind.ModuleBlock; @@ -5439,7 +5441,7 @@ declare namespace ts { interface ImportEqualsDeclaration extends DeclarationStatement, JSDocContainer { readonly kind: SyntaxKind.ImportEqualsDeclaration; readonly parent: SourceFile | ModuleBlock; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly name: Identifier; readonly isTypeOnly: boolean; readonly moduleReference: ModuleReference; @@ -5452,12 +5454,12 @@ declare namespace ts { interface ImportDeclaration extends Statement { readonly kind: SyntaxKind.ImportDeclaration; readonly parent: SourceFile | ModuleBlock; - readonly modifiers?: NodeArray; - readonly importClause?: ImportClause; + readonly modifiers?: NodeArray | undefined; + readonly importClause?: ImportClause | undefined; /** If this is not a StringLiteral it will be a grammar error. */ readonly moduleSpecifier: Expression; - /** @deprecated */ readonly assertClause?: AssertClause; - readonly attributes?: ImportAttributes; + /** @deprecated */ readonly assertClause?: AssertClause | undefined; + readonly attributes?: ImportAttributes | undefined; } type NamedImportBindings = NamespaceImport | NamedImports; type NamedExportBindings = NamespaceExport | NamedExports; @@ -5465,8 +5467,8 @@ declare namespace ts { readonly kind: SyntaxKind.ImportClause; readonly parent: ImportDeclaration | JSDocImportTag; readonly isTypeOnly: boolean; - readonly name?: Identifier; - readonly namedBindings?: NamedImportBindings; + readonly name?: Identifier | undefined; + readonly namedBindings?: NamedImportBindings | undefined; } /** @deprecated */ type AssertionKey = ImportAttributeName; @@ -5484,11 +5486,11 @@ declare namespace ts { readonly value: Expression; } interface ImportAttributes extends Node { - readonly token: SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword; readonly kind: SyntaxKind.ImportAttributes; + readonly token: SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword; readonly parent: ImportDeclaration | ExportDeclaration; readonly elements: NodeArray; - readonly multiLine?: boolean; + readonly multiLine?: boolean | undefined; } interface NamespaceImport extends NamedDeclaration { readonly kind: SyntaxKind.NamespaceImport; @@ -5507,14 +5509,14 @@ declare namespace ts { interface ExportDeclaration extends DeclarationStatement, JSDocContainer { readonly kind: SyntaxKind.ExportDeclaration; readonly parent: SourceFile | ModuleBlock; - readonly modifiers?: NodeArray; + readonly modifiers?: NodeArray | undefined; readonly isTypeOnly: boolean; /** Will not be assigned in the case of `export * from "foo";` */ - readonly exportClause?: NamedExportBindings; + readonly exportClause?: NamedExportBindings | undefined; /** If this is not a StringLiteral it will be a grammar error. */ - readonly moduleSpecifier?: Expression; - /** @deprecated */ readonly assertClause?: AssertClause; - readonly attributes?: ImportAttributes; + readonly moduleSpecifier?: Expression | undefined; + /** @deprecated */ readonly assertClause?: AssertClause | undefined; + readonly attributes?: ImportAttributes | undefined; } interface NamedImports extends Node { readonly kind: SyntaxKind.NamedImports; @@ -5530,7 +5532,7 @@ declare namespace ts { interface ImportSpecifier extends NamedDeclaration { readonly kind: SyntaxKind.ImportSpecifier; readonly parent: NamedImports; - readonly propertyName?: ModuleExportName; + readonly propertyName?: ModuleExportName | undefined; readonly name: Identifier; readonly isTypeOnly: boolean; } @@ -5538,7 +5540,7 @@ declare namespace ts { readonly kind: SyntaxKind.ExportSpecifier; readonly parent: NamedExports; readonly isTypeOnly: boolean; - readonly propertyName?: ModuleExportName; + readonly propertyName?: ModuleExportName | undefined; readonly name: ModuleExportName; } type ModuleExportName = Identifier | StringLiteral; @@ -5596,8 +5598,8 @@ declare namespace ts { interface ExportAssignment extends DeclarationStatement, JSDocContainer { readonly kind: SyntaxKind.ExportAssignment; readonly parent: SourceFile; - readonly modifiers?: NodeArray; - readonly isExportEquals?: boolean; + readonly modifiers?: NodeArray | undefined; + readonly isExportEquals?: boolean | undefined; readonly expression: Expression; } interface FileReference extends TextRange { @@ -5671,27 +5673,27 @@ declare namespace ts { interface JSDoc extends Node { readonly kind: SyntaxKind.JSDoc; readonly parent: HasJSDoc; - readonly tags?: NodeArray; - readonly comment?: string | NodeArray; + readonly tags?: NodeArray | undefined; + readonly comment?: string | NodeArray | undefined; } interface JSDocTag extends Node { readonly parent: JSDoc | JSDocTypeLiteral; readonly tagName: Identifier; - readonly comment?: string | NodeArray; + readonly comment?: string | NodeArray | undefined; } interface JSDocLink extends Node { readonly kind: SyntaxKind.JSDocLink; - readonly name?: EntityName | JSDocMemberName; + readonly name?: EntityName | JSDocMemberName | undefined; text: string; } interface JSDocLinkCode extends Node { readonly kind: SyntaxKind.JSDocLinkCode; - readonly name?: EntityName | JSDocMemberName; + readonly name?: EntityName | JSDocMemberName | undefined; text: string; } interface JSDocLinkPlain extends Node { readonly kind: SyntaxKind.JSDocLinkPlain; - readonly name?: EntityName | JSDocMemberName; + readonly name?: EntityName | JSDocMemberName | undefined; text: string; } type JSDocComment = JSDocText | JSDocLink | JSDocLinkCode | JSDocLinkPlain; @@ -5702,27 +5704,26 @@ declare namespace ts { interface JSDocUnknownTag extends JSDocTag { readonly kind: SyntaxKind.JSDocTag; } + interface JSDocClassReference extends ExpressionWithTypeArguments { + readonly expression: Identifier | PropertyAccessEntityNameExpression; + } /** * Note that `@extends` is a synonym of `@augments`. * Both tags are represented by this interface. */ interface JSDocAugmentsTag extends JSDocTag { readonly kind: SyntaxKind.JSDocAugmentsTag; - readonly class: ExpressionWithTypeArguments & { - readonly expression: Identifier | PropertyAccessEntityNameExpression; - }; + readonly class: JSDocClassReference; } interface JSDocImplementsTag extends JSDocTag { readonly kind: SyntaxKind.JSDocImplementsTag; - readonly class: ExpressionWithTypeArguments & { - readonly expression: Identifier | PropertyAccessEntityNameExpression; - }; + readonly class: JSDocClassReference; } interface JSDocAuthorTag extends JSDocTag { readonly kind: SyntaxKind.JSDocAuthorTag; } interface JSDocDeprecatedTag extends JSDocTag { - kind: SyntaxKind.JSDocDeprecatedTag; + readonly kind: SyntaxKind.JSDocDeprecatedTag; } interface JSDocClassTag extends JSDocTag { readonly kind: SyntaxKind.JSDocClassTag; @@ -5758,11 +5759,11 @@ declare namespace ts { } interface JSDocSeeTag extends JSDocTag { readonly kind: SyntaxKind.JSDocSeeTag; - readonly name?: JSDocNameReference; + readonly name?: JSDocNameReference | undefined; } interface JSDocReturnTag extends JSDocTag { readonly kind: SyntaxKind.JSDocReturnTag; - readonly typeExpression?: JSDocTypeExpression; + readonly typeExpression?: JSDocTypeExpression | undefined; } interface JSDocTypeTag extends JSDocTag { readonly kind: SyntaxKind.JSDocTypeTag; @@ -5771,15 +5772,15 @@ declare namespace ts { interface JSDocTypedefTag extends JSDocTag, NamedDeclaration, LocalsContainer { readonly kind: SyntaxKind.JSDocTypedefTag; readonly parent: JSDoc; - readonly fullName?: JSDocNamespaceDeclaration | Identifier; - readonly name?: Identifier; - readonly typeExpression?: JSDocTypeExpression | JSDocTypeLiteral; + readonly fullName?: JSDocNamespaceDeclaration | Identifier | undefined; + readonly name?: Identifier | undefined; + readonly typeExpression?: JSDocTypeExpression | JSDocTypeLiteral | undefined; } interface JSDocCallbackTag extends JSDocTag, NamedDeclaration, LocalsContainer { readonly kind: SyntaxKind.JSDocCallbackTag; readonly parent: JSDoc; - readonly fullName?: JSDocNamespaceDeclaration | Identifier; - readonly name?: Identifier; + readonly fullName?: JSDocNamespaceDeclaration | Identifier | undefined; + readonly name?: Identifier | undefined; readonly typeExpression: JSDocSignature; } interface JSDocOverloadTag extends JSDocTag { @@ -5789,18 +5790,18 @@ declare namespace ts { } interface JSDocThrowsTag extends JSDocTag { readonly kind: SyntaxKind.JSDocThrowsTag; - readonly typeExpression?: JSDocTypeExpression; + readonly typeExpression?: JSDocTypeExpression | undefined; } interface JSDocSignature extends JSDocType, Declaration, JSDocContainer, LocalsContainer { readonly kind: SyntaxKind.JSDocSignature; - readonly typeParameters?: readonly JSDocTemplateTag[]; + readonly typeParameters?: readonly JSDocTemplateTag[] | undefined; readonly parameters: readonly JSDocParameterTag[]; readonly type: JSDocReturnTag | undefined; } interface JSDocPropertyLikeTag extends JSDocTag, Declaration { readonly parent: JSDoc; readonly name: EntityName; - readonly typeExpression?: JSDocTypeExpression; + readonly typeExpression?: JSDocTypeExpression | undefined; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ readonly isNameFirst: boolean; readonly isBracketed: boolean; @@ -5813,7 +5814,7 @@ declare namespace ts { } interface JSDocTypeLiteral extends JSDocType, Declaration { readonly kind: SyntaxKind.JSDocTypeLiteral; - readonly jsDocPropertyTags?: readonly JSDocPropertyLikeTag[]; + readonly jsDocPropertyTags?: readonly JSDocPropertyLikeTag[] | undefined; /** If true, then this type literal represents an *array* of its type. */ readonly isArrayType: boolean; } @@ -5824,9 +5825,9 @@ declare namespace ts { interface JSDocImportTag extends JSDocTag { readonly kind: SyntaxKind.JSDocImportTag; readonly parent: JSDoc; - readonly importClause?: ImportClause; + readonly importClause?: ImportClause | undefined; readonly moduleSpecifier: Expression; - readonly attributes?: ImportAttributes; + readonly attributes?: ImportAttributes | undefined; } type FlowType = Type | IncompleteType; interface IncompleteType { @@ -5854,7 +5855,7 @@ declare namespace ts { fileName: string; text: string; amdDependencies: readonly AmdDependency[]; - moduleName?: string; + moduleName?: string | undefined; referencedFiles: readonly FileReference[]; typeReferenceDirectives: readonly FileReference[]; libReferenceDirectives: readonly FileReference[]; @@ -5887,7 +5888,7 @@ declare namespace ts { * of `node`). If so, this field will be unset and source files will be considered to be * CommonJS-output-format by the node module transformer and type checker, regardless of extension or context. */ - impliedNodeFormat?: ResolutionMode; + impliedNodeFormat?: ResolutionMode | undefined; } interface SourceFile { getLineAndCharacterOfPosition(pos: number): LineAndCharacter; @@ -5907,7 +5908,6 @@ declare namespace ts { extendedSourceFiles?: string[]; } interface JsonMinusNumericLiteral extends PrefixUnaryExpression { - readonly kind: SyntaxKind.PrefixUnaryExpression; readonly operator: SyntaxKind.MinusToken; readonly operand: NumericLiteral; } @@ -7784,7 +7784,8 @@ declare namespace ts { createJsxText(text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText; updateJsxText(node: JsxText, text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText; createJsxOpeningFragment(): JsxOpeningFragment; - createJsxJsxClosingFragment(): JsxClosingFragment; + createJsxClosingFragment(): JsxClosingFragment; + /** @deprecated*/ createJsxJsxClosingFragment(): JsxClosingFragment; updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment): JsxFragment; createJsxAttribute(name: JsxAttributeName, initializer: JsxAttributeValue | undefined): JsxAttribute; updateJsxAttribute(node: JsxAttribute, name: JsxAttributeName, initializer: JsxAttributeValue | undefined): JsxAttribute; diff --git a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeErrors-file.js.diff b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeErrors-file.js.diff index 663c0633bf173..5d2d5d57fe484 100644 --- a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeErrors-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeErrors-file.js.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeErrors -@@ -230,7 +230,7 @@ +@@ -231,7 +231,7 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeErrors-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeErrors-file.ts.diff index c50da716b91b9..850c2d3e48610 100644 --- a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeErrors-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeErrors-file.ts.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeErrors -@@ -8,9 +8,8 @@ +@@ -9,9 +9,8 @@ "0": { "kind": "FunctionDeclaration", "pos": 0, @@ -11,7 +11,7 @@ "transformFlags": 4194304, "name": { "kind": "Identifier", -@@ -39,42 +38,9 @@ +@@ -40,42 +39,9 @@ "hasTrailingComma": false, "transformFlags": 0 }, @@ -55,7 +55,7 @@ "1": { "kind": "ExpressionStatement", "pos": 46, -@@ -230,6 +196,6 @@ +@@ -231,6 +197,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeInfo-file.js.diff b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeInfo-file.js.diff index f700c77c48c7f..7e0a3078ac6ea 100644 --- a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeInfo-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeInfo-file.js.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeInfo -@@ -230,7 +230,7 @@ +@@ -231,7 +231,7 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeInfo-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeInfo-file.ts.diff index f63d4526fd75c..bef57a7f4babb 100644 --- a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeInfo-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeInfo-file.ts.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeInfo -@@ -8,9 +8,8 @@ +@@ -9,9 +9,8 @@ "0": { "kind": "FunctionDeclaration", "pos": 0, @@ -11,7 +11,7 @@ "transformFlags": 4194304, "name": { "kind": "Identifier", -@@ -39,42 +38,9 @@ +@@ -40,42 +39,9 @@ "hasTrailingComma": false, "transformFlags": 0 }, @@ -55,7 +55,7 @@ "1": { "kind": "ExpressionStatement", "pos": 46, -@@ -106,9 +72,8 @@ +@@ -107,9 +73,8 @@ "2": { "kind": "FunctionDeclaration", "pos": 61, @@ -65,7 +65,7 @@ "transformFlags": 4194304, "name": { "kind": "Identifier", -@@ -137,43 +102,9 @@ +@@ -138,43 +103,9 @@ "hasTrailingComma": false, "transformFlags": 0 }, @@ -110,7 +110,7 @@ "3": { "kind": "ExpressionStatement", "pos": 135, -@@ -230,6 +161,6 @@ +@@ -231,6 +162,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseNone-file.js.diff b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseNone-file.js.diff index 567ff8973d13a..be73320a32c8d 100644 --- a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseNone-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseNone-file.js.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseNone -@@ -8,9 +8,8 @@ +@@ -9,9 +9,8 @@ "0": { "kind": "FunctionDeclaration", "pos": 0, @@ -11,7 +11,7 @@ "transformFlags": 4194304, "name": { "kind": "Identifier", -@@ -39,42 +38,9 @@ +@@ -40,42 +39,9 @@ "hasTrailingComma": false, "transformFlags": 0 }, @@ -55,7 +55,7 @@ "1": { "kind": "ExpressionStatement", "pos": 46, -@@ -106,9 +72,8 @@ +@@ -107,9 +73,8 @@ "2": { "kind": "FunctionDeclaration", "pos": 61, @@ -65,7 +65,7 @@ "transformFlags": 4194304, "name": { "kind": "Identifier", -@@ -137,43 +102,9 @@ +@@ -138,43 +103,9 @@ "hasTrailingComma": false, "transformFlags": 0 }, @@ -110,7 +110,7 @@ "3": { "kind": "ExpressionStatement", "pos": 135, -@@ -230,7 +161,6 @@ +@@ -231,7 +162,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseNone-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseNone-file.ts.diff index 852412d8420f3..c17b1b6d49d70 100644 --- a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseNone-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseNone-file.ts.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseNone -@@ -8,9 +8,8 @@ +@@ -9,9 +9,8 @@ "0": { "kind": "FunctionDeclaration", "pos": 0, @@ -11,7 +11,7 @@ "transformFlags": 4194304, "name": { "kind": "Identifier", -@@ -39,42 +38,9 @@ +@@ -40,42 +39,9 @@ "hasTrailingComma": false, "transformFlags": 0 }, @@ -55,7 +55,7 @@ "1": { "kind": "ExpressionStatement", "pos": 46, -@@ -106,9 +72,8 @@ +@@ -107,9 +73,8 @@ "2": { "kind": "FunctionDeclaration", "pos": 61, @@ -65,7 +65,7 @@ "transformFlags": 4194304, "name": { "kind": "Identifier", -@@ -137,43 +102,9 @@ +@@ -138,43 +103,9 @@ "hasTrailingComma": false, "transformFlags": 0 }, @@ -110,7 +110,7 @@ "3": { "kind": "ExpressionStatement", "pos": 135, -@@ -230,6 +161,6 @@ +@@ -231,6 +162,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.js.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.js.diff index e85d3dac9427d..494c3aeb461ff 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.js.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeErrors -@@ -214,7 +214,7 @@ +@@ -213,7 +213,7 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.ts.diff index d54b75b0af7d6..0af7fab532413 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.ts.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeErrors -@@ -214,6 +214,6 @@ +@@ -213,6 +213,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.js.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.js.diff index 894c809d38c7e..5a045b4126e5e 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.js.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeInfo -@@ -214,7 +214,7 @@ +@@ -213,7 +213,7 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff index 0c2bff5a4677e..124598753a8b7 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff @@ -55,7 +55,7 @@ "length": 2, "pos": 0, "end": 70, -@@ -214,6 +171,6 @@ +@@ -213,6 +170,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff index 3a1028bb08254..41a1390a61b54 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff @@ -55,7 +55,7 @@ "length": 2, "pos": 0, "end": 70, -@@ -214,7 +171,6 @@ +@@ -213,7 +170,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff index 41135dc2495ba..bcb71c32e1381 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff @@ -55,7 +55,7 @@ "length": 2, "pos": 0, "end": 70, -@@ -214,6 +171,6 @@ +@@ -213,6 +170,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeErrors-file.js.diff b/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeErrors-file.js.diff index 8cd70cc2c15d5..93a31a015f64b 100644 --- a/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeErrors-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeErrors-file.js.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeErrors -@@ -295,7 +295,7 @@ +@@ -296,7 +296,7 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeErrors-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeErrors-file.ts.diff index e02a89d1bca31..f280373a70791 100644 --- a/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeErrors-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeErrors-file.ts.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeErrors -@@ -295,6 +295,6 @@ +@@ -296,6 +296,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.js.diff b/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.js.diff index 85dc2f66b7242..196a1c8c9f85c 100644 --- a/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.js.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeInfo -@@ -295,7 +295,7 @@ +@@ -296,7 +296,7 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.ts.diff index 277a3fbe56a55..3063fb1931b88 100644 --- a/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.ts.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeInfo -@@ -38,235 +38,9 @@ +@@ -39,235 +39,9 @@ "end": 108, "hasTrailingComma": false, "transformFlags": 0 @@ -238,7 +238,7 @@ "length": 1, "pos": 0, "end": 109, -@@ -295,6 +69,6 @@ +@@ -296,6 +70,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.js.diff b/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.js.diff index cae5537d772c6..a341a7806e2a8 100644 --- a/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.js.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseNone -@@ -38,235 +38,9 @@ +@@ -39,235 +39,9 @@ "end": 108, "hasTrailingComma": false, "transformFlags": 0 @@ -238,7 +238,7 @@ "length": 1, "pos": 0, "end": 109, -@@ -295,7 +69,6 @@ +@@ -296,7 +70,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.ts.diff index d89f8511e680a..e8d9f5347f962 100644 --- a/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.ts.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseNone -@@ -38,235 +38,9 @@ +@@ -39,235 +39,9 @@ "end": 108, "hasTrailingComma": false, "transformFlags": 0 @@ -238,7 +238,7 @@ "length": 1, "pos": 0, "end": 109, -@@ -295,6 +69,6 @@ +@@ -296,6 +70,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], From 7e2f1bb99a283f00a857d008163aa4c605321bf4 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Sep 2024 16:19:43 -0400 Subject: [PATCH 02/10] formatting --- src/compiler/ast.ts | 10007 +++++++++++----- src/compiler/factory/astNodeFactory.ts | 9 +- src/compiler/factory/astNodeTests.ts | 8 +- src/compiler/factory/astParenthesizerRules.ts | 7 +- src/compiler/factory/nodeFactory.ts | 8 +- src/compiler/factory/parenthesizerRules.ts | 5 +- src/compiler/parser.ts | 4 +- src/compiler/utilitiesPublic.ts | 2 +- src/harness/harnessUtils.ts | 5 +- src/services/services.ts | 3 +- 10 files changed, 7118 insertions(+), 2940 deletions(-) diff --git a/src/compiler/ast.ts b/src/compiler/ast.ts index bfea5a415f3ca..cd93debb87a9d 100644 --- a/src/compiler/ast.ts +++ b/src/compiler/ast.ts @@ -1,3 +1,4 @@ +import { isAstParenthesizedExpression } from "./_namespaces/ts.ast.js"; import * as ts from "./_namespaces/ts.js"; import { __String, @@ -73,7 +74,6 @@ import { TypeNodeSyntaxKind, updateSourceFile, } from "./_namespaces/ts.js"; -import { isAstParenthesizedExpression } from "./_namespaces/ts.ast.js"; /** @internal */ export type NextContainer = AstNode; @@ -126,14 +126,28 @@ export class AstNode = Node> | undefined { return this._extra?.original; } - set original(value) { this.extra.original = value; } - get emitNode(): ts.EmitNode | undefined { return this._extra?.emitNode; } - set emitNode(value) { this.extra.emitNode = value; } + get id(): number { + return this._extra?.id.id ?? 0; + } + set id(value) { + this.extra.id.id = value; + } + get original(): AstNode> | undefined { + return this._extra?.original; + } + set original(value) { + this.extra.original = value; + } + get emitNode(): ts.EmitNode | undefined { + return this._extra?.emitNode; + } + set emitNode(value) { + this.extra.emitNode = value; + } get transformFlags(): ts.TransformFlags { const transformFlags = this._extra?.transformFlags; if (transformFlags === undefined) { @@ -142,12 +156,20 @@ export class AstNode = Node = Node = N extends unknown ? AstNode : never; @@ -517,30 +967,78 @@ export class Node { // for use with vscode-js-debug's new customDescriptionGenerator in launch.json __tsDebuggerDisplay: { value(this: Node) { - const nodeHeader = - ts.isGeneratedIdentifier(this) ? "GeneratedIdentifier" : + const nodeHeader = ts.isGeneratedIdentifier(this) ? "GeneratedIdentifier" : ts.isIdentifier(this) ? `Identifier '${idText(this)}'` : ts.isPrivateIdentifier(this) ? `PrivateIdentifier '${idText(this)}'` : ts.isStringLiteral(this) ? `StringLiteral ${JSON.stringify(this.text.length < 10 ? this.text : this.text.slice(10) + "...")}` : @@ -765,11 +1262,19 @@ export class AstNodeArray { this.hasTrailingComma = hasTrailingComma; } - /** @private */ get extra(): AstNodeArrayExtraFields { return this._extra ??= new AstNodeArrayExtraFields(); } + /** @private */ get extra(): AstNodeArrayExtraFields { + return this._extra ??= new AstNodeArrayExtraFields(); + } - get nodes(): NodeArray { return this.extra.nodes ??= new NodeArray(this); } - get hasTrailingComma(): boolean { return this._extra?.hasTrailingComma ?? false; } - set hasTrailingComma(value) { this.extra.hasTrailingComma = value; } + get nodes(): NodeArray { + return this.extra.nodes ??= new NodeArray(this); + } + get hasTrailingComma(): boolean { + return this._extra?.hasTrailingComma ?? false; + } + set hasTrailingComma(value) { + this.extra.hasTrailingComma = value; + } get transformFlags(): ts.TransformFlags { let transformFlags = this._extra?.transformFlags; @@ -782,7 +1287,9 @@ export class AstNodeArray { } return transformFlags; } - set transformFlags(value) { this.extra.transformFlags = value; } + set transformFlags(value) { + this.extra.transformFlags = value; + } } /** @internal */ @@ -797,21 +1304,47 @@ export class NodeArray extends Array implements ts.NodeArray< Object.preventExtensions(this); } - static override get [globalThis.Symbol.species](): ArrayConstructor { return Array; } + static override get [globalThis.Symbol.species](): ArrayConstructor { + return Array; + } - get pos(): number { return this.ast.pos; } - set pos(value) { this.ast.pos = value; } - get end(): number { return this.ast.end; } - set end(value) { this.ast.end = value; } - get hasTrailingComma(): boolean { return this.ast.hasTrailingComma; } - set hasTrailingComma(value) { this.ast.hasTrailingComma = value; } - get transformFlags(): ts.TransformFlags { return this.ast.transformFlags; } - set transformFlags(value) { this.ast.transformFlags = value; } + get pos(): number { + return this.ast.pos; + } + set pos(value) { + this.ast.pos = value; + } + get end(): number { + return this.ast.end; + } + set end(value) { + this.ast.end = value; + } + get hasTrailingComma(): boolean { + return this.ast.hasTrailingComma; + } + set hasTrailingComma(value) { + this.ast.hasTrailingComma = value; + } + get transformFlags(): ts.TransformFlags { + return this.ast.transformFlags; + } + set transformFlags(value) { + this.ast.transformFlags = value; + } - get __pos(): number | undefined { return astNodeArrayMaybeExtra(this.ast)?.__pos; } // eslint-disable-line @typescript-eslint/naming-convention - set __pos(value) { this.ast.extra.__pos = value; } // eslint-disable-line @typescript-eslint/naming-convention - get __end(): number | undefined { return astNodeArrayMaybeExtra(this.ast)?.__end; } // eslint-disable-line @typescript-eslint/naming-convention - set __end(value) { this.ast.extra.__end = value; } // eslint-disable-line @typescript-eslint/naming-convention + get __pos(): number | undefined { // eslint-disable-line @typescript-eslint/naming-convention + return astNodeArrayMaybeExtra(this.ast)?.__pos; + } + set __pos(value) { // eslint-disable-line @typescript-eslint/naming-convention + this.ast.extra.__pos = value; + } + get __end(): number | undefined { // eslint-disable-line @typescript-eslint/naming-convention + return astNodeArrayMaybeExtra(this.ast)?.__end; + } + set __end(value) { // eslint-disable-line @typescript-eslint/naming-convention + this.ast.extra.__end = value; + } } Debug.registerDebugInfo(() => { @@ -1121,8 +1654,12 @@ export class EndOfFileToken extends Token implements Prim /** @internal */ export type BooleanLiteral = | TrueLiteral - | FalseLiteral - ; + | FalseLiteral; /** @internal */ export type AstBooleanLiteral = AstNodeOneOf; @@ -1232,7 +1776,7 @@ export type AstBooleanLiteral = AstNodeOneOf; // Punctuation /** @internal */ -export interface PunctuationToken extends Token { } +export interface PunctuationToken extends Token {} /** @internal */ export type DotToken = PunctuationToken; @@ -1298,7 +1842,7 @@ export type AstQuestionDotToken = AstNode; // Keywords /** @internal */ -export interface KeywordToken extends Token { } +export interface KeywordToken extends Token {} /** @internal */ export type AssertsKeyword = KeywordToken; @@ -1324,7 +1868,7 @@ export type AstCaseKeyword = AstNode; // Modifiers /** @internal */ -export interface ModifierToken extends KeywordToken { } +export interface ModifierToken extends KeywordToken {} /** @internal */ export type AbstractKeyword = ModifierToken; @@ -1434,20 +1978,46 @@ export class Identifier extends Token declare _jsdocContainerBrand: any; declare _flowContainerBrand: any; - get escapedText(): __String { return this.ast.data.escapedText; } - set escapedText(value: __String) { this.ast.data.escapedText = value; } - get resolvedSymbol(): Symbol { return this.ast.data.resolvedSymbol; } - set resolvedSymbol(value: Symbol) { this.ast.data.resolvedSymbol = value; } - get symbol(): Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } - set flowNode(value) { this.ast.data.flowNode = value; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value) { this.ast.data.jsDoc = value; } + get escapedText(): __String { + return this.ast.data.escapedText; + } + set escapedText(value: __String) { + this.ast.data.escapedText = value; + } + get resolvedSymbol(): Symbol { + return this.ast.data.resolvedSymbol; + } + set resolvedSymbol(value: Symbol) { + this.ast.data.resolvedSymbol = value; + } + get symbol(): Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get flowNode(): FlowNode | undefined { + return this.ast.data.flowNode; + } + set flowNode(value) { + this.ast.data.flowNode = value; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value) { + this.ast.data.jsDoc = value; + } - get text(): string { return idText(this); } + get text(): string { + return idText(this); + } } /** @internal */ @@ -1477,12 +2047,24 @@ export class QualifiedName extends Node; export class ComputedPropertyName extends Node implements ts.ComputedPropertyName { declare readonly ast: AstComputedPropertyName; - override get parent() { return super.parent as Declaration; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as Declaration; + } + override set parent(value) { + super.parent = value; + } - get expression(): Expression { return this.ast.data.expression?.node; } - set expression(value: Expression) { this.ast.data.expression = value?.ast; } + get expression(): Expression { + return this.ast.data.expression?.node; + } + set expression(value: Expression) { + this.ast.data.expression = value?.ast; + } } /** @internal */ @@ -1579,10 +2169,16 @@ export class PrivateIdentifier extends Token | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value: NodeArray | undefined) { this.ast.data.modifiers = value?.ast; } - get name(): Identifier { return this.ast.data.name?.node; } - set name(value: Identifier) { this.ast.data.name = value?.ast; } - get constraint(): TypeNode | undefined { return this.ast.data.constraint?.node; } - set constraint(value: TypeNode | undefined) { this.ast.data.constraint = value?.ast; } - get default(): TypeNode | undefined { return this.ast.data.default?.node; } - set default(value: TypeNode | undefined) { this.ast.data.default = value?.ast; } - get expression(): Expression | undefined { return this.ast.data.expression?.node; } - set expression(value: Expression | undefined) { this.ast.data.expression = value?.ast; } - get symbol(): Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value) { this.ast.data.jsDoc = value; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value: NodeArray | undefined) { + this.ast.data.modifiers = value?.ast; + } + get name(): Identifier { + return this.ast.data.name?.node; + } + set name(value: Identifier) { + this.ast.data.name = value?.ast; + } + get constraint(): TypeNode | undefined { + return this.ast.data.constraint?.node; + } + set constraint(value: TypeNode | undefined) { + this.ast.data.constraint = value?.ast; + } + get default(): TypeNode | undefined { + return this.ast.data.default?.node; + } + set default(value: TypeNode | undefined) { + this.ast.data.default = value?.ast; + } + get expression(): Expression | undefined { + return this.ast.data.expression?.node; + } + set expression(value: Expression | undefined) { + this.ast.data.expression = value?.ast; + } + get symbol(): Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value) { + this.ast.data.jsDoc = value; + } } /** @internal */ @@ -1642,27 +2274,67 @@ export class ParameterDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value: NodeArray | undefined) { this.ast.data.modifiers = value?.ast; } - get dotDotDotToken(): DotDotDotToken | undefined { return this.ast.data.dotDotDotToken?.node; } - set dotDotDotToken(value: DotDotDotToken | undefined) { this.ast.data.dotDotDotToken = value?.ast; } - get name(): BindingName { return this.ast.data.name?.node; } - set name(value: BindingName) { this.ast.data.name = value?.ast; } - get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } - set questionToken(value: QuestionToken | undefined) { this.ast.data.questionToken = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value: TypeNode | undefined) { this.ast.data.type = value?.ast; } - get initializer(): Expression | undefined { return this.ast.data.initializer?.node; } - set initializer(value: Expression | undefined) { this.ast.data.initializer = value?.ast; } - get symbol(): Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value) { this.ast.data.jsDoc = value; } + override get parent() { + return super.parent as SignatureDeclaration; + } + override set parent(value) { + super.parent = value; + } + + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value: NodeArray | undefined) { + this.ast.data.modifiers = value?.ast; + } + get dotDotDotToken(): DotDotDotToken | undefined { + return this.ast.data.dotDotDotToken?.node; + } + set dotDotDotToken(value: DotDotDotToken | undefined) { + this.ast.data.dotDotDotToken = value?.ast; + } + get name(): BindingName { + return this.ast.data.name?.node; + } + set name(value: BindingName) { + this.ast.data.name = value?.ast; + } + get questionToken(): QuestionToken | undefined { + return this.ast.data.questionToken?.node; + } + set questionToken(value: QuestionToken | undefined) { + this.ast.data.questionToken = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value: TypeNode | undefined) { + this.ast.data.type = value?.ast; + } + get initializer(): Expression | undefined { + return this.ast.data.initializer?.node; + } + set initializer(value: Expression | undefined) { + this.ast.data.initializer = value?.ast; + } + get symbol(): Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value) { + this.ast.data.jsDoc = value; + } } /** @internal */ @@ -1698,11 +2370,19 @@ export class AstParameterDeclarationData extends AstData { export class Decorator extends Node implements ts.Decorator { declare readonly ast: AstDecorator; - override get parent() { return super.parent as Declaration; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as Declaration; + } + override set parent(value) { + super.parent = value; + } - get expression(): LeftHandSideExpression { return this.ast.data.expression?.node; } - set expression(value: LeftHandSideExpression) { this.ast.data.expression = value?.ast; } + get expression(): LeftHandSideExpression { + return this.ast.data.expression?.node; + } + set expression(value: LeftHandSideExpression) { + this.ast.data.expression = value?.ast; + } } /** @internal */ @@ -1725,25 +2405,61 @@ export class PropertySignature extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value: NodeArray | undefined) { this.ast.data.modifiers = value?.ast; } - get name(): PropertyName { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } - set questionToken(value) { this.ast.data.questionToken = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get initializer(): Expression | undefined { return this.ast.data.initializer?.node; } - set initializer(value) { this.ast.data.initializer = value?.ast; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value: NodeArray | undefined) { + this.ast.data.modifiers = value?.ast; + } + get name(): PropertyName { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get questionToken(): QuestionToken | undefined { + return this.ast.data.questionToken?.node; + } + set questionToken(value) { + this.ast.data.questionToken = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get initializer(): Expression | undefined { + return this.ast.data.initializer?.node; + } + set initializer(value) { + this.ast.data.initializer = value?.ast; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } } /** @internal */ @@ -1787,24 +2503,60 @@ export class CallSignatureDeclaration extends Node | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -1829,24 +2581,60 @@ export class ConstructSignatureDeclaration extends Node | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -1869,23 +2657,55 @@ export class VariableDeclaration extends Node implements ts.VariableDeclarationList { declare readonly ast: AstVariableDeclarationList; - override get parent() { return super.parent as VariableStatement | ForStatement | ForOfStatement | ForInStatement; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as VariableStatement | ForStatement | ForOfStatement | ForInStatement; + } + override set parent(value) { + super.parent = value; + } - get declarations(): NodeArray { return this.ast.data.declarations.nodes; } - set declarations(value) { this.ast.data.declarations = value?.ast; } + get declarations(): NodeArray { + return this.ast.data.declarations.nodes; + } + set declarations(value) { + this.ast.data.declarations = value?.ast; + } } /** @internal */ @@ -1942,23 +2770,55 @@ export class BindingElement extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get name(): PropertyName { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } - set questionToken(value) { this.ast.data.questionToken = value?.ast; } - get exclamationToken(): ExclamationToken | undefined { return this.ast.data.exclamationToken?.node; } - set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get initializer(): Expression | undefined { return this.ast.data.initializer?.node; } - set initializer(value) { this.ast.data.initializer = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + override get parent() { + return super.parent as ClassLikeDeclaration; + } + override set parent(value) { + super.parent = value; + } + + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get name(): PropertyName { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get questionToken(): QuestionToken | undefined { + return this.ast.data.questionToken?.node; + } + set questionToken(value) { + this.ast.data.questionToken = value?.ast; + } + get exclamationToken(): ExclamationToken | undefined { + return this.ast.data.exclamationToken?.node; + } + set exclamationToken(value) { + this.ast.data.exclamationToken = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get initializer(): Expression | undefined { + return this.ast.data.initializer?.node; + } + set initializer(value) { + this.ast.data.initializer = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -2047,25 +2947,61 @@ export class PropertyAssignment extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } - set questionToken(value) { this.ast.data.questionToken = value?.ast; } - get exclamationToken(): ExclamationToken | undefined { return this.ast.data.exclamationToken?.node; } - set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get name(): PropertyName { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get initializer(): Expression { + return this.ast.data.initializer?.node; + } + set initializer(value) { + this.ast.data.initializer = value?.ast; + } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get questionToken(): QuestionToken | undefined { + return this.ast.data.questionToken?.node; + } + set questionToken(value) { + this.ast.data.questionToken = value?.ast; + } + get exclamationToken(): ExclamationToken | undefined { + return this.ast.data.exclamationToken?.node; + } + set exclamationToken(value) { + this.ast.data.exclamationToken = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -2094,27 +3030,67 @@ export class ShorthandPropertyAssignment extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } - set questionToken(value) { this.ast.data.questionToken = value?.ast; } - get exclamationToken(): ExclamationToken | undefined { return this.ast.data.exclamationToken?.node; } - set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + override get parent() { + return super.parent as ObjectLiteralExpression; + } + override set parent(value) { + super.parent = value; + } + + get name(): Identifier { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get equalsToken(): EqualsToken | undefined { + return this.ast.data.equalsToken?.node; + } + set equalsToken(value) { + this.ast.data.equalsToken = value?.ast; + } + get objectAssignmentInitializer(): Expression | undefined { + return this.ast.data.objectAssignmentInitializer?.node; + } + set objectAssignmentInitializer(value) { + this.ast.data.objectAssignmentInitializer = value?.ast; + } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get questionToken(): QuestionToken | undefined { + return this.ast.data.questionToken?.node; + } + set questionToken(value) { + this.ast.data.questionToken = value?.ast; + } + get exclamationToken(): ExclamationToken | undefined { + return this.ast.data.exclamationToken?.node; + } + set exclamationToken(value) { + this.ast.data.exclamationToken = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -2145,17 +3121,37 @@ export class SpreadAssignment extends Node; @@ -2185,8 +3180,7 @@ export type AstBindingPattern = AstNodeOneOf; /** @internal */ export type ArrayBindingElement = | BindingElement - | OmittedExpression - ; + | OmittedExpression; /** @internal */ export type AstArrayBindingElement = AstNodeOneOf; @@ -2195,11 +3189,19 @@ export type AstArrayBindingElement = AstNodeOneOf; export class ObjectBindingPattern extends Node implements ts.ObjectBindingPattern { declare readonly ast: AstObjectBindingPattern; - override get parent() { return super.parent as VariableDeclaration | ParameterDeclaration | BindingElement; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as VariableDeclaration | ParameterDeclaration | BindingElement; + } + override set parent(value) { + super.parent = value; + } - get elements(): NodeArray { return this.ast.data.elements?.nodes!; } // TODO: remove `!` - set elements(value) { this.ast.data.elements = value?.ast; } + get elements(): NodeArray { + return this.ast.data.elements?.nodes!; // TODO: remove `!` + } + set elements(value) { + this.ast.data.elements = value?.ast; + } } /** @internal */ @@ -2221,11 +3223,19 @@ export class AstObjectBindingPatternData extends AstData { export class ArrayBindingPattern extends Node implements ts.ArrayBindingPattern { declare readonly ast: AstArrayBindingPattern; - override get parent() { return super.parent as VariableDeclaration | ParameterDeclaration | BindingElement; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as VariableDeclaration | ParameterDeclaration | BindingElement; + } + override set parent(value) { + super.parent = value; + } - get elements(): NodeArray { return this.ast.data.elements?.nodes!; } // TODO: remove `!` - set elements(value) { this.ast.data.elements = value?.ast; } + get elements(): NodeArray { + return this.ast.data.elements?.nodes!; // TODO: remove `!` + } + set elements(value) { + this.ast.data.elements = value?.ast; + } } /** @internal */ @@ -2249,37 +3259,97 @@ export class FunctionDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get asteriskToken(): AsteriskToken | undefined { return this.ast.data.asteriskToken?.node; } - set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } - get name(): Identifier | undefined { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get body(): Block | undefined { return this.ast.data.body?.node; } - set body(value) { this.ast.data.body = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } - get endFlowNode(): ts.FlowNode | undefined { return this.ast.data.endFlowNode; } - set endFlowNode(value) { this.ast.data.endFlowNode = value; } - get returnFlowNode(): ts.FlowNode | undefined { return this.ast.data.returnFlowNode; } - set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } - - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } // Used for quick info, replaces typeParameters for instantiated signatures - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get asteriskToken(): AsteriskToken | undefined { + return this.ast.data.asteriskToken?.node; + } + set asteriskToken(value) { + this.ast.data.asteriskToken = value?.ast; + } + get name(): Identifier | undefined { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get body(): Block | undefined { + return this.ast.data.body?.node; + } + set body(value) { + this.ast.data.body = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } + get endFlowNode(): ts.FlowNode | undefined { + return this.ast.data.endFlowNode; + } + set endFlowNode(value) { + this.ast.data.endFlowNode = value; + } + get returnFlowNode(): ts.FlowNode | undefined { + return this.ast.data.returnFlowNode; + } + set returnFlowNode(value) { + this.ast.data.returnFlowNode = value; + } + + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } // Used for quick info, replaces typeParameters for instantiated signatures + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } } /** @internal */ @@ -2337,33 +3407,85 @@ export class MethodSignature extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get name(): PropertyName { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } - set questionToken(value) { this.ast.data.questionToken = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + override get parent() { + return super.parent as TypeLiteralNode | InterfaceDeclaration; + } + override set parent(value) { + super.parent = value; + } + + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get name(): PropertyName { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get questionToken(): QuestionToken | undefined { + return this.ast.data.questionToken?.node; + } + set questionToken(value) { + this.ast.data.questionToken = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -2395,45 +3517,121 @@ export class MethodDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get asteriskToken(): AsteriskToken | undefined { return this.ast.data.asteriskToken?.node; } - set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } - get name(): PropertyName { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } - set questionToken(value) { this.ast.data.questionToken = value?.ast; } - get exclamationToken(): ExclamationToken | undefined { return this.ast.data.exclamationToken?.node; } - set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get body(): Block | undefined { return this.ast.data.body?.node; } - set body(value) { this.ast.data.body = value?.ast; } - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } - get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } - set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } - get endFlowNode(): ts.FlowNode | undefined { return this.ast.data.endFlowNode; } - set endFlowNode(value) { this.ast.data.endFlowNode = value; } - get returnFlowNode(): ts.FlowNode | undefined { return this.ast.data.returnFlowNode; } - set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } + override get parent() { + return super.parent as ClassLikeDeclaration | ObjectLiteralExpression; + } + override set parent(value) { + super.parent = value; + } + + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get asteriskToken(): AsteriskToken | undefined { + return this.ast.data.asteriskToken?.node; + } + set asteriskToken(value) { + this.ast.data.asteriskToken = value?.ast; + } + get name(): PropertyName { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get questionToken(): QuestionToken | undefined { + return this.ast.data.questionToken?.node; + } + set questionToken(value) { + this.ast.data.questionToken = value?.ast; + } + get exclamationToken(): ExclamationToken | undefined { + return this.ast.data.exclamationToken?.node; + } + set exclamationToken(value) { + this.ast.data.exclamationToken = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get body(): Block | undefined { + return this.ast.data.body?.node; + } + set body(value) { + this.ast.data.body = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } + get flowNode(): FlowNode | undefined { + return this.ast.data.flowNode; + } + set flowNode(value: FlowNode | undefined) { + this.ast.data.flowNode = value; + } + get endFlowNode(): ts.FlowNode | undefined { + return this.ast.data.endFlowNode; + } + set endFlowNode(value) { + this.ast.data.endFlowNode = value; + } + get returnFlowNode(): ts.FlowNode | undefined { + return this.ast.data.returnFlowNode; + } + set returnFlowNode(value) { + this.ast.data.returnFlowNode = value; + } } /** @internal */ @@ -2495,35 +3693,91 @@ export class ConstructorDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get body(): Block | undefined { return this.ast.data.body?.node; } - set body(value) { this.ast.data.body = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } - get endFlowNode(): ts.FlowNode | undefined { return this.ast.data.endFlowNode; } - set endFlowNode(value) { this.ast.data.endFlowNode = value; } - get returnFlowNode(): ts.FlowNode | undefined { return this.ast.data.returnFlowNode; } - set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } + override get parent() { + return super.parent as ClassLikeDeclaration; + } + override set parent(value) { + super.parent = value; + } + + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get body(): Block | undefined { + return this.ast.data.body?.node; + } + set body(value) { + this.ast.data.body = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } + get endFlowNode(): ts.FlowNode | undefined { + return this.ast.data.endFlowNode; + } + set endFlowNode(value) { + this.ast.data.endFlowNode = value; + } + get returnFlowNode(): ts.FlowNode | undefined { + return this.ast.data.returnFlowNode; + } + set returnFlowNode(value) { + this.ast.data.returnFlowNode = value; + } } /** @internal */ @@ -2566,11 +3820,19 @@ export class SemicolonClassElement extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get name(): PropertyName { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get body(): Block | undefined { return this.ast.data.body?.node; } - set body(value) { this.ast.data.body = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } - get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } - set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } - get endFlowNode(): ts.FlowNode | undefined { return this.ast.data.endFlowNode; } - set endFlowNode(value) { this.ast.data.endFlowNode = value; } - get returnFlowNode(): ts.FlowNode | undefined { return this.ast.data.returnFlowNode; } - set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } + override get parent() { + return super.parent as ClassLikeDeclaration | ObjectLiteralExpression; + } + override set parent(value) { + super.parent = value; + } + + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get name(): PropertyName { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get body(): Block | undefined { + return this.ast.data.body?.node; + } + set body(value) { + this.ast.data.body = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } + get flowNode(): FlowNode | undefined { + return this.ast.data.flowNode; + } + set flowNode(value: FlowNode | undefined) { + this.ast.data.flowNode = value; + } + get endFlowNode(): ts.FlowNode | undefined { + return this.ast.data.endFlowNode; + } + set endFlowNode(value) { + this.ast.data.endFlowNode = value; + } + get returnFlowNode(): ts.FlowNode | undefined { + return this.ast.data.returnFlowNode; + } + set returnFlowNode(value) { + this.ast.data.returnFlowNode = value; + } } /** @internal */ @@ -2661,7 +3987,6 @@ export class AstGetAccessorDeclarationData extends AstData { (propagateChildFlags(this.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | (this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); } - } } @@ -2678,39 +4003,103 @@ export class SetAccessorDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get name(): PropertyName { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get body(): Block | undefined { return this.ast.data.body?.node; } - set body(value) { this.ast.data.body = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } - get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } - set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } - get endFlowNode(): ts.FlowNode | undefined { return this.ast.data.endFlowNode; } - set endFlowNode(value) { this.ast.data.endFlowNode = value; } - get returnFlowNode(): ts.FlowNode | undefined { return this.ast.data.returnFlowNode; } - set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } + override get parent() { + return super.parent as ClassLikeDeclaration | ObjectLiteralExpression; + } + override set parent(value) { + super.parent = value; + } + + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get name(): PropertyName { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get body(): Block | undefined { + return this.ast.data.body?.node; + } + set body(value) { + this.ast.data.body = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } + get flowNode(): FlowNode | undefined { + return this.ast.data.flowNode; + } + set flowNode(value: FlowNode | undefined) { + this.ast.data.flowNode = value; + } + get endFlowNode(): ts.FlowNode | undefined { + return this.ast.data.endFlowNode; + } + set endFlowNode(value) { + this.ast.data.endFlowNode = value; + } + get returnFlowNode(): ts.FlowNode | undefined { + return this.ast.data.returnFlowNode; + } + set returnFlowNode(value) { + this.ast.data.returnFlowNode = value; + } } /** @internal */ @@ -2749,8 +4138,7 @@ export class AstSetAccessorDeclarationData extends AstData { /** @internal */ export type AccessorDeclaration = | GetAccessorDeclaration - | SetAccessorDeclaration - ; + | SetAccessorDeclaration; /** @internal */ export type AstAccessorDeclaration = AstNodeOneOf; @@ -2765,29 +4153,73 @@ export class IndexSignatureDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode { return this.ast.data.type?.node!; } - set type(value) { this.ast.data.type = value?.ast; } - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + override get parent() { + return super.parent as ObjectTypeDeclaration; + } + override set parent(value) { + super.parent = value; + } + + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode { + return this.ast.data.type?.node!; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -2814,27 +4246,67 @@ export class ClassStaticBlockDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } - get endFlowNode(): ts.FlowNode | undefined { return this.ast.data.endFlowNode; } - set endFlowNode(value) { this.ast.data.endFlowNode = value; } - get returnFlowNode(): ts.FlowNode | undefined { return this.ast.data.returnFlowNode; } - set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } + override get parent() { + return super.parent as ClassLikeDeclaration; + } + override set parent(value) { + super.parent = value; + } + + get body(): Block { + return this.ast.data.body?.node; + } + set body(value) { + this.ast.data.body = value?.ast; + } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } + get endFlowNode(): ts.FlowNode | undefined { + return this.ast.data.endFlowNode; + } + set endFlowNode(value) { + this.ast.data.endFlowNode = value; + } + get returnFlowNode(): ts.FlowNode | undefined { + return this.ast.data.returnFlowNode; + } + set returnFlowNode(value) { + this.ast.data.returnFlowNode = value; + } } /** @internal */ @@ -2862,14 +4334,26 @@ export class AstClassStaticBlockDeclarationData extends AstData { export class ImportTypeAssertionContainer extends Node implements ts.ImportTypeAssertionContainer { declare readonly ast: AstImportTypeAssertionContainer; - override get parent() { return super.parent as ImportTypeNode; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as ImportTypeNode; + } + override set parent(value) { + super.parent = value; + } /** @deprecated */ - get assertClause(): ImportAttributes { return this.ast.data.assertClause?.node; } - set assertClause(value) { this.ast.data.assertClause = value?.ast; } - get multiLine(): boolean { return this.ast.data.multiLine; } - set multiLine(value) { this.ast.data.multiLine = value; } + get assertClause(): ImportAttributes { + return this.ast.data.assertClause?.node; + } + set assertClause(value) { + this.ast.data.assertClause = value?.ast; + } + get multiLine(): boolean { + return this.ast.data.multiLine; + } + set multiLine(value) { + this.ast.data.multiLine = value; + } } /** @@ -2893,19 +4377,43 @@ export class ImportTypeNode extends Node | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get attributes(): ImportAttributes | undefined { + return this.ast.data.attributes?.node; + } + set attributes(value) { + this.ast.data.attributes = value?.ast; + } + get assertions(): ImportTypeAssertionContainer | undefined { + return this.ast.data.assertions?.node; + } + set assertions(value) { + this.ast.data.assertions = value?.ast; + } + get qualifier(): Identifier | QualifiedName | undefined { + return this.ast.data.qualifier?.node; + } + set qualifier(value) { + this.ast.data.qualifier = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } } /** @internal */ @@ -2948,26 +4456,66 @@ export class FunctionTypeNode extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -2994,26 +4542,66 @@ export class ConstructorTypeNode extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -3037,10 +4625,18 @@ export class TypeReferenceNode extends Node | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get typeName(): Identifier | QualifiedName { + return this.ast.data.typeName?.node; + } + set typeName(value) { + this.ast.data.typeName = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } } /** @internal */ @@ -3055,15 +4651,31 @@ export class TypePredicateNode extends Node | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get exprName(): Identifier | QualifiedName { + return this.ast.data.exprName?.node; + } + set exprName(value) { + this.ast.data.exprName = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } } /** @internal */ @@ -3098,12 +4718,24 @@ export class TypeLiteralNode extends Node { return this.ast.data.members?.nodes!; } // TODO: remove '!' - set members(value) { this.ast.data.members = value?.ast; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get members(): NodeArray { + return this.ast.data.members?.nodes!; + } // TODO: remove '!' + set members(value) { + this.ast.data.members = value?.ast; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -3119,8 +4751,12 @@ export class ArrayTypeNode extends Node { return this.ast.data.elements?.nodes!; } // TODO: remove '!' - set elements(value: NodeArray) { this.ast.data.elements = value?.ast; } + get elements(): NodeArray { + return this.ast.data.elements?.nodes!; + } // TODO: remove '!' + set elements(value: NodeArray) { + this.ast.data.elements = value?.ast; + } } /** @internal */ @@ -3151,20 +4791,48 @@ export class NamedTupleMember extends Node declare _typeNodeBrand: any; - get type(): TypeNode { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } + get type(): TypeNode { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } } /** @internal */ @@ -3215,8 +4891,12 @@ export class UnionTypeNode extends Node { return this.ast.data.types?.nodes!; } // TODO: remove '!' - set types(value) { this.ast.data.types = value?.ast; } + get types(): NodeArray { + return this.ast.data.types?.nodes!; + } // TODO: remove '!' + set types(value) { + this.ast.data.types = value?.ast; + } } /** @internal */ @@ -3230,8 +4910,12 @@ export class IntersectionTypeNode extends Node { return this.ast.data.types?.nodes!; } // TODO: remove '!' - set types(value) { this.ast.data.types = value?.ast; } + get types(): NodeArray { + return this.ast.data.types?.nodes!; + } // TODO: remove '!' + set types(value) { + this.ast.data.types = value?.ast; + } } /** @internal */ @@ -3246,18 +4930,42 @@ export class ConditionalTypeNode extends Node | undefined { return this.ast.data.members?.nodes; } - set members(value) { this.ast.data.members = value?.ast; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get readonlyToken(): PlusToken | MinusToken | ReadonlyKeyword | undefined { + return this.ast.data.readonlyToken?.node; + } + set readonlyToken(value) { + this.ast.data.readonlyToken = value?.ast; + } + get typeParameter(): TypeParameterDeclaration { + return this.ast.data.typeParameter?.node; + } + set typeParameter(value) { + this.ast.data.typeParameter = value?.ast; + } + get nameType(): TypeNode | undefined { + return this.ast.data.nameType?.node; + } + set nameType(value) { + this.ast.data.nameType = value?.ast; + } + get questionToken(): QuestionToken | PlusToken | MinusToken | undefined { + return this.ast.data.questionToken?.node; + } + set questionToken(value) { + this.ast.data.questionToken = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get members(): NodeArray | undefined { + return this.ast.data.members?.nodes; + } + set members(value) { + this.ast.data.members = value?.ast; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -3386,8 +5158,12 @@ export class LiteralTypeNode extends Node { return this.ast.data.templateSpans?.nodes!; } // TODO: remove '!' - set templateSpans(value) { this.ast.data.templateSpans = value?.ast; } + get head(): TemplateHead { + return this.ast.data.head?.node; + } + set head(value) { + this.ast.data.head = value?.ast; + } + get templateSpans(): NodeArray { + return this.ast.data.templateSpans?.nodes!; + } // TODO: remove '!' + set templateSpans(value) { + this.ast.data.templateSpans = value?.ast; + } } /** @internal */ @@ -3430,13 +5214,25 @@ export class TemplateLiteralTypeSpan extends Node; @@ -3480,10 +5275,18 @@ export class PrefixUnaryExpression extends Node { return this.ast.data.colonToken?.node; } - set colonToken(value) { this.ast.data.colonToken = value?.ast; } - get whenFalse(): Expression { return this.ast.data.whenFalse?.node; } - set whenFalse(value) { this.ast.data.whenFalse = value?.ast; } + get condition(): Expression { + return this.ast.data.condition?.node; + } + set condition(value) { + this.ast.data.condition = value?.ast; + } + get questionToken(): QuestionToken { + return this.ast.data.questionToken?.node; + } + set questionToken(value) { + this.ast.data.questionToken = value?.ast; + } + get whenTrue(): Expression { + return this.ast.data.whenTrue?.node; + } + set whenTrue(value) { + this.ast.data.whenTrue = value?.ast; + } + get colonToken(): Token { + return this.ast.data.colonToken?.node; + } + set colonToken(value) { + this.ast.data.colonToken = value?.ast; + } + get whenFalse(): Expression { + return this.ast.data.whenFalse?.node; + } + set whenFalse(value) { + this.ast.data.whenFalse = value?.ast; + } } /** @internal */ @@ -3788,8 +5667,7 @@ export class AstConditionalExpressionData extends AstData { } /** @internal */ -export type FunctionBody = - | Block; +export type FunctionBody = Block; /** @internal */ export type AstFunctionBody = AstNodeOneOf; @@ -3818,38 +5696,102 @@ export class FunctionExpression extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get asteriskToken(): AsteriskToken | undefined { return this.ast.data.asteriskToken?.node; } - set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } - get name(): Identifier | undefined { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get body(): Block { return this.ast.data.body?.node; } - set body(value) { this.ast.data.body = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } - get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } - set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } - get endFlowNode(): ts.FlowNode | undefined { return this.ast.data.endFlowNode; } - set endFlowNode(value) { this.ast.data.endFlowNode = value; } - get returnFlowNode(): ts.FlowNode | undefined { return this.ast.data.returnFlowNode; } - set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get asteriskToken(): AsteriskToken | undefined { + return this.ast.data.asteriskToken?.node; + } + set asteriskToken(value) { + this.ast.data.asteriskToken = value?.ast; + } + get name(): Identifier | undefined { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + /** @internal */ get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + /** @internal */ set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get body(): Block { + return this.ast.data.body?.node; + } + set body(value) { + this.ast.data.body = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } + get flowNode(): FlowNode | undefined { + return this.ast.data.flowNode; + } + set flowNode(value: FlowNode | undefined) { + this.ast.data.flowNode = value; + } + get endFlowNode(): ts.FlowNode | undefined { + return this.ast.data.endFlowNode; + } + set endFlowNode(value) { + this.ast.data.endFlowNode = value; + } + get returnFlowNode(): ts.FlowNode | undefined { + return this.ast.data.returnFlowNode; + } + set returnFlowNode(value) { + this.ast.data.returnFlowNode = value; + } } /** @internal */ @@ -3907,36 +5849,96 @@ export class ArrowFunction extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get equalsGreaterThanToken(): EqualsGreaterThanToken { return this.ast.data.equalsGreaterThanToken?.node; } - set equalsGreaterThanToken(value) { this.ast.data.equalsGreaterThanToken = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get body(): Block | Expression { return this.ast.data.body?.node; } - set body(value) { this.ast.data.body = value?.ast; } - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } - get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } - set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } - get endFlowNode(): ts.FlowNode | undefined { return this.ast.data.endFlowNode; } - set endFlowNode(value) { this.ast.data.endFlowNode = value; } - get returnFlowNode(): ts.FlowNode | undefined { return this.ast.data.returnFlowNode; } - set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get equalsGreaterThanToken(): EqualsGreaterThanToken { + return this.ast.data.equalsGreaterThanToken?.node; + } + set equalsGreaterThanToken(value) { + this.ast.data.equalsGreaterThanToken = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get body(): Block | Expression { + return this.ast.data.body?.node; + } + set body(value) { + this.ast.data.body = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } + get flowNode(): FlowNode | undefined { + return this.ast.data.flowNode; + } + set flowNode(value: FlowNode | undefined) { + this.ast.data.flowNode = value; + } + get endFlowNode(): ts.FlowNode | undefined { + return this.ast.data.endFlowNode; + } + set endFlowNode(value) { + this.ast.data.endFlowNode = value; + } + get returnFlowNode(): ts.FlowNode | undefined { + return this.ast.data.returnFlowNode; + } + set returnFlowNode(value) { + this.ast.data.returnFlowNode = value; + } } /** @internal */ @@ -3987,12 +5989,24 @@ export class RegularExpressionLiteral extends Token; export class TemplateHead extends Token implements ts.TemplateHead { declare readonly ast: AstTemplateHead; - override get parent() { return super.parent as TemplateExpression | TemplateLiteralTypeNode; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as TemplateExpression | TemplateLiteralTypeNode; + } + override set parent(value) { + super.parent = value; + } - get text(): string { return this.ast.data.text; } - set text(value) { this.ast.data.text = value; } - get isUnterminated(): boolean | undefined { return this.ast.data.isUnterminated; } - set isUnterminated(value) { this.ast.data.isUnterminated = value; } - get hasExtendedUnicodeEscape(): boolean | undefined { return this.ast.data.hasExtendedUnicodeEscape; } - set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } - get rawText(): string | undefined { return this.ast.data.rawText; } - set rawText(value) { this.ast.data.rawText = value; } - get templateFlags(): ts.TokenFlags { return this.ast.data.templateFlags; } - set templateFlags(value) { this.ast.data.templateFlags = value; } + get text(): string { + return this.ast.data.text; + } + set text(value) { + this.ast.data.text = value; + } + get isUnterminated(): boolean | undefined { + return this.ast.data.isUnterminated; + } + set isUnterminated(value) { + this.ast.data.isUnterminated = value; + } + get hasExtendedUnicodeEscape(): boolean | undefined { + return this.ast.data.hasExtendedUnicodeEscape; + } + set hasExtendedUnicodeEscape(value) { + this.ast.data.hasExtendedUnicodeEscape = value; + } + get rawText(): string | undefined { + return this.ast.data.rawText; + } + set rawText(value) { + this.ast.data.rawText = value; + } + get templateFlags(): ts.TokenFlags { + return this.ast.data.templateFlags; + } + set templateFlags(value) { + this.ast.data.templateFlags = value; + } } /** @internal */ @@ -4229,19 +6343,43 @@ export class AstTemplateHeadData extends AstTokenData { export class TemplateMiddle extends Token implements ts.TemplateMiddle { declare readonly ast: AstTemplateMiddle; - override get parent() { return super.parent as TemplateSpan | TemplateLiteralTypeSpan; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as TemplateSpan | TemplateLiteralTypeSpan; + } + override set parent(value) { + super.parent = value; + } - get text(): string { return this.ast.data.text; } - set text(value) { this.ast.data.text = value; } - get isUnterminated(): boolean | undefined { return this.ast.data.isUnterminated; } - set isUnterminated(value) { this.ast.data.isUnterminated = value; } - get hasExtendedUnicodeEscape(): boolean | undefined { return this.ast.data.hasExtendedUnicodeEscape; } - set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } - get rawText(): string | undefined { return this.ast.data.rawText; } - set rawText(value) { this.ast.data.rawText = value; } - get templateFlags(): ts.TokenFlags { return this.ast.data.templateFlags; } - set templateFlags(value) { this.ast.data.templateFlags = value; } + get text(): string { + return this.ast.data.text; + } + set text(value) { + this.ast.data.text = value; + } + get isUnterminated(): boolean | undefined { + return this.ast.data.isUnterminated; + } + set isUnterminated(value) { + this.ast.data.isUnterminated = value; + } + get hasExtendedUnicodeEscape(): boolean | undefined { + return this.ast.data.hasExtendedUnicodeEscape; + } + set hasExtendedUnicodeEscape(value) { + this.ast.data.hasExtendedUnicodeEscape = value; + } + get rawText(): string | undefined { + return this.ast.data.rawText; + } + set rawText(value) { + this.ast.data.rawText = value; + } + get templateFlags(): ts.TokenFlags { + return this.ast.data.templateFlags; + } + set templateFlags(value) { + this.ast.data.templateFlags = value; + } } /** @internal */ @@ -4261,19 +6399,43 @@ export class AstTemplateMiddleData extends AstTokenData { export class TemplateTail extends Token implements ts.TemplateTail { declare readonly ast: AstTemplateTail; - override get parent() { return super.parent as TemplateSpan | TemplateLiteralTypeSpan; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as TemplateSpan | TemplateLiteralTypeSpan; + } + override set parent(value) { + super.parent = value; + } - get text(): string { return this.ast.data.text; } - set text(value) { this.ast.data.text = value; } - get isUnterminated(): boolean | undefined { return this.ast.data.isUnterminated; } - set isUnterminated(value) { this.ast.data.isUnterminated = value; } - get hasExtendedUnicodeEscape(): boolean | undefined { return this.ast.data.hasExtendedUnicodeEscape; } - set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } - get rawText(): string | undefined { return this.ast.data.rawText; } - set rawText(value) { this.ast.data.rawText = value; } - get templateFlags(): ts.TokenFlags { return this.ast.data.templateFlags; } - set templateFlags(value) { this.ast.data.templateFlags = value; } + get text(): string { + return this.ast.data.text; + } + set text(value) { + this.ast.data.text = value; + } + get isUnterminated(): boolean | undefined { + return this.ast.data.isUnterminated; + } + set isUnterminated(value) { + this.ast.data.isUnterminated = value; + } + get hasExtendedUnicodeEscape(): boolean | undefined { + return this.ast.data.hasExtendedUnicodeEscape; + } + set hasExtendedUnicodeEscape(value) { + this.ast.data.hasExtendedUnicodeEscape = value; + } + get rawText(): string | undefined { + return this.ast.data.rawText; + } + set rawText(value) { + this.ast.data.rawText = value; + } + get templateFlags(): ts.TokenFlags { + return this.ast.data.templateFlags; + } + set templateFlags(value) { + this.ast.data.templateFlags = value; + } } /** @internal */ @@ -4300,10 +6462,18 @@ export class TemplateExpression extends Node { return this.ast.data.templateSpans?.nodes!; } // TODO: remove `!` - set templateSpans(value) { this.ast.data.templateSpans = value?.ast; } + get head(): TemplateHead { + return this.ast.data.head?.node; + } + set head(value) { + this.ast.data.head = value?.ast; + } + get templateSpans(): NodeArray { + return this.ast.data.templateSpans?.nodes!; // TODO: remove `!` + } + set templateSpans(value) { + this.ast.data.templateSpans = value?.ast; + } } /** @internal */ @@ -4322,13 +6492,25 @@ export class AstTemplateExpressionData extends AstData { export class TemplateSpan extends Node implements ts.TemplateSpan { declare readonly ast: AstTemplateSpan; - override get parent() { return super.parent as TemplateExpression; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as TemplateExpression; + } + override set parent(value) { + super.parent = value; + } - get expression(): Expression { return this.ast.data.expression?.node; } - set expression(value) { this.ast.data.expression = value?.ast; } - get literal(): TemplateMiddle | TemplateTail { return this.ast.data.literal?.node; } - set literal(value) { this.ast.data.literal = value?.ast; } + get expression(): Expression { + return this.ast.data.expression?.node; + } + set expression(value) { + this.ast.data.expression = value?.ast; + } + get literal(): TemplateMiddle | TemplateTail { + return this.ast.data.literal?.node; + } + set literal(value) { + this.ast.data.literal = value?.ast; + } } /** @internal */ @@ -4355,10 +6537,18 @@ export class ParenthesizedExpression extends Node { return this.ast.data.elements?.nodes!; } // TODO: remove '!' - set elements(value: NodeArray) { this.ast.data.elements = value?.ast; } - get multiLine(): boolean | undefined { return this.ast.data.multiLine; } - set multiLine(value) { this.ast.data.multiLine = value; } + get elements(): NodeArray { + return this.ast.data.elements?.nodes!; + } // TODO: remove '!' + set elements(value: NodeArray) { + this.ast.data.elements = value?.ast; + } + get multiLine(): boolean | undefined { + return this.ast.data.multiLine; + } + set multiLine(value) { + this.ast.data.multiLine = value; + } } /** @internal */ @@ -4413,11 +6611,19 @@ export class SpreadElement extends Node; @@ -4465,16 +6670,36 @@ export class ObjectLiteralExpression extends Node { return this.ast.data.properties?.nodes!; } // TODO: remove '!' - set properties(value) { this.ast.data.properties = value?.ast; } - get multiLine(): boolean | undefined { return this.ast.data.multiLine; } - set multiLine(value) { this.ast.data.multiLine = value; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get properties(): NodeArray { + return this.ast.data.properties?.nodes!; + } // TODO: remove '!' + set properties(value) { + this.ast.data.properties = value?.ast; + } + get multiLine(): boolean | undefined { + return this.ast.data.multiLine; + } + set multiLine(value) { + this.ast.data.multiLine = value; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -4504,20 +6729,48 @@ export class PropertyAccessExpression extends Node | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get arguments(): NodeArray { return this.ast.data.arguments?.nodes!; } // TODO: remove `!` - set arguments(value) { this.ast.data.arguments = value?.ast; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get expression(): LeftHandSideExpression { + return this.ast.data.expression?.node; + } + set expression(value) { + this.ast.data.expression = value?.ast; + } + get questionDotToken(): QuestionDotToken | undefined { + return this.ast.data.questionDotToken?.node; + } + set questionDotToken(value) { + this.ast.data.questionDotToken = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get arguments(): NodeArray { + return this.ast.data.arguments?.nodes!; // TODO: remove `!` + } + set arguments(value) { + this.ast.data.arguments = value?.ast; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -4711,8 +7016,9 @@ export class AstCallExpressionData extends AstData { if (this.typeArguments) { transformFlags |= TransformFlags.ContainsTypeScript; } - if ((this.expression.kind === SyntaxKind.PropertyAccessExpression || - this.expression.kind === SyntaxKind.ElementAccessExpression) && + if ( + (this.expression.kind === SyntaxKind.PropertyAccessExpression || + this.expression.kind === SyntaxKind.ElementAccessExpression) && (this.expression as AstNode).data.expression.kind === SyntaxKind.SuperKeyword ) { transformFlags |= TransformFlags.ContainsLexicalThis; @@ -4764,10 +7070,18 @@ export class ExpressionWithTypeArguments extends Node | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get expression(): LeftHandSideExpression { + return this.ast.data.expression?.node; + } + set expression(value) { + this.ast.data.expression = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } } /** @internal */ @@ -4794,16 +7108,36 @@ export class NewExpression extends Node | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get arguments(): NodeArray | undefined { return this.ast.data.arguments?.nodes; } - set arguments(value) { this.ast.data.arguments = value?.ast; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get expression(): LeftHandSideExpression { + return this.ast.data.expression?.node; + } + set expression(value) { + this.ast.data.expression = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get arguments(): NodeArray | undefined { + return this.ast.data.arguments?.nodes; + } + set arguments(value) { + this.ast.data.arguments = value?.ast; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -4830,8 +7164,7 @@ export class AstNewExpressionData extends AstData { /** @internal */ export type TemplateLiteral = | TemplateExpression - | NoSubstitutionTemplateLiteral - ; + | NoSubstitutionTemplateLiteral; /** @internal */ export type AstTemplateLiteral = AstNodeOneOf; @@ -4846,14 +7179,30 @@ export class TaggedTemplateExpression extends Node | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get template(): NoSubstitutionTemplateLiteral | TemplateExpression { return this.ast.data.template?.node; } - set template(value) { this.ast.data.template = value?.ast; } - get questionDotToken(): QuestionDotToken | undefined { return this.ast.data.questionDotToken?.node; } - set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } + get tag(): LeftHandSideExpression { + return this.ast.data.tag?.node; + } + set tag(value) { + this.ast.data.tag = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get template(): NoSubstitutionTemplateLiteral | TemplateExpression { + return this.ast.data.template?.node; + } + set template(value) { + this.ast.data.template = value?.ast; + } + get questionDotToken(): QuestionDotToken | undefined { + return this.ast.data.questionDotToken?.node; + } + set questionDotToken(value) { + this.ast.data.questionDotToken = value?.ast; + } } /** @internal */ @@ -4884,10 +7233,18 @@ export class AsExpression extends Node i declare _unaryExpressionBrand: any; declare _expressionBrand: any; - get openingElement(): JsxOpeningElement { return this.ast.data.openingElement?.node; } - set openingElement(value: JsxOpeningElement) { this.ast.data.openingElement = value?.ast; } - get children(): NodeArray { return this.ast.data.children.nodes; } - set children(value: NodeArray) { this.ast.data.children = value?.ast; } - get closingElement(): JsxClosingElement { return this.ast.data.closingElement?.node; } - set closingElement(value: JsxClosingElement) { this.ast.data.closingElement = value?.ast; } + get openingElement(): JsxOpeningElement { + return this.ast.data.openingElement?.node; + } + set openingElement(value: JsxOpeningElement) { + this.ast.data.openingElement = value?.ast; + } + get children(): NodeArray { + return this.ast.data.children.nodes; + } + set children(value: NodeArray) { + this.ast.data.children = value?.ast; + } + get closingElement(): JsxClosingElement { + return this.ast.data.closingElement?.node; + } + set closingElement(value: JsxClosingElement) { + this.ast.data.closingElement = value?.ast; + } } /** @internal */ @@ -5062,8 +7463,7 @@ export class AstJsxElementData extends AstData { /** @internal */ export type JsxOpeningLikeElement = | JsxSelfClosingElement - | JsxOpeningElement - ; + | JsxOpeningElement; /** @internal */ export type AstJsxOpeningLikeElement = AstNodeOneOf; @@ -5121,15 +7521,31 @@ export class JsxAttributes extends Node { return this.ast.data.properties.nodes; } - set properties(value) { this.ast.data.properties = value?.ast; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get properties(): NodeArray { + return this.ast.data.properties.nodes; + } + set properties(value) { + this.ast.data.properties = value?.ast; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -5149,10 +7565,18 @@ export class AstJsxAttributesData extends AstData { export class JsxNamespacedName extends Node implements ts.JsxNamespacedName { declare readonly ast: AstJsxNamespacedName; - get name(): Identifier { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get namespace(): Identifier { return this.ast.data.namespace?.node; } - set namespace(value) { this.ast.data.namespace = value?.ast; } + get name(): Identifier { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get namespace(): Identifier { + return this.ast.data.namespace?.node; + } + set namespace(value) { + this.ast.data.namespace = value?.ast; + } } /** @internal */ @@ -5173,15 +7597,31 @@ export class JsxOpeningElement extends Node | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get attributes(): JsxAttributes { return this.ast.data.attributes?.node; } - set attributes(value) { this.ast.data.attributes = value?.ast; } + get tagName(): JsxTagNameExpression { + return this.ast.data.tagName?.node; + } + set tagName(value) { + this.ast.data.tagName = value.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get attributes(): JsxAttributes { + return this.ast.data.attributes?.node; + } + set attributes(value) { + this.ast.data.attributes = value?.ast; + } } /** @internal */ @@ -5206,11 +7646,19 @@ export class AstJsxOpeningElementData extends AstData { export class JsxClosingElement extends Node implements ts.JsxClosingElement { declare readonly ast: AstJsxClosingElement; - override get parent() { return super.parent as JsxElement; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as JsxElement; + } + override set parent(value) { + super.parent = value; + } - get tagName(): JsxTagNameExpression { return this.ast.data.tagName?.node; } - set tagName(value) { this.ast.data.tagName = value.ast; } + get tagName(): JsxTagNameExpression { + return this.ast.data.tagName?.node; + } + set tagName(value) { + this.ast.data.tagName = value.ast; + } } /** @internal */ @@ -5234,12 +7682,24 @@ export class JsxSelfClosingElement extends Node | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get attributes(): JsxAttributes { return this.ast.data.attributes?.node; } - set attributes(value) { this.ast.data.attributes = value?.ast; } + get tagName(): JsxTagNameExpression { + return this.ast.data.tagName?.node; + } + set tagName(value) { + this.ast.data.tagName = value.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get attributes(): JsxAttributes { + return this.ast.data.attributes?.node; + } + set attributes(value) { + this.ast.data.attributes = value?.ast; + } } /** @internal */ @@ -5271,12 +7731,24 @@ export class JsxFragment extends Node { return this.ast.data.children.nodes; } - set children(value: NodeArray) { this.ast.data.children = value?.ast; } - get closingFragment(): JsxClosingFragment { return this.ast.data.closingFragment?.node; } - set closingFragment(value: JsxClosingFragment) { this.ast.data.closingFragment = value?.ast; } + get openingFragment(): JsxOpeningFragment { + return this.ast.data.openingFragment?.node; + } + set openingFragment(value: JsxOpeningFragment) { + this.ast.data.openingFragment = value?.ast; + } + get children(): NodeArray { + return this.ast.data.children.nodes; + } + set children(value: NodeArray) { + this.ast.data.children = value?.ast; + } + get closingFragment(): JsxClosingFragment { + return this.ast.data.closingFragment?.node; + } + set closingFragment(value: JsxClosingFragment) { + this.ast.data.closingFragment = value?.ast; + } } /** @internal */ @@ -5299,8 +7771,12 @@ export class JsxOpeningFragment extends Node implements ts.JsxText { declare readonly ast: AstJsxText; - override get parent() { return super.parent as JsxElement | JsxFragment; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as JsxElement | JsxFragment; + } + override set parent(value) { + super.parent = value; + } - get text(): string { return this.ast.data.text; } - set text(value) { this.ast.data.text = value; } - get isUnterminated(): boolean | undefined { return this.ast.data.isUnterminated; } - set isUnterminated(value) { this.ast.data.isUnterminated = value; } - get hasExtendedUnicodeEscape(): boolean | undefined { return this.ast.data.hasExtendedUnicodeEscape; } - set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } - get containsOnlyTriviaWhiteSpaces(): boolean { return this.ast.data.containsOnlyTriviaWhiteSpaces; } - set containsOnlyTriviaWhiteSpaces(value) { this.ast.data.containsOnlyTriviaWhiteSpaces = value; } + get text(): string { + return this.ast.data.text; + } + set text(value) { + this.ast.data.text = value; + } + get isUnterminated(): boolean | undefined { + return this.ast.data.isUnterminated; + } + set isUnterminated(value) { + this.ast.data.isUnterminated = value; + } + get hasExtendedUnicodeEscape(): boolean | undefined { + return this.ast.data.hasExtendedUnicodeEscape; + } + set hasExtendedUnicodeEscape(value) { + this.ast.data.hasExtendedUnicodeEscape = value; + } + get containsOnlyTriviaWhiteSpaces(): boolean { + return this.ast.data.containsOnlyTriviaWhiteSpaces; + } + set containsOnlyTriviaWhiteSpaces(value) { + this.ast.data.containsOnlyTriviaWhiteSpaces = value; + } } /** @internal */ @@ -5460,20 +8000,17 @@ export type JsxChild = | JsxExpression | JsxElement | JsxSelfClosingElement - | JsxFragment - ; + | JsxFragment; /** @internal */ export type AstJsxChild = AstNodeOneOf; - /** @internal */ export type IterationStatement = | DoStatement | WhileStatement | ForStatement - | ForInOrOfStatement - ; + | ForInOrOfStatement; /** @internal */ export type AstIterationStatement = AstNodeOneOf; @@ -5485,8 +8022,12 @@ export class EmptyStatement extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get name(): Identifier | undefined { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -5570,16 +8139,36 @@ export class Block extends Node implements JSDoc declare _jsdocContainerBrand: any; declare _localsContainerBrand: any; - get statements(): NodeArray { return this.ast.data.statements?.nodes!; } // TODO: remove `!` - set statements(value) { this.ast.data.statements = value?.ast; } - get multiLine(): boolean | undefined { return this.ast.data.multiLine; } - set multiLine(value) { this.ast.data.multiLine = value; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get statements(): NodeArray { + return this.ast.data.statements?.nodes!; // TODO: remove `!` + } + set statements(value) { + this.ast.data.statements = value?.ast; + } + get multiLine(): boolean | undefined { + return this.ast.data.multiLine; + } + set multiLine(value) { + this.ast.data.multiLine = value; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -5604,14 +8193,30 @@ export class VariableStatement extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get declarationList(): VariableDeclarationList { return this.ast.data.declarationList?.node; } - set declarationList(value) { this.ast.data.declarationList = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } - set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get declarationList(): VariableDeclarationList { + return this.ast.data.declarationList?.node; + } + set declarationList(value) { + this.ast.data.declarationList = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get flowNode(): FlowNode | undefined { + return this.ast.data.flowNode; + } + set flowNode(value: FlowNode | undefined) { + this.ast.data.flowNode = value; + } } /** @internal */ @@ -5640,12 +8245,24 @@ export class ExpressionStatement extends Node; - /** @internal */ export class ForStatement extends Node implements JSDocContainer, LocalsContainer, FlowContainer, ts.ForStatement { declare readonly ast: AstForStatement; @@ -5782,22 +8449,54 @@ export class ForStatement extends Node; @@ -5838,20 +8536,48 @@ export class ForInStatement extends Node impl declare _localsContainerBrand: any; - override get parent() { return super.parent as SwitchStatement; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as SwitchStatement; + } + override set parent(value) { + super.parent = value; + } - get clauses(): NodeArray { return this.ast.data.clauses?.nodes!; } // TODO: remove '!' - set clauses(value) { this.ast.data.clauses = value?.ast; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get clauses(): NodeArray { + return this.ast.data.clauses?.nodes!; + } // TODO: remove '!' + set clauses(value) { + this.ast.data.clauses = value?.ast; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -6121,17 +8967,37 @@ export class CaseClause extends Node i declare _jsdocContainerBrand: any; - override get parent() { return super.parent as CaseBlock; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as CaseBlock; + } + override set parent(value) { + super.parent = value; + } - get expression(): Expression { return this.ast.data.expression?.node; } - set expression(value) { this.ast.data.expression = value?.ast; } - get statements(): NodeArray { return this.ast.data.statements?.nodes!; } // TODO: remove `!` - set statements(value) { this.ast.data.statements = value?.ast; } - get fallthroughFlowNode(): ts.FlowNode | undefined { return this.ast.data.fallthroughFlowNode; } - set fallthroughFlowNode(value) { this.ast.data.fallthroughFlowNode = value; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get expression(): Expression { + return this.ast.data.expression?.node; + } + set expression(value) { + this.ast.data.expression = value?.ast; + } + get statements(): NodeArray { + return this.ast.data.statements?.nodes!; // TODO: remove `!` + } + set statements(value) { + this.ast.data.statements = value?.ast; + } + get fallthroughFlowNode(): ts.FlowNode | undefined { + return this.ast.data.fallthroughFlowNode; + } + set fallthroughFlowNode(value) { + this.ast.data.fallthroughFlowNode = value; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } } /** @internal */ @@ -6152,13 +9018,25 @@ export class AstCaseClauseData extends AstData { export class DefaultClause extends Node implements ts.DefaultClause { declare readonly ast: AstDefaultClause; - override get parent() { return super.parent as CaseBlock; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as CaseBlock; + } + override set parent(value) { + super.parent = value; + } - get statements(): NodeArray { return this.ast.data.statements?.nodes!; } // TODO: remove `!` - set statements(value) { this.ast.data.statements = value?.ast; } - get fallthroughFlowNode(): ts.FlowNode | undefined { return this.ast.data.fallthroughFlowNode; } - set fallthroughFlowNode(value) { this.ast.data.fallthroughFlowNode = value; } + get statements(): NodeArray { + return this.ast.data.statements?.nodes!; // TODO: remove `!` + } + set statements(value) { + this.ast.data.statements = value?.ast; + } + get fallthroughFlowNode(): ts.FlowNode | undefined { + return this.ast.data.fallthroughFlowNode; + } + set fallthroughFlowNode(value) { + this.ast.data.fallthroughFlowNode = value; + } } /** @internal */ @@ -6175,8 +9053,7 @@ export class AstDefaultClauseData extends AstData { /** @internal */ export type CaseOrDefaultClause = | CaseClause - | DefaultClause - ; + | DefaultClause; /** @internal */ export type AstCaseOrDefaultClause = AstNodeOneOf; @@ -6189,14 +9066,30 @@ export class LabeledStatement extends Node; @@ -6361,22 +9305,54 @@ export class ClassDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get name(): Identifier | undefined { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get heritageClauses(): NodeArray | undefined { return this.ast.data.heritageClauses?.nodes; } - set heritageClauses(value) { this.ast.data.heritageClauses = value?.ast; } - get members(): NodeArray { return this.ast.data.members?.nodes!; } // TODO: remove `!` - set members(value: NodeArray) { this.ast.data.members = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get name(): Identifier | undefined { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get heritageClauses(): NodeArray | undefined { + return this.ast.data.heritageClauses?.nodes; + } + set heritageClauses(value) { + this.ast.data.heritageClauses = value?.ast; + } + get members(): NodeArray { + return this.ast.data.members?.nodes!; // TODO: remove `!` + } + set members(value: NodeArray) { + this.ast.data.members = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -6424,22 +9400,54 @@ export class ClassExpression extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get name(): Identifier | undefined { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get heritageClauses(): NodeArray | undefined { return this.ast.data.heritageClauses?.nodes; } - set heritageClauses(value) { this.ast.data.heritageClauses = value?.ast; } - get members(): NodeArray { return this.ast.data.members?.nodes!; } // TODO: remove `!` - set members(value) { this.ast.data.members = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get name(): Identifier | undefined { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get heritageClauses(): NodeArray | undefined { + return this.ast.data.heritageClauses?.nodes; + } + set heritageClauses(value) { + this.ast.data.heritageClauses = value?.ast; + } + get members(): NodeArray { + return this.ast.data.members?.nodes!; // TODO: remove `!` + } + set members(value) { + this.ast.data.members = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -6491,22 +9499,54 @@ export class InterfaceDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get name(): Identifier { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get heritageClauses(): NodeArray | undefined { return this.ast.data.heritageClauses?.nodes; } - set heritageClauses(value) { this.ast.data.heritageClauses = value?.ast; } - get members(): NodeArray { return this.ast.data.members?.nodes!; } // TODO: remove '!' - set members(value) { this.ast.data.members = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get name(): Identifier { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get heritageClauses(): NodeArray | undefined { + return this.ast.data.heritageClauses?.nodes; + } + set heritageClauses(value) { + this.ast.data.heritageClauses = value?.ast; + } + get members(): NodeArray { + return this.ast.data.members?.nodes!; + } // TODO: remove '!' + set members(value) { + this.ast.data.members = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -6526,13 +9566,25 @@ export class AstInterfaceDeclarationData extends AstTypeScriptNodeData { export class HeritageClause extends Node implements ts.HeritageClause { declare readonly ast: AstHeritageClause; - override get parent() { return super.parent as InterfaceDeclaration | ClassLikeDeclaration; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as InterfaceDeclaration | ClassLikeDeclaration; + } + override set parent(value) { + super.parent = value; + } - get token(): ts.SyntaxKind.ExtendsKeyword | ts.SyntaxKind.ImplementsKeyword { return this.ast.data.token; } - set token(value) { this.ast.data.token = value; } - get types(): NodeArray { return this.ast.data.types?.nodes!; } // TODO: remove '!' - set types(value) { this.ast.data.types = value?.ast; } + get token(): ts.SyntaxKind.ExtendsKeyword | ts.SyntaxKind.ImplementsKeyword { + return this.ast.data.token; + } + set token(value) { + this.ast.data.token = value; + } + get types(): NodeArray { + return this.ast.data.types?.nodes!; + } // TODO: remove '!' + set types(value) { + this.ast.data.types = value?.ast; + } } /** @internal */ @@ -6561,24 +9613,60 @@ export class TypeAliasDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get name(): Identifier { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get type(): TypeNode { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get name(): Identifier { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get type(): TypeNode { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -6603,18 +9691,42 @@ export class EnumDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get name(): Identifier { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get members(): NodeArray { return this.ast.data.members?.nodes!; } // TODO: remove '!' - set members(value) { this.ast.data.members = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get name(): Identifier { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get members(): NodeArray { + return this.ast.data.members?.nodes!; + } // TODO: remove '!' + set members(value) { + this.ast.data.members = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -6644,19 +9756,43 @@ export class EnumMember extends Node i declare _declarationBrand: any; declare _jsdocContainerBrand: any; - override get parent() { return super.parent as EnumDeclaration; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as EnumDeclaration; + } + override set parent(value) { + super.parent = value; + } - get name(): PropertyName { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get initializer(): Expression | undefined { return this.ast.data.initializer?.node; } - set initializer(value) { this.ast.data.initializer = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get name(): PropertyName { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get initializer(): Expression | undefined { + return this.ast.data.initializer?.node; + } + set initializer(value) { + this.ast.data.initializer = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -6678,8 +9814,7 @@ export class AstEnumMemberData extends AstData { /** @internal */ export type ModuleName = | Identifier - | StringLiteral - ; + | StringLiteral; /** @internal */ export type AstModuleName = AstNodeOneOf; @@ -6687,8 +9822,7 @@ export type AstModuleName = AstNodeOneOf; /** @internal */ export type ModuleBody = | NamespaceBody - | JSDocNamespaceBody - ; + | JSDocNamespaceBody; /** @internal */ export type AstModuleBody = AstNodeOneOf; @@ -6702,25 +9836,61 @@ export class ModuleDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get name(): ModuleName { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get body(): ModuleBody | JSDocNamespaceDeclaration | undefined { return this.ast.data.body?.node; } - set body(value) { this.ast.data.body = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get name(): ModuleName { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get body(): ModuleBody | JSDocNamespaceDeclaration | undefined { + return this.ast.data.body?.node; + } + set body(value) { + this.ast.data.body = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -6753,8 +9923,7 @@ export class AstModuleDeclarationData extends AstData { /** @internal */ export type NamespaceBody = | ModuleBlock - | NamespaceDeclaration - ; + | NamespaceDeclaration; /** @internal */ export type AstNamespaceBody = AstNodeOneOf; @@ -6779,8 +9948,7 @@ export interface AstNamespaceDeclarationData extends AstModuleDeclarationData { /** @internal */ export type JSDocNamespaceBody = | Identifier - | JSDocNamespaceDeclaration - ; + | JSDocNamespaceDeclaration; /** @internal */ export type AstJSDocNamespaceBody = AstNodeOneOf; @@ -6809,13 +9977,25 @@ export class ModuleBlock extends Node { return this.ast.data.statements?.nodes!; } // TODO: remove `!` - set statements(value) { this.ast.data.statements = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + get statements(): NodeArray { + return this.ast.data.statements?.nodes!; // TODO: remove `!` + } + set statements(value) { + this.ast.data.statements = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } } /** @internal */ @@ -6831,8 +10011,7 @@ export class AstModuleBlockData extends AstData { /** @internal */ export type ModuleReference = | EntityName - | ExternalModuleReference - ; + | ExternalModuleReference; /** @internal */ export type AstModuleReference = AstNodeOneOf; @@ -6845,23 +10024,55 @@ export class ImportEqualsDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get name(): Identifier { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get isTypeOnly(): boolean { return this.ast.data.isTypeOnly; } - set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } - get moduleReference(): ModuleReference { return this.ast.data.moduleReference?.node; } - set moduleReference(value) { this.ast.data.moduleReference = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get name(): Identifier { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get isTypeOnly(): boolean { + return this.ast.data.isTypeOnly; + } + set isTypeOnly(value) { + this.ast.data.isTypeOnly = value; + } + get moduleReference(): ModuleReference { + return this.ast.data.moduleReference?.node; + } + set moduleReference(value) { + this.ast.data.moduleReference = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -6892,11 +10103,19 @@ export class AstImportEqualsDeclarationData extends AstData { export class ExternalModuleReference extends Node implements ts.ExternalModuleReference { declare readonly ast: AstExternalModuleReference; - override get parent() { return super.parent as ImportEqualsDeclaration; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as ImportEqualsDeclaration; + } + override set parent(value) { + super.parent = value; + } - get expression(): Expression { return this.ast.data.expression?.node; } - set expression(value) { this.ast.data.expression = value?.ast; } + get expression(): Expression { + return this.ast.data.expression?.node; + } + set expression(value) { + this.ast.data.expression = value?.ast; + } } /** @internal */ @@ -6917,26 +10136,62 @@ export class ImportDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get importClause(): ImportClause | undefined { return this.ast.data.importClause?.node; } - set importClause(value) { this.ast.data.importClause = value?.ast; } - get moduleSpecifier(): Expression { return this.ast.data.moduleSpecifier?.node; } - set moduleSpecifier(value) { this.ast.data.moduleSpecifier = value?.ast; } - get attributes(): ImportAttributes | undefined { return this.ast.data.attributes?.node; } - set attributes(value) { this.ast.data.attributes = value?.ast; } + override get parent() { + return super.parent as ModuleBlock | SourceFile; + } + override set parent(value) { + super.parent = value; + } + + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get importClause(): ImportClause | undefined { + return this.ast.data.importClause?.node; + } + set importClause(value) { + this.ast.data.importClause = value?.ast; + } + get moduleSpecifier(): Expression { + return this.ast.data.moduleSpecifier?.node; + } + set moduleSpecifier(value) { + this.ast.data.moduleSpecifier = value?.ast; + } + get attributes(): ImportAttributes | undefined { + return this.ast.data.attributes?.node; + } + set attributes(value) { + this.ast.data.attributes = value?.ast; + } /** @deprecated */ - get assertClause(): ImportAttributes | undefined { return this.ast.data.attributes?.node; } - set assertClause(value) { this.ast.data.attributes = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get assertClause(): ImportAttributes | undefined { + return this.ast.data.attributes?.node; + } + set assertClause(value) { + this.ast.data.attributes = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -6961,8 +10216,7 @@ export class AstImportDeclarationData extends AstData { /** @internal */ export type NamedImportBindings = | NamespaceImport - | NamedImports - ; + | NamedImports; /** @internal */ export type AstNamedImportBindings = AstNodeOneOf; @@ -6970,8 +10224,7 @@ export type AstNamedImportBindings = AstNodeOneOf; /** @internal */ export type NamedExportBindings = | NamespaceExport - | NamedExports - ; + | NamedExports; /** @internal */ export type AstNamedExportBindings = AstNodeOneOf; @@ -6982,19 +10235,43 @@ export class ImportClause extends Node; @@ -7050,13 +10326,25 @@ export type AstImportAttributeName = AstNodeOneOf; export class ImportAttribute extends Node implements ts.ImportAttribute { declare readonly ast: AstImportAttribute; - override get parent() { return super.parent as ImportAttributes; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as ImportAttributes; + } + override set parent(value) { + super.parent = value; + } - get name(): ImportAttributeName { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get value(): Expression { return this.ast.data.value?.node; } - set value(value) { this.ast.data.value = value?.ast; } + get name(): ImportAttributeName { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get value(): Expression { + return this.ast.data.value?.node; + } + set value(value) { + this.ast.data.value = value?.ast; + } } /** @internal */ @@ -7085,15 +10373,31 @@ export type AstAssertClause = AstNode; export class ImportAttributes extends Node implements ts.ImportAttributes { declare readonly ast: AstImportAttributes; - override get parent() { return super.parent as ImportDeclaration | ExportDeclaration; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as ImportDeclaration | ExportDeclaration; + } + override set parent(value) { + super.parent = value; + } - get token(): ts.SyntaxKind.WithKeyword | ts.SyntaxKind.AssertKeyword { return this.ast.data.token; } - set token(value) { this.ast.data.token = value; } - get elements(): NodeArray { return this.ast.data.elements?.nodes!; } // TODO: remove `!` - set elements(value) { this.ast.data.elements = value?.ast; } - get multiLine(): boolean | undefined { return this.ast.data.multiLine; } - set multiLine(value) { this.ast.data.multiLine = value; } + get token(): ts.SyntaxKind.WithKeyword | ts.SyntaxKind.AssertKeyword { + return this.ast.data.token; + } + set token(value) { + this.ast.data.token = value; + } + get elements(): NodeArray { + return this.ast.data.elements?.nodes!; // TODO: remove `!` + } + set elements(value) { + this.ast.data.elements = value?.ast; + } + get multiLine(): boolean | undefined { + return this.ast.data.multiLine; + } + set multiLine(value) { + this.ast.data.multiLine = value; + } } /** @internal */ @@ -7113,15 +10417,31 @@ export class NamespaceImport extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get name(): Identifier { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -7211,28 +10567,68 @@ export class ExportDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get isTypeOnly(): boolean { return this.ast.data.isTypeOnly; } - set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } - get exportClause(): NamedExportBindings | undefined { return this.ast.data.exportClause?.node; } - set exportClause(value) { this.ast.data.exportClause = value?.ast; } - get moduleSpecifier(): Expression | undefined { return this.ast.data.moduleSpecifier?.node; } - set moduleSpecifier(value) { this.ast.data.moduleSpecifier = value?.ast; } - get attributes(): ImportAttributes | undefined { return this.ast.data.attributes?.node; } - set attributes(value) { this.ast.data.attributes = value?.ast; } + override get parent() { + return super.parent as SourceFile | ModuleBlock; + } + override set parent(value) { + super.parent = value; + } + + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get isTypeOnly(): boolean { + return this.ast.data.isTypeOnly; + } + set isTypeOnly(value) { + this.ast.data.isTypeOnly = value; + } + get exportClause(): NamedExportBindings | undefined { + return this.ast.data.exportClause?.node; + } + set exportClause(value) { + this.ast.data.exportClause = value?.ast; + } + get moduleSpecifier(): Expression | undefined { + return this.ast.data.moduleSpecifier?.node; + } + set moduleSpecifier(value) { + this.ast.data.moduleSpecifier = value?.ast; + } + get attributes(): ImportAttributes | undefined { + return this.ast.data.attributes?.node; + } + set attributes(value) { + this.ast.data.attributes = value?.ast; + } /** @deprecated */ - get assertClause(): ImportAttributes | undefined { return this.ast.data.attributes?.node; } - set assertClause(value) { this.ast.data.attributes = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get assertClause(): ImportAttributes | undefined { + return this.ast.data.attributes?.node; + } + set assertClause(value) { + this.ast.data.attributes = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -7260,11 +10656,19 @@ export class AstExportDeclarationData extends AstData { export class NamedImports extends Node implements ts.NamedImports { declare readonly ast: AstNamedImports; - override get parent() { return super.parent as ImportClause; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as ImportClause; + } + override set parent(value) { + super.parent = value; + } - get elements(): NodeArray { return this.ast.data.elements.nodes; } - set elements(value) { this.ast.data.elements = value?.ast; } + get elements(): NodeArray { + return this.ast.data.elements.nodes; + } + set elements(value) { + this.ast.data.elements = value?.ast; + } } /** @internal */ @@ -7282,11 +10686,19 @@ export class AstNamedImportsData extends AstData { export class NamedExports extends Node implements ts.NamedExports { declare readonly ast: AstNamedExports; - override get parent() { return super.parent as ExportDeclaration; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as ExportDeclaration; + } + override set parent(value) { + super.parent = value; + } - get elements(): NodeArray { return this.ast.data.elements?.nodes!; } // TODO: remove '!' - set elements(value) { this.ast.data.elements = value?.ast; } + get elements(): NodeArray { + return this.ast.data.elements?.nodes!; + } // TODO: remove '!' + set elements(value) { + this.ast.data.elements = value?.ast; + } } /** @internal */ @@ -7306,19 +10718,43 @@ export class ImportSpecifier extends Node | undefined { return this.ast.data.modifiers?.nodes; } - set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get isExportEquals(): boolean | undefined { return this.ast.data.isExportEquals; } - set isExportEquals(value) { this.ast.data.isExportEquals = value; } - get expression(): Expression { return this.ast.data.expression?.node; } - set expression(value) { this.ast.data.expression = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get modifiers(): NodeArray | undefined { + return this.ast.data.modifiers?.nodes; + } + set modifiers(value) { + this.ast.data.modifiers = value?.ast; + } + get isExportEquals(): boolean | undefined { + return this.ast.data.isExportEquals; + } + set isExportEquals(value) { + this.ast.data.isExportEquals = value; + } + get expression(): Expression { + return this.ast.data.expression?.node; + } + set expression(value) { + this.ast.data.expression = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value: JSDocArray | undefined) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -7438,8 +10930,12 @@ export class JSDocTypeExpression extends Node implements ts.JSDocNameReference { declare readonly ast: AstJSDocNameReference; - get name(): EntityName | JSDocMemberName { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } + get name(): EntityName | JSDocMemberName { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } } /** @internal */ @@ -7464,10 +10964,18 @@ export class AstJSDocNameReferenceData extends AstData { export class JSDocMemberName extends Node implements ts.JSDocMemberName { declare readonly ast: AstJSDocMemberName; - get left(): EntityName | JSDocMemberName { return this.ast.data.left?.node; } - set left(value) { this.ast.data.left = value?.ast; } - get right(): Identifier { return this.ast.data.right?.node; } - set right(value) { this.ast.data.right = value?.ast; } + get left(): EntityName | JSDocMemberName { + return this.ast.data.left?.node; + } + set left(value) { + this.ast.data.left = value?.ast; + } + get right(): Identifier { + return this.ast.data.right?.node; + } + set right(value) { + this.ast.data.right = value?.ast; + } } /** @internal */ @@ -7521,10 +11029,18 @@ export class JSDocNonNullableType extends Node | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters?.nodes!; } // TODO: remove `!` - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): TypeNode | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } - set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters?.nodes!; // TODO: remove `!` + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): TypeNode | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get typeArguments(): NodeArray | undefined { + return this.ast.data.typeArguments?.nodes; + } + set typeArguments(value) { + this.ast.data.typeArguments = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -7619,8 +11183,12 @@ export class JSDocVariadicType extends Node implements ts.JSDoc { declare readonly ast: AstJSDocNode; - override get parent() { return super.parent as HasJSDoc; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as HasJSDoc; + } + override set parent(value) { + super.parent = value; + } - get tags(): NodeArray | undefined { return this.ast.data.tags?.nodes; } - set tags(value) { this.ast.data.tags = value?.ast; } + get tags(): NodeArray | undefined { + return this.ast.data.tags?.nodes; + } + set tags(value) { + this.ast.data.tags = value?.ast; + } get comment(): string | NodeArray | undefined { const comment = this.ast.data.comment; return typeof comment === "string" ? comment : comment?.nodes; } - set comment(value) { this.ast.data.comment = typeof value === "string" ? value : value?.ast; } + set comment(value) { + this.ast.data.comment = typeof value === "string" ? value : value?.ast; + } } /** @internal */ @@ -7762,8 +11344,7 @@ export type JSDocTag = | JSDocPropertyTag | JSDocParameterTag | JSDocSatisfiesTag - | JSDocImportTag - ; + | JSDocImportTag; /** @internal */ export type AstJSDocTag = AstNodeOneOf; @@ -7772,10 +11353,18 @@ export type AstJSDocTag = AstNodeOneOf; export class JSDocLink extends Node implements ts.JSDocLink { declare readonly ast: AstJSDocLink; - get name(): EntityName | JSDocMemberName | undefined { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get text(): string { return this.ast.data.text; } - set text(value) { this.ast.data.text = value; } + get name(): EntityName | JSDocMemberName | undefined { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get text(): string { + return this.ast.data.text; + } + set text(value) { + this.ast.data.text = value; + } } /** @internal */ @@ -7788,10 +11377,18 @@ export class AstJSDocLinkData extends AstData { export class JSDocLinkCode extends Node implements ts.JSDocLinkCode { declare readonly ast: AstJSDocLinkCode; - get name(): EntityName | JSDocMemberName | undefined { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get text(): string { return this.ast.data.text; } - set text(value) { this.ast.data.text = value; } + get name(): EntityName | JSDocMemberName | undefined { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get text(): string { + return this.ast.data.text; + } + set text(value) { + this.ast.data.text = value; + } } /** @internal */ @@ -7804,10 +11401,18 @@ export class AstJSDocLinkCodeData extends AstData { export class JSDocLinkPlain extends Node implements ts.JSDocLinkPlain { declare readonly ast: AstJSDocLinkPlain; - get name(): EntityName | JSDocMemberName | undefined { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } - get text(): string { return this.ast.data.text; } - set text(value) { this.ast.data.text = value; } + get name(): EntityName | JSDocMemberName | undefined { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } + get text(): string { + return this.ast.data.text; + } + set text(value) { + this.ast.data.text = value; + } } /** @internal */ @@ -7821,8 +11426,7 @@ export type JSDocComment = | JSDocText | JSDocLink | JSDocLinkCode - | JSDocLinkPlain - ; + | JSDocLinkPlain; /** @internal */ export type AstJSDocComment = AstNodeOneOf; @@ -7831,8 +11435,12 @@ export type AstJSDocComment = AstNodeOneOf; export class JSDocText extends Node implements ts.JSDocText { declare readonly ast: AstJSDocText; - get text(): string { return this.ast.data.text; } - set text(value) { this.ast.data.text = value; } + get text(): string { + return this.ast.data.text; + } + set text(value) { + this.ast.data.text = value; + } } /** @internal */ @@ -7844,16 +11452,26 @@ export class AstJSDocTextData extends AstData { export class BaseJSDocTag extends Node implements ts.JSDocTag { declare readonly ast: AstBaseJSDocTag; - override get parent() { return super.parent as JSDocNode | JSDocTypeLiteral; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as JSDocNode | JSDocTypeLiteral; + } + override set parent(value) { + super.parent = value; + } - get tagName(): Identifier { return this.ast.data.tagName?.node; } - set tagName(value) { this.ast.data.tagName = value?.ast; } + get tagName(): Identifier { + return this.ast.data.tagName?.node; + } + set tagName(value) { + this.ast.data.tagName = value?.ast; + } get comment(): string | NodeArray | undefined { const comment = this.ast.data.comment; return typeof comment === "string" ? comment : comment?.nodes; } - set comment(value) { this.ast.data.comment = typeof value === "string" ? value : value?.ast; } + set comment(value) { + this.ast.data.comment = typeof value === "string" ? value : value?.ast; + } } /** @internal */ @@ -7896,8 +11514,12 @@ export interface AstJSDocClassReferenceData extends AstExpressionWithTypeArgumen /** @internal */ export class JSDocAugmentsTag extends BaseJSDocTag implements ts.JSDocAugmentsTag { declare readonly ast: AstJSDocAugmentsTag; - get class(): JSDocClassReference { return this.ast.data.class.node; } - set class(value) { this.ast.data.class = value.ast; } + get class(): JSDocClassReference { + return this.ast.data.class.node; + } + set class(value) { + this.ast.data.class = value.ast; + } } /** @internal */ @@ -7908,8 +11530,12 @@ export class AstJSDocAugmentsTagData extends AstJSDocTagData { /** @internal */ export class JSDocImplementsTag extends BaseJSDocTag implements ts.JSDocImplementsTag { declare readonly ast: AstJSDocImplementsTag; - get class(): JSDocClassReference { return this.ast.data.class.node; } - set class(value) { this.ast.data.class = value.ast; } + get class(): JSDocClassReference { + return this.ast.data.class.node; + } + set class(value) { + this.ast.data.class = value.ast; + } } /** @internal */ @@ -7995,19 +11621,43 @@ export class JSDocEnumTag extends BaseJSDocTag implements ts.JSDocThisTag { declare readonly ast: AstJSDocThisTag; - get typeExpression(): JSDocTypeExpression { return this.ast.data.typeExpression?.node; } - set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + get typeExpression(): JSDocTypeExpression { + return this.ast.data.typeExpression?.node; + } + set typeExpression(value) { + this.ast.data.typeExpression = value?.ast; + } } /** @internal */ @@ -8035,10 +11689,18 @@ export class AstJSDocThisTagData extends AstJSDocTagData { /** @internal */ export class JSDocTemplateTag extends BaseJSDocTag implements ts.JSDocTemplateTag { declare readonly ast: AstJSDocTemplateTag; - get constraint(): JSDocTypeExpression | undefined { return this.ast.data.constraint?.node; } - set constraint(value) { this.ast.data.constraint = value?.ast; } - get typeParameters(): NodeArray { return this.ast.data.typeParameters?.nodes!; } // TODO: remove `!` - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get constraint(): JSDocTypeExpression | undefined { + return this.ast.data.constraint?.node; + } + set constraint(value) { + this.ast.data.constraint = value?.ast; + } + get typeParameters(): NodeArray { + return this.ast.data.typeParameters?.nodes!; // TODO: remove `!` + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } } /** @internal */ @@ -8050,8 +11712,12 @@ export class AstJSDocTemplateTagData extends AstJSDocTagData { /** @internal */ export class JSDocSeeTag extends BaseJSDocTag implements ts.JSDocSeeTag { declare readonly ast: AstJSDocSeeTag; - get name(): JSDocNameReference | undefined { return this.ast.data.name?.node; } - set name(value) { this.ast.data.name = value?.ast; } + get name(): JSDocNameReference | undefined { + return this.ast.data.name?.node; + } + set name(value) { + this.ast.data.name = value?.ast; + } } /** @internal */ @@ -8062,8 +11728,12 @@ export class AstJSDocSeeTagData extends AstJSDocTagData { /** @internal */ export class JSDocReturnTag extends BaseJSDocTag implements ts.JSDocReturnTag { declare readonly ast: AstJSDocReturnTag; - get typeExpression(): JSDocTypeExpression | undefined { return this.ast.data.typeExpression?.node; } - set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + get typeExpression(): JSDocTypeExpression | undefined { + return this.ast.data.typeExpression?.node; + } + set typeExpression(value) { + this.ast.data.typeExpression = value?.ast; + } } /** @internal */ @@ -8074,8 +11744,12 @@ export class AstJSDocReturnTagData extends AstJSDocTagData { /** @internal */ export class JSDocTypeTag extends BaseJSDocTag implements ts.JSDocTypeTag { declare readonly ast: AstJSDocTypeTag; - get typeExpression(): JSDocTypeExpression { return this.ast.data.typeExpression?.node; } - set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + get typeExpression(): JSDocTypeExpression { + return this.ast.data.typeExpression?.node; + } + set typeExpression(value) { + this.ast.data.typeExpression = value?.ast; + } } /** @internal */ @@ -8089,23 +11763,55 @@ export class JSDocTypedefTag extends BaseJSDocTag implements ts.JSDocOverloadTag { declare readonly ast: AstJSDocOverloadTag; - override get parent() { return super.parent as JSDocNode; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as JSDocNode; + } + override set parent(value) { + super.parent = value; + } - get typeExpression(): JSDocSignature { return this.ast.data.typeExpression?.node; } - set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + get typeExpression(): JSDocSignature { + return this.ast.data.typeExpression?.node; + } + set typeExpression(value) { + this.ast.data.typeExpression = value?.ast; + } } /** @internal */ @@ -8176,8 +11922,12 @@ export class AstJSDocOverloadTagData extends AstJSDocTagData { /** @internal */ export class JSDocThrowsTag extends BaseJSDocTag implements ts.JSDocThrowsTag { declare readonly ast: AstJSDocThrowsTag; - get typeExpression(): JSDocTypeExpression | undefined { return this.ast.data.typeExpression?.node; } - set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + get typeExpression(): JSDocTypeExpression | undefined { + return this.ast.data.typeExpression?.node; + } + set typeExpression(value) { + this.ast.data.typeExpression = value?.ast; + } } /** @internal */ @@ -8195,22 +11945,54 @@ export class JSDocSignature extends Node | undefined { return this.ast.data.typeParameters?.nodes; } - set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters(): NodeArray { return this.ast.data.parameters.nodes; } - set parameters(value) { this.ast.data.parameters = value?.ast; } - get type(): JSDocReturnTag | undefined { return this.ast.data.type?.node; } - set type(value) { this.ast.data.type = value?.ast; } - get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } - set jsDoc(value) { this.ast.data.jsDoc = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } + get typeParameters(): NodeArray | undefined { + return this.ast.data.typeParameters?.nodes; + } + set typeParameters(value) { + this.ast.data.typeParameters = value?.ast; + } + get parameters(): NodeArray { + return this.ast.data.parameters.nodes; + } + set parameters(value) { + this.ast.data.parameters = value?.ast; + } + get type(): JSDocReturnTag | undefined { + return this.ast.data.type?.node; + } + set type(value) { + this.ast.data.type = value?.ast; + } + get jsDoc(): JSDocArray | undefined { + return this.ast.data.jsDoc; + } + set jsDoc(value) { + this.ast.data.jsDoc = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } } /** @internal */ @@ -8231,21 +12013,49 @@ export class JSDocPropertyTag extends BaseJSDocTag; @@ -8309,14 +12146,30 @@ export class JSDocTypeLiteral extends Node | undefined { return this.ast.data.jsDocPropertyTags?.nodes; } - set jsDocPropertyTags(value) { this.ast.data.jsDocPropertyTags = value?.ast; } - get isArrayType(): boolean { return this.ast.data.isArrayType; } - set isArrayType(value) { this.ast.data.isArrayType = value; } - get symbol(): ts.Symbol { return this.ast.data.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } + get jsDocPropertyTags(): NodeArray | undefined { + return this.ast.data.jsDocPropertyTags?.nodes; + } + set jsDocPropertyTags(value) { + this.ast.data.jsDocPropertyTags = value?.ast; + } + get isArrayType(): boolean { + return this.ast.data.isArrayType; + } + set isArrayType(value) { + this.ast.data.isArrayType = value; + } + get symbol(): ts.Symbol { + return this.ast.data.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.localSymbol; + } + set localSymbol(value) { + this.ast.data.localSymbol = value; + } } /** @internal */ @@ -8330,8 +12183,12 @@ export class AstJSDocTypeLiteralData extends AstData { /** @internal */ export class JSDocSatisfiesTag extends BaseJSDocTag implements ts.JSDocSatisfiesTag { declare readonly ast: AstJSDocSatisfiesTag; - get typeExpression(): JSDocTypeExpression { return this.ast.data.typeExpression?.node; } - set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + get typeExpression(): JSDocTypeExpression { + return this.ast.data.typeExpression?.node; + } + set typeExpression(value) { + this.ast.data.typeExpression = value?.ast; + } } /** @internal */ @@ -8343,15 +12200,31 @@ export class AstJSDocSatisfiesTagData extends AstJSDocTagData { export class JSDocImportTag extends BaseJSDocTag implements ts.JSDocImportTag { declare readonly ast: AstJSDocImportTag; - override get parent() { return super.parent as JSDocNode; } - override set parent(value) { super.parent = value; } + override get parent() { + return super.parent as JSDocNode; + } + override set parent(value) { + super.parent = value; + } - get importClause(): ImportClause | undefined { return this.ast.data.importClause?.node; } - set importClause(value) { this.ast.data.importClause = value?.ast; } - get moduleSpecifier(): Expression { return this.ast.data.moduleSpecifier?.node; } - set moduleSpecifier(value) { this.ast.data.moduleSpecifier = value?.ast; } - get attributes(): ImportAttributes | undefined { return this.ast.data.attributes?.node; } - set attributes(value) { this.ast.data.attributes = value?.ast; } + get importClause(): ImportClause | undefined { + return this.ast.data.importClause?.node; + } + set importClause(value) { + this.ast.data.importClause = value?.ast; + } + get moduleSpecifier(): Expression { + return this.ast.data.moduleSpecifier?.node; + } + set moduleSpecifier(value) { + this.ast.data.moduleSpecifier = value?.ast; + } + get attributes(): ImportAttributes | undefined { + return this.ast.data.attributes?.node; + } + set attributes(value) { + this.ast.data.attributes = value?.ast; + } } /** @internal */ @@ -8366,12 +12239,24 @@ export class SyntheticExpression extends Node implements ts.Bundle { declare readonly ast: AstBundle; - get sourceFiles(): readonly SourceFile[] { return this.ast.data.sourceFiles; } - set sourceFiles(value: readonly SourceFile[]) { this.ast.data.sourceFiles = value; } - get syntheticFileReferences(): readonly FileReference[] | undefined { return this.ast.data.syntheticFileReferences; } - set syntheticFileReferences(value: readonly FileReference[] | undefined) { this.ast.data.syntheticFileReferences = value; } - get syntheticTypeReferences(): readonly FileReference[] | undefined { return this.ast.data.syntheticTypeReferences; } - set syntheticTypeReferences(value: readonly FileReference[] | undefined) { this.ast.data.syntheticTypeReferences = value; } - get syntheticLibReferences(): readonly FileReference[] | undefined { return this.ast.data.syntheticLibReferences; } - set syntheticLibReferences(value: readonly FileReference[] | undefined) { this.ast.data.syntheticLibReferences = value; } - get hasNoDefaultLib(): boolean | undefined { return this.ast.data.hasNoDefaultLib; } - set hasNoDefaultLib(value: boolean | undefined) { this.ast.data.hasNoDefaultLib = value; } + get sourceFiles(): readonly SourceFile[] { + return this.ast.data.sourceFiles; + } + set sourceFiles(value: readonly SourceFile[]) { + this.ast.data.sourceFiles = value; + } + get syntheticFileReferences(): readonly FileReference[] | undefined { + return this.ast.data.syntheticFileReferences; + } + set syntheticFileReferences(value: readonly FileReference[] | undefined) { + this.ast.data.syntheticFileReferences = value; + } + get syntheticTypeReferences(): readonly FileReference[] | undefined { + return this.ast.data.syntheticTypeReferences; + } + set syntheticTypeReferences(value: readonly FileReference[] | undefined) { + this.ast.data.syntheticTypeReferences = value; + } + get syntheticLibReferences(): readonly FileReference[] | undefined { + return this.ast.data.syntheticLibReferences; + } + set syntheticLibReferences(value: readonly FileReference[] | undefined) { + this.ast.data.syntheticLibReferences = value; + } + get hasNoDefaultLib(): boolean | undefined { + return this.ast.data.hasNoDefaultLib; + } + set hasNoDefaultLib(value: boolean | undefined) { + this.ast.data.hasNoDefaultLib = value; + } } /** @internal */ @@ -8408,8 +12313,12 @@ export class AstBundleData extends AstData { /** @internal */ export class SyntaxList extends Node implements ts.SyntaxList { - get _children(): readonly Node[] { return this.ast.data._children; } - set _children(value: readonly Node[]) { this.ast.data._children = value; } + get _children(): readonly Node[] { + return this.ast.data._children; + } + set _children(value: readonly Node[]) { + this.ast.data._children = value; + } } /** @internal */ @@ -8424,8 +12333,12 @@ export class NotEmittedStatement extends Node { return this.ast.data.elements.nodes; } - set elements(value: NodeArray) { this.ast.data.elements = value?.ast; } + get elements(): NodeArray { + return this.ast.data.elements.nodes; + } + set elements(value: NodeArray) { + this.ast.data.elements = value?.ast; + } } /** @internal */ @@ -8508,10 +12445,18 @@ export class SyntheticReferenceExpression extends Node i declare _declarationBrand: any; declare _localsContainerBrand: any; - get statements(): NodeArray { return this.ast.data.statements?.nodes!; } // TODO: remove `!` - set statements(value) { this.ast.data.statements = value?.ast; } - get endOfFileToken(): EndOfFileToken { return this.ast.data.endOfFileToken?.node; } - set endOfFileToken(value) { this.ast.data.endOfFileToken = value?.ast; } - get fileName(): string { return this.ast.data.fileName; } - set fileName(value) { this.ast.data.fileName = value; } - - get path(): ts.Path { return this.ast.data.path; } - set path(value) { this.ast.data.path = value; } - get text(): string { return this.ast.data.text; } - set text(value) { this.ast.data.text = value; } - get resolvedPath(): ts.Path { return this.ast.data.resolvedPath; } - set resolvedPath(value) { this.ast.data.resolvedPath = value; } - get originalFileName(): string { return this.ast.data.originalFileName; } - set originalFileName(value) { this.ast.data.originalFileName = value; } - get amdDependencies(): ts.AmdDependency[] { return this.ast.data.amdDependencies; } - set amdDependencies(value) { this.ast.data.amdDependencies = value; } - get moduleName(): string | undefined { return this.ast.data.moduleName; } - set moduleName(value) { this.ast.data.moduleName = value; } - get referencedFiles(): readonly ts.FileReference[] { return this.ast.data.referencedFiles; } - set referencedFiles(value) { this.ast.data.referencedFiles = value; } - get typeReferenceDirectives(): readonly ts.FileReference[] { return this.ast.data.typeReferenceDirectives; } - set typeReferenceDirectives(value) { this.ast.data.typeReferenceDirectives = value; } - get libReferenceDirectives(): readonly ts.FileReference[] { return this.ast.data.libReferenceDirectives; } - set libReferenceDirectives(value) { this.ast.data.libReferenceDirectives = value; } - get languageVariant(): ts.LanguageVariant { return this.ast.data.languageVariant; } - set languageVariant(value) { this.ast.data.languageVariant = value; } - get isDeclarationFile(): boolean { return this.ast.data.isDeclarationFile; } - set isDeclarationFile(value) { this.ast.data.isDeclarationFile = value; } - get renamedDependencies(): Map { return this.ast.data.renamedDependencies; } - set renamedDependencies(value) { this.ast.data.renamedDependencies = value; } - get hasNoDefaultLib(): boolean { return this.ast.data.hasNoDefaultLib; } - set hasNoDefaultLib(value) { this.ast.data.hasNoDefaultLib = value; } - get languageVersion(): ts.ScriptTarget { return this.ast.data.languageVersion; } - set languageVersion(value) { this.ast.data.languageVersion = value; } - get impliedNodeFormat(): ts.ResolutionMode { return this.ast.data.impliedNodeFormat; } - set impliedNodeFormat(value) { this.ast.data.impliedNodeFormat = value; } - get scriptKind(): ts.ScriptKind { return this.ast.data.scriptKind; } - set scriptKind(value) { this.ast.data.scriptKind = value; } - get pragmas(): ts.ReadonlyPragmaMap { return this.ast.data.pragmas; } - set pragmas(value) { this.ast.data.pragmas = value; } - get externalModuleIndicator(): true | Node | undefined { return this.ast.data.externalModuleIndicator; } - set externalModuleIndicator(value) { this.ast.data.externalModuleIndicator = value; } - get commonJsModuleIndicator(): Node | undefined { return this.ast.data.commonJsModuleIndicator; } - set commonJsModuleIndicator(value) { this.ast.data.commonJsModuleIndicator = value; } - get identifiers(): Map { return this.ast.data.identifiers; } - set identifiers(value) { this.ast.data.identifiers = value; } - get parseDiagnostics(): ts.DiagnosticWithLocation[] { return this.ast.data.parseDiagnostics; } - set parseDiagnostics(value) { this.ast.data.parseDiagnostics = value; } - get bindDiagnostics(): ts.DiagnosticWithLocation[] { return this.ast.data.bindDiagnostics; } - set bindDiagnostics(value) { this.ast.data.bindDiagnostics = value; } - get bindSuggestionDiagnostics(): ts.DiagnosticWithLocation[] | undefined { return this.ast.data.bindSuggestionDiagnostics; } - set bindSuggestionDiagnostics(value) { this.ast.data.bindSuggestionDiagnostics = value; } - get lineMap(): readonly number[] { return this.ast.data.lineMap; } - set lineMap(value) { this.ast.data.lineMap = value; } - get jsDocDiagnostics(): ts.DiagnosticWithLocation[] | undefined { return this.ast.data.jsDocDiagnostics; } - set jsDocDiagnostics(value) { this.ast.data.jsDocDiagnostics = value; } - get commentDirectives(): ts.CommentDirective[] | undefined { return this.ast.data.commentDirectives; } - set commentDirectives(value) { this.ast.data.commentDirectives = value; } - get checkJsDirective(): ts.CheckJsDirective | undefined { return this.ast.data.checkJsDirective; } - set checkJsDirective(value) { this.ast.data.checkJsDirective = value; } - get version(): string { return this.ast.data.version; } - set version(value) { this.ast.data.version = value; } - - get symbol(): ts.Symbol { return this.ast.data.declaration.symbol!; } // TODO: remove `!` - set symbol(value) { this.ast.data.declaration.symbol = value; } - get localSymbol(): ts.Symbol | undefined { return this.ast.data.declaration.localSymbol; } - set localSymbol(value) { this.ast.data.declaration.localSymbol = value; } - get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get redirectInfo(): ts.RedirectInfo | undefined { return this.ast.data.redirectInfo; } - set redirectInfo(value) { this.ast.data.redirectInfo = value; } - get packageJsonLocations(): readonly string[] | undefined { return this.ast.data.packageJsonLocations; } - set packageJsonLocations(value) { this.ast.data.packageJsonLocations = value; } - get packageJsonScope(): ts.PackageJsonInfo | undefined { return this.ast.data.packageJsonScope; } - set packageJsonScope(value) { this.ast.data.packageJsonScope = value; } - get setExternalModuleIndicator(): ((file: ts.SourceFile) => void) | undefined { return this.ast.data.setExternalModuleIndicator; } - set setExternalModuleIndicator(value) { this.ast.data.setExternalModuleIndicator = value; } - get jsGlobalAugmentations(): ts.SymbolTable | undefined { return this.ast.data.jsGlobalAugmentations; } - set jsGlobalAugmentations(value) { this.ast.data.jsGlobalAugmentations = value; } - get nodeCount(): number { return this.ast.data.nodeCount; } - set nodeCount(value) { this.ast.data.nodeCount = value; } - get identifierCount(): number { return this.ast.data.identifierCount; } - set identifierCount(value) { this.ast.data.identifierCount = value; } - get symbolCount(): number { return this.ast.data.symbolCount; } - set symbolCount(value) { this.ast.data.symbolCount = value; } - get additionalSyntacticDiagnostics(): readonly ts.DiagnosticWithLocation[] | undefined { return this.ast.data.additionalSyntacticDiagnostics; } - set additionalSyntacticDiagnostics(value) { this.ast.data.additionalSyntacticDiagnostics = value; } - get classifiableNames(): ReadonlySet | undefined { return this.ast.data.classifiableNames; } - set classifiableNames(value) { this.ast.data.classifiableNames = value; } - get imports(): readonly ts.StringLiteralLike[] { return this.ast.data.imports; } - set imports(value) { this.ast.data.imports = value; } - get moduleAugmentations(): readonly (ts.Identifier | ts.StringLiteral)[] { return this.ast.data.moduleAugmentations; } - set moduleAugmentations(value) { this.ast.data.moduleAugmentations = value; } - get patternAmbientModules(): ts.PatternAmbientModule[] | undefined { return this.ast.data.patternAmbientModules; } - set patternAmbientModules(value) { this.ast.data.patternAmbientModules = value; } - get ambientModuleNames(): readonly string[] { return this.ast.data.ambientModuleNames; } - set ambientModuleNames(value) { this.ast.data.ambientModuleNames = value; } - get localJsxNamespace(): ts.__String | undefined { return this.ast.data.localJsxNamespace; } - set localJsxNamespace(value) { this.ast.data.localJsxNamespace = value; } - get localJsxFragmentNamespace(): ts.__String | undefined { return this.ast.data.localJsxFragmentNamespace; } - set localJsxFragmentNamespace(value) { this.ast.data.localJsxFragmentNamespace = value; } - get localJsxFactory(): ts.EntityName | undefined { return this.ast.data.localJsxFactory; } - set localJsxFactory(value) { this.ast.data.localJsxFactory = value; } - get localJsxFragmentFactory(): ts.EntityName | undefined { return this.ast.data.localJsxFragmentFactory; } - set localJsxFragmentFactory(value) { this.ast.data.localJsxFragmentFactory = value; } - get endFlowNode(): ts.FlowNode | undefined { return this.ast.data.endFlowNode; } - set endFlowNode(value) { this.ast.data.endFlowNode = value; } - get jsDocParsingMode(): ts.JSDocParsingMode | undefined { return this.ast.data.jsDocParsingMode; } - set jsDocParsingMode(value) { this.ast.data.jsDocParsingMode = value; } - - get scriptSnapshot(): any { return this.ast.data.scriptSnapshot; } - set scriptSnapshot(value) { this.ast.data.scriptSnapshot = value; } - get nameTable(): Map | undefined { return this.ast.data.nameTable; } - set nameTable(value) { this.ast.data.nameTable = value; } - - get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast as NextContainer | undefined; } - - get extendedSourceFiles(): string[] | undefined { return this.ast.data.extendedSourceFiles; } - set extendedSourceFiles(value) { this.ast.data.extendedSourceFiles = value; } - get configFileSpecs(): ts.ConfigFileSpecs | undefined { return this.ast.data.configFileSpecs; } - set configFileSpecs(value) { this.ast.data.configFileSpecs = value; } + get statements(): NodeArray { + return this.ast.data.statements?.nodes!; // TODO: remove `!` + } + set statements(value) { + this.ast.data.statements = value?.ast; + } + get endOfFileToken(): EndOfFileToken { + return this.ast.data.endOfFileToken?.node; + } + set endOfFileToken(value) { + this.ast.data.endOfFileToken = value?.ast; + } + get fileName(): string { + return this.ast.data.fileName; + } + set fileName(value) { + this.ast.data.fileName = value; + } + + get path(): ts.Path { + return this.ast.data.path; + } + set path(value) { + this.ast.data.path = value; + } + get text(): string { + return this.ast.data.text; + } + set text(value) { + this.ast.data.text = value; + } + get resolvedPath(): ts.Path { + return this.ast.data.resolvedPath; + } + set resolvedPath(value) { + this.ast.data.resolvedPath = value; + } + get originalFileName(): string { + return this.ast.data.originalFileName; + } + set originalFileName(value) { + this.ast.data.originalFileName = value; + } + get amdDependencies(): ts.AmdDependency[] { + return this.ast.data.amdDependencies; + } + set amdDependencies(value) { + this.ast.data.amdDependencies = value; + } + get moduleName(): string | undefined { + return this.ast.data.moduleName; + } + set moduleName(value) { + this.ast.data.moduleName = value; + } + get referencedFiles(): readonly ts.FileReference[] { + return this.ast.data.referencedFiles; + } + set referencedFiles(value) { + this.ast.data.referencedFiles = value; + } + get typeReferenceDirectives(): readonly ts.FileReference[] { + return this.ast.data.typeReferenceDirectives; + } + set typeReferenceDirectives(value) { + this.ast.data.typeReferenceDirectives = value; + } + get libReferenceDirectives(): readonly ts.FileReference[] { + return this.ast.data.libReferenceDirectives; + } + set libReferenceDirectives(value) { + this.ast.data.libReferenceDirectives = value; + } + get languageVariant(): ts.LanguageVariant { + return this.ast.data.languageVariant; + } + set languageVariant(value) { + this.ast.data.languageVariant = value; + } + get isDeclarationFile(): boolean { + return this.ast.data.isDeclarationFile; + } + set isDeclarationFile(value) { + this.ast.data.isDeclarationFile = value; + } + get renamedDependencies(): Map { + return this.ast.data.renamedDependencies; + } + set renamedDependencies(value) { + this.ast.data.renamedDependencies = value; + } + get hasNoDefaultLib(): boolean { + return this.ast.data.hasNoDefaultLib; + } + set hasNoDefaultLib(value) { + this.ast.data.hasNoDefaultLib = value; + } + get languageVersion(): ts.ScriptTarget { + return this.ast.data.languageVersion; + } + set languageVersion(value) { + this.ast.data.languageVersion = value; + } + get impliedNodeFormat(): ts.ResolutionMode { + return this.ast.data.impliedNodeFormat; + } + set impliedNodeFormat(value) { + this.ast.data.impliedNodeFormat = value; + } + get scriptKind(): ts.ScriptKind { + return this.ast.data.scriptKind; + } + set scriptKind(value) { + this.ast.data.scriptKind = value; + } + get pragmas(): ts.ReadonlyPragmaMap { + return this.ast.data.pragmas; + } + set pragmas(value) { + this.ast.data.pragmas = value; + } + get externalModuleIndicator(): true | Node | undefined { + return this.ast.data.externalModuleIndicator; + } + set externalModuleIndicator(value) { + this.ast.data.externalModuleIndicator = value; + } + get commonJsModuleIndicator(): Node | undefined { + return this.ast.data.commonJsModuleIndicator; + } + set commonJsModuleIndicator(value) { + this.ast.data.commonJsModuleIndicator = value; + } + get identifiers(): Map { + return this.ast.data.identifiers; + } + set identifiers(value) { + this.ast.data.identifiers = value; + } + get parseDiagnostics(): ts.DiagnosticWithLocation[] { + return this.ast.data.parseDiagnostics; + } + set parseDiagnostics(value) { + this.ast.data.parseDiagnostics = value; + } + get bindDiagnostics(): ts.DiagnosticWithLocation[] { + return this.ast.data.bindDiagnostics; + } + set bindDiagnostics(value) { + this.ast.data.bindDiagnostics = value; + } + get bindSuggestionDiagnostics(): ts.DiagnosticWithLocation[] | undefined { + return this.ast.data.bindSuggestionDiagnostics; + } + set bindSuggestionDiagnostics(value) { + this.ast.data.bindSuggestionDiagnostics = value; + } + get lineMap(): readonly number[] { + return this.ast.data.lineMap; + } + set lineMap(value) { + this.ast.data.lineMap = value; + } + get jsDocDiagnostics(): ts.DiagnosticWithLocation[] | undefined { + return this.ast.data.jsDocDiagnostics; + } + set jsDocDiagnostics(value) { + this.ast.data.jsDocDiagnostics = value; + } + get commentDirectives(): ts.CommentDirective[] | undefined { + return this.ast.data.commentDirectives; + } + set commentDirectives(value) { + this.ast.data.commentDirectives = value; + } + get checkJsDirective(): ts.CheckJsDirective | undefined { + return this.ast.data.checkJsDirective; + } + set checkJsDirective(value) { + this.ast.data.checkJsDirective = value; + } + get version(): string { + return this.ast.data.version; + } + set version(value) { + this.ast.data.version = value; + } + + get symbol(): ts.Symbol { + return this.ast.data.declaration.symbol!; // TODO: remove `!` + } + set symbol(value) { + this.ast.data.declaration.symbol = value; + } + get localSymbol(): ts.Symbol | undefined { + return this.ast.data.declaration.localSymbol; + } + set localSymbol(value) { + this.ast.data.declaration.localSymbol = value; + } + get locals(): ts.SymbolTable | undefined { + return this.ast.data.locals; + } + set locals(value) { + this.ast.data.locals = value; + } + get redirectInfo(): ts.RedirectInfo | undefined { + return this.ast.data.redirectInfo; + } + set redirectInfo(value) { + this.ast.data.redirectInfo = value; + } + get packageJsonLocations(): readonly string[] | undefined { + return this.ast.data.packageJsonLocations; + } + set packageJsonLocations(value) { + this.ast.data.packageJsonLocations = value; + } + get packageJsonScope(): ts.PackageJsonInfo | undefined { + return this.ast.data.packageJsonScope; + } + set packageJsonScope(value) { + this.ast.data.packageJsonScope = value; + } + get setExternalModuleIndicator(): ((file: ts.SourceFile) => void) | undefined { + return this.ast.data.setExternalModuleIndicator; + } + set setExternalModuleIndicator(value) { + this.ast.data.setExternalModuleIndicator = value; + } + get jsGlobalAugmentations(): ts.SymbolTable | undefined { + return this.ast.data.jsGlobalAugmentations; + } + set jsGlobalAugmentations(value) { + this.ast.data.jsGlobalAugmentations = value; + } + get nodeCount(): number { + return this.ast.data.nodeCount; + } + set nodeCount(value) { + this.ast.data.nodeCount = value; + } + get identifierCount(): number { + return this.ast.data.identifierCount; + } + set identifierCount(value) { + this.ast.data.identifierCount = value; + } + get symbolCount(): number { + return this.ast.data.symbolCount; + } + set symbolCount(value) { + this.ast.data.symbolCount = value; + } + get additionalSyntacticDiagnostics(): readonly ts.DiagnosticWithLocation[] | undefined { + return this.ast.data.additionalSyntacticDiagnostics; + } + set additionalSyntacticDiagnostics(value) { + this.ast.data.additionalSyntacticDiagnostics = value; + } + get classifiableNames(): ReadonlySet | undefined { + return this.ast.data.classifiableNames; + } + set classifiableNames(value) { + this.ast.data.classifiableNames = value; + } + get imports(): readonly ts.StringLiteralLike[] { + return this.ast.data.imports; + } + set imports(value) { + this.ast.data.imports = value; + } + get moduleAugmentations(): readonly (ts.Identifier | ts.StringLiteral)[] { + return this.ast.data.moduleAugmentations; + } + set moduleAugmentations(value) { + this.ast.data.moduleAugmentations = value; + } + get patternAmbientModules(): ts.PatternAmbientModule[] | undefined { + return this.ast.data.patternAmbientModules; + } + set patternAmbientModules(value) { + this.ast.data.patternAmbientModules = value; + } + get ambientModuleNames(): readonly string[] { + return this.ast.data.ambientModuleNames; + } + set ambientModuleNames(value) { + this.ast.data.ambientModuleNames = value; + } + get localJsxNamespace(): ts.__String | undefined { + return this.ast.data.localJsxNamespace; + } + set localJsxNamespace(value) { + this.ast.data.localJsxNamespace = value; + } + get localJsxFragmentNamespace(): ts.__String | undefined { + return this.ast.data.localJsxFragmentNamespace; + } + set localJsxFragmentNamespace(value) { + this.ast.data.localJsxFragmentNamespace = value; + } + get localJsxFactory(): ts.EntityName | undefined { + return this.ast.data.localJsxFactory; + } + set localJsxFactory(value) { + this.ast.data.localJsxFactory = value; + } + get localJsxFragmentFactory(): ts.EntityName | undefined { + return this.ast.data.localJsxFragmentFactory; + } + set localJsxFragmentFactory(value) { + this.ast.data.localJsxFragmentFactory = value; + } + get endFlowNode(): ts.FlowNode | undefined { + return this.ast.data.endFlowNode; + } + set endFlowNode(value) { + this.ast.data.endFlowNode = value; + } + get jsDocParsingMode(): ts.JSDocParsingMode | undefined { + return this.ast.data.jsDocParsingMode; + } + set jsDocParsingMode(value) { + this.ast.data.jsDocParsingMode = value; + } + + get scriptSnapshot(): any { + return this.ast.data.scriptSnapshot; + } + set scriptSnapshot(value) { + this.ast.data.scriptSnapshot = value; + } + get nameTable(): Map | undefined { + return this.ast.data.nameTable; + } + set nameTable(value) { + this.ast.data.nameTable = value; + } + + get nextContainer(): HasLocals | undefined { + return this.ast.data.nextContainer?.node; + } + set nextContainer(value) { + this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + } + + get extendedSourceFiles(): string[] | undefined { + return this.ast.data.extendedSourceFiles; + } + set extendedSourceFiles(value) { + this.ast.data.extendedSourceFiles = value; + } + get configFileSpecs(): ts.ConfigFileSpecs | undefined { + return this.ast.data.configFileSpecs; + } + set configFileSpecs(value) { + this.ast.data.configFileSpecs = value; + } public update(newText: string, textChangeRange: ts.TextChangeRange): ts.SourceFile { return updateSourceFile(this, newText, textChangeRange); @@ -9492,7 +13673,7 @@ function hasInvalidEscape(template: AstTemplateLiteral): boolean { } function isNoSubstitutionTemplateLiteral(template: AstTemplateLiteral): template is AstNoSubstitutionTemplateLiteral { - return template.kind === SyntaxKind.NoSubstitutionTemplateLiteral; + return template.kind === SyntaxKind.NoSubstitutionTemplateLiteral; } // copied from services/utilities.ts @@ -9668,728 +13849,728 @@ export function skipAstOuterExpressions(node: AstNode, kinds: ts.OuterExpression /** @internal */ export interface NodeType { - [SyntaxKind.Unknown]: Token, - [SyntaxKind.EndOfFileToken]: EndOfFileToken, - [SyntaxKind.SingleLineCommentTrivia]: Token, - [SyntaxKind.MultiLineCommentTrivia]: Token, - [SyntaxKind.NewLineTrivia]: Token, - [SyntaxKind.WhitespaceTrivia]: Token, - [SyntaxKind.ShebangTrivia]: Token, - [SyntaxKind.ConflictMarkerTrivia]: Token, - [SyntaxKind.NonTextFileMarkerTrivia]: never, - [SyntaxKind.NumericLiteral]: NumericLiteral, - [SyntaxKind.BigIntLiteral]: BigIntLiteral, - [SyntaxKind.StringLiteral]: StringLiteral, - [SyntaxKind.JsxText]: JsxText, - [SyntaxKind.JsxTextAllWhiteSpaces]: never, - [SyntaxKind.RegularExpressionLiteral]: RegularExpressionLiteral, - [SyntaxKind.NoSubstitutionTemplateLiteral]: NoSubstitutionTemplateLiteral, - [SyntaxKind.TemplateHead]: TemplateHead, - [SyntaxKind.TemplateMiddle]: TemplateMiddle, - [SyntaxKind.TemplateTail]: TemplateTail, - [SyntaxKind.OpenBraceToken]: Token, - [SyntaxKind.CloseBraceToken]: Token, - [SyntaxKind.OpenParenToken]: Token, - [SyntaxKind.CloseParenToken]: Token, - [SyntaxKind.OpenBracketToken]: Token, - [SyntaxKind.CloseBracketToken]: Token, - [SyntaxKind.DotToken]: Token, - [SyntaxKind.DotDotDotToken]: Token, - [SyntaxKind.SemicolonToken]: Token, - [SyntaxKind.CommaToken]: Token, - [SyntaxKind.QuestionDotToken]: Token, - [SyntaxKind.LessThanToken]: Token, - [SyntaxKind.LessThanSlashToken]: Token, - [SyntaxKind.GreaterThanToken]: Token, - [SyntaxKind.LessThanEqualsToken]: Token, - [SyntaxKind.GreaterThanEqualsToken]: Token, - [SyntaxKind.EqualsEqualsToken]: Token, - [SyntaxKind.ExclamationEqualsToken]: Token, - [SyntaxKind.EqualsEqualsEqualsToken]: Token, - [SyntaxKind.ExclamationEqualsEqualsToken]: Token, - [SyntaxKind.EqualsGreaterThanToken]: Token, - [SyntaxKind.PlusToken]: Token, - [SyntaxKind.MinusToken]: Token, - [SyntaxKind.AsteriskToken]: Token, - [SyntaxKind.AsteriskAsteriskToken]: Token, - [SyntaxKind.SlashToken]: Token, - [SyntaxKind.PercentToken]: Token, - [SyntaxKind.PlusPlusToken]: Token, - [SyntaxKind.MinusMinusToken]: Token, - [SyntaxKind.LessThanLessThanToken]: Token, - [SyntaxKind.GreaterThanGreaterThanToken]: Token, - [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: Token, - [SyntaxKind.AmpersandToken]: Token, - [SyntaxKind.BarToken]: Token, - [SyntaxKind.CaretToken]: Token, - [SyntaxKind.ExclamationToken]: Token, - [SyntaxKind.TildeToken]: Token, - [SyntaxKind.AmpersandAmpersandToken]: Token, - [SyntaxKind.BarBarToken]: Token, - [SyntaxKind.QuestionToken]: Token, - [SyntaxKind.ColonToken]: Token, - [SyntaxKind.AtToken]: Token, - [SyntaxKind.QuestionQuestionToken]: Token, - [SyntaxKind.BacktickToken]: Token, - [SyntaxKind.HashToken]: Token, - [SyntaxKind.EqualsToken]: Token, - [SyntaxKind.PlusEqualsToken]: Token, - [SyntaxKind.MinusEqualsToken]: Token, - [SyntaxKind.AsteriskEqualsToken]: Token, - [SyntaxKind.AsteriskAsteriskEqualsToken]: Token, - [SyntaxKind.SlashEqualsToken]: Token, - [SyntaxKind.PercentEqualsToken]: Token, - [SyntaxKind.LessThanLessThanEqualsToken]: Token, - [SyntaxKind.GreaterThanGreaterThanEqualsToken]: Token, - [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: Token, - [SyntaxKind.AmpersandEqualsToken]: Token, - [SyntaxKind.BarEqualsToken]: Token, - [SyntaxKind.BarBarEqualsToken]: Token, - [SyntaxKind.AmpersandAmpersandEqualsToken]: Token, - [SyntaxKind.QuestionQuestionEqualsToken]: Token, - [SyntaxKind.CaretEqualsToken]: Token, - [SyntaxKind.Identifier]: Identifier, - [SyntaxKind.PrivateIdentifier]: PrivateIdentifier, - [SyntaxKind.JSDocCommentTextToken]: never, - [SyntaxKind.BreakKeyword]: Token, - [SyntaxKind.CaseKeyword]: Token, - [SyntaxKind.CatchKeyword]: Token, - [SyntaxKind.ClassKeyword]: Token, - [SyntaxKind.ConstKeyword]: Token, - [SyntaxKind.ContinueKeyword]: Token, - [SyntaxKind.DebuggerKeyword]: Token, - [SyntaxKind.DefaultKeyword]: Token, - [SyntaxKind.DeleteKeyword]: Token, - [SyntaxKind.DoKeyword]: Token, - [SyntaxKind.ElseKeyword]: Token, - [SyntaxKind.EnumKeyword]: Token, - [SyntaxKind.ExportKeyword]: Token, - [SyntaxKind.ExtendsKeyword]: Token, - [SyntaxKind.FalseKeyword]: FalseLiteral, - [SyntaxKind.FinallyKeyword]: Token, - [SyntaxKind.ForKeyword]: Token, - [SyntaxKind.FunctionKeyword]: Token, - [SyntaxKind.IfKeyword]: Token, - [SyntaxKind.ImportKeyword]: ImportExpression, - [SyntaxKind.InKeyword]: Token, - [SyntaxKind.InstanceOfKeyword]: Token, - [SyntaxKind.NewKeyword]: Token, - [SyntaxKind.NullKeyword]: NullLiteral, - [SyntaxKind.ReturnKeyword]: Token, - [SyntaxKind.SuperKeyword]: SuperExpression, - [SyntaxKind.SwitchKeyword]: Token, - [SyntaxKind.ThisKeyword]: ThisExpression, - [SyntaxKind.ThrowKeyword]: Token, - [SyntaxKind.TrueKeyword]: TrueLiteral, - [SyntaxKind.TryKeyword]: Token, - [SyntaxKind.TypeOfKeyword]: Token, - [SyntaxKind.VarKeyword]: Token, - [SyntaxKind.VoidKeyword]: Token, - [SyntaxKind.WhileKeyword]: Token, - [SyntaxKind.WithKeyword]: Token, - [SyntaxKind.ImplementsKeyword]: Token, - [SyntaxKind.InterfaceKeyword]: Token, - [SyntaxKind.LetKeyword]: Token, - [SyntaxKind.PackageKeyword]: Token, - [SyntaxKind.PrivateKeyword]: Token, - [SyntaxKind.ProtectedKeyword]: Token, - [SyntaxKind.PublicKeyword]: Token, - [SyntaxKind.StaticKeyword]: Token, - [SyntaxKind.YieldKeyword]: Token, - [SyntaxKind.AbstractKeyword]: Token, - [SyntaxKind.AccessorKeyword]: Token, - [SyntaxKind.AsKeyword]: Token, - [SyntaxKind.AssertsKeyword]: Token, - [SyntaxKind.AssertKeyword]: Token, - [SyntaxKind.AnyKeyword]: Token, - [SyntaxKind.AsyncKeyword]: Token, - [SyntaxKind.AwaitKeyword]: Token, - [SyntaxKind.BooleanKeyword]: Token, - [SyntaxKind.ConstructorKeyword]: Token, - [SyntaxKind.DeclareKeyword]: Token, - [SyntaxKind.GetKeyword]: Token, - [SyntaxKind.InferKeyword]: Token, - [SyntaxKind.IntrinsicKeyword]: Token, - [SyntaxKind.IsKeyword]: Token, - [SyntaxKind.KeyOfKeyword]: Token, - [SyntaxKind.ModuleKeyword]: Token, - [SyntaxKind.NamespaceKeyword]: Token, - [SyntaxKind.NeverKeyword]: Token, - [SyntaxKind.OutKeyword]: Token, - [SyntaxKind.ReadonlyKeyword]: Token, - [SyntaxKind.RequireKeyword]: Token, - [SyntaxKind.NumberKeyword]: Token, - [SyntaxKind.ObjectKeyword]: Token, - [SyntaxKind.SatisfiesKeyword]: Token, - [SyntaxKind.SetKeyword]: Token, - [SyntaxKind.StringKeyword]: Token, - [SyntaxKind.SymbolKeyword]: Token, - [SyntaxKind.TypeKeyword]: Token, - [SyntaxKind.UndefinedKeyword]: Token, - [SyntaxKind.UniqueKeyword]: Token, - [SyntaxKind.UnknownKeyword]: Token, - [SyntaxKind.UsingKeyword]: Token, - [SyntaxKind.FromKeyword]: Token, - [SyntaxKind.GlobalKeyword]: Token, - [SyntaxKind.BigIntKeyword]: Token, - [SyntaxKind.OverrideKeyword]: Token, - [SyntaxKind.OfKeyword]: Token, - [SyntaxKind.QualifiedName]: QualifiedName, - [SyntaxKind.ComputedPropertyName]: ComputedPropertyName, - [SyntaxKind.Decorator]: Decorator, - [SyntaxKind.TypeParameter]: TypeParameterDeclaration, - [SyntaxKind.CallSignature]: CallSignatureDeclaration, - [SyntaxKind.ConstructSignature]: ConstructSignatureDeclaration, - [SyntaxKind.VariableDeclaration]: VariableDeclaration, - [SyntaxKind.VariableDeclarationList]: VariableDeclarationList, - [SyntaxKind.Parameter]: ParameterDeclaration, - [SyntaxKind.BindingElement]: BindingElement, - [SyntaxKind.PropertySignature]: PropertySignature, - [SyntaxKind.PropertyDeclaration]: PropertyDeclaration, - [SyntaxKind.PropertyAssignment]: PropertyAssignment, - [SyntaxKind.ShorthandPropertyAssignment]: ShorthandPropertyAssignment, - [SyntaxKind.SpreadAssignment]: SpreadAssignment, - [SyntaxKind.ObjectBindingPattern]: ObjectBindingPattern, - [SyntaxKind.ArrayBindingPattern]: ArrayBindingPattern, - [SyntaxKind.FunctionDeclaration]: FunctionDeclaration, - [SyntaxKind.MethodSignature]: MethodSignature, - [SyntaxKind.MethodDeclaration]: MethodDeclaration, - [SyntaxKind.Constructor]: ConstructorDeclaration, - [SyntaxKind.SemicolonClassElement]: SemicolonClassElement, - [SyntaxKind.GetAccessor]: GetAccessorDeclaration, - [SyntaxKind.SetAccessor]: SetAccessorDeclaration, - [SyntaxKind.IndexSignature]: IndexSignatureDeclaration, - [SyntaxKind.ClassStaticBlockDeclaration]: ClassStaticBlockDeclaration, - [SyntaxKind.ImportTypeAssertionContainer]: ImportTypeAssertionContainer, - [SyntaxKind.ImportType]: ImportTypeNode, - [SyntaxKind.ThisType]: ThisTypeNode, - [SyntaxKind.FunctionType]: FunctionTypeNode, - [SyntaxKind.ConstructorType]: ConstructorTypeNode, - [SyntaxKind.TypeReference]: TypeReferenceNode, - [SyntaxKind.TypePredicate]: TypePredicateNode, - [SyntaxKind.TypeQuery]: TypeQueryNode, - [SyntaxKind.TypeLiteral]: TypeLiteralNode, - [SyntaxKind.ArrayType]: ArrayTypeNode, - [SyntaxKind.TupleType]: TupleTypeNode, - [SyntaxKind.NamedTupleMember]: NamedTupleMember, - [SyntaxKind.OptionalType]: OptionalTypeNode, - [SyntaxKind.RestType]: RestTypeNode, - [SyntaxKind.UnionType]: UnionTypeNode, - [SyntaxKind.IntersectionType]: IntersectionTypeNode, - [SyntaxKind.ConditionalType]: ConditionalTypeNode, - [SyntaxKind.InferType]: InferTypeNode, - [SyntaxKind.ParenthesizedType]: ParenthesizedTypeNode, - [SyntaxKind.TypeOperator]: TypeOperatorNode, - [SyntaxKind.IndexedAccessType]: IndexedAccessTypeNode, - [SyntaxKind.MappedType]: MappedTypeNode, - [SyntaxKind.LiteralType]: LiteralTypeNode, - [SyntaxKind.TemplateLiteralType]: TemplateLiteralTypeNode, - [SyntaxKind.TemplateLiteralTypeSpan]: TemplateLiteralTypeSpan, - [SyntaxKind.OmittedExpression]: OmittedExpression, - [SyntaxKind.PrefixUnaryExpression]: PrefixUnaryExpression, - [SyntaxKind.PostfixUnaryExpression]: PostfixUnaryExpression, - [SyntaxKind.DeleteExpression]: DeleteExpression, - [SyntaxKind.TypeOfExpression]: TypeOfExpression, - [SyntaxKind.VoidExpression]: VoidExpression, - [SyntaxKind.AwaitExpression]: AwaitExpression, - [SyntaxKind.YieldExpression]: YieldExpression, - [SyntaxKind.BinaryExpression]: BinaryExpression, - [SyntaxKind.ConditionalExpression]: ConditionalExpression, - [SyntaxKind.FunctionExpression]: FunctionExpression, - [SyntaxKind.ArrowFunction]: ArrowFunction, - [SyntaxKind.TemplateExpression]: TemplateExpression, - [SyntaxKind.TemplateSpan]: TemplateSpan, - [SyntaxKind.ParenthesizedExpression]: ParenthesizedExpression, - [SyntaxKind.ArrayLiteralExpression]: ArrayLiteralExpression, - [SyntaxKind.SpreadElement]: SpreadElement, - [SyntaxKind.ObjectLiteralExpression]: ObjectLiteralExpression, - [SyntaxKind.PropertyAccessExpression]: PropertyAccessExpression, - [SyntaxKind.ElementAccessExpression]: ElementAccessExpression, - [SyntaxKind.CallExpression]: CallExpression, - [SyntaxKind.ExpressionWithTypeArguments]: ExpressionWithTypeArguments, - [SyntaxKind.NewExpression]: NewExpression, - [SyntaxKind.TaggedTemplateExpression]: TaggedTemplateExpression, - [SyntaxKind.AsExpression]: AsExpression, - [SyntaxKind.TypeAssertionExpression]: TypeAssertion, - [SyntaxKind.SyntheticExpression]: SyntheticExpression, - [SyntaxKind.SatisfiesExpression]: SatisfiesExpression, - [SyntaxKind.NonNullExpression]: NonNullExpression, - [SyntaxKind.MetaProperty]: MetaProperty, - [SyntaxKind.JsxElement]: JsxElement, - [SyntaxKind.JsxAttributes]: JsxAttributes, - [SyntaxKind.JsxNamespacedName]: JsxNamespacedName, - [SyntaxKind.JsxOpeningElement]: JsxOpeningElement, - [SyntaxKind.JsxSelfClosingElement]: JsxSelfClosingElement, - [SyntaxKind.JsxFragment]: JsxFragment, - [SyntaxKind.JsxOpeningFragment]: JsxOpeningFragment, - [SyntaxKind.JsxClosingFragment]: JsxClosingFragment, - [SyntaxKind.JsxAttribute]: JsxAttribute, - [SyntaxKind.JsxSpreadAttribute]: JsxSpreadAttribute, - [SyntaxKind.JsxClosingElement]: JsxClosingElement, - [SyntaxKind.JsxExpression]: JsxExpression, - [SyntaxKind.EmptyStatement]: EmptyStatement, - [SyntaxKind.DebuggerStatement]: DebuggerStatement, - [SyntaxKind.MissingDeclaration]: MissingDeclaration, - [SyntaxKind.Block]: Block, - [SyntaxKind.VariableStatement]: VariableStatement, - [SyntaxKind.ExpressionStatement]: ExpressionStatement, - [SyntaxKind.IfStatement]: IfStatement, - [SyntaxKind.DoStatement]: DoStatement, - [SyntaxKind.WhileStatement]: WhileStatement, - [SyntaxKind.ForStatement]: ForStatement, - [SyntaxKind.ForInStatement]: ForInStatement, - [SyntaxKind.ForOfStatement]: ForOfStatement, - [SyntaxKind.BreakStatement]: BreakStatement, - [SyntaxKind.ContinueStatement]: ContinueStatement, - [SyntaxKind.ReturnStatement]: ReturnStatement, - [SyntaxKind.WithStatement]: WithStatement, - [SyntaxKind.SwitchStatement]: SwitchStatement, - [SyntaxKind.CaseBlock]: CaseBlock, - [SyntaxKind.CaseClause]: CaseClause, - [SyntaxKind.DefaultClause]: DefaultClause, - [SyntaxKind.LabeledStatement]: LabeledStatement, - [SyntaxKind.ThrowStatement]: ThrowStatement, - [SyntaxKind.TryStatement]: TryStatement, - [SyntaxKind.CatchClause]: CatchClause, - [SyntaxKind.ClassDeclaration]: ClassDeclaration, - [SyntaxKind.ClassExpression]: ClassExpression, - [SyntaxKind.InterfaceDeclaration]: InterfaceDeclaration, - [SyntaxKind.HeritageClause]: HeritageClause, - [SyntaxKind.TypeAliasDeclaration]: TypeAliasDeclaration, - [SyntaxKind.EnumMember]: EnumMember, - [SyntaxKind.EnumDeclaration]: EnumDeclaration, - [SyntaxKind.ModuleDeclaration]: ModuleDeclaration, - [SyntaxKind.ModuleBlock]: ModuleBlock, - [SyntaxKind.ImportEqualsDeclaration]: ImportEqualsDeclaration, - [SyntaxKind.ExternalModuleReference]: ExternalModuleReference, - [SyntaxKind.ImportDeclaration]: ImportDeclaration, - [SyntaxKind.ImportClause]: ImportClause, - [SyntaxKind.ImportAttribute]: ImportAttribute, - [SyntaxKind.ImportAttributes]: ImportAttributes, - [SyntaxKind.NamespaceImport]: NamespaceImport, - [SyntaxKind.NamespaceExport]: NamespaceExport, - [SyntaxKind.NamespaceExportDeclaration]: NamespaceExportDeclaration, - [SyntaxKind.ExportDeclaration]: ExportDeclaration, - [SyntaxKind.NamedImports]: NamedImports, - [SyntaxKind.NamedExports]: NamedExports, - [SyntaxKind.ImportSpecifier]: ImportSpecifier, - [SyntaxKind.ExportSpecifier]: ExportSpecifier, - [SyntaxKind.ExportAssignment]: ExportAssignment, - [SyntaxKind.JSDocTypeExpression]: JSDocTypeExpression, - [SyntaxKind.JSDocNameReference]: JSDocNameReference, - [SyntaxKind.JSDocMemberName]: JSDocMemberName, - [SyntaxKind.JSDocAllType]: JSDocAllType, - [SyntaxKind.JSDocUnknownType]: JSDocUnknownType, - [SyntaxKind.JSDocNonNullableType]: JSDocNonNullableType, - [SyntaxKind.JSDocNullableType]: JSDocNullableType, - [SyntaxKind.JSDocOptionalType]: JSDocOptionalType, - [SyntaxKind.JSDocFunctionType]: JSDocFunctionType, - [SyntaxKind.JSDocVariadicType]: JSDocVariadicType, - [SyntaxKind.JSDocNamepathType]: JSDocNamepathType, - [SyntaxKind.JSDoc]: JSDocNode, - [SyntaxKind.JSDocLink]: JSDocLink, - [SyntaxKind.JSDocLinkCode]: JSDocLinkCode, - [SyntaxKind.JSDocLinkPlain]: JSDocLinkPlain, - [SyntaxKind.JSDocText]: JSDocText, - [SyntaxKind.JSDocTag]: JSDocUnknownTag, - [SyntaxKind.JSDocAugmentsTag]: JSDocAugmentsTag, - [SyntaxKind.JSDocImplementsTag]: JSDocImplementsTag, - [SyntaxKind.JSDocAuthorTag]: JSDocAuthorTag, - [SyntaxKind.JSDocDeprecatedTag]: JSDocDeprecatedTag, - [SyntaxKind.JSDocClassTag]: JSDocClassTag, - [SyntaxKind.JSDocPublicTag]: JSDocPublicTag, - [SyntaxKind.JSDocPrivateTag]: JSDocPrivateTag, - [SyntaxKind.JSDocProtectedTag]: JSDocProtectedTag, - [SyntaxKind.JSDocReadonlyTag]: JSDocReadonlyTag, - [SyntaxKind.JSDocOverrideTag]: JSDocOverrideTag, - [SyntaxKind.JSDocEnumTag]: JSDocEnumTag, - [SyntaxKind.JSDocThisTag]: JSDocThisTag, - [SyntaxKind.JSDocTemplateTag]: JSDocTemplateTag, - [SyntaxKind.JSDocSeeTag]: JSDocSeeTag, - [SyntaxKind.JSDocReturnTag]: JSDocReturnTag, - [SyntaxKind.JSDocTypeTag]: JSDocTypeTag, - [SyntaxKind.JSDocTypedefTag]: JSDocTypedefTag, - [SyntaxKind.JSDocCallbackTag]: JSDocCallbackTag, - [SyntaxKind.JSDocOverloadTag]: JSDocOverloadTag, - [SyntaxKind.JSDocThrowsTag]: JSDocThrowsTag, - [SyntaxKind.JSDocSignature]: JSDocSignature, - [SyntaxKind.JSDocPropertyTag]: JSDocPropertyTag, - [SyntaxKind.JSDocParameterTag]: JSDocParameterTag, - [SyntaxKind.JSDocTypeLiteral]: JSDocTypeLiteral, - [SyntaxKind.JSDocSatisfiesTag]: JSDocSatisfiesTag, - [SyntaxKind.JSDocImportTag]: JSDocImportTag, - [SyntaxKind.SourceFile]: SourceFile, - [SyntaxKind.Bundle]: Bundle, - [SyntaxKind.SyntaxList]: SyntaxList, - [SyntaxKind.NotEmittedStatement]: NotEmittedStatement, - [SyntaxKind.NotEmittedTypeElement]: NotEmittedTypeElement, - [SyntaxKind.PartiallyEmittedExpression]: PartiallyEmittedExpression, - [SyntaxKind.CommaListExpression]: CommaListExpression, - [SyntaxKind.SyntheticReferenceExpression]: SyntheticReferenceExpression, - [SyntaxKind.Count]: never, - [SyntaxKind.NonTextFileMarkerTrivia]: never, -} - -/** @internal */ + [SyntaxKind.Unknown]: Token; + [SyntaxKind.EndOfFileToken]: EndOfFileToken; + [SyntaxKind.SingleLineCommentTrivia]: Token; + [SyntaxKind.MultiLineCommentTrivia]: Token; + [SyntaxKind.NewLineTrivia]: Token; + [SyntaxKind.WhitespaceTrivia]: Token; + [SyntaxKind.ShebangTrivia]: Token; + [SyntaxKind.ConflictMarkerTrivia]: Token; + [SyntaxKind.NonTextFileMarkerTrivia]: never; + [SyntaxKind.NumericLiteral]: NumericLiteral; + [SyntaxKind.BigIntLiteral]: BigIntLiteral; + [SyntaxKind.StringLiteral]: StringLiteral; + [SyntaxKind.JsxText]: JsxText; + [SyntaxKind.JsxTextAllWhiteSpaces]: never; + [SyntaxKind.RegularExpressionLiteral]: RegularExpressionLiteral; + [SyntaxKind.NoSubstitutionTemplateLiteral]: NoSubstitutionTemplateLiteral; + [SyntaxKind.TemplateHead]: TemplateHead; + [SyntaxKind.TemplateMiddle]: TemplateMiddle; + [SyntaxKind.TemplateTail]: TemplateTail; + [SyntaxKind.OpenBraceToken]: Token; + [SyntaxKind.CloseBraceToken]: Token; + [SyntaxKind.OpenParenToken]: Token; + [SyntaxKind.CloseParenToken]: Token; + [SyntaxKind.OpenBracketToken]: Token; + [SyntaxKind.CloseBracketToken]: Token; + [SyntaxKind.DotToken]: Token; + [SyntaxKind.DotDotDotToken]: Token; + [SyntaxKind.SemicolonToken]: Token; + [SyntaxKind.CommaToken]: Token; + [SyntaxKind.QuestionDotToken]: Token; + [SyntaxKind.LessThanToken]: Token; + [SyntaxKind.LessThanSlashToken]: Token; + [SyntaxKind.GreaterThanToken]: Token; + [SyntaxKind.LessThanEqualsToken]: Token; + [SyntaxKind.GreaterThanEqualsToken]: Token; + [SyntaxKind.EqualsEqualsToken]: Token; + [SyntaxKind.ExclamationEqualsToken]: Token; + [SyntaxKind.EqualsEqualsEqualsToken]: Token; + [SyntaxKind.ExclamationEqualsEqualsToken]: Token; + [SyntaxKind.EqualsGreaterThanToken]: Token; + [SyntaxKind.PlusToken]: Token; + [SyntaxKind.MinusToken]: Token; + [SyntaxKind.AsteriskToken]: Token; + [SyntaxKind.AsteriskAsteriskToken]: Token; + [SyntaxKind.SlashToken]: Token; + [SyntaxKind.PercentToken]: Token; + [SyntaxKind.PlusPlusToken]: Token; + [SyntaxKind.MinusMinusToken]: Token; + [SyntaxKind.LessThanLessThanToken]: Token; + [SyntaxKind.GreaterThanGreaterThanToken]: Token; + [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: Token; + [SyntaxKind.AmpersandToken]: Token; + [SyntaxKind.BarToken]: Token; + [SyntaxKind.CaretToken]: Token; + [SyntaxKind.ExclamationToken]: Token; + [SyntaxKind.TildeToken]: Token; + [SyntaxKind.AmpersandAmpersandToken]: Token; + [SyntaxKind.BarBarToken]: Token; + [SyntaxKind.QuestionToken]: Token; + [SyntaxKind.ColonToken]: Token; + [SyntaxKind.AtToken]: Token; + [SyntaxKind.QuestionQuestionToken]: Token; + [SyntaxKind.BacktickToken]: Token; + [SyntaxKind.HashToken]: Token; + [SyntaxKind.EqualsToken]: Token; + [SyntaxKind.PlusEqualsToken]: Token; + [SyntaxKind.MinusEqualsToken]: Token; + [SyntaxKind.AsteriskEqualsToken]: Token; + [SyntaxKind.AsteriskAsteriskEqualsToken]: Token; + [SyntaxKind.SlashEqualsToken]: Token; + [SyntaxKind.PercentEqualsToken]: Token; + [SyntaxKind.LessThanLessThanEqualsToken]: Token; + [SyntaxKind.GreaterThanGreaterThanEqualsToken]: Token; + [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: Token; + [SyntaxKind.AmpersandEqualsToken]: Token; + [SyntaxKind.BarEqualsToken]: Token; + [SyntaxKind.BarBarEqualsToken]: Token; + [SyntaxKind.AmpersandAmpersandEqualsToken]: Token; + [SyntaxKind.QuestionQuestionEqualsToken]: Token; + [SyntaxKind.CaretEqualsToken]: Token; + [SyntaxKind.Identifier]: Identifier; + [SyntaxKind.PrivateIdentifier]: PrivateIdentifier; + [SyntaxKind.JSDocCommentTextToken]: never; + [SyntaxKind.BreakKeyword]: Token; + [SyntaxKind.CaseKeyword]: Token; + [SyntaxKind.CatchKeyword]: Token; + [SyntaxKind.ClassKeyword]: Token; + [SyntaxKind.ConstKeyword]: Token; + [SyntaxKind.ContinueKeyword]: Token; + [SyntaxKind.DebuggerKeyword]: Token; + [SyntaxKind.DefaultKeyword]: Token; + [SyntaxKind.DeleteKeyword]: Token; + [SyntaxKind.DoKeyword]: Token; + [SyntaxKind.ElseKeyword]: Token; + [SyntaxKind.EnumKeyword]: Token; + [SyntaxKind.ExportKeyword]: Token; + [SyntaxKind.ExtendsKeyword]: Token; + [SyntaxKind.FalseKeyword]: FalseLiteral; + [SyntaxKind.FinallyKeyword]: Token; + [SyntaxKind.ForKeyword]: Token; + [SyntaxKind.FunctionKeyword]: Token; + [SyntaxKind.IfKeyword]: Token; + [SyntaxKind.ImportKeyword]: ImportExpression; + [SyntaxKind.InKeyword]: Token; + [SyntaxKind.InstanceOfKeyword]: Token; + [SyntaxKind.NewKeyword]: Token; + [SyntaxKind.NullKeyword]: NullLiteral; + [SyntaxKind.ReturnKeyword]: Token; + [SyntaxKind.SuperKeyword]: SuperExpression; + [SyntaxKind.SwitchKeyword]: Token; + [SyntaxKind.ThisKeyword]: ThisExpression; + [SyntaxKind.ThrowKeyword]: Token; + [SyntaxKind.TrueKeyword]: TrueLiteral; + [SyntaxKind.TryKeyword]: Token; + [SyntaxKind.TypeOfKeyword]: Token; + [SyntaxKind.VarKeyword]: Token; + [SyntaxKind.VoidKeyword]: Token; + [SyntaxKind.WhileKeyword]: Token; + [SyntaxKind.WithKeyword]: Token; + [SyntaxKind.ImplementsKeyword]: Token; + [SyntaxKind.InterfaceKeyword]: Token; + [SyntaxKind.LetKeyword]: Token; + [SyntaxKind.PackageKeyword]: Token; + [SyntaxKind.PrivateKeyword]: Token; + [SyntaxKind.ProtectedKeyword]: Token; + [SyntaxKind.PublicKeyword]: Token; + [SyntaxKind.StaticKeyword]: Token; + [SyntaxKind.YieldKeyword]: Token; + [SyntaxKind.AbstractKeyword]: Token; + [SyntaxKind.AccessorKeyword]: Token; + [SyntaxKind.AsKeyword]: Token; + [SyntaxKind.AssertsKeyword]: Token; + [SyntaxKind.AssertKeyword]: Token; + [SyntaxKind.AnyKeyword]: Token; + [SyntaxKind.AsyncKeyword]: Token; + [SyntaxKind.AwaitKeyword]: Token; + [SyntaxKind.BooleanKeyword]: Token; + [SyntaxKind.ConstructorKeyword]: Token; + [SyntaxKind.DeclareKeyword]: Token; + [SyntaxKind.GetKeyword]: Token; + [SyntaxKind.InferKeyword]: Token; + [SyntaxKind.IntrinsicKeyword]: Token; + [SyntaxKind.IsKeyword]: Token; + [SyntaxKind.KeyOfKeyword]: Token; + [SyntaxKind.ModuleKeyword]: Token; + [SyntaxKind.NamespaceKeyword]: Token; + [SyntaxKind.NeverKeyword]: Token; + [SyntaxKind.OutKeyword]: Token; + [SyntaxKind.ReadonlyKeyword]: Token; + [SyntaxKind.RequireKeyword]: Token; + [SyntaxKind.NumberKeyword]: Token; + [SyntaxKind.ObjectKeyword]: Token; + [SyntaxKind.SatisfiesKeyword]: Token; + [SyntaxKind.SetKeyword]: Token; + [SyntaxKind.StringKeyword]: Token; + [SyntaxKind.SymbolKeyword]: Token; + [SyntaxKind.TypeKeyword]: Token; + [SyntaxKind.UndefinedKeyword]: Token; + [SyntaxKind.UniqueKeyword]: Token; + [SyntaxKind.UnknownKeyword]: Token; + [SyntaxKind.UsingKeyword]: Token; + [SyntaxKind.FromKeyword]: Token; + [SyntaxKind.GlobalKeyword]: Token; + [SyntaxKind.BigIntKeyword]: Token; + [SyntaxKind.OverrideKeyword]: Token; + [SyntaxKind.OfKeyword]: Token; + [SyntaxKind.QualifiedName]: QualifiedName; + [SyntaxKind.ComputedPropertyName]: ComputedPropertyName; + [SyntaxKind.Decorator]: Decorator; + [SyntaxKind.TypeParameter]: TypeParameterDeclaration; + [SyntaxKind.CallSignature]: CallSignatureDeclaration; + [SyntaxKind.ConstructSignature]: ConstructSignatureDeclaration; + [SyntaxKind.VariableDeclaration]: VariableDeclaration; + [SyntaxKind.VariableDeclarationList]: VariableDeclarationList; + [SyntaxKind.Parameter]: ParameterDeclaration; + [SyntaxKind.BindingElement]: BindingElement; + [SyntaxKind.PropertySignature]: PropertySignature; + [SyntaxKind.PropertyDeclaration]: PropertyDeclaration; + [SyntaxKind.PropertyAssignment]: PropertyAssignment; + [SyntaxKind.ShorthandPropertyAssignment]: ShorthandPropertyAssignment; + [SyntaxKind.SpreadAssignment]: SpreadAssignment; + [SyntaxKind.ObjectBindingPattern]: ObjectBindingPattern; + [SyntaxKind.ArrayBindingPattern]: ArrayBindingPattern; + [SyntaxKind.FunctionDeclaration]: FunctionDeclaration; + [SyntaxKind.MethodSignature]: MethodSignature; + [SyntaxKind.MethodDeclaration]: MethodDeclaration; + [SyntaxKind.Constructor]: ConstructorDeclaration; + [SyntaxKind.SemicolonClassElement]: SemicolonClassElement; + [SyntaxKind.GetAccessor]: GetAccessorDeclaration; + [SyntaxKind.SetAccessor]: SetAccessorDeclaration; + [SyntaxKind.IndexSignature]: IndexSignatureDeclaration; + [SyntaxKind.ClassStaticBlockDeclaration]: ClassStaticBlockDeclaration; + [SyntaxKind.ImportTypeAssertionContainer]: ImportTypeAssertionContainer; + [SyntaxKind.ImportType]: ImportTypeNode; + [SyntaxKind.ThisType]: ThisTypeNode; + [SyntaxKind.FunctionType]: FunctionTypeNode; + [SyntaxKind.ConstructorType]: ConstructorTypeNode; + [SyntaxKind.TypeReference]: TypeReferenceNode; + [SyntaxKind.TypePredicate]: TypePredicateNode; + [SyntaxKind.TypeQuery]: TypeQueryNode; + [SyntaxKind.TypeLiteral]: TypeLiteralNode; + [SyntaxKind.ArrayType]: ArrayTypeNode; + [SyntaxKind.TupleType]: TupleTypeNode; + [SyntaxKind.NamedTupleMember]: NamedTupleMember; + [SyntaxKind.OptionalType]: OptionalTypeNode; + [SyntaxKind.RestType]: RestTypeNode; + [SyntaxKind.UnionType]: UnionTypeNode; + [SyntaxKind.IntersectionType]: IntersectionTypeNode; + [SyntaxKind.ConditionalType]: ConditionalTypeNode; + [SyntaxKind.InferType]: InferTypeNode; + [SyntaxKind.ParenthesizedType]: ParenthesizedTypeNode; + [SyntaxKind.TypeOperator]: TypeOperatorNode; + [SyntaxKind.IndexedAccessType]: IndexedAccessTypeNode; + [SyntaxKind.MappedType]: MappedTypeNode; + [SyntaxKind.LiteralType]: LiteralTypeNode; + [SyntaxKind.TemplateLiteralType]: TemplateLiteralTypeNode; + [SyntaxKind.TemplateLiteralTypeSpan]: TemplateLiteralTypeSpan; + [SyntaxKind.OmittedExpression]: OmittedExpression; + [SyntaxKind.PrefixUnaryExpression]: PrefixUnaryExpression; + [SyntaxKind.PostfixUnaryExpression]: PostfixUnaryExpression; + [SyntaxKind.DeleteExpression]: DeleteExpression; + [SyntaxKind.TypeOfExpression]: TypeOfExpression; + [SyntaxKind.VoidExpression]: VoidExpression; + [SyntaxKind.AwaitExpression]: AwaitExpression; + [SyntaxKind.YieldExpression]: YieldExpression; + [SyntaxKind.BinaryExpression]: BinaryExpression; + [SyntaxKind.ConditionalExpression]: ConditionalExpression; + [SyntaxKind.FunctionExpression]: FunctionExpression; + [SyntaxKind.ArrowFunction]: ArrowFunction; + [SyntaxKind.TemplateExpression]: TemplateExpression; + [SyntaxKind.TemplateSpan]: TemplateSpan; + [SyntaxKind.ParenthesizedExpression]: ParenthesizedExpression; + [SyntaxKind.ArrayLiteralExpression]: ArrayLiteralExpression; + [SyntaxKind.SpreadElement]: SpreadElement; + [SyntaxKind.ObjectLiteralExpression]: ObjectLiteralExpression; + [SyntaxKind.PropertyAccessExpression]: PropertyAccessExpression; + [SyntaxKind.ElementAccessExpression]: ElementAccessExpression; + [SyntaxKind.CallExpression]: CallExpression; + [SyntaxKind.ExpressionWithTypeArguments]: ExpressionWithTypeArguments; + [SyntaxKind.NewExpression]: NewExpression; + [SyntaxKind.TaggedTemplateExpression]: TaggedTemplateExpression; + [SyntaxKind.AsExpression]: AsExpression; + [SyntaxKind.TypeAssertionExpression]: TypeAssertion; + [SyntaxKind.SyntheticExpression]: SyntheticExpression; + [SyntaxKind.SatisfiesExpression]: SatisfiesExpression; + [SyntaxKind.NonNullExpression]: NonNullExpression; + [SyntaxKind.MetaProperty]: MetaProperty; + [SyntaxKind.JsxElement]: JsxElement; + [SyntaxKind.JsxAttributes]: JsxAttributes; + [SyntaxKind.JsxNamespacedName]: JsxNamespacedName; + [SyntaxKind.JsxOpeningElement]: JsxOpeningElement; + [SyntaxKind.JsxSelfClosingElement]: JsxSelfClosingElement; + [SyntaxKind.JsxFragment]: JsxFragment; + [SyntaxKind.JsxOpeningFragment]: JsxOpeningFragment; + [SyntaxKind.JsxClosingFragment]: JsxClosingFragment; + [SyntaxKind.JsxAttribute]: JsxAttribute; + [SyntaxKind.JsxSpreadAttribute]: JsxSpreadAttribute; + [SyntaxKind.JsxClosingElement]: JsxClosingElement; + [SyntaxKind.JsxExpression]: JsxExpression; + [SyntaxKind.EmptyStatement]: EmptyStatement; + [SyntaxKind.DebuggerStatement]: DebuggerStatement; + [SyntaxKind.MissingDeclaration]: MissingDeclaration; + [SyntaxKind.Block]: Block; + [SyntaxKind.VariableStatement]: VariableStatement; + [SyntaxKind.ExpressionStatement]: ExpressionStatement; + [SyntaxKind.IfStatement]: IfStatement; + [SyntaxKind.DoStatement]: DoStatement; + [SyntaxKind.WhileStatement]: WhileStatement; + [SyntaxKind.ForStatement]: ForStatement; + [SyntaxKind.ForInStatement]: ForInStatement; + [SyntaxKind.ForOfStatement]: ForOfStatement; + [SyntaxKind.BreakStatement]: BreakStatement; + [SyntaxKind.ContinueStatement]: ContinueStatement; + [SyntaxKind.ReturnStatement]: ReturnStatement; + [SyntaxKind.WithStatement]: WithStatement; + [SyntaxKind.SwitchStatement]: SwitchStatement; + [SyntaxKind.CaseBlock]: CaseBlock; + [SyntaxKind.CaseClause]: CaseClause; + [SyntaxKind.DefaultClause]: DefaultClause; + [SyntaxKind.LabeledStatement]: LabeledStatement; + [SyntaxKind.ThrowStatement]: ThrowStatement; + [SyntaxKind.TryStatement]: TryStatement; + [SyntaxKind.CatchClause]: CatchClause; + [SyntaxKind.ClassDeclaration]: ClassDeclaration; + [SyntaxKind.ClassExpression]: ClassExpression; + [SyntaxKind.InterfaceDeclaration]: InterfaceDeclaration; + [SyntaxKind.HeritageClause]: HeritageClause; + [SyntaxKind.TypeAliasDeclaration]: TypeAliasDeclaration; + [SyntaxKind.EnumMember]: EnumMember; + [SyntaxKind.EnumDeclaration]: EnumDeclaration; + [SyntaxKind.ModuleDeclaration]: ModuleDeclaration; + [SyntaxKind.ModuleBlock]: ModuleBlock; + [SyntaxKind.ImportEqualsDeclaration]: ImportEqualsDeclaration; + [SyntaxKind.ExternalModuleReference]: ExternalModuleReference; + [SyntaxKind.ImportDeclaration]: ImportDeclaration; + [SyntaxKind.ImportClause]: ImportClause; + [SyntaxKind.ImportAttribute]: ImportAttribute; + [SyntaxKind.ImportAttributes]: ImportAttributes; + [SyntaxKind.NamespaceImport]: NamespaceImport; + [SyntaxKind.NamespaceExport]: NamespaceExport; + [SyntaxKind.NamespaceExportDeclaration]: NamespaceExportDeclaration; + [SyntaxKind.ExportDeclaration]: ExportDeclaration; + [SyntaxKind.NamedImports]: NamedImports; + [SyntaxKind.NamedExports]: NamedExports; + [SyntaxKind.ImportSpecifier]: ImportSpecifier; + [SyntaxKind.ExportSpecifier]: ExportSpecifier; + [SyntaxKind.ExportAssignment]: ExportAssignment; + [SyntaxKind.JSDocTypeExpression]: JSDocTypeExpression; + [SyntaxKind.JSDocNameReference]: JSDocNameReference; + [SyntaxKind.JSDocMemberName]: JSDocMemberName; + [SyntaxKind.JSDocAllType]: JSDocAllType; + [SyntaxKind.JSDocUnknownType]: JSDocUnknownType; + [SyntaxKind.JSDocNonNullableType]: JSDocNonNullableType; + [SyntaxKind.JSDocNullableType]: JSDocNullableType; + [SyntaxKind.JSDocOptionalType]: JSDocOptionalType; + [SyntaxKind.JSDocFunctionType]: JSDocFunctionType; + [SyntaxKind.JSDocVariadicType]: JSDocVariadicType; + [SyntaxKind.JSDocNamepathType]: JSDocNamepathType; + [SyntaxKind.JSDoc]: JSDocNode; + [SyntaxKind.JSDocLink]: JSDocLink; + [SyntaxKind.JSDocLinkCode]: JSDocLinkCode; + [SyntaxKind.JSDocLinkPlain]: JSDocLinkPlain; + [SyntaxKind.JSDocText]: JSDocText; + [SyntaxKind.JSDocTag]: JSDocUnknownTag; + [SyntaxKind.JSDocAugmentsTag]: JSDocAugmentsTag; + [SyntaxKind.JSDocImplementsTag]: JSDocImplementsTag; + [SyntaxKind.JSDocAuthorTag]: JSDocAuthorTag; + [SyntaxKind.JSDocDeprecatedTag]: JSDocDeprecatedTag; + [SyntaxKind.JSDocClassTag]: JSDocClassTag; + [SyntaxKind.JSDocPublicTag]: JSDocPublicTag; + [SyntaxKind.JSDocPrivateTag]: JSDocPrivateTag; + [SyntaxKind.JSDocProtectedTag]: JSDocProtectedTag; + [SyntaxKind.JSDocReadonlyTag]: JSDocReadonlyTag; + [SyntaxKind.JSDocOverrideTag]: JSDocOverrideTag; + [SyntaxKind.JSDocEnumTag]: JSDocEnumTag; + [SyntaxKind.JSDocThisTag]: JSDocThisTag; + [SyntaxKind.JSDocTemplateTag]: JSDocTemplateTag; + [SyntaxKind.JSDocSeeTag]: JSDocSeeTag; + [SyntaxKind.JSDocReturnTag]: JSDocReturnTag; + [SyntaxKind.JSDocTypeTag]: JSDocTypeTag; + [SyntaxKind.JSDocTypedefTag]: JSDocTypedefTag; + [SyntaxKind.JSDocCallbackTag]: JSDocCallbackTag; + [SyntaxKind.JSDocOverloadTag]: JSDocOverloadTag; + [SyntaxKind.JSDocThrowsTag]: JSDocThrowsTag; + [SyntaxKind.JSDocSignature]: JSDocSignature; + [SyntaxKind.JSDocPropertyTag]: JSDocPropertyTag; + [SyntaxKind.JSDocParameterTag]: JSDocParameterTag; + [SyntaxKind.JSDocTypeLiteral]: JSDocTypeLiteral; + [SyntaxKind.JSDocSatisfiesTag]: JSDocSatisfiesTag; + [SyntaxKind.JSDocImportTag]: JSDocImportTag; + [SyntaxKind.SourceFile]: SourceFile; + [SyntaxKind.Bundle]: Bundle; + [SyntaxKind.SyntaxList]: SyntaxList; + [SyntaxKind.NotEmittedStatement]: NotEmittedStatement; + [SyntaxKind.NotEmittedTypeElement]: NotEmittedTypeElement; + [SyntaxKind.PartiallyEmittedExpression]: PartiallyEmittedExpression; + [SyntaxKind.CommaListExpression]: CommaListExpression; + [SyntaxKind.SyntheticReferenceExpression]: SyntheticReferenceExpression; + [SyntaxKind.Count]: never; + [SyntaxKind.NonTextFileMarkerTrivia]: never; +} + +/** @internal @knipignore */ export interface AstNodeType { - [SyntaxKind.Unknown]: AstToken, - [SyntaxKind.EndOfFileToken]: AstEndOfFileToken, - [SyntaxKind.SingleLineCommentTrivia]: AstToken, - [SyntaxKind.MultiLineCommentTrivia]: AstToken, - [SyntaxKind.NewLineTrivia]: AstToken, - [SyntaxKind.WhitespaceTrivia]: AstToken, - [SyntaxKind.ShebangTrivia]: AstToken, - [SyntaxKind.ConflictMarkerTrivia]: AstToken, - [SyntaxKind.NonTextFileMarkerTrivia]: never, - [SyntaxKind.NumericLiteral]: AstNumericLiteral, - [SyntaxKind.BigIntLiteral]: AstBigIntLiteral, - [SyntaxKind.StringLiteral]: AstStringLiteral, - [SyntaxKind.JsxText]: AstJsxText, - [SyntaxKind.JsxTextAllWhiteSpaces]: never, - [SyntaxKind.RegularExpressionLiteral]: AstRegularExpressionLiteral, - [SyntaxKind.NoSubstitutionTemplateLiteral]: AstNoSubstitutionTemplateLiteral, - [SyntaxKind.TemplateHead]: AstTemplateHead, - [SyntaxKind.TemplateMiddle]: AstTemplateMiddle, - [SyntaxKind.TemplateTail]: AstTemplateTail, - [SyntaxKind.OpenBraceToken]: AstToken, - [SyntaxKind.CloseBraceToken]: AstToken, - [SyntaxKind.OpenParenToken]: AstToken, - [SyntaxKind.CloseParenToken]: AstToken, - [SyntaxKind.OpenBracketToken]: AstToken, - [SyntaxKind.CloseBracketToken]: AstToken, - [SyntaxKind.DotToken]: AstDotToken, - [SyntaxKind.DotDotDotToken]: AstDotDotDotToken, - [SyntaxKind.SemicolonToken]: AstToken, - [SyntaxKind.CommaToken]: AstToken, - [SyntaxKind.QuestionDotToken]: AstQuestionDotToken, - [SyntaxKind.LessThanToken]: AstToken, - [SyntaxKind.LessThanSlashToken]: AstToken, - [SyntaxKind.GreaterThanToken]: AstToken, - [SyntaxKind.LessThanEqualsToken]: AstToken, - [SyntaxKind.GreaterThanEqualsToken]: AstToken, - [SyntaxKind.EqualsEqualsToken]: AstToken, - [SyntaxKind.ExclamationEqualsToken]: AstToken, - [SyntaxKind.EqualsEqualsEqualsToken]: AstToken, - [SyntaxKind.ExclamationEqualsEqualsToken]: AstToken, - [SyntaxKind.EqualsGreaterThanToken]: AstEqualsGreaterThanToken, - [SyntaxKind.PlusToken]: AstPlusToken, - [SyntaxKind.MinusToken]: AstMinusToken, - [SyntaxKind.AsteriskToken]: AstAsteriskToken, - [SyntaxKind.AsteriskAsteriskToken]: AstToken, - [SyntaxKind.SlashToken]: AstToken, - [SyntaxKind.PercentToken]: AstToken, - [SyntaxKind.PlusPlusToken]: AstToken, - [SyntaxKind.MinusMinusToken]: AstToken, - [SyntaxKind.LessThanLessThanToken]: AstToken, - [SyntaxKind.GreaterThanGreaterThanToken]: AstToken, - [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: AstToken, - [SyntaxKind.AmpersandToken]: AstToken, - [SyntaxKind.BarToken]: AstToken, - [SyntaxKind.CaretToken]: AstToken, - [SyntaxKind.ExclamationToken]: AstExclamationToken, - [SyntaxKind.TildeToken]: AstToken, - [SyntaxKind.AmpersandAmpersandToken]: AstToken, - [SyntaxKind.BarBarToken]: AstToken, - [SyntaxKind.QuestionToken]: AstQuestionToken, - [SyntaxKind.ColonToken]: AstColonToken, - [SyntaxKind.AtToken]: AstToken, - [SyntaxKind.QuestionQuestionToken]: AstToken, - [SyntaxKind.BacktickToken]: AstToken, - [SyntaxKind.HashToken]: AstToken, - [SyntaxKind.EqualsToken]: AstEqualsToken, - [SyntaxKind.PlusEqualsToken]: AstToken, - [SyntaxKind.MinusEqualsToken]: AstToken, - [SyntaxKind.AsteriskEqualsToken]: AstToken, - [SyntaxKind.AsteriskAsteriskEqualsToken]: AstToken, - [SyntaxKind.SlashEqualsToken]: AstToken, - [SyntaxKind.PercentEqualsToken]: AstToken, - [SyntaxKind.LessThanLessThanEqualsToken]: AstToken, - [SyntaxKind.GreaterThanGreaterThanEqualsToken]: AstToken, - [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: AstToken, - [SyntaxKind.AmpersandEqualsToken]: AstToken, - [SyntaxKind.BarEqualsToken]: AstToken, - [SyntaxKind.BarBarEqualsToken]: AstBarBarEqualsToken, - [SyntaxKind.AmpersandAmpersandEqualsToken]: AstAmpersandAmpersandEqualsToken, - [SyntaxKind.QuestionQuestionEqualsToken]: AstQuestionQuestionEqualsToken, - [SyntaxKind.CaretEqualsToken]: AstToken, - [SyntaxKind.Identifier]: AstIdentifier, - [SyntaxKind.PrivateIdentifier]: AstPrivateIdentifier, - [SyntaxKind.JSDocCommentTextToken]: never, - [SyntaxKind.BreakKeyword]: AstToken, - [SyntaxKind.CaseKeyword]: AstCaseKeyword, - [SyntaxKind.CatchKeyword]: AstToken, - [SyntaxKind.ClassKeyword]: AstToken, - [SyntaxKind.ConstKeyword]: AstToken, - [SyntaxKind.ContinueKeyword]: AstToken, - [SyntaxKind.DebuggerKeyword]: AstToken, - [SyntaxKind.DefaultKeyword]: AstDefaultKeyword, - [SyntaxKind.DeleteKeyword]: AstToken, - [SyntaxKind.DoKeyword]: AstToken, - [SyntaxKind.ElseKeyword]: AstToken, - [SyntaxKind.EnumKeyword]: AstToken, - [SyntaxKind.ExportKeyword]: AstExportKeyword, - [SyntaxKind.ExtendsKeyword]: AstToken, - [SyntaxKind.FalseKeyword]: AstFalseLiteral, - [SyntaxKind.FinallyKeyword]: AstToken, - [SyntaxKind.ForKeyword]: AstToken, - [SyntaxKind.FunctionKeyword]: AstToken, - [SyntaxKind.IfKeyword]: AstToken, - [SyntaxKind.ImportKeyword]: AstImportExpression, - [SyntaxKind.InKeyword]: AstInKeyword, - [SyntaxKind.InstanceOfKeyword]: AstToken, - [SyntaxKind.NewKeyword]: AstToken, - [SyntaxKind.NullKeyword]: AstNullLiteral, - [SyntaxKind.ReturnKeyword]: AstToken, - [SyntaxKind.SuperKeyword]: AstSuperExpression, - [SyntaxKind.SwitchKeyword]: AstToken, - [SyntaxKind.ThisKeyword]: AstThisExpression, - [SyntaxKind.ThrowKeyword]: AstToken, - [SyntaxKind.TrueKeyword]: AstTrueLiteral, - [SyntaxKind.TryKeyword]: AstToken, - [SyntaxKind.TypeOfKeyword]: AstToken, - [SyntaxKind.VarKeyword]: AstToken, - [SyntaxKind.VoidKeyword]: AstToken, - [SyntaxKind.WhileKeyword]: AstToken, - [SyntaxKind.WithKeyword]: AstToken, - [SyntaxKind.ImplementsKeyword]: AstToken, - [SyntaxKind.InterfaceKeyword]: AstToken, - [SyntaxKind.LetKeyword]: AstToken, - [SyntaxKind.PackageKeyword]: AstToken, - [SyntaxKind.PrivateKeyword]: AstPrivateKeyword, - [SyntaxKind.ProtectedKeyword]: AstProtectedKeyword, - [SyntaxKind.PublicKeyword]: AstPublicKeyword, - [SyntaxKind.StaticKeyword]: AstStaticKeyword, - [SyntaxKind.YieldKeyword]: AstToken, - [SyntaxKind.AbstractKeyword]: AstAbstractKeyword, - [SyntaxKind.AccessorKeyword]: AstAccessorKeyword, - [SyntaxKind.AsKeyword]: AstToken, - [SyntaxKind.AssertsKeyword]: AstAssertsKeyword, - [SyntaxKind.AssertKeyword]: AstAssertKeyword, - [SyntaxKind.AnyKeyword]: AstToken, - [SyntaxKind.AsyncKeyword]: AstAsyncKeyword, - [SyntaxKind.AwaitKeyword]: AstAwaitKeyword, - [SyntaxKind.BooleanKeyword]: AstToken, - [SyntaxKind.ConstructorKeyword]: AstToken, - [SyntaxKind.DeclareKeyword]: AstDeclareKeyword, - [SyntaxKind.GetKeyword]: AstToken, - [SyntaxKind.InferKeyword]: AstToken, - [SyntaxKind.IntrinsicKeyword]: AstToken, - [SyntaxKind.IsKeyword]: AstToken, - [SyntaxKind.KeyOfKeyword]: AstToken, - [SyntaxKind.ModuleKeyword]: AstToken, - [SyntaxKind.NamespaceKeyword]: AstToken, - [SyntaxKind.NeverKeyword]: AstToken, - [SyntaxKind.OutKeyword]: AstOutKeyword, - [SyntaxKind.ReadonlyKeyword]: AstReadonlyKeyword, - [SyntaxKind.RequireKeyword]: AstToken, - [SyntaxKind.NumberKeyword]: AstToken, - [SyntaxKind.ObjectKeyword]: AstToken, - [SyntaxKind.SatisfiesKeyword]: AstToken, - [SyntaxKind.SetKeyword]: AstToken, - [SyntaxKind.StringKeyword]: AstToken, - [SyntaxKind.SymbolKeyword]: AstToken, - [SyntaxKind.TypeKeyword]: AstToken, - [SyntaxKind.UndefinedKeyword]: AstToken, - [SyntaxKind.UniqueKeyword]: AstToken, - [SyntaxKind.UnknownKeyword]: AstToken, - [SyntaxKind.UsingKeyword]: AstToken, - [SyntaxKind.FromKeyword]: AstToken, - [SyntaxKind.GlobalKeyword]: AstToken, - [SyntaxKind.BigIntKeyword]: AstToken, - [SyntaxKind.OverrideKeyword]: AstOverrideKeyword, - [SyntaxKind.OfKeyword]: AstToken, - [SyntaxKind.QualifiedName]: AstQualifiedName, - [SyntaxKind.ComputedPropertyName]: AstComputedPropertyName, - [SyntaxKind.Decorator]: AstDecorator, - [SyntaxKind.TypeParameter]: AstTypeParameterDeclaration, - [SyntaxKind.CallSignature]: AstCallSignatureDeclaration, - [SyntaxKind.ConstructSignature]: AstConstructSignatureDeclaration, - [SyntaxKind.VariableDeclaration]: AstVariableDeclaration, - [SyntaxKind.VariableDeclarationList]: AstVariableDeclarationList, - [SyntaxKind.Parameter]: AstParameterDeclaration, - [SyntaxKind.BindingElement]: AstBindingElement, - [SyntaxKind.PropertySignature]: AstPropertySignature, - [SyntaxKind.PropertyDeclaration]: AstPropertyDeclaration, - [SyntaxKind.PropertyAssignment]: AstPropertyAssignment, - [SyntaxKind.ShorthandPropertyAssignment]: AstShorthandPropertyAssignment, - [SyntaxKind.SpreadAssignment]: AstSpreadAssignment, - [SyntaxKind.ObjectBindingPattern]: AstObjectBindingPattern, - [SyntaxKind.ArrayBindingPattern]: AstArrayBindingPattern, - [SyntaxKind.FunctionDeclaration]: AstFunctionDeclaration, - [SyntaxKind.MethodSignature]: AstMethodSignature, - [SyntaxKind.MethodDeclaration]: AstMethodDeclaration, - [SyntaxKind.Constructor]: AstConstructorDeclaration, - [SyntaxKind.SemicolonClassElement]: AstSemicolonClassElement, - [SyntaxKind.GetAccessor]: AstGetAccessorDeclaration, - [SyntaxKind.SetAccessor]: AstSetAccessorDeclaration, - [SyntaxKind.IndexSignature]: AstIndexSignatureDeclaration, - [SyntaxKind.ClassStaticBlockDeclaration]: AstClassStaticBlockDeclaration, - [SyntaxKind.ImportTypeAssertionContainer]: AstImportTypeAssertionContainer, - [SyntaxKind.ImportType]: AstImportTypeNode, - [SyntaxKind.ThisType]: AstThisTypeNode, - [SyntaxKind.FunctionType]: AstFunctionTypeNode, - [SyntaxKind.ConstructorType]: AstConstructorTypeNode, - [SyntaxKind.TypeReference]: AstTypeReferenceNode, - [SyntaxKind.TypePredicate]: AstTypePredicateNode, - [SyntaxKind.TypeQuery]: AstTypeQueryNode, - [SyntaxKind.TypeLiteral]: AstTypeLiteralNode, - [SyntaxKind.ArrayType]: AstArrayTypeNode, - [SyntaxKind.TupleType]: AstTupleTypeNode, - [SyntaxKind.NamedTupleMember]: AstNamedTupleMember, - [SyntaxKind.OptionalType]: AstOptionalTypeNode, - [SyntaxKind.RestType]: AstRestTypeNode, - [SyntaxKind.UnionType]: AstUnionTypeNode, - [SyntaxKind.IntersectionType]: AstIntersectionTypeNode, - [SyntaxKind.ConditionalType]: AstConditionalTypeNode, - [SyntaxKind.InferType]: AstInferTypeNode, - [SyntaxKind.ParenthesizedType]: AstParenthesizedTypeNode, - [SyntaxKind.TypeOperator]: AstTypeOperatorNode, - [SyntaxKind.IndexedAccessType]: AstIndexedAccessTypeNode, - [SyntaxKind.MappedType]: AstMappedTypeNode, - [SyntaxKind.LiteralType]: AstLiteralTypeNode, - [SyntaxKind.TemplateLiteralType]: AstTemplateLiteralTypeNode, - [SyntaxKind.TemplateLiteralTypeSpan]: AstTemplateLiteralTypeSpan, - [SyntaxKind.OmittedExpression]: AstOmittedExpression, - [SyntaxKind.PrefixUnaryExpression]: AstPrefixUnaryExpression, - [SyntaxKind.PostfixUnaryExpression]: AstPostfixUnaryExpression, - [SyntaxKind.DeleteExpression]: AstDeleteExpression, - [SyntaxKind.TypeOfExpression]: AstTypeOfExpression, - [SyntaxKind.VoidExpression]: AstVoidExpression, - [SyntaxKind.AwaitExpression]: AstAwaitExpression, - [SyntaxKind.YieldExpression]: AstYieldExpression, - [SyntaxKind.BinaryExpression]: AstBinaryExpression, - [SyntaxKind.ConditionalExpression]: AstConditionalExpression, - [SyntaxKind.FunctionExpression]: AstFunctionExpression, - [SyntaxKind.ArrowFunction]: AstArrowFunction, - [SyntaxKind.TemplateExpression]: AstTemplateExpression, - [SyntaxKind.TemplateSpan]: AstTemplateSpan, - [SyntaxKind.ParenthesizedExpression]: AstParenthesizedExpression, - [SyntaxKind.ArrayLiteralExpression]: AstArrayLiteralExpression, - [SyntaxKind.SpreadElement]: AstSpreadElement, - [SyntaxKind.ObjectLiteralExpression]: AstObjectLiteralExpression, - [SyntaxKind.PropertyAccessExpression]: AstPropertyAccessExpression, - [SyntaxKind.ElementAccessExpression]: AstElementAccessExpression, - [SyntaxKind.CallExpression]: AstCallExpression, - [SyntaxKind.ExpressionWithTypeArguments]: AstExpressionWithTypeArguments, - [SyntaxKind.NewExpression]: AstNewExpression, - [SyntaxKind.TaggedTemplateExpression]: AstTaggedTemplateExpression, - [SyntaxKind.AsExpression]: AstAsExpression, - [SyntaxKind.TypeAssertionExpression]: AstTypeAssertion, - [SyntaxKind.SyntheticExpression]: AstSyntheticExpression, - [SyntaxKind.SatisfiesExpression]: AstSatisfiesExpression, - [SyntaxKind.NonNullExpression]: AstNonNullExpression, - [SyntaxKind.MetaProperty]: AstMetaProperty, - [SyntaxKind.JsxElement]: AstJsxElement, - [SyntaxKind.JsxAttributes]: AstJsxAttributes, - [SyntaxKind.JsxNamespacedName]: AstJsxNamespacedName, - [SyntaxKind.JsxOpeningElement]: AstJsxOpeningElement, - [SyntaxKind.JsxSelfClosingElement]: AstJsxSelfClosingElement, - [SyntaxKind.JsxFragment]: AstJsxFragment, - [SyntaxKind.JsxOpeningFragment]: AstJsxOpeningFragment, - [SyntaxKind.JsxClosingFragment]: AstJsxClosingFragment, - [SyntaxKind.JsxAttribute]: AstJsxAttribute, - [SyntaxKind.JsxSpreadAttribute]: AstJsxSpreadAttribute, - [SyntaxKind.JsxClosingElement]: AstJsxClosingElement, - [SyntaxKind.JsxExpression]: AstJsxExpression, - [SyntaxKind.EmptyStatement]: AstEmptyStatement, - [SyntaxKind.DebuggerStatement]: AstDebuggerStatement, - [SyntaxKind.MissingDeclaration]: AstMissingDeclaration, - [SyntaxKind.Block]: AstBlock, - [SyntaxKind.VariableStatement]: AstVariableStatement, - [SyntaxKind.ExpressionStatement]: AstExpressionStatement, - [SyntaxKind.IfStatement]: AstIfStatement, - [SyntaxKind.DoStatement]: AstDoStatement, - [SyntaxKind.WhileStatement]: AstWhileStatement, - [SyntaxKind.ForStatement]: AstForStatement, - [SyntaxKind.ForInStatement]: AstForInStatement, - [SyntaxKind.ForOfStatement]: AstForOfStatement, - [SyntaxKind.BreakStatement]: AstBreakStatement, - [SyntaxKind.ContinueStatement]: AstContinueStatement, - [SyntaxKind.ReturnStatement]: AstReturnStatement, - [SyntaxKind.WithStatement]: AstWithStatement, - [SyntaxKind.SwitchStatement]: AstSwitchStatement, - [SyntaxKind.CaseBlock]: AstCaseBlock, - [SyntaxKind.CaseClause]: AstCaseClause, - [SyntaxKind.DefaultClause]: AstDefaultClause, - [SyntaxKind.LabeledStatement]: AstLabeledStatement, - [SyntaxKind.ThrowStatement]: AstThrowStatement, - [SyntaxKind.TryStatement]: AstTryStatement, - [SyntaxKind.CatchClause]: AstCatchClause, - [SyntaxKind.ClassDeclaration]: AstClassDeclaration, - [SyntaxKind.ClassExpression]: AstClassExpression, - [SyntaxKind.InterfaceDeclaration]: AstInterfaceDeclaration, - [SyntaxKind.HeritageClause]: AstHeritageClause, - [SyntaxKind.TypeAliasDeclaration]: AstTypeAliasDeclaration, - [SyntaxKind.EnumMember]: AstEnumMember, - [SyntaxKind.EnumDeclaration]: AstEnumDeclaration, - [SyntaxKind.ModuleDeclaration]: AstModuleDeclaration, - [SyntaxKind.ModuleBlock]: AstModuleBlock, - [SyntaxKind.ImportEqualsDeclaration]: AstImportEqualsDeclaration, - [SyntaxKind.ExternalModuleReference]: AstExternalModuleReference, - [SyntaxKind.ImportDeclaration]: AstImportDeclaration, - [SyntaxKind.ImportClause]: AstImportClause, - [SyntaxKind.ImportAttribute]: AstImportAttribute, - [SyntaxKind.ImportAttributes]: AstImportAttributes, - [SyntaxKind.NamespaceImport]: AstNamespaceImport, - [SyntaxKind.NamespaceExport]: AstNamespaceExport, - [SyntaxKind.NamespaceExportDeclaration]: AstNamespaceExportDeclaration, - [SyntaxKind.ExportDeclaration]: AstExportDeclaration, - [SyntaxKind.NamedImports]: AstNamedImports, - [SyntaxKind.NamedExports]: AstNamedExports, - [SyntaxKind.ImportSpecifier]: AstImportSpecifier, - [SyntaxKind.ExportSpecifier]: AstExportSpecifier, - [SyntaxKind.ExportAssignment]: AstExportAssignment, - [SyntaxKind.JSDocTypeExpression]: AstJSDocTypeExpression, - [SyntaxKind.JSDocNameReference]: AstJSDocNameReference, - [SyntaxKind.JSDocMemberName]: AstJSDocMemberName, - [SyntaxKind.JSDocAllType]: AstJSDocAllType, - [SyntaxKind.JSDocUnknownType]: AstJSDocUnknownType, - [SyntaxKind.JSDocNonNullableType]: AstJSDocNonNullableType, - [SyntaxKind.JSDocNullableType]: AstJSDocNullableType, - [SyntaxKind.JSDocOptionalType]: AstJSDocOptionalType, - [SyntaxKind.JSDocFunctionType]: AstJSDocFunctionType, - [SyntaxKind.JSDocVariadicType]: AstJSDocVariadicType, - [SyntaxKind.JSDocNamepathType]: AstJSDocNamepathType, - [SyntaxKind.JSDoc]: AstJSDocNode, - [SyntaxKind.JSDocLink]: AstJSDocLink, - [SyntaxKind.JSDocLinkCode]: AstJSDocLinkCode, - [SyntaxKind.JSDocLinkPlain]: AstJSDocLinkPlain, - [SyntaxKind.JSDocText]: AstJSDocText, - [SyntaxKind.JSDocTag]: AstJSDocUnknownTag, - [SyntaxKind.JSDocAugmentsTag]: AstJSDocAugmentsTag, - [SyntaxKind.JSDocImplementsTag]: AstJSDocImplementsTag, - [SyntaxKind.JSDocAuthorTag]: AstJSDocAuthorTag, - [SyntaxKind.JSDocDeprecatedTag]: AstJSDocDeprecatedTag, - [SyntaxKind.JSDocClassTag]: AstJSDocClassTag, - [SyntaxKind.JSDocPublicTag]: AstJSDocPublicTag, - [SyntaxKind.JSDocPrivateTag]: AstJSDocPrivateTag, - [SyntaxKind.JSDocProtectedTag]: AstJSDocProtectedTag, - [SyntaxKind.JSDocReadonlyTag]: AstJSDocReadonlyTag, - [SyntaxKind.JSDocOverrideTag]: AstJSDocOverrideTag, - [SyntaxKind.JSDocEnumTag]: AstJSDocEnumTag, - [SyntaxKind.JSDocThisTag]: AstJSDocThisTag, - [SyntaxKind.JSDocTemplateTag]: AstJSDocTemplateTag, - [SyntaxKind.JSDocSeeTag]: AstJSDocSeeTag, - [SyntaxKind.JSDocReturnTag]: AstJSDocReturnTag, - [SyntaxKind.JSDocTypeTag]: AstJSDocTypeTag, - [SyntaxKind.JSDocTypedefTag]: AstJSDocTypedefTag, - [SyntaxKind.JSDocCallbackTag]: AstJSDocCallbackTag, - [SyntaxKind.JSDocOverloadTag]: AstJSDocOverloadTag, - [SyntaxKind.JSDocThrowsTag]: AstJSDocThrowsTag, - [SyntaxKind.JSDocSignature]: AstJSDocSignature, - [SyntaxKind.JSDocPropertyTag]: AstJSDocPropertyTag, - [SyntaxKind.JSDocParameterTag]: AstJSDocParameterTag, - [SyntaxKind.JSDocTypeLiteral]: AstJSDocTypeLiteral, - [SyntaxKind.JSDocSatisfiesTag]: AstJSDocSatisfiesTag, - [SyntaxKind.JSDocImportTag]: AstJSDocImportTag, - [SyntaxKind.SourceFile]: AstSourceFile, - [SyntaxKind.Bundle]: AstBundle, - [SyntaxKind.SyntaxList]: AstSyntaxList, - [SyntaxKind.NotEmittedStatement]: AstNotEmittedStatement, - [SyntaxKind.NotEmittedTypeElement]: AstNotEmittedTypeElement, - [SyntaxKind.PartiallyEmittedExpression]: AstPartiallyEmittedExpression, - [SyntaxKind.CommaListExpression]: AstCommaListExpression, - [SyntaxKind.SyntheticReferenceExpression]: AstSyntheticReferenceExpression, - [SyntaxKind.Count]: never, - [SyntaxKind.NonTextFileMarkerTrivia]: never, + [SyntaxKind.Unknown]: AstToken; + [SyntaxKind.EndOfFileToken]: AstEndOfFileToken; + [SyntaxKind.SingleLineCommentTrivia]: AstToken; + [SyntaxKind.MultiLineCommentTrivia]: AstToken; + [SyntaxKind.NewLineTrivia]: AstToken; + [SyntaxKind.WhitespaceTrivia]: AstToken; + [SyntaxKind.ShebangTrivia]: AstToken; + [SyntaxKind.ConflictMarkerTrivia]: AstToken; + [SyntaxKind.NonTextFileMarkerTrivia]: never; + [SyntaxKind.NumericLiteral]: AstNumericLiteral; + [SyntaxKind.BigIntLiteral]: AstBigIntLiteral; + [SyntaxKind.StringLiteral]: AstStringLiteral; + [SyntaxKind.JsxText]: AstJsxText; + [SyntaxKind.JsxTextAllWhiteSpaces]: never; + [SyntaxKind.RegularExpressionLiteral]: AstRegularExpressionLiteral; + [SyntaxKind.NoSubstitutionTemplateLiteral]: AstNoSubstitutionTemplateLiteral; + [SyntaxKind.TemplateHead]: AstTemplateHead; + [SyntaxKind.TemplateMiddle]: AstTemplateMiddle; + [SyntaxKind.TemplateTail]: AstTemplateTail; + [SyntaxKind.OpenBraceToken]: AstToken; + [SyntaxKind.CloseBraceToken]: AstToken; + [SyntaxKind.OpenParenToken]: AstToken; + [SyntaxKind.CloseParenToken]: AstToken; + [SyntaxKind.OpenBracketToken]: AstToken; + [SyntaxKind.CloseBracketToken]: AstToken; + [SyntaxKind.DotToken]: AstDotToken; + [SyntaxKind.DotDotDotToken]: AstDotDotDotToken; + [SyntaxKind.SemicolonToken]: AstToken; + [SyntaxKind.CommaToken]: AstToken; + [SyntaxKind.QuestionDotToken]: AstQuestionDotToken; + [SyntaxKind.LessThanToken]: AstToken; + [SyntaxKind.LessThanSlashToken]: AstToken; + [SyntaxKind.GreaterThanToken]: AstToken; + [SyntaxKind.LessThanEqualsToken]: AstToken; + [SyntaxKind.GreaterThanEqualsToken]: AstToken; + [SyntaxKind.EqualsEqualsToken]: AstToken; + [SyntaxKind.ExclamationEqualsToken]: AstToken; + [SyntaxKind.EqualsEqualsEqualsToken]: AstToken; + [SyntaxKind.ExclamationEqualsEqualsToken]: AstToken; + [SyntaxKind.EqualsGreaterThanToken]: AstEqualsGreaterThanToken; + [SyntaxKind.PlusToken]: AstPlusToken; + [SyntaxKind.MinusToken]: AstMinusToken; + [SyntaxKind.AsteriskToken]: AstAsteriskToken; + [SyntaxKind.AsteriskAsteriskToken]: AstToken; + [SyntaxKind.SlashToken]: AstToken; + [SyntaxKind.PercentToken]: AstToken; + [SyntaxKind.PlusPlusToken]: AstToken; + [SyntaxKind.MinusMinusToken]: AstToken; + [SyntaxKind.LessThanLessThanToken]: AstToken; + [SyntaxKind.GreaterThanGreaterThanToken]: AstToken; + [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: AstToken; + [SyntaxKind.AmpersandToken]: AstToken; + [SyntaxKind.BarToken]: AstToken; + [SyntaxKind.CaretToken]: AstToken; + [SyntaxKind.ExclamationToken]: AstExclamationToken; + [SyntaxKind.TildeToken]: AstToken; + [SyntaxKind.AmpersandAmpersandToken]: AstToken; + [SyntaxKind.BarBarToken]: AstToken; + [SyntaxKind.QuestionToken]: AstQuestionToken; + [SyntaxKind.ColonToken]: AstColonToken; + [SyntaxKind.AtToken]: AstToken; + [SyntaxKind.QuestionQuestionToken]: AstToken; + [SyntaxKind.BacktickToken]: AstToken; + [SyntaxKind.HashToken]: AstToken; + [SyntaxKind.EqualsToken]: AstEqualsToken; + [SyntaxKind.PlusEqualsToken]: AstToken; + [SyntaxKind.MinusEqualsToken]: AstToken; + [SyntaxKind.AsteriskEqualsToken]: AstToken; + [SyntaxKind.AsteriskAsteriskEqualsToken]: AstToken; + [SyntaxKind.SlashEqualsToken]: AstToken; + [SyntaxKind.PercentEqualsToken]: AstToken; + [SyntaxKind.LessThanLessThanEqualsToken]: AstToken; + [SyntaxKind.GreaterThanGreaterThanEqualsToken]: AstToken; + [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: AstToken; + [SyntaxKind.AmpersandEqualsToken]: AstToken; + [SyntaxKind.BarEqualsToken]: AstToken; + [SyntaxKind.BarBarEqualsToken]: AstBarBarEqualsToken; + [SyntaxKind.AmpersandAmpersandEqualsToken]: AstAmpersandAmpersandEqualsToken; + [SyntaxKind.QuestionQuestionEqualsToken]: AstQuestionQuestionEqualsToken; + [SyntaxKind.CaretEqualsToken]: AstToken; + [SyntaxKind.Identifier]: AstIdentifier; + [SyntaxKind.PrivateIdentifier]: AstPrivateIdentifier; + [SyntaxKind.JSDocCommentTextToken]: never; + [SyntaxKind.BreakKeyword]: AstToken; + [SyntaxKind.CaseKeyword]: AstCaseKeyword; + [SyntaxKind.CatchKeyword]: AstToken; + [SyntaxKind.ClassKeyword]: AstToken; + [SyntaxKind.ConstKeyword]: AstToken; + [SyntaxKind.ContinueKeyword]: AstToken; + [SyntaxKind.DebuggerKeyword]: AstToken; + [SyntaxKind.DefaultKeyword]: AstDefaultKeyword; + [SyntaxKind.DeleteKeyword]: AstToken; + [SyntaxKind.DoKeyword]: AstToken; + [SyntaxKind.ElseKeyword]: AstToken; + [SyntaxKind.EnumKeyword]: AstToken; + [SyntaxKind.ExportKeyword]: AstExportKeyword; + [SyntaxKind.ExtendsKeyword]: AstToken; + [SyntaxKind.FalseKeyword]: AstFalseLiteral; + [SyntaxKind.FinallyKeyword]: AstToken; + [SyntaxKind.ForKeyword]: AstToken; + [SyntaxKind.FunctionKeyword]: AstToken; + [SyntaxKind.IfKeyword]: AstToken; + [SyntaxKind.ImportKeyword]: AstImportExpression; + [SyntaxKind.InKeyword]: AstInKeyword; + [SyntaxKind.InstanceOfKeyword]: AstToken; + [SyntaxKind.NewKeyword]: AstToken; + [SyntaxKind.NullKeyword]: AstNullLiteral; + [SyntaxKind.ReturnKeyword]: AstToken; + [SyntaxKind.SuperKeyword]: AstSuperExpression; + [SyntaxKind.SwitchKeyword]: AstToken; + [SyntaxKind.ThisKeyword]: AstThisExpression; + [SyntaxKind.ThrowKeyword]: AstToken; + [SyntaxKind.TrueKeyword]: AstTrueLiteral; + [SyntaxKind.TryKeyword]: AstToken; + [SyntaxKind.TypeOfKeyword]: AstToken; + [SyntaxKind.VarKeyword]: AstToken; + [SyntaxKind.VoidKeyword]: AstToken; + [SyntaxKind.WhileKeyword]: AstToken; + [SyntaxKind.WithKeyword]: AstToken; + [SyntaxKind.ImplementsKeyword]: AstToken; + [SyntaxKind.InterfaceKeyword]: AstToken; + [SyntaxKind.LetKeyword]: AstToken; + [SyntaxKind.PackageKeyword]: AstToken; + [SyntaxKind.PrivateKeyword]: AstPrivateKeyword; + [SyntaxKind.ProtectedKeyword]: AstProtectedKeyword; + [SyntaxKind.PublicKeyword]: AstPublicKeyword; + [SyntaxKind.StaticKeyword]: AstStaticKeyword; + [SyntaxKind.YieldKeyword]: AstToken; + [SyntaxKind.AbstractKeyword]: AstAbstractKeyword; + [SyntaxKind.AccessorKeyword]: AstAccessorKeyword; + [SyntaxKind.AsKeyword]: AstToken; + [SyntaxKind.AssertsKeyword]: AstAssertsKeyword; + [SyntaxKind.AssertKeyword]: AstAssertKeyword; + [SyntaxKind.AnyKeyword]: AstToken; + [SyntaxKind.AsyncKeyword]: AstAsyncKeyword; + [SyntaxKind.AwaitKeyword]: AstAwaitKeyword; + [SyntaxKind.BooleanKeyword]: AstToken; + [SyntaxKind.ConstructorKeyword]: AstToken; + [SyntaxKind.DeclareKeyword]: AstDeclareKeyword; + [SyntaxKind.GetKeyword]: AstToken; + [SyntaxKind.InferKeyword]: AstToken; + [SyntaxKind.IntrinsicKeyword]: AstToken; + [SyntaxKind.IsKeyword]: AstToken; + [SyntaxKind.KeyOfKeyword]: AstToken; + [SyntaxKind.ModuleKeyword]: AstToken; + [SyntaxKind.NamespaceKeyword]: AstToken; + [SyntaxKind.NeverKeyword]: AstToken; + [SyntaxKind.OutKeyword]: AstOutKeyword; + [SyntaxKind.ReadonlyKeyword]: AstReadonlyKeyword; + [SyntaxKind.RequireKeyword]: AstToken; + [SyntaxKind.NumberKeyword]: AstToken; + [SyntaxKind.ObjectKeyword]: AstToken; + [SyntaxKind.SatisfiesKeyword]: AstToken; + [SyntaxKind.SetKeyword]: AstToken; + [SyntaxKind.StringKeyword]: AstToken; + [SyntaxKind.SymbolKeyword]: AstToken; + [SyntaxKind.TypeKeyword]: AstToken; + [SyntaxKind.UndefinedKeyword]: AstToken; + [SyntaxKind.UniqueKeyword]: AstToken; + [SyntaxKind.UnknownKeyword]: AstToken; + [SyntaxKind.UsingKeyword]: AstToken; + [SyntaxKind.FromKeyword]: AstToken; + [SyntaxKind.GlobalKeyword]: AstToken; + [SyntaxKind.BigIntKeyword]: AstToken; + [SyntaxKind.OverrideKeyword]: AstOverrideKeyword; + [SyntaxKind.OfKeyword]: AstToken; + [SyntaxKind.QualifiedName]: AstQualifiedName; + [SyntaxKind.ComputedPropertyName]: AstComputedPropertyName; + [SyntaxKind.Decorator]: AstDecorator; + [SyntaxKind.TypeParameter]: AstTypeParameterDeclaration; + [SyntaxKind.CallSignature]: AstCallSignatureDeclaration; + [SyntaxKind.ConstructSignature]: AstConstructSignatureDeclaration; + [SyntaxKind.VariableDeclaration]: AstVariableDeclaration; + [SyntaxKind.VariableDeclarationList]: AstVariableDeclarationList; + [SyntaxKind.Parameter]: AstParameterDeclaration; + [SyntaxKind.BindingElement]: AstBindingElement; + [SyntaxKind.PropertySignature]: AstPropertySignature; + [SyntaxKind.PropertyDeclaration]: AstPropertyDeclaration; + [SyntaxKind.PropertyAssignment]: AstPropertyAssignment; + [SyntaxKind.ShorthandPropertyAssignment]: AstShorthandPropertyAssignment; + [SyntaxKind.SpreadAssignment]: AstSpreadAssignment; + [SyntaxKind.ObjectBindingPattern]: AstObjectBindingPattern; + [SyntaxKind.ArrayBindingPattern]: AstArrayBindingPattern; + [SyntaxKind.FunctionDeclaration]: AstFunctionDeclaration; + [SyntaxKind.MethodSignature]: AstMethodSignature; + [SyntaxKind.MethodDeclaration]: AstMethodDeclaration; + [SyntaxKind.Constructor]: AstConstructorDeclaration; + [SyntaxKind.SemicolonClassElement]: AstSemicolonClassElement; + [SyntaxKind.GetAccessor]: AstGetAccessorDeclaration; + [SyntaxKind.SetAccessor]: AstSetAccessorDeclaration; + [SyntaxKind.IndexSignature]: AstIndexSignatureDeclaration; + [SyntaxKind.ClassStaticBlockDeclaration]: AstClassStaticBlockDeclaration; + [SyntaxKind.ImportTypeAssertionContainer]: AstImportTypeAssertionContainer; + [SyntaxKind.ImportType]: AstImportTypeNode; + [SyntaxKind.ThisType]: AstThisTypeNode; + [SyntaxKind.FunctionType]: AstFunctionTypeNode; + [SyntaxKind.ConstructorType]: AstConstructorTypeNode; + [SyntaxKind.TypeReference]: AstTypeReferenceNode; + [SyntaxKind.TypePredicate]: AstTypePredicateNode; + [SyntaxKind.TypeQuery]: AstTypeQueryNode; + [SyntaxKind.TypeLiteral]: AstTypeLiteralNode; + [SyntaxKind.ArrayType]: AstArrayTypeNode; + [SyntaxKind.TupleType]: AstTupleTypeNode; + [SyntaxKind.NamedTupleMember]: AstNamedTupleMember; + [SyntaxKind.OptionalType]: AstOptionalTypeNode; + [SyntaxKind.RestType]: AstRestTypeNode; + [SyntaxKind.UnionType]: AstUnionTypeNode; + [SyntaxKind.IntersectionType]: AstIntersectionTypeNode; + [SyntaxKind.ConditionalType]: AstConditionalTypeNode; + [SyntaxKind.InferType]: AstInferTypeNode; + [SyntaxKind.ParenthesizedType]: AstParenthesizedTypeNode; + [SyntaxKind.TypeOperator]: AstTypeOperatorNode; + [SyntaxKind.IndexedAccessType]: AstIndexedAccessTypeNode; + [SyntaxKind.MappedType]: AstMappedTypeNode; + [SyntaxKind.LiteralType]: AstLiteralTypeNode; + [SyntaxKind.TemplateLiteralType]: AstTemplateLiteralTypeNode; + [SyntaxKind.TemplateLiteralTypeSpan]: AstTemplateLiteralTypeSpan; + [SyntaxKind.OmittedExpression]: AstOmittedExpression; + [SyntaxKind.PrefixUnaryExpression]: AstPrefixUnaryExpression; + [SyntaxKind.PostfixUnaryExpression]: AstPostfixUnaryExpression; + [SyntaxKind.DeleteExpression]: AstDeleteExpression; + [SyntaxKind.TypeOfExpression]: AstTypeOfExpression; + [SyntaxKind.VoidExpression]: AstVoidExpression; + [SyntaxKind.AwaitExpression]: AstAwaitExpression; + [SyntaxKind.YieldExpression]: AstYieldExpression; + [SyntaxKind.BinaryExpression]: AstBinaryExpression; + [SyntaxKind.ConditionalExpression]: AstConditionalExpression; + [SyntaxKind.FunctionExpression]: AstFunctionExpression; + [SyntaxKind.ArrowFunction]: AstArrowFunction; + [SyntaxKind.TemplateExpression]: AstTemplateExpression; + [SyntaxKind.TemplateSpan]: AstTemplateSpan; + [SyntaxKind.ParenthesizedExpression]: AstParenthesizedExpression; + [SyntaxKind.ArrayLiteralExpression]: AstArrayLiteralExpression; + [SyntaxKind.SpreadElement]: AstSpreadElement; + [SyntaxKind.ObjectLiteralExpression]: AstObjectLiteralExpression; + [SyntaxKind.PropertyAccessExpression]: AstPropertyAccessExpression; + [SyntaxKind.ElementAccessExpression]: AstElementAccessExpression; + [SyntaxKind.CallExpression]: AstCallExpression; + [SyntaxKind.ExpressionWithTypeArguments]: AstExpressionWithTypeArguments; + [SyntaxKind.NewExpression]: AstNewExpression; + [SyntaxKind.TaggedTemplateExpression]: AstTaggedTemplateExpression; + [SyntaxKind.AsExpression]: AstAsExpression; + [SyntaxKind.TypeAssertionExpression]: AstTypeAssertion; + [SyntaxKind.SyntheticExpression]: AstSyntheticExpression; + [SyntaxKind.SatisfiesExpression]: AstSatisfiesExpression; + [SyntaxKind.NonNullExpression]: AstNonNullExpression; + [SyntaxKind.MetaProperty]: AstMetaProperty; + [SyntaxKind.JsxElement]: AstJsxElement; + [SyntaxKind.JsxAttributes]: AstJsxAttributes; + [SyntaxKind.JsxNamespacedName]: AstJsxNamespacedName; + [SyntaxKind.JsxOpeningElement]: AstJsxOpeningElement; + [SyntaxKind.JsxSelfClosingElement]: AstJsxSelfClosingElement; + [SyntaxKind.JsxFragment]: AstJsxFragment; + [SyntaxKind.JsxOpeningFragment]: AstJsxOpeningFragment; + [SyntaxKind.JsxClosingFragment]: AstJsxClosingFragment; + [SyntaxKind.JsxAttribute]: AstJsxAttribute; + [SyntaxKind.JsxSpreadAttribute]: AstJsxSpreadAttribute; + [SyntaxKind.JsxClosingElement]: AstJsxClosingElement; + [SyntaxKind.JsxExpression]: AstJsxExpression; + [SyntaxKind.EmptyStatement]: AstEmptyStatement; + [SyntaxKind.DebuggerStatement]: AstDebuggerStatement; + [SyntaxKind.MissingDeclaration]: AstMissingDeclaration; + [SyntaxKind.Block]: AstBlock; + [SyntaxKind.VariableStatement]: AstVariableStatement; + [SyntaxKind.ExpressionStatement]: AstExpressionStatement; + [SyntaxKind.IfStatement]: AstIfStatement; + [SyntaxKind.DoStatement]: AstDoStatement; + [SyntaxKind.WhileStatement]: AstWhileStatement; + [SyntaxKind.ForStatement]: AstForStatement; + [SyntaxKind.ForInStatement]: AstForInStatement; + [SyntaxKind.ForOfStatement]: AstForOfStatement; + [SyntaxKind.BreakStatement]: AstBreakStatement; + [SyntaxKind.ContinueStatement]: AstContinueStatement; + [SyntaxKind.ReturnStatement]: AstReturnStatement; + [SyntaxKind.WithStatement]: AstWithStatement; + [SyntaxKind.SwitchStatement]: AstSwitchStatement; + [SyntaxKind.CaseBlock]: AstCaseBlock; + [SyntaxKind.CaseClause]: AstCaseClause; + [SyntaxKind.DefaultClause]: AstDefaultClause; + [SyntaxKind.LabeledStatement]: AstLabeledStatement; + [SyntaxKind.ThrowStatement]: AstThrowStatement; + [SyntaxKind.TryStatement]: AstTryStatement; + [SyntaxKind.CatchClause]: AstCatchClause; + [SyntaxKind.ClassDeclaration]: AstClassDeclaration; + [SyntaxKind.ClassExpression]: AstClassExpression; + [SyntaxKind.InterfaceDeclaration]: AstInterfaceDeclaration; + [SyntaxKind.HeritageClause]: AstHeritageClause; + [SyntaxKind.TypeAliasDeclaration]: AstTypeAliasDeclaration; + [SyntaxKind.EnumMember]: AstEnumMember; + [SyntaxKind.EnumDeclaration]: AstEnumDeclaration; + [SyntaxKind.ModuleDeclaration]: AstModuleDeclaration; + [SyntaxKind.ModuleBlock]: AstModuleBlock; + [SyntaxKind.ImportEqualsDeclaration]: AstImportEqualsDeclaration; + [SyntaxKind.ExternalModuleReference]: AstExternalModuleReference; + [SyntaxKind.ImportDeclaration]: AstImportDeclaration; + [SyntaxKind.ImportClause]: AstImportClause; + [SyntaxKind.ImportAttribute]: AstImportAttribute; + [SyntaxKind.ImportAttributes]: AstImportAttributes; + [SyntaxKind.NamespaceImport]: AstNamespaceImport; + [SyntaxKind.NamespaceExport]: AstNamespaceExport; + [SyntaxKind.NamespaceExportDeclaration]: AstNamespaceExportDeclaration; + [SyntaxKind.ExportDeclaration]: AstExportDeclaration; + [SyntaxKind.NamedImports]: AstNamedImports; + [SyntaxKind.NamedExports]: AstNamedExports; + [SyntaxKind.ImportSpecifier]: AstImportSpecifier; + [SyntaxKind.ExportSpecifier]: AstExportSpecifier; + [SyntaxKind.ExportAssignment]: AstExportAssignment; + [SyntaxKind.JSDocTypeExpression]: AstJSDocTypeExpression; + [SyntaxKind.JSDocNameReference]: AstJSDocNameReference; + [SyntaxKind.JSDocMemberName]: AstJSDocMemberName; + [SyntaxKind.JSDocAllType]: AstJSDocAllType; + [SyntaxKind.JSDocUnknownType]: AstJSDocUnknownType; + [SyntaxKind.JSDocNonNullableType]: AstJSDocNonNullableType; + [SyntaxKind.JSDocNullableType]: AstJSDocNullableType; + [SyntaxKind.JSDocOptionalType]: AstJSDocOptionalType; + [SyntaxKind.JSDocFunctionType]: AstJSDocFunctionType; + [SyntaxKind.JSDocVariadicType]: AstJSDocVariadicType; + [SyntaxKind.JSDocNamepathType]: AstJSDocNamepathType; + [SyntaxKind.JSDoc]: AstJSDocNode; + [SyntaxKind.JSDocLink]: AstJSDocLink; + [SyntaxKind.JSDocLinkCode]: AstJSDocLinkCode; + [SyntaxKind.JSDocLinkPlain]: AstJSDocLinkPlain; + [SyntaxKind.JSDocText]: AstJSDocText; + [SyntaxKind.JSDocTag]: AstJSDocUnknownTag; + [SyntaxKind.JSDocAugmentsTag]: AstJSDocAugmentsTag; + [SyntaxKind.JSDocImplementsTag]: AstJSDocImplementsTag; + [SyntaxKind.JSDocAuthorTag]: AstJSDocAuthorTag; + [SyntaxKind.JSDocDeprecatedTag]: AstJSDocDeprecatedTag; + [SyntaxKind.JSDocClassTag]: AstJSDocClassTag; + [SyntaxKind.JSDocPublicTag]: AstJSDocPublicTag; + [SyntaxKind.JSDocPrivateTag]: AstJSDocPrivateTag; + [SyntaxKind.JSDocProtectedTag]: AstJSDocProtectedTag; + [SyntaxKind.JSDocReadonlyTag]: AstJSDocReadonlyTag; + [SyntaxKind.JSDocOverrideTag]: AstJSDocOverrideTag; + [SyntaxKind.JSDocEnumTag]: AstJSDocEnumTag; + [SyntaxKind.JSDocThisTag]: AstJSDocThisTag; + [SyntaxKind.JSDocTemplateTag]: AstJSDocTemplateTag; + [SyntaxKind.JSDocSeeTag]: AstJSDocSeeTag; + [SyntaxKind.JSDocReturnTag]: AstJSDocReturnTag; + [SyntaxKind.JSDocTypeTag]: AstJSDocTypeTag; + [SyntaxKind.JSDocTypedefTag]: AstJSDocTypedefTag; + [SyntaxKind.JSDocCallbackTag]: AstJSDocCallbackTag; + [SyntaxKind.JSDocOverloadTag]: AstJSDocOverloadTag; + [SyntaxKind.JSDocThrowsTag]: AstJSDocThrowsTag; + [SyntaxKind.JSDocSignature]: AstJSDocSignature; + [SyntaxKind.JSDocPropertyTag]: AstJSDocPropertyTag; + [SyntaxKind.JSDocParameterTag]: AstJSDocParameterTag; + [SyntaxKind.JSDocTypeLiteral]: AstJSDocTypeLiteral; + [SyntaxKind.JSDocSatisfiesTag]: AstJSDocSatisfiesTag; + [SyntaxKind.JSDocImportTag]: AstJSDocImportTag; + [SyntaxKind.SourceFile]: AstSourceFile; + [SyntaxKind.Bundle]: AstBundle; + [SyntaxKind.SyntaxList]: AstSyntaxList; + [SyntaxKind.NotEmittedStatement]: AstNotEmittedStatement; + [SyntaxKind.NotEmittedTypeElement]: AstNotEmittedTypeElement; + [SyntaxKind.PartiallyEmittedExpression]: AstPartiallyEmittedExpression; + [SyntaxKind.CommaListExpression]: AstCommaListExpression; + [SyntaxKind.SyntheticReferenceExpression]: AstSyntheticReferenceExpression; + [SyntaxKind.Count]: never; + [SyntaxKind.NonTextFileMarkerTrivia]: never; } diff --git a/src/compiler/factory/astNodeFactory.ts b/src/compiler/factory/astNodeFactory.ts index 4682f8852ba6c..664683ba49417 100644 --- a/src/compiler/factory/astNodeFactory.ts +++ b/src/compiler/factory/astNodeFactory.ts @@ -929,7 +929,7 @@ export interface AstNodeFactory { cloneNode(node: T): T; restoreOuterExpressions(outerExpression: AstExpression | undefined, innerExpression: AstExpression, kinds?: OuterExpressionKinds): AstExpression; - + // // // // Common operators // // @@ -1668,7 +1668,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no return new AstNodeArray(elements ?? [], hasTrailingComma); } - function finishUpdateBaseSignatureDeclaration(updated: T, original: T) { + function finishUpdateBaseSignatureDeclaration(updated: T, original: T) { if (updated !== original) { // copy children used for quick info updated.data.typeArguments = original.data.typeArguments; @@ -2676,7 +2676,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no // TODO: remove this? 'assertions' is never defined here if (node.data.assertions && node.data.assertions.data.assertClause && node.data.attributes) { - (node.data.assertions).data.assertClause = node.data.attributes; + node.data.assertions.data.assertClause = node.data.attributes; } node.data.qualifier = qualifier; @@ -3009,7 +3009,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no node.data.typeArguments = asNodeArray(typeArguments); node.data.arguments = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray)); return finish(node); - } + } // @api function updateCallChain(node: AstCallChain, expression: AstExpression, questionDotToken: AstQuestionDotToken | undefined, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike) { @@ -4952,7 +4952,6 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no : node; } - // @api // createJSDocAuthorTag // createJSDocClassTag diff --git a/src/compiler/factory/astNodeTests.ts b/src/compiler/factory/astNodeTests.ts index f28cf8d701a23..2de63a4b8a63f 100644 --- a/src/compiler/factory/astNodeTests.ts +++ b/src/compiler/factory/astNodeTests.ts @@ -439,8 +439,8 @@ export function isAstTypeParameterDeclaration(node: AstNode): node is AstN return node.kind === SyntaxKind.TypeParameter; } - -/** @internal */// TODO(rbuckton): Rename to 'isParameterDeclaration' +/** @internal */ +// TODO(rbuckton): Rename to 'isParameterDeclaration' export function isAstParameter(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Parameter; } @@ -1193,8 +1193,8 @@ export function isAstEnumMember(node: AstNode): node is AstNode): node is AstNode { return node.kind === SyntaxKind.SourceFile; } diff --git a/src/compiler/factory/astParenthesizerRules.ts b/src/compiler/factory/astParenthesizerRules.ts index a6033c6773a72..1fa10e23920fa 100644 --- a/src/compiler/factory/astParenthesizerRules.ts +++ b/src/compiler/factory/astParenthesizerRules.ts @@ -58,15 +58,14 @@ import { sameMap, setTextRange, SyntaxKind, - TextRange + TextRange, } from "../_namespaces/ts.js"; /** @internal */ export interface AstParenthesizerRules { getParenthesizeLeftSideOfBinaryForOperator(binaryOperator: SyntaxKind): (leftSide: AstExpression) => AstExpression; getParenthesizeRightSideOfBinaryForOperator(binaryOperator: SyntaxKind): (rightSide: AstExpression) => AstExpression; - parenthesizeLeftSideOfBinary(binaryOperator: SyntaxKind, - leftSide: AstExpression): AstExpression; + parenthesizeLeftSideOfBinary(binaryOperator: SyntaxKind, leftSide: AstExpression): AstExpression; parenthesizeRightSideOfBinary(binaryOperator: SyntaxKind, leftSide: AstExpression | undefined, rightSide: AstExpression): AstExpression; parenthesizeExpressionOfComputedPropertyName(expression: AstExpression): AstExpression; parenthesizeConditionOfConditionalExpression(condition: AstExpression): AstExpression; @@ -556,7 +555,7 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth return parenthesizeCheckTypeOfConditionalType(type); } - function parenthesizeConstituentTypesOfUnionType(members:AstNodeArrayLike): AstNodeArray { + function parenthesizeConstituentTypesOfUnionType(members: AstNodeArrayLike): AstNodeArray { return factory.createNodeArray(sameMap(items(members), parenthesizeConstituentTypeOfUnionType)); } diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 79ade6c8bee01..d5d2079d4e98b 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -1,3 +1,4 @@ +import * as ast from "../_namespaces/ts.ast.js"; import { AccessorDeclaration, addRange, @@ -403,7 +404,6 @@ import { WithStatement, YieldExpression, } from "../_namespaces/ts.js"; -import * as ast from "../_namespaces/ts.ast.js"; let nextAutoGenerateId = 0; @@ -1556,7 +1556,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, ): IndexSignatureDeclaration { - return astFactory.createIndexSignature(asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node + return astFactory.createIndexSignature(asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; } // @api @@ -3351,7 +3351,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: return astFactory.updateJSDocSatisfiesTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } - // // JSX // @@ -4419,8 +4418,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: } } - type ToNode = - Expression extends T ? ast.Expression : + type ToNode = Expression extends T ? ast.Expression : Statement extends T ? ast.Statement : TypeNode extends T ? ast.TypeNode : TypeElement extends T ? ast.TypeElement : diff --git a/src/compiler/factory/parenthesizerRules.ts b/src/compiler/factory/parenthesizerRules.ts index a39efee11a950..093b69a79df74 100644 --- a/src/compiler/factory/parenthesizerRules.ts +++ b/src/compiler/factory/parenthesizerRules.ts @@ -30,7 +30,7 @@ import { SyntaxKind, TypeElement, TypeNode, - UnaryExpression + UnaryExpression, } from "../_namespaces/ts.js"; /** @internal */ @@ -207,8 +207,7 @@ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRul return astRules.parenthesizeTypeArguments(asNodeArray(typeArguments)?.ast)?.nodes; } - type ToNode = - Expression extends T ? ast.Expression : + type ToNode = Expression extends T ? ast.Expression : Statement extends T ? ast.Statement : TypeNode extends T ? ast.TypeNode : TypeElement extends T ? ast.TypeElement : diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b1fe9bc1f5b1c..de9ad87602619 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1422,7 +1422,9 @@ namespace Parser { var disallowInAndDecoratorContext = NodeFlags.DisallowInContext | NodeFlags.DecoratorContext; - var factory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules | NodeFactoryFlags.NoNodeConverters | NodeFactoryFlags.NoOriginalNode, _ => { nodeCount++; }); + var factory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules | NodeFactoryFlags.NoNodeConverters | NodeFactoryFlags.NoOriginalNode, _ => { + nodeCount++; + }); var { createNodeArray: factoryCreateNodeArray, diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index c77df625bec83..41c8549cc807e 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -9,6 +9,7 @@ import { AssertionExpression, AssignmentDeclarationKind, AssignmentPattern, + ast, AutoAccessorPropertyDeclaration, BinaryExpression, BindableObjectDefinePropertyCall, @@ -290,7 +291,6 @@ import { TypeReferenceType, UnaryExpression, VariableDeclaration, - ast, } from "./_namespaces/ts.js"; export function isExternalModuleNameRelative(moduleName: string): boolean { diff --git a/src/harness/harnessUtils.ts b/src/harness/harnessUtils.ts index 93418cb6ddb45..63635adb82425 100644 --- a/src/harness/harnessUtils.ts +++ b/src/harness/harnessUtils.ts @@ -236,7 +236,7 @@ export function sourceFileToJSON(file: ts.Node): string { if (flags) { o[propertyName] = getNodeFlagName(flags); } - break; + break; case "parseDiagnostics": o[propertyName] = convertDiagnostics(obj[propertyName]); @@ -247,7 +247,7 @@ export function sourceFileToJSON(file: ts.Node): string { o[propertyName] = { kind: (obj as ts.HasLocals).nextContainer!.kind, pos: (obj as ts.HasLocals).nextContainer!.pos, - end: (obj as ts.HasLocals).nextContainer!.end + end: (obj as ts.HasLocals).nextContainer!.end, }; } break; @@ -273,7 +273,6 @@ export function sourceFileToJSON(file: ts.Node): string { } } } - } function serializeNode(n: ts.Node | ts.NodeArray): any { diff --git a/src/services/services.ts b/src/services/services.ts index ec4662bc467e4..159b7df754779 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -295,7 +295,8 @@ import { UnionOrIntersectionType, UnionType, updateSourceFile, - UserPreferences} from "./_namespaces/ts.js"; + UserPreferences, +} from "./_namespaces/ts.js"; import * as NavigateTo from "./_namespaces/ts.NavigateTo.js"; import * as NavigationBar from "./_namespaces/ts.NavigationBar.js"; import { From 85e91cb62b32720e015f6f71e673cb585dd5cff3 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 18 Sep 2024 09:56:02 -0400 Subject: [PATCH 03/10] Less aggressive use of optional chaining --- src/compiler/ast.ts | 1363 ++++++++++++++++++++--------------------- src/compiler/types.ts | 1 + 2 files changed, 681 insertions(+), 683 deletions(-) diff --git a/src/compiler/ast.ts b/src/compiler/ast.ts index cd93debb87a9d..dadf5c740ba70 100644 --- a/src/compiler/ast.ts +++ b/src/compiler/ast.ts @@ -76,7 +76,7 @@ import { } from "./_namespaces/ts.js"; /** @internal */ -export type NextContainer = AstNode; +export type AstNextContainer = AstHasLocals; /** @internal */ export class AstNodeId { @@ -1991,7 +1991,7 @@ export class Identifier extends Token this.ast.data.resolvedSymbol = value; } get symbol(): Symbol { - return this.ast.data.symbol!; // TODO: remove `!` + return this.ast.data.symbol; } set symbol(value) { this.ast.data.symbol = value; @@ -2025,7 +2025,7 @@ export class AstIdentifierData extends AstTokenData { escapedText: __String = undefined!; resolvedSymbol: Symbol = undefined!; // TransientIdentifier jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) @@ -2140,10 +2140,10 @@ export class ComputedPropertyName extends Node | undefined = undefined; dotDotDotToken: AstDotDotDotToken | undefined = undefined; - name: AstBindingName = undefined!; + name: AstBindingName = undefined!; // TODO(rbuckton): `name` can be undefined for JSDoc signature parameters questionToken: AstQuestionToken | undefined = undefined; type: AstTypeNode | undefined = undefined; initializer: AstExpression | undefined = undefined; - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) @@ -2378,10 +2378,10 @@ export class Decorator extends Node impl } get expression(): LeftHandSideExpression { - return this.ast.data.expression?.node; + return this.ast.data.expression.node; } set expression(value: LeftHandSideExpression) { - this.ast.data.expression = value?.ast; + this.ast.data.expression = value.ast; } } @@ -2419,10 +2419,10 @@ export class PropertySignature extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode | undefined { return this.ast.data.type?.node; @@ -2534,7 +2534,7 @@ export class CallSignatureDeclaration extends Node | undefined = undefined; - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; typeArguments: AstNodeArray | undefined = undefined; // quick info locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + nextContainer: AstNextContainer | undefined = undefined; + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) } @@ -2588,10 +2588,10 @@ export class ConstructSignatureDeclaration extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode | undefined { return this.ast.data.type?.node; @@ -2612,7 +2612,7 @@ export class ConstructSignatureDeclaration extends Node | undefined = undefined; - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; typeArguments: AstNodeArray | undefined = undefined; // quick info jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; } /** @internal */ @@ -2665,10 +2665,10 @@ export class VariableDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name(): PropertyName { + return this.ast.data.name.node; + } + set name(value) { + this.ast.data.name = value.ast; + } get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } @@ -2984,6 +2978,12 @@ export class PropertyAssignment extends Node | undefined { return this.ast.data.modifiers?.nodes; } set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name(): Identifier { + return this.ast.data.name.node; + } + set name(value) { + this.ast.data.name = value.ast; + } get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } @@ -3073,6 +3061,18 @@ export class ShorthandPropertyAssignment extends Node { - return this.ast.data.elements?.nodes!; // TODO: remove `!` + return this.ast.data.elements.nodes; } set elements(value) { - this.ast.data.elements = value?.ast; + this.ast.data.elements = value.ast; } } /** @internal */ export class AstObjectBindingPatternData extends AstData { - elements: AstNodeArray | undefined = undefined; + elements: AstNodeArray = undefined!; override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildrenFlags(this.elements) | @@ -3231,16 +3231,16 @@ export class ArrayBindingPattern extends Node { - return this.ast.data.elements?.nodes!; // TODO: remove `!` + return this.ast.data.elements.nodes; } set elements(value) { - this.ast.data.elements = value?.ast; + this.ast.data.elements = value.ast; } } /** @internal */ export class AstArrayBindingPatternData extends AstData { - elements: AstNodeArray | undefined = undefined; + elements: AstNodeArray = undefined!; override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.elements) | @@ -3284,10 +3284,10 @@ export class FunctionDeclaration extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode | undefined { return this.ast.data.type?.node; @@ -3308,7 +3308,7 @@ export class FunctionDeclaration extends Node | undefined { - return this.ast.data.typeArguments?.nodes; - } // Used for quick info, replaces typeParameters for instantiated signatures + return this.ast.data.typeArguments?.nodes; // Used for quick info, replaces typeParameters for instantiated signatures + } set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } @@ -3358,15 +3357,14 @@ export class AstFunctionDeclarationData extends AstData { asteriskToken: AstAsteriskToken | undefined = undefined; name: AstIdentifier | undefined = undefined; typeParameters: AstNodeArray | undefined = undefined; - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; body: AstFunctionBody | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) @@ -3421,10 +3419,10 @@ export class MethodSignature extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode | undefined { return this.ast.data.type?.node; @@ -3463,7 +3461,7 @@ export class MethodSignature extends Node | undefined = undefined; - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; - typeArguments: AstNodeArray | undefined = undefined; // quick info + typeArguments: AstNodeArray | undefined = undefined; // quick info jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; } /** @internal */ @@ -3537,10 +3535,10 @@ export class MethodDeclaration extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode | undefined { return this.ast.data.type?.node; @@ -3591,7 +3589,7 @@ export class MethodDeclaration extends Node | undefined = undefined; - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; body: AstFunctionBody | undefined = undefined; typeArguments: AstNodeArray | undefined = undefined; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) @@ -3719,10 +3717,10 @@ export class ConstructorDeclaration extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode | undefined { return this.ast.data.type?.node; @@ -3743,7 +3741,7 @@ export class ConstructorDeclaration extends Node | undefined = undefined; body: AstFunctionBody | undefined = undefined; typeParameters: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; // initialized by parser (grammar error) typeArguments: AstNodeArray | undefined = undefined; // quick info jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) @@ -3871,10 +3869,10 @@ export class GetAccessorDeclaration extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode | undefined { return this.ast.data.type?.node; @@ -3913,7 +3911,7 @@ export class GetAccessorDeclaration extends Node | undefined = undefined; // initialized by parser (grammar error) - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; typeArguments: AstNodeArray | undefined = undefined; // quick info jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) @@ -4017,10 +4015,10 @@ export class SetAccessorDeclaration extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode | undefined { return this.ast.data.type?.node; @@ -4059,7 +4057,7 @@ export class SetAccessorDeclaration extends Node | undefined = undefined; // initialized by parser (grammar error) - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; // initialized by parser (grammar error) typeArguments: AstNodeArray | undefined = undefined; // quick info jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) @@ -4173,10 +4171,10 @@ export class IndexSignatureDeclaration extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode { return this.ast.data.type?.node!; @@ -4197,7 +4195,7 @@ export class IndexSignatureDeclaration extends Node | undefined = undefined; typeParameters: AstNodeArray | undefined = undefined; - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; typeArguments: AstNodeArray | undefined = undefined; // quick info jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; } /** @internal */ @@ -4253,18 +4251,18 @@ export class ClassStaticBlockDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get body(): Block { + return this.ast.data.body.node; + } + set body(value) { + this.ast.data.body = value.ast; + } get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } @@ -4272,7 +4270,7 @@ export class ClassStaticBlockDeclaration extends Node | undefined = undefined; // initialized by parser (grammar error) jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) @@ -4343,10 +4341,10 @@ export class ImportTypeAssertionContainer extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode { - return this.ast.data.type?.node; + return this.ast.data.type.node; } set type(value) { - this.ast.data.type = value?.ast; + this.ast.data.type = value.ast; } get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; @@ -4493,7 +4491,7 @@ export class FunctionTypeNode extends Node | undefined = undefined; - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode = undefined!; typeArguments: AstNodeArray | undefined = undefined; // quick info modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; } /** @internal */ @@ -4555,16 +4553,16 @@ export class ConstructorTypeNode extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode { - return this.ast.data.type?.node; + return this.ast.data.type.node; } set type(value) { - this.ast.data.type = value?.ast; + this.ast.data.type = value.ast; } get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; @@ -4579,7 +4577,7 @@ export class ConstructorTypeNode extends Node | undefined = undefined; typeParameters: AstNodeArray | undefined = undefined; - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode = undefined!; typeArguments: AstNodeArray | undefined = undefined; // quick info jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; } /** @internal */ @@ -4626,10 +4624,10 @@ export class TypeReferenceNode extends Node | undefined { return this.ast.data.typeArguments?.nodes; @@ -4665,10 +4663,10 @@ export class TypePredicateNode extends Node | undefined { return this.ast.data.typeArguments?.nodes; @@ -4719,13 +4717,13 @@ export class TypeLiteralNode extends Node { - return this.ast.data.members?.nodes!; - } // TODO: remove '!' + return this.ast.data.members.nodes; + } set members(value) { - this.ast.data.members = value?.ast; + this.ast.data.members = value.ast; } get symbol(): ts.Symbol { - return this.ast.data.symbol!; // TODO: remove `!` + return this.ast.data.symbol; } set symbol(value) { this.ast.data.symbol = value; @@ -4740,8 +4738,8 @@ export class TypeLiteralNode extends Node | undefined = undefined; - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + members: AstNodeArray = undefined!; + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } @@ -4752,10 +4750,10 @@ export class ArrayTypeNode extends Node { - return this.ast.data.elements?.nodes!; - } // TODO: remove '!' + return this.ast.data.elements.nodes; + } set elements(value: NodeArray) { - this.ast.data.elements = value?.ast; + this.ast.data.elements = value.ast; } } /** @internal */ export class AstTupleTypeNodeData extends AstTypeScriptNodeData { - elements: AstNodeArray | undefined = undefined; + elements: AstNodeArray = undefined!; } /** @internal */ @@ -4798,10 +4796,10 @@ export class NamedTupleMember extends Node declare _typeNodeBrand: any; get type(): TypeNode { - return this.ast.data.type?.node; + return this.ast.data.type.node; } set type(value) { - this.ast.data.type = value?.ast; + this.ast.data.type = value.ast; } } @@ -4892,16 +4890,16 @@ export class UnionTypeNode extends Node { - return this.ast.data.types?.nodes!; - } // TODO: remove '!' + return this.ast.data.types.nodes; + } set types(value) { - this.ast.data.types = value?.ast; + this.ast.data.types = value.ast; } } /** @internal */ export class AstUnionTypeNodeData extends AstTypeScriptNodeData { - types: AstNodeArray | undefined = undefined; + types: AstNodeArray = undefined!; } /** @internal */ @@ -4911,16 +4909,16 @@ export class IntersectionTypeNode extends Node { - return this.ast.data.types?.nodes!; - } // TODO: remove '!' + return this.ast.data.types.nodes; + } set types(value) { - this.ast.data.types = value?.ast; + this.ast.data.types = value.ast; } } /** @internal */ export class AstIntersectionTypeNodeData extends AstTypeScriptNodeData { - types: AstNodeArray | undefined = undefined; + types: AstNodeArray = undefined!; } /** @internal */ @@ -4931,28 +4929,28 @@ export class ConditionalTypeNode extends Node | undefined = undefined; - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; } /** @internal */ @@ -5159,10 +5157,10 @@ export class LiteralTypeNode extends Node { - return this.ast.data.templateSpans?.nodes!; - } // TODO: remove '!' + return this.ast.data.templateSpans.nodes; + } set templateSpans(value) { - this.ast.data.templateSpans = value?.ast; + this.ast.data.templateSpans = value.ast; } } /** @internal */ export class AstTemplateLiteralTypeNodeData extends AstTypeScriptNodeData { head: AstTemplateHead = undefined!; - templateSpans: AstNodeArray | undefined = undefined; + templateSpans: AstNodeArray = undefined!; } /** @internal */ @@ -5222,16 +5220,16 @@ export class TemplateLiteralTypeSpan extends Node { - return this.ast.data.colonToken?.node; + get colonToken(): ColonToken { + return this.ast.data.colonToken.node; } set colonToken(value) { - this.ast.data.colonToken = value?.ast; + this.ast.data.colonToken = value.ast; } get whenFalse(): Expression { - return this.ast.data.whenFalse?.node; + return this.ast.data.whenFalse.node; } set whenFalse(value) { - this.ast.data.whenFalse = value?.ast; + this.ast.data.whenFalse = value.ast; } } @@ -5727,10 +5725,10 @@ export class FunctionExpression extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode | undefined { return this.ast.data.type?.node; @@ -5739,10 +5737,10 @@ export class FunctionExpression extends Node | undefined = undefined; - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; body: AstFunctionBody = undefined!; /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // Used for quick info, replaces typeParameters for instantiated signatures jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) @@ -5856,10 +5854,10 @@ export class ArrowFunction extends Node | undefined { return this.ast.data.typeParameters?.nodes; @@ -5868,10 +5866,10 @@ export class ArrowFunction extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode | undefined { return this.ast.data.type?.node; @@ -5880,10 +5878,10 @@ export class ArrowFunction extends Node | undefined { return this.ast.data.typeArguments?.nodes; @@ -5898,7 +5896,7 @@ export class ArrowFunction extends Node | undefined = undefined; equalsGreaterThanToken: AstEqualsGreaterThanToken = undefined!; typeParameters: AstNodeArray | undefined = undefined; - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; body: AstConciseBody = undefined!; typeArguments: AstNodeArray | undefined = undefined; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) @@ -6064,7 +6062,7 @@ export class StringLiteral extends Token | undefined; - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) override computeTransformFlags(_: AstNode): TransformFlags { @@ -6137,7 +6135,7 @@ export class NoSubstitutionTemplateLiteral extends Token { - return this.ast.data.templateSpans?.nodes!; // TODO: remove `!` + return this.ast.data.templateSpans.nodes; } set templateSpans(value) { - this.ast.data.templateSpans = value?.ast; + this.ast.data.templateSpans = value.ast; } } /** @internal */ export class AstTemplateExpressionData extends AstData { head: AstTemplateHead = undefined!; - templateSpans: AstNodeArray | undefined = undefined; + templateSpans: AstNodeArray = undefined!; override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.head) | @@ -6500,16 +6498,16 @@ export class TemplateSpan extends Node { - return this.ast.data.elements?.nodes!; - } // TODO: remove '!' + return this.ast.data.elements.nodes; + } set elements(value: NodeArray) { - this.ast.data.elements = value?.ast; + this.ast.data.elements = value.ast; } get multiLine(): boolean | undefined { return this.ast.data.multiLine; @@ -6597,7 +6595,7 @@ export class ArrayLiteralExpression extends Node | undefined = undefined; + elements: AstNodeArray = undefined!; multiLine: boolean | undefined = undefined; override computeTransformFlags(_: AstNode): TransformFlags { @@ -6619,10 +6617,10 @@ export class SpreadElement extends Node { - return this.ast.data.properties?.nodes!; - } // TODO: remove '!' + return this.ast.data.properties.nodes; + } set properties(value) { - this.ast.data.properties = value?.ast; + this.ast.data.properties = value.ast; } get multiLine(): boolean | undefined { return this.ast.data.multiLine; @@ -6689,7 +6687,7 @@ export class ObjectLiteralExpression extends Node | undefined = undefined; + properties: AstNodeArray = undefined!; multiLine: boolean | undefined = undefined; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) override computeTransformFlags(_: AstNode): TransformFlags { @@ -6730,10 +6728,10 @@ export class PropertyAccessExpression extends Node { - return this.ast.data.arguments?.nodes!; // TODO: remove `!` + return this.ast.data.arguments.nodes; } set arguments(value) { - this.ast.data.arguments = value?.ast; + this.ast.data.arguments = value.ast; } get symbol(): ts.Symbol { - return this.ast.data.symbol!; // TODO: remove `!` + return this.ast.data.symbol; } set symbol(value) { this.ast.data.symbol = value; @@ -7003,9 +7001,9 @@ export class AstCallExpressionData extends AstData { expression: AstLeftHandSideExpression = undefined!; questionDotToken: AstQuestionDotToken | undefined = undefined; typeArguments: AstNodeArray | undefined = undefined; - arguments: AstNodeArray | undefined = undefined; + arguments: AstNodeArray = undefined!; - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) override computeTransformFlags(node: AstNode): TransformFlags { @@ -7071,10 +7069,10 @@ export class ExpressionWithTypeArguments extends Node | undefined { return this.ast.data.typeArguments?.nodes; @@ -7109,10 +7107,10 @@ export class NewExpression extends Node | undefined { return this.ast.data.typeArguments?.nodes; @@ -7127,7 +7125,7 @@ export class NewExpression extends Node | undefined = undefined; arguments: AstNodeArray | undefined = undefined; - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) override computeTransformFlags(_: AstNode): TransformFlags { @@ -7180,10 +7178,10 @@ export class TaggedTemplateExpression extends Node | undefined { return this.ast.data.typeArguments?.nodes; @@ -7192,10 +7190,10 @@ export class TaggedTemplateExpression extends Node i declare _expressionBrand: any; get openingElement(): JsxOpeningElement { - return this.ast.data.openingElement?.node; + return this.ast.data.openingElement.node; } set openingElement(value: JsxOpeningElement) { - this.ast.data.openingElement = value?.ast; + this.ast.data.openingElement = value.ast; } get children(): NodeArray { return this.ast.data.children.nodes; } set children(value: NodeArray) { - this.ast.data.children = value?.ast; + this.ast.data.children = value.ast; } get closingElement(): JsxClosingElement { - return this.ast.data.closingElement?.node; + return this.ast.data.closingElement.node; } set closingElement(value: JsxClosingElement) { - this.ast.data.closingElement = value?.ast; + this.ast.data.closingElement = value.ast; } } @@ -7532,10 +7530,10 @@ export class JsxAttributes extends Node = undefined!; - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) override computeTransformFlags(_: AstNode): TransformFlags { @@ -7566,16 +7564,16 @@ export class JsxNamespacedName extends Node { return this.ast.data.children.nodes; } set children(value: NodeArray) { - this.ast.data.children = value?.ast; + this.ast.data.children = value.ast; } get closingFragment(): JsxClosingFragment { - return this.ast.data.closingFragment?.node; + return this.ast.data.closingFragment.node; } set closingFragment(value: JsxClosingFragment) { - this.ast.data.closingFragment = value?.ast; + this.ast.data.closingFragment = value.ast; } } @@ -7821,10 +7819,10 @@ export class JsxAttribute extends Node | undefined = undefined; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) override computeTransformFlags(_: AstNode): TransformFlags { @@ -8140,10 +8138,10 @@ export class Block extends Node implements JSDoc declare _localsContainerBrand: any; get statements(): NodeArray { - return this.ast.data.statements?.nodes!; // TODO: remove `!` + return this.ast.data.statements.nodes; } set statements(value) { - this.ast.data.statements = value?.ast; + this.ast.data.statements = value.ast; } get multiLine(): boolean | undefined { return this.ast.data.multiLine; @@ -8167,18 +8165,18 @@ export class Block extends Node implements JSDoc return this.ast.data.nextContainer?.node; } set nextContainer(value) { - this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + this.ast.data.nextContainer = value?.ast; } } /** @internal */ export class AstBlockData extends AstData { - statements: AstNodeArray | undefined = undefined; + statements: AstNodeArray = undefined!; multiLine: boolean | undefined = undefined; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.statements); @@ -8200,10 +8198,10 @@ export class VariableStatement extends Node impl } get clauses(): NodeArray { - return this.ast.data.clauses?.nodes!; - } // TODO: remove '!' + return this.ast.data.clauses.nodes; + } set clauses(value) { - this.ast.data.clauses = value?.ast; + this.ast.data.clauses = value.ast; } get locals(): ts.SymbolTable | undefined { return this.ast.data.locals; @@ -8945,16 +8943,16 @@ export class CaseBlock extends Node impl return this.ast.data.nextContainer?.node; } set nextContainer(value) { - this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + this.ast.data.nextContainer = value?.ast; } } /** @internal */ export class AstCaseBlockData extends AstData { - clauses: AstNodeArray | undefined = undefined; + clauses: AstNodeArray = undefined!; locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.clauses); @@ -8975,16 +8973,16 @@ export class CaseClause extends Node i } get expression(): Expression { - return this.ast.data.expression?.node; + return this.ast.data.expression.node; } set expression(value) { - this.ast.data.expression = value?.ast; + this.ast.data.expression = value.ast; } get statements(): NodeArray { - return this.ast.data.statements?.nodes!; // TODO: remove `!` + return this.ast.data.statements.nodes; } set statements(value) { - this.ast.data.statements = value?.ast; + this.ast.data.statements = value.ast; } get fallthroughFlowNode(): ts.FlowNode | undefined { return this.ast.data.fallthroughFlowNode; @@ -9003,7 +9001,7 @@ export class CaseClause extends Node i /** @internal */ export class AstCaseClauseData extends AstData { expression: AstExpression = undefined!; - statements: AstNodeArray | undefined = undefined; + statements: AstNodeArray = undefined!; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) fallthroughFlowNode?: FlowNode | undefined; @@ -9026,10 +9024,10 @@ export class DefaultClause extends Node { - return this.ast.data.statements?.nodes!; // TODO: remove `!` + return this.ast.data.statements.nodes; } set statements(value) { - this.ast.data.statements = value?.ast; + this.ast.data.statements = value.ast; } get fallthroughFlowNode(): ts.FlowNode | undefined { return this.ast.data.fallthroughFlowNode; @@ -9041,7 +9039,7 @@ export class DefaultClause extends Node | undefined = undefined; + statements: AstNodeArray = undefined!; fallthroughFlowNode?: FlowNode | undefined = undefined; @@ -9067,16 +9065,16 @@ export class LabeledStatement extends Node { - return this.ast.data.members?.nodes!; // TODO: remove `!` + return this.ast.data.members.nodes; } set members(value: NodeArray) { - this.ast.data.members = value?.ast; + this.ast.data.members = value.ast; } get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; @@ -9342,7 +9340,7 @@ export class ClassDeclaration extends Node | undefined = undefined; heritageClauses: AstNodeArray | undefined = undefined; - members: AstNodeArray | undefined = undefined; + members: AstNodeArray = undefined!; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) override computeTransformFlags(_: AstNode): TransformFlags { @@ -9425,10 +9423,10 @@ export class ClassExpression extends Node { - return this.ast.data.members?.nodes!; // TODO: remove `!` + return this.ast.data.members.nodes; } set members(value) { - this.ast.data.members = value?.ast; + this.ast.data.members = value.ast; } get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; @@ -9437,7 +9435,7 @@ export class ClassExpression extends Node | undefined = undefined; heritageClauses: AstNodeArray | undefined = undefined; - members: AstNodeArray | undefined = undefined; + members: AstNodeArray = undefined!; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) override computeTransformFlags(_: AstNode): TransformFlags { @@ -9506,10 +9504,10 @@ export class InterfaceDeclaration extends Node | undefined { return this.ast.data.typeParameters?.nodes; @@ -9524,10 +9522,10 @@ export class InterfaceDeclaration extends Node { - return this.ast.data.members?.nodes!; - } // TODO: remove '!' + return this.ast.data.members.nodes; + } set members(value) { - this.ast.data.members = value?.ast; + this.ast.data.members = value.ast; } get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; @@ -9536,7 +9534,7 @@ export class InterfaceDeclaration extends Node | undefined = undefined; heritageClauses: AstNodeArray | undefined = undefined; - members: AstNodeArray | undefined = undefined; + members: AstNodeArray = undefined!; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } @@ -9580,17 +9578,17 @@ export class HeritageClause extends Node { - return this.ast.data.types?.nodes!; - } // TODO: remove '!' + return this.ast.data.types.nodes; + } set types(value) { - this.ast.data.types = value?.ast; + this.ast.data.types = value.ast; } } /** @internal */ export class AstHeritageClauseData extends AstData { token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword = undefined!; - types: AstNodeArray | undefined = undefined; + types: AstNodeArray = undefined!; override computeTransformFlags(_: AstNode): TransformFlags { switch (this.token) { @@ -9620,10 +9618,10 @@ export class TypeAliasDeclaration extends Node | undefined { return this.ast.data.typeParameters?.nodes; @@ -9632,10 +9630,10 @@ export class TypeAliasDeclaration extends Node { - return this.ast.data.members?.nodes!; - } // TODO: remove '!' + return this.ast.data.members.nodes; + } set members(value) { - this.ast.data.members = value?.ast; + this.ast.data.members = value.ast; } get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; @@ -9716,7 +9714,7 @@ export class EnumDeclaration extends Node | undefined = undefined; name: AstIdentifier = undefined!; - members: AstNodeArray | undefined = undefined; + members: AstNodeArray = undefined!; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) override computeTransformFlags(_: AstNode): TransformFlags { @@ -9764,10 +9762,10 @@ export class EnumMember extends Node i } get name(): PropertyName { - return this.ast.data.name?.node; + return this.ast.data.name.node; } set name(value) { - this.ast.data.name = value?.ast; + this.ast.data.name = value.ast; } get initializer(): Expression | undefined { return this.ast.data.initializer?.node; @@ -9782,7 +9780,7 @@ export class EnumMember extends Node i this.ast.data.jsDoc = value; } get symbol(): ts.Symbol { - return this.ast.data.symbol!; // TODO: remove `!` + return this.ast.data.symbol; } set symbol(value) { this.ast.data.symbol = value; @@ -9801,7 +9799,7 @@ export class AstEnumMemberData extends AstData { initializer: AstExpression | undefined = undefined; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) override computeTransformFlags(_: AstNode): TransformFlags { @@ -9850,10 +9848,10 @@ export class ModuleDeclaration extends Node { - return this.ast.data.statements?.nodes!; // TODO: remove `!` + return this.ast.data.statements.nodes; } set statements(value) { - this.ast.data.statements = value?.ast; + this.ast.data.statements = value.ast; } get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; @@ -10000,7 +9998,7 @@ export class ModuleBlock extends Node | undefined = undefined; + statements: AstNodeArray = undefined!; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) override computeTransformFlags(_: AstNode): TransformFlags { @@ -10038,10 +10036,10 @@ export class ImportEqualsDeclaration extends Node { - return this.ast.data.elements?.nodes!; // TODO: remove `!` + return this.ast.data.elements.nodes; } set elements(value) { - this.ast.data.elements = value?.ast; + this.ast.data.elements = value.ast; } get multiLine(): boolean | undefined { return this.ast.data.multiLine; @@ -10402,8 +10400,8 @@ export class ImportAttributes extends Node | undefined = undefined; + token: SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword = SyntaxKind.WithKeyword; + elements: AstNodeArray = undefined!; multiLine: boolean | undefined = undefined; override computeTransformFlags(_: AstNode): TransformFlags { @@ -10425,13 +10423,13 @@ export class NamespaceImport extends Node | undefined { return this.ast.data.modifiers?.nodes; @@ -10532,7 +10530,7 @@ export class NamespaceExportDeclaration extends Node | undefined = undefined; // initialized by parser (grammar error) name: AstIdentifier = undefined!; jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) override computeTransformFlags(_: AstNode): TransformFlags { @@ -10618,7 +10616,7 @@ export class ExportDeclaration extends Node { - return this.ast.data.elements?.nodes!; - } // TODO: remove '!' + return this.ast.data.elements.nodes; + } set elements(value) { - this.ast.data.elements = value?.ast; + this.ast.data.elements = value.ast; } } /** @internal */ export class AstNamedExportsData extends AstData { - elements: AstNodeArray | undefined = undefined; + elements: AstNodeArray = undefined!; override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildrenFlags(this.elements); @@ -10732,10 +10730,10 @@ export class ImportSpecifier extends Node { - return this.ast.data.parameters?.nodes!; // TODO: remove `!` + return this.ast.data.parameters.nodes; } set parameters(value) { - this.ast.data.parameters = value?.ast; + this.ast.data.parameters = value.ast; } get type(): TypeNode | undefined { return this.ast.data.type?.node; @@ -11138,7 +11136,7 @@ export class JSDocFunctionType extends Node | undefined = undefined; - parameters: AstNodeArray | undefined = undefined; + parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; typeArguments: AstNodeArray | undefined = undefined; // quick info jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; } /** @internal */ @@ -11184,10 +11182,10 @@ export class JSDocVariadicType extends Node | undefined { const comment = this.ast.data.comment; @@ -11629,13 +11627,13 @@ export class JSDocEnumTag extends BaseJSDocTag implements ts.JSDocThisTag { declare readonly ast: AstJSDocThisTag; get typeExpression(): JSDocTypeExpression { - return this.ast.data.typeExpression?.node; + return this.ast.data.typeExpression.node; } set typeExpression(value) { - this.ast.data.typeExpression = value?.ast; + this.ast.data.typeExpression = value.ast; } } @@ -11696,17 +11694,17 @@ export class JSDocTemplateTag extends BaseJSDocTag { - return this.ast.data.typeParameters?.nodes!; // TODO: remove `!` + return this.ast.data.typeParameters.nodes; } set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; + this.ast.data.typeParameters = value.ast; } } /** @internal */ export class AstJSDocTemplateTagData extends AstJSDocTagData { constraint: AstJSDocTypeExpression | undefined = undefined; - typeParameters: AstNodeArray | undefined = undefined; + typeParameters: AstNodeArray = undefined!; } /** @internal */ @@ -11745,10 +11743,10 @@ export class AstJSDocReturnTagData extends AstJSDocTagData { export class JSDocTypeTag extends BaseJSDocTag implements ts.JSDocTypeTag { declare readonly ast: AstJSDocTypeTag; get typeExpression(): JSDocTypeExpression { - return this.ast.data.typeExpression?.node; + return this.ast.data.typeExpression.node; } set typeExpression(value) { - this.ast.data.typeExpression = value?.ast; + this.ast.data.typeExpression = value.ast; } } @@ -11789,7 +11787,7 @@ export class JSDocTypedefTag extends BaseJSDocTag | undefined = undefined; isArrayType = false; - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } @@ -12184,10 +12182,10 @@ export class AstJSDocTypeLiteralData extends AstData { export class JSDocSatisfiesTag extends BaseJSDocTag implements ts.JSDocSatisfiesTag { declare readonly ast: AstJSDocSatisfiesTag; get typeExpression(): JSDocTypeExpression { - return this.ast.data.typeExpression?.node; + return this.ast.data.typeExpression.node; } set typeExpression(value) { - this.ast.data.typeExpression = value?.ast; + this.ast.data.typeExpression = value.ast; } } @@ -12214,10 +12212,10 @@ export class JSDocImportTag extends BaseJSDocTag) { - this.ast.data.elements = value?.ast; + this.ast.data.elements = value.ast; } } @@ -12446,16 +12444,16 @@ export class SyntheticReferenceExpression extends Node i declare _localsContainerBrand: any; get statements(): NodeArray { - return this.ast.data.statements?.nodes!; // TODO: remove `!` + return this.ast.data.statements.nodes; } set statements(value) { - this.ast.data.statements = value?.ast; + this.ast.data.statements = value.ast; } get endOfFileToken(): EndOfFileToken { - return this.ast.data.endOfFileToken?.node; + return this.ast.data.endOfFileToken.node; } set endOfFileToken(value) { - this.ast.data.endOfFileToken = value?.ast; + this.ast.data.endOfFileToken = value.ast; } get fileName(): string { return this.ast.data.fileName; @@ -12664,9 +12662,8 @@ export class SourceFile extends Node i set version(value) { this.ast.data.version = value; } - get symbol(): ts.Symbol { - return this.ast.data.declaration.symbol!; // TODO: remove `!` + return this.ast.data.declaration.symbol; } set symbol(value) { this.ast.data.declaration.symbol = value; @@ -12821,7 +12818,7 @@ export class SourceFile extends Node i return this.ast.data.nextContainer?.node; } set nextContainer(value) { - this.ast.data.nextContainer = value?.ast as NextContainer | undefined; + this.ast.data.nextContainer = value?.ast; } get extendedSourceFiles(): string[] | undefined { @@ -13029,14 +13026,14 @@ export class SourceFile extends Node i /** @internal */ export class AstDeclarationData { - symbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + symbol: Symbol = undefined!; // initialized by binder (Declaration) localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } /** @internal */ export class AstSourceFileData extends AstData { declaration: AstDeclarationData = new AstDeclarationData(); - statements: AstNodeArray | undefined = undefined; + statements: AstNodeArray = undefined!; endOfFileToken: AstEndOfFileToken = undefined!; text = ""; fileName = ""; @@ -13049,7 +13046,7 @@ export class AstSourceFileData extends AstData { isDeclarationFile = false; hasNoDefaultLib = false; locals: SymbolTable | undefined = undefined; - nextContainer: NextContainer | undefined = undefined; + nextContainer: AstNextContainer | undefined = undefined; endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) nodeCount = 0; identifierCount = 0; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2f3fb9e8a7f99..091e5410ed41b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1895,6 +1895,7 @@ export interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { readonly parent: SignatureDeclaration; readonly modifiers?: NodeArray | undefined; readonly dotDotDotToken?: DotDotDotToken | undefined; // Present on rest parameter + // TODO(rbuckton): `name` can be undefined for JSDoc signature parameters readonly name: BindingName; // Declared parameter name. readonly questionToken?: QuestionToken | undefined; // Present on optional parameter readonly type?: TypeNode | undefined; // Optional type annotation From 648e4a912df7be2073264e8fd3ae41a9f599df73 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 18 Sep 2024 14:01:41 -0400 Subject: [PATCH 04/10] migrate majority of parser to slim ast node --- src/compiler/_namespaces/ts.ts | 1 + src/compiler/ast.ts | 226 +- src/compiler/factory/astNodeFactory.ts | 3 +- src/compiler/factory/astNodeTests.ts | 507 +++-- src/compiler/forEachChild.ts | 1018 +++++++++ src/compiler/parser.ts | 2846 +++++++++--------------- src/compiler/utilities.ts | 33 +- src/compiler/utilitiesPublic.ts | 16 +- 8 files changed, 2534 insertions(+), 2116 deletions(-) create mode 100644 src/compiler/forEachChild.ts diff --git a/src/compiler/_namespaces/ts.ts b/src/compiler/_namespaces/ts.ts index ba2aa8541c636..22938bf674fe4 100644 --- a/src/compiler/_namespaces/ts.ts +++ b/src/compiler/_namespaces/ts.ts @@ -22,6 +22,7 @@ export * from "../factory/nodeTests.js"; export * from "../factory/nodeChildren.js"; export * from "../factory/utilities.js"; export * from "../factory/utilitiesPublic.js"; +export * from "../forEachChild.js"; export * from "../parser.js"; export * from "../commandLineParser.js"; export * from "../moduleNameResolver.js"; diff --git a/src/compiler/ast.ts b/src/compiler/ast.ts index dadf5c740ba70..191e2e9d9dbce 100644 --- a/src/compiler/ast.ts +++ b/src/compiler/ast.ts @@ -90,21 +90,19 @@ export class AstNodeExtraFields { original: AstNode | undefined = undefined; emitNode: EmitNode | undefined = undefined; modifierFlagsCache: ts.ModifierFlags = ModifierFlags.None; - transformFlags: TransformFlags | undefined = undefined; - __pos: number | undefined = undefined; - __end: number | undefined = undefined; + transformFlags: TransformFlags = (-1 as TransformFlags); + __pos: number = -1; + __end: number = -1; } let astNodeCloneCore: (node: AstNode) => AstNode; let astNodeShadowCore: (node: AstNode) => AstNode; -let astNodeMaybeExtra: (node: AstNode) => AstNodeExtraFields | undefined; /** @internal */ export class AstNode = Node> { static { astNodeCloneCore = node => node.cloneCore(); astNodeShadowCore = node => node.shadowCore(); - astNodeMaybeExtra = node => node._extra; } private _node: N | undefined = undefined; @@ -115,11 +113,14 @@ export class AstNode = Node> | undefined = undefined; - flags: NodeFlags; + flags: NodeFlags = NodeFlags.None; pos = -1; end = -1; constructor(kind: N["kind"], data: N["data"], nodeConstructor: NodeConstructor, flags: ts.NodeFlags = NodeFlags.None) { + // catch any excess properties assigned to the Node + Object.preventExtensions(this); + this.kind = kind; this.data = data; this.flags = flags; @@ -149,23 +150,51 @@ export class AstNode = Node implements ts.Node { - readonly ast: AstNode>; + readonly ast: AstNode> = undefined!; constructor(ast: AstNode>) { - this.ast = ast; - // catch any excess properties assigned to the Node Object.preventExtensions(this); + + this.ast = ast; } get kind(): K { @@ -1028,16 +1057,16 @@ export class Node { private _extra: AstNodeArrayExtraFields | undefined = undefined; constructor(items: readonly N[], hasTrailingComma = false) { + // catch any excess properties assigned to the NodeArray + Object.preventExtensions(this); + this.items = items; this.hasTrailingComma = hasTrailingComma; } @@ -1273,7 +1305,9 @@ export class AstNodeArray { return this._extra?.hasTrailingComma ?? false; } set hasTrailingComma(value) { - this.extra.hasTrailingComma = value; + if (value !== this.hasTrailingComma) { + this.extra.hasTrailingComma = value; + } } get transformFlags(): ts.TransformFlags { @@ -1335,7 +1369,7 @@ export class NodeArray extends Array implements ts.NodeArray< get __pos(): number | undefined { // eslint-disable-line @typescript-eslint/naming-convention return astNodeArrayMaybeExtra(this.ast)?.__pos; - } + } set __pos(value) { // eslint-disable-line @typescript-eslint/naming-convention this.ast.extra.__pos = value; } @@ -1565,8 +1599,57 @@ export interface PrimaryExpression extends MemberExpression { export type AstPrimaryExpression = AstNode; /** @internal */ -export interface LiteralExpression extends PrimaryExpression { +export interface KeywordExpression extends PrimaryExpression, KeywordToken { + readonly ast: AstKeywordExpression; + readonly kind: TKind; +} + +/** @internal */ +export type AstKeywordExpression = AstNode>; + +/** @internal */ +export interface LiteralLikeNode extends Node { + readonly ast: AstLiteralLikeNode; + readonly data: AstLiteralLikeNodeData; + + text: string; + isUnterminated?: boolean | undefined; + hasExtendedUnicodeEscape?: boolean | undefined; +} + +/** @internal */ +export type AstLiteralLikeNode = AstNode; + +/** @internal */ +export interface AstLiteralLikeNodeData extends AstData { + text: string; + isUnterminated?: boolean | undefined; + hasExtendedUnicodeEscape?: boolean | undefined; +} + +/** @internal */ +export interface TemplateLiteralLikeNode extends LiteralLikeNode { + readonly ast: AstTemplateLiteralLikeNode; + readonly data: AstTemplateLiteralLikeNodeData; + rawText?: string | undefined; + /** @internal */ + templateFlags?: TokenFlags | undefined; +} + +/** @internal */ +export interface AstTemplateLiteralLikeNodeData extends AstLiteralLikeNodeData { + rawText?: string | undefined; + /** @internal */ + templateFlags?: TokenFlags | undefined; +} + +/** @internal */ +export type AstTemplateLiteralLikeNode = AstNode; + +/** @internal */ +export interface LiteralExpression extends PrimaryExpression, LiteralLikeNode { readonly ast: AstLiteralExpression; + readonly data: AstLiteralExpressionData; _literalExpressionBrand: any; get text(): string; @@ -1576,6 +1659,10 @@ export interface LiteralExpression extends PrimaryExpression { /** @internal */ export type AstLiteralExpression = AstNode; +/** @internal */ +export interface AstLiteralExpressionData extends AstLiteralLikeNodeData { +} + /** @internal */ export class Token extends Node implements ts.Token { public override getChildCount(_sourceFile?: ts.SourceFile): number { @@ -1668,7 +1755,7 @@ export class AstEndOfFileTokenData extends AstTokenData { } /** @internal */ -export class ThisExpression extends Token implements PrimaryExpression, FlowContainer, ts.ThisExpression { +export class ThisExpression extends Token implements KeywordExpression, FlowContainer, ts.ThisExpression { declare readonly ast: AstThisExpression; declare _primaryExpressionBrand: any; @@ -1693,7 +1780,7 @@ export class AstThisExpressionData extends AstTokenData { } /** @internal */ -export class SuperExpression extends Token implements PrimaryExpression, FlowContainer, ts.SuperExpression { +export class SuperExpression extends Token implements KeywordExpression, FlowContainer, ts.SuperExpression { declare readonly ast: AstSuperExpression; declare _primaryExpressionBrand: any; @@ -1718,7 +1805,7 @@ export class AstSuperExpressionData extends AstTokenData { } /** @internal */ -export class ImportExpression extends Token implements PrimaryExpression, ts.ImportExpression { +export class ImportExpression extends Token implements KeywordExpression, ts.ImportExpression { declare readonly ast: AstImportExpression; declare _primaryExpressionBrand: any; @@ -1730,7 +1817,7 @@ export class ImportExpression extends Token implements } /** @internal */ -export class NullLiteral extends Token implements PrimaryExpression, ts.NullLiteral { +export class NullLiteral extends Token implements KeywordExpression, ts.NullLiteral { declare readonly ast: AstNullLiteral; declare _primaryExpressionBrand: any; @@ -1742,7 +1829,7 @@ export class NullLiteral extends Token implements Primar } /** @internal */ -export class TrueLiteral extends Token implements PrimaryExpression, ts.TrueLiteral { +export class TrueLiteral extends Token implements KeywordExpression, ts.TrueLiteral { declare readonly ast: AstTrueLiteral; declare _primaryExpressionBrand: any; @@ -1754,7 +1841,7 @@ export class TrueLiteral extends Token implements Primar } /** @internal */ -export class FalseLiteral extends Token implements PrimaryExpression, ts.FalseLiteral { +export class FalseLiteral extends Token implements KeywordExpression, ts.FalseLiteral { declare readonly ast: AstFalseLiteral; declare _primaryExpressionBrand: any; @@ -4445,6 +4532,14 @@ export class ThisTypeNode extends Node export class AstThisTypeNodeData extends AstTypeScriptNodeData { } +/** @internal */ +export type FunctionOrConstructorTypeNode = + | FunctionTypeNode + | ConstructorTypeNode; + +/** @internal */ +export type AstFunctionOrConstructorTypeNode = AstNodeOneOf; + /** @internal */ export class FunctionTypeNode extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.FunctionTypeNode { declare readonly ast: AstFunctionTypeNode; @@ -4518,11 +4613,11 @@ export class FunctionTypeNode extends Node | undefined = undefined; // initialized by parser (grammar error) typeParameters: AstNodeArray | undefined = undefined; parameters: AstNodeArray = undefined!; type: AstTypeNode = undefined!; typeArguments: AstNodeArray | undefined = undefined; // quick info - modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) symbol: Symbol = undefined!; // initialized by binder (Declaration) @@ -4883,6 +4978,14 @@ export class AstRestTypeNodeData extends AstTypeScriptNodeData { type: AstTypeNode = undefined!; } +/** @internal */ +export type UnionOrIntersectionTypeNode = + | UnionTypeNode + | IntersectionTypeNode; + +/** @internal */ +export type AstUnionOrIntersectionTypeNode = AstNodeOneOf; + /** @internal */ export class UnionTypeNode extends Node implements ts.UnionTypeNode { declare readonly ast: AstUnionTypeNode; @@ -7944,7 +8047,7 @@ export class AstJsxExpressionData extends AstData { } /** @internal */ -export class JsxText extends Token implements ts.JsxText { +export class JsxText extends Token implements ts.JsxText, LiteralLikeNode { declare readonly ast: AstJsxText; override get parent() { @@ -13533,6 +13636,69 @@ export type AstCommaListExpression = AstNode; /** @internal */ export type AstSyntheticReferenceExpression = AstNode; +// JSON + +/** @internal */ +export interface JsonMinusNumericLiteral extends PrefixUnaryExpression { + readonly ast: AstJsonMinusNumericLiteral; + readonly data: AstJsonMinusNumericLiteralData; + + readonly operator: SyntaxKind.MinusToken; + readonly operand: NumericLiteral; +} + +/** @internal */ +export interface AstJsonMinusNumericLiteralData extends AstPrefixUnaryExpressionData { + operator: SyntaxKind.MinusToken; + operand: AstNumericLiteral; +} + +/** @internal */ +export type AstJsonMinusNumericLiteral = AstNode; + +/** @internal */ +export type JsonObjectExpression = + | ObjectLiteralExpression + | ArrayLiteralExpression + | JsonMinusNumericLiteral + | NumericLiteral + | StringLiteral + | BooleanLiteral + | NullLiteral; + +/** @internal */ +export type AstJsonObjectExpression = AstNodeOneOf; + +/** @internal */ +export interface JsonObjectExpressionStatement extends ExpressionStatement { + readonly ast: AstJsonObjectExpressionStatement; + readonly data: AstJsonObjectExpressionStatementData; + readonly expression: JsonObjectExpression; +} + +/** @internal */ +export type AstJsonObjectExpressionStatement = AstNode; + +/** @internal */ +export interface AstJsonObjectExpressionStatementData extends AstExpressionStatementData { + expression: AstJsonObjectExpression; +} + +/** @internal */ +export interface JsonSourceFile extends SourceFile { + readonly ast: AstJsonSourceFile; + readonly data: AstJsonSourceFileData; + readonly statements: NodeArray; +} + +/** @internal */ +export type AstJsonSourceFile = AstNode; + +/** @internal */ +export interface AstJsonSourceFileData extends AstSourceFileData { + statements: AstNodeArray; +} + function propagateNameFlags(node: AstPropertyName | AstBindingPattern | AstNoSubstitutionTemplateLiteral | undefined) { return node?.kind === SyntaxKind.Identifier ? propagateIdentifierNameFlags(node) : propagateChildFlags(node); } diff --git a/src/compiler/factory/astNodeFactory.ts b/src/compiler/factory/astNodeFactory.ts index 664683ba49417..659cea94723f4 100644 --- a/src/compiler/factory/astNodeFactory.ts +++ b/src/compiler/factory/astNodeFactory.ts @@ -347,6 +347,7 @@ import { SyntaxKind, TokenFlags, TokenSyntaxKind, + TransformFlags, Type, } from "../_namespaces/ts.js"; @@ -5482,7 +5483,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no node.data.typeReferenceDirectives = typeReferences; node.data.hasNoDefaultLib = hasNoDefaultLib; node.data.libReferenceDirectives = libReferences; - node.extra.transformFlags = undefined; + node.extra.transformFlags = -1 as TransformFlags; return finish(node); } diff --git a/src/compiler/factory/astNodeTests.ts b/src/compiler/factory/astNodeTests.ts index 2de63a4b8a63f..49154ccde35f7 100644 --- a/src/compiler/factory/astNodeTests.ts +++ b/src/compiler/factory/astNodeTests.ts @@ -10,13 +10,18 @@ import { AssertEntry, AssertsKeyword, AstCallChain, + AstDeclareKeyword, AstElementAccessChain, AsteriskToken, + AstHasJSDoc, + AstLeftHandSideExpression, AstNode, AstNonNullChain, + AstNumericLiteral, AstOptionalChainRoot, AstPropertyAccessChain, AstPropertyName, + AstStringLiteralLike, AsyncKeyword, AwaitExpression, AwaitKeyword, @@ -194,6 +199,7 @@ import { SemicolonClassElement, SetAccessorDeclaration, ShorthandPropertyAssignment, + skipAstOuterExpressions, SourceFile, SpreadAssignment, SpreadElement, @@ -236,759 +242,767 @@ import { YieldExpression, } from "../_namespaces/ts.ast.js"; import { + canHaveJSDoc, + isLeftHandSideExpressionKind, NodeFlags, + OuterExpressionKinds, SyntaxKind, } from "../_namespaces/ts.js"; // Literals /** @internal */ -export function isAstNumericLiteral(node: AstNode): node is AstNode { +export function isAstNumericLiteral(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NumericLiteral; } /** @internal */ -export function isAstBigIntLiteral(node: AstNode): node is AstNode { +export function isAstBigIntLiteral(node: AstNode): node is AstNode { return node.kind === SyntaxKind.BigIntLiteral; } /** @internal */ -export function isAstStringLiteral(node: AstNode): node is AstNode { +export function isAstStringLiteral(node: AstNode): node is AstNode { return node.kind === SyntaxKind.StringLiteral; } /** @internal */ -export function isAstJsxText(node: AstNode): node is AstNode { +export function isAstJsxText(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxText; } /** @internal */ -export function isAstRegularExpressionLiteral(node: AstNode): node is AstNode { +export function isAstRegularExpressionLiteral(node: AstNode): node is AstNode { return node.kind === SyntaxKind.RegularExpressionLiteral; } /** @internal */ -export function isAstNoSubstitutionTemplateLiteral(node: AstNode): node is AstNode { +export function isAstNoSubstitutionTemplateLiteral(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NoSubstitutionTemplateLiteral; } // Pseudo-literals /** @internal */ -export function isAstTemplateHead(node: AstNode): node is AstNode { +export function isAstTemplateHead(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateHead; } /** @internal */ -export function isAstTemplateMiddle(node: AstNode): node is AstNode { +export function isAstTemplateMiddle(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateMiddle; } /** @internal */ -export function isAstTemplateTail(node: AstNode): node is AstNode { +export function isAstTemplateTail(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateTail; } // Punctuation /** @internal */ -export function isAstDotDotDotToken(node: AstNode): node is AstNode { +export function isAstDotDotDotToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.DotDotDotToken; } /** @internal */ -export function isAstCommaToken(node: AstNode): node is AstNode> { +export function isAstCommaToken(node: AstNode): node is AstNode> { return node.kind === SyntaxKind.CommaToken; } /** @internal */ -export function isAstPlusToken(node: AstNode): node is AstNode { +export function isAstPlusToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PlusToken; } /** @internal */ -export function isAstMinusToken(node: AstNode): node is AstNode { +export function isAstMinusToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.MinusToken; } /** @internal */ -export function isAstAsteriskToken(node: AstNode): node is AstNode { +export function isAstAsteriskToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AsteriskToken; } /** @internal */ -export function isAstExclamationToken(node: AstNode): node is AstNode { +export function isAstExclamationToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExclamationToken; } /** @internal */ -export function isAstQuestionToken(node: AstNode): node is AstNode { +export function isAstQuestionToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.QuestionToken; } /** @internal */ -export function isAstColonToken(node: AstNode): node is AstNode { +export function isAstColonToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ColonToken; } /** @internal */ -export function isAstQuestionDotToken(node: AstNode): node is AstNode { +export function isAstQuestionDotToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.QuestionDotToken; } /** @internal */ -export function isAstEqualsGreaterThanToken(node: AstNode): node is AstNode { +export function isAstEqualsGreaterThanToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.EqualsGreaterThanToken; } // Identifiers /** @internal */ -export function isAstIdentifier(node: AstNode): node is AstNode { +export function isAstIdentifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Identifier; } /** @internal */ -export function isAstPrivateIdentifier(node: AstNode): node is AstNode { +export function isAstPrivateIdentifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PrivateIdentifier; } // Reserved Words /** @internal */ -export function isAstExportModifier(node: AstNode): node is AstNode { +export function isAstExportModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExportKeyword; } /** @internal */ -export function isAstDefaultModifier(node: AstNode): node is AstNode { +export function isAstDefaultModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.DefaultKeyword; } /** @internal */ -export function isAstAsyncModifier(node: AstNode): node is AstNode { +export function isAstAsyncModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AsyncKeyword; } /** @internal */ -export function isAstAssertsKeyword(node: AstNode): node is AstNode { +export function isAstAssertsKeyword(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AssertsKeyword; } /** @internal */ -export function isAstAwaitKeyword(node: AstNode): node is AstNode { +export function isAstAwaitKeyword(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AwaitKeyword; } /** @internal */ -export function isAstReadonlyKeyword(node: AstNode): node is AstNode { +export function isAstReadonlyKeyword(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ReadonlyKeyword; } /** @internal */ -export function isAstStaticModifier(node: AstNode): node is AstNode { +export function isAstStaticModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.StaticKeyword; } /** @internal */ -export function isAstAbstractModifier(node: AstNode): node is AstNode { +export function isAstAbstractModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AbstractKeyword; } /** @internal */ -export function isAstOverrideModifier(node: AstNode): node is AstNode { +export function isAstOverrideModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.OverrideKeyword; } /** @internal */ -export function isAstAccessorModifier(node: AstNode): node is AstNode { +export function isAstAccessorModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AccessorKeyword; } /** @internal */ -export function isAstSuperKeyword(node: AstNode): node is AstNode { +export function isAstSuperKeyword(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SuperKeyword; } /** @internal */ -export function isAstImportKeyword(node: AstNode): node is AstNode { +export function isAstImportKeyword(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportKeyword; } /** @internal */ -export function isAstCaseKeyword(node: AstNode): node is AstNode { +export function isAstCaseKeyword(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CaseKeyword; } +/** @internal */ +export function isAstDeclareKeyword(node: AstNode): node is AstDeclareKeyword { + return node.kind === SyntaxKind.DeclareKeyword; +} + // Names /** @internal */ -export function isAstQualifiedName(node: AstNode): node is AstNode { +export function isAstQualifiedName(node: AstNode): node is AstNode { return node.kind === SyntaxKind.QualifiedName; } /** @internal */ -export function isAstComputedPropertyName(node: AstNode): node is AstNode { +export function isAstComputedPropertyName(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ComputedPropertyName; } // Signature elements /** @internal */ -export function isAstTypeParameterDeclaration(node: AstNode): node is AstNode { +export function isAstTypeParameterDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeParameter; } /** @internal */ // TODO(rbuckton): Rename to 'isParameterDeclaration' -export function isAstParameter(node: AstNode): node is AstNode { +export function isAstParameter(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Parameter; } /** @internal */ -export function isAstDecorator(node: AstNode): node is AstNode { +export function isAstDecorator(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Decorator; } // TypeMember /** @internal */ -export function isAstPropertySignature(node: AstNode): node is AstNode { +export function isAstPropertySignature(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PropertySignature; } /** @internal */ -export function isAstPropertyDeclaration(node: AstNode): node is AstNode { +export function isAstPropertyDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PropertyDeclaration; } /** @internal */ -export function isAstMethodSignature(node: AstNode): node is AstNode { +export function isAstMethodSignature(node: AstNode): node is AstNode { return node.kind === SyntaxKind.MethodSignature; } /** @internal */ -export function isAstMethodDeclaration(node: AstNode): node is AstNode { +export function isAstMethodDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.MethodDeclaration; } /** @internal */ -export function isAstClassStaticBlockDeclaration(node: AstNode): node is AstNode { +export function isAstClassStaticBlockDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ClassStaticBlockDeclaration; } /** @internal */ -export function isAstConstructorDeclaration(node: AstNode): node is AstNode { +export function isAstConstructorDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Constructor; } /** @internal */ -export function isAstGetAccessorDeclaration(node: AstNode): node is AstNode { +export function isAstGetAccessorDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.GetAccessor; } /** @internal */ -export function isAstSetAccessorDeclaration(node: AstNode): node is AstNode { +export function isAstSetAccessorDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SetAccessor; } /** @internal */ -export function isAstCallSignatureDeclaration(node: AstNode): node is AstNode { +export function isAstCallSignatureDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CallSignature; } /** @internal */ -export function isAstConstructSignatureDeclaration(node: AstNode): node is AstNode { +export function isAstConstructSignatureDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ConstructSignature; } /** @internal */ -export function isAstIndexSignatureDeclaration(node: AstNode): node is AstNode { +export function isAstIndexSignatureDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.IndexSignature; } // Type /** @internal */ -export function isAstTypePredicateNode(node: AstNode): node is AstNode { +export function isAstTypePredicateNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypePredicate; } /** @internal */ -export function isAstTypeReferenceNode(node: AstNode): node is AstNode { +export function isAstTypeReferenceNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeReference; } /** @internal */ -export function isAstFunctionTypeNode(node: AstNode): node is AstNode { +export function isAstFunctionTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.FunctionType; } /** @internal */ -export function isAstConstructorTypeNode(node: AstNode): node is AstNode { +export function isAstConstructorTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ConstructorType; } /** @internal */ -export function isAstTypeQueryNode(node: AstNode): node is AstNode { +export function isAstTypeQueryNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeQuery; } /** @internal */ -export function isAstTypeLiteralNode(node: AstNode): node is AstNode { +export function isAstTypeLiteralNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeLiteral; } /** @internal */ -export function isAstArrayTypeNode(node: AstNode): node is AstNode { +export function isAstArrayTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ArrayType; } /** @internal */ -export function isAstTupleTypeNode(node: AstNode): node is AstNode { +export function isAstTupleTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TupleType; } /** @internal */ -export function isAstNamedTupleMember(node: AstNode): node is AstNode { +export function isAstNamedTupleMember(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NamedTupleMember; } /** @internal */ -export function isAstOptionalTypeNode(node: AstNode): node is AstNode { +export function isAstOptionalTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.OptionalType; } /** @internal */ -export function isAstRestTypeNode(node: AstNode): node is AstNode { +export function isAstRestTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.RestType; } /** @internal */ -export function isAstUnionTypeNode(node: AstNode): node is AstNode { +export function isAstUnionTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.UnionType; } /** @internal */ -export function isAstIntersectionTypeNode(node: AstNode): node is AstNode { +export function isAstIntersectionTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.IntersectionType; } /** @internal */ -export function isAstConditionalTypeNode(node: AstNode): node is AstNode { +export function isAstConditionalTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ConditionalType; } /** @internal */ -export function isAstInferTypeNode(node: AstNode): node is AstNode { +export function isAstInferTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.InferType; } /** @internal */ -export function isAstParenthesizedTypeNode(node: AstNode): node is AstNode { +export function isAstParenthesizedTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ParenthesizedType; } /** @internal */ -export function isAstThisTypeNode(node: AstNode): node is AstNode { +export function isAstThisTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ThisType; } /** @internal */ -export function isAstTypeOperatorNode(node: AstNode): node is AstNode { +export function isAstTypeOperatorNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeOperator; } /** @internal */ -export function isAstIndexedAccessTypeNode(node: AstNode): node is AstNode { +export function isAstIndexedAccessTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.IndexedAccessType; } /** @internal */ -export function isAstMappedTypeNode(node: AstNode): node is AstNode { +export function isAstMappedTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.MappedType; } /** @internal */ -export function isAstLiteralTypeNode(node: AstNode): node is AstNode { +export function isAstLiteralTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.LiteralType; } /** @internal */ -export function isAstImportTypeNode(node: AstNode): node is AstNode { +export function isAstImportTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportType; } /** @internal */ -export function isAstTemplateLiteralTypeSpan(node: AstNode): node is AstNode { +export function isAstTemplateLiteralTypeSpan(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateLiteralTypeSpan; } /** @internal */ -export function isAstTemplateLiteralTypeNode(node: AstNode): node is AstNode { +export function isAstTemplateLiteralTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateLiteralType; } // Binding patterns /** @internal */ -export function isAstObjectBindingPattern(node: AstNode): node is AstNode { +export function isAstObjectBindingPattern(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ObjectBindingPattern; } /** @internal */ -export function isAstArrayBindingPattern(node: AstNode): node is AstNode { +export function isAstArrayBindingPattern(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ArrayBindingPattern; } /** @internal */ -export function isAstBindingElement(node: AstNode): node is AstNode { +export function isAstBindingElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.BindingElement; } // Expression /** @internal */ -export function isAstArrayLiteralExpression(node: AstNode): node is AstNode { +export function isAstArrayLiteralExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ArrayLiteralExpression; } /** @internal */ -export function isAstObjectLiteralExpression(node: AstNode): node is AstNode { +export function isAstObjectLiteralExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ObjectLiteralExpression; } /** @internal */ -export function isAstPropertyAccessExpression(node: AstNode): node is AstNode { +export function isAstPropertyAccessExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PropertyAccessExpression; } /** @internal */ -export function isAstElementAccessExpression(node: AstNode): node is AstNode { +export function isAstElementAccessExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ElementAccessExpression; } /** @internal */ -export function isAstCallExpression(node: AstNode): node is AstNode { +export function isAstCallExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CallExpression; } /** @internal */ -export function isAstNewExpression(node: AstNode): node is AstNode { +export function isAstNewExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NewExpression; } /** @internal */ -export function isAstTaggedTemplateExpression(node: AstNode): node is AstNode { +export function isAstTaggedTemplateExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TaggedTemplateExpression; } /** @internal */ -export function isAstTypeAssertionExpression(node: AstNode): node is AstNode { +export function isAstTypeAssertionExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeAssertionExpression; } /** @internal */ -export function isAstParenthesizedExpression(node: AstNode): node is AstNode { +export function isAstParenthesizedExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ParenthesizedExpression; } /** @internal */ -export function isAstFunctionExpression(node: AstNode): node is AstNode { +export function isAstFunctionExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.FunctionExpression; } /** @internal */ -export function isAstArrowFunction(node: AstNode): node is AstNode { +export function isAstArrowFunction(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ArrowFunction; } /** @internal */ -export function isAstDeleteExpression(node: AstNode): node is AstNode { +export function isAstDeleteExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.DeleteExpression; } /** @internal */ -export function isAstTypeOfExpression(node: AstNode): node is AstNode { +export function isAstTypeOfExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeOfExpression; } /** @internal */ -export function isAstVoidExpression(node: AstNode): node is AstNode { +export function isAstVoidExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.VoidExpression; } /** @internal */ -export function isAstAwaitExpression(node: AstNode): node is AstNode { +export function isAstAwaitExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AwaitExpression; } /** @internal */ -export function isAstPrefixUnaryExpression(node: AstNode): node is AstNode { +export function isAstPrefixUnaryExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PrefixUnaryExpression; } /** @internal */ -export function isAstPostfixUnaryExpression(node: AstNode): node is AstNode { +export function isAstPostfixUnaryExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PostfixUnaryExpression; } /** @internal */ -export function isAstBinaryExpression(node: AstNode): node is AstNode { +export function isAstBinaryExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.BinaryExpression; } /** @internal */ -export function isAstConditionalExpression(node: AstNode): node is AstNode { +export function isAstConditionalExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ConditionalExpression; } /** @internal */ -export function isAstTemplateExpression(node: AstNode): node is AstNode { +export function isAstTemplateExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateExpression; } /** @internal */ -export function isAstYieldExpression(node: AstNode): node is AstNode { +export function isAstYieldExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.YieldExpression; } /** @internal */ -export function isAstSpreadElement(node: AstNode): node is AstNode { +export function isAstSpreadElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SpreadElement; } /** @internal */ -export function isAstClassExpression(node: AstNode): node is AstNode { +export function isAstClassExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ClassExpression; } /** @internal */ -export function isAstOmittedExpression(node: AstNode): node is AstNode { +export function isAstOmittedExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.OmittedExpression; } /** @internal */ -export function isAstExpressionWithTypeArguments(node: AstNode): node is AstNode { +export function isAstExpressionWithTypeArguments(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExpressionWithTypeArguments; } /** @internal */ -export function isAstAsExpression(node: AstNode): node is AstNode { +export function isAstAsExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AsExpression; } /** @internal */ -export function isAstSatisfiesExpression(node: AstNode): node is AstNode { +export function isAstSatisfiesExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SatisfiesExpression; } /** @internal */ -export function isAstNonNullExpression(node: AstNode): node is AstNode { +export function isAstNonNullExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NonNullExpression; } /** @internal */ -export function isAstMetaProperty(node: AstNode): node is AstNode { +export function isAstMetaProperty(node: AstNode): node is AstNode { return node.kind === SyntaxKind.MetaProperty; } /** @internal */ -export function isAstSyntheticExpression(node: AstNode): node is AstNode { +export function isAstSyntheticExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SyntheticExpression; } /** @internal */ -export function isAstPartiallyEmittedExpression(node: AstNode): node is AstNode { +export function isAstPartiallyEmittedExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PartiallyEmittedExpression; } /** @internal */ -export function isAstCommaListExpression(node: AstNode): node is AstNode { +export function isAstCommaListExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CommaListExpression; } // Misc /** @internal */ -export function isAstTemplateSpan(node: AstNode): node is AstNode { +export function isAstTemplateSpan(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateSpan; } /** @internal */ -export function isAstSemicolonClassElement(node: AstNode): node is AstNode { +export function isAstSemicolonClassElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SemicolonClassElement; } // Elements /** @internal */ -export function isAstBlock(node: AstNode): node is AstNode { +export function isAstBlock(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Block; } /** @internal */ -export function isAstVariableStatement(node: AstNode): node is AstNode { +export function isAstVariableStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.VariableStatement; } /** @internal */ -export function isAstEmptyStatement(node: AstNode): node is AstNode { +export function isAstEmptyStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.EmptyStatement; } /** @internal */ -export function isAstExpressionStatement(node: AstNode): node is AstNode { +export function isAstExpressionStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExpressionStatement; } /** @internal */ -export function isAstIfStatement(node: AstNode): node is AstNode { +export function isAstIfStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.IfStatement; } /** @internal */ -export function isAstDoStatement(node: AstNode): node is AstNode { +export function isAstDoStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.DoStatement; } /** @internal */ -export function isAstWhileStatement(node: AstNode): node is AstNode { +export function isAstWhileStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.WhileStatement; } /** @internal */ -export function isAstForStatement(node: AstNode): node is AstNode { +export function isAstForStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ForStatement; } /** @internal */ -export function isAstForInStatement(node: AstNode): node is AstNode { +export function isAstForInStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ForInStatement; } /** @internal */ -export function isAstForOfStatement(node: AstNode): node is AstNode { +export function isAstForOfStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ForOfStatement; } /** @internal */ -export function isAstContinueStatement(node: AstNode): node is AstNode { +export function isAstContinueStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ContinueStatement; } /** @internal */ -export function isAstBreakStatement(node: AstNode): node is AstNode { +export function isAstBreakStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.BreakStatement; } /** @internal */ -export function isAstReturnStatement(node: AstNode): node is AstNode { +export function isAstReturnStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ReturnStatement; } /** @internal */ -export function isAstWithStatement(node: AstNode): node is AstNode { +export function isAstWithStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.WithStatement; } /** @internal */ -export function isAstSwitchStatement(node: AstNode): node is AstNode { +export function isAstSwitchStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SwitchStatement; } /** @internal */ -export function isAstLabeledStatement(node: AstNode): node is AstNode { +export function isAstLabeledStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.LabeledStatement; } /** @internal */ -export function isAstThrowStatement(node: AstNode): node is AstNode { +export function isAstThrowStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ThrowStatement; } /** @internal */ -export function isAstTryStatement(node: AstNode): node is AstNode { +export function isAstTryStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TryStatement; } /** @internal */ -export function isAstDebuggerStatement(node: AstNode): node is AstNode { +export function isAstDebuggerStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.DebuggerStatement; } /** @internal */ -export function isAstVariableDeclaration(node: AstNode): node is AstNode { +export function isAstVariableDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.VariableDeclaration; } /** @internal */ -export function isAstVariableDeclarationList(node: AstNode): node is AstNode { +export function isAstVariableDeclarationList(node: AstNode): node is AstNode { return node.kind === SyntaxKind.VariableDeclarationList; } /** @internal */ -export function isAstFunctionDeclaration(node: AstNode): node is AstNode { +export function isAstFunctionDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.FunctionDeclaration; } /** @internal */ -export function isAstClassDeclaration(node: AstNode): node is AstNode { +export function isAstClassDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ClassDeclaration; } /** @internal */ -export function isAstInterfaceDeclaration(node: AstNode): node is AstNode { +export function isAstInterfaceDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.InterfaceDeclaration; } /** @internal */ -export function isAstTypeAliasDeclaration(node: AstNode): node is AstNode { +export function isAstTypeAliasDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeAliasDeclaration; } /** @internal */ -export function isAstEnumDeclaration(node: AstNode): node is AstNode { +export function isAstEnumDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.EnumDeclaration; } /** @internal */ -export function isAstModuleDeclaration(node: AstNode): node is AstNode { +export function isAstModuleDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ModuleDeclaration; } /** @internal */ -export function isAstModuleBlock(node: AstNode): node is AstNode { +export function isAstModuleBlock(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ModuleBlock; } /** @internal */ -export function isAstCaseBlock(node: AstNode): node is AstNode { +export function isAstCaseBlock(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CaseBlock; } /** @internal */ -export function isAstNamespaceExportDeclaration(node: AstNode): node is AstNode { +export function isAstNamespaceExportDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NamespaceExportDeclaration; } /** @internal */ -export function isAstImportEqualsDeclaration(node: AstNode): node is AstNode { +export function isAstImportEqualsDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportEqualsDeclaration; } /** @internal */ -export function isAstImportDeclaration(node: AstNode): node is AstNode { +export function isAstImportDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportDeclaration; } /** @internal */ -export function isAstImportClause(node: AstNode): node is AstNode { +export function isAstImportClause(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportClause; } /** @internal */ -export function isAstImportTypeAssertionContainer(node: AstNode): node is AstNode { +export function isAstImportTypeAssertionContainer(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportTypeAssertionContainer; } @@ -996,7 +1010,7 @@ export function isAstImportTypeAssertionContainer(node: AstNode): node is * @deprecated * @internal */ -export function isAstAssertClause(node: AstNode): node is AstNode { +export function isAstAssertClause(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AssertClause; } @@ -1004,203 +1018,203 @@ export function isAstAssertClause(node: AstNode): node is AstNode): node is AstNode { +export function isAstAssertEntry(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AssertEntry; } /** @internal */ -export function isAstImportAttributes(node: AstNode): node is AstNode { +export function isAstImportAttributes(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportAttributes; } /** @internal */ -export function isAstImportAttribute(node: AstNode): node is AstNode { +export function isAstImportAttribute(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportAttribute; } /** @internal */ -export function isAstNamespaceImport(node: AstNode): node is AstNode { +export function isAstNamespaceImport(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NamespaceImport; } /** @internal */ -export function isAstNamespaceExport(node: AstNode): node is AstNode { +export function isAstNamespaceExport(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NamespaceExport; } /** @internal */ -export function isAstNamedImports(node: AstNode): node is AstNode { +export function isAstNamedImports(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NamedImports; } /** @internal */ -export function isAstImportSpecifier(node: AstNode): node is AstNode { +export function isAstImportSpecifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportSpecifier; } /** @internal */ -export function isAstExportAssignment(node: AstNode): node is AstNode { +export function isAstExportAssignment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExportAssignment; } /** @internal */ -export function isAstExportDeclaration(node: AstNode): node is AstNode { +export function isAstExportDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExportDeclaration; } /** @internal */ -export function isAstNamedExports(node: AstNode): node is AstNode { +export function isAstNamedExports(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NamedExports; } /** @internal */ -export function isAstExportSpecifier(node: AstNode): node is AstNode { +export function isAstExportSpecifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExportSpecifier; } /** @internal */ -export function isAstModuleExportName(node: AstNode): node is AstNode { +export function isAstModuleExportName(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral; } /** @internal */ -export function isAstMissingDeclaration(node: AstNode): node is AstNode { +export function isAstMissingDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.MissingDeclaration; } /** @internal */ -export function isAstNotEmittedStatement(node: AstNode): node is AstNode { +export function isAstNotEmittedStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NotEmittedStatement; } /** @internal */ -export function isAstSyntheticReference(node: AstNode): node is AstNode { +export function isAstSyntheticReference(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SyntheticReferenceExpression; } // Module References /** @internal */ -export function isAstExternalModuleReference(node: AstNode): node is AstNode { +export function isAstExternalModuleReference(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExternalModuleReference; } // JSX /** @internal */ -export function isAstJsxElement(node: AstNode): node is AstNode { +export function isAstJsxElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxElement; } /** @internal */ -export function isAstJsxSelfClosingElement(node: AstNode): node is AstNode { +export function isAstJsxSelfClosingElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxSelfClosingElement; } /** @internal */ -export function isAstJsxOpeningElement(node: AstNode): node is AstNode { +export function isAstJsxOpeningElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxOpeningElement; } /** @internal */ -export function isAstJsxClosingElement(node: AstNode): node is AstNode { +export function isAstJsxClosingElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxClosingElement; } /** @internal */ -export function isAstJsxFragment(node: AstNode): node is AstNode { +export function isAstJsxFragment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxFragment; } /** @internal */ -export function isAstJsxOpeningFragment(node: AstNode): node is AstNode { +export function isAstJsxOpeningFragment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxOpeningFragment; } /** @internal */ -export function isAstJsxClosingFragment(node: AstNode): node is AstNode { +export function isAstJsxClosingFragment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxClosingFragment; } /** @internal */ -export function isAstJsxAttribute(node: AstNode): node is AstNode { +export function isAstJsxAttribute(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxAttribute; } /** @internal */ -export function isAstJsxAttributes(node: AstNode): node is AstNode { +export function isAstJsxAttributes(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxAttributes; } /** @internal */ -export function isAstJsxSpreadAttribute(node: AstNode): node is AstNode { +export function isAstJsxSpreadAttribute(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxSpreadAttribute; } /** @internal */ -export function isAstJsxExpression(node: AstNode): node is AstNode { +export function isAstJsxExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxExpression; } /** @internal */ -export function isAstJsxNamespacedName(node: AstNode): node is AstNode { +export function isAstJsxNamespacedName(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxNamespacedName; } // Clauses /** @internal */ -export function isAstCaseClause(node: AstNode): node is AstNode { +export function isAstCaseClause(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CaseClause; } /** @internal */ -export function isAstDefaultClause(node: AstNode): node is AstNode { +export function isAstDefaultClause(node: AstNode): node is AstNode { return node.kind === SyntaxKind.DefaultClause; } /** @internal */ -export function isAstHeritageClause(node: AstNode): node is AstNode { +export function isAstHeritageClause(node: AstNode): node is AstNode { return node.kind === SyntaxKind.HeritageClause; } /** @internal */ -export function isAstCatchClause(node: AstNode): node is AstNode { +export function isAstCatchClause(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CatchClause; } // Property assignments /** @internal */ -export function isAstPropertyAssignment(node: AstNode): node is AstNode { +export function isAstPropertyAssignment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PropertyAssignment; } /** @internal */ -export function isAstShorthandPropertyAssignment(node: AstNode): node is AstNode { +export function isAstShorthandPropertyAssignment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ShorthandPropertyAssignment; } /** @internal */ -export function isAstSpreadAssignment(node: AstNode): node is AstNode { +export function isAstSpreadAssignment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SpreadAssignment; } // Enum /** @internal */ -export function isAstEnumMember(node: AstNode): node is AstNode { +export function isAstEnumMember(node: AstNode): node is AstNode { return node.kind === SyntaxKind.EnumMember; } /** @internal */ // Top-level nodes -export function isAstSourceFile(node: AstNode): node is AstNode { +export function isAstSourceFile(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SourceFile; } /** @internal */ -export function isAstBundle(node: AstNode): node is AstNode { +export function isAstBundle(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Bundle; } @@ -1209,214 +1223,214 @@ export function isAstBundle(node: AstNode): node is AstNode { // JSDoc Elements /** @internal */ -export function isAstJSDocTypeExpression(node: AstNode): node is AstNode { +export function isAstJSDocTypeExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocTypeExpression; } /** @internal */ -export function isAstJSDocNameReference(node: AstNode): node is AstNode { +export function isAstJSDocNameReference(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocNameReference; } /** @internal */ -export function isAstJSDocMemberName(node: AstNode): node is AstNode { +export function isAstJSDocMemberName(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocMemberName; } /** @internal */ -export function isAstJSDocLink(node: AstNode): node is AstNode { +export function isAstJSDocLink(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocLink; } /** @internal */ -export function isAstJSDocLinkCode(node: AstNode): node is AstNode { +export function isAstJSDocLinkCode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocLinkCode; } /** @internal */ -export function isAstJSDocLinkPlain(node: AstNode): node is AstNode { +export function isAstJSDocLinkPlain(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocLinkPlain; } /** @internal */ -export function isAstJSDocAllType(node: AstNode): node is AstNode { +export function isAstJSDocAllType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocAllType; } /** @internal */ -export function isAstJSDocUnknownType(node: AstNode): node is AstNode { +export function isAstJSDocUnknownType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocUnknownType; } /** @internal */ -export function isAstJSDocNullableType(node: AstNode): node is AstNode { +export function isAstJSDocNullableType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocNullableType; } /** @internal */ -export function isAstJSDocNonNullableType(node: AstNode): node is AstNode { +export function isAstJSDocNonNullableType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocNonNullableType; } /** @internal */ -export function isAstJSDocOptionalType(node: AstNode): node is AstNode { +export function isAstJSDocOptionalType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocOptionalType; } /** @internal */ -export function isAstJSDocFunctionType(node: AstNode): node is AstNode { +export function isAstJSDocFunctionType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocFunctionType; } /** @internal */ -export function isAstJSDocVariadicType(node: AstNode): node is AstNode { +export function isAstJSDocVariadicType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocVariadicType; } /** @internal */ -export function isAstJSDocNamepathType(node: AstNode): node is AstNode { +export function isAstJSDocNamepathType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocNamepathType; } /** @internal */ -export function isAstJSDoc(node: AstNode): node is AstNode { +export function isAstJSDoc(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDoc; } /** @internal */ -export function isAstJSDocTypeLiteral(node: AstNode): node is AstNode { +export function isAstJSDocTypeLiteral(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocTypeLiteral; } /** @internal */ -export function isAstJSDocSignature(node: AstNode): node is AstNode { +export function isAstJSDocSignature(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocSignature; } // JSDoc Tags /** @internal */ -export function isAstJSDocAugmentsTag(node: AstNode): node is AstNode { +export function isAstJSDocAugmentsTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocAugmentsTag; } /** @internal */ -export function isAstJSDocAuthorTag(node: AstNode): node is AstNode { +export function isAstJSDocAuthorTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocAuthorTag; } /** @internal */ -export function isAstJSDocClassTag(node: AstNode): node is AstNode { +export function isAstJSDocClassTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocClassTag; } /** @internal */ -export function isAstJSDocCallbackTag(node: AstNode): node is AstNode { +export function isAstJSDocCallbackTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocCallbackTag; } /** @internal */ -export function isAstJSDocPublicTag(node: AstNode): node is AstNode { +export function isAstJSDocPublicTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocPublicTag; } /** @internal */ -export function isAstJSDocPrivateTag(node: AstNode): node is AstNode { +export function isAstJSDocPrivateTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocPrivateTag; } /** @internal */ -export function isAstJSDocProtectedTag(node: AstNode): node is AstNode { +export function isAstJSDocProtectedTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocProtectedTag; } /** @internal */ -export function isAstJSDocReadonlyTag(node: AstNode): node is AstNode { +export function isAstJSDocReadonlyTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocReadonlyTag; } /** @internal */ -export function isAstJSDocOverrideTag(node: AstNode): node is AstNode { +export function isAstJSDocOverrideTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocOverrideTag; } /** @internal */ -export function isAstJSDocOverloadTag(node: AstNode): node is AstNode { +export function isAstJSDocOverloadTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocOverloadTag; } /** @internal */ -export function isAstJSDocDeprecatedTag(node: AstNode): node is AstNode { +export function isAstJSDocDeprecatedTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocDeprecatedTag; } /** @internal */ -export function isAstJSDocSeeTag(node: AstNode): node is AstNode { +export function isAstJSDocSeeTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocSeeTag; } /** @internal */ -export function isAstJSDocEnumTag(node: AstNode): node is AstNode { +export function isAstJSDocEnumTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocEnumTag; } /** @internal */ -export function isAstJSDocParameterTag(node: AstNode): node is AstNode { +export function isAstJSDocParameterTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocParameterTag; } /** @internal */ -export function isAstJSDocReturnTag(node: AstNode): node is AstNode { +export function isAstJSDocReturnTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocReturnTag; } /** @internal */ -export function isAstJSDocThisTag(node: AstNode): node is AstNode { +export function isAstJSDocThisTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocThisTag; } /** @internal */ -export function isAstJSDocTypeTag(node: AstNode): node is AstNode { +export function isAstJSDocTypeTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocTypeTag; } /** @internal */ -export function isAstJSDocTemplateTag(node: AstNode): node is AstNode { +export function isAstJSDocTemplateTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocTemplateTag; } /** @internal */ -export function isAstJSDocTypedefTag(node: AstNode): node is AstNode { +export function isAstJSDocTypedefTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocTypedefTag; } /** @internal */ -export function isAstJSDocUnknownTag(node: AstNode): node is AstNode { +export function isAstJSDocUnknownTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocTag; } /** @internal */ -export function isAstJSDocPropertyTag(node: AstNode): node is AstNode { +export function isAstJSDocPropertyTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocPropertyTag; } /** @internal */ -export function isAstJSDocImplementsTag(node: AstNode): node is AstNode { +export function isAstJSDocImplementsTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocImplementsTag; } /** @internal */ -export function isAstJSDocSatisfiesTag(node: AstNode): node is AstNode { +export function isAstJSDocSatisfiesTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocSatisfiesTag; } /** @internal */ -export function isAstJSDocThrowsTag(node: AstNode): node is AstNode { +export function isAstJSDocThrowsTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocThrowsTag; } /** @internal */ -export function isAstJSDocImportTag(node: AstNode): node is AstNode { +export function isAstJSDocImportTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocImportTag; } @@ -1430,7 +1444,7 @@ export function isAstSyntaxList(n: Node): n is SyntaxList { // Unions /** @internal */ -export function isAstPropertyName(node: AstNode): node is AstPropertyName { +export function isAstPropertyName(node: AstNode): node is AstPropertyName { const kind = node.kind; return kind === SyntaxKind.Identifier || kind === SyntaxKind.PrivateIdentifier @@ -1440,27 +1454,27 @@ export function isAstPropertyName(node: AstNode): node is AstPropertyName } /** @internal */ -export function isAstPropertyAccessChain(node: AstNode): node is AstPropertyAccessChain { +export function isAstPropertyAccessChain(node: AstNode): node is AstPropertyAccessChain { return isAstPropertyAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } /** @internal */ -export function isAstElementAccessChain(node: AstNode): node is AstElementAccessChain { +export function isAstElementAccessChain(node: AstNode): node is AstElementAccessChain { return isAstElementAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } /** @internal */ -export function isAstCallChain(node: AstNode): node is AstCallChain { +export function isAstCallChain(node: AstNode): node is AstCallChain { return isAstCallExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } /** @internal */ -export function isAstNonNullChain(node: AstNode): node is AstNonNullChain { +export function isAstNonNullChain(node: AstNode): node is AstNonNullChain { return isAstNonNullExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } /** @internal */ -export function isAstOptionalChain(node: AstNode): node is AstPropertyAccessChain | AstElementAccessChain | AstCallChain | AstNonNullChain { +export function isAstOptionalChain(node: AstNode): node is AstPropertyAccessChain | AstElementAccessChain | AstCallChain | AstNonNullChain { const kind = node.kind; return !!(node.flags & NodeFlags.OptionalChain) && (kind === SyntaxKind.PropertyAccessExpression @@ -1470,6 +1484,33 @@ export function isAstOptionalChain(node: AstNode): node is AstPropertyAcce } /** @internal */ -export function isAstOptionalChainRoot(node: AstNode): node is AstOptionalChainRoot { +export function isAstOptionalChainRoot(node: AstNode): node is AstOptionalChainRoot { return isAstOptionalChain(node) && !isAstNonNullExpression(node) && !!node.data.questionDotToken; } + +/** @internal */ +export function isAstLeftHandSideExpression(node: AstNode): node is AstLeftHandSideExpression { + return isLeftHandSideExpressionKind(skipAstOuterExpressions(node, OuterExpressionKinds.PartiallyEmittedExpressions).kind); +} + +/** @internal */ +export function isAstStringOrNumericLiteralLike(node: AstNode): node is AstStringLiteralLike | AstNumericLiteral { + return isAstStringLiteralLike(node) || isAstNumericLiteral(node); +} + +/** @internal */ +export function isAstStringLiteralLike(node: AstNode): node is AstStringLiteralLike { + return node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NoSubstitutionTemplateLiteral; +} + +/** + * True if has jsdoc nodes attached to it. + * + * @internal + */ +export function hasAstJSDocNodes(node: AstNode): node is AstHasJSDoc { + if (!canHaveJSDoc(node)) return false; + + const { data: { jsDoc } } = node; + return !!jsDoc && jsDoc.length > 0; +} diff --git a/src/compiler/forEachChild.ts b/src/compiler/forEachChild.ts new file mode 100644 index 0000000000000..7c4b92a142864 --- /dev/null +++ b/src/compiler/forEachChild.ts @@ -0,0 +1,1018 @@ +import { + ArrayLiteralExpression, + ArrayTypeNode, + ArrowFunction, + AsExpression, + AwaitExpression, + BinaryExpression, + BindingElement, + BindingPattern, + Block, + BreakStatement, + CallExpression, + CallSignatureDeclaration, + CaseBlock, + CaseClause, + CatchClause, + ClassDeclaration, + ClassExpression, + ClassStaticBlockDeclaration, + CommaListExpression, + ComputedPropertyName, + ConditionalExpression, + ConditionalTypeNode, + ConstructorDeclaration, + ConstructorTypeNode, + ConstructSignatureDeclaration, + ContinueStatement, + Decorator, + DefaultClause, + DeleteExpression, + DoStatement, + ElementAccessExpression, + EnumDeclaration, + EnumMember, + ExportAssignment, + ExportDeclaration, + ExportSpecifier, + ExpressionStatement, + ExpressionWithTypeArguments, + ExternalModuleReference, + forEach, + ForEachChildNodes, + ForInStatement, + ForOfStatement, + ForStatement, + FunctionDeclaration, + FunctionExpression, + FunctionTypeNode, + GetAccessorDeclaration, + HeritageClause, + IfStatement, + ImportAttribute, + ImportAttributes, + ImportClause, + ImportDeclaration, + ImportEqualsDeclaration, + ImportSpecifier, + ImportTypeAssertionContainer, + ImportTypeNode, + IndexedAccessTypeNode, + IndexSignatureDeclaration, + InferTypeNode, + InterfaceDeclaration, + IntersectionTypeNode, + isArray, + JSDoc, + JSDocAugmentsTag, + JSDocAuthorTag, + JSDocCallbackTag, + JSDocClassTag, + JSDocDeprecatedTag, + JSDocEnumTag, + JSDocFunctionType, + JSDocImplementsTag, + JSDocImportTag, + JSDocLink, + JSDocLinkCode, + JSDocLinkPlain, + JSDocMemberName, + JSDocNameReference, + JSDocNonNullableType, + JSDocNullableType, + JSDocOptionalType, + JSDocOverloadTag, + JSDocOverrideTag, + JSDocParameterTag, + JSDocPrivateTag, + JSDocPropertyTag, + JSDocProtectedTag, + JSDocPublicTag, + JSDocReadonlyTag, + JSDocReturnTag, + JSDocSatisfiesTag, + JSDocSeeTag, + JSDocSignature, + JSDocTemplateTag, + JSDocThisTag, + JSDocThrowsTag, + JSDocTypedefTag, + JSDocTypeExpression, + JSDocTypeLiteral, + JSDocTypeTag, + JSDocUnknownTag, + JSDocVariadicType, + JsxAttribute, + JsxAttributes, + JsxClosingElement, + JsxElement, + JsxExpression, + JsxFragment, + JsxNamespacedName, + JsxOpeningLikeElement, + JsxSpreadAttribute, + LabeledStatement, + LiteralTypeNode, + MappedTypeNode, + MetaProperty, + MethodDeclaration, + MethodSignature, + MissingDeclaration, + ModuleBlock, + ModuleDeclaration, + NamedExports, + NamedImports, + NamedTupleMember, + NamespaceExport, + NamespaceExportDeclaration, + NamespaceImport, + NewExpression, + Node, + NodeArray, + NonNullExpression, + ObjectLiteralExpression, + OptionalTypeNode, + ParameterDeclaration, + ParenthesizedExpression, + ParenthesizedTypeNode, + PartiallyEmittedExpression, + PostfixUnaryExpression, + PrefixUnaryExpression, + PropertyAccessExpression, + PropertyAssignment, + PropertyDeclaration, + PropertySignature, + QualifiedName, + RestTypeNode, + ReturnStatement, + SatisfiesExpression, + SetAccessorDeclaration, + ShorthandPropertyAssignment, + SourceFile, + SpreadAssignment, + SpreadElement, + SwitchStatement, + SyntaxKind, + TaggedTemplateExpression, + TemplateExpression, + TemplateLiteralTypeNode, + TemplateLiteralTypeSpan, + TemplateSpan, + ThrowStatement, + TryStatement, + TupleTypeNode, + TypeAliasDeclaration, + TypeAssertion, + TypeLiteralNode, + TypeOfExpression, + TypeOperatorNode, + TypeParameterDeclaration, + TypePredicateNode, + TypeQueryNode, + TypeReferenceNode, + UnionTypeNode, + VariableDeclaration, + VariableDeclarationList, + VariableStatement, + VoidExpression, + WhileStatement, + WithStatement, + YieldExpression, +} from "./_namespaces/ts.js"; + +function visitNode(cbNode: (node: Node) => T, node: Node | undefined): T | undefined { + return node && cbNode(node); +} + +function visitNodes(cbNode: (node: Node) => T, cbNodes: ((node: NodeArray) => T | undefined) | undefined, nodes: NodeArray | undefined): T | undefined { + if (nodes) { + if (cbNodes) { + return cbNodes(nodes); + } + for (const node of nodes) { + const result = cbNode(node); + if (result) { + return result; + } + } + } +} + +type ForEachChildFunction = (node: TNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined) => T | undefined; +type ForEachChildTable = { [TNode in ForEachChildNodes as TNode["kind"]]: ForEachChildFunction; }; + +const forEachChildTable: ForEachChildTable = { + [SyntaxKind.QualifiedName]: function forEachChildInQualifiedName(node: QualifiedName, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.left) || + visitNode(cbNode, node.right); + }, + [SyntaxKind.TypeParameter]: function forEachChildInTypeParameter(node: TypeParameterDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.constraint) || + visitNode(cbNode, node.default) || + visitNode(cbNode, node.expression); + }, + [SyntaxKind.ShorthandPropertyAssignment]: function forEachChildInShorthandPropertyAssignment(node: ShorthandPropertyAssignment, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.exclamationToken) || + visitNode(cbNode, node.equalsToken) || + visitNode(cbNode, node.objectAssignmentInitializer); + }, + [SyntaxKind.SpreadAssignment]: function forEachChildInSpreadAssignment(node: SpreadAssignment, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.Parameter]: function forEachChildInParameter(node: ParameterDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.dotDotDotToken) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.type) || + visitNode(cbNode, node.initializer); + }, + [SyntaxKind.PropertyDeclaration]: function forEachChildInPropertyDeclaration(node: PropertyDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.exclamationToken) || + visitNode(cbNode, node.type) || + visitNode(cbNode, node.initializer); + }, + [SyntaxKind.PropertySignature]: function forEachChildInPropertySignature(node: PropertySignature, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.type) || + visitNode(cbNode, node.initializer); + }, + [SyntaxKind.PropertyAssignment]: function forEachChildInPropertyAssignment(node: PropertyAssignment, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.exclamationToken) || + visitNode(cbNode, node.initializer); + }, + [SyntaxKind.VariableDeclaration]: function forEachChildInVariableDeclaration(node: VariableDeclaration, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.name) || + visitNode(cbNode, node.exclamationToken) || + visitNode(cbNode, node.type) || + visitNode(cbNode, node.initializer); + }, + [SyntaxKind.BindingElement]: function forEachChildInBindingElement(node: BindingElement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.dotDotDotToken) || + visitNode(cbNode, node.propertyName) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.initializer); + }, + [SyntaxKind.IndexSignature]: function forEachChildInIndexSignature(node: IndexSignatureDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type); + }, + [SyntaxKind.ConstructorType]: function forEachChildInConstructorType(node: ConstructorTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type); + }, + [SyntaxKind.FunctionType]: function forEachChildInFunctionType(node: FunctionTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type); + }, + [SyntaxKind.CallSignature]: forEachChildInCallOrConstructSignature, + [SyntaxKind.ConstructSignature]: forEachChildInCallOrConstructSignature, + [SyntaxKind.MethodDeclaration]: function forEachChildInMethodDeclaration(node: MethodDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.asteriskToken) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.exclamationToken) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type) || + visitNode(cbNode, node.body); + }, + [SyntaxKind.MethodSignature]: function forEachChildInMethodSignature(node: MethodSignature, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.questionToken) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type); + }, + [SyntaxKind.Constructor]: function forEachChildInConstructor(node: ConstructorDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type) || + visitNode(cbNode, node.body); + }, + [SyntaxKind.GetAccessor]: function forEachChildInGetAccessor(node: GetAccessorDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type) || + visitNode(cbNode, node.body); + }, + [SyntaxKind.SetAccessor]: function forEachChildInSetAccessor(node: SetAccessorDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type) || + visitNode(cbNode, node.body); + }, + [SyntaxKind.FunctionDeclaration]: function forEachChildInFunctionDeclaration(node: FunctionDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.asteriskToken) || + visitNode(cbNode, node.name) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type) || + visitNode(cbNode, node.body); + }, + [SyntaxKind.FunctionExpression]: function forEachChildInFunctionExpression(node: FunctionExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.asteriskToken) || + visitNode(cbNode, node.name) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type) || + visitNode(cbNode, node.body); + }, + [SyntaxKind.ArrowFunction]: function forEachChildInArrowFunction(node: ArrowFunction, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type) || + visitNode(cbNode, node.equalsGreaterThanToken) || + visitNode(cbNode, node.body); + }, + [SyntaxKind.ClassStaticBlockDeclaration]: function forEachChildInClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.body); + }, + [SyntaxKind.TypeReference]: function forEachChildInTypeReference(node: TypeReferenceNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.typeName) || + visitNodes(cbNode, cbNodes, node.typeArguments); + }, + [SyntaxKind.TypePredicate]: function forEachChildInTypePredicate(node: TypePredicateNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.assertsModifier) || + visitNode(cbNode, node.parameterName) || + visitNode(cbNode, node.type); + }, + [SyntaxKind.TypeQuery]: function forEachChildInTypeQuery(node: TypeQueryNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.exprName) || + visitNodes(cbNode, cbNodes, node.typeArguments); + }, + [SyntaxKind.TypeLiteral]: function forEachChildInTypeLiteral(node: TypeLiteralNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.members); + }, + [SyntaxKind.ArrayType]: function forEachChildInArrayType(node: ArrayTypeNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.elementType); + }, + [SyntaxKind.TupleType]: function forEachChildInTupleType(node: TupleTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.elements); + }, + [SyntaxKind.UnionType]: forEachChildInUnionOrIntersectionType, + [SyntaxKind.IntersectionType]: forEachChildInUnionOrIntersectionType, + [SyntaxKind.ConditionalType]: function forEachChildInConditionalType(node: ConditionalTypeNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.checkType) || + visitNode(cbNode, node.extendsType) || + visitNode(cbNode, node.trueType) || + visitNode(cbNode, node.falseType); + }, + [SyntaxKind.InferType]: function forEachChildInInferType(node: InferTypeNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.typeParameter); + }, + [SyntaxKind.ImportType]: function forEachChildInImportType(node: ImportTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.argument) || + visitNode(cbNode, node.attributes) || + visitNode(cbNode, node.qualifier) || + visitNodes(cbNode, cbNodes, node.typeArguments); + }, + [SyntaxKind.ImportTypeAssertionContainer]: function forEachChildInImportTypeAssertionContainer(node: ImportTypeAssertionContainer, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.assertClause); + }, + [SyntaxKind.ParenthesizedType]: forEachChildInParenthesizedTypeOrTypeOperator, + [SyntaxKind.TypeOperator]: forEachChildInParenthesizedTypeOrTypeOperator, + [SyntaxKind.IndexedAccessType]: function forEachChildInIndexedAccessType(node: IndexedAccessTypeNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.objectType) || + visitNode(cbNode, node.indexType); + }, + [SyntaxKind.MappedType]: function forEachChildInMappedType(node: MappedTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.readonlyToken) || + visitNode(cbNode, node.typeParameter) || + visitNode(cbNode, node.nameType) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.type) || + visitNodes(cbNode, cbNodes, node.members); + }, + [SyntaxKind.LiteralType]: function forEachChildInLiteralType(node: LiteralTypeNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.literal); + }, + [SyntaxKind.NamedTupleMember]: function forEachChildInNamedTupleMember(node: NamedTupleMember, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.dotDotDotToken) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.type); + }, + [SyntaxKind.ObjectBindingPattern]: forEachChildInObjectOrArrayBindingPattern, + [SyntaxKind.ArrayBindingPattern]: forEachChildInObjectOrArrayBindingPattern, + [SyntaxKind.ArrayLiteralExpression]: function forEachChildInArrayLiteralExpression(node: ArrayLiteralExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.elements); + }, + [SyntaxKind.ObjectLiteralExpression]: function forEachChildInObjectLiteralExpression(node: ObjectLiteralExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.properties); + }, + [SyntaxKind.PropertyAccessExpression]: function forEachChildInPropertyAccessExpression(node: PropertyAccessExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.questionDotToken) || + visitNode(cbNode, node.name); + }, + [SyntaxKind.ElementAccessExpression]: function forEachChildInElementAccessExpression(node: ElementAccessExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.questionDotToken) || + visitNode(cbNode, node.argumentExpression); + }, + [SyntaxKind.CallExpression]: forEachChildInCallOrNewExpression, + [SyntaxKind.NewExpression]: forEachChildInCallOrNewExpression, + [SyntaxKind.TaggedTemplateExpression]: function forEachChildInTaggedTemplateExpression(node: TaggedTemplateExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tag) || + visitNode(cbNode, node.questionDotToken) || + visitNodes(cbNode, cbNodes, node.typeArguments) || + visitNode(cbNode, node.template); + }, + [SyntaxKind.TypeAssertionExpression]: function forEachChildInTypeAssertionExpression(node: TypeAssertion, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.type) || + visitNode(cbNode, node.expression); + }, + [SyntaxKind.ParenthesizedExpression]: function forEachChildInParenthesizedExpression(node: ParenthesizedExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.DeleteExpression]: function forEachChildInDeleteExpression(node: DeleteExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.TypeOfExpression]: function forEachChildInTypeOfExpression(node: TypeOfExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.VoidExpression]: function forEachChildInVoidExpression(node: VoidExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.PrefixUnaryExpression]: function forEachChildInPrefixUnaryExpression(node: PrefixUnaryExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.operand); + }, + [SyntaxKind.YieldExpression]: function forEachChildInYieldExpression(node: YieldExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.asteriskToken) || + visitNode(cbNode, node.expression); + }, + [SyntaxKind.AwaitExpression]: function forEachChildInAwaitExpression(node: AwaitExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.PostfixUnaryExpression]: function forEachChildInPostfixUnaryExpression(node: PostfixUnaryExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.operand); + }, + [SyntaxKind.BinaryExpression]: function forEachChildInBinaryExpression(node: BinaryExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.left) || + visitNode(cbNode, node.operatorToken) || + visitNode(cbNode, node.right); + }, + [SyntaxKind.AsExpression]: function forEachChildInAsExpression(node: AsExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.type); + }, + [SyntaxKind.NonNullExpression]: function forEachChildInNonNullExpression(node: NonNullExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.SatisfiesExpression]: function forEachChildInSatisfiesExpression(node: SatisfiesExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); + }, + [SyntaxKind.MetaProperty]: function forEachChildInMetaProperty(node: MetaProperty, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.name); + }, + [SyntaxKind.ConditionalExpression]: function forEachChildInConditionalExpression(node: ConditionalExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.condition) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.whenTrue) || + visitNode(cbNode, node.colonToken) || + visitNode(cbNode, node.whenFalse); + }, + [SyntaxKind.SpreadElement]: function forEachChildInSpreadElement(node: SpreadElement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.Block]: forEachChildInBlock, + [SyntaxKind.ModuleBlock]: forEachChildInBlock, + [SyntaxKind.SourceFile]: function forEachChildInSourceFile(node: SourceFile, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.statements) || + visitNode(cbNode, node.endOfFileToken); + }, + [SyntaxKind.VariableStatement]: function forEachChildInVariableStatement(node: VariableStatement, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.declarationList); + }, + [SyntaxKind.VariableDeclarationList]: function forEachChildInVariableDeclarationList(node: VariableDeclarationList, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.declarations); + }, + [SyntaxKind.ExpressionStatement]: function forEachChildInExpressionStatement(node: ExpressionStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.IfStatement]: function forEachChildInIfStatement(node: IfStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.thenStatement) || + visitNode(cbNode, node.elseStatement); + }, + [SyntaxKind.DoStatement]: function forEachChildInDoStatement(node: DoStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.statement) || + visitNode(cbNode, node.expression); + }, + [SyntaxKind.WhileStatement]: function forEachChildInWhileStatement(node: WhileStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.statement); + }, + [SyntaxKind.ForStatement]: function forEachChildInForStatement(node: ForStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.initializer) || + visitNode(cbNode, node.condition) || + visitNode(cbNode, node.incrementor) || + visitNode(cbNode, node.statement); + }, + [SyntaxKind.ForInStatement]: function forEachChildInForInStatement(node: ForInStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.initializer) || + visitNode(cbNode, node.expression) || + visitNode(cbNode, node.statement); + }, + [SyntaxKind.ForOfStatement]: function forEachChildInForOfStatement(node: ForOfStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.awaitModifier) || + visitNode(cbNode, node.initializer) || + visitNode(cbNode, node.expression) || + visitNode(cbNode, node.statement); + }, + [SyntaxKind.ContinueStatement]: forEachChildInContinueOrBreakStatement, + [SyntaxKind.BreakStatement]: forEachChildInContinueOrBreakStatement, + [SyntaxKind.ReturnStatement]: function forEachChildInReturnStatement(node: ReturnStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.WithStatement]: function forEachChildInWithStatement(node: WithStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.statement); + }, + [SyntaxKind.SwitchStatement]: function forEachChildInSwitchStatement(node: SwitchStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.caseBlock); + }, + [SyntaxKind.CaseBlock]: function forEachChildInCaseBlock(node: CaseBlock, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.clauses); + }, + [SyntaxKind.CaseClause]: function forEachChildInCaseClause(node: CaseClause, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression) || + visitNodes(cbNode, cbNodes, node.statements); + }, + [SyntaxKind.DefaultClause]: function forEachChildInDefaultClause(node: DefaultClause, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.statements); + }, + [SyntaxKind.LabeledStatement]: function forEachChildInLabeledStatement(node: LabeledStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.label) || + visitNode(cbNode, node.statement); + }, + [SyntaxKind.ThrowStatement]: function forEachChildInThrowStatement(node: ThrowStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.TryStatement]: function forEachChildInTryStatement(node: TryStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tryBlock) || + visitNode(cbNode, node.catchClause) || + visitNode(cbNode, node.finallyBlock); + }, + [SyntaxKind.CatchClause]: function forEachChildInCatchClause(node: CatchClause, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.variableDeclaration) || + visitNode(cbNode, node.block); + }, + [SyntaxKind.Decorator]: function forEachChildInDecorator(node: Decorator, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.ClassDeclaration]: forEachChildInClassDeclarationOrExpression, + [SyntaxKind.ClassExpression]: forEachChildInClassDeclarationOrExpression, + [SyntaxKind.InterfaceDeclaration]: function forEachChildInInterfaceDeclaration(node: InterfaceDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.heritageClauses) || + visitNodes(cbNode, cbNodes, node.members); + }, + [SyntaxKind.TypeAliasDeclaration]: function forEachChildInTypeAliasDeclaration(node: TypeAliasDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNode(cbNode, node.type); + }, + [SyntaxKind.EnumDeclaration]: function forEachChildInEnumDeclaration(node: EnumDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNodes(cbNode, cbNodes, node.members); + }, + [SyntaxKind.EnumMember]: function forEachChildInEnumMember(node: EnumMember, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.name) || + visitNode(cbNode, node.initializer); + }, + [SyntaxKind.ModuleDeclaration]: function forEachChildInModuleDeclaration(node: ModuleDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.body); + }, + [SyntaxKind.ImportEqualsDeclaration]: function forEachChildInImportEqualsDeclaration(node: ImportEqualsDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.moduleReference); + }, + [SyntaxKind.ImportDeclaration]: function forEachChildInImportDeclaration(node: ImportDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.importClause) || + visitNode(cbNode, node.moduleSpecifier) || + visitNode(cbNode, node.attributes); + }, + [SyntaxKind.ImportClause]: function forEachChildInImportClause(node: ImportClause, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.name) || + visitNode(cbNode, node.namedBindings); + }, + [SyntaxKind.ImportAttributes]: function forEachChildInImportAttributes(node: ImportAttributes, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.elements); + }, + [SyntaxKind.ImportAttribute]: function forEachChildInImportAttribute(node: ImportAttribute, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.name) || + visitNode(cbNode, node.value); + }, + [SyntaxKind.NamespaceExportDeclaration]: function forEachChildInNamespaceExportDeclaration(node: NamespaceExportDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name); + }, + [SyntaxKind.NamespaceImport]: function forEachChildInNamespaceImport(node: NamespaceImport, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.name); + }, + [SyntaxKind.NamespaceExport]: function forEachChildInNamespaceExport(node: NamespaceExport, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.name); + }, + [SyntaxKind.NamedImports]: forEachChildInNamedImportsOrExports, + [SyntaxKind.NamedExports]: forEachChildInNamedImportsOrExports, + [SyntaxKind.ExportDeclaration]: function forEachChildInExportDeclaration(node: ExportDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.exportClause) || + visitNode(cbNode, node.moduleSpecifier) || + visitNode(cbNode, node.attributes); + }, + [SyntaxKind.ImportSpecifier]: forEachChildInImportOrExportSpecifier, + [SyntaxKind.ExportSpecifier]: forEachChildInImportOrExportSpecifier, + [SyntaxKind.ExportAssignment]: function forEachChildInExportAssignment(node: ExportAssignment, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.expression); + }, + [SyntaxKind.TemplateExpression]: function forEachChildInTemplateExpression(node: TemplateExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.head) || + visitNodes(cbNode, cbNodes, node.templateSpans); + }, + [SyntaxKind.TemplateSpan]: function forEachChildInTemplateSpan(node: TemplateSpan, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.literal); + }, + [SyntaxKind.TemplateLiteralType]: function forEachChildInTemplateLiteralType(node: TemplateLiteralTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.head) || + visitNodes(cbNode, cbNodes, node.templateSpans); + }, + [SyntaxKind.TemplateLiteralTypeSpan]: function forEachChildInTemplateLiteralTypeSpan(node: TemplateLiteralTypeSpan, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.type) || + visitNode(cbNode, node.literal); + }, + [SyntaxKind.ComputedPropertyName]: function forEachChildInComputedPropertyName(node: ComputedPropertyName, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.HeritageClause]: function forEachChildInHeritageClause(node: HeritageClause, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.types); + }, + [SyntaxKind.ExpressionWithTypeArguments]: function forEachChildInExpressionWithTypeArguments(node: ExpressionWithTypeArguments, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression) || + visitNodes(cbNode, cbNodes, node.typeArguments); + }, + [SyntaxKind.ExternalModuleReference]: function forEachChildInExternalModuleReference(node: ExternalModuleReference, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.MissingDeclaration]: function forEachChildInMissingDeclaration(node: MissingDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers); + }, + [SyntaxKind.CommaListExpression]: function forEachChildInCommaListExpression(node: CommaListExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.elements); + }, + [SyntaxKind.JsxElement]: function forEachChildInJsxElement(node: JsxElement, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.openingElement) || + visitNodes(cbNode, cbNodes, node.children) || + visitNode(cbNode, node.closingElement); + }, + [SyntaxKind.JsxFragment]: function forEachChildInJsxFragment(node: JsxFragment, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.openingFragment) || + visitNodes(cbNode, cbNodes, node.children) || + visitNode(cbNode, node.closingFragment); + }, + [SyntaxKind.JsxSelfClosingElement]: forEachChildInJsxOpeningOrSelfClosingElement, + [SyntaxKind.JsxOpeningElement]: forEachChildInJsxOpeningOrSelfClosingElement, + [SyntaxKind.JsxAttributes]: function forEachChildInJsxAttributes(node: JsxAttributes, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.properties); + }, + [SyntaxKind.JsxAttribute]: function forEachChildInJsxAttribute(node: JsxAttribute, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.name) || + visitNode(cbNode, node.initializer); + }, + [SyntaxKind.JsxSpreadAttribute]: function forEachChildInJsxSpreadAttribute(node: JsxSpreadAttribute, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); + }, + [SyntaxKind.JsxExpression]: function forEachChildInJsxExpression(node: JsxExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.dotDotDotToken) || + visitNode(cbNode, node.expression); + }, + [SyntaxKind.JsxClosingElement]: function forEachChildInJsxClosingElement(node: JsxClosingElement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName); + }, + [SyntaxKind.JsxNamespacedName]: function forEachChildInJsxNamespacedName(node: JsxNamespacedName, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.namespace) || + visitNode(cbNode, node.name); + }, + [SyntaxKind.OptionalType]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.RestType]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.JSDocTypeExpression]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.JSDocNonNullableType]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.JSDocNullableType]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.JSDocOptionalType]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.JSDocVariadicType]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.JSDocFunctionType]: function forEachChildInJSDocFunctionType(node: JSDocFunctionType, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type); + }, + [SyntaxKind.JSDoc]: function forEachChildInJSDoc(node: JSDoc, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)) + || visitNodes(cbNode, cbNodes, node.tags); + }, + [SyntaxKind.JSDocSeeTag]: function forEachChildInJSDocSeeTag(node: JSDocSeeTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName) || + visitNode(cbNode, node.name) || + (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); + }, + [SyntaxKind.JSDocNameReference]: function forEachChildInJSDocNameReference(node: JSDocNameReference, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.name); + }, + [SyntaxKind.JSDocMemberName]: function forEachChildInJSDocMemberName(node: JSDocMemberName, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.left) || + visitNode(cbNode, node.right); + }, + [SyntaxKind.JSDocParameterTag]: forEachChildInJSDocParameterOrPropertyTag, + [SyntaxKind.JSDocPropertyTag]: forEachChildInJSDocParameterOrPropertyTag, + [SyntaxKind.JSDocAuthorTag]: function forEachChildInJSDocAuthorTag(node: JSDocAuthorTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName) || + (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); + }, + [SyntaxKind.JSDocImplementsTag]: function forEachChildInJSDocImplementsTag(node: JSDocImplementsTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName) || + visitNode(cbNode, node.class) || + (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); + }, + [SyntaxKind.JSDocAugmentsTag]: function forEachChildInJSDocAugmentsTag(node: JSDocAugmentsTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName) || + visitNode(cbNode, node.class) || + (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); + }, + [SyntaxKind.JSDocTemplateTag]: function forEachChildInJSDocTemplateTag(node: JSDocTemplateTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName) || + visitNode(cbNode, node.constraint) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); + }, + [SyntaxKind.JSDocTypedefTag]: function forEachChildInJSDocTypedefTag(node: JSDocTypedefTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName) || + (node.typeExpression && + node.typeExpression.kind === SyntaxKind.JSDocTypeExpression + ? visitNode(cbNode, node.typeExpression) || + visitNode(cbNode, node.fullName) || + (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)) + : visitNode(cbNode, node.fullName) || + visitNode(cbNode, node.typeExpression) || + (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment))); + }, + [SyntaxKind.JSDocCallbackTag]: function forEachChildInJSDocCallbackTag(node: JSDocCallbackTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName) || + visitNode(cbNode, node.fullName) || + visitNode(cbNode, node.typeExpression) || + (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); + }, + [SyntaxKind.JSDocReturnTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocTypeTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocThisTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocEnumTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocSatisfiesTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocThrowsTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocOverloadTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocSignature]: function forEachChildInJSDocSignature(node: JSDocSignature, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return forEach(node.typeParameters, cbNode) || + forEach(node.parameters, cbNode) || + visitNode(cbNode, node.type); + }, + [SyntaxKind.JSDocLink]: forEachChildInJSDocLinkCodeOrPlain, + [SyntaxKind.JSDocLinkCode]: forEachChildInJSDocLinkCodeOrPlain, + [SyntaxKind.JSDocLinkPlain]: forEachChildInJSDocLinkCodeOrPlain, + [SyntaxKind.JSDocTypeLiteral]: function forEachChildInJSDocTypeLiteral(node: JSDocTypeLiteral, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return forEach(node.jsDocPropertyTags, cbNode); + }, + [SyntaxKind.JSDocTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocClassTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocPublicTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocPrivateTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocProtectedTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocReadonlyTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocDeprecatedTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocOverrideTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocImportTag]: forEachChildInJSDocImportTag, + [SyntaxKind.PartiallyEmittedExpression]: forEachChildInPartiallyEmittedExpression, +}; + +// shared + +function forEachChildInCallOrConstructSignature(node: CallSignatureDeclaration | ConstructSignatureDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.parameters) || + visitNode(cbNode, node.type); +} + +function forEachChildInUnionOrIntersectionType(node: UnionTypeNode | IntersectionTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.types); +} + +function forEachChildInParenthesizedTypeOrTypeOperator(node: ParenthesizedTypeNode | TypeOperatorNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.type); +} + +function forEachChildInObjectOrArrayBindingPattern(node: BindingPattern, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.elements); +} + +function forEachChildInCallOrNewExpression(node: CallExpression | NewExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression) || + // TODO: should we separate these branches out? + visitNode(cbNode, (node as CallExpression).questionDotToken) || + visitNodes(cbNode, cbNodes, node.typeArguments) || + visitNodes(cbNode, cbNodes, node.arguments); +} + +function forEachChildInBlock(node: Block | ModuleBlock, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.statements); +} + +function forEachChildInContinueOrBreakStatement(node: ContinueStatement | BreakStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.label); +} + +function forEachChildInClassDeclarationOrExpression(node: ClassDeclaration | ClassExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.heritageClauses) || + visitNodes(cbNode, cbNodes, node.members); +} + +function forEachChildInNamedImportsOrExports(node: NamedImports | NamedExports, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.elements); +} + +function forEachChildInImportOrExportSpecifier(node: ImportSpecifier | ExportSpecifier, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.propertyName) || + visitNode(cbNode, node.name); +} + +function forEachChildInJsxOpeningOrSelfClosingElement(node: JsxOpeningLikeElement, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName) || + visitNodes(cbNode, cbNodes, node.typeArguments) || + visitNode(cbNode, node.attributes); +} + +function forEachChildInOptionalRestOrJSDocParameterModifier(node: OptionalTypeNode | RestTypeNode | JSDocTypeExpression | JSDocNullableType | JSDocNonNullableType | JSDocOptionalType | JSDocVariadicType, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.type); +} + +function forEachChildInJSDocParameterOrPropertyTag(node: JSDocParameterTag | JSDocPropertyTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName) || + (node.isNameFirst + ? visitNode(cbNode, node.name) || visitNode(cbNode, node.typeExpression) + : visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.name)) || + (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); +} + +function forEachChildInJSDocTypeLikeTag(node: JSDocReturnTag | JSDocTypeTag | JSDocThisTag | JSDocEnumTag | JSDocThrowsTag | JSDocOverloadTag | JSDocSatisfiesTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName) || + visitNode(cbNode, node.typeExpression) || + (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); +} + +function forEachChildInJSDocLinkCodeOrPlain(node: JSDocLink | JSDocLinkCode | JSDocLinkPlain, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.name); +} + +function forEachChildInJSDocTag(node: JSDocUnknownTag | JSDocClassTag | JSDocPublicTag | JSDocPrivateTag | JSDocProtectedTag | JSDocReadonlyTag | JSDocDeprecatedTag | JSDocOverrideTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName) + || (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); +} + +function forEachChildInJSDocImportTag(node: JSDocImportTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.tagName) + || visitNode(cbNode, node.importClause) + || visitNode(cbNode, node.moduleSpecifier) + || visitNode(cbNode, node.attributes) + || (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); +} + +function forEachChildInPartiallyEmittedExpression(node: PartiallyEmittedExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.expression); +} + +/** + * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes + * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, + * embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns + * a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. + * + * @param node a given node to visit its children + * @param cbNode a callback to be invoked for all child nodes + * @param cbNodes a callback to be invoked for embedded array + * + * @remarks `forEachChild` must visit the children of a node in the order + * that they appear in the source code. The language service depends on this property to locate nodes by position. + */ +export function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + if (node === undefined || node.kind <= SyntaxKind.LastToken) { + return; + } + const fn = (forEachChildTable as Record>)[node.kind]; + return fn === undefined ? undefined : fn(node, cbNode, cbNodes); +} + +/** + * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes + * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; additionally, + * unlike `forEachChild`, embedded arrays are flattened and the 'cbNode' callback is invoked for each element. + * If a callback returns a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. + * + * @param node a given node to visit its children + * @param cbNode a callback to be invoked for all child nodes + * @param cbNodes a callback to be invoked for embedded array + * + * @remarks Unlike `forEachChild`, `forEachChildRecursively` handles recursively invoking the traversal on each child node found, + * and while doing so, handles traversing the structure without relying on the callstack to encode the tree structure. + * + * @internal + */ +export function forEachChildRecursively(rootNode: Node, cbNode: (node: Node, parent: Node) => T | "skip" | undefined, cbNodes?: (nodes: NodeArray, parent: Node) => T | "skip" | undefined): T | undefined { + const queue: (Node | NodeArray)[] = gatherPossibleChildren(rootNode); + const parents: Node[] = []; // tracks parent references for elements in queue + while (parents.length < queue.length) { + parents.push(rootNode); + } + while (queue.length !== 0) { + const current = queue.pop()!; + const parent = parents.pop()!; + if (isArray(current)) { + if (cbNodes) { + const res = cbNodes(current, parent); + if (res) { + if (res === "skip") continue; + return res; + } + } + for (let i = current.length - 1; i >= 0; --i) { + queue.push(current[i]); + parents.push(parent); + } + } + else { + const res = cbNode(current, parent); + if (res) { + if (res === "skip") continue; + return res; + } + if (current.kind >= SyntaxKind.FirstNode) { + // add children in reverse order to the queue, so popping gives the first child + for (const child of gatherPossibleChildren(current)) { + queue.push(child); + parents.push(current); + } + } + } + } +} + +function gatherPossibleChildren(node: Node) { + const children: (Node | NodeArray)[] = []; + forEachChild(node, addWorkItem, addWorkItem); // By using a stack above and `unshift` here, we emulate a depth-first preorder traversal + return children; + + function addWorkItem(n: Node | NodeArray) { + children.unshift(n); + } +} diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index de9ad87602619..6643fd57636ea 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1,55 +1,256 @@ import { - AccessorDeclaration, + AstAccessorDeclaration, + AstArrayBindingElement, + AstArrayBindingPattern, + AstArrayLiteralExpression, + AstArrayTypeNode, + AstArrowFunction, + AstAsExpression, + AstAsteriskToken, + AstBigIntLiteral, + AstBinaryExpression, + AstBinaryOperatorToken, + AstBindingElement, + AstBindingName, + AstBindingPattern, + AstBlock, + AstBooleanLiteral, + AstBreakOrContinueStatement, + AstCallSignatureDeclaration, + AstCaseBlock, + AstCaseClause, + AstCaseOrDefaultClause, + AstCatchClause, + AstClassDeclaration, + AstClassElement, + AstClassExpression, + AstClassLikeDeclaration, + AstClassStaticBlockDeclaration, + AstComputedPropertyName, + AstConciseBody, + AstConstructorDeclaration, + AstConstructSignatureDeclaration, + AstDecorator, + AstDefaultClause, + AstDoStatement, + AstDotDotDotToken, + AstEndOfFileToken, + AstEntityName, + AstEntityNameExpression, + AstEnumDeclaration, + AstEnumMember, + AstExclamationToken, + AstExportAssignment, + AstExportDeclaration, + AstExportSpecifier, + AstExpression, + AstExpressionStatement, + AstExpressionWithTypeArguments, + AstForInitializer, + AstForInOrOfStatement, + AstForStatement, + AstFunctionDeclaration, + AstFunctionExpression, + AstFunctionOrConstructorTypeNode, + AstHasJSDoc, + AstHeritageClause, + AstIdentifier, + AstIfStatement, + AstImportAttributes, + AstImportClause, + AstImportDeclaration, + AstImportEqualsDeclaration, + AstImportExpression, + AstImportSpecifier, + AstImportTypeNode, + AstIndexSignatureDeclaration, + AstInferTypeNode, + AstInterfaceDeclaration, + AstIterationStatement, + AstJSDocAllType, + AstJSDocAugmentsTag, + AstJSDocAuthorTag, + AstJSDocCallbackTag, + AstJSDocClassReference, + AstJSDocComment, + AstJSDocEnumTag, + AstJSDocFunctionType, + AstJSDocImplementsTag, + AstJSDocImportTag, + AstJSDocMemberName, + AstJSDocNameReference, + AstJSDocNamespaceDeclaration, + AstJSDocNode, + AstJSDocNullableType, + AstJSDocOptionalType, + AstJSDocOverloadTag, + AstJSDocParameterTag, + AstJSDocPropertyLikeTag, + AstJSDocPropertyTag, + AstJSDocReturnTag, + AstJSDocSatisfiesTag, + AstJSDocSeeTag, + AstJSDocSignature, + AstJSDocTag, + AstJSDocTemplateTag, + AstJSDocText, + AstJSDocThisTag, + AstJSDocThrowsTag, + AstJSDocTypedefTag, + AstJSDocTypeExpression, + AstJSDocTypeLiteral, + AstJSDocTypeTag, + AstJSDocUnknownType, + AstJsonMinusNumericLiteral, + AstJsonObjectExpressionStatement, + AstJsonSourceFile, + AstJsxAttribute, + AstJsxAttributes, + AstJsxAttributeValue, + AstJsxChild, + AstJsxClosingElement, + AstJsxClosingFragment, + AstJsxElement, + AstJsxExpression, + AstJsxFragment, + AstJsxNamespacedName, + AstJsxOpeningElement, + AstJsxOpeningFragment, + AstJsxOpeningLikeElement, + AstJsxSelfClosingElement, + AstJsxSpreadAttribute, + AstJsxTagNameExpression, + AstJsxText, + AstKeywordExpression, + AstKeywordTypeNode, + AstLabeledStatement, + AstLeftHandSideExpression, + AstLiteralExpression, + AstLiteralLikeNode, + AstLiteralTypeNode, + AstMemberExpression, + AstMetaProperty, + AstMethodDeclaration, + AstMethodSignature, + AstMinusToken, + AstMissingDeclaration, + AstModifier, + AstModifierLike, + AstModuleBlock, + AstModuleDeclaration, + AstModuleExportName, + AstNamedExportBindings, + AstNamedExports, + AstNamedImports, + AstNamespaceDeclaration, + AstNamespaceExport, + AstNamespaceExportDeclaration, + AstNamespaceImport, + AstNewExpression, + AstNode, + AstNodeArray, + AstNodeArrayLike, + AstNoSubstitutionTemplateLiteral, + AstNullLiteral, + AstNumericLiteral, + AstObjectBindingPattern, + AstObjectLiteralElementLike, + AstObjectLiteralExpression, + AstParameterDeclaration, + AstParenthesizedExpression, + AstParenthesizedTypeNode, + AstPlusToken, + AstPrefixUnaryExpression, + AstPrimaryExpression, + AstPrivateIdentifier, + AstPropertyAccessEntityNameExpression, + AstPropertyAccessExpression, + AstPropertyAssignment, + AstPropertyDeclaration, + AstPropertyName, + AstPropertySignature, + AstQualifiedName, + AstQuestionDotToken, + AstQuestionToken, + AstReadonlyKeyword, + AstReturnStatement, + AstSatisfiesExpression, + AstShorthandPropertyAssignment, + AstSourceFile, + AstStatement, + AstStringLiteral, + AstSuperExpression, + AstSwitchStatement, + AstTemplateExpression, + AstTemplateHead, + AstTemplateLiteralToken, + AstTemplateLiteralTypeNode, + AstTemplateLiteralTypeSpan, + AstTemplateMiddle, + AstTemplateSpan, + AstTemplateTail, + AstThisExpression, + AstThisTypeNode, + AstThrowStatement, + AstToken, + AstTryStatement, + AstTupleTypeNode, + AstTypeAliasDeclaration, + AstTypeAssertion, + AstTypeElement, + AstTypeLiteralNode, + AstTypeNode, + AstTypeParameterDeclaration, + AstTypePredicateNode, + AstTypeQueryNode, + AstTypeReferenceNode, + AstUnaryExpression, + AstUnionOrIntersectionTypeNode, + AstUpdateExpression, + AstVariableDeclaration, + AstVariableDeclarationList, + AstVariableStatement, + AstWhileStatement, + AstWithStatement, + AstYieldExpression, + createAstNodeFactory, + hasAstJSDocNodes, + isAstAsyncModifier, + isAstDeclareKeyword, + isAstExportModifier, + isAstExpressionWithTypeArguments, + isAstFunctionTypeNode, + isAstIdentifier, + isAstJSDocFunctionType, + isAstJSDocNullableType, + isAstJSDocReturnTag, + isAstJSDocTypeTag, + isAstJsxNamespacedName, + isAstJsxOpeningElement, + isAstJsxOpeningFragment, + isAstLeftHandSideExpression, + isAstNonNullExpression, + isAstPrivateIdentifier, + isAstSetAccessorDeclaration, + isAstStringOrNumericLiteralLike, + isAstTaggedTemplateExpression, + isAstTypeReferenceNode, +} from "./_namespaces/ts.ast.js"; +import { addRange, addRelatedInfo, append, - ArrayBindingElement, - ArrayBindingPattern, - ArrayLiteralExpression, - ArrayTypeNode, - ArrowFunction, - AsExpression, AssertionLevel, - AsteriskToken, + ast, attachFileToDiagnostics, - AwaitExpression, - BigIntLiteral, - BinaryExpression, - BinaryOperatorToken, - BindingElement, - BindingName, - BindingPattern, - Block, - BooleanLiteral, - BreakOrContinueStatement, - BreakStatement, - CallExpression, - CallSignatureDeclaration, canHaveJSDoc, canHaveModifiers, - CaseBlock, - CaseClause, - CaseOrDefaultClause, - CatchClause, CharacterCodes, - ClassDeclaration, - ClassElement, - ClassExpression, - ClassLikeDeclaration, - ClassStaticBlockDeclaration, - CommaListExpression, CommentDirective, commentPragmas, CommentRange, - ComputedPropertyName, concatenate, - ConditionalExpression, - ConditionalTypeNode, - ConstructorDeclaration, - ConstructorTypeNode, - ConstructSignatureDeclaration, containsParseError, - ContinueStatement, convertToJson, createDetachedDiagnostic, createNodeFactory, @@ -57,47 +258,21 @@ import { createTextChangeRange, createTextSpanFromBounds, Debug, - Decorator, - DefaultClause, - DeleteExpression, Diagnostic, DiagnosticArguments, DiagnosticMessage, Diagnostics, DiagnosticWithDetachedLocation, - DoStatement, - DotDotDotToken, - ElementAccessExpression, emptyArray, emptyMap, - EndOfFileToken, ensureScriptKind, EntityName, - EnumDeclaration, - EnumMember, - ExclamationToken, - ExportAssignment, - ExportDeclaration, - ExportSpecifier, - Expression, - ExpressionStatement, - ExpressionWithTypeArguments, Extension, - ExternalModuleReference, fileExtensionIs, findIndex, firstOrUndefined, forEach, - ForEachChildNodes, - ForInOrOfStatement, - ForInStatement, - ForOfStatement, - ForStatement, - FunctionDeclaration, - FunctionExpression, - FunctionOrConstructorTypeNode, - FunctionTypeNode, - GetAccessorDeclaration, + forEachChild, getAnyExtensionFromPath, getBaseFileName, getBinaryOperatorPrecedence, @@ -108,167 +283,38 @@ import { getLeadingCommentRanges, getSpellingSuggestion, getTextOfNodeFromSourceText, - HasJSDoc, - hasJSDocNodes, HasModifiers, - HeritageClause, - Identifier, identity, - idText, - IfStatement, - ImportAttribute, - ImportAttributes, - ImportClause, - ImportDeclaration, - ImportEqualsDeclaration, - ImportOrExportSpecifier, - ImportSpecifier, - ImportTypeAssertionContainer, - ImportTypeNode, - IndexedAccessTypeNode, - IndexSignatureDeclaration, - InferTypeNode, - InterfaceDeclaration, - IntersectionTypeNode, isArray, isAssignmentOperator, - isAsyncModifier, isClassMemberModifier, isExportAssignment, isExportDeclaration, - isExportModifier, - isExpressionWithTypeArguments, isExternalModuleReference, - isFunctionTypeNode, - isIdentifier as isIdentifierNode, isIdentifierText, isImportDeclaration, isImportEqualsDeclaration, - isJSDocFunctionType, - isJSDocNullableType, - isJSDocReturnTag, - isJSDocTypeTag, - isJsxNamespacedName, - isJsxOpeningElement, - isJsxOpeningFragment, isKeyword, isKeywordOrPunctuation, - isLeftHandSideExpression, isLiteralKind, isMetaProperty, isModifierKind, - isNonNullExpression, - isPrivateIdentifier, - isSetAccessorDeclaration, - isStringOrNumericLiteralLike, - isTaggedTemplateExpression, isTemplateLiteralKind, - isTypeReferenceNode, - IterationStatement, JSDoc, - JSDocAllType, - JSDocAugmentsTag, - JSDocAuthorTag, - JSDocCallbackTag, - JSDocClassTag, - JSDocComment, - JSDocDeprecatedTag, - JSDocEnumTag, - JSDocFunctionType, - JSDocImplementsTag, - JSDocImportTag, - JSDocLink, - JSDocLinkCode, - JSDocLinkPlain, - JSDocMemberName, - JSDocNameReference, - JSDocNamespaceDeclaration, - JSDocNonNullableType, - JSDocNullableType, - JSDocOptionalType, - JSDocOverloadTag, - JSDocOverrideTag, - JSDocParameterTag, JSDocParsingMode, - JSDocPrivateTag, - JSDocPropertyLikeTag, - JSDocPropertyTag, - JSDocProtectedTag, - JSDocPublicTag, - JSDocReadonlyTag, - JSDocReturnTag, - JSDocSatisfiesTag, - JSDocSeeTag, - JSDocSignature, JSDocSyntaxKind, - JSDocTag, - JSDocTemplateTag, - JSDocText, - JSDocThisTag, - JSDocThrowsTag, - JSDocTypedefTag, JSDocTypeExpression, - JSDocTypeLiteral, - JSDocTypeTag, - JSDocUnknownTag, - JSDocUnknownType, - JSDocVariadicType, - JsonMinusNumericLiteral, - JsonObjectExpressionStatement, JsonSourceFile, - JsxAttribute, - JsxAttributes, - JsxAttributeValue, - JsxChild, - JsxClosingElement, - JsxClosingFragment, - JsxElement, - JsxExpression, - JsxFragment, - JsxNamespacedName, - JsxOpeningElement, - JsxOpeningFragment, - JsxOpeningLikeElement, - JsxSelfClosingElement, - JsxSpreadAttribute, JsxTagNameExpression, - JsxText, JsxTokenSyntaxKind, - LabeledStatement, LanguageVariant, lastOrUndefined, - LeftHandSideExpression, - LiteralExpression, - LiteralLikeNode, - LiteralTypeNode, map, mapDefined, - MappedTypeNode, - MemberExpression, - MetaProperty, - MethodDeclaration, - MethodSignature, - MinusToken, - MissingDeclaration, - Modifier, ModifierFlags, - ModifierLike, modifiersToFlags, - ModuleBlock, - ModuleDeclaration, - ModuleExportName, ModuleKind, Mutable, - NamedExportBindings, - NamedExports, - NamedImports, - NamedImportsOrExports, - NamedTupleMember, - NamespaceDeclaration, - NamespaceExport, - NamespaceExportDeclaration, - NamespaceImport, - NewExpression, Node, NodeArray, NodeFactory, @@ -276,24 +322,10 @@ import { NodeFlags, nodeIsMissing, nodeIsPresent, - NonNullExpression, noop, normalizePath, - NoSubstitutionTemplateLiteral, - NullLiteral, - NumericLiteral, - ObjectBindingPattern, - ObjectLiteralElementLike, - ObjectLiteralExpression, OperatorPrecedence, - OptionalTypeNode, PackageJsonInfo, - ParameterDeclaration, - ParenthesizedExpression, - ParenthesizedTypeNode, - PartiallyEmittedExpression, - PlusToken, - PostfixUnaryExpression, PostfixUnaryOperator, PragmaContext, PragmaDefinition, @@ -301,101 +333,42 @@ import { PragmaMap, PragmaPseudoMap, PragmaPseudoMapEntry, - PrefixUnaryExpression, PrefixUnaryOperator, - PrimaryExpression, - PrivateIdentifier, - PropertyAccessEntityNameExpression, - PropertyAccessExpression, - PropertyAssignment, - PropertyDeclaration, - PropertyName, - PropertySignature, PunctuationOrKeywordSyntaxKind, PunctuationSyntaxKind, - QualifiedName, - QuestionDotToken, - QuestionToken, - ReadonlyKeyword, ReadonlyPragmaMap, ResolutionMode, - RestTypeNode, - ReturnStatement, - SatisfiesExpression, ScriptKind, ScriptTarget, - SetAccessorDeclaration, setParent, setParentRecursive, setTextRange, setTextRangePos, setTextRangePosEnd, setTextRangePosWidth, - ShorthandPropertyAssignment, skipTrivia, some, SourceFile, - SpreadAssignment, - SpreadElement, startsWith, - Statement, - StringLiteral, supportedDeclarationExtensions, - SwitchStatement, SyntaxKind, - TaggedTemplateExpression, - TemplateExpression, - TemplateHead, - TemplateLiteralToken, - TemplateLiteralTypeNode, - TemplateLiteralTypeSpan, - TemplateMiddle, - TemplateSpan, - TemplateTail, TextChangeRange, textChangeRangeIsUnchanged, textChangeRangeNewSpan, TextRange, textSpanEnd, textToKeywordObj, - ThisExpression, - ThisTypeNode, - ThrowStatement, toArray, - Token, TokenFlags, tokenIsIdentifierOrKeyword, tokenIsIdentifierOrKeywordOrGreaterThan, + TokenSyntaxKind, tokenToString, tracing, transferSourceFileChildren, TransformFlags, - TryStatement, - TupleTypeNode, - TypeAliasDeclaration, - TypeAssertion, - TypeElement, - TypeLiteralNode, - TypeNode, - TypeOfExpression, - TypeOperatorNode, - TypeParameterDeclaration, - TypePredicateNode, - TypeQueryNode, - TypeReferenceNode, - UnaryExpression, unescapeLeadingUnderscores, - UnionOrIntersectionTypeNode, - UnionTypeNode, unsetNodeChildren, - UpdateExpression, - VariableDeclaration, - VariableDeclarationList, - VariableStatement, - VoidExpression, - WhileStatement, - WithStatement, - YieldExpression, } from "./_namespaces/ts.js"; import * as performance from "./_namespaces/ts.performance.js"; @@ -417,24 +390,6 @@ const enum SpeculationKind { /** @internal */ export const parseNodeFactory: NodeFactory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules); -function visitNode(cbNode: (node: Node) => T, node: Node | undefined): T | undefined { - return node && cbNode(node); -} - -function visitNodes(cbNode: (node: Node) => T, cbNodes: ((node: NodeArray) => T | undefined) | undefined, nodes: NodeArray | undefined): T | undefined { - if (nodes) { - if (cbNodes) { - return cbNodes(nodes); - } - for (const node of nodes) { - const result = cbNode(node); - if (result) { - return result; - } - } - } -} - /** @internal */ export function isJSDocLikeText(text: string, start: number): boolean { return text.charCodeAt(start + 1) === CharacterCodes.asterisk && @@ -477,824 +432,6 @@ function isImportMeta(node: Node): boolean { return isMetaProperty(node) && node.keywordToken === SyntaxKind.ImportKeyword && node.name.escapedText === "meta"; } -type ForEachChildFunction = (node: TNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined) => T | undefined; -type ForEachChildTable = { [TNode in ForEachChildNodes as TNode["kind"]]: ForEachChildFunction; }; -const forEachChildTable: ForEachChildTable = { - [SyntaxKind.QualifiedName]: function forEachChildInQualifiedName(node: QualifiedName, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.left) || - visitNode(cbNode, node.right); - }, - [SyntaxKind.TypeParameter]: function forEachChildInTypeParameter(node: TypeParameterDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNode(cbNode, node.constraint) || - visitNode(cbNode, node.default) || - visitNode(cbNode, node.expression); - }, - [SyntaxKind.ShorthandPropertyAssignment]: function forEachChildInShorthandPropertyAssignment(node: ShorthandPropertyAssignment, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNode(cbNode, node.questionToken) || - visitNode(cbNode, node.exclamationToken) || - visitNode(cbNode, node.equalsToken) || - visitNode(cbNode, node.objectAssignmentInitializer); - }, - [SyntaxKind.SpreadAssignment]: function forEachChildInSpreadAssignment(node: SpreadAssignment, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.Parameter]: function forEachChildInParameter(node: ParameterDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.dotDotDotToken) || - visitNode(cbNode, node.name) || - visitNode(cbNode, node.questionToken) || - visitNode(cbNode, node.type) || - visitNode(cbNode, node.initializer); - }, - [SyntaxKind.PropertyDeclaration]: function forEachChildInPropertyDeclaration(node: PropertyDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNode(cbNode, node.questionToken) || - visitNode(cbNode, node.exclamationToken) || - visitNode(cbNode, node.type) || - visitNode(cbNode, node.initializer); - }, - [SyntaxKind.PropertySignature]: function forEachChildInPropertySignature(node: PropertySignature, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNode(cbNode, node.questionToken) || - visitNode(cbNode, node.type) || - visitNode(cbNode, node.initializer); - }, - [SyntaxKind.PropertyAssignment]: function forEachChildInPropertyAssignment(node: PropertyAssignment, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNode(cbNode, node.questionToken) || - visitNode(cbNode, node.exclamationToken) || - visitNode(cbNode, node.initializer); - }, - [SyntaxKind.VariableDeclaration]: function forEachChildInVariableDeclaration(node: VariableDeclaration, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.name) || - visitNode(cbNode, node.exclamationToken) || - visitNode(cbNode, node.type) || - visitNode(cbNode, node.initializer); - }, - [SyntaxKind.BindingElement]: function forEachChildInBindingElement(node: BindingElement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.dotDotDotToken) || - visitNode(cbNode, node.propertyName) || - visitNode(cbNode, node.name) || - visitNode(cbNode, node.initializer); - }, - [SyntaxKind.IndexSignature]: function forEachChildInIndexSignature(node: IndexSignatureDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type); - }, - [SyntaxKind.ConstructorType]: function forEachChildInConstructorType(node: ConstructorTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type); - }, - [SyntaxKind.FunctionType]: function forEachChildInFunctionType(node: FunctionTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type); - }, - [SyntaxKind.CallSignature]: forEachChildInCallOrConstructSignature, - [SyntaxKind.ConstructSignature]: forEachChildInCallOrConstructSignature, - [SyntaxKind.MethodDeclaration]: function forEachChildInMethodDeclaration(node: MethodDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.asteriskToken) || - visitNode(cbNode, node.name) || - visitNode(cbNode, node.questionToken) || - visitNode(cbNode, node.exclamationToken) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type) || - visitNode(cbNode, node.body); - }, - [SyntaxKind.MethodSignature]: function forEachChildInMethodSignature(node: MethodSignature, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNode(cbNode, node.questionToken) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type); - }, - [SyntaxKind.Constructor]: function forEachChildInConstructor(node: ConstructorDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type) || - visitNode(cbNode, node.body); - }, - [SyntaxKind.GetAccessor]: function forEachChildInGetAccessor(node: GetAccessorDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type) || - visitNode(cbNode, node.body); - }, - [SyntaxKind.SetAccessor]: function forEachChildInSetAccessor(node: SetAccessorDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type) || - visitNode(cbNode, node.body); - }, - [SyntaxKind.FunctionDeclaration]: function forEachChildInFunctionDeclaration(node: FunctionDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.asteriskToken) || - visitNode(cbNode, node.name) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type) || - visitNode(cbNode, node.body); - }, - [SyntaxKind.FunctionExpression]: function forEachChildInFunctionExpression(node: FunctionExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.asteriskToken) || - visitNode(cbNode, node.name) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type) || - visitNode(cbNode, node.body); - }, - [SyntaxKind.ArrowFunction]: function forEachChildInArrowFunction(node: ArrowFunction, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type) || - visitNode(cbNode, node.equalsGreaterThanToken) || - visitNode(cbNode, node.body); - }, - [SyntaxKind.ClassStaticBlockDeclaration]: function forEachChildInClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.body); - }, - [SyntaxKind.TypeReference]: function forEachChildInTypeReference(node: TypeReferenceNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.typeName) || - visitNodes(cbNode, cbNodes, node.typeArguments); - }, - [SyntaxKind.TypePredicate]: function forEachChildInTypePredicate(node: TypePredicateNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.assertsModifier) || - visitNode(cbNode, node.parameterName) || - visitNode(cbNode, node.type); - }, - [SyntaxKind.TypeQuery]: function forEachChildInTypeQuery(node: TypeQueryNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.exprName) || - visitNodes(cbNode, cbNodes, node.typeArguments); - }, - [SyntaxKind.TypeLiteral]: function forEachChildInTypeLiteral(node: TypeLiteralNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.members); - }, - [SyntaxKind.ArrayType]: function forEachChildInArrayType(node: ArrayTypeNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.elementType); - }, - [SyntaxKind.TupleType]: function forEachChildInTupleType(node: TupleTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.elements); - }, - [SyntaxKind.UnionType]: forEachChildInUnionOrIntersectionType, - [SyntaxKind.IntersectionType]: forEachChildInUnionOrIntersectionType, - [SyntaxKind.ConditionalType]: function forEachChildInConditionalType(node: ConditionalTypeNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.checkType) || - visitNode(cbNode, node.extendsType) || - visitNode(cbNode, node.trueType) || - visitNode(cbNode, node.falseType); - }, - [SyntaxKind.InferType]: function forEachChildInInferType(node: InferTypeNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.typeParameter); - }, - [SyntaxKind.ImportType]: function forEachChildInImportType(node: ImportTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.argument) || - visitNode(cbNode, node.attributes) || - visitNode(cbNode, node.qualifier) || - visitNodes(cbNode, cbNodes, node.typeArguments); - }, - [SyntaxKind.ImportTypeAssertionContainer]: function forEachChildInImportTypeAssertionContainer(node: ImportTypeAssertionContainer, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.assertClause); - }, - [SyntaxKind.ParenthesizedType]: forEachChildInParenthesizedTypeOrTypeOperator, - [SyntaxKind.TypeOperator]: forEachChildInParenthesizedTypeOrTypeOperator, - [SyntaxKind.IndexedAccessType]: function forEachChildInIndexedAccessType(node: IndexedAccessTypeNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.objectType) || - visitNode(cbNode, node.indexType); - }, - [SyntaxKind.MappedType]: function forEachChildInMappedType(node: MappedTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.readonlyToken) || - visitNode(cbNode, node.typeParameter) || - visitNode(cbNode, node.nameType) || - visitNode(cbNode, node.questionToken) || - visitNode(cbNode, node.type) || - visitNodes(cbNode, cbNodes, node.members); - }, - [SyntaxKind.LiteralType]: function forEachChildInLiteralType(node: LiteralTypeNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.literal); - }, - [SyntaxKind.NamedTupleMember]: function forEachChildInNamedTupleMember(node: NamedTupleMember, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.dotDotDotToken) || - visitNode(cbNode, node.name) || - visitNode(cbNode, node.questionToken) || - visitNode(cbNode, node.type); - }, - [SyntaxKind.ObjectBindingPattern]: forEachChildInObjectOrArrayBindingPattern, - [SyntaxKind.ArrayBindingPattern]: forEachChildInObjectOrArrayBindingPattern, - [SyntaxKind.ArrayLiteralExpression]: function forEachChildInArrayLiteralExpression(node: ArrayLiteralExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.elements); - }, - [SyntaxKind.ObjectLiteralExpression]: function forEachChildInObjectLiteralExpression(node: ObjectLiteralExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.properties); - }, - [SyntaxKind.PropertyAccessExpression]: function forEachChildInPropertyAccessExpression(node: PropertyAccessExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression) || - visitNode(cbNode, node.questionDotToken) || - visitNode(cbNode, node.name); - }, - [SyntaxKind.ElementAccessExpression]: function forEachChildInElementAccessExpression(node: ElementAccessExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression) || - visitNode(cbNode, node.questionDotToken) || - visitNode(cbNode, node.argumentExpression); - }, - [SyntaxKind.CallExpression]: forEachChildInCallOrNewExpression, - [SyntaxKind.NewExpression]: forEachChildInCallOrNewExpression, - [SyntaxKind.TaggedTemplateExpression]: function forEachChildInTaggedTemplateExpression(node: TaggedTemplateExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tag) || - visitNode(cbNode, node.questionDotToken) || - visitNodes(cbNode, cbNodes, node.typeArguments) || - visitNode(cbNode, node.template); - }, - [SyntaxKind.TypeAssertionExpression]: function forEachChildInTypeAssertionExpression(node: TypeAssertion, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.type) || - visitNode(cbNode, node.expression); - }, - [SyntaxKind.ParenthesizedExpression]: function forEachChildInParenthesizedExpression(node: ParenthesizedExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.DeleteExpression]: function forEachChildInDeleteExpression(node: DeleteExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.TypeOfExpression]: function forEachChildInTypeOfExpression(node: TypeOfExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.VoidExpression]: function forEachChildInVoidExpression(node: VoidExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.PrefixUnaryExpression]: function forEachChildInPrefixUnaryExpression(node: PrefixUnaryExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.operand); - }, - [SyntaxKind.YieldExpression]: function forEachChildInYieldExpression(node: YieldExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.asteriskToken) || - visitNode(cbNode, node.expression); - }, - [SyntaxKind.AwaitExpression]: function forEachChildInAwaitExpression(node: AwaitExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.PostfixUnaryExpression]: function forEachChildInPostfixUnaryExpression(node: PostfixUnaryExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.operand); - }, - [SyntaxKind.BinaryExpression]: function forEachChildInBinaryExpression(node: BinaryExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.left) || - visitNode(cbNode, node.operatorToken) || - visitNode(cbNode, node.right); - }, - [SyntaxKind.AsExpression]: function forEachChildInAsExpression(node: AsExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression) || - visitNode(cbNode, node.type); - }, - [SyntaxKind.NonNullExpression]: function forEachChildInNonNullExpression(node: NonNullExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.SatisfiesExpression]: function forEachChildInSatisfiesExpression(node: SatisfiesExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); - }, - [SyntaxKind.MetaProperty]: function forEachChildInMetaProperty(node: MetaProperty, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.name); - }, - [SyntaxKind.ConditionalExpression]: function forEachChildInConditionalExpression(node: ConditionalExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.condition) || - visitNode(cbNode, node.questionToken) || - visitNode(cbNode, node.whenTrue) || - visitNode(cbNode, node.colonToken) || - visitNode(cbNode, node.whenFalse); - }, - [SyntaxKind.SpreadElement]: function forEachChildInSpreadElement(node: SpreadElement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.Block]: forEachChildInBlock, - [SyntaxKind.ModuleBlock]: forEachChildInBlock, - [SyntaxKind.SourceFile]: function forEachChildInSourceFile(node: SourceFile, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.statements) || - visitNode(cbNode, node.endOfFileToken); - }, - [SyntaxKind.VariableStatement]: function forEachChildInVariableStatement(node: VariableStatement, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.declarationList); - }, - [SyntaxKind.VariableDeclarationList]: function forEachChildInVariableDeclarationList(node: VariableDeclarationList, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.declarations); - }, - [SyntaxKind.ExpressionStatement]: function forEachChildInExpressionStatement(node: ExpressionStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.IfStatement]: function forEachChildInIfStatement(node: IfStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression) || - visitNode(cbNode, node.thenStatement) || - visitNode(cbNode, node.elseStatement); - }, - [SyntaxKind.DoStatement]: function forEachChildInDoStatement(node: DoStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.statement) || - visitNode(cbNode, node.expression); - }, - [SyntaxKind.WhileStatement]: function forEachChildInWhileStatement(node: WhileStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression) || - visitNode(cbNode, node.statement); - }, - [SyntaxKind.ForStatement]: function forEachChildInForStatement(node: ForStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.initializer) || - visitNode(cbNode, node.condition) || - visitNode(cbNode, node.incrementor) || - visitNode(cbNode, node.statement); - }, - [SyntaxKind.ForInStatement]: function forEachChildInForInStatement(node: ForInStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.initializer) || - visitNode(cbNode, node.expression) || - visitNode(cbNode, node.statement); - }, - [SyntaxKind.ForOfStatement]: function forEachChildInForOfStatement(node: ForOfStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.awaitModifier) || - visitNode(cbNode, node.initializer) || - visitNode(cbNode, node.expression) || - visitNode(cbNode, node.statement); - }, - [SyntaxKind.ContinueStatement]: forEachChildInContinueOrBreakStatement, - [SyntaxKind.BreakStatement]: forEachChildInContinueOrBreakStatement, - [SyntaxKind.ReturnStatement]: function forEachChildInReturnStatement(node: ReturnStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.WithStatement]: function forEachChildInWithStatement(node: WithStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression) || - visitNode(cbNode, node.statement); - }, - [SyntaxKind.SwitchStatement]: function forEachChildInSwitchStatement(node: SwitchStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression) || - visitNode(cbNode, node.caseBlock); - }, - [SyntaxKind.CaseBlock]: function forEachChildInCaseBlock(node: CaseBlock, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.clauses); - }, - [SyntaxKind.CaseClause]: function forEachChildInCaseClause(node: CaseClause, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression) || - visitNodes(cbNode, cbNodes, node.statements); - }, - [SyntaxKind.DefaultClause]: function forEachChildInDefaultClause(node: DefaultClause, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.statements); - }, - [SyntaxKind.LabeledStatement]: function forEachChildInLabeledStatement(node: LabeledStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.label) || - visitNode(cbNode, node.statement); - }, - [SyntaxKind.ThrowStatement]: function forEachChildInThrowStatement(node: ThrowStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.TryStatement]: function forEachChildInTryStatement(node: TryStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tryBlock) || - visitNode(cbNode, node.catchClause) || - visitNode(cbNode, node.finallyBlock); - }, - [SyntaxKind.CatchClause]: function forEachChildInCatchClause(node: CatchClause, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.variableDeclaration) || - visitNode(cbNode, node.block); - }, - [SyntaxKind.Decorator]: function forEachChildInDecorator(node: Decorator, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.ClassDeclaration]: forEachChildInClassDeclarationOrExpression, - [SyntaxKind.ClassExpression]: forEachChildInClassDeclarationOrExpression, - [SyntaxKind.InterfaceDeclaration]: function forEachChildInInterfaceDeclaration(node: InterfaceDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.heritageClauses) || - visitNodes(cbNode, cbNodes, node.members); - }, - [SyntaxKind.TypeAliasDeclaration]: function forEachChildInTypeAliasDeclaration(node: TypeAliasDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNode(cbNode, node.type); - }, - [SyntaxKind.EnumDeclaration]: function forEachChildInEnumDeclaration(node: EnumDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNodes(cbNode, cbNodes, node.members); - }, - [SyntaxKind.EnumMember]: function forEachChildInEnumMember(node: EnumMember, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.name) || - visitNode(cbNode, node.initializer); - }, - [SyntaxKind.ModuleDeclaration]: function forEachChildInModuleDeclaration(node: ModuleDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNode(cbNode, node.body); - }, - [SyntaxKind.ImportEqualsDeclaration]: function forEachChildInImportEqualsDeclaration(node: ImportEqualsDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNode(cbNode, node.moduleReference); - }, - [SyntaxKind.ImportDeclaration]: function forEachChildInImportDeclaration(node: ImportDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.importClause) || - visitNode(cbNode, node.moduleSpecifier) || - visitNode(cbNode, node.attributes); - }, - [SyntaxKind.ImportClause]: function forEachChildInImportClause(node: ImportClause, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.name) || - visitNode(cbNode, node.namedBindings); - }, - [SyntaxKind.ImportAttributes]: function forEachChildInImportAttributes(node: ImportAttributes, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.elements); - }, - [SyntaxKind.ImportAttribute]: function forEachChildInImportAttribute(node: ImportAttribute, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.name) || - visitNode(cbNode, node.value); - }, - [SyntaxKind.NamespaceExportDeclaration]: function forEachChildInNamespaceExportDeclaration(node: NamespaceExportDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name); - }, - [SyntaxKind.NamespaceImport]: function forEachChildInNamespaceImport(node: NamespaceImport, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.name); - }, - [SyntaxKind.NamespaceExport]: function forEachChildInNamespaceExport(node: NamespaceExport, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.name); - }, - [SyntaxKind.NamedImports]: forEachChildInNamedImportsOrExports, - [SyntaxKind.NamedExports]: forEachChildInNamedImportsOrExports, - [SyntaxKind.ExportDeclaration]: function forEachChildInExportDeclaration(node: ExportDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.exportClause) || - visitNode(cbNode, node.moduleSpecifier) || - visitNode(cbNode, node.attributes); - }, - [SyntaxKind.ImportSpecifier]: forEachChildInImportOrExportSpecifier, - [SyntaxKind.ExportSpecifier]: forEachChildInImportOrExportSpecifier, - [SyntaxKind.ExportAssignment]: function forEachChildInExportAssignment(node: ExportAssignment, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.expression); - }, - [SyntaxKind.TemplateExpression]: function forEachChildInTemplateExpression(node: TemplateExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.head) || - visitNodes(cbNode, cbNodes, node.templateSpans); - }, - [SyntaxKind.TemplateSpan]: function forEachChildInTemplateSpan(node: TemplateSpan, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression) || - visitNode(cbNode, node.literal); - }, - [SyntaxKind.TemplateLiteralType]: function forEachChildInTemplateLiteralType(node: TemplateLiteralTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.head) || - visitNodes(cbNode, cbNodes, node.templateSpans); - }, - [SyntaxKind.TemplateLiteralTypeSpan]: function forEachChildInTemplateLiteralTypeSpan(node: TemplateLiteralTypeSpan, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.type) || - visitNode(cbNode, node.literal); - }, - [SyntaxKind.ComputedPropertyName]: function forEachChildInComputedPropertyName(node: ComputedPropertyName, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.HeritageClause]: function forEachChildInHeritageClause(node: HeritageClause, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.types); - }, - [SyntaxKind.ExpressionWithTypeArguments]: function forEachChildInExpressionWithTypeArguments(node: ExpressionWithTypeArguments, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression) || - visitNodes(cbNode, cbNodes, node.typeArguments); - }, - [SyntaxKind.ExternalModuleReference]: function forEachChildInExternalModuleReference(node: ExternalModuleReference, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.MissingDeclaration]: function forEachChildInMissingDeclaration(node: MissingDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers); - }, - [SyntaxKind.CommaListExpression]: function forEachChildInCommaListExpression(node: CommaListExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.elements); - }, - [SyntaxKind.JsxElement]: function forEachChildInJsxElement(node: JsxElement, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.openingElement) || - visitNodes(cbNode, cbNodes, node.children) || - visitNode(cbNode, node.closingElement); - }, - [SyntaxKind.JsxFragment]: function forEachChildInJsxFragment(node: JsxFragment, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.openingFragment) || - visitNodes(cbNode, cbNodes, node.children) || - visitNode(cbNode, node.closingFragment); - }, - [SyntaxKind.JsxSelfClosingElement]: forEachChildInJsxOpeningOrSelfClosingElement, - [SyntaxKind.JsxOpeningElement]: forEachChildInJsxOpeningOrSelfClosingElement, - [SyntaxKind.JsxAttributes]: function forEachChildInJsxAttributes(node: JsxAttributes, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.properties); - }, - [SyntaxKind.JsxAttribute]: function forEachChildInJsxAttribute(node: JsxAttribute, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.name) || - visitNode(cbNode, node.initializer); - }, - [SyntaxKind.JsxSpreadAttribute]: function forEachChildInJsxSpreadAttribute(node: JsxSpreadAttribute, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); - }, - [SyntaxKind.JsxExpression]: function forEachChildInJsxExpression(node: JsxExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.dotDotDotToken) || - visitNode(cbNode, node.expression); - }, - [SyntaxKind.JsxClosingElement]: function forEachChildInJsxClosingElement(node: JsxClosingElement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName); - }, - [SyntaxKind.JsxNamespacedName]: function forEachChildInJsxNamespacedName(node: JsxNamespacedName, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.namespace) || - visitNode(cbNode, node.name); - }, - [SyntaxKind.OptionalType]: forEachChildInOptionalRestOrJSDocParameterModifier, - [SyntaxKind.RestType]: forEachChildInOptionalRestOrJSDocParameterModifier, - [SyntaxKind.JSDocTypeExpression]: forEachChildInOptionalRestOrJSDocParameterModifier, - [SyntaxKind.JSDocNonNullableType]: forEachChildInOptionalRestOrJSDocParameterModifier, - [SyntaxKind.JSDocNullableType]: forEachChildInOptionalRestOrJSDocParameterModifier, - [SyntaxKind.JSDocOptionalType]: forEachChildInOptionalRestOrJSDocParameterModifier, - [SyntaxKind.JSDocVariadicType]: forEachChildInOptionalRestOrJSDocParameterModifier, - [SyntaxKind.JSDocFunctionType]: function forEachChildInJSDocFunctionType(node: JSDocFunctionType, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type); - }, - [SyntaxKind.JSDoc]: function forEachChildInJSDoc(node: JSDoc, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)) - || visitNodes(cbNode, cbNodes, node.tags); - }, - [SyntaxKind.JSDocSeeTag]: function forEachChildInJSDocSeeTag(node: JSDocSeeTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName) || - visitNode(cbNode, node.name) || - (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); - }, - [SyntaxKind.JSDocNameReference]: function forEachChildInJSDocNameReference(node: JSDocNameReference, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.name); - }, - [SyntaxKind.JSDocMemberName]: function forEachChildInJSDocMemberName(node: JSDocMemberName, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.left) || - visitNode(cbNode, node.right); - }, - [SyntaxKind.JSDocParameterTag]: forEachChildInJSDocParameterOrPropertyTag, - [SyntaxKind.JSDocPropertyTag]: forEachChildInJSDocParameterOrPropertyTag, - [SyntaxKind.JSDocAuthorTag]: function forEachChildInJSDocAuthorTag(node: JSDocAuthorTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName) || - (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); - }, - [SyntaxKind.JSDocImplementsTag]: function forEachChildInJSDocImplementsTag(node: JSDocImplementsTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName) || - visitNode(cbNode, node.class) || - (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); - }, - [SyntaxKind.JSDocAugmentsTag]: function forEachChildInJSDocAugmentsTag(node: JSDocAugmentsTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName) || - visitNode(cbNode, node.class) || - (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); - }, - [SyntaxKind.JSDocTemplateTag]: function forEachChildInJSDocTemplateTag(node: JSDocTemplateTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName) || - visitNode(cbNode, node.constraint) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); - }, - [SyntaxKind.JSDocTypedefTag]: function forEachChildInJSDocTypedefTag(node: JSDocTypedefTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName) || - (node.typeExpression && - node.typeExpression.kind === SyntaxKind.JSDocTypeExpression - ? visitNode(cbNode, node.typeExpression) || - visitNode(cbNode, node.fullName) || - (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)) - : visitNode(cbNode, node.fullName) || - visitNode(cbNode, node.typeExpression) || - (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment))); - }, - [SyntaxKind.JSDocCallbackTag]: function forEachChildInJSDocCallbackTag(node: JSDocCallbackTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName) || - visitNode(cbNode, node.fullName) || - visitNode(cbNode, node.typeExpression) || - (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); - }, - [SyntaxKind.JSDocReturnTag]: forEachChildInJSDocTypeLikeTag, - [SyntaxKind.JSDocTypeTag]: forEachChildInJSDocTypeLikeTag, - [SyntaxKind.JSDocThisTag]: forEachChildInJSDocTypeLikeTag, - [SyntaxKind.JSDocEnumTag]: forEachChildInJSDocTypeLikeTag, - [SyntaxKind.JSDocSatisfiesTag]: forEachChildInJSDocTypeLikeTag, - [SyntaxKind.JSDocThrowsTag]: forEachChildInJSDocTypeLikeTag, - [SyntaxKind.JSDocOverloadTag]: forEachChildInJSDocTypeLikeTag, - [SyntaxKind.JSDocSignature]: function forEachChildInJSDocSignature(node: JSDocSignature, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return forEach(node.typeParameters, cbNode) || - forEach(node.parameters, cbNode) || - visitNode(cbNode, node.type); - }, - [SyntaxKind.JSDocLink]: forEachChildInJSDocLinkCodeOrPlain, - [SyntaxKind.JSDocLinkCode]: forEachChildInJSDocLinkCodeOrPlain, - [SyntaxKind.JSDocLinkPlain]: forEachChildInJSDocLinkCodeOrPlain, - [SyntaxKind.JSDocTypeLiteral]: function forEachChildInJSDocTypeLiteral(node: JSDocTypeLiteral, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return forEach(node.jsDocPropertyTags, cbNode); - }, - [SyntaxKind.JSDocTag]: forEachChildInJSDocTag, - [SyntaxKind.JSDocClassTag]: forEachChildInJSDocTag, - [SyntaxKind.JSDocPublicTag]: forEachChildInJSDocTag, - [SyntaxKind.JSDocPrivateTag]: forEachChildInJSDocTag, - [SyntaxKind.JSDocProtectedTag]: forEachChildInJSDocTag, - [SyntaxKind.JSDocReadonlyTag]: forEachChildInJSDocTag, - [SyntaxKind.JSDocDeprecatedTag]: forEachChildInJSDocTag, - [SyntaxKind.JSDocOverrideTag]: forEachChildInJSDocTag, - [SyntaxKind.JSDocImportTag]: forEachChildInJSDocImportTag, - [SyntaxKind.PartiallyEmittedExpression]: forEachChildInPartiallyEmittedExpression, -}; - -// shared - -function forEachChildInCallOrConstructSignature(node: CallSignatureDeclaration | ConstructSignatureDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.parameters) || - visitNode(cbNode, node.type); -} - -function forEachChildInUnionOrIntersectionType(node: UnionTypeNode | IntersectionTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.types); -} - -function forEachChildInParenthesizedTypeOrTypeOperator(node: ParenthesizedTypeNode | TypeOperatorNode, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.type); -} - -function forEachChildInObjectOrArrayBindingPattern(node: BindingPattern, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.elements); -} - -function forEachChildInCallOrNewExpression(node: CallExpression | NewExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression) || - // TODO: should we separate these branches out? - visitNode(cbNode, (node as CallExpression).questionDotToken) || - visitNodes(cbNode, cbNodes, node.typeArguments) || - visitNodes(cbNode, cbNodes, node.arguments); -} - -function forEachChildInBlock(node: Block | ModuleBlock, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.statements); -} - -function forEachChildInContinueOrBreakStatement(node: ContinueStatement | BreakStatement, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.label); -} - -function forEachChildInClassDeclarationOrExpression(node: ClassDeclaration | ClassExpression, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNodes(cbNode, cbNodes, node.typeParameters) || - visitNodes(cbNode, cbNodes, node.heritageClauses) || - visitNodes(cbNode, cbNodes, node.members); -} - -function forEachChildInNamedImportsOrExports(node: NamedImports | NamedExports, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNodes(cbNode, cbNodes, node.elements); -} - -function forEachChildInImportOrExportSpecifier(node: ImportSpecifier | ExportSpecifier, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.propertyName) || - visitNode(cbNode, node.name); -} - -function forEachChildInJsxOpeningOrSelfClosingElement(node: JsxOpeningLikeElement, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName) || - visitNodes(cbNode, cbNodes, node.typeArguments) || - visitNode(cbNode, node.attributes); -} - -function forEachChildInOptionalRestOrJSDocParameterModifier(node: OptionalTypeNode | RestTypeNode | JSDocTypeExpression | JSDocNullableType | JSDocNonNullableType | JSDocOptionalType | JSDocVariadicType, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.type); -} - -function forEachChildInJSDocParameterOrPropertyTag(node: JSDocParameterTag | JSDocPropertyTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName) || - (node.isNameFirst - ? visitNode(cbNode, node.name) || visitNode(cbNode, node.typeExpression) - : visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.name)) || - (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); -} - -function forEachChildInJSDocTypeLikeTag(node: JSDocReturnTag | JSDocTypeTag | JSDocThisTag | JSDocEnumTag | JSDocThrowsTag | JSDocOverloadTag | JSDocSatisfiesTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName) || - visitNode(cbNode, node.typeExpression) || - (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); -} - -function forEachChildInJSDocLinkCodeOrPlain(node: JSDocLink | JSDocLinkCode | JSDocLinkPlain, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.name); -} - -function forEachChildInJSDocTag(node: JSDocUnknownTag | JSDocClassTag | JSDocPublicTag | JSDocPrivateTag | JSDocProtectedTag | JSDocReadonlyTag | JSDocDeprecatedTag | JSDocOverrideTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName) - || (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); -} - -function forEachChildInJSDocImportTag(node: JSDocImportTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.tagName) - || visitNode(cbNode, node.importClause) - || visitNode(cbNode, node.moduleSpecifier) - || visitNode(cbNode, node.attributes) - || (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); -} - -function forEachChildInPartiallyEmittedExpression(node: PartiallyEmittedExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - return visitNode(cbNode, node.expression); -} - -/** - * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes - * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, - * embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns - * a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. - * - * @param node a given node to visit its children - * @param cbNode a callback to be invoked for all child nodes - * @param cbNodes a callback to be invoked for embedded array - * - * @remarks `forEachChild` must visit the children of a node in the order - * that they appear in the source code. The language service depends on this property to locate nodes by position. - */ -export function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { - if (node === undefined || node.kind <= SyntaxKind.LastToken) { - return; - } - const fn = (forEachChildTable as Record>)[node.kind]; - return fn === undefined ? undefined : fn(node, cbNode, cbNodes); -} - -/** - * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes - * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; additionally, - * unlike `forEachChild`, embedded arrays are flattened and the 'cbNode' callback is invoked for each element. - * If a callback returns a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. - * - * @param node a given node to visit its children - * @param cbNode a callback to be invoked for all child nodes - * @param cbNodes a callback to be invoked for embedded array - * - * @remarks Unlike `forEachChild`, `forEachChildRecursively` handles recursively invoking the traversal on each child node found, - * and while doing so, handles traversing the structure without relying on the callstack to encode the tree structure. - * - * @internal - */ -export function forEachChildRecursively(rootNode: Node, cbNode: (node: Node, parent: Node) => T | "skip" | undefined, cbNodes?: (nodes: NodeArray, parent: Node) => T | "skip" | undefined): T | undefined { - const queue: (Node | NodeArray)[] = gatherPossibleChildren(rootNode); - const parents: Node[] = []; // tracks parent references for elements in queue - while (parents.length < queue.length) { - parents.push(rootNode); - } - while (queue.length !== 0) { - const current = queue.pop()!; - const parent = parents.pop()!; - if (isArray(current)) { - if (cbNodes) { - const res = cbNodes(current, parent); - if (res) { - if (res === "skip") continue; - return res; - } - } - for (let i = current.length - 1; i >= 0; --i) { - queue.push(current[i]); - parents.push(parent); - } - } - else { - const res = cbNode(current, parent); - if (res) { - if (res === "skip") continue; - return res; - } - if (current.kind >= SyntaxKind.FirstNode) { - // add children in reverse order to the queue, so popping gives the first child - for (const child of gatherPossibleChildren(current)) { - queue.push(child); - parents.push(current); - } - } - } - } -} - -function gatherPossibleChildren(node: Node) { - const children: (Node | NodeArray)[] = []; - forEachChild(node, addWorkItem, addWorkItem); // By using a stack above and `unshift` here, we emulate a depth-first preorder traversal - return children; - - function addWorkItem(n: Node | NodeArray) { - children.unshift(n); - } -} - export interface CreateSourceFileOptions { languageVersion: ScriptTarget; /** @@ -1321,7 +458,7 @@ function setExternalModuleIndicator(sourceFile: SourceFile) { export function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes = false, scriptKind?: ScriptKind): SourceFile { tracing?.push(tracing.Phase.Parse, "createSourceFile", { path: fileName }, /*separateBeginAndEnd*/ true); performance.mark("beforeParse"); - let result: SourceFile; + let result: AstSourceFile; const { languageVersion, @@ -1343,7 +480,7 @@ export function createSourceFile(fileName: string, sourceText: string, languageV performance.mark("afterParse"); performance.measure("Parse", "beforeParse", "afterParse"); tracing?.pop(); - return result; + return result.node; } export function parseIsolatedEntityName(text: string, languageVersion: ScriptTarget): EntityName | undefined { @@ -1356,7 +493,7 @@ export function parseIsolatedEntityName(text: string, languageVersion: ScriptTar * @param sourceText */ export function parseJsonText(fileName: string, sourceText: string): JsonSourceFile { - return Parser.parseJsonText(fileName, sourceText); + return Parser.parseJsonText(fileName, sourceText).node; } // See also `isExternalOrCommonJsModule` in utilities.ts @@ -1374,11 +511,11 @@ export function isExternalModule(file: SourceFile): boolean { // becoming detached from any SourceFile). It is recommended that this SourceFile not // be used once 'update' is called on it. export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks = false): SourceFile { - const newSourceFile = IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); + const newSourceFile = IncrementalParser.updateSourceFile((sourceFile as AstSourceFile["node"]).ast, newText, textChangeRange, aggressiveChecks); // Because new source file node is created, it may not have the flag PossiblyContainDynamicImport. This is the case if there is no new edit to add dynamic import. // We will manually port the flag to the new source file. - (newSourceFile as Mutable).flags |= sourceFile.flags & NodeFlags.PermanentlySetIncrementalFlags; - return newSourceFile; + newSourceFile.flags |= sourceFile.flags & NodeFlags.PermanentlySetIncrementalFlags; + return newSourceFile.node; } /** @internal */ @@ -1393,7 +530,7 @@ export function parseIsolatedJSDocComment(content: string, start?: number, lengt if (result && result.jsDoc) { // because the jsDocComment was parsed out of the source file, it might // not be covered by the fixupParentReferences. - Parser.fixupParentReferences(result.jsDoc); + Parser.fixupParentReferences((result.jsDoc as AstJSDocNode["node"]).ast); } return result; @@ -1422,7 +559,7 @@ namespace Parser { var disallowInAndDecoratorContext = NodeFlags.DisallowInContext | NodeFlags.DecoratorContext; - var factory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules | NodeFactoryFlags.NoNodeConverters | NodeFactoryFlags.NoOriginalNode, _ => { + var factory = createAstNodeFactory(NodeFactoryFlags.NoParenthesizerRules | NodeFactoryFlags.NoNodeConverters | NodeFactoryFlags.NoOriginalNode, _ => { nodeCount++; }); @@ -1556,7 +693,7 @@ namespace Parser { // attached to the EOF token. var parseErrorBeforeNextFinishedNode = false; - var missingLists: Set>; + var missingLists: Set>; /* eslint-enable no-var */ export function parseSourceFile( @@ -1568,17 +705,17 @@ namespace Parser { scriptKind?: ScriptKind, setExternalModuleIndicatorOverride?: (file: SourceFile) => void, jsDocParsingMode = JSDocParsingMode.ParseAll, - ): SourceFile { + ): AstSourceFile { scriptKind = ensureScriptKind(fileName, scriptKind); if (scriptKind === ScriptKind.JSON) { const result = parseJsonText(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes); - convertToJson(result, result.statements[0]?.expression, result.parseDiagnostics, /*returnValue*/ false, /*jsonConversionNotifier*/ undefined); - result.referencedFiles = emptyArray; - result.typeReferenceDirectives = emptyArray; - result.libReferenceDirectives = emptyArray; - result.amdDependencies = emptyArray; - result.hasNoDefaultLib = false; - result.pragmas = emptyMap as ReadonlyPragmaMap; + convertToJson(result.node, result.data.statements.items[0]?.data.expression.node, result.data.parseDiagnostics, /*returnValue*/ false, /*jsonConversionNotifier*/ undefined); + result.data.referencedFiles = emptyArray; + result.data.typeReferenceDirectives = emptyArray; + result.data.libReferenceDirectives = emptyArray; + result.data.amdDependencies = emptyArray; + result.data.hasNoDefaultLib = false; + result.data.pragmas = emptyMap as ReadonlyPragmaMap; return result; } @@ -1599,10 +736,10 @@ namespace Parser { const entityName = parseEntityName(/*allowReservedWords*/ true); const isValid = token() === SyntaxKind.EndOfFileToken && !parseDiagnostics.length; clearState(); - return isValid ? entityName : undefined; + return isValid ? entityName.node : undefined; } - export function parseJsonText(fileName: string, sourceText: string, languageVersion: ScriptTarget = ScriptTarget.ES2015, syntaxCursor?: IncrementalParser.SyntaxCursor, setParentNodes = false): JsonSourceFile { + export function parseJsonText(fileName: string, sourceText: string, languageVersion: ScriptTarget = ScriptTarget.ES2015, syntaxCursor?: IncrementalParser.SyntaxCursor, setParentNodes = false): AstJsonSourceFile { initializeState(fileName, sourceText, languageVersion, syntaxCursor, ScriptKind.JSON, JSDocParsingMode.ParseAll); sourceFlags = contextFlags; @@ -1611,13 +748,13 @@ namespace Parser { const pos = getNodePos(); let statements, endOfFileToken; if (token() === SyntaxKind.EndOfFileToken) { - statements = createNodeArray([], pos, pos); - endOfFileToken = parseTokenNode(); + statements = createNodeArray([], pos, pos); + endOfFileToken = parseTokenNode(); } else { // Loop and synthesize an ArrayLiteralExpression if there are more than // one top-level expressions to ensure all input text is consumed. - let expressions: Expression[] | Expression | undefined; + let expressions: AstExpression[] | AstExpression | undefined; while (token() !== SyntaxKind.EndOfFileToken) { let expression; switch (token()) { @@ -1627,11 +764,11 @@ namespace Parser { case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: case SyntaxKind.NullKeyword: - expression = parseTokenNode(); + expression = parseTokenNode(); break; case SyntaxKind.MinusToken: if (lookAhead(() => nextToken() === SyntaxKind.NumericLiteral && nextToken() !== SyntaxKind.ColonToken)) { - expression = parsePrefixUnaryExpression() as JsonMinusNumericLiteral; + expression = parsePrefixUnaryExpression() as AstJsonMinusNumericLiteral; } else { expression = parseObjectLiteralExpression(); @@ -1640,7 +777,7 @@ namespace Parser { case SyntaxKind.NumericLiteral: case SyntaxKind.StringLiteral: if (lookAhead(() => nextToken() !== SyntaxKind.ColonToken)) { - expression = parseLiteralNode() as StringLiteral | NumericLiteral; + expression = parseLiteralNode() as AstStringLiteral | AstNumericLiteral; break; } // falls through @@ -1665,10 +802,10 @@ namespace Parser { } const expression = isArray(expressions) ? finishNode(factoryCreateArrayLiteralExpression(expressions), pos) : Debug.checkDefined(expressions); - const statement = factoryCreateExpressionStatement(expression) as JsonObjectExpressionStatement; + const statement = factoryCreateExpressionStatement(expression) as AstJsonObjectExpressionStatement; finishNode(statement, pos); statements = createNodeArray([statement], pos); - endOfFileToken = parseExpectedToken(SyntaxKind.EndOfFileToken, Diagnostics.Unexpected_token) as EndOfFileToken; + endOfFileToken = parseExpectedToken(SyntaxKind.EndOfFileToken, Diagnostics.Unexpected_token) as AstEndOfFileToken; } // Set source file so that errors will be reported with this file name @@ -1678,15 +815,15 @@ namespace Parser { fixupParentReferences(sourceFile); } - sourceFile.nodeCount = nodeCount; - sourceFile.identifierCount = identifierCount; - sourceFile.identifiers = identifiers; - sourceFile.parseDiagnostics = attachFileToDiagnostics(parseDiagnostics, sourceFile); + sourceFile.data.nodeCount = nodeCount; + sourceFile.data.identifierCount = identifierCount; + sourceFile.data.identifiers = identifiers; + sourceFile.data.parseDiagnostics = attachFileToDiagnostics(parseDiagnostics, sourceFile.node); // TODO(rbuckton): do not instantiate node if (jsDocDiagnostics) { - sourceFile.jsDocDiagnostics = attachFileToDiagnostics(jsDocDiagnostics, sourceFile); + sourceFile.data.jsDocDiagnostics = attachFileToDiagnostics(jsDocDiagnostics, sourceFile.node); // TODO(rbuckton): do not instantiate node } - const result = sourceFile as JsonSourceFile; + const result = sourceFile as AstJsonSourceFile; clearState(); return result; } @@ -1755,7 +892,7 @@ namespace Parser { topLevel = true; } - function parseSourceFileWorker(languageVersion: ScriptTarget, setParentNodes: boolean, scriptKind: ScriptKind, setExternalModuleIndicator: (file: SourceFile) => void, jsDocParsingMode: JSDocParsingMode): SourceFile { + function parseSourceFileWorker(languageVersion: ScriptTarget, setParentNodes: boolean, scriptKind: ScriptKind, setExternalModuleIndicator: (file: SourceFile) => void, jsDocParsingMode: JSDocParsingMode): AstSourceFile { const isDeclarationFile = isDeclarationFileName(fileName); if (isDeclarationFile) { contextFlags |= NodeFlags.Ambient; @@ -1769,22 +906,22 @@ namespace Parser { const statements = parseList(ParsingContext.SourceElements, parseStatement); Debug.assert(token() === SyntaxKind.EndOfFileToken); const endHasJSDoc = hasPrecedingJSDocComment(); - const endOfFileToken = withJSDoc(parseTokenNode(), endHasJSDoc); + const endOfFileToken = withJSDoc(parseTokenNode(), endHasJSDoc); const sourceFile = createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, sourceFlags, setExternalModuleIndicator); // A member of ReadonlyArray isn't assignable to a member of T[] (and prevents a direct cast) - but this is where we set up those members so they can be readonly in the future - processCommentPragmas(sourceFile as {} as PragmaContext, sourceText); - processPragmasIntoFields(sourceFile as {} as PragmaContext, reportPragmaDiagnostic); - - sourceFile.commentDirectives = scanner.getCommentDirectives(); - sourceFile.nodeCount = nodeCount; - sourceFile.identifierCount = identifierCount; - sourceFile.identifiers = identifiers; - sourceFile.parseDiagnostics = attachFileToDiagnostics(parseDiagnostics, sourceFile); - sourceFile.jsDocParsingMode = jsDocParsingMode; + processCommentPragmas(sourceFile.data as {} as PragmaContext, sourceText); + processPragmasIntoFields(sourceFile.data as {} as PragmaContext, reportPragmaDiagnostic); + + sourceFile.data.commentDirectives = scanner.getCommentDirectives(); + sourceFile.data.nodeCount = nodeCount; + sourceFile.data.identifierCount = identifierCount; + sourceFile.data.identifiers = identifiers; + sourceFile.data.parseDiagnostics = attachFileToDiagnostics(parseDiagnostics, sourceFile.node); // TODO(rbuckton): do not instantiate node + sourceFile.data.jsDocParsingMode = jsDocParsingMode; if (jsDocDiagnostics) { - sourceFile.jsDocDiagnostics = attachFileToDiagnostics(jsDocDiagnostics, sourceFile); + sourceFile.data.jsDocDiagnostics = attachFileToDiagnostics(jsDocDiagnostics, sourceFile.node); // TODO(rbuckton): do not instantiate node } if (setParentNodes) { @@ -1799,14 +936,14 @@ namespace Parser { } let hasDeprecatedTag = false; - function withJSDoc(node: T, hasJSDoc: boolean): T { + function withJSDoc(node: T, hasJSDoc: boolean): T { if (!hasJSDoc) { return node; } - Debug.assert(!node.jsDoc); // Should only be called once per node - const jsDoc = mapDefined(getJSDocCommentRanges(node, sourceText), comment => JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos)); - if (jsDoc.length) node.jsDoc = jsDoc; + Debug.assert(!node.data.jsDoc); // Should only be called once per node + const jsDoc = mapDefined(getJSDocCommentRanges(node, sourceText), comment => JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos)?.node); // TODO(rbuckton): do not instantiate .node + if (jsDoc.length) node.data.jsDoc = jsDoc; if (hasDeprecatedTag) { hasDeprecatedTag = false; (node as Mutable).flags |= NodeFlags.Deprecated; @@ -1814,24 +951,24 @@ namespace Parser { return node; } - function reparseTopLevelAwait(sourceFile: SourceFile) { + function reparseTopLevelAwait(sourceFile: AstSourceFile) { const savedSyntaxCursor = syntaxCursor; const baseSyntaxCursor = IncrementalParser.createSyntaxCursor(sourceFile); syntaxCursor = { currentNode }; - const statements: Statement[] = []; + const statements: AstStatement[] = []; const savedParseDiagnostics = parseDiagnostics; parseDiagnostics = []; let pos = 0; - let start = findNextStatementWithAwait(sourceFile.statements, 0); + let start = findNextStatementWithAwait(sourceFile.data.statements, 0); while (start !== -1) { // append all statements between pos and start - const prevStatement = sourceFile.statements[pos]; - const nextStatement = sourceFile.statements[start]; - addRange(statements, sourceFile.statements, pos, start); - pos = findNextStatementWithoutAwait(sourceFile.statements, start); + const prevStatement = sourceFile.data.statements.items[pos]; + const nextStatement = sourceFile.data.statements.items[start]; + addRange(statements, sourceFile.data.statements.items, pos, start); + pos = findNextStatementWithoutAwait(sourceFile.data.statements, start); // append all diagnostics associated with the copied range const diagnosticStart = findIndex(savedParseDiagnostics, diagnostic => diagnostic.start >= prevStatement.pos); @@ -1856,14 +993,14 @@ namespace Parser { } if (pos >= 0) { - const nonAwaitStatement = sourceFile.statements[pos]; + const nonAwaitStatement = sourceFile.data.statements.items[pos]; if (statement.end === nonAwaitStatement.pos) { // done reparsing this section break; } if (statement.end > nonAwaitStatement.pos) { // we ate into the next statement, so we must reparse it. - pos = findNextStatementWithoutAwait(sourceFile.statements, pos + 1); + pos = findNextStatementWithoutAwait(sourceFile.data.statements, pos + 1); } } } @@ -1872,13 +1009,13 @@ namespace Parser { }, SpeculationKind.Reparse); // find the next statement containing an `await` - start = pos >= 0 ? findNextStatementWithAwait(sourceFile.statements, pos) : -1; + start = pos >= 0 ? findNextStatementWithAwait(sourceFile.data.statements, pos) : -1; } // append all statements between pos and the end of the list if (pos >= 0) { - const prevStatement = sourceFile.statements[pos]; - addRange(statements, sourceFile.statements, pos); + const prevStatement = sourceFile.data.statements.items[pos]; + addRange(statements, sourceFile.data.statements.items, pos); // append all diagnostics associated with the copied range const diagnosticStart = findIndex(savedParseDiagnostics, diagnostic => diagnostic.start >= prevStatement.pos); @@ -1888,25 +1025,25 @@ namespace Parser { } syntaxCursor = savedSyntaxCursor; - return factory.updateSourceFile(sourceFile, setTextRange(factoryCreateNodeArray(statements), sourceFile.statements)); + return factory.updateSourceFile(sourceFile, setTextRange(factoryCreateNodeArray(statements), sourceFile.data.statements)); - function containsPossibleTopLevelAwait(node: Node) { + function containsPossibleTopLevelAwait(node: AstNode) { return !(node.flags & NodeFlags.AwaitContext) && !!(node.transformFlags & TransformFlags.ContainsPossibleTopLevelAwait); } - function findNextStatementWithAwait(statements: NodeArray, start: number) { - for (let i = start; i < statements.length; i++) { - if (containsPossibleTopLevelAwait(statements[i])) { + function findNextStatementWithAwait(statements: AstNodeArray, start: number) { + for (let i = start; i < statements.items.length; i++) { + if (containsPossibleTopLevelAwait(statements.items[i])) { return i; } } return -1; } - function findNextStatementWithoutAwait(statements: NodeArray, start: number) { - for (let i = start; i < statements.length; i++) { - if (!containsPossibleTopLevelAwait(statements[i])) { + function findNextStatementWithoutAwait(statements: AstNodeArray, start: number) { + for (let i = start; i < statements.items.length; i++) { + if (!containsPossibleTopLevelAwait(statements.items[i])) { return i; } } @@ -1922,12 +1059,12 @@ namespace Parser { } } - export function fixupParentReferences(rootNode: Node) { + export function fixupParentReferences(rootNode: AstNode) { // normally parent references are set during binding. However, for clients that only need // a syntax tree, and no semantic features, then the binding process is an unnecessary // overhead. This functions allows us to set all the parents, without all the expense of // binding. - setParentRecursive(rootNode, /*incremental*/ true); + setParentRecursive(rootNode.node, /*incremental*/ true); // TODO: do not instantiate node } function createSourceFile( @@ -1935,11 +1072,11 @@ namespace Parser { languageVersion: ScriptTarget, scriptKind: ScriptKind, isDeclarationFile: boolean, - statements: readonly Statement[], - endOfFileToken: EndOfFileToken, + statements: AstNodeArrayLike, + endOfFileToken: AstEndOfFileToken, flags: NodeFlags, setExternalModuleIndicator: (sourceFile: SourceFile) => void, - ): SourceFile { + ): AstSourceFile { // code from createNode is inlined here so createNode won't have to deal with special case of creating source files // this is quite rare comparing to other nodes and createNode should be as fast as possible let sourceFile = factory.createSourceFile(statements, endOfFileToken, flags); @@ -1947,7 +1084,7 @@ namespace Parser { setFields(sourceFile); // If we parsed this as an external module, it may contain top-level await - if (!isDeclarationFile && isExternalModule(sourceFile) && sourceFile.transformFlags & TransformFlags.ContainsPossibleTopLevelAwait) { + if (!isDeclarationFile && isExternalModule(sourceFile.node) && sourceFile.transformFlags & TransformFlags.ContainsPossibleTopLevelAwait) { const oldSourceFile = sourceFile; sourceFile = reparseTopLevelAwait(sourceFile); if (oldSourceFile !== sourceFile) setFields(sourceFile); @@ -1955,18 +1092,18 @@ namespace Parser { return sourceFile; - function setFields(sourceFile: SourceFile) { - sourceFile.text = sourceText; - sourceFile.bindDiagnostics = []; - sourceFile.bindSuggestionDiagnostics = undefined; - sourceFile.languageVersion = languageVersion; - sourceFile.fileName = fileName; - sourceFile.languageVariant = getLanguageVariant(scriptKind); - sourceFile.isDeclarationFile = isDeclarationFile; - sourceFile.scriptKind = scriptKind; + function setFields(sourceFile: AstSourceFile) { + sourceFile.data.text = sourceText; + sourceFile.data.bindDiagnostics = []; + sourceFile.data.bindSuggestionDiagnostics = undefined; + sourceFile.data.languageVersion = languageVersion; + sourceFile.data.fileName = fileName; + sourceFile.data.languageVariant = getLanguageVariant(scriptKind); + sourceFile.data.isDeclarationFile = isDeclarationFile; + sourceFile.data.scriptKind = scriptKind; - setExternalModuleIndicator(sourceFile); - sourceFile.setExternalModuleIndicator = setExternalModuleIndicator; + setExternalModuleIndicator(sourceFile.node); + sourceFile.data.setExternalModuleIndicator = setExternalModuleIndicator; } } @@ -2316,17 +1453,17 @@ namespace Parser { * * @param node Node preceding the expected semicolon location. */ - function parseErrorForMissingSemicolonAfter(node: Expression | PropertyName): void { + function parseErrorForMissingSemicolonAfter(node: AstExpression | AstPropertyName): void { // Tagged template literals are sometimes used in places where only simple strings are allowed, i.e.: // module `M1` { // ^^^^^^^^^^^ This block is parsed as a template literal like module`M1`. - if (isTaggedTemplateExpression(node)) { - parseErrorAt(skipTrivia(sourceText, node.template.pos), node.template.end, Diagnostics.Module_declaration_names_may_only_use_or_quoted_strings); + if (isAstTaggedTemplateExpression(node)) { + parseErrorAt(skipTrivia(sourceText, node.data.template.pos), node.data.template.end, Diagnostics.Module_declaration_names_may_only_use_or_quoted_strings); return; } // Otherwise, if this isn't a well-known keyword-like identifier, give the generic fallback message. - const expressionText = isIdentifierNode(node) ? idText(node) : undefined; + const expressionText = isAstIdentifier(node) ? unescapeLeadingUnderscores(node.data.escapedText) : undefined; if (!expressionText || !isIdentifierText(expressionText, languageVersion)) { parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(SyntaxKind.SemicolonToken)); return; @@ -2406,7 +1543,7 @@ namespace Parser { return undefined; } - function parseSemicolonAfterPropertyName(name: PropertyName, type: TypeNode | undefined, initializer: Expression | undefined) { + function parseSemicolonAfterPropertyName(name: AstPropertyName, type: AstTypeNode | undefined, initializer: AstExpression | undefined) { if (token() === SyntaxKind.AtToken && !scanner.hasPrecedingLineBreak()) { parseErrorAtCurrentToken(Diagnostics.Decorators_must_precede_the_name_and_all_keywords_of_property_declarations); return; @@ -2475,48 +1612,50 @@ namespace Parser { return false; } - function parseOptionalToken(t: TKind): Token; - function parseOptionalToken(t: SyntaxKind): Node | undefined { + function parseOptionalToken(t: TKind): AstToken; + function parseOptionalToken(t: TokenSyntaxKind): AstNode | undefined { if (token() === t) { return parseTokenNode(); } return undefined; } - function parseOptionalTokenJSDoc(t: TKind): Token; - function parseOptionalTokenJSDoc(t: JSDocSyntaxKind): Node | undefined { + function parseOptionalTokenJSDoc(t: TKind): AstToken; + function parseOptionalTokenJSDoc(t: JSDocSyntaxKind): AstNode | undefined { if (token() === t) { return parseTokenNodeJSDoc(); } return undefined; } - function parseExpectedToken(t: TKind, diagnosticMessage?: DiagnosticMessage, arg0?: string): Token; - function parseExpectedToken(t: SyntaxKind, diagnosticMessage?: DiagnosticMessage, arg0?: string): Node { + function parseExpectedToken(t: TKind, diagnosticMessage?: DiagnosticMessage, arg0?: string): AstToken; + function parseExpectedToken(t: TokenSyntaxKind, diagnosticMessage?: DiagnosticMessage, arg0?: string): AstToken { return parseOptionalToken(t) || createMissingNode(t, /*reportAtCurrentPosition*/ false, diagnosticMessage || Diagnostics._0_expected, arg0 || tokenToString(t)!); } - function parseExpectedTokenJSDoc(t: TKind): Token; - function parseExpectedTokenJSDoc(t: JSDocSyntaxKind): Node { + function parseExpectedTokenJSDoc(t: TKind): AstToken; + function parseExpectedTokenJSDoc(t: JSDocSyntaxKind): AstNode { const optional = parseOptionalTokenJSDoc(t); if (optional) return optional; Debug.assert(isKeywordOrPunctuation(t)); return createMissingNode(t, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(t)); } - function parseTokenNode(): T { + function parseTokenNode(): T { const pos = getNodePos(); const kind = token(); nextToken(); - return finishNode(factoryCreateToken(kind), pos) as T; + // TODO(rbuckton): verify assertion + return finishNode(factoryCreateToken(kind as TokenSyntaxKind), pos) as T; } - function parseTokenNodeJSDoc(): T { + function parseTokenNodeJSDoc(): T { const pos = getNodePos(); const kind = token(); nextTokenJSDoc(); - return finishNode(factoryCreateToken(kind), pos) as T; + // TODO(rbuckton): verify assertion + return finishNode(factoryCreateToken(kind as TokenSyntaxKind), pos) as T; } function canParseSemicolon() { @@ -2546,13 +1685,13 @@ namespace Parser { return tryParseSemicolon() || parseExpected(SyntaxKind.SemicolonToken); } - function createNodeArray(elements: T[], pos: number, end?: number, hasTrailingComma?: boolean): NodeArray { + function createNodeArray(elements: T[], pos: number, end?: number, hasTrailingComma?: boolean): AstNodeArray { const array = factoryCreateNodeArray(elements, hasTrailingComma); setTextRangePosEnd(array, pos, end ?? scanner.getTokenFullStart()); return array; } - function finishNode(node: T, pos: number, end?: number): T { + function finishNode(node: T, pos: number, end?: number): T { setTextRangePosEnd(node, pos, end ?? scanner.getTokenFullStart()); if (contextFlags) { (node as Mutable).flags |= contextFlags; @@ -2569,9 +1708,9 @@ namespace Parser { return node; } - function createMissingNode(kind: T["kind"], reportAtCurrentPosition: false, diagnosticMessage?: DiagnosticMessage, ...args: DiagnosticArguments): T; - function createMissingNode(kind: T["kind"], reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, ...args: DiagnosticArguments): T; - function createMissingNode(kind: T["kind"], reportAtCurrentPosition: boolean, diagnosticMessage?: DiagnosticMessage, ...args: DiagnosticArguments): T { + function createMissingNode(kind: T["kind"], reportAtCurrentPosition: false, diagnosticMessage?: DiagnosticMessage, ...args: DiagnosticArguments): T; + function createMissingNode(kind: T["kind"], reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, ...args: DiagnosticArguments): T; + function createMissingNode(kind: T["kind"], reportAtCurrentPosition: boolean, diagnosticMessage?: DiagnosticMessage, ...args: DiagnosticArguments): T { if (reportAtCurrentPosition) { parseErrorAtPosition(scanner.getTokenFullStart(), 0, diagnosticMessage!, ...args); } @@ -2580,12 +1719,12 @@ namespace Parser { } const pos = getNodePos(); - const result = kind === SyntaxKind.Identifier ? factoryCreateIdentifier("", /*originalKeywordKind*/ undefined) : + const result = kind === SyntaxKind.Identifier ? factoryCreateIdentifier("") : isTemplateLiteralKind(kind) ? factory.createTemplateLiteralLikeNode(kind, "", "", /*templateFlags*/ undefined) : kind === SyntaxKind.NumericLiteral ? factoryCreateNumericLiteral("", /*numericLiteralFlags*/ undefined) : kind === SyntaxKind.StringLiteral ? factoryCreateStringLiteral("", /*isSingleQuote*/ undefined) : kind === SyntaxKind.MissingDeclaration ? factory.createMissingDeclaration() : - factoryCreateToken(kind); + factoryCreateToken(kind as TokenSyntaxKind); // TODO(rbuckton): verify assertion return finishNode(result, pos) as T; } @@ -2600,16 +1739,14 @@ namespace Parser { // An identifier that starts with two underscores has an extra underscore character prepended to it to avoid issues // with magic property names like '__proto__'. The 'identifiers' object is used to share a single string instance for // each identifier in order to reduce memory consumption. - function createIdentifier(isIdentifier: boolean, diagnosticMessage?: DiagnosticMessage, privateIdentifierDiagnosticMessage?: DiagnosticMessage): Identifier { + function createIdentifier(isIdentifier: boolean, diagnosticMessage?: DiagnosticMessage, privateIdentifierDiagnosticMessage?: DiagnosticMessage): AstIdentifier { if (isIdentifier) { identifierCount++; const pos = scanner.hasPrecedingJSDocLeadingAsterisks() ? scanner.getTokenStart() : getNodePos(); - // Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker - const originalKeywordKind = token(); const text = internIdentifier(scanner.getTokenValue()); const hasExtendedUnicodeEscape = scanner.hasExtendedUnicodeEscape(); nextTokenWithoutCheck(); - return finishNode(factoryCreateIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape), pos); + return finishNode(factoryCreateIdentifier(text, hasExtendedUnicodeEscape), pos); } if (token() === SyntaxKind.PrivateIdentifier) { @@ -2633,22 +1770,22 @@ namespace Parser { Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here : Diagnostics.Identifier_expected; - return createMissingNode(SyntaxKind.Identifier, reportAtCurrentPosition, diagnosticMessage || defaultMessage, msgArg); + return createMissingNode(SyntaxKind.Identifier, reportAtCurrentPosition, diagnosticMessage || defaultMessage, msgArg); } function parseBindingIdentifier(privateIdentifierDiagnosticMessage?: DiagnosticMessage) { return createIdentifier(isBindingIdentifier(), /*diagnosticMessage*/ undefined, privateIdentifierDiagnosticMessage); } - function parseIdentifier(diagnosticMessage?: DiagnosticMessage, privateIdentifierDiagnosticMessage?: DiagnosticMessage): Identifier { + function parseIdentifier(diagnosticMessage?: DiagnosticMessage, privateIdentifierDiagnosticMessage?: DiagnosticMessage): AstIdentifier { return createIdentifier(isIdentifier(), diagnosticMessage, privateIdentifierDiagnosticMessage); } - function parseIdentifierName(diagnosticMessage?: DiagnosticMessage): Identifier { + function parseIdentifierName(diagnosticMessage?: DiagnosticMessage): AstIdentifier { return createIdentifier(tokenIsIdentifierOrKeyword(token()), diagnosticMessage); } - function parseIdentifierNameErrorOnUnicodeEscapeSequence(): Identifier { + function parseIdentifierNameErrorOnUnicodeEscapeSequence(): AstIdentifier { if (scanner.hasUnicodeEscape() || scanner.hasExtendedUnicodeEscape()) { parseErrorAtCurrentToken(Diagnostics.Unicode_escape_sequence_cannot_appear_here); } @@ -2666,10 +1803,10 @@ namespace Parser { return tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.StringLiteral; } - function parsePropertyNameWorker(allowComputedPropertyNames: boolean): PropertyName { + function parsePropertyNameWorker(allowComputedPropertyNames: boolean): AstPropertyName { if (token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral || token() === SyntaxKind.BigIntLiteral) { - const node = parseLiteralNode() as StringLiteral | NumericLiteral | BigIntLiteral; - node.text = internIdentifier(node.text); + const node = parseLiteralNode() as AstStringLiteral | AstNumericLiteral | AstBigIntLiteral; + node.data.text = internIdentifier(node.data.text); return node; } if (allowComputedPropertyNames && token() === SyntaxKind.OpenBracketToken) { @@ -2681,11 +1818,11 @@ namespace Parser { return parseIdentifierName(); } - function parsePropertyName(): PropertyName { + function parsePropertyName(): AstPropertyName { return parsePropertyNameWorker(/*allowComputedPropertyNames*/ true); } - function parseComputedPropertyName(): ComputedPropertyName { + function parseComputedPropertyName(): AstComputedPropertyName { // PropertyName [Yield]: // LiteralPropertyName // ComputedPropertyName[?Yield] @@ -2699,7 +1836,7 @@ namespace Parser { return finishNode(factory.createComputedPropertyName(expression), pos); } - function parsePrivateIdentifier(): PrivateIdentifier { + function parsePrivateIdentifier(): AstPrivateIdentifier { const pos = getNodePos(); const node = factoryCreatePrivateIdentifier(internIdentifier(scanner.getTokenValue())); nextToken(); @@ -3039,7 +2176,7 @@ namespace Parser { } // Parses a list of elements - function parseList(kind: ParsingContext, parseElement: () => T): NodeArray { + function parseList(kind: ParsingContext, parseElement: () => T): AstNodeArray { const saveParsingContext = parsingContext; parsingContext |= 1 << kind; const list = []; @@ -3061,7 +2198,7 @@ namespace Parser { return createNodeArray(list, listPos); } - function parseListElement(parsingContext: ParsingContext, parseElement: () => T): T { + function parseListElement(parsingContext: ParsingContext, parseElement: () => T): T { const node = currentNode(parsingContext); if (node) { return consumeNode(node) as T; @@ -3070,7 +2207,7 @@ namespace Parser { return parseElement(); } - function currentNode(parsingContext: ParsingContext, pos?: number): Node | undefined { + function currentNode(parsingContext: ParsingContext, pos?: number): AstNode | undefined { // If we don't have a cursor or the parsing context isn't reusable, there's nothing to reuse. // // If there is an outstanding parse error that we've encountered, but not attached to @@ -3116,15 +2253,15 @@ namespace Parser { return undefined; } - if (canHaveJSDoc(node) && node.jsDoc?.jsDocCache) { + if (canHaveJSDoc(node) && node.data.jsDoc?.jsDocCache) { // jsDocCache may include tags from parent nodes, which might have been modified. - node.jsDoc.jsDocCache = undefined; + node.data.jsDoc.jsDocCache = undefined; } return node; } - function consumeNode(node: Node) { + function consumeNode(node: AstNode) { // Move the scanner so it is after the node we just consumed. scanner.resetTokenState(node.end); nextToken(); @@ -3148,7 +2285,7 @@ namespace Parser { return false; } - function canReuseNode(node: Node, parsingContext: ParsingContext): boolean { + function canReuseNode(node: AstNode, parsingContext: ParsingContext): boolean { switch (parsingContext) { case ParsingContext.ClassMembers: return isReusableClassMember(node); @@ -3226,7 +2363,7 @@ namespace Parser { return false; } - function isReusableClassMember(node: Node) { + function isReusableClassMember(node: AstNode) { if (node) { switch (node.kind) { case SyntaxKind.Constructor: @@ -3240,9 +2377,9 @@ namespace Parser { // Method declarations are not necessarily reusable. An object-literal // may have a method calls "constructor(...)" and we must reparse that // into an actual .ConstructorDeclaration. - const methodDeclaration = node as MethodDeclaration; - const nameIsConstructor = methodDeclaration.name.kind === SyntaxKind.Identifier && - methodDeclaration.name.escapedText === "constructor"; + const methodDeclaration = node as AstMethodDeclaration; + const nameIsConstructor = methodDeclaration.data.name.kind === SyntaxKind.Identifier && + methodDeclaration.data.name.data.escapedText === "constructor"; return !nameIsConstructor; } @@ -3251,7 +2388,7 @@ namespace Parser { return false; } - function isReusableSwitchClause(node: Node) { + function isReusableSwitchClause(node: AstNode) { if (node) { switch (node.kind) { case SyntaxKind.CaseClause: @@ -3263,7 +2400,7 @@ namespace Parser { return false; } - function isReusableStatement(node: Node) { + function isReusableStatement(node: AstNode) { if (node) { switch (node.kind) { case SyntaxKind.FunctionDeclaration: @@ -3302,11 +2439,11 @@ namespace Parser { return false; } - function isReusableEnumMember(node: Node) { + function isReusableEnumMember(node: AstNode) { return node.kind === SyntaxKind.EnumMember; } - function isReusableTypeMember(node: Node) { + function isReusableTypeMember(node: AstNode) { if (node) { switch (node.kind) { case SyntaxKind.ConstructSignature: @@ -3321,7 +2458,7 @@ namespace Parser { return false; } - function isReusableVariableDeclaration(node: Node) { + function isReusableVariableDeclaration(node: AstNode) { if (node.kind !== SyntaxKind.VariableDeclaration) { return false; } @@ -3340,18 +2477,18 @@ namespace Parser { // // In order to prevent this, we do not allow a variable declarator to be reused if it // has an initializer. - const variableDeclarator = node as VariableDeclaration; - return variableDeclarator.initializer === undefined; + const variableDeclarator = node as AstVariableDeclaration; + return variableDeclarator.data.initializer === undefined; } - function isReusableParameter(node: Node) { + function isReusableParameter(node: AstNode) { if (node.kind !== SyntaxKind.Parameter) { return false; } // See the comment in isReusableVariableDeclaration for why we do this. - const parameter = node as ParameterDeclaration; - return parameter.initializer === undefined; + const parameter = node as AstParameterDeclaration; + return parameter.data.initializer === undefined; } // Returns true if we should abort parsing. @@ -3435,9 +2572,9 @@ namespace Parser { } // Parses a comma-delimited list of elements - function parseDelimitedList(kind: ParsingContext, parseElement: () => T, considerSemicolonAsDelimiter?: boolean): NodeArray; - function parseDelimitedList(kind: ParsingContext, parseElement: () => T, considerSemicolonAsDelimiter?: boolean): NodeArray> | undefined; - function parseDelimitedList(kind: ParsingContext, parseElement: () => T, considerSemicolonAsDelimiter?: boolean): NodeArray> | undefined { + function parseDelimitedList(kind: ParsingContext, parseElement: () => T, considerSemicolonAsDelimiter?: boolean): AstNodeArray; + function parseDelimitedList(kind: ParsingContext, parseElement: () => T, considerSemicolonAsDelimiter?: boolean): AstNodeArray> | undefined; + function parseDelimitedList(kind: ParsingContext, parseElement: () => T, considerSemicolonAsDelimiter?: boolean): AstNodeArray> | undefined { const saveParsingContext = parsingContext; parsingContext |= 1 << kind; const list: NonNullable[] = []; @@ -3510,17 +2647,17 @@ namespace Parser { return kind === ParsingContext.EnumMembers ? Diagnostics.An_enum_member_name_must_be_followed_by_a_or : undefined; } - function createMissingList(): NodeArray { + function createMissingList(): AstNodeArray { const list = createNodeArray([], getNodePos()); missingLists.add(list); return list; } - function isMissingList(arr: NodeArray): boolean { + function isMissingList(arr: AstNodeArray): boolean { return missingLists.has(arr); } - function parseBracketedList(kind: ParsingContext, parseElement: () => T, open: PunctuationSyntaxKind, close: PunctuationSyntaxKind): NodeArray { + function parseBracketedList(kind: ParsingContext, parseElement: () => T, open: PunctuationSyntaxKind, close: PunctuationSyntaxKind): AstNodeArray { if (parseExpected(open)) { const result = parseDelimitedList(kind, parseElement); parseExpected(close); @@ -3530,9 +2667,9 @@ namespace Parser { return createMissingList(); } - function parseEntityName(allowReservedWords: boolean, diagnosticMessage?: DiagnosticMessage): EntityName { + function parseEntityName(allowReservedWords: boolean, diagnosticMessage?: DiagnosticMessage): AstEntityName { const pos = getNodePos(); - let entity: EntityName = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage); + let entity: AstEntityName = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage); while (parseOptional(SyntaxKind.DotToken)) { if (token() === SyntaxKind.LessThanToken) { // The entity is part of a JSDoc-style generic. We will use the gap between `typeName` and @@ -3542,7 +2679,7 @@ namespace Parser { entity = finishNode( factory.createQualifiedName( entity, - parseRightSideOfDot(allowReservedWords, /*allowPrivateIdentifiers*/ false, /*allowUnicodeEscapeSequenceInIdentifierName*/ true) as Identifier, + parseRightSideOfDot(allowReservedWords, /*allowPrivateIdentifiers*/ false, /*allowUnicodeEscapeSequenceInIdentifierName*/ true) as AstIdentifier, ), pos, ); @@ -3550,11 +2687,11 @@ namespace Parser { return entity; } - function createQualifiedName(entity: EntityName, name: Identifier): QualifiedName { + function createQualifiedName(entity: AstEntityName, name: AstIdentifier): AstQualifiedName { return finishNode(factory.createQualifiedName(entity, name), entity.pos); } - function parseRightSideOfDot(allowIdentifierNames: boolean, allowPrivateIdentifiers: boolean, allowUnicodeEscapeSequenceInIdentifierName: boolean): Identifier | PrivateIdentifier { + function parseRightSideOfDot(allowIdentifierNames: boolean, allowPrivateIdentifiers: boolean, allowUnicodeEscapeSequenceInIdentifierName: boolean): AstIdentifier | AstPrivateIdentifier { // Technically a keyword is valid here as all identifiers and keywords are identifier names. // However, often we'll encounter this in error situations when the identifier or keyword // is actually starting another valid construct. @@ -3581,13 +2718,13 @@ namespace Parser { // Report that we need an identifier. However, report it right after the dot, // and not on the next token. This is because the next token might actually // be an identifier and the error would be quite confusing. - return createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Identifier_expected); + return createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Identifier_expected); } } if (token() === SyntaxKind.PrivateIdentifier) { const node = parsePrivateIdentifier(); - return allowPrivateIdentifiers ? node : createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Identifier_expected); + return allowPrivateIdentifiers ? node : createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Identifier_expected); } if (allowIdentifierNames) { @@ -3600,16 +2737,16 @@ namespace Parser { function parseTemplateSpans(isTaggedTemplate: boolean) { const pos = getNodePos(); const list = []; - let node: TemplateSpan; + let node: AstTemplateSpan; do { node = parseTemplateSpan(isTaggedTemplate); list.push(node); } - while (node.literal.kind === SyntaxKind.TemplateMiddle); + while (node.data.literal.kind === SyntaxKind.TemplateMiddle); return createNodeArray(list, pos); } - function parseTemplateExpression(isTaggedTemplate: boolean): TemplateExpression { + function parseTemplateExpression(isTaggedTemplate: boolean): AstTemplateExpression { const pos = getNodePos(); return finishNode( factory.createTemplateExpression( @@ -3620,7 +2757,7 @@ namespace Parser { ); } - function parseTemplateType(): TemplateLiteralTypeNode { + function parseTemplateType(): AstTemplateLiteralTypeNode { const pos = getNodePos(); return finishNode( factory.createTemplateLiteralType( @@ -3634,16 +2771,16 @@ namespace Parser { function parseTemplateTypeSpans() { const pos = getNodePos(); const list = []; - let node: TemplateLiteralTypeSpan; + let node: AstTemplateLiteralTypeSpan; do { node = parseTemplateTypeSpan(); list.push(node); } - while (node.literal.kind === SyntaxKind.TemplateMiddle); + while (node.data.literal.kind === SyntaxKind.TemplateMiddle); return createNodeArray(list, pos); } - function parseTemplateTypeSpan(): TemplateLiteralTypeSpan { + function parseTemplateTypeSpan(): AstTemplateLiteralTypeSpan { const pos = getNodePos(); return finishNode( factory.createTemplateLiteralTypeSpan( @@ -3654,18 +2791,18 @@ namespace Parser { ); } - function parseLiteralOfTemplateSpan(isTaggedTemplate: boolean) { + function parseLiteralOfTemplateSpan(isTaggedTemplate: boolean): AstTemplateMiddle | AstTemplateTail { if (token() === SyntaxKind.CloseBraceToken) { reScanTemplateToken(isTaggedTemplate); return parseTemplateMiddleOrTemplateTail(); } else { // TODO(rbuckton): Do we need to call `parseExpectedToken` or can we just call `createMissingNode` directly? - return parseExpectedToken(SyntaxKind.TemplateTail, Diagnostics._0_expected, tokenToString(SyntaxKind.CloseBraceToken)) as TemplateTail; + return parseExpectedToken(SyntaxKind.TemplateTail, Diagnostics._0_expected, tokenToString(SyntaxKind.CloseBraceToken)) as AstTemplateTail; } } - function parseTemplateSpan(isTaggedTemplate: boolean): TemplateSpan { + function parseTemplateSpan(isTaggedTemplate: boolean): AstTemplateSpan { const pos = getNodePos(); return finishNode( factory.createTemplateSpan( @@ -3676,32 +2813,32 @@ namespace Parser { ); } - function parseLiteralNode(): LiteralExpression { - return parseLiteralLikeNode(token()) as LiteralExpression; + function parseLiteralNode(): AstLiteralExpression { + return parseLiteralLikeNode(token()) as AstLiteralExpression; } - function parseTemplateHead(isTaggedTemplate: boolean): TemplateHead { + function parseTemplateHead(isTaggedTemplate: boolean): AstTemplateHead { if (!isTaggedTemplate && scanner.getTokenFlags() & TokenFlags.IsInvalid) { reScanTemplateToken(/*isTaggedTemplate*/ false); } const fragment = parseLiteralLikeNode(token()); Debug.assert(fragment.kind === SyntaxKind.TemplateHead, "Template head has wrong token kind"); - return fragment as TemplateHead; + return fragment as AstTemplateHead; } - function parseTemplateMiddleOrTemplateTail(): TemplateMiddle | TemplateTail { + function parseTemplateMiddleOrTemplateTail(): AstTemplateMiddle | AstTemplateTail { const fragment = parseLiteralLikeNode(token()); Debug.assert(fragment.kind === SyntaxKind.TemplateMiddle || fragment.kind === SyntaxKind.TemplateTail, "Template fragment has wrong token kind"); - return fragment as TemplateMiddle | TemplateTail; + return fragment as AstTemplateMiddle | AstTemplateTail; } - function getTemplateLiteralRawText(kind: TemplateLiteralToken["kind"]) { + function getTemplateLiteralRawText(kind: AstTemplateLiteralToken["kind"]) { const isLast = kind === SyntaxKind.NoSubstitutionTemplateLiteral || kind === SyntaxKind.TemplateTail; const tokenText = scanner.getTokenText(); return tokenText.substring(1, tokenText.length - (scanner.isUnterminated() ? 0 : isLast ? 1 : 2)); } - function parseLiteralLikeNode(kind: SyntaxKind): LiteralLikeNode { + function parseLiteralLikeNode(kind: SyntaxKind): AstLiteralLikeNode { const pos = getNodePos(); const node = isTemplateLiteralKind(kind) ? factory.createTemplateLiteralLikeNode(kind, scanner.getTokenValue(), getTemplateLiteralRawText(kind), scanner.getTokenFlags() & TokenFlags.TemplateLiteralLikeFlags) : // Note that theoretically the following condition would hold true literals like 009, @@ -3714,12 +2851,21 @@ namespace Parser { isLiteralKind(kind) ? factoryCreateLiteralLikeNode(kind, scanner.getTokenValue()) : Debug.fail(); - if (scanner.hasExtendedUnicodeEscape()) { - node.hasExtendedUnicodeEscape = true; - } - - if (scanner.isUnterminated()) { - node.isUnterminated = true; + switch (node.kind) { + case SyntaxKind.TemplateHead: + case SyntaxKind.TemplateMiddle: + case SyntaxKind.TemplateTail: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.StringLiteral: + case SyntaxKind.JsxText: + case SyntaxKind.RegularExpressionLiteral: + if (scanner.hasExtendedUnicodeEscape()) { + node.data.hasExtendedUnicodeEscape = true; + } + if (scanner.isUnterminated()) { + node.data.isUnterminated = true; + } + break; } nextToken(); @@ -3738,7 +2884,7 @@ namespace Parser { } } - function parseTypeReference(): TypeReferenceNode { + function parseTypeReference(): AstTypeReferenceNode { const pos = getNodePos(); return finishNode( factory.createTypeReferenceNode( @@ -3750,46 +2896,46 @@ namespace Parser { } // If true, we should abort parsing an error function. - function typeHasArrowFunctionBlockingParseError(node: TypeNode): boolean { + function typeHasArrowFunctionBlockingParseError(node: AstTypeNode): boolean { switch (node.kind) { case SyntaxKind.TypeReference: - return nodeIsMissing((node as TypeReferenceNode).typeName); + return nodeIsMissing((node as AstTypeReferenceNode).data.typeName); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: { - const { parameters, type } = node as FunctionOrConstructorTypeNode; + const { data: { parameters, type } } = node as AstFunctionOrConstructorTypeNode; return isMissingList(parameters) || typeHasArrowFunctionBlockingParseError(type); } case SyntaxKind.ParenthesizedType: - return typeHasArrowFunctionBlockingParseError((node as ParenthesizedTypeNode).type); + return typeHasArrowFunctionBlockingParseError((node as AstParenthesizedTypeNode).data.type); default: return false; } } - function parseThisTypePredicate(lhs: ThisTypeNode): TypePredicateNode { + function parseThisTypePredicate(lhs: AstThisTypeNode): AstTypePredicateNode { nextToken(); return finishNode(factory.createTypePredicateNode(/*assertsModifier*/ undefined, lhs, parseType()), lhs.pos); } - function parseThisTypeNode(): ThisTypeNode { + function parseThisTypeNode(): AstThisTypeNode { const pos = getNodePos(); nextToken(); return finishNode(factory.createThisTypeNode(), pos); } - function parseJSDocAllType(): JSDocAllType | JSDocOptionalType { + function parseJSDocAllType(): AstJSDocAllType | AstJSDocOptionalType { const pos = getNodePos(); nextToken(); return finishNode(factory.createJSDocAllType(), pos); } - function parseJSDocNonNullableType(): TypeNode { + function parseJSDocNonNullableType(): AstTypeNode { const pos = getNodePos(); nextToken(); return finishNode(factory.createJSDocNonNullableType(parseNonArrayType(), /*postfix*/ false), pos); } - function parseJSDocUnknownOrNullableType(): JSDocUnknownType | JSDocNullableType { + function parseJSDocUnknownOrNullableType(): AstJSDocUnknownType | AstJSDocNullableType { const pos = getNodePos(); // skip the ? nextToken(); @@ -3819,7 +2965,7 @@ namespace Parser { } } - function parseJSDocFunctionType(): JSDocFunctionType | TypeReferenceNode { + function parseJSDocFunctionType(): AstJSDocFunctionType | AstTypeReferenceNode { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); if (tryParse(nextTokenIsOpenParen)) { @@ -3830,9 +2976,9 @@ namespace Parser { return finishNode(factory.createTypeReferenceNode(parseIdentifierName(), /*typeArguments*/ undefined), pos); } - function parseJSDocParameter(): ParameterDeclaration { + function parseJSDocParameter(): AstParameterDeclaration { const pos = getNodePos(); - let name: Identifier | undefined; + let name: AstIdentifier | undefined; if (token() === SyntaxKind.ThisKeyword || token() === SyntaxKind.NewKeyword) { name = parseIdentifierName(); parseExpected(SyntaxKind.ColonToken); @@ -3851,7 +2997,7 @@ namespace Parser { ); } - function parseJSDocType(): TypeNode { + function parseJSDocType(): AstTypeNode { scanner.setSkipJsDocLeadingAsterisks(true); const pos = getNodePos(); if (parseOptional(SyntaxKind.ModuleKeyword)) { @@ -3887,7 +3033,7 @@ namespace Parser { return type; } - function parseTypeQuery(): TypeQueryNode { + function parseTypeQuery(): AstTypeQueryNode { const pos = getNodePos(); parseExpected(SyntaxKind.TypeOfKeyword); const entityName = parseEntityName(/*allowReservedWords*/ true); @@ -3896,12 +3042,12 @@ namespace Parser { return finishNode(factory.createTypeQueryNode(entityName, typeArguments), pos); } - function parseTypeParameter(): TypeParameterDeclaration { + function parseTypeParameter(): AstTypeParameterDeclaration { const pos = getNodePos(); const modifiers = parseModifiers(/*allowDecorators*/ false, /*permitConstAsModifier*/ true); const name = parseIdentifier(); - let constraint: TypeNode | undefined; - let expression: Expression | undefined; + let constraint: AstTypeNode | undefined; + let expression: AstExpression | undefined; if (parseOptional(SyntaxKind.ExtendsKeyword)) { // It's not uncommon for people to write improper constraints to a generic. If the // user writes a constraint that is an expression and not an actual type, then parse @@ -3924,11 +3070,11 @@ namespace Parser { const defaultType = parseOptional(SyntaxKind.EqualsToken) ? parseType() : undefined; const node = factory.createTypeParameterDeclaration(modifiers, name, constraint, defaultType); - node.expression = expression; + node.data.expression = expression; return finishNode(node, pos); } - function parseTypeParameters(): NodeArray | undefined { + function parseTypeParameters(): AstNodeArray | undefined { if (token() === SyntaxKind.LessThanToken) { return parseBracketedList(ParsingContext.TypeParameters, parseTypeParameter, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); } @@ -3942,11 +3088,11 @@ namespace Parser { isStartOfType(/*inStartOfParameter*/ !isJSDocParameter); } - function parseNameOfParameter(modifiers: NodeArray | undefined) { + function parseNameOfParameter(modifiers: AstNodeArray | undefined) { // FormalParameter [Yield,Await]: // BindingElement[?Yield,?Await] const name = parseIdentifierOrPattern(Diagnostics.Private_identifiers_cannot_be_used_as_parameters); - if (getFullWidth(name) === 0 && !some(modifiers) && isModifierKind(token())) { + if (getFullWidth(name) === 0 && !some(modifiers?.items) && isModifierKind(token())) { // in cases like // 'use strict' // function foo(static) @@ -3967,17 +3113,17 @@ namespace Parser { return isBindingIdentifier() || token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.OpenBraceToken; } - function parseParameter(inOuterAwaitContext: boolean): ParameterDeclaration { + function parseParameter(inOuterAwaitContext: boolean): AstParameterDeclaration { return parseParameterWorker(inOuterAwaitContext); } - function parseParameterForSpeculation(inOuterAwaitContext: boolean): ParameterDeclaration | undefined { + function parseParameterForSpeculation(inOuterAwaitContext: boolean): AstParameterDeclaration | undefined { return parseParameterWorker(inOuterAwaitContext, /*allowAmbiguity*/ false); } - function parseParameterWorker(inOuterAwaitContext: boolean): ParameterDeclaration; - function parseParameterWorker(inOuterAwaitContext: boolean, allowAmbiguity: false): ParameterDeclaration | undefined; - function parseParameterWorker(inOuterAwaitContext: boolean, allowAmbiguity = true): ParameterDeclaration | undefined { + function parseParameterWorker(inOuterAwaitContext: boolean): AstParameterDeclaration; + function parseParameterWorker(inOuterAwaitContext: boolean, allowAmbiguity: false): AstParameterDeclaration | undefined; + function parseParameterWorker(inOuterAwaitContext: boolean, allowAmbiguity = true): AstParameterDeclaration | undefined { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); @@ -3999,7 +3145,7 @@ namespace Parser { /*initializer*/ undefined, ); - const modifier = firstOrUndefined(modifiers); + const modifier = firstOrUndefined(modifiers?.items); if (modifier) { parseErrorAtRange(modifier, Diagnostics.Neither_decorators_nor_modifiers_may_be_applied_to_this_parameters); } @@ -4034,8 +3180,8 @@ namespace Parser { return node; } - function parseReturnType(returnToken: SyntaxKind.EqualsGreaterThanToken, isType: boolean): TypeNode; - function parseReturnType(returnToken: SyntaxKind.ColonToken | SyntaxKind.EqualsGreaterThanToken, isType: boolean): TypeNode | undefined; + function parseReturnType(returnToken: SyntaxKind.EqualsGreaterThanToken, isType: boolean): AstTypeNode; + function parseReturnType(returnToken: SyntaxKind.ColonToken | SyntaxKind.EqualsGreaterThanToken, isType: boolean): AstTypeNode | undefined; function parseReturnType(returnToken: SyntaxKind.ColonToken | SyntaxKind.EqualsGreaterThanToken, isType: boolean) { if (shouldParseReturnType(returnToken, isType)) { return allowConditionalTypesAnd(parseTypeOrTypePredicate); @@ -4059,9 +3205,9 @@ namespace Parser { return false; } - function parseParametersWorker(flags: SignatureFlags, allowAmbiguity: true): NodeArray; - function parseParametersWorker(flags: SignatureFlags, allowAmbiguity: false): NodeArray | undefined; - function parseParametersWorker(flags: SignatureFlags, allowAmbiguity: boolean): NodeArray | undefined { + function parseParametersWorker(flags: SignatureFlags, allowAmbiguity: true): AstNodeArray; + function parseParametersWorker(flags: SignatureFlags, allowAmbiguity: false): AstNodeArray | undefined; + function parseParametersWorker(flags: SignatureFlags, allowAmbiguity: boolean): AstNodeArray | undefined { // FormalParameters [Yield,Await]: (modified) // [empty] // FormalParameterList[?Yield,Await] @@ -4091,7 +3237,7 @@ namespace Parser { return parameters; } - function parseParameters(flags: SignatureFlags): NodeArray { + function parseParameters(flags: SignatureFlags): AstNodeArray { // FormalParameters [Yield,Await]: (modified) // [empty] // FormalParameterList[?Yield,Await] @@ -4106,7 +3252,7 @@ namespace Parser { // SingleNameBinding [Yield,Await]: // BindingIdentifier[?Yield,?Await]Initializer [In, ?Yield,?Await] opt if (!parseExpected(SyntaxKind.OpenParenToken)) { - return createMissingList(); + return createMissingList(); } const parameters = parseParametersWorker(flags, /*allowAmbiguity*/ true); @@ -4125,7 +3271,7 @@ namespace Parser { parseSemicolon(); } - function parseSignatureMember(kind: SyntaxKind.CallSignature | SyntaxKind.ConstructSignature): CallSignatureDeclaration | ConstructSignatureDeclaration { + function parseSignatureMember(kind: SyntaxKind.CallSignature | SyntaxKind.ConstructSignature): AstCallSignatureDeclaration | AstConstructSignatureDeclaration { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); if (kind === SyntaxKind.ConstructSignature) { @@ -4201,18 +3347,18 @@ namespace Parser { return token() === SyntaxKind.ColonToken || token() === SyntaxKind.CommaToken || token() === SyntaxKind.CloseBracketToken; } - function parseIndexSignatureDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): IndexSignatureDeclaration { - const parameters = parseBracketedList(ParsingContext.Parameters, () => parseParameter(/*inOuterAwaitContext*/ false), SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); + function parseIndexSignatureDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstIndexSignatureDeclaration { + const parameters = parseBracketedList(ParsingContext.Parameters, () => parseParameter(/*inOuterAwaitContext*/ false), SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); const type = parseTypeAnnotation(); parseTypeMemberSemicolon(); const node = factory.createIndexSignature(modifiers, parameters, type); return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parsePropertyOrMethodSignature(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): PropertySignature | MethodSignature { + function parsePropertyOrMethodSignature(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstPropertySignature | AstMethodSignature { const name = parsePropertyName(); const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); - let node: PropertySignature | MethodSignature; + let node: AstPropertySignature | AstMethodSignature; if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { // Method signatures don't exist in expression contexts. So they have neither // [Yield] nor [Await] @@ -4227,7 +3373,9 @@ namespace Parser { // Although type literal properties cannot not have initializers, we attempt // to parse an initializer so we can report in the checker that an interface // property or type literal property cannot have an initializer. - if (token() === SyntaxKind.EqualsToken) (node as Mutable).initializer = parseInitializer(); + if (token() === SyntaxKind.EqualsToken) { + node.data.initializer = parseInitializer(); + } } parseTypeMemberSemicolon(); return withJSDoc(finishNode(node, pos), hasJSDoc); @@ -4271,7 +3419,7 @@ namespace Parser { return false; } - function parseTypeMember(): TypeElement { + function parseTypeMember(): AstTypeElement { if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return parseSignatureMember(SyntaxKind.CallSignature); } @@ -4314,19 +3462,19 @@ namespace Parser { return false; } - function parseTypeLiteral(): TypeLiteralNode { + function parseTypeLiteral(): AstTypeLiteralNode { const pos = getNodePos(); return finishNode(factory.createTypeLiteralNode(parseObjectTypeMembers()), pos); } - function parseObjectTypeMembers(): NodeArray { - let members: NodeArray; + function parseObjectTypeMembers(): AstNodeArray { + let members: AstNodeArray; if (parseExpected(SyntaxKind.OpenBraceToken)) { members = parseList(ParsingContext.TypeMembers, parseTypeMember); parseExpected(SyntaxKind.CloseBraceToken); } else { - members = createMissingList(); + members = createMissingList(); } return members; @@ -4354,9 +3502,9 @@ namespace Parser { function parseMappedType() { const pos = getNodePos(); parseExpected(SyntaxKind.OpenBraceToken); - let readonlyToken: ReadonlyKeyword | PlusToken | MinusToken | undefined; + let readonlyToken: AstReadonlyKeyword | AstPlusToken | AstMinusToken | undefined; if (token() === SyntaxKind.ReadonlyKeyword || token() === SyntaxKind.PlusToken || token() === SyntaxKind.MinusToken) { - readonlyToken = parseTokenNode(); + readonlyToken = parseTokenNode(); if (readonlyToken.kind !== SyntaxKind.ReadonlyKeyword) { parseExpected(SyntaxKind.ReadonlyKeyword); } @@ -4365,9 +3513,9 @@ namespace Parser { const typeParameter = parseMappedTypeParameter(); const nameType = parseOptional(SyntaxKind.AsKeyword) ? parseType() : undefined; parseExpected(SyntaxKind.CloseBracketToken); - let questionToken: QuestionToken | PlusToken | MinusToken | undefined; + let questionToken: AstQuestionToken | AstPlusToken | AstMinusToken | undefined; if (token() === SyntaxKind.QuestionToken || token() === SyntaxKind.PlusToken || token() === SyntaxKind.MinusToken) { - questionToken = parseTokenNode(); + questionToken = parseTokenNode(); if (questionToken.kind !== SyntaxKind.QuestionToken) { parseExpected(SyntaxKind.QuestionToken); } @@ -4385,10 +3533,10 @@ namespace Parser { return finishNode(factory.createRestTypeNode(parseType()), pos); } const type = parseType(); - if (isJSDocNullableType(type) && type.pos === type.type.pos) { - const node = factory.createOptionalTypeNode(type.type); + if (isAstJSDocNullableType(type) && type.pos === type.data.type.pos) { + const node = factory.createOptionalTypeNode(type.data.type); setTextRange(node, type); - (node as Mutable).flags = type.flags; + node.flags = type.flags; return node; } return type; @@ -4420,7 +3568,7 @@ namespace Parser { return parseTupleElementType(); } - function parseTupleType(): TupleTypeNode { + function parseTupleType(): AstTupleTypeNode { const pos = getNodePos(); return finishNode( factory.createTupleTypeNode( @@ -4430,7 +3578,7 @@ namespace Parser { ); } - function parseParenthesizedType(): TypeNode { + function parseParenthesizedType(): AstTypeNode { const pos = getNodePos(); parseExpected(SyntaxKind.OpenParenToken); const type = parseType(); @@ -4438,18 +3586,18 @@ namespace Parser { return finishNode(factory.createParenthesizedType(type), pos); } - function parseModifiersForConstructorType(): NodeArray | undefined { - let modifiers: NodeArray | undefined; + function parseModifiersForConstructorType(): AstNodeArray | undefined { + let modifiers: AstNodeArray | undefined; if (token() === SyntaxKind.AbstractKeyword) { const pos = getNodePos(); nextToken(); const modifier = finishNode(factoryCreateToken(SyntaxKind.AbstractKeyword), pos); - modifiers = createNodeArray([modifier], pos); + modifiers = createNodeArray([modifier], pos); } return modifiers; } - function parseFunctionOrConstructorType(): TypeNode { + function parseFunctionOrConstructorType(): AstTypeNode { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); const modifiers = parseModifiersForConstructorType(); @@ -4464,19 +3612,19 @@ namespace Parser { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseKeywordAndNoDot(): TypeNode | undefined { - const node = parseTokenNode(); + function parseKeywordAndNoDot(): AstKeywordTypeNode | undefined { + const node = parseTokenNode(); return token() === SyntaxKind.DotToken ? undefined : node; } - function parseLiteralTypeNode(negative?: boolean): LiteralTypeNode { + function parseLiteralTypeNode(negative?: boolean): AstLiteralTypeNode { const pos = getNodePos(); if (negative) { nextToken(); } - let expression: BooleanLiteral | NullLiteral | LiteralExpression | PrefixUnaryExpression = token() === SyntaxKind.TrueKeyword || token() === SyntaxKind.FalseKeyword || token() === SyntaxKind.NullKeyword ? - parseTokenNode() : - parseLiteralLikeNode(token()) as LiteralExpression; + let expression: AstBooleanLiteral | AstNullLiteral | AstLiteralExpression | AstPrefixUnaryExpression = token() === SyntaxKind.TrueKeyword || token() === SyntaxKind.FalseKeyword || token() === SyntaxKind.NullKeyword ? + parseTokenNode() : + parseLiteralLikeNode(token()) as AstLiteralExpression; if (negative) { expression = finishNode(factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, expression), pos); } @@ -4488,14 +3636,14 @@ namespace Parser { return token() === SyntaxKind.ImportKeyword; } - function parseImportType(): ImportTypeNode { + function parseImportType(): AstImportTypeNode { sourceFlags |= NodeFlags.PossiblyContainsDynamicImport; const pos = getNodePos(); const isTypeOf = parseOptional(SyntaxKind.TypeOfKeyword); parseExpected(SyntaxKind.ImportKeyword); parseExpected(SyntaxKind.OpenParenToken); const type = parseType(); - let attributes: ImportAttributes | undefined; + let attributes: AstImportAttributes | undefined; if (parseOptional(SyntaxKind.CommaToken)) { const openBracePosition = scanner.getTokenStart(); parseExpected(SyntaxKind.OpenBraceToken); @@ -4529,7 +3677,7 @@ namespace Parser { return token() === SyntaxKind.NumericLiteral || token() === SyntaxKind.BigIntLiteral; } - function parseNonArrayType(): TypeNode { + function parseNonArrayType(): AstTypeNode { switch (token()) { case SyntaxKind.AnyKeyword: case SyntaxKind.UnknownKeyword: @@ -4570,7 +3718,7 @@ namespace Parser { case SyntaxKind.MinusToken: return lookAhead(nextTokenIsNumericOrBigIntLiteral) ? parseLiteralTypeNode(/*negative*/ true) : parseTypeReference(); case SyntaxKind.VoidKeyword: - return parseTokenNode(); + return parseTokenNode(); case SyntaxKind.ThisKeyword: { const thisKeyword = parseThisTypeNode(); if (token() === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { @@ -4656,7 +3804,7 @@ namespace Parser { return token() === SyntaxKind.CloseParenToken || isStartOfParameter(/*isJSDocParameter*/ false) || isStartOfType(); } - function parsePostfixTypeOrHigher(): TypeNode { + function parsePostfixTypeOrHigher(): AstTypeNode { const pos = getNodePos(); let type = parseNonArrayType(); while (!scanner.hasPrecedingLineBreak()) { @@ -4707,7 +3855,7 @@ namespace Parser { } } - function parseTypeParameterOfInferType(): TypeParameterDeclaration { + function parseTypeParameterOfInferType(): AstTypeParameterDeclaration { const pos = getNodePos(); const name = parseIdentifier(); const constraint = tryParse(tryParseConstraintOfInferType); @@ -4715,13 +3863,13 @@ namespace Parser { return finishNode(node, pos); } - function parseInferType(): InferTypeNode { + function parseInferType(): AstInferTypeNode { const pos = getNodePos(); parseExpected(SyntaxKind.InferKeyword); return finishNode(factory.createInferTypeNode(parseTypeParameterOfInferType()), pos); } - function parseTypeOperatorOrHigher(): TypeNode { + function parseTypeOperatorOrHigher(): AstTypeNode { const operator = token(); switch (operator) { case SyntaxKind.KeyOfKeyword: @@ -4736,14 +3884,14 @@ namespace Parser { function parseFunctionOrConstructorTypeToError( isInUnionType: boolean, - ): TypeNode | undefined { + ): AstTypeNode | undefined { // the function type and constructor type shorthand notation // are not allowed directly in unions and intersections, but we'll // try to parse them gracefully and issue a helpful message. if (isStartOfFunctionTypeOrConstructorType()) { const type = parseFunctionOrConstructorType(); let diagnostic: DiagnosticMessage; - if (isFunctionTypeNode(type)) { + if (isAstFunctionTypeNode(type)) { diagnostic = isInUnionType ? Diagnostics.Function_type_notation_must_be_parenthesized_when_used_in_a_union_type : Diagnostics.Function_type_notation_must_be_parenthesized_when_used_in_an_intersection_type; @@ -4761,9 +3909,9 @@ namespace Parser { function parseUnionOrIntersectionType( operator: SyntaxKind.BarToken | SyntaxKind.AmpersandToken, - parseConstituentType: () => TypeNode, - createTypeNode: (types: NodeArray) => UnionOrIntersectionTypeNode, - ): TypeNode { + parseConstituentType: () => AstTypeNode, + createTypeNode: (types: AstNodeArray) => AstUnionOrIntersectionTypeNode, + ): AstTypeNode { const pos = getNodePos(); const isUnionType = operator === SyntaxKind.BarToken; const hasLeadingOperator = parseOptional(operator); @@ -4779,11 +3927,11 @@ namespace Parser { return type; } - function parseIntersectionTypeOrHigher(): TypeNode { + function parseIntersectionTypeOrHigher(): AstTypeNode { return parseUnionOrIntersectionType(SyntaxKind.AmpersandToken, parseTypeOperatorOrHigher, factory.createIntersectionTypeNode); } - function parseUnionTypeOrHigher(): TypeNode { + function parseUnionTypeOrHigher(): AstTypeNode { return parseUnionOrIntersectionType(SyntaxKind.BarToken, parseIntersectionTypeOrHigher, factory.createUnionTypeNode); } @@ -4852,7 +4000,7 @@ namespace Parser { return false; } - function parseTypeOrTypePredicate(): TypeNode { + function parseTypeOrTypePredicate(): AstTypeNode { const pos = getNodePos(); const typePredicateVariable = isIdentifier() && tryParse(parseTypePredicatePrefix); const type = parseType(); @@ -4872,7 +4020,7 @@ namespace Parser { } } - function parseAssertsTypePredicate(): TypeNode { + function parseAssertsTypePredicate(): AstTypeNode { const pos = getNodePos(); const assertsModifier = parseExpectedToken(SyntaxKind.AssertsKeyword); const parameterName = token() === SyntaxKind.ThisKeyword ? parseThisTypeNode() : parseIdentifier(); @@ -4880,7 +4028,7 @@ namespace Parser { return finishNode(factory.createTypePredicateNode(assertsModifier, parameterName, type), pos); } - function parseType(): TypeNode { + function parseType(): AstTypeNode { if (contextFlags & NodeFlags.TypeExcludesFlags) { return doOutsideOfContext(NodeFlags.TypeExcludesFlags, parseType); } @@ -4901,7 +4049,7 @@ namespace Parser { return type; } - function parseTypeAnnotation(): TypeNode | undefined { + function parseTypeAnnotation(): AstTypeNode | undefined { return parseOptional(SyntaxKind.ColonToken) ? parseType() : undefined; } @@ -4981,7 +4129,7 @@ namespace Parser { isStartOfExpression(); } - function parseExpression(): Expression { + function parseExpression(): AstExpression { // Expression[in]: // AssignmentExpression[in] // Expression[in] , AssignmentExpression[in] @@ -4994,7 +4142,7 @@ namespace Parser { const pos = getNodePos(); let expr = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); - let operatorToken: BinaryOperatorToken; + let operatorToken: AstBinaryOperatorToken; while ((operatorToken = parseOptionalToken(SyntaxKind.CommaToken))) { expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true), pos); } @@ -5005,11 +4153,11 @@ namespace Parser { return expr; } - function parseInitializer(): Expression | undefined { + function parseInitializer(): AstExpression | undefined { return parseOptional(SyntaxKind.EqualsToken) ? parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true) : undefined; } - function parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction: boolean): Expression { + function parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction: boolean): AstExpression { // AssignmentExpression[in,yield]: // 1) ConditionalExpression[?in,?yield] // 2) LeftHandSideExpression = AssignmentExpression[?in,?yield] @@ -5059,7 +4207,7 @@ namespace Parser { // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single // identifier and the current token is an arrow. if (expr.kind === SyntaxKind.Identifier && token() === SyntaxKind.EqualsGreaterThanToken) { - return parseSimpleArrowFunctionExpression(pos, expr as Identifier, allowReturnTypeInArrowFunction, hasJSDoc, /*asyncModifier*/ undefined); + return parseSimpleArrowFunctionExpression(pos, expr as AstIdentifier, allowReturnTypeInArrowFunction, hasJSDoc, /*asyncModifier*/ undefined); } // Now see if we might be in cases '2' or '3'. @@ -5068,7 +4216,7 @@ namespace Parser { // // Note: we call reScanGreaterToken so that we get an appropriately merged token // for cases like `> > =` becoming `>>=` - if (isLeftHandSideExpression(expr) && isAssignmentOperator(reScanGreaterToken())) { + if (isAstLeftHandSideExpression(expr) && isAssignmentOperator(reScanGreaterToken())) { return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction), pos); } @@ -5109,7 +4257,7 @@ namespace Parser { return !scanner.hasPrecedingLineBreak() && isIdentifier(); } - function parseYieldExpression(): YieldExpression { + function parseYieldExpression(): AstYieldExpression { const pos = getNodePos(); // YieldExpression[In] : @@ -5137,7 +4285,7 @@ namespace Parser { } } - function parseSimpleArrowFunctionExpression(pos: number, identifier: Identifier, allowReturnTypeInArrowFunction: boolean, hasJSDoc: boolean, asyncModifier?: NodeArray | undefined): ArrowFunction { + function parseSimpleArrowFunctionExpression(pos: number, identifier: AstIdentifier, allowReturnTypeInArrowFunction: boolean, hasJSDoc: boolean, asyncModifier?: AstNodeArray | undefined): AstArrowFunction { Debug.assert(token() === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); const parameter = factory.createParameterDeclaration( /*modifiers*/ undefined, @@ -5149,14 +4297,14 @@ namespace Parser { ); finishNode(parameter, identifier.pos); - const parameters = createNodeArray([parameter], parameter.pos, parameter.end); + const parameters = createNodeArray([parameter], parameter.pos, parameter.end); const equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken); const body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier, allowReturnTypeInArrowFunction); const node = factory.createArrowFunction(asyncModifier, /*typeParameters*/ undefined, parameters, /*type*/ undefined, equalsGreaterThanToken, body); return withJSDoc(finishNode(node, pos), hasJSDoc); } - function tryParseParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction: boolean): Expression | undefined { + function tryParseParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction: boolean): AstExpression | undefined { const triState = isParenthesizedArrowFunctionExpression(); if (triState === Tristate.False) { // It's definitely not a parenthesized arrow function expression. @@ -5321,7 +4469,7 @@ namespace Parser { } } - function parsePossibleParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction: boolean): ArrowFunction | undefined { + function parsePossibleParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction: boolean): AstArrowFunction | undefined { const tokenPos = scanner.getTokenStart(); if (notParenthesizedArrow?.has(tokenPos)) { return undefined; @@ -5335,7 +4483,7 @@ namespace Parser { return result; } - function tryParseAsyncSimpleArrowFunctionExpression(allowReturnTypeInArrowFunction: boolean): ArrowFunction | undefined { + function tryParseAsyncSimpleArrowFunctionExpression(allowReturnTypeInArrowFunction: boolean): AstArrowFunction | undefined { // We do a check here so that we won't be doing unnecessarily call to "lookAhead" if (token() === SyntaxKind.AsyncKeyword) { if (lookAhead(isUnParenthesizedAsyncArrowFunctionWorker) === Tristate.True) { @@ -5343,7 +4491,7 @@ namespace Parser { const hasJSDoc = hasPrecedingJSDocComment(); const asyncModifier = parseModifiersForArrowFunction(); const expr = parseBinaryExpressionOrHigher(OperatorPrecedence.Lowest); - return parseSimpleArrowFunctionExpression(pos, expr as Identifier, allowReturnTypeInArrowFunction, hasJSDoc, asyncModifier); + return parseSimpleArrowFunctionExpression(pos, expr as AstIdentifier, allowReturnTypeInArrowFunction, hasJSDoc, asyncModifier); } } return undefined; @@ -5370,11 +4518,11 @@ namespace Parser { return Tristate.False; } - function parseParenthesizedArrowFunctionExpression(allowAmbiguity: boolean, allowReturnTypeInArrowFunction: boolean): ArrowFunction | undefined { + function parseParenthesizedArrowFunctionExpression(allowAmbiguity: boolean, allowReturnTypeInArrowFunction: boolean): AstArrowFunction | undefined { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); const modifiers = parseModifiersForArrowFunction(); - const isAsync = some(modifiers, isAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; + const isAsync = some(modifiers?.items, isAstAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; // Arrow functions are never generators. // // If we're speculatively parsing a signature for a parenthesized arrow function, then @@ -5384,12 +4532,12 @@ namespace Parser { // close paren. const typeParameters = parseTypeParameters(); - let parameters: NodeArray; + let parameters: AstNodeArray; if (!parseExpected(SyntaxKind.OpenParenToken)) { if (!allowAmbiguity) { return undefined; } - parameters = createMissingList(); + parameters = createMissingList(); } else { if (!allowAmbiguity) { @@ -5426,10 +4574,10 @@ namespace Parser { let unwrappedType = type; while (unwrappedType?.kind === SyntaxKind.ParenthesizedType) { - unwrappedType = (unwrappedType as ParenthesizedTypeNode).type; // Skip parens if need be + unwrappedType = (unwrappedType as AstParenthesizedTypeNode).data.type; // Skip parens if need be } - const hasJSDocFunctionType = unwrappedType && isJSDocFunctionType(unwrappedType); + const hasJSDocFunctionType = unwrappedType && isAstJSDocFunctionType(unwrappedType); if (!allowAmbiguity && token() !== SyntaxKind.EqualsGreaterThanToken && (hasJSDocFunctionType || token() !== SyntaxKind.OpenBraceToken)) { // Returning undefined here will cause our caller to rewind to where we started from. return undefined; @@ -5440,7 +4588,7 @@ namespace Parser { const lastToken = token(); const equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken); const body = (lastToken === SyntaxKind.EqualsGreaterThanToken || lastToken === SyntaxKind.OpenBraceToken) - ? parseArrowFunctionExpressionBody(some(modifiers, isAsyncModifier), allowReturnTypeInArrowFunction) + ? parseArrowFunctionExpressionBody(some(modifiers?.items, isAstAsyncModifier), allowReturnTypeInArrowFunction) : parseIdentifier(); // Given: @@ -5473,7 +4621,7 @@ namespace Parser { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseArrowFunctionExpressionBody(isAsync: boolean, allowReturnTypeInArrowFunction: boolean): Block | Expression { + function parseArrowFunctionExpressionBody(isAsync: boolean, allowReturnTypeInArrowFunction: boolean): AstConciseBody { if (token() === SyntaxKind.OpenBraceToken) { return parseFunctionBlock(isAsync ? SignatureFlags.Await : SignatureFlags.None); } @@ -5511,7 +4659,7 @@ namespace Parser { return node; } - function parseConditionalExpressionRest(leftOperand: Expression, pos: number, allowReturnTypeInArrowFunction: boolean): Expression { + function parseConditionalExpressionRest(leftOperand: AstExpression, pos: number, allowReturnTypeInArrowFunction: boolean): AstExpression { // Note: we are passed in an expression which was produced from parseBinaryExpressionOrHigher. const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (!questionToken) { @@ -5535,7 +4683,7 @@ namespace Parser { ); } - function parseBinaryExpressionOrHigher(precedence: OperatorPrecedence): Expression { + function parseBinaryExpressionOrHigher(precedence: OperatorPrecedence): AstExpression { const pos = getNodePos(); const leftOperand = parseUnaryExpressionOrHigher(); return parseBinaryExpressionRest(precedence, leftOperand, pos); @@ -5545,7 +4693,7 @@ namespace Parser { return t === SyntaxKind.InKeyword || t === SyntaxKind.OfKeyword; } - function parseBinaryExpressionRest(precedence: OperatorPrecedence, leftOperand: Expression, pos: number): Expression { + function parseBinaryExpressionRest(precedence: OperatorPrecedence, leftOperand: AstExpression, pos: number): AstExpression { while (true) { // We either have a binary operator here, or we're finished. We call // reScanGreaterToken so that we merge token sequences like > and = into >= @@ -5618,15 +4766,15 @@ namespace Parser { return getBinaryOperatorPrecedence(token()) > 0; } - function makeSatisfiesExpression(left: Expression, right: TypeNode): SatisfiesExpression { + function makeSatisfiesExpression(left: AstExpression, right: AstTypeNode): AstSatisfiesExpression { return finishNode(factory.createSatisfiesExpression(left, right), left.pos); } - function makeBinaryExpression(left: Expression, operatorToken: BinaryOperatorToken, right: Expression, pos: number): BinaryExpression { + function makeBinaryExpression(left: AstExpression, operatorToken: AstBinaryOperatorToken, right: AstExpression, pos: number): AstBinaryExpression { return finishNode(factory.createBinaryExpression(left, operatorToken, right), pos); } - function makeAsExpression(left: Expression, right: TypeNode): AsExpression { + function makeAsExpression(left: AstExpression, right: AstTypeNode): AstAsExpression { return finishNode(factory.createAsExpression(left, right), left.pos); } @@ -5675,7 +4823,7 @@ namespace Parser { * 1) UnaryExpression[?Yield] * 2) UpdateExpression[?Yield] ** ExponentiationExpression[?Yield] */ - function parseUnaryExpressionOrHigher(): UnaryExpression | BinaryExpression { + function parseUnaryExpressionOrHigher(): AstUnaryExpression | AstBinaryExpression { /** * ES7 UpdateExpression: * 1) LeftHandSideExpression[?Yield] @@ -5688,7 +4836,7 @@ namespace Parser { const pos = getNodePos(); const updateExpression = parseUpdateExpression(); return token() === SyntaxKind.AsteriskAsteriskToken ? - parseBinaryExpressionRest(getBinaryOperatorPrecedence(token()), updateExpression, pos) as BinaryExpression : + parseBinaryExpressionRest(getBinaryOperatorPrecedence(token()), updateExpression, pos) as AstBinaryExpression : updateExpression; } @@ -5733,7 +4881,7 @@ namespace Parser { * 8) ! UnaryExpression[?yield] * 9) [+Await] await UnaryExpression[?yield] */ - function parseSimpleUnaryExpression(): UnaryExpression { + function parseSimpleUnaryExpression(): AstUnaryExpression { switch (token()) { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: @@ -5812,7 +4960,7 @@ namespace Parser { * 5) --LeftHandSideExpression[?yield] * In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression */ - function parseUpdateExpression(): UpdateExpression { + function parseUpdateExpression(): AstUpdateExpression { if (token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) { const pos = getNodePos(); return finishNode(factory.createPrefixUnaryExpression(token() as PrefixUnaryOperator, nextTokenAnd(parseLeftHandSideExpressionOrHigher)), pos); @@ -5824,7 +4972,7 @@ namespace Parser { const expression = parseLeftHandSideExpressionOrHigher(); - Debug.assert(isLeftHandSideExpression(expression)); + Debug.assert(isAstLeftHandSideExpression(expression)); if ((token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) && !scanner.hasPrecedingLineBreak()) { const operator = token() as PostfixUnaryOperator; nextToken(); @@ -5834,7 +4982,7 @@ namespace Parser { return expression; } - function parseLeftHandSideExpressionOrHigher(): LeftHandSideExpression { + function parseLeftHandSideExpressionOrHigher(): AstLeftHandSideExpression { // Original Ecma: // LeftHandSideExpression: See 11.2 // NewExpression @@ -5867,7 +5015,7 @@ namespace Parser { // 3)we have a MemberExpression which either completes the LeftHandSideExpression, // or starts the beginning of the first four CallExpression productions. const pos = getNodePos(); - let expression: MemberExpression; + let expression: AstMemberExpression; if (token() === SyntaxKind.ImportKeyword) { if (lookAhead(nextTokenIsOpenParenOrLessThan)) { // We don't want to eagerly consume all import keyword as import call expression so we look ahead to find "(" @@ -5876,7 +5024,7 @@ namespace Parser { // import * as foo1 from "module-from-node // We want this import to be a statement rather than import call expression sourceFlags |= NodeFlags.PossiblyContainsDynamicImport; - expression = parseTokenNode(); + expression = parseTokenNode(); } else if (lookAhead(nextTokenIsDot)) { // This is an 'import.*' metaproperty (i.e. 'import.meta') @@ -5899,7 +5047,7 @@ namespace Parser { return parseCallExpressionRest(pos, expression); } - function parseMemberExpressionOrHigher(): MemberExpression { + function parseMemberExpressionOrHigher(): AstMemberExpression { // Note: to make our lives simpler, we decompose the NewExpression productions and // place ObjectCreationExpression and FunctionExpression into PrimaryExpression. // like so: @@ -5952,9 +5100,9 @@ namespace Parser { return parseMemberExpressionRest(pos, expression, /*allowOptionalChain*/ true); } - function parseSuperExpression(): MemberExpression { + function parseSuperExpression(): AstMemberExpression { const pos = getNodePos(); - let expression = parseTokenNode(); + let expression: AstMemberExpression = parseTokenNode(); if (token() === SyntaxKind.LessThanToken) { const startPos = getNodePos(); const typeArguments = tryParse(parseTypeArgumentsInExpression); @@ -5977,47 +5125,47 @@ namespace Parser { return finishNode(factoryCreatePropertyAccessExpression(expression, parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true, /*allowUnicodeEscapeSequenceInIdentifierName*/ true)), pos); } - function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean, topInvalidNodePosition?: number, openingTag?: JsxOpeningElement | JsxOpeningFragment, mustBeUnary = false): JsxElement | JsxSelfClosingElement | JsxFragment { + function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean, topInvalidNodePosition?: number, openingTag?: AstJsxOpeningElement | AstJsxOpeningFragment, mustBeUnary = false): AstJsxElement | AstJsxSelfClosingElement | AstJsxFragment { const pos = getNodePos(); const opening = parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext); - let result: JsxElement | JsxSelfClosingElement | JsxFragment; + let result: AstJsxElement | AstJsxSelfClosingElement | AstJsxFragment; if (opening.kind === SyntaxKind.JsxOpeningElement) { let children = parseJsxChildren(opening); - let closingElement: JsxClosingElement; + let closingElement: AstJsxClosingElement; - const lastChild: JsxChild | undefined = children[children.length - 1]; + const lastChild: AstJsxChild | undefined = children.items[children.items.length - 1]; if ( lastChild?.kind === SyntaxKind.JsxElement - && !tagNamesAreEquivalent(lastChild.openingElement.tagName, lastChild.closingElement.tagName) - && tagNamesAreEquivalent(opening.tagName, lastChild.closingElement.tagName) + && !tagNamesAreEquivalent(lastChild.data.openingElement.data.tagName, lastChild.data.closingElement.data.tagName) + && tagNamesAreEquivalent(opening.data.tagName, lastChild.data.closingElement.data.tagName) ) { // when an unclosed JsxOpeningElement incorrectly parses its parent's JsxClosingElement, // restructure (
(......
)) --> (
(......)
) // (no need to error; the parent will error) - const end = lastChild.children.end; + const end = lastChild.data.children.end; const newLast = finishNode( factory.createJsxElement( - lastChild.openingElement, - lastChild.children, + lastChild.data.openingElement, + lastChild.data.children, finishNode(factory.createJsxClosingElement(finishNode(factoryCreateIdentifier(""), end, end)), end, end), ), - lastChild.openingElement.pos, + lastChild.data.openingElement.pos, end, ); - children = createNodeArray([...children.slice(0, children.length - 1), newLast], children.pos, end); - closingElement = lastChild.closingElement; + children = createNodeArray([...children.items.slice(0, children.items.length - 1), newLast], children.pos, end); + closingElement = lastChild.data.closingElement; } else { closingElement = parseJsxClosingElement(opening, inExpressionContext); - if (!tagNamesAreEquivalent(opening.tagName, closingElement.tagName)) { - if (openingTag && isJsxOpeningElement(openingTag) && tagNamesAreEquivalent(closingElement.tagName, openingTag.tagName)) { + if (!tagNamesAreEquivalent(opening.data.tagName, closingElement.data.tagName)) { + if (openingTag && isAstJsxOpeningElement(openingTag) && tagNamesAreEquivalent(closingElement.data.tagName, openingTag.data.tagName)) { // opening incorrectly matched with its parent's closing -- put error on opening - parseErrorAtRange(opening.tagName, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, opening.tagName)); + parseErrorAtRange(opening.data.tagName, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, opening.data.tagName)); } else { // other opening/closing mismatches -- put error on closing - parseErrorAtRange(closingElement.tagName, Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, getTextOfNodeFromSourceText(sourceText, opening.tagName)); + parseErrorAtRange(closingElement.data.tagName, Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, getTextOfNodeFromSourceText(sourceText, opening.data.tagName)); } } } @@ -6048,34 +5196,35 @@ namespace Parser { const operatorToken = createMissingNode(SyntaxKind.CommaToken, /*reportAtCurrentPosition*/ false); setTextRangePosWidth(operatorToken, invalidElement.pos, 0); parseErrorAt(skipTrivia(sourceText, topBadPos), invalidElement.end, Diagnostics.JSX_expressions_must_have_one_parent_element); - return finishNode(factory.createBinaryExpression(result, operatorToken as Token, invalidElement), pos) as Node as JsxElement; + // TODO(rbuckton): We shouldn't lie to the type system here and should allow BinaryExpression here or do something else less hacky + return finishNode(factory.createBinaryExpression(result, operatorToken as AstToken, invalidElement), pos) as AstNode as AstJsxElement; } } return result; } - function parseJsxText(): JsxText { + function parseJsxText(): AstJsxText { const pos = getNodePos(); const node = factory.createJsxText(scanner.getTokenValue(), currentToken === SyntaxKind.JsxTextAllWhiteSpaces); currentToken = scanner.scanJsxToken(); return finishNode(node, pos); } - function parseJsxChild(openingTag: JsxOpeningElement | JsxOpeningFragment, token: JsxTokenSyntaxKind): JsxChild | undefined { + function parseJsxChild(openingTag: AstJsxOpeningElement | AstJsxOpeningFragment, token: JsxTokenSyntaxKind): AstJsxChild | undefined { switch (token) { case SyntaxKind.EndOfFileToken: // If we hit EOF, issue the error at the tag that lacks the closing element // rather than at the end of the file (which is useless) - if (isJsxOpeningFragment(openingTag)) { + if (isAstJsxOpeningFragment(openingTag)) { parseErrorAtRange(openingTag, Diagnostics.JSX_fragment_has_no_corresponding_closing_tag); } else { // We want the error span to cover only 'Foo.Bar' in < Foo.Bar > // or to cover only 'Foo' in < Foo > - const tag = openingTag.tagName; + const tag = openingTag.data.tagName; const start = Math.min(skipTrivia(sourceText, tag.pos), tag.end); - parseErrorAt(start, tag.end, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.tagName)); + parseErrorAt(start, tag.end, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.data.tagName)); } return undefined; case SyntaxKind.LessThanSlashToken: @@ -6093,7 +5242,7 @@ namespace Parser { } } - function parseJsxChildren(openingTag: JsxOpeningElement | JsxOpeningFragment): NodeArray { + function parseJsxChildren(openingTag: AstJsxOpeningElement | AstJsxOpeningFragment): AstNodeArray { const list = []; const listPos = getNodePos(); const saveParsingContext = parsingContext; @@ -6104,10 +5253,10 @@ namespace Parser { if (!child) break; list.push(child); if ( - isJsxOpeningElement(openingTag) + isAstJsxOpeningElement(openingTag) && child?.kind === SyntaxKind.JsxElement - && !tagNamesAreEquivalent(child.openingElement.tagName, child.closingElement.tagName) - && tagNamesAreEquivalent(openingTag.tagName, child.closingElement.tagName) + && !tagNamesAreEquivalent(child.data.openingElement.data.tagName, child.data.closingElement.data.tagName) + && tagNamesAreEquivalent(openingTag.data.tagName, child.data.closingElement.data.tagName) ) { // stop after parsing a mismatched child like
...(
) in order to reattach the higher break; @@ -6118,12 +5267,12 @@ namespace Parser { return createNodeArray(list, listPos); } - function parseJsxAttributes(): JsxAttributes { + function parseJsxAttributes(): AstJsxAttributes { const pos = getNodePos(); return finishNode(factory.createJsxAttributes(parseList(ParsingContext.JsxAttributes, parseJsxAttribute)), pos); } - function parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext: boolean): JsxOpeningElement | JsxSelfClosingElement | JsxOpeningFragment { + function parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext: boolean): AstJsxOpeningElement | AstJsxSelfClosingElement | AstJsxOpeningFragment { const pos = getNodePos(); parseExpected(SyntaxKind.LessThanToken); @@ -6137,7 +5286,7 @@ namespace Parser { const typeArguments = (contextFlags & NodeFlags.JavaScriptFile) === 0 ? tryParseTypeArguments() : undefined; const attributes = parseJsxAttributes(); - let node: JsxOpeningLikeElement; + let node: AstJsxOpeningLikeElement; if (token() === SyntaxKind.GreaterThanToken) { // Closing tag, so scan the immediately-following text with the JSX scanning instead @@ -6163,7 +5312,7 @@ namespace Parser { return finishNode(node, pos); } - function parseJsxElementName(): JsxTagNameExpression { + function parseJsxElementName(): AstJsxTagNameExpression { const pos = getNodePos(); // JsxElement can have name in the form of // propertyAccessExpression @@ -6171,17 +5320,17 @@ namespace Parser { // We can't just simply use parseLeftHandSideExpressionOrHigher because then we will start consider class,function etc as a keyword // We only want to consider "this" as a primaryExpression const initialExpression = parseJsxTagName(); - if (isJsxNamespacedName(initialExpression)) { + if (isAstJsxNamespacedName(initialExpression)) { return initialExpression; // `a:b.c` is invalid syntax, don't even look for the `.` if we parse `a:b`, and let `parseAttribute` report "unexpected :" instead. } - let expression: PropertyAccessExpression | Identifier | ThisExpression = initialExpression; + let expression: AstPropertyAccessExpression | AstIdentifier | AstThisExpression = initialExpression; while (parseOptional(SyntaxKind.DotToken)) { expression = finishNode(factoryCreatePropertyAccessExpression(expression, parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ false, /*allowUnicodeEscapeSequenceInIdentifierName*/ false)), pos); } - return expression as JsxTagNameExpression; + return expression as AstJsxTagNameExpression; } - function parseJsxTagName(): Identifier | JsxNamespacedName | ThisExpression { + function parseJsxTagName(): AstIdentifier | AstJsxNamespacedName | AstThisExpression { const pos = getNodePos(); scanJsxIdentifier(); @@ -6194,14 +5343,14 @@ namespace Parser { return isThis ? finishNode(factory.createToken(SyntaxKind.ThisKeyword), pos) : tagName; } - function parseJsxExpression(inExpressionContext: boolean): JsxExpression | undefined { + function parseJsxExpression(inExpressionContext: boolean): AstJsxExpression | undefined { const pos = getNodePos(); if (!parseExpected(SyntaxKind.OpenBraceToken)) { return undefined; } - let dotDotDotToken: DotDotDotToken | undefined; - let expression: Expression | undefined; + let dotDotDotToken: AstDotDotDotToken | undefined; + let expression: AstExpression | undefined; if (token() !== SyntaxKind.CloseBraceToken) { if (!inExpressionContext) { dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken); @@ -6223,7 +5372,7 @@ namespace Parser { return finishNode(factory.createJsxExpression(dotDotDotToken, expression), pos); } - function parseJsxAttribute(): JsxAttribute | JsxSpreadAttribute { + function parseJsxAttribute(): AstJsxAttribute | AstJsxSpreadAttribute { if (token() === SyntaxKind.OpenBraceToken) { return parseJsxSpreadAttribute(); } @@ -6232,10 +5381,10 @@ namespace Parser { return finishNode(factory.createJsxAttribute(parseJsxAttributeName(), parseJsxAttributeValue()), pos); } - function parseJsxAttributeValue(): JsxAttributeValue | undefined { + function parseJsxAttributeValue(): AstJsxAttributeValue | undefined { if (token() === SyntaxKind.EqualsToken) { if (scanJsxAttributeValue() === SyntaxKind.StringLiteral) { - return parseLiteralNode() as StringLiteral; + return parseLiteralNode() as AstStringLiteral; } if (token() === SyntaxKind.OpenBraceToken) { return parseJsxExpression(/*inExpressionContext*/ true); @@ -6260,7 +5409,7 @@ namespace Parser { return attrName; } - function parseJsxSpreadAttribute(): JsxSpreadAttribute { + function parseJsxSpreadAttribute(): AstJsxSpreadAttribute { const pos = getNodePos(); parseExpected(SyntaxKind.OpenBraceToken); parseExpected(SyntaxKind.DotDotDotToken); @@ -6269,13 +5418,13 @@ namespace Parser { return finishNode(factory.createJsxSpreadAttribute(expression), pos); } - function parseJsxClosingElement(open: JsxOpeningElement, inExpressionContext: boolean): JsxClosingElement { + function parseJsxClosingElement(open: AstJsxOpeningElement, inExpressionContext: boolean): AstJsxClosingElement { const pos = getNodePos(); parseExpected(SyntaxKind.LessThanSlashToken); const tagName = parseJsxElementName(); if (parseExpected(SyntaxKind.GreaterThanToken, /*diagnosticMessage*/ undefined, /*shouldAdvance*/ false)) { // manually advance the scanner in order to look for jsx text inside jsx - if (inExpressionContext || !tagNamesAreEquivalent(open.tagName, tagName)) { + if (inExpressionContext || !tagNamesAreEquivalent(open.data.tagName, tagName)) { nextToken(); } else { @@ -6285,7 +5434,7 @@ namespace Parser { return finishNode(factory.createJsxClosingElement(tagName), pos); } - function parseJsxClosingFragment(inExpressionContext: boolean): JsxClosingFragment { + function parseJsxClosingFragment(inExpressionContext: boolean): AstJsxClosingFragment { const pos = getNodePos(); parseExpected(SyntaxKind.LessThanSlashToken); if (parseExpected(SyntaxKind.GreaterThanToken, Diagnostics.Expected_corresponding_closing_tag_for_JSX_fragment, /*shouldAdvance*/ false)) { @@ -6297,10 +5446,10 @@ namespace Parser { scanJsxText(); } } - return finishNode(factory.createJsxJsxClosingFragment(), pos); + return finishNode(factory.createJsxClosingFragment(), pos); } - function parseTypeAssertion(): TypeAssertion { + function parseTypeAssertion(): AstTypeAssertion { Debug.assert(languageVariant !== LanguageVariant.JSX, "Type assertions should never be parsed in JSX; they should be parsed as comparisons or JSX elements/fragments."); const pos = getNodePos(); parseExpected(SyntaxKind.LessThanToken); @@ -6322,21 +5471,21 @@ namespace Parser { && lookAhead(nextTokenIsIdentifierOrKeywordOrOpenBracketOrTemplate); } - function tryReparseOptionalChain(node: Expression) { + function tryReparseOptionalChain(node: AstExpression) { if (node.flags & NodeFlags.OptionalChain) { return true; } // check for an optional chain in a non-null expression - if (isNonNullExpression(node)) { - let expr = node.expression; - while (isNonNullExpression(expr) && !(expr.flags & NodeFlags.OptionalChain)) { - expr = expr.expression; + if (isAstNonNullExpression(node)) { + let expr = node.data.expression; + while (isAstNonNullExpression(expr) && !(expr.flags & NodeFlags.OptionalChain)) { + expr = expr.data.expression; } if (expr.flags & NodeFlags.OptionalChain) { // this is part of an optional chain. Walk down from `node` to `expression` and set the flag. - while (isNonNullExpression(node)) { - (node as Mutable).flags |= NodeFlags.OptionalChain; - node = node.expression; + while (isAstNonNullExpression(node)) { + node.flags |= NodeFlags.OptionalChain; + node = node.data.expression; } return true; } @@ -6344,32 +5493,32 @@ namespace Parser { return false; } - function parsePropertyAccessExpressionRest(pos: number, expression: LeftHandSideExpression, questionDotToken: QuestionDotToken | undefined) { + function parsePropertyAccessExpressionRest(pos: number, expression: AstLeftHandSideExpression, questionDotToken: AstQuestionDotToken | undefined) { const name = parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true, /*allowUnicodeEscapeSequenceInIdentifierName*/ true); const isOptionalChain = questionDotToken || tryReparseOptionalChain(expression); const propertyAccess = isOptionalChain ? factoryCreatePropertyAccessChain(expression, questionDotToken, name) : factoryCreatePropertyAccessExpression(expression, name); - if (isOptionalChain && isPrivateIdentifier(propertyAccess.name)) { - parseErrorAtRange(propertyAccess.name, Diagnostics.An_optional_chain_cannot_contain_private_identifiers); + if (isOptionalChain && isAstPrivateIdentifier(propertyAccess.data.name)) { + parseErrorAtRange(propertyAccess.data.name, Diagnostics.An_optional_chain_cannot_contain_private_identifiers); } - if (isExpressionWithTypeArguments(expression) && expression.typeArguments) { - const pos = expression.typeArguments.pos - 1; - const end = skipTrivia(sourceText, expression.typeArguments.end) + 1; + if (isAstExpressionWithTypeArguments(expression) && expression.data.typeArguments) { + const pos = expression.data.typeArguments.pos - 1; + const end = skipTrivia(sourceText, expression.data.typeArguments.end) + 1; parseErrorAt(pos, end, Diagnostics.An_instantiation_expression_cannot_be_followed_by_a_property_access); } return finishNode(propertyAccess, pos); } - function parseElementAccessExpressionRest(pos: number, expression: LeftHandSideExpression, questionDotToken: QuestionDotToken | undefined) { - let argumentExpression: Expression; + function parseElementAccessExpressionRest(pos: number, expression: AstLeftHandSideExpression, questionDotToken: AstQuestionDotToken | undefined) { + let argumentExpression: AstExpression; if (token() === SyntaxKind.CloseBracketToken) { argumentExpression = createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.An_element_access_expression_should_take_an_argument); } else { const argument = allowInAnd(parseExpression); - if (isStringOrNumericLiteralLike(argument)) { - argument.text = internIdentifier(argument.text); + if (isAstStringOrNumericLiteralLike(argument)) { + argument.data.text = internIdentifier(argument.data.text); } argumentExpression = argument; } @@ -6382,9 +5531,9 @@ namespace Parser { return finishNode(indexedAccess, pos); } - function parseMemberExpressionRest(pos: number, expression: LeftHandSideExpression, allowOptionalChain: boolean): MemberExpression { + function parseMemberExpressionRest(pos: number, expression: AstLeftHandSideExpression, allowOptionalChain: boolean): AstMemberExpression { while (true) { - let questionDotToken: QuestionDotToken | undefined; + let questionDotToken: AstQuestionDotToken | undefined; let isPropertyAccess = false; if (allowOptionalChain && isStartOfOptionalPropertyOrElementAccessChain()) { questionDotToken = parseExpectedToken(SyntaxKind.QuestionDotToken); @@ -6407,8 +5556,8 @@ namespace Parser { if (isTemplateStartOfTaggedTemplate()) { // Absorb type arguments into TemplateExpression when preceding expression is ExpressionWithTypeArguments - expression = !questionDotToken && expression.kind === SyntaxKind.ExpressionWithTypeArguments ? - parseTaggedTemplateRest(pos, (expression as ExpressionWithTypeArguments).expression, questionDotToken, (expression as ExpressionWithTypeArguments).typeArguments) : + expression = !questionDotToken && isAstExpressionWithTypeArguments(expression) ? + parseTaggedTemplateRest(pos, expression.data.expression, questionDotToken, expression.data.typeArguments) : parseTaggedTemplateRest(pos, expression, questionDotToken, /*typeArguments*/ undefined); continue; } @@ -6426,7 +5575,7 @@ namespace Parser { } } - return expression as MemberExpression; + return expression as AstMemberExpression; } } @@ -6434,25 +5583,25 @@ namespace Parser { return token() === SyntaxKind.NoSubstitutionTemplateLiteral || token() === SyntaxKind.TemplateHead; } - function parseTaggedTemplateRest(pos: number, tag: LeftHandSideExpression, questionDotToken: QuestionDotToken | undefined, typeArguments: NodeArray | undefined) { + function parseTaggedTemplateRest(pos: number, tag: AstLeftHandSideExpression, questionDotToken: AstQuestionDotToken | undefined, typeArguments: AstNodeArray | undefined) { const tagExpression = factory.createTaggedTemplateExpression( tag, typeArguments, token() === SyntaxKind.NoSubstitutionTemplateLiteral ? - (reScanTemplateToken(/*isTaggedTemplate*/ true), parseLiteralNode() as NoSubstitutionTemplateLiteral) : + (reScanTemplateToken(/*isTaggedTemplate*/ true), parseLiteralNode() as AstNoSubstitutionTemplateLiteral) : parseTemplateExpression(/*isTaggedTemplate*/ true), ); if (questionDotToken || tag.flags & NodeFlags.OptionalChain) { - (tagExpression as Mutable).flags |= NodeFlags.OptionalChain; + tagExpression.flags |= NodeFlags.OptionalChain; } - tagExpression.questionDotToken = questionDotToken; + tagExpression.data.questionDotToken = questionDotToken; return finishNode(tagExpression, pos); } - function parseCallExpressionRest(pos: number, expression: LeftHandSideExpression): LeftHandSideExpression { + function parseCallExpressionRest(pos: number, expression: AstLeftHandSideExpression): AstLeftHandSideExpression { while (true) { expression = parseMemberExpressionRest(pos, expression, /*allowOptionalChain*/ true); - let typeArguments: NodeArray | undefined; + let typeArguments: AstNodeArray | undefined; const questionDotToken = parseOptionalToken(SyntaxKind.QuestionDotToken); if (questionDotToken) { typeArguments = tryParse(parseTypeArgumentsInExpression); @@ -6463,9 +5612,9 @@ namespace Parser { } if (typeArguments || token() === SyntaxKind.OpenParenToken) { // Absorb type arguments into CallExpression when preceding expression is ExpressionWithTypeArguments - if (!questionDotToken && expression.kind === SyntaxKind.ExpressionWithTypeArguments) { - typeArguments = (expression as ExpressionWithTypeArguments).typeArguments; - expression = (expression as ExpressionWithTypeArguments).expression; + if (!questionDotToken && isAstExpressionWithTypeArguments(expression)) { + typeArguments = expression.data.typeArguments; + expression = expression.data.expression; } const argumentList = parseArgumentList(); const callExpr = questionDotToken || tryReparseOptionalChain(expression) ? @@ -6476,7 +5625,7 @@ namespace Parser { } if (questionDotToken) { // We parsed `?.` but then failed to parse anything, so report a missing identifier here. - const name = createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false, Diagnostics.Identifier_expected); + const name = createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false, Diagnostics.Identifier_expected); expression = finishNode(factoryCreatePropertyAccessChain(expression, questionDotToken, name), pos); } break; @@ -6537,7 +5686,7 @@ namespace Parser { return scanner.hasPrecedingLineBreak() || isBinaryOperator() || !isStartOfExpression(); } - function parsePrimaryExpression(): PrimaryExpression { + function parsePrimaryExpression(): AstPrimaryExpression { switch (token()) { case SyntaxKind.NoSubstitutionTemplateLiteral: if (scanner.getTokenFlags() & TokenFlags.IsInvalid) { @@ -6553,7 +5702,7 @@ namespace Parser { case SyntaxKind.NullKeyword: case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: - return parseTokenNode(); + return parseTokenNode(); case SyntaxKind.OpenParenToken: return parseParenthesizedExpression(); case SyntaxKind.OpenBracketToken: @@ -6592,7 +5741,7 @@ namespace Parser { return parseIdentifier(Diagnostics.Expression_expected); } - function parseParenthesizedExpression(): ParenthesizedExpression { + function parseParenthesizedExpression(): AstParenthesizedExpression { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); parseExpected(SyntaxKind.OpenParenToken); @@ -6601,24 +5750,24 @@ namespace Parser { return withJSDoc(finishNode(factoryCreateParenthesizedExpression(expression), pos), hasJSDoc); } - function parseSpreadElement(): Expression { + function parseSpreadElement(): AstExpression { const pos = getNodePos(); parseExpected(SyntaxKind.DotDotDotToken); const expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); return finishNode(factory.createSpreadElement(expression), pos); } - function parseArgumentOrArrayLiteralElement(): Expression { + function parseArgumentOrArrayLiteralElement(): AstExpression { return token() === SyntaxKind.DotDotDotToken ? parseSpreadElement() : token() === SyntaxKind.CommaToken ? finishNode(factory.createOmittedExpression(), getNodePos()) : parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); } - function parseArgumentExpression(): Expression { + function parseArgumentExpression(): AstExpression { return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement); } - function parseArrayLiteralExpression(): ArrayLiteralExpression { + function parseArrayLiteralExpression(): AstArrayLiteralExpression { const pos = getNodePos(); const openBracketPosition = scanner.getTokenStart(); const openBracketParsed = parseExpected(SyntaxKind.OpenBracketToken); @@ -6628,7 +5777,7 @@ namespace Parser { return finishNode(factoryCreateArrayLiteralExpression(elements, multiLine), pos); } - function parseObjectLiteralElement(): ObjectLiteralElementLike { + function parseObjectLiteralElement(): AstObjectLiteralElementLike { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); @@ -6662,15 +5811,15 @@ namespace Parser { // CoverInitializedName[Yield] : // IdentifierReference[?Yield] Initializer[In, ?Yield] // this is necessary because ObjectLiteral productions are also used to cover grammar for ObjectAssignmentPattern - let node: Mutable; + let node: AstShorthandPropertyAssignment | AstPropertyAssignment; const isShorthandPropertyAssignment = tokenIsIdentifier && (token() !== SyntaxKind.ColonToken); if (isShorthandPropertyAssignment) { const equalsToken = parseOptionalToken(SyntaxKind.EqualsToken); const objectAssignmentInitializer = equalsToken ? allowInAnd(() => parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true)) : undefined; - node = factory.createShorthandPropertyAssignment(name as Identifier, objectAssignmentInitializer); + node = factory.createShorthandPropertyAssignment(name as AstIdentifier, objectAssignmentInitializer); // Save equals token for error reporting. // TODO(rbuckton): Consider manufacturing this when we need to report an error as it is otherwise not useful. - node.equalsToken = equalsToken; + node.data.equalsToken = equalsToken; } else { parseExpected(SyntaxKind.ColonToken); @@ -6678,13 +5827,13 @@ namespace Parser { node = factory.createPropertyAssignment(name, initializer); } // Decorators, Modifiers, questionToken, and exclamationToken are not supported by property assignments and are reported in the grammar checker - node.modifiers = modifiers; - node.questionToken = questionToken; - node.exclamationToken = exclamationToken; + node.data.modifiers = modifiers; + node.data.questionToken = questionToken; + node.data.exclamationToken = exclamationToken; return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseObjectLiteralExpression(): ObjectLiteralExpression { + function parseObjectLiteralExpression(): AstObjectLiteralExpression { const pos = getNodePos(); const openBracePosition = scanner.getTokenStart(); const openBraceParsed = parseExpected(SyntaxKind.OpenBraceToken); @@ -6694,7 +5843,7 @@ namespace Parser { return finishNode(factoryCreateObjectLiteralExpression(properties, multiLine), pos); } - function parseFunctionExpression(): FunctionExpression { + function parseFunctionExpression(): AstFunctionExpression { // GeneratorExpression: // function* BindingIdentifier [Yield][opt](FormalParameters[Yield]){ GeneratorBody } // @@ -6709,7 +5858,7 @@ namespace Parser { parseExpected(SyntaxKind.FunctionKeyword); const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); const isGenerator = asteriskToken ? SignatureFlags.Yield : SignatureFlags.None; - const isAsync = some(modifiers, isAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; + const isAsync = some(modifiers?.items, isAstAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; const name = isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalBindingIdentifier) : isGenerator ? doInYieldContext(parseOptionalBindingIdentifier) : isAsync ? doInAwaitContext(parseOptionalBindingIdentifier) : @@ -6726,11 +5875,11 @@ namespace Parser { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseOptionalBindingIdentifier(): Identifier | undefined { + function parseOptionalBindingIdentifier(): AstIdentifier | undefined { return isBindingIdentifier() ? parseBindingIdentifier() : undefined; } - function parseNewExpressionOrNewDotTarget(): NewExpression | MetaProperty { + function parseNewExpressionOrNewDotTarget(): AstNewExpression | AstMetaProperty { const pos = getNodePos(); parseExpected(SyntaxKind.NewKeyword); if (parseOptional(SyntaxKind.DotToken)) { @@ -6738,12 +5887,12 @@ namespace Parser { return finishNode(factory.createMetaProperty(SyntaxKind.NewKeyword, name), pos); } const expressionPos = getNodePos(); - let expression: LeftHandSideExpression = parseMemberExpressionRest(expressionPos, parsePrimaryExpression(), /*allowOptionalChain*/ false); - let typeArguments: NodeArray | undefined; + let expression: AstLeftHandSideExpression = parseMemberExpressionRest(expressionPos, parsePrimaryExpression(), /*allowOptionalChain*/ false); + let typeArguments: AstNodeArray | undefined; // Absorb type arguments into NewExpression when preceding expression is ExpressionWithTypeArguments - if (expression.kind === SyntaxKind.ExpressionWithTypeArguments) { - typeArguments = (expression as ExpressionWithTypeArguments).typeArguments; - expression = (expression as ExpressionWithTypeArguments).expression; + if (isAstExpressionWithTypeArguments(expression)) { + typeArguments = expression.data.typeArguments; + expression = expression.data.expression; } if (token() === SyntaxKind.QuestionDotToken) { parseErrorAtCurrentToken(Diagnostics.Invalid_optional_chain_from_new_expression_Did_you_mean_to_call_0, getTextOfNodeFromSourceText(sourceText, expression)); @@ -6753,7 +5902,7 @@ namespace Parser { } // STATEMENTS - function parseBlock(ignoreMissingOpenBrace: boolean, diagnosticMessage?: DiagnosticMessage): Block { + function parseBlock(ignoreMissingOpenBrace: boolean, diagnosticMessage?: DiagnosticMessage): AstBlock { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); const openBracePosition = scanner.getTokenStart(); @@ -6771,12 +5920,12 @@ namespace Parser { return result; } else { - const statements = createMissingList(); + const statements = createMissingList(); return withJSDoc(finishNode(factoryCreateBlock(statements, /*multiLine*/ undefined), pos), hasJSDoc); } } - function parseFunctionBlock(flags: SignatureFlags, diagnosticMessage?: DiagnosticMessage): Block { + function parseFunctionBlock(flags: SignatureFlags, diagnosticMessage?: DiagnosticMessage): AstBlock { const savedYieldContext = inYieldContext(); setYieldContext(!!(flags & SignatureFlags.Yield)); @@ -6806,14 +5955,14 @@ namespace Parser { return block; } - function parseEmptyStatement(): Statement { + function parseEmptyStatement(): AstStatement { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); parseExpected(SyntaxKind.SemicolonToken); return withJSDoc(finishNode(factory.createEmptyStatement(), pos), hasJSDoc); } - function parseIfStatement(): IfStatement { + function parseIfStatement(): AstIfStatement { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); parseExpected(SyntaxKind.IfKeyword); @@ -6826,7 +5975,7 @@ namespace Parser { return withJSDoc(finishNode(factoryCreateIfStatement(expression, thenStatement, elseStatement), pos), hasJSDoc); } - function parseDoStatement(): DoStatement { + function parseDoStatement(): AstDoStatement { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); parseExpected(SyntaxKind.DoKeyword); @@ -6845,7 +5994,7 @@ namespace Parser { return withJSDoc(finishNode(factory.createDoStatement(statement, expression), pos), hasJSDoc); } - function parseWhileStatement(): WhileStatement { + function parseWhileStatement(): AstWhileStatement { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); parseExpected(SyntaxKind.WhileKeyword); @@ -6857,14 +6006,14 @@ namespace Parser { return withJSDoc(finishNode(factoryCreateWhileStatement(expression, statement), pos), hasJSDoc); } - function parseForOrForInOrForOfStatement(): Statement { + function parseForOrForInOrForOfStatement(): AstStatement { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); parseExpected(SyntaxKind.ForKeyword); const awaitToken = parseOptionalToken(SyntaxKind.AwaitKeyword); parseExpected(SyntaxKind.OpenParenToken); - let initializer!: VariableDeclarationList | Expression; + let initializer!: AstForInitializer; if (token() !== SyntaxKind.SemicolonToken) { if ( token() === SyntaxKind.VarKeyword || token() === SyntaxKind.LetKeyword || token() === SyntaxKind.ConstKeyword || @@ -6879,7 +6028,7 @@ namespace Parser { } } - let node: IterationStatement; + let node: AstIterationStatement; if (awaitToken ? parseExpected(SyntaxKind.OfKeyword) : parseOptional(SyntaxKind.OfKeyword)) { const expression = allowInAnd(() => parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true)); parseExpected(SyntaxKind.CloseParenToken); @@ -6903,10 +6052,10 @@ namespace Parser { node = factoryCreateForStatement(initializer, condition, incrementor, parseStatement()); } - return withJSDoc(finishNode(node, pos) as ForStatement | ForInOrOfStatement, hasJSDoc); + return withJSDoc(finishNode(node, pos) as AstForStatement | AstForInOrOfStatement, hasJSDoc); } - function parseBreakOrContinueStatement(kind: SyntaxKind): BreakOrContinueStatement { + function parseBreakOrContinueStatement(kind: SyntaxKind): AstBreakOrContinueStatement { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); @@ -6920,7 +6069,7 @@ namespace Parser { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseReturnStatement(): ReturnStatement { + function parseReturnStatement(): AstReturnStatement { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); parseExpected(SyntaxKind.ReturnKeyword); @@ -6929,7 +6078,7 @@ namespace Parser { return withJSDoc(finishNode(factory.createReturnStatement(expression), pos), hasJSDoc); } - function parseWithStatement(): WithStatement { + function parseWithStatement(): AstWithStatement { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); parseExpected(SyntaxKind.WithKeyword); @@ -6941,7 +6090,7 @@ namespace Parser { return withJSDoc(finishNode(factory.createWithStatement(expression, statement), pos), hasJSDoc); } - function parseCaseClause(): CaseClause { + function parseCaseClause(): AstCaseClause { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); parseExpected(SyntaxKind.CaseKeyword); @@ -6951,7 +6100,7 @@ namespace Parser { return withJSDoc(finishNode(factory.createCaseClause(expression, statements), pos), hasJSDoc); } - function parseDefaultClause(): DefaultClause { + function parseDefaultClause(): AstDefaultClause { const pos = getNodePos(); parseExpected(SyntaxKind.DefaultKeyword); parseExpected(SyntaxKind.ColonToken); @@ -6959,11 +6108,11 @@ namespace Parser { return finishNode(factory.createDefaultClause(statements), pos); } - function parseCaseOrDefaultClause(): CaseOrDefaultClause { + function parseCaseOrDefaultClause(): AstCaseOrDefaultClause { return token() === SyntaxKind.CaseKeyword ? parseCaseClause() : parseDefaultClause(); } - function parseCaseBlock(): CaseBlock { + function parseCaseBlock(): AstCaseBlock { const pos = getNodePos(); parseExpected(SyntaxKind.OpenBraceToken); const clauses = parseList(ParsingContext.SwitchClauses, parseCaseOrDefaultClause); @@ -6971,7 +6120,7 @@ namespace Parser { return finishNode(factory.createCaseBlock(clauses), pos); } - function parseSwitchStatement(): SwitchStatement { + function parseSwitchStatement(): AstSwitchStatement { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); parseExpected(SyntaxKind.SwitchKeyword); @@ -6982,7 +6131,7 @@ namespace Parser { return withJSDoc(finishNode(factory.createSwitchStatement(expression, caseBlock), pos), hasJSDoc); } - function parseThrowStatement(): ThrowStatement { + function parseThrowStatement(): AstThrowStatement { // ThrowStatement[Yield] : // throw [no LineTerminator here]Expression[In, ?Yield]; @@ -7007,7 +6156,7 @@ namespace Parser { } // TODO: Review for error recovery - function parseTryStatement(): TryStatement { + function parseTryStatement(): AstTryStatement { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); @@ -7017,7 +6166,7 @@ namespace Parser { // If we don't have a catch clause, then we must have a finally clause. Try to parse // one out no matter what. - let finallyBlock: Block | undefined; + let finallyBlock: AstBlock | undefined; if (!catchClause || token() === SyntaxKind.FinallyKeyword) { parseExpected(SyntaxKind.FinallyKeyword, Diagnostics.catch_or_finally_expected); finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false); @@ -7026,7 +6175,7 @@ namespace Parser { return withJSDoc(finishNode(factory.createTryStatement(tryBlock, catchClause, finallyBlock), pos), hasJSDoc); } - function parseCatchClause(): CatchClause { + function parseCatchClause(): AstCatchClause { const pos = getNodePos(); parseExpected(SyntaxKind.CatchKeyword); @@ -7044,7 +6193,7 @@ namespace Parser { return finishNode(factory.createCatchClause(variableDeclaration, block), pos); } - function parseDebuggerStatement(): Statement { + function parseDebuggerStatement(): AstStatement { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); parseExpected(SyntaxKind.DebuggerKeyword); @@ -7052,16 +6201,16 @@ namespace Parser { return withJSDoc(finishNode(factory.createDebuggerStatement(), pos), hasJSDoc); } - function parseExpressionOrLabeledStatement(): ExpressionStatement | LabeledStatement { + function parseExpressionOrLabeledStatement(): AstExpressionStatement | AstLabeledStatement { // Avoiding having to do the lookahead for a labeled statement by just trying to parse // out an expression, seeing if it is identifier and then seeing if it is followed by // a colon. const pos = getNodePos(); let hasJSDoc = hasPrecedingJSDocComment(); - let node: ExpressionStatement | LabeledStatement; + let node: AstExpressionStatement | AstLabeledStatement; const hasParen = token() === SyntaxKind.OpenParenToken; const expression = allowInAnd(parseExpression); - if (isIdentifierNode(expression) && parseOptional(SyntaxKind.ColonToken)) { + if (isAstIdentifier(expression) && parseOptional(SyntaxKind.ColonToken)) { node = factory.createLabeledStatement(expression, parseStatement()); } else { @@ -7300,7 +6449,7 @@ namespace Parser { return lookAhead(nextTokenIsUsingKeywordThenBindingIdentifierOrStartOfObjectDestructuringOnSameLine); } - function parseStatement(): Statement { + function parseStatement(): AstStatement { switch (token()) { case SyntaxKind.SemicolonToken: return parseEmptyStatement(); @@ -7383,26 +6532,22 @@ namespace Parser { return parseExpressionOrLabeledStatement(); } - function isDeclareModifier(modifier: ModifierLike) { - return modifier.kind === SyntaxKind.DeclareKeyword; - } - - function parseDeclaration(): Statement { + function parseDeclaration(): AstStatement { // `parseListElement` attempted to get the reused node at this position, // but the ambient context flag was not yet set, so the node appeared // not reusable in that context. const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); const modifiers = parseModifiers(/*allowDecorators*/ true); - const isAmbient = some(modifiers, isDeclareModifier); + const isAmbient = some(modifiers?.items, isAstDeclareKeyword); if (isAmbient) { const node = tryReuseAmbientDeclaration(pos); if (node) { return node; } - for (const m of modifiers!) { - (m as Mutable).flags |= NodeFlags.Ambient; + for (const m of modifiers!.items) { + m.flags |= NodeFlags.Ambient; } return doInsideOfContext(NodeFlags.Ambient, () => parseDeclarationWorker(pos, hasJSDoc, modifiers)); } @@ -7411,18 +6556,18 @@ namespace Parser { } } - function tryReuseAmbientDeclaration(pos: number): Statement | undefined { + function tryReuseAmbientDeclaration(pos: number): AstStatement | undefined { return doInsideOfContext(NodeFlags.Ambient, () => { // TODO(jakebailey): this is totally wrong; `parsingContext` is the result of ORing a bunch of `1 << ParsingContext.XYZ`. // The enum should really be a bunch of flags. const node = currentNode(parsingContext, pos); if (node) { - return consumeNode(node) as Statement; + return consumeNode(node) as AstStatement; } }); } - function parseDeclarationWorker(pos: number, hasJSDoc: boolean, modifiersIn: NodeArray | undefined): Statement { + function parseDeclarationWorker(pos: number, hasJSDoc: boolean, modifiersIn: AstNodeArray | undefined): AstStatement { switch (token()) { case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: @@ -7461,9 +6606,9 @@ namespace Parser { if (modifiersIn) { // We reached this point because we encountered decorators and/or modifiers and assumed a declaration // would follow. For recovery and error reporting purposes, return an incomplete declaration. - const missing = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); + const missing = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); setTextRangePos(missing, pos); - (missing as Mutable).modifiers = modifiersIn; + missing.data.modifiers = modifiersIn; return missing; } return undefined!; // TODO: GH#18217 @@ -7484,7 +6629,7 @@ namespace Parser { return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token() === SyntaxKind.StringLiteral); } - function parseFunctionBlockOrSemicolon(flags: SignatureFlags, diagnosticMessage?: DiagnosticMessage): Block | undefined { + function parseFunctionBlockOrSemicolon(flags: SignatureFlags, diagnosticMessage?: DiagnosticMessage): AstBlock | undefined { if (token() !== SyntaxKind.OpenBraceToken) { if (flags & SignatureFlags.Type) { parseTypeMemberSemicolon(); @@ -7500,7 +6645,7 @@ namespace Parser { // DECLARATIONS - function parseArrayBindingElement(): ArrayBindingElement { + function parseArrayBindingElement(): AstArrayBindingElement { const pos = getNodePos(); if (token() === SyntaxKind.CommaToken) { return finishNode(factory.createOmittedExpression(), pos); @@ -7511,14 +6656,14 @@ namespace Parser { return finishNode(factory.createBindingElement(dotDotDotToken, /*propertyName*/ undefined, name, initializer), pos); } - function parseObjectBindingElement(): BindingElement { + function parseObjectBindingElement(): AstBindingElement { const pos = getNodePos(); const dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken); const tokenIsIdentifier = isBindingIdentifier(); - let propertyName: PropertyName | undefined = parsePropertyName(); - let name: BindingName; + let propertyName: AstPropertyName | undefined = parsePropertyName(); + let name: AstBindingName; if (tokenIsIdentifier && token() !== SyntaxKind.ColonToken) { - name = propertyName as Identifier; + name = propertyName as AstIdentifier; propertyName = undefined; } else { @@ -7529,7 +6674,7 @@ namespace Parser { return finishNode(factory.createBindingElement(dotDotDotToken, propertyName, name, initializer), pos); } - function parseObjectBindingPattern(): ObjectBindingPattern { + function parseObjectBindingPattern(): AstObjectBindingPattern { const pos = getNodePos(); parseExpected(SyntaxKind.OpenBraceToken); const elements = allowInAnd(() => parseDelimitedList(ParsingContext.ObjectBindingElements, parseObjectBindingElement)); @@ -7537,7 +6682,7 @@ namespace Parser { return finishNode(factory.createObjectBindingPattern(elements), pos); } - function parseArrayBindingPattern(): ArrayBindingPattern { + function parseArrayBindingPattern(): AstArrayBindingPattern { const pos = getNodePos(); parseExpected(SyntaxKind.OpenBracketToken); const elements = allowInAnd(() => parseDelimitedList(ParsingContext.ArrayBindingElements, parseArrayBindingElement)); @@ -7552,7 +6697,7 @@ namespace Parser { || isBindingIdentifier(); } - function parseIdentifierOrPattern(privateIdentifierDiagnosticMessage?: DiagnosticMessage): Identifier | BindingPattern { + function parseIdentifierOrPattern(privateIdentifierDiagnosticMessage?: DiagnosticMessage): AstIdentifier | AstBindingPattern { if (token() === SyntaxKind.OpenBracketToken) { return parseArrayBindingPattern(); } @@ -7566,16 +6711,16 @@ namespace Parser { return parseVariableDeclaration(/*allowExclamation*/ true); } - function parseVariableDeclaration(allowExclamation?: boolean): VariableDeclaration { + function parseVariableDeclaration(allowExclamation?: boolean): AstVariableDeclaration { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); const name = parseIdentifierOrPattern(Diagnostics.Private_identifiers_are_not_allowed_in_variable_declarations); - let exclamationToken: ExclamationToken | undefined; + let exclamationToken: AstExclamationToken | undefined; if ( allowExclamation && name.kind === SyntaxKind.Identifier && token() === SyntaxKind.ExclamationToken && !scanner.hasPrecedingLineBreak() ) { - exclamationToken = parseTokenNode>(); + exclamationToken = parseTokenNode(); } const type = parseTypeAnnotation(); const initializer = isInOrOfKeyword(token()) ? undefined : parseInitializer(); @@ -7583,7 +6728,7 @@ namespace Parser { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseVariableDeclarationList(inForStatementInitializer: boolean): VariableDeclarationList { + function parseVariableDeclarationList(inForStatementInitializer: boolean): AstVariableDeclarationList { const pos = getNodePos(); let flags: NodeFlags = 0; @@ -7619,9 +6764,9 @@ namespace Parser { // So we need to look ahead to determine if 'of' should be treated as a keyword in // this context. // The checker will then give an error that there is an empty declaration list. - let declarations: readonly VariableDeclaration[]; + let declarations: AstNodeArray; if (token() === SyntaxKind.OfKeyword && lookAhead(canFollowContextualOfKeyword)) { - declarations = createMissingList(); + declarations = createMissingList(); } else { const savedDisallowIn = inDisallowInContext(); @@ -7642,16 +6787,16 @@ namespace Parser { return nextTokenIsIdentifier() && nextToken() === SyntaxKind.CloseParenToken; } - function parseVariableStatement(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): VariableStatement { + function parseVariableStatement(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstVariableStatement { const declarationList = parseVariableDeclarationList(/*inForStatementInitializer*/ false); parseSemicolon(); const node = factoryCreateVariableStatement(modifiers, declarationList); return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseFunctionDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): FunctionDeclaration { + function parseFunctionDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstFunctionDeclaration { const savedAwaitContext = inAwaitContext(); - const modifierFlags = modifiersToFlags(modifiers); + const modifierFlags = modifiersToFlags(modifiers?.items); parseExpected(SyntaxKind.FunctionKeyword); const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); // We don't parse the name here in await context, instead we will report a grammar error in the checker. @@ -7675,12 +6820,12 @@ namespace Parser { if (token() === SyntaxKind.StringLiteral && lookAhead(nextToken) === SyntaxKind.OpenParenToken) { return tryParse(() => { const literalNode = parseLiteralNode(); - return literalNode.text === "constructor" ? literalNode : undefined; + return literalNode.data.text === "constructor" ? literalNode : undefined; }); } } - function tryParseConstructorDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): ConstructorDeclaration | undefined { + function tryParseConstructorDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstConstructorDeclaration | undefined { return tryParse(() => { if (parseConstructorName()) { const typeParameters = parseTypeParameters(); @@ -7690,8 +6835,8 @@ namespace Parser { const node = factory.createConstructorDeclaration(modifiers, parameters, body); // Attach invalid nodes if they exist so that we can report them in the grammar checker. - (node as Mutable).typeParameters = typeParameters; - (node as Mutable).type = type; + node.data.typeParameters = typeParameters; + node.data.type = type; return withJSDoc(finishNode(node, pos), hasJSDoc); } }); @@ -7700,15 +6845,15 @@ namespace Parser { function parseMethodDeclaration( pos: number, hasJSDoc: boolean, - modifiers: NodeArray | undefined, - asteriskToken: AsteriskToken | undefined, - name: PropertyName, - questionToken: QuestionToken | undefined, - exclamationToken: ExclamationToken | undefined, + modifiers: AstNodeArray | undefined, + asteriskToken: AstAsteriskToken | undefined, + name: AstPropertyName, + questionToken: AstQuestionToken | undefined, + exclamationToken: AstExclamationToken | undefined, diagnosticMessage?: DiagnosticMessage, - ): MethodDeclaration { + ): AstMethodDeclaration { const isGenerator = asteriskToken ? SignatureFlags.Yield : SignatureFlags.None; - const isAsync = some(modifiers, isAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; + const isAsync = some(modifiers?.items, isAstAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; const typeParameters = parseTypeParameters(); const parameters = parseParameters(isGenerator | isAsync); const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); @@ -7725,17 +6870,17 @@ namespace Parser { ); // An exclamation token on a method is invalid syntax and will be handled by the grammar checker - (node as Mutable).exclamationToken = exclamationToken; + node.data.exclamationToken = exclamationToken; return withJSDoc(finishNode(node, pos), hasJSDoc); } function parsePropertyDeclaration( pos: number, hasJSDoc: boolean, - modifiers: NodeArray | undefined, - name: PropertyName, - questionToken: QuestionToken | undefined, - ): PropertyDeclaration { + modifiers: AstNodeArray | undefined, + name: AstPropertyName, + questionToken: AstQuestionToken | undefined, + ): AstPropertyDeclaration { const exclamationToken = !questionToken && !scanner.hasPrecedingLineBreak() ? parseOptionalToken(SyntaxKind.ExclamationToken) : undefined; const type = parseTypeAnnotation(); const initializer = doOutsideOfContext(NodeFlags.YieldContext | NodeFlags.AwaitContext | NodeFlags.DisallowInContext, parseInitializer); @@ -7753,8 +6898,8 @@ namespace Parser { function parsePropertyOrMethodDeclaration( pos: number, hasJSDoc: boolean, - modifiers: NodeArray | undefined, - ): PropertyDeclaration | MethodDeclaration { + modifiers: AstNodeArray | undefined, + ): AstPropertyDeclaration | AstMethodDeclaration { const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); const name = parsePropertyName(); // Note: this is not legal as per the grammar. But we allow it in the parser and @@ -7766,7 +6911,7 @@ namespace Parser { return parsePropertyDeclaration(pos, hasJSDoc, modifiers, name, questionToken); } - function parseAccessorDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined, kind: AccessorDeclaration["kind"], flags: SignatureFlags): AccessorDeclaration { + function parseAccessorDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined, kind: AstAccessorDeclaration["kind"], flags: SignatureFlags): AstAccessorDeclaration { const name = parsePropertyName(); const typeParameters = parseTypeParameters(); const parameters = parseParameters(SignatureFlags.None); @@ -7776,8 +6921,10 @@ namespace Parser { ? factory.createGetAccessorDeclaration(modifiers, name, parameters, type, body) : factory.createSetAccessorDeclaration(modifiers, name, parameters, body); // Keep track of `typeParameters` (for both) and `type` (for setters) if they were parsed those indicate grammar errors - (node as Mutable).typeParameters = typeParameters; - if (isSetAccessorDeclaration(node)) (node as Mutable).type = type; + node.data.typeParameters = typeParameters; + if (isAstSetAccessorDeclaration(node)) { + node.data.type = type; + } return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -7850,11 +6997,11 @@ namespace Parser { return false; } - function parseClassStaticBlockDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): ClassStaticBlockDeclaration { + function parseClassStaticBlockDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstClassStaticBlockDeclaration { parseExpectedToken(SyntaxKind.StaticKeyword); const body = parseClassStaticBlockBody(); const node = withJSDoc(finishNode(factory.createClassStaticBlockDeclaration(body), pos), hasJSDoc); - (node as Mutable).modifiers = modifiers; + node.data.modifiers = modifiers; return node; } @@ -7886,7 +7033,7 @@ namespace Parser { return parseLeftHandSideExpressionOrHigher(); } - function tryParseDecorator(): Decorator | undefined { + function tryParseDecorator(): AstDecorator | undefined { const pos = getNodePos(); if (!parseOptional(SyntaxKind.AtToken)) { return undefined; @@ -7895,7 +7042,7 @@ namespace Parser { return finishNode(factory.createDecorator(expression), pos); } - function tryParseModifier(hasSeenStaticModifier: boolean, permitConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): Modifier | undefined { + function tryParseModifier(hasSeenStaticModifier: boolean, permitConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): AstModifier | undefined { const pos = getNodePos(); const kind = token(); @@ -7918,7 +7065,7 @@ namespace Parser { } } - return finishNode(factoryCreateToken(kind as Modifier["kind"]), pos); + return finishNode(factoryCreateToken(kind as AstModifier["kind"]) as AstModifier, pos); } /* @@ -7928,11 +7075,11 @@ namespace Parser { * * In such situations, 'permitConstAsModifier' should be set to true. */ - function parseModifiers(allowDecorators: false, permitConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): NodeArray | undefined; - function parseModifiers(allowDecorators: true, permitConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): NodeArray | undefined; - function parseModifiers(allowDecorators: boolean, permitConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): NodeArray | undefined { + function parseModifiers(allowDecorators: false, permitConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): AstNodeArray | undefined; + function parseModifiers(allowDecorators: true, permitConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): AstNodeArray | undefined; + function parseModifiers(allowDecorators: boolean, permitConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): AstNodeArray | undefined { const pos = getNodePos(); - let list: ModifierLike[] | undefined; + let list: AstModifierLike[] | undefined; let decorator, modifier, hasSeenStaticModifier = false, hasLeadingModifier = false, hasTrailingDecorator = false; // Decorators should be contiguous in a list of modifiers but can potentially appear in two places (i.e., `[...leadingDecorators, ...leadingModifiers, ...trailingDecorators, ...trailingModifiers]`). @@ -7972,18 +7119,18 @@ namespace Parser { return list && createNodeArray(list, pos); } - function parseModifiersForArrowFunction(): NodeArray | undefined { - let modifiers: NodeArray | undefined; + function parseModifiersForArrowFunction(): AstNodeArray | undefined { + let modifiers: AstNodeArray | undefined; if (token() === SyntaxKind.AsyncKeyword) { const pos = getNodePos(); nextToken(); const modifier = finishNode(factoryCreateToken(SyntaxKind.AsyncKeyword), pos); - modifiers = createNodeArray([modifier], pos); + modifiers = createNodeArray([modifier], pos); } return modifiers; } - function parseClassElement(): ClassElement { + function parseClassElement(): AstClassElement { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); if (token() === SyntaxKind.SemicolonToken) { @@ -8025,10 +7172,10 @@ namespace Parser { token() === SyntaxKind.AsteriskToken || token() === SyntaxKind.OpenBracketToken ) { - const isAmbient = some(modifiers, isDeclareModifier); + const isAmbient = some(modifiers?.items, isAstDeclareKeyword); if (isAmbient) { - for (const m of modifiers!) { - (m as Mutable).flags |= NodeFlags.Ambient; + for (const m of modifiers!.items) { + m.flags |= NodeFlags.Ambient; } return doInsideOfContext(NodeFlags.Ambient, () => parsePropertyOrMethodDeclaration(pos, hasJSDoc, modifiers)); } @@ -8039,7 +7186,7 @@ namespace Parser { if (modifiers) { // treat this as a property declaration with a missing name. - const name = createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); + const name = createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); return parsePropertyDeclaration(pos, hasJSDoc, modifiers, name, /*questionToken*/ undefined); } @@ -8047,36 +7194,36 @@ namespace Parser { return Debug.fail("Should not have attempted to parse class member declaration."); } - function parseDecoratedExpression(): PrimaryExpression { + function parseDecoratedExpression(): AstPrimaryExpression { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); const modifiers = parseModifiers(/*allowDecorators*/ true); if (token() === SyntaxKind.ClassKeyword) { - return parseClassDeclarationOrExpression(pos, hasJSDoc, modifiers, SyntaxKind.ClassExpression) as ClassExpression; + return parseClassDeclarationOrExpression(pos, hasJSDoc, modifiers, SyntaxKind.ClassExpression) as AstClassExpression; } - const missing = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Expression_expected); + const missing = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Expression_expected); setTextRangePos(missing, pos); - (missing as Mutable).modifiers = modifiers; + missing.data.modifiers = modifiers; return missing; } - function parseClassExpression(): ClassExpression { - return parseClassDeclarationOrExpression(getNodePos(), hasPrecedingJSDocComment(), /*modifiers*/ undefined, SyntaxKind.ClassExpression) as ClassExpression; + function parseClassExpression(): AstClassExpression { + return parseClassDeclarationOrExpression(getNodePos(), hasPrecedingJSDocComment(), /*modifiers*/ undefined, SyntaxKind.ClassExpression) as AstClassExpression; } - function parseClassDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): ClassDeclaration { - return parseClassDeclarationOrExpression(pos, hasJSDoc, modifiers, SyntaxKind.ClassDeclaration) as ClassDeclaration; + function parseClassDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstClassDeclaration { + return parseClassDeclarationOrExpression(pos, hasJSDoc, modifiers, SyntaxKind.ClassDeclaration) as AstClassDeclaration; } - function parseClassDeclarationOrExpression(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined, kind: ClassLikeDeclaration["kind"]): ClassLikeDeclaration { + function parseClassDeclarationOrExpression(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined, kind: AstClassLikeDeclaration["kind"]): AstClassLikeDeclaration { const savedAwaitContext = inAwaitContext(); parseExpected(SyntaxKind.ClassKeyword); // We don't parse the name here in await context, instead we will report a grammar error in the checker. const name = parseNameOfClassDeclarationOrExpression(); const typeParameters = parseTypeParameters(); - if (some(modifiers, isExportModifier)) setAwaitContext(/*value*/ true); + if (some(modifiers?.items, isAstExportModifier)) setAwaitContext(/*value*/ true); const heritageClauses = parseHeritageClauses(); let members; @@ -8087,7 +7234,7 @@ namespace Parser { parseExpected(SyntaxKind.CloseBraceToken); } else { - members = createMissingList(); + members = createMissingList(); } setAwaitContext(savedAwaitContext); const node = kind === SyntaxKind.ClassDeclaration @@ -8096,7 +7243,7 @@ namespace Parser { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseNameOfClassDeclarationOrExpression(): Identifier | undefined { + function parseNameOfClassDeclarationOrExpression(): AstIdentifier | undefined { // implements is a future reserved word so // 'class implements' might mean either // - class expression with omitted name, 'implements' starts heritage clause @@ -8111,7 +7258,7 @@ namespace Parser { return token() === SyntaxKind.ImplementsKeyword && lookAhead(nextTokenIsIdentifierOrKeyword); } - function parseHeritageClauses(): NodeArray | undefined { + function parseHeritageClauses(): AstNodeArray | undefined { // ClassTail[Yield,Await] : (Modified) See 14.5 // ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt } @@ -8122,7 +7269,7 @@ namespace Parser { return undefined; } - function parseHeritageClause(): HeritageClause { + function parseHeritageClause(): AstHeritageClause { const pos = getNodePos(); const tok = token(); Debug.assert(tok === SyntaxKind.ExtendsKeyword || tok === SyntaxKind.ImplementsKeyword); // isListElement() should ensure this. @@ -8131,17 +7278,17 @@ namespace Parser { return finishNode(factory.createHeritageClause(tok, types), pos); } - function parseExpressionWithTypeArguments(): ExpressionWithTypeArguments { + function parseExpressionWithTypeArguments(): AstExpressionWithTypeArguments { const pos = getNodePos(); const expression = parseLeftHandSideExpressionOrHigher(); if (expression.kind === SyntaxKind.ExpressionWithTypeArguments) { - return expression as ExpressionWithTypeArguments; + return expression as AstExpressionWithTypeArguments; } const typeArguments = tryParseTypeArguments(); return finishNode(factory.createExpressionWithTypeArguments(expression, typeArguments), pos); } - function tryParseTypeArguments(): NodeArray | undefined { + function tryParseTypeArguments(): AstNodeArray | undefined { return token() === SyntaxKind.LessThanToken ? parseBracketedList(ParsingContext.TypeArguments, parseType, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken) : undefined; } @@ -8150,11 +7297,11 @@ namespace Parser { return token() === SyntaxKind.ExtendsKeyword || token() === SyntaxKind.ImplementsKeyword; } - function parseClassMembers(): NodeArray { + function parseClassMembers(): AstNodeArray { return parseList(ParsingContext.ClassMembers, parseClassElement); } - function parseInterfaceDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): InterfaceDeclaration { + function parseInterfaceDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstInterfaceDeclaration { parseExpected(SyntaxKind.InterfaceKeyword); const name = parseIdentifier(); const typeParameters = parseTypeParameters(); @@ -8164,7 +7311,7 @@ namespace Parser { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseTypeAliasDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): TypeAliasDeclaration { + function parseTypeAliasDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstTypeAliasDeclaration { parseExpected(SyntaxKind.TypeKeyword); if (scanner.hasPrecedingLineBreak()) { parseErrorAtCurrentToken(Diagnostics.Line_break_not_permitted_here); @@ -8182,7 +7329,7 @@ namespace Parser { // In a non-ambient declaration, the grammar allows uninitialized members only in a // ConstantEnumMemberSection, which starts at the beginning of an enum declaration // or any time an integer literal initializer is encountered. - function parseEnumMember(): EnumMember { + function parseEnumMember(): AstEnumMember { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); const name = parsePropertyName(); @@ -8190,7 +7337,7 @@ namespace Parser { return withJSDoc(finishNode(factory.createEnumMember(name, initializer), pos), hasJSDoc); } - function parseEnumDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): EnumDeclaration { + function parseEnumDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstEnumDeclaration { parseExpected(SyntaxKind.EnumKeyword); const name = parseIdentifier(); let members; @@ -8199,13 +7346,13 @@ namespace Parser { parseExpected(SyntaxKind.CloseBraceToken); } else { - members = createMissingList(); + members = createMissingList(); } const node = factory.createEnumDeclaration(modifiers, name, members); return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseModuleBlock(): ModuleBlock { + function parseModuleBlock(): AstModuleBlock { const pos = getNodePos(); let statements; if (parseExpected(SyntaxKind.OpenBraceToken)) { @@ -8213,24 +7360,24 @@ namespace Parser { parseExpected(SyntaxKind.CloseBraceToken); } else { - statements = createMissingList(); + statements = createMissingList(); } return finishNode(factory.createModuleBlock(statements), pos); } - function parseModuleOrNamespaceDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined, flags: NodeFlags): ModuleDeclaration { + function parseModuleOrNamespaceDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined, flags: NodeFlags): AstModuleDeclaration { // If we are parsing a dotted namespace name, we want to // propagate the 'Namespace' flag across the names if set. const namespaceFlag = flags & NodeFlags.Namespace; const name = flags & NodeFlags.NestedNamespace ? parseIdentifierName() : parseIdentifier(); const body = parseOptional(SyntaxKind.DotToken) - ? parseModuleOrNamespaceDeclaration(getNodePos(), /*hasJSDoc*/ false, /*modifiers*/ undefined, NodeFlags.NestedNamespace | namespaceFlag) as NamespaceDeclaration + ? parseModuleOrNamespaceDeclaration(getNodePos(), /*hasJSDoc*/ false, /*modifiers*/ undefined, NodeFlags.NestedNamespace | namespaceFlag) as AstNamespaceDeclaration : parseModuleBlock(); const node = factory.createModuleDeclaration(modifiers, name, body, flags); return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseAmbientExternalModuleDeclaration(pos: number, hasJSDoc: boolean, modifiersIn: NodeArray | undefined): ModuleDeclaration { + function parseAmbientExternalModuleDeclaration(pos: number, hasJSDoc: boolean, modifiersIn: AstNodeArray | undefined): AstModuleDeclaration { let flags: NodeFlags = 0; let name; if (token() === SyntaxKind.GlobalKeyword) { @@ -8239,10 +7386,10 @@ namespace Parser { flags |= NodeFlags.GlobalAugmentation; } else { - name = parseLiteralNode() as StringLiteral; - name.text = internIdentifier(name.text); + name = parseLiteralNode() as AstStringLiteral; + name.data.text = internIdentifier(name.data.text); } - let body: ModuleBlock | undefined; + let body: AstModuleBlock | undefined; if (token() === SyntaxKind.OpenBraceToken) { body = parseModuleBlock(); } @@ -8253,7 +7400,7 @@ namespace Parser { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseModuleDeclaration(pos: number, hasJSDoc: boolean, modifiersIn: NodeArray | undefined): ModuleDeclaration { + function parseModuleDeclaration(pos: number, hasJSDoc: boolean, modifiersIn: AstNodeArray | undefined): AstModuleDeclaration { let flags: NodeFlags = 0; if (token() === SyntaxKind.GlobalKeyword) { // global augmentation @@ -8288,31 +7435,31 @@ namespace Parser { return nextToken() === SyntaxKind.SlashToken; } - function parseNamespaceExportDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): NamespaceExportDeclaration { + function parseNamespaceExportDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstNamespaceExportDeclaration { parseExpected(SyntaxKind.AsKeyword); parseExpected(SyntaxKind.NamespaceKeyword); const name = parseIdentifier(); parseSemicolon(); const node = factory.createNamespaceExportDeclaration(name); // NamespaceExportDeclaration nodes cannot have decorators or modifiers, so we attach them here so we can report them in the grammar checker - (node as Mutable).modifiers = modifiers; + node.data.modifiers = modifiers; return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseImportDeclarationOrImportEqualsDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): ImportEqualsDeclaration | ImportDeclaration { + function parseImportDeclarationOrImportEqualsDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstImportEqualsDeclaration | AstImportDeclaration { parseExpected(SyntaxKind.ImportKeyword); const afterImportPos = scanner.getTokenFullStart(); // We don't parse the identifier here in await context, instead we will report a grammar error in the checker. - let identifier: Identifier | undefined; + let identifier: AstIdentifier | undefined; if (isIdentifier()) { identifier = parseIdentifier(); } let isTypeOnly = false; if ( - identifier?.escapedText === "type" && + identifier?.data.escapedText === "type" && (token() !== SyntaxKind.FromKeyword || isIdentifier() && lookAhead(nextTokenIsFromKeywordOrEqualsToken)) && (isIdentifier() || tokenAfterImportDefinitelyProducesImportDeclaration()) ) { @@ -8333,11 +7480,11 @@ namespace Parser { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function tryParseImportClause(identifier: Identifier | undefined, pos: number, isTypeOnly: boolean, skipJsDocLeadingAsterisks = false) { + function tryParseImportClause(identifier: AstIdentifier | undefined, pos: number, isTypeOnly: boolean, skipJsDocLeadingAsterisks = false) { // ImportDeclaration: // import ImportClause from ModuleSpecifier ; // import ModuleSpecifier; - let importClause: ImportClause | undefined; + let importClause: AstImportClause | undefined; if ( identifier || // import id token() === SyntaxKind.AsteriskToken || // import * @@ -8358,7 +7505,7 @@ namespace Parser { function parseImportAttribute() { const pos = getNodePos(); - const name = tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral; + const name = tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(SyntaxKind.StringLiteral) as AstStringLiteral; parseExpected(SyntaxKind.ColonToken); const value = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); return finishNode(factory.createImportAttribute(name, value), pos); @@ -8400,7 +7547,7 @@ namespace Parser { return token() === SyntaxKind.CommaToken || token() === SyntaxKind.FromKeyword; } - function parseImportEqualsDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined, identifier: Identifier, isTypeOnly: boolean): ImportEqualsDeclaration { + function parseImportEqualsDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined, identifier: AstIdentifier, isTypeOnly: boolean): AstImportEqualsDeclaration { parseExpected(SyntaxKind.EqualsToken); const moduleReference = parseModuleReference(); parseSemicolon(); @@ -8409,7 +7556,7 @@ namespace Parser { return finished; } - function parseImportClause(identifier: Identifier | undefined, pos: number, isTypeOnly: boolean, skipJsDocLeadingAsterisks: boolean) { + function parseImportClause(identifier: AstIdentifier | undefined, pos: number, isTypeOnly: boolean, skipJsDocLeadingAsterisks: boolean) { // ImportClause: // ImportedDefaultBinding // NameSpaceImport @@ -8419,7 +7566,7 @@ namespace Parser { // If there was no default import or if there is comma token after default import // parse namespace or named imports - let namedBindings: NamespaceImport | NamedImports | undefined; + let namedBindings: AstNamespaceImport | AstNamedImports | undefined; if ( !identifier || parseOptional(SyntaxKind.CommaToken) @@ -8447,10 +7594,10 @@ namespace Parser { return finishNode(factory.createExternalModuleReference(expression), pos); } - function parseModuleSpecifier(): Expression { + function parseModuleSpecifier(): AstExpression { if (token() === SyntaxKind.StringLiteral) { const result = parseLiteralNode(); - result.text = internIdentifier(result.text); + result.data.text = internIdentifier(result.data.text); return result; } else { @@ -8461,7 +7608,7 @@ namespace Parser { } } - function parseNamespaceImport(): NamespaceImport { + function parseNamespaceImport(): AstNamespaceImport { // NameSpaceImport: // * as ImportedBinding const pos = getNodePos(); @@ -8475,13 +7622,13 @@ namespace Parser { return tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.StringLiteral; } - function parseModuleExportName(parseName: () => Identifier): ModuleExportName { - return token() === SyntaxKind.StringLiteral ? parseLiteralNode() as StringLiteral : parseName(); + function parseModuleExportName(parseName: () => AstIdentifier): AstModuleExportName { + return token() === SyntaxKind.StringLiteral ? parseLiteralNode() as AstStringLiteral : parseName(); } - function parseNamedImportsOrExports(kind: SyntaxKind.NamedImports): NamedImports; - function parseNamedImportsOrExports(kind: SyntaxKind.NamedExports): NamedExports; - function parseNamedImportsOrExports(kind: SyntaxKind): NamedImportsOrExports { + function parseNamedImportsOrExports(kind: SyntaxKind.NamedImports): AstNamedImports; + function parseNamedImportsOrExports(kind: SyntaxKind.NamedExports): AstNamedExports; + function parseNamedImportsOrExports(kind: SyntaxKind): AstNamedImports | AstNamedExports { const pos = getNodePos(); // NamedImports: @@ -8500,14 +7647,14 @@ namespace Parser { function parseExportSpecifier() { const hasJSDoc = hasPrecedingJSDocComment(); - return withJSDoc(parseImportOrExportSpecifier(SyntaxKind.ExportSpecifier) as ExportSpecifier, hasJSDoc); + return withJSDoc(parseImportOrExportSpecifier(SyntaxKind.ExportSpecifier) as AstExportSpecifier, hasJSDoc); } function parseImportSpecifier() { - return parseImportOrExportSpecifier(SyntaxKind.ImportSpecifier) as ImportSpecifier; + return parseImportOrExportSpecifier(SyntaxKind.ImportSpecifier) as AstImportSpecifier; } - function parseImportOrExportSpecifier(kind: SyntaxKind): ImportOrExportSpecifier { + function parseImportOrExportSpecifier(kind: SyntaxKind): AstImportSpecifier | AstExportSpecifier { const pos = getNodePos(); // ImportSpecifier: // BindingIdentifier @@ -8519,10 +7666,10 @@ namespace Parser { let checkIdentifierStart = scanner.getTokenStart(); let checkIdentifierEnd = scanner.getTokenEnd(); let isTypeOnly = false; - let propertyName: ModuleExportName | undefined; + let propertyName: AstModuleExportName | undefined; let canParseAsKeyword = true; let name = parseModuleExportName(parseIdentifierName); - if (name.kind === SyntaxKind.Identifier && name.escapedText === "type") { + if (name.kind === SyntaxKind.Identifier && name.data.escapedText === "type") { // If the first token of an import specifier is 'type', there are a lot of possibilities, // especially if we see 'as' afterwards: // @@ -8581,14 +7728,14 @@ namespace Parser { if (name.kind !== SyntaxKind.Identifier) { // ImportSpecifier casts "name" to Identifier below, so make sure it's an identifier parseErrorAt(skipTrivia(sourceText, name.pos), name.end, Diagnostics.Identifier_expected); - name = setTextRangePosEnd(createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false), name.pos, name.pos); + name = setTextRangePosEnd(createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false), name.pos, name.pos); } else if (checkIdentifierIsKeyword) { parseErrorAt(checkIdentifierStart, checkIdentifierEnd, Diagnostics.Identifier_expected); } } const node = kind === SyntaxKind.ImportSpecifier - ? factory.createImportSpecifier(isTypeOnly, propertyName, name as Identifier) + ? factory.createImportSpecifier(isTypeOnly, propertyName, name as AstIdentifier) : factory.createExportSpecifier(isTypeOnly, propertyName, name); return finishNode(node, pos); @@ -8600,16 +7747,16 @@ namespace Parser { } } - function parseNamespaceExport(pos: number): NamespaceExport { + function parseNamespaceExport(pos: number): AstNamespaceExport { return finishNode(factory.createNamespaceExport(parseModuleExportName(parseIdentifierName)), pos); } - function parseExportDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): ExportDeclaration { + function parseExportDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstExportDeclaration { const savedAwaitContext = inAwaitContext(); setAwaitContext(/*value*/ true); - let exportClause: NamedExportBindings | undefined; - let moduleSpecifier: Expression | undefined; - let attributes: ImportAttributes | undefined; + let exportClause: AstNamedExportBindings | undefined; + let moduleSpecifier: AstExpression | undefined; + let attributes: AstImportAttributes | undefined; const isTypeOnly = parseOptional(SyntaxKind.TypeKeyword); const namespaceExportPos = getNodePos(); if (parseOptional(SyntaxKind.AsteriskToken)) { @@ -8639,7 +7786,7 @@ namespace Parser { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseExportAssignment(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): ExportAssignment { + function parseExportAssignment(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstExportAssignment { const savedAwaitContext = inAwaitContext(); setAwaitContext(/*value*/ true); let isExportEquals: boolean | undefined; @@ -8701,18 +7848,18 @@ namespace Parser { const jsDocTypeExpression = parseJSDocTypeExpression(); const sourceFile = createSourceFile("file.js", ScriptTarget.Latest, ScriptKind.JS, /*isDeclarationFile*/ false, [], factoryCreateToken(SyntaxKind.EndOfFileToken), NodeFlags.None, noop); - const diagnostics = attachFileToDiagnostics(parseDiagnostics, sourceFile); + const diagnostics = attachFileToDiagnostics(parseDiagnostics, sourceFile.node); // TODO(rbuckton): do not instantiate node if (jsDocDiagnostics) { - sourceFile.jsDocDiagnostics = attachFileToDiagnostics(jsDocDiagnostics, sourceFile); + sourceFile.data.jsDocDiagnostics = attachFileToDiagnostics(jsDocDiagnostics, sourceFile.node); // TODO(rbuckton): do not instantiate node } clearState(); - return jsDocTypeExpression ? { jsDocTypeExpression, diagnostics } : undefined; + return jsDocTypeExpression ? { jsDocTypeExpression: jsDocTypeExpression.node, diagnostics } : undefined; } // Parses out a JSDoc type expression. - export function parseJSDocTypeExpression(mayOmitBraces?: boolean): JSDocTypeExpression { + export function parseJSDocTypeExpression(mayOmitBraces?: boolean): AstJSDocTypeExpression { const pos = getNodePos(); const hasBrace = (mayOmitBraces ? parseOptional : parseExpected)(SyntaxKind.OpenBraceToken); const type = doInsideOfContext(NodeFlags.JSDoc, parseJSDocType); @@ -8725,11 +7872,11 @@ namespace Parser { return finishNode(result, pos); } - export function parseJSDocNameReference(): JSDocNameReference { + export function parseJSDocNameReference(): AstJSDocNameReference { const pos = getNodePos(); const hasBrace = parseOptional(SyntaxKind.OpenBraceToken); const p2 = getNodePos(); - let entityName: EntityName | JSDocMemberName = parseEntityName(/*allowReservedWords*/ false); + let entityName: AstEntityName | AstJSDocMemberName = parseEntityName(/*allowReservedWords*/ false); while (token() === SyntaxKind.PrivateIdentifier) { reScanHashToken(); // rescan #id as # id nextTokenJSDoc(); // then skip the # @@ -8752,10 +7899,10 @@ namespace Parser { const diagnostics = attachFileToDiagnostics(parseDiagnostics, sourceFile); clearState(); - return jsDoc ? { jsDoc, diagnostics } : undefined; + return jsDoc ? { jsDoc: jsDoc.node, diagnostics } : undefined; } - export function parseJSDocComment(parent: HasJSDoc, start: number, length: number): JSDoc | undefined { + export function parseJSDocComment(parent: AstHasJSDoc, start: number, length: number): AstJSDocNode | undefined { const saveToken = currentToken; const saveParseDiagnosticsLength = parseDiagnostics.length; const saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; @@ -8788,7 +7935,7 @@ namespace Parser { CallbackParameter = 1 << 2, } - function parseJSDocCommentWorker(start = 0, length: number | undefined): JSDoc | undefined { + function parseJSDocCommentWorker(start = 0, length: number | undefined): AstJSDocNode | undefined { const content = sourceText; const end = length === undefined ? content.length : start + length; length = end - start; @@ -8802,13 +7949,13 @@ namespace Parser { return undefined; } - let tags: JSDocTag[]; + let tags: AstJSDocTag[]; let tagsPos: number; let tagsEnd: number; let linkEnd: number; let commentsPos: number | undefined; let comments: string[] = []; - const parts: JSDocComment[] = []; + const parts: AstJSDocComment[] = []; const saveParsingContext = parsingContext; parsingContext |= 1 << ParsingContext.JSDocComment; @@ -9006,8 +8153,8 @@ namespace Parser { const tagName = parseJSDocIdentifierName(/*message*/ undefined); const indentText = skipWhitespaceOrAsterisk(); - let tag: JSDocTag | undefined; - switch (tagName.escapedText) { + let tag: AstJSDocTag | undefined; + switch (tagName.data.escapedText) { case "author": tag = parseAuthorTag(start, tagName, margin, indentText); break; @@ -9098,10 +8245,10 @@ namespace Parser { return parseTagComments(margin, indentText.slice(margin)); } - function parseTagComments(indent: number, initialMargin?: string): string | NodeArray | undefined { + function parseTagComments(indent: number, initialMargin?: string): string | AstNodeArray | undefined { const commentsPos = getNodePos(); let comments: string[] = []; - const parts: JSDocComment[] = []; + const parts: AstJSDocComment[] = []; let linkEnd; let state = JSDocState.BeginningOfLine; let margin: number | undefined; @@ -9235,9 +8382,9 @@ namespace Parser { if (tokenIsIdentifierOrKeyword(token())) { const pos = getNodePos(); - let name: EntityName | JSDocMemberName = parseIdentifierName(); + let name: AstEntityName | AstJSDocMemberName = parseIdentifierName(); while (parseOptional(SyntaxKind.DotToken)) { - name = finishNode(factory.createQualifiedName(name, token() === SyntaxKind.PrivateIdentifier ? createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false) : parseIdentifierName()), pos); + name = finishNode(factory.createQualifiedName(name, token() === SyntaxKind.PrivateIdentifier ? createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false) : parseIdentifierName()), pos); } while (token() === SyntaxKind.PrivateIdentifier) { reScanHashToken(); @@ -9265,11 +8412,11 @@ namespace Parser { return kind === "link" || kind === "linkcode" || kind === "linkplain"; } - function parseUnknownTag(start: number, tagName: Identifier, indent: number, indentText: string) { + function parseUnknownTag(start: number, tagName: AstIdentifier, indent: number, indentText: string) { return finishNode(factory.createJSDocUnknownTag(tagName, parseTrailingTagComments(start, getNodePos(), indent, indentText)), start); } - function addTag(tag: JSDocTag | undefined): void { + function addTag(tag: AstJSDocTag | undefined): void { if (!tag) { return; } @@ -9283,12 +8430,12 @@ namespace Parser { tagsEnd = tag.end; } - function tryParseTypeExpression(): JSDocTypeExpression | undefined { + function tryParseTypeExpression(): AstJSDocTypeExpression | undefined { skipWhitespaceOrAsterisk(); return token() === SyntaxKind.OpenBraceToken ? parseJSDocTypeExpression() : undefined; } - function parseBracketNameInPropertyAndParamTag(): { name: EntityName; isBracketed: boolean; } { + function parseBracketNameInPropertyAndParamTag(): { name: AstEntityName; isBracketed: boolean; } { // Looking for something like '[foo]', 'foo', '[foo.bar]' or 'foo.bar' const isBracketed = parseOptionalJsdoc(SyntaxKind.OpenBracketToken); if (isBracketed) { @@ -9313,18 +8460,18 @@ namespace Parser { return { name, isBracketed }; } - function isObjectOrObjectArrayTypeReference(node: TypeNode): boolean { + function isObjectOrObjectArrayTypeReference(node: AstTypeNode): boolean { switch (node.kind) { case SyntaxKind.ObjectKeyword: return true; case SyntaxKind.ArrayType: - return isObjectOrObjectArrayTypeReference((node as ArrayTypeNode).elementType); + return isObjectOrObjectArrayTypeReference((node as AstArrayTypeNode).data.elementType); default: - return isTypeReferenceNode(node) && isIdentifierNode(node.typeName) && node.typeName.escapedText === "Object" && !node.typeArguments; + return isAstTypeReferenceNode(node) && isAstIdentifier(node.data.typeName) && node.data.typeName.data.escapedText === "Object" && !node.data.typeArguments; } } - function parseParameterOrPropertyTag(start: number, tagName: Identifier, target: PropertyLikeParse, indent: number): JSDocParameterTag | JSDocPropertyTag { + function parseParameterOrPropertyTag(start: number, tagName: AstIdentifier, target: PropertyLikeParse, indent: number): AstJSDocParameterTag | AstJSDocPropertyTag { let typeExpression = tryParseTypeExpression(); let isNameFirst = !typeExpression; skipWhitespaceOrAsterisk(); @@ -9349,38 +8496,38 @@ namespace Parser { return finishNode(result, start); } - function parseNestedTypeLiteral(typeExpression: JSDocTypeExpression | undefined, name: EntityName, target: PropertyLikeParse, indent: number) { - if (typeExpression && isObjectOrObjectArrayTypeReference(typeExpression.type)) { + function parseNestedTypeLiteral(typeExpression: AstJSDocTypeExpression | undefined, name: AstEntityName, target: PropertyLikeParse, indent: number) { + if (typeExpression && isObjectOrObjectArrayTypeReference(typeExpression.data.type)) { const pos = getNodePos(); - let child: JSDocPropertyLikeTag | JSDocTypeTag | JSDocTemplateTag | JSDocThisTag | false; - let children: JSDocPropertyLikeTag[] | undefined; + let child: AstJSDocPropertyLikeTag | AstJSDocTypeTag | AstJSDocTemplateTag | AstJSDocThisTag | false; + let children: AstJSDocPropertyLikeTag[] | undefined; while (child = tryParse(() => parseChildParameterOrPropertyTag(target, indent, name))) { if (child.kind === SyntaxKind.JSDocParameterTag || child.kind === SyntaxKind.JSDocPropertyTag) { children = append(children, child); } else if (child.kind === SyntaxKind.JSDocTemplateTag) { - parseErrorAtRange(child.tagName, Diagnostics.A_JSDoc_template_tag_may_not_follow_a_typedef_callback_or_overload_tag); + parseErrorAtRange(child.data.tagName, Diagnostics.A_JSDoc_template_tag_may_not_follow_a_typedef_callback_or_overload_tag); } } if (children) { - const literal = finishNode(factory.createJSDocTypeLiteral(children, typeExpression.type.kind === SyntaxKind.ArrayType), pos); + const literal = finishNode(factory.createJSDocTypeLiteral(children, typeExpression.data.type.kind === SyntaxKind.ArrayType), pos); return finishNode(factory.createJSDocTypeExpression(literal), pos); } } } - function parseReturnTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocReturnTag { - if (some(tags, isJSDocReturnTag)) { - parseErrorAt(tagName.pos, scanner.getTokenStart(), Diagnostics._0_tag_already_specified, unescapeLeadingUnderscores(tagName.escapedText)); + function parseReturnTag(start: number, tagName: AstIdentifier, indent: number, indentText: string): AstJSDocReturnTag { + if (some(tags, isAstJSDocReturnTag)) { + parseErrorAt(tagName.pos, scanner.getTokenStart(), Diagnostics._0_tag_already_specified, unescapeLeadingUnderscores(tagName.data.escapedText)); } const typeExpression = tryParseTypeExpression(); return finishNode(factory.createJSDocReturnTag(tagName, typeExpression, parseTrailingTagComments(start, getNodePos(), indent, indentText)), start); } - function parseTypeTag(start: number, tagName: Identifier, indent?: number, indentText?: string): JSDocTypeTag { - if (some(tags, isJSDocTypeTag)) { - parseErrorAt(tagName.pos, scanner.getTokenStart(), Diagnostics._0_tag_already_specified, unescapeLeadingUnderscores(tagName.escapedText)); + function parseTypeTag(start: number, tagName: AstIdentifier, indent?: number, indentText?: string): AstJSDocTypeTag { + if (some(tags, isAstJSDocTypeTag)) { + parseErrorAt(tagName.pos, scanner.getTokenStart(), Diagnostics._0_tag_already_specified, unescapeLeadingUnderscores(tagName.data.escapedText)); } const typeExpression = parseJSDocTypeExpression(/*mayOmitBraces*/ true); @@ -9388,7 +8535,7 @@ namespace Parser { return finishNode(factory.createJSDocTypeTag(tagName, typeExpression, comments), start); } - function parseSeeTag(start: number, tagName: Identifier, indent?: number, indentText?: string): JSDocSeeTag { + function parseSeeTag(start: number, tagName: AstIdentifier, indent?: number, indentText?: string): AstJSDocSeeTag { const isMarkdownOrJSDocLink = token() === SyntaxKind.OpenBracketToken || lookAhead(() => nextTokenJSDoc() === SyntaxKind.AtToken && tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && isJSDocLinkTag(scanner.getTokenValue())); const nameExpression = isMarkdownOrJSDocLink ? undefined : parseJSDocNameReference(); @@ -9396,13 +8543,13 @@ namespace Parser { return finishNode(factory.createJSDocSeeTag(tagName, nameExpression, comments), start); } - function parseThrowsTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocThrowsTag { + function parseThrowsTag(start: number, tagName: AstIdentifier, indent: number, indentText: string): AstJSDocThrowsTag { const typeExpression = tryParseTypeExpression(); const comment = parseTrailingTagComments(start, getNodePos(), indent, indentText); return finishNode(factory.createJSDocThrowsTag(tagName, typeExpression, comment), start); } - function parseAuthorTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocAuthorTag { + function parseAuthorTag(start: number, tagName: AstIdentifier, indent: number, indentText: string): AstJSDocAuthorTag { const commentStart = getNodePos(); const textOnly = parseAuthorNameAndEmail(); let commentEnd = scanner.getTokenFullStart(); @@ -9411,12 +8558,12 @@ namespace Parser { commentEnd = scanner.getTokenFullStart(); } const allParts = typeof comments !== "string" - ? createNodeArray(concatenate([finishNode(textOnly, commentStart, commentEnd)], comments) as JSDocComment[], commentStart) // cast away readonly - : textOnly.text + comments; + ? createNodeArray(concatenate([finishNode(textOnly, commentStart, commentEnd)], comments?.items) as AstJSDocComment[], commentStart) // cast away readonly + : textOnly.data.text + comments; return finishNode(factory.createJSDocAuthorTag(tagName, allParts), start); } - function parseAuthorNameAndEmail(): JSDocText { + function parseAuthorNameAndEmail(): AstJSDocText { const comments: string[] = []; let inEmail = false; let token = scanner.getToken(); @@ -9439,26 +8586,26 @@ namespace Parser { return factory.createJSDocText(comments.join("")); } - function parseImplementsTag(start: number, tagName: Identifier, margin: number, indentText: string): JSDocImplementsTag { + function parseImplementsTag(start: number, tagName: AstIdentifier, margin: number, indentText: string): AstJSDocImplementsTag { const className = parseExpressionWithTypeArgumentsForAugments(); return finishNode(factory.createJSDocImplementsTag(tagName, className, parseTrailingTagComments(start, getNodePos(), margin, indentText)), start); } - function parseAugmentsTag(start: number, tagName: Identifier, margin: number, indentText: string): JSDocAugmentsTag { + function parseAugmentsTag(start: number, tagName: AstIdentifier, margin: number, indentText: string): AstJSDocAugmentsTag { const className = parseExpressionWithTypeArgumentsForAugments(); return finishNode(factory.createJSDocAugmentsTag(tagName, className, parseTrailingTagComments(start, getNodePos(), margin, indentText)), start); } - function parseSatisfiesTag(start: number, tagName: Identifier, margin: number, indentText: string): JSDocSatisfiesTag { + function parseSatisfiesTag(start: number, tagName: AstIdentifier, margin: number, indentText: string): AstJSDocSatisfiesTag { const typeExpression = parseJSDocTypeExpression(/*mayOmitBraces*/ false); const comments = margin !== undefined && indentText !== undefined ? parseTrailingTagComments(start, getNodePos(), margin, indentText) : undefined; return finishNode(factory.createJSDocSatisfiesTag(tagName, typeExpression, comments), start); } - function parseImportTag(start: number, tagName: Identifier, margin: number, indentText: string): JSDocImportTag { + function parseImportTag(start: number, tagName: AstIdentifier, margin: number, indentText: string): AstJSDocImportTag { const afterImportTagPos = scanner.getTokenFullStart(); - let identifier: Identifier | undefined; + let identifier: AstIdentifier | undefined; if (isIdentifier()) { identifier = parseIdentifier(); } @@ -9471,14 +8618,14 @@ namespace Parser { return finishNode(factory.createJSDocImportTag(tagName, importClause, moduleSpecifier, attributes, comments), start); } - function parseExpressionWithTypeArgumentsForAugments(): ExpressionWithTypeArguments & { expression: Identifier | PropertyAccessEntityNameExpression; } { + function parseExpressionWithTypeArgumentsForAugments(): AstJSDocClassReference { const usedBrace = parseOptional(SyntaxKind.OpenBraceToken); const pos = getNodePos(); const expression = parsePropertyAccessEntityNameExpression(); scanner.setSkipJsDocLeadingAsterisks(true); const typeArguments = tryParseTypeArguments(); scanner.setSkipJsDocLeadingAsterisks(false); - const node = factory.createExpressionWithTypeArguments(expression, typeArguments) as ExpressionWithTypeArguments & { expression: Identifier | PropertyAccessEntityNameExpression; }; + const node = factory.createExpressionWithTypeArguments(expression, typeArguments) as AstJSDocClassReference; const res = finishNode(node, pos); if (usedBrace) { parseExpected(SyntaxKind.CloseBraceToken); @@ -9488,32 +8635,32 @@ namespace Parser { function parsePropertyAccessEntityNameExpression() { const pos = getNodePos(); - let node: Identifier | PropertyAccessEntityNameExpression = parseJSDocIdentifierName(); + let node: AstEntityNameExpression = parseJSDocIdentifierName(); while (parseOptional(SyntaxKind.DotToken)) { const name = parseJSDocIdentifierName(); - node = finishNode(factoryCreatePropertyAccessExpression(node, name), pos) as PropertyAccessEntityNameExpression; + node = finishNode(factoryCreatePropertyAccessExpression(node, name), pos) as AstPropertyAccessEntityNameExpression; } return node; } - function parseSimpleTag(start: number, createTag: (tagName: Identifier | undefined, comment?: string | NodeArray) => JSDocTag, tagName: Identifier, margin: number, indentText: string): JSDocTag { + function parseSimpleTag(start: number, createTag: (tagName: AstIdentifier | undefined, comment?: string | AstNodeArray) => AstJSDocTag, tagName: AstIdentifier, margin: number, indentText: string): AstJSDocTag { return finishNode(createTag(tagName, parseTrailingTagComments(start, getNodePos(), margin, indentText)), start); } - function parseThisTag(start: number, tagName: Identifier, margin: number, indentText: string): JSDocThisTag { + function parseThisTag(start: number, tagName: AstIdentifier, margin: number, indentText: string): AstJSDocThisTag { const typeExpression = parseJSDocTypeExpression(/*mayOmitBraces*/ true); skipWhitespace(); return finishNode(factory.createJSDocThisTag(tagName, typeExpression, parseTrailingTagComments(start, getNodePos(), margin, indentText)), start); } - function parseEnumTag(start: number, tagName: Identifier, margin: number, indentText: string): JSDocEnumTag { + function parseEnumTag(start: number, tagName: AstIdentifier, margin: number, indentText: string): AstJSDocEnumTag { const typeExpression = parseJSDocTypeExpression(/*mayOmitBraces*/ true); skipWhitespace(); return finishNode(factory.createJSDocEnumTag(tagName, typeExpression, parseTrailingTagComments(start, getNodePos(), margin, indentText)), start); } - function parseTypedefTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocTypedefTag { - let typeExpression: JSDocTypeExpression | JSDocTypeLiteral | undefined = tryParseTypeExpression(); + function parseTypedefTag(start: number, tagName: AstIdentifier, indent: number, indentText: string): AstJSDocTypedefTag { + let typeExpression: AstJSDocTypeExpression | AstJSDocTypeLiteral | undefined = tryParseTypeExpression(); skipWhitespaceOrAsterisk(); const fullName = parseJSDocTypeNameWithNamespace(); @@ -9521,10 +8668,10 @@ namespace Parser { let comment = parseTagComments(indent); let end: number | undefined; - if (!typeExpression || isObjectOrObjectArrayTypeReference(typeExpression.type)) { - let child: JSDocTypeTag | JSDocPropertyTag | JSDocTemplateTag | false; - let childTypeTag: JSDocTypeTag | undefined; - let jsDocPropertyTags: JSDocPropertyTag[] | undefined; + if (!typeExpression || isObjectOrObjectArrayTypeReference(typeExpression.data.type)) { + let child: AstJSDocTypeTag | AstJSDocPropertyTag | AstJSDocTemplateTag | false; + let childTypeTag: AstJSDocTypeTag | undefined; + let jsDocPropertyTags: AstJSDocPropertyTag[] | undefined; let hasChildren = false; while (child = tryParse(() => parseChildPropertyTag(indent))) { if (child.kind === SyntaxKind.JSDocTemplateTag) { @@ -9548,10 +8695,10 @@ namespace Parser { } } if (hasChildren) { - const isArrayType = typeExpression && typeExpression.type.kind === SyntaxKind.ArrayType; + const isArrayType = typeExpression && typeExpression.data.type.kind === SyntaxKind.ArrayType; const jsdocTypeLiteral = factory.createJSDocTypeLiteral(jsDocPropertyTags, isArrayType); - typeExpression = childTypeTag && childTypeTag.typeExpression && !isObjectOrObjectArrayTypeReference(childTypeTag.typeExpression.type) ? - childTypeTag.typeExpression : + typeExpression = childTypeTag && childTypeTag.data.typeExpression && !isObjectOrObjectArrayTypeReference(childTypeTag.data.typeExpression.data.type) ? + childTypeTag.data.typeExpression : finishNode(jsdocTypeLiteral, start); end = typeExpression.end; } @@ -9583,23 +8730,23 @@ namespace Parser { typeNameOrNamespaceName, body, nested ? NodeFlags.NestedNamespace : undefined, - ) as JSDocNamespaceDeclaration; + ) as AstJSDocNamespaceDeclaration; return finishNode(jsDocNamespaceNode, start); } if (nested) { - (typeNameOrNamespaceName as Mutable).flags |= NodeFlags.IdentifierIsInJSDocNamespace; + typeNameOrNamespaceName.flags |= NodeFlags.IdentifierIsInJSDocNamespace; } return typeNameOrNamespaceName; } function parseCallbackTagParameters(indent: number) { const pos = getNodePos(); - let child: JSDocParameterTag | JSDocTemplateTag | false; + let child: AstJSDocParameterTag | AstJSDocTemplateTag | false; let parameters; - while (child = tryParse(() => parseChildParameterOrPropertyTag(PropertyLikeParse.CallbackParameter, indent) as JSDocParameterTag | JSDocTemplateTag)) { + while (child = tryParse(() => parseChildParameterOrPropertyTag(PropertyLikeParse.CallbackParameter, indent) as AstJSDocParameterTag | AstJSDocTemplateTag)) { if (child.kind === SyntaxKind.JSDocTemplateTag) { - parseErrorAtRange(child.tagName, Diagnostics.A_JSDoc_template_tag_may_not_follow_a_typedef_callback_or_overload_tag); + parseErrorAtRange(child.data.tagName, Diagnostics.A_JSDoc_template_tag_may_not_follow_a_typedef_callback_or_overload_tag); break; } parameters = append(parameters, child); @@ -9607,20 +8754,20 @@ namespace Parser { return createNodeArray(parameters || [], pos); } - function parseJSDocSignature(start: number, indent: number): JSDocSignature { + function parseJSDocSignature(start: number, indent: number): AstJSDocSignature { const parameters = parseCallbackTagParameters(indent); const returnTag = tryParse(() => { if (parseOptionalJsdoc(SyntaxKind.AtToken)) { const tag = parseTag(indent); if (tag && tag.kind === SyntaxKind.JSDocReturnTag) { - return tag as JSDocReturnTag; + return tag as AstJSDocReturnTag; } } }); return finishNode(factory.createJSDocSignature(/*typeParameters*/ undefined, parameters, returnTag), start); } - function parseCallbackTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocCallbackTag { + function parseCallbackTag(start: number, tagName: AstIdentifier, indent: number, indentText: string): AstJSDocCallbackTag { const fullName = parseJSDocTypeNameWithNamespace(); skipWhitespace(); let comment = parseTagComments(indent); @@ -9632,7 +8779,7 @@ namespace Parser { return finishNode(factory.createJSDocCallbackTag(tagName, typeExpression, fullName, comment), start, end); } - function parseOverloadTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocOverloadTag { + function parseOverloadTag(start: number, tagName: AstIdentifier, indent: number, indentText: string): AstJSDocOverloadTag { skipWhitespace(); let comment = parseTagComments(indent); const typeExpression = parseJSDocSignature(start, indent); @@ -9643,24 +8790,24 @@ namespace Parser { return finishNode(factory.createJSDocOverloadTag(tagName, typeExpression, comment), start, end); } - function escapedTextsEqual(a: EntityName, b: EntityName): boolean { - while (!isIdentifierNode(a) || !isIdentifierNode(b)) { - if (!isIdentifierNode(a) && !isIdentifierNode(b) && a.right.escapedText === b.right.escapedText) { - a = a.left; - b = b.left; + function escapedTextsEqual(a: AstEntityName, b: AstEntityName): boolean { + while (!isAstIdentifier(a) || !isAstIdentifier(b)) { + if (!isAstIdentifier(a) && !isAstIdentifier(b) && a.data.right.data.escapedText === b.data.right.data.escapedText) { + a = a.data.left; + b = b.data.left; } else { return false; } } - return a.escapedText === b.escapedText; + return a.data.escapedText === b.data.escapedText; } function parseChildPropertyTag(indent: number) { - return parseChildParameterOrPropertyTag(PropertyLikeParse.Property, indent) as JSDocTypeTag | JSDocPropertyTag | JSDocTemplateTag | false; + return parseChildParameterOrPropertyTag(PropertyLikeParse.Property, indent) as AstJSDocTypeTag | AstJSDocPropertyTag | AstJSDocTemplateTag | false; } - function parseChildParameterOrPropertyTag(target: PropertyLikeParse, indent: number, name?: EntityName): JSDocTypeTag | JSDocPropertyTag | JSDocParameterTag | JSDocTemplateTag | JSDocThisTag | false { + function parseChildParameterOrPropertyTag(target: PropertyLikeParse, indent: number, name?: AstEntityName): AstJSDocTypeTag | AstJSDocPropertyTag | AstJSDocParameterTag | AstJSDocTemplateTag | AstJSDocThisTag | false { let canParseTag = true; let seenAsterisk = false; while (true) { @@ -9670,7 +8817,7 @@ namespace Parser { const child = tryParseChildTag(target, indent); if ( child && (child.kind === SyntaxKind.JSDocParameterTag || child.kind === SyntaxKind.JSDocPropertyTag) && - name && (isIdentifierNode(child.name) || !escapedTextsEqual(name, child.name.left)) + name && (isAstIdentifier(child.data.name) || !escapedTextsEqual(name, child.data.name.data.left)) ) { return false; } @@ -9697,7 +8844,7 @@ namespace Parser { } } - function tryParseChildTag(target: PropertyLikeParse, indent: number): JSDocTypeTag | JSDocPropertyTag | JSDocParameterTag | JSDocTemplateTag | JSDocThisTag | false { + function tryParseChildTag(target: PropertyLikeParse, indent: number): AstJSDocTypeTag | AstJSDocPropertyTag | AstJSDocParameterTag | AstJSDocTemplateTag | AstJSDocThisTag | false { Debug.assert(token() === SyntaxKind.AtToken); const start = scanner.getTokenFullStart(); nextTokenJSDoc(); @@ -9705,7 +8852,7 @@ namespace Parser { const tagName = parseJSDocIdentifierName(); const indentText = skipWhitespaceOrAsterisk(); let t: PropertyLikeParse; - switch (tagName.escapedText) { + switch (tagName.data.escapedText) { case "type": return target === PropertyLikeParse.Property && parseTypeTag(start, tagName); case "prop": @@ -9739,7 +8886,7 @@ namespace Parser { const modifiers = parseModifiers(/*allowDecorators*/ false, /*permitConstAsModifier*/ true); const name = parseJSDocIdentifierName(Diagnostics.Unexpected_token_A_type_parameter_name_was_expected_without_curly_braces); - let defaultType: TypeNode | undefined; + let defaultType: AstTypeNode | undefined; if (isBracketed) { skipWhitespace(); parseExpected(SyntaxKind.EqualsToken); @@ -9768,7 +8915,7 @@ namespace Parser { return createNodeArray(typeParameters, pos); } - function parseTemplateTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocTemplateTag { + function parseTemplateTag(start: number, tagName: AstIdentifier, indent: number, indentText: string): AstJSDocTemplateTag { // The template tag looks like one of the following: // @template T,U,V // @template {Constraint} T @@ -9793,8 +8940,8 @@ namespace Parser { return false; } - function parseJSDocEntityName(): EntityName { - let entity: EntityName = parseJSDocIdentifierName(); + function parseJSDocEntityName(): AstEntityName { + let entity: AstEntityName = parseJSDocIdentifierName(); if (parseOptional(SyntaxKind.OpenBracketToken)) { parseExpected(SyntaxKind.CloseBracketToken); // Note that y[] is accepted as an entity name, but the postfix brackets are not saved for checking. @@ -9811,17 +8958,16 @@ namespace Parser { return entity; } - function parseJSDocIdentifierName(message?: DiagnosticMessage): Identifier { + function parseJSDocIdentifierName(message?: DiagnosticMessage): AstIdentifier { if (!tokenIsIdentifierOrKeyword(token())) { - return createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ !message, message || Diagnostics.Identifier_expected); + return createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ !message, message || Diagnostics.Identifier_expected); } identifierCount++; const start = scanner.getTokenStart(); const end = scanner.getTokenEnd(); - const originalKeywordKind = token(); const text = internIdentifier(scanner.getTokenValue()); - const result = finishNode(factoryCreateIdentifier(text, originalKeywordKind), start, end); + const result = finishNode(factoryCreateIdentifier(text), start, end); nextTokenJSDoc(); return result; } @@ -9829,27 +8975,27 @@ namespace Parser { } } -const incrementallyParsedFiles = new WeakSet(); +const incrementallyParsedFiles = new WeakSet(); -function markAsIncrementallyParsed(sourceFile: SourceFile) { +function markAsIncrementallyParsed(sourceFile: AstSourceFile) { if (incrementallyParsedFiles.has(sourceFile)) { Debug.fail("Source file has already been incrementally parsed"); } incrementallyParsedFiles.add(sourceFile); } -const intersectingChangeSet = new WeakSet>(); +const intersectingChangeSet = new WeakSet>(); -function intersectsIncrementalChange(node: Node | NodeArray): boolean { +function intersectsIncrementalChange(node: AstNode | AstNodeArray): boolean { return intersectingChangeSet.has(node); } -function markAsIntersectingIncrementalChange(node: Node | NodeArray) { +function markAsIntersectingIncrementalChange(node: AstNode | AstNodeArray) { intersectingChangeSet.add(node); } namespace IncrementalParser { - export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks: boolean): SourceFile { + export function updateSourceFile(sourceFile: AstSourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks: boolean): AstSourceFile { aggressiveChecks = aggressiveChecks || Debug.shouldAssert(AssertionLevel.Aggressive); checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks); @@ -9858,10 +9004,10 @@ namespace IncrementalParser { return sourceFile; } - if (sourceFile.statements.length === 0) { + if (sourceFile.data.statements.items.length === 0) { // If we don't have any statements in the current source file, then there's no real // way to incrementally parse. So just do a full parse instead. - return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator, sourceFile.jsDocParsingMode); + return Parser.parseSourceFile(sourceFile.data.fileName, newText, sourceFile.data.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.data.scriptKind, sourceFile.data.setExternalModuleIndicator, sourceFile.data.jsDocParsingMode); } // Make sure we're not trying to incrementally update a source file more than once. Once @@ -9872,7 +9018,7 @@ namespace IncrementalParser { // tree at all is not possible as far too much of it may violate invariants. markAsIncrementallyParsed(sourceFile); Parser.fixupParentReferences(sourceFile); - const oldText = sourceFile.text; + const oldText = sourceFile.data.text; const syntaxCursor = createSyntaxCursor(sourceFile); // Make the actual change larger so that we know to reparse anything whose lookahead @@ -9922,10 +9068,10 @@ namespace IncrementalParser { // inconsistent tree. Setting the parents on the new tree should be very fast. We // will immediately bail out of walking any subtrees when we can see that their parents // are already correct. - const result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator, sourceFile.jsDocParsingMode); - result.commentDirectives = getNewCommentDirectives( - sourceFile.commentDirectives, - result.commentDirectives, + const result = Parser.parseSourceFile(sourceFile.data.fileName, newText, sourceFile.data.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.data.scriptKind, sourceFile.data.setExternalModuleIndicator, sourceFile.data.jsDocParsingMode); + result.data.commentDirectives = getNewCommentDirectives( + sourceFile.data.commentDirectives, + result.data.commentDirectives, changeRange.span.start, textSpanEnd(changeRange.span), delta, @@ -9933,8 +9079,8 @@ namespace IncrementalParser { newText, aggressiveChecks, ); - result.impliedNodeFormat = sourceFile.impliedNodeFormat; - transferSourceFileChildren(sourceFile, result); + result.data.impliedNodeFormat = sourceFile.data.impliedNodeFormat; + transferSourceFileChildren(sourceFile.node, result.node); // TODO(rbuckton): do not instantiate .node return result; } @@ -9987,18 +9133,22 @@ namespace IncrementalParser { } } - function moveElementEntirelyPastChangeRange(element: Node, origSourceFile: SourceFile, isArray: false, delta: number, oldText: string, newText: string, aggressiveChecks: boolean): void; - function moveElementEntirelyPastChangeRange(element: NodeArray, origSourceFile: SourceFile, isArray: true, delta: number, oldText: string, newText: string, aggressiveChecks: boolean): void; - function moveElementEntirelyPastChangeRange(element: Node | NodeArray, origSourceFile: SourceFile, isArray: boolean, delta: number, oldText: string, newText: string, aggressiveChecks: boolean) { + function moveElementEntirelyPastChangeRange(element: AstNode, origSourceFile: AstSourceFile, isArray: false, delta: number, oldText: string, newText: string, aggressiveChecks: boolean): void; + function moveElementEntirelyPastChangeRange(element: AstNodeArray, origSourceFile: AstSourceFile, isArray: true, delta: number, oldText: string, newText: string, aggressiveChecks: boolean): void; + function moveElementEntirelyPastChangeRange(element: AstNode | AstNodeArray, origSourceFile: AstSourceFile, isArray: boolean, delta: number, oldText: string, newText: string, aggressiveChecks: boolean) { if (isArray) { - visitArray(element as NodeArray); + visitArray(element as AstNodeArray); } else { - visitNode(element as Node); + visitNode(element as AstNode); } return; - function visitNode(node: Node) { + function visitNode(node: Node | AstNode) { + if (!(node instanceof AstNode)) { + node = (node as AstNode["node"]).ast; + } + let text = ""; if (aggressiveChecks && shouldCheckNode(node)) { text = oldText.substring(node.pos, node.end); @@ -10006,7 +9156,7 @@ namespace IncrementalParser { // Ditch any existing LS children we may have created. This way we can avoid // moving them forward. - unsetNodeChildren(node, origSourceFile); + unsetNodeChildren(node.node, origSourceFile.node); // TODO: do not instantiate .node setTextRangePosEnd(node, node.pos + delta, node.end + delta); @@ -10014,25 +9164,29 @@ namespace IncrementalParser { Debug.assert(text === newText.substring(node.pos, node.end)); } - forEachChild(node, visitNode as (node: Node) => void, visitArray as (nodes: NodeArray) => void); - if (hasJSDocNodes(node)) { - for (const jsDocComment of node.jsDoc!) { + forEachChild(node.node, visitNode as (node: Node) => void, visitArray as (nodes: NodeArray) => void); // TODO(rbuckton): do not instantiate .node + if (hasAstJSDocNodes(node)) { + for (const jsDocComment of node.data.jsDoc!) { visitNode(jsDocComment); } } checkNodePositions(node, aggressiveChecks); } - function visitArray(array: NodeArray) { + function visitArray(array: NodeArray | AstNodeArray) { + if (!(array instanceof AstNodeArray)) { + array = (array as AstNodeArray["nodes"]).ast; + } + setTextRangePosEnd(array, array.pos + delta, array.end + delta); - for (const node of array) { + for (const node of array.items) { visitNode(node); } } } - function shouldCheckNode(node: Node) { + function shouldCheckNode(node: AstNode) { switch (node.kind) { case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: @@ -10043,7 +9197,7 @@ namespace IncrementalParser { return false; } - function adjustIntersectingElement(element: Node | NodeArray, changeStart: number, changeRangeOldEnd: number, changeRangeNewEnd: number, delta: number) { + function adjustIntersectingElement(element: AstNode | AstNodeArray, changeStart: number, changeRangeOldEnd: number, changeRangeNewEnd: number, delta: number) { Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range"); Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range"); Debug.assert(element.pos <= element.end); @@ -10118,25 +9272,25 @@ namespace IncrementalParser { setTextRangePosEnd(element, pos, end); } - function checkNodePositions(node: Node, aggressiveChecks: boolean) { + function checkNodePositions(node: AstNode, aggressiveChecks: boolean) { if (aggressiveChecks) { let pos = node.pos; const visitNode = (child: Node) => { Debug.assert(child.pos >= pos); pos = child.end; }; - if (hasJSDocNodes(node)) { - for (const jsDocComment of node.jsDoc!) { + if (hasAstJSDocNodes(node)) { + for (const jsDocComment of node.data.jsDoc!) { visitNode(jsDocComment); } } - forEachChild(node, visitNode); + forEachChild(node.node, visitNode); // TODO: do not instantiate .node Debug.assert(pos <= node.end); } } function updateTokenPositionsAndMarkElements( - sourceFile: SourceFile, + sourceFile: AstSourceFile, changeStart: number, changeRangeOldEnd: number, changeRangeNewEnd: number, @@ -10148,7 +9302,11 @@ namespace IncrementalParser { visitNode(sourceFile); return; - function visitNode(child: Node) { + function visitNode(child: Node | AstNode) { + if (!(child instanceof AstNode)) { + child = (child as AstNode["node"]).ast; + } + Debug.assert(child.pos <= child.end); if (child.pos > changeRangeOldEnd) { // Node is entirely past the change range. We need to move both its pos and @@ -10163,14 +9321,14 @@ namespace IncrementalParser { const fullEnd = child.end; if (fullEnd >= changeStart) { markAsIntersectingIncrementalChange(child); - unsetNodeChildren(child, sourceFile); + unsetNodeChildren(child.node, sourceFile.node); // TODO(rbuckton): do not instantiate .node // Adjust the pos or end (or both) of the intersecting element accordingly. adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); - forEachChild(child, visitNode as (node: Node) => void, visitArray as (nodes: NodeArray) => void); - if (hasJSDocNodes(child)) { - for (const jsDocComment of child.jsDoc!) { - visitNode(jsDocComment); + forEachChild(child.node, visitNode as (node: Node) => void, visitArray as (nodes: NodeArray) => void); // TODO: do not instantiate .node + if (hasAstJSDocNodes(child)) { // TODO: do not instantiate .node + for (const jsDocComment of child.data.jsDoc!) { + visitNode((jsDocComment as AstJSDocNode["node"]).ast); } } checkNodePositions(child, aggressiveChecks); @@ -10181,7 +9339,11 @@ namespace IncrementalParser { Debug.assert(fullEnd < changeStart); } - function visitArray(array: NodeArray) { + function visitArray(array: NodeArray | AstNodeArray) { + if (!(array instanceof AstNodeArray)) { + array = (array as AstNodeArray["nodes"]).ast; + } + Debug.assert(array.pos <= array.end); if (array.pos > changeRangeOldEnd) { // Array is entirely after the change range. We need to move it, and move any of @@ -10199,7 +9361,7 @@ namespace IncrementalParser { // Adjust the pos or end (or both) of the intersecting array accordingly. adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); - for (const node of array) { + for (const node of array.items) { visitNode(node); } return; @@ -10210,7 +9372,7 @@ namespace IncrementalParser { } } - function extendToAffectedRange(sourceFile: SourceFile, changeRange: TextChangeRange): TextChangeRange { + function extendToAffectedRange(sourceFile: AstSourceFile, changeRange: TextChangeRange): TextChangeRange { // Consider the following code: // void foo() { /; } // @@ -10242,11 +9404,11 @@ namespace IncrementalParser { return createTextChangeRange(finalSpan, finalLength); } - function findNearestNodeStartingBeforeOrAtPosition(sourceFile: SourceFile, position: number): Node { - let bestResult: Node = sourceFile; - let lastNodeEntirelyBeforePosition: Node | undefined; + function findNearestNodeStartingBeforeOrAtPosition(sourceFile: AstSourceFile, position: number): AstNode { + let bestResult: AstNode = sourceFile; + let lastNodeEntirelyBeforePosition: AstNode | undefined; - forEachChild(sourceFile, visit); + forEachChild(sourceFile.node, visit); // TODO(rbuckton): do not instantiate .node if (lastNodeEntirelyBeforePosition) { const lastChildOfLastEntireNodeBeforePosition = getLastDescendant(lastNodeEntirelyBeforePosition); @@ -10257,11 +9419,11 @@ namespace IncrementalParser { return bestResult; - function getLastDescendant(node: Node): Node { + function getLastDescendant(node: AstNode): AstNode { while (true) { - const lastChild = getLastChild(node); + const lastChild = getLastChild(node.node); // TODO(rbuckton): do not instantiate .node if (lastChild) { - node = lastChild; + node = (lastChild as AstNode["node"]).ast; } else { return node; @@ -10269,7 +9431,11 @@ namespace IncrementalParser { } } - function visit(child: Node) { + function visit(child: Node | AstNode) { + if (!(child instanceof AstNode)) { + child = (child as AstNode["node"]).ast; + } + if (nodeIsMissing(child)) { // Missing nodes are effectively invisible to us. We never even consider them // When trying to find the nearest node before us. @@ -10293,7 +9459,7 @@ namespace IncrementalParser { // The nearest node is either this child, or one of the children inside // of it. We've already marked this child as the best so far. Recurse // in case one of the children is better. - forEachChild(child, visit); + forEachChild(child.node, visit); // TODO(rbuckton): do not instantiate .node // Once we look at the children of this node, then there's no need to // continue any further. @@ -10327,8 +9493,8 @@ namespace IncrementalParser { } } - function checkChangeRange(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks: boolean) { - const oldText = sourceFile.text; + function checkChangeRange(sourceFile: AstSourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks: boolean) { + const oldText = sourceFile.data.text; if (textChangeRange) { Debug.assert((oldText.length - textChangeRange.span.length + textChangeRange.newLength) === newText.length); @@ -10348,15 +9514,15 @@ namespace IncrementalParser { // The implementation takes advantage of the calling pattern it knows the parser will // make in order to optimize finding nodes as quickly as possible. export interface SyntaxCursor { - currentNode(position: number): Node; + currentNode(position: number): AstNode; } - export function createSyntaxCursor(sourceFile: SourceFile): SyntaxCursor { - let currentArray: NodeArray = sourceFile.statements; + export function createSyntaxCursor(sourceFile: AstSourceFile): SyntaxCursor { + let currentArray: AstNodeArray = sourceFile.data.statements; let currentArrayIndex = 0; - Debug.assert(currentArrayIndex < currentArray.length); - let current = currentArray[currentArrayIndex]; + Debug.assert(currentArrayIndex < currentArray.items.length); + let current = currentArray.items[currentArrayIndex]; let lastQueriedPosition = InvalidPosition.Value; return { @@ -10369,9 +9535,9 @@ namespace IncrementalParser { // Much of the time the parser will need the very next node in the array that // we just returned a node from.So just simply check for that case and move // forward in the array instead of searching for the node again. - if (current && current.end === position && currentArrayIndex < (currentArray.length - 1)) { + if (current && current.end === position && currentArrayIndex < (currentArray.items.length - 1)) { currentArrayIndex++; - current = currentArray[currentArrayIndex]; + current = currentArray.items[currentArrayIndex]; } // If we don't have a node, or the node we have isn't in the right position, @@ -10404,10 +9570,10 @@ namespace IncrementalParser { current = undefined!; // Recurse into the source file to find the highest node at this position. - forEachChild(sourceFile, visitNode, visitArray); + forEachChild(sourceFile.node, visitNode, visitArray); // TODO(rbuckton): do not instantiate .node return; - function visitNode(node: Node) { + function visitNode(node: Node) { // TODO(rbuckton): use AstNode if (position >= node.pos && position < node.end) { // Position was within this node. Keep searching deeper to find the node. forEachChild(node, visitNode, visitArray); @@ -10420,12 +9586,16 @@ namespace IncrementalParser { return false; } - function visitArray(array: NodeArray) { + function visitArray(array: NodeArray | AstNodeArray) { + if (!(array instanceof AstNodeArray)) { + array = (array as AstNodeArray["nodes"]).ast; + } + if (position >= array.pos && position < array.end) { // position was in this array. Search through this array to see if we find a // viable element. - for (let i = 0; i < array.length; i++) { - const child = array[i]; + for (let i = 0; i < array.items.length; i++) { + const child = array.items[i]; if (child) { if (child.pos === position) { // Found the right node. We're done. @@ -10438,7 +9608,7 @@ namespace IncrementalParser { if (child.pos < position && position < child.end) { // Position in somewhere within this child. Search in it and // stop searching in this array. - forEachChild(child, visitNode, visitArray); + forEachChild(child.node, visitNode, visitArray); // TODO(rbuckton): do not instantiate .node return true; } } @@ -10702,13 +9872,15 @@ function getNamedPragmaArguments(pragma: PragmaDefinition, text: string | undefi } /** @internal */ -export function tagNamesAreEquivalent(lhs: JsxTagNameExpression, rhs: JsxTagNameExpression): boolean { +export function tagNamesAreEquivalent(lhs: JsxTagNameExpression | ast.AstJsxTagNameExpression, rhs: JsxTagNameExpression | ast.AstJsxTagNameExpression): boolean { + if (!(lhs instanceof AstNode)) lhs = (lhs as AstJsxTagNameExpression["node"]).ast; + if (!(rhs instanceof AstNode)) rhs = (rhs as AstJsxTagNameExpression["node"]).ast; if (lhs.kind !== rhs.kind) { return false; } if (lhs.kind === SyntaxKind.Identifier) { - return lhs.escapedText === (rhs as Identifier).escapedText; + return lhs.data.escapedText === (rhs as AstIdentifier).data.escapedText; } if (lhs.kind === SyntaxKind.ThisKeyword) { @@ -10716,13 +9888,13 @@ export function tagNamesAreEquivalent(lhs: JsxTagNameExpression, rhs: JsxTagName } if (lhs.kind === SyntaxKind.JsxNamespacedName) { - return lhs.namespace.escapedText === (rhs as JsxNamespacedName).namespace.escapedText && - lhs.name.escapedText === (rhs as JsxNamespacedName).name.escapedText; + return lhs.data.namespace.data.escapedText === (rhs as AstJsxNamespacedName).data.namespace.data.escapedText && + lhs.data.name.data.escapedText === (rhs as AstJsxNamespacedName).data.name.data.escapedText; } // If we are at this statement then we must have PropertyAccessExpression and because tag name in Jsx element can only // take forms of JsxTagNameExpression which includes an identifier, "this" expression, or another propertyAccessExpression // it is safe to case the expression property as such. See parseJsxElementName for how we parse tag name in Jsx element - return (lhs as PropertyAccessExpression).name.escapedText === (rhs as PropertyAccessExpression).name.escapedText && - tagNamesAreEquivalent((lhs as PropertyAccessExpression).expression as JsxTagNameExpression, (rhs as PropertyAccessExpression).expression as JsxTagNameExpression); + return (lhs as AstPropertyAccessExpression).data.name.data.escapedText === (rhs as AstPropertyAccessExpression).data.name.data.escapedText && + tagNamesAreEquivalent((lhs as AstPropertyAccessExpression).data.expression as AstJsxTagNameExpression, (rhs as AstPropertyAccessExpression).data.expression as AstJsxTagNameExpression); } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 709211b797d9e..1ebfe3837a405 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -777,7 +777,7 @@ export function usingSingleLineStringWriter(action: (writer: EmitTextWriter) => } /** @internal */ -export function getFullWidth(node: Node): number { +export function getFullWidth(node: Node | ast.AstNode): number { return node.end - node.pos; } @@ -933,8 +933,8 @@ export function hasChangesInResolutions( // Returns true if this node contains a parse error anywhere underneath it. /** @internal */ -export function containsParseError(node: Node): boolean { - aggregateChildData(node); +export function containsParseError(node: Node | ast.AstNode): boolean { + aggregateChildData(node instanceof ast.AstNode ? node.node : node); // TODO(rbuckton): do not instantiate node return (node.flags & NodeFlags.ThisNodeOrAnySubNodesHasError) !== 0; } @@ -1058,7 +1058,7 @@ export function isFileLevelUniqueName(sourceFile: SourceFile, name: string, hasG // However, this node will be 'missing' in the sense that no actual source-code/tokens are // contained within it. /** @internal */ -export function nodeIsMissing(node: Node | undefined): boolean { +export function nodeIsMissing(node: Node | ast.AstNode | undefined): boolean { if (node === undefined) { return true; } @@ -1067,7 +1067,7 @@ export function nodeIsMissing(node: Node | undefined): boolean { } /** @internal */ -export function nodeIsPresent(node: Node | undefined): boolean { +export function nodeIsPresent(node: Node | ast.AstNode | undefined): boolean { return !nodeIsMissing(node); } @@ -1279,8 +1279,10 @@ export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: return getTextOfNodeFromSourceText(sourceFile.text, node, includeTrivia); } -function isJSDocTypeExpressionOrChild(node: Node): boolean { - return !!findAncestor(node, isJSDocTypeExpression); +function isJSDocTypeExpressionOrChild(node: Node | ast.AstNode): boolean { + return node instanceof ast.AstNode ? + !!findAncestor(node, ast.isAstJSDocTypeExpression) : + !!findAncestor(node, isJSDocTypeExpression); } /** @internal */ @@ -1310,7 +1312,7 @@ export function moduleExportNameIsDefault(node: ModuleExportName): boolean { } /** @internal */ -export function getTextOfNodeFromSourceText(sourceText: string, node: Node, includeTrivia = false): string { +export function getTextOfNodeFromSourceText(sourceText: string, node: Node | ast.AstNode, includeTrivia = false): string { if (nodeIsMissing(node)) { return ""; } @@ -2608,7 +2610,7 @@ export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: Sour } /** @internal */ -export function getJSDocCommentRanges(node: Node, text: string): CommentRange[] | undefined { +export function getJSDocCommentRanges(node: Node | ast.AstNode, text: string): CommentRange[] | undefined { const commentRanges = (node.kind === SyntaxKind.Parameter || node.kind === SyntaxKind.TypeParameter || node.kind === SyntaxKind.FunctionExpression || @@ -4390,7 +4392,10 @@ export function canHaveFlowNode(node: Node): node is HasFlowNode { } /** @internal */ -export function canHaveJSDoc(node: Node): node is HasJSDoc { +export function canHaveJSDoc(node: Node): node is HasJSDoc; +/** @internal */ +export function canHaveJSDoc(node: ast.AstNode): node is ast.AstHasJSDoc; +export function canHaveJSDoc(node: Node | ast.AstNode) { switch (node.kind) { case SyntaxKind.ArrowFunction: case SyntaxKind.BinaryExpression: @@ -7167,7 +7172,7 @@ export function getSyntacticModifierFlagsNoCache(node: Node): ModifierFlags { } /** @internal */ -export function modifiersToFlags(modifiers: readonly ModifierLike[] | undefined): ModifierFlags { +export function modifiersToFlags(modifiers: readonly ModifierLike[] | readonly ast.AstModifierLike[] | undefined): ModifierFlags { let flags = ModifierFlags.None; if (modifiers) { for (const modifier of modifiers) { @@ -10419,11 +10424,11 @@ export function setNodeFlags(node: T | undefined, newFlags: Node * * @internal */ -export function setParent(child: T, parent: T["parent"] | undefined): T; +export function setParent(child: T, parent: T["parent"] | undefined): T; /** @internal */ -export function setParent(child: T | undefined, parent: T["parent"] | undefined): T | undefined; +export function setParent(child: T | undefined, parent: T["parent"] | undefined): T | undefined; /** @internal */ -export function setParent(child: T | undefined, parent: T["parent"] | undefined): T | undefined { +export function setParent(child: T | undefined, parent: T["parent"] | undefined): T | undefined { if (child && parent) { (child as Mutable).parent = parent; } diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 41c8549cc807e..3608fbada2251 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -769,6 +769,18 @@ export function getOriginalNode(node: Node | undefined, nodeTest return nodeTest(node) ? node : undefined; } +interface AncestorTraversable> { + parent: T | undefined; +} + +/** + * Iterates through the parent chain of a node and performs the callback on each parent until the callback + * returns a truthy value, then returns that value. + * If no such value is found, it applies the callback until the parent pointer is undefined or the callback returns "quit" + * At that point findAncestor returns undefined. + * @internal + */ +export function findAncestor(node: ast.AstNode | undefined, callback: (element: ast.AstNode) => element is T): T | undefined; /** * Iterates through the parent chain of a node and performs the callback on each parent until the callback * returns a truthy value, then returns that value. @@ -776,8 +788,10 @@ export function getOriginalNode(node: Node | undefined, nodeTest * At that point findAncestor returns undefined. */ export function findAncestor(node: Node | undefined, callback: (element: Node) => element is T): T | undefined; +/** @internal */ +export function findAncestor(node: ast.AstNode | undefined, callback: (element: ast.AstNode) => boolean | "quit"): ast.AstNode | undefined; export function findAncestor(node: Node | undefined, callback: (element: Node) => boolean | "quit"): Node | undefined; -export function findAncestor(node: Node | undefined, callback: (element: Node) => boolean | "quit"): Node | undefined { +export function findAncestor>(node: T | T | undefined, callback: (element: T) => boolean | "quit"): T | undefined { while (node) { const result = callback(node); if (result === "quit") { From 014214a5cf56bb9b15092c21c27c6f93066b5580 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 18 Sep 2024 14:44:18 -0400 Subject: [PATCH 05/10] Add slim variant of forEachChild --- src/compiler/_namespaces/ts.ast.ts | 2 + src/compiler/ast.ts | 222 ++++- src/compiler/astForEachChild.ts | 1042 ++++++++++++++++++++++++ src/compiler/factory/astNodeFactory.ts | 8 +- src/compiler/factory/astNodeTests.ts | 50 +- src/compiler/parser.ts | 118 ++- 6 files changed, 1353 insertions(+), 89 deletions(-) create mode 100644 src/compiler/astForEachChild.ts diff --git a/src/compiler/_namespaces/ts.ast.ts b/src/compiler/_namespaces/ts.ast.ts index e80ad13e119b6..11cf59bd99d2c 100644 --- a/src/compiler/_namespaces/ts.ast.ts +++ b/src/compiler/_namespaces/ts.ast.ts @@ -6,3 +6,5 @@ export * from "../factory/astNodeTests.js"; export * from "../factory/astNodeFactory.js"; /** @internal */ export * from "../factory/astParenthesizerRules.js"; +/** @internal */ +export * from "../astForEachChild.js"; diff --git a/src/compiler/ast.ts b/src/compiler/ast.ts index 191e2e9d9dbce..235c237c44a2a 100644 --- a/src/compiler/ast.ts +++ b/src/compiler/ast.ts @@ -793,8 +793,8 @@ export class AstNode = Node; +/** @internal */ +export type HasChildren = + | QualifiedName + | ComputedPropertyName + | TypeParameterDeclaration + | ParameterDeclaration + | Decorator + | PropertySignature + | PropertyDeclaration + | MethodSignature + | MethodDeclaration + | ConstructorDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration + | ClassStaticBlockDeclaration + | CallSignatureDeclaration + | ConstructSignatureDeclaration + | IndexSignatureDeclaration + | TypePredicateNode + | TypeReferenceNode + | FunctionTypeNode + | ConstructorTypeNode + | TypeQueryNode + | TypeLiteralNode + | ArrayTypeNode + | TupleTypeNode + | OptionalTypeNode + | RestTypeNode + | UnionTypeNode + | IntersectionTypeNode + | ConditionalTypeNode + | InferTypeNode + | ImportTypeNode + | ImportTypeAssertionContainer + | NamedTupleMember + | ParenthesizedTypeNode + | TypeOperatorNode + | IndexedAccessTypeNode + | MappedTypeNode + | LiteralTypeNode + | TemplateLiteralTypeNode + | TemplateLiteralTypeSpan + | ObjectBindingPattern + | ArrayBindingPattern + | BindingElement + | ArrayLiteralExpression + | ObjectLiteralExpression + | PropertyAccessExpression + | ElementAccessExpression + | CallExpression + | NewExpression + | TaggedTemplateExpression + | TypeAssertion + | ParenthesizedExpression + | FunctionExpression + | ArrowFunction + | DeleteExpression + | TypeOfExpression + | VoidExpression + | AwaitExpression + | PrefixUnaryExpression + | PostfixUnaryExpression + | BinaryExpression + | ConditionalExpression + | TemplateExpression + | YieldExpression + | SpreadElement + | ClassExpression + | ExpressionWithTypeArguments + | AsExpression + | NonNullExpression + | SatisfiesExpression + | MetaProperty + | TemplateSpan + | Block + | VariableStatement + | ExpressionStatement + | IfStatement + | DoStatement + | WhileStatement + | ForStatement + | ForInStatement + | ForOfStatement + | ContinueStatement + | BreakStatement + | ReturnStatement + | WithStatement + | SwitchStatement + | LabeledStatement + | ThrowStatement + | TryStatement + | VariableDeclaration + | VariableDeclarationList + | FunctionDeclaration + | ClassDeclaration + | InterfaceDeclaration + | TypeAliasDeclaration + | EnumDeclaration + | ModuleDeclaration + | ModuleBlock + | CaseBlock + | NamespaceExportDeclaration + | ImportEqualsDeclaration + | ImportDeclaration + | AssertClause + | AssertEntry + | ImportAttributes + | ImportAttribute + | ImportClause + | NamespaceImport + | NamespaceExport + | NamedImports + | ImportSpecifier + | ExportAssignment + | ExportDeclaration + | NamedExports + | ExportSpecifier + | ExternalModuleReference + | JsxElement + | JsxSelfClosingElement + | JsxOpeningElement + | JsxClosingElement + | JsxFragment + | JsxAttribute + | JsxAttributes + | JsxSpreadAttribute + | JsxExpression + | JsxNamespacedName + | CaseClause + | DefaultClause + | HeritageClause + | CatchClause + | PropertyAssignment + | ShorthandPropertyAssignment + | SpreadAssignment + | EnumMember + | SourceFile + | PartiallyEmittedExpression + | CommaListExpression; + +/** @internal */ +export type AstHasChildren = AstNodeOneOf; + +/** @internal */ +export type ForEachChildNodes = + | HasChildren + | MissingDeclaration + | JSDocTypeExpression + | JSDocNonNullableType + | JSDocNullableType + | JSDocOptionalType + | JSDocVariadicType + | JSDocFunctionType + | JSDoc + | JSDocSeeTag + | JSDocNameReference + | JSDocMemberName + | JSDocParameterTag + | JSDocPropertyTag + | JSDocAuthorTag + | JSDocImplementsTag + | JSDocAugmentsTag + | JSDocTemplateTag + | JSDocTypedefTag + | JSDocCallbackTag + | JSDocReturnTag + | JSDocTypeTag + | JSDocThisTag + | JSDocEnumTag + | JSDocSignature + | JSDocLink + | JSDocLinkCode + | JSDocLinkPlain + | JSDocTypeLiteral + | JSDocUnknownTag + | JSDocClassTag + | JSDocPublicTag + | JSDocPrivateTag + | JSDocProtectedTag + | JSDocReadonlyTag + | JSDocDeprecatedTag + | JSDocThrowsTag + | JSDocOverrideTag + | JSDocSatisfiesTag + | JSDocOverloadTag + | JSDocImportTag; + +/** @internal */ +export type AstForEachChildNodes = AstNodeOneOf; + /** @internal */ export interface Declaration extends Node { readonly ast: AstDeclaration; @@ -11318,8 +11508,8 @@ export class AstJSDocNamepathTypeData extends AstData { } /** @internal */ -export class JSDocNode extends Node implements ts.JSDoc { - declare readonly ast: AstJSDocNode; +export class JSDoc extends Node implements ts.JSDoc { + declare readonly ast: AstJSDoc; override get parent() { return super.parent as HasJSDoc; @@ -11344,7 +11534,7 @@ export class JSDocNode extends Node implemen } /** @internal */ -export class AstJSDocNodeData extends AstData { +export class AstJSDocData extends AstData { comment: string | AstNodeArray | undefined = undefined; tags: AstNodeArray | undefined = undefined; } @@ -11554,7 +11744,7 @@ export class BaseJSDocTag; override get parent() { - return super.parent as JSDocNode | JSDocTypeLiteral; + return super.parent as JSDoc | JSDocTypeLiteral; } override set parent(value) { super.parent = value; @@ -11723,7 +11913,7 @@ export class JSDocEnumTag extends BaseJSDocTag; /** @internal */ export type AstJSDocNamepathType = AstNode; /** @internal */ -export type AstJSDocNode = AstNode; +export type AstJSDoc = AstNode; /** @internal */ export type AstJSDocLink = AstNode; /** @internal */ @@ -14330,7 +14520,7 @@ export interface NodeType { [SyntaxKind.JSDocFunctionType]: JSDocFunctionType; [SyntaxKind.JSDocVariadicType]: JSDocVariadicType; [SyntaxKind.JSDocNamepathType]: JSDocNamepathType; - [SyntaxKind.JSDoc]: JSDocNode; + [SyntaxKind.JSDoc]: JSDoc; [SyntaxKind.JSDocLink]: JSDocLink; [SyntaxKind.JSDocLinkCode]: JSDocLinkCode; [SyntaxKind.JSDocLinkPlain]: JSDocLinkPlain; @@ -14694,7 +14884,7 @@ export interface AstNodeType { [SyntaxKind.JSDocFunctionType]: AstJSDocFunctionType; [SyntaxKind.JSDocVariadicType]: AstJSDocVariadicType; [SyntaxKind.JSDocNamepathType]: AstJSDocNamepathType; - [SyntaxKind.JSDoc]: AstJSDocNode; + [SyntaxKind.JSDoc]: AstJSDoc; [SyntaxKind.JSDocLink]: AstJSDocLink; [SyntaxKind.JSDocLinkCode]: AstJSDocLinkCode; [SyntaxKind.JSDocLinkPlain]: AstJSDocLinkPlain; diff --git a/src/compiler/astForEachChild.ts b/src/compiler/astForEachChild.ts new file mode 100644 index 0000000000000..3bc5a3fa76a73 --- /dev/null +++ b/src/compiler/astForEachChild.ts @@ -0,0 +1,1042 @@ +import { + AstArrayLiteralExpression, + AstArrayTypeNode, + AstArrowFunction, + AstAsExpression, + AstAwaitExpression, + AstBinaryExpression, + AstBindingElement, + AstBindingPattern, + AstBlock, + AstBreakStatement, + AstCallExpression, + AstCallSignatureDeclaration, + AstCaseBlock, + AstCaseClause, + AstCatchClause, + AstClassDeclaration, + AstClassExpression, + AstClassStaticBlockDeclaration, + AstCommaListExpression, + AstComputedPropertyName, + AstConditionalExpression, + AstConditionalTypeNode, + AstConstructorDeclaration, + AstConstructorTypeNode, + AstConstructSignatureDeclaration, + AstContinueStatement, + AstDecorator, + AstDefaultClause, + AstDeleteExpression, + AstDoStatement, + AstElementAccessExpression, + AstEnumDeclaration, + AstEnumMember, + AstExportAssignment, + AstExportDeclaration, + AstExportSpecifier, + AstExpressionStatement, + AstExpressionWithTypeArguments, + AstExternalModuleReference, + AstForInStatement, + AstForOfStatement, + AstForStatement, + AstFunctionDeclaration, + AstFunctionExpression, + AstFunctionTypeNode, + AstGetAccessorDeclaration, + AstHeritageClause, + AstIfStatement, + AstImportAttribute, + AstImportAttributes, + AstImportClause, + AstImportDeclaration, + AstImportEqualsDeclaration, + AstImportSpecifier, + AstImportTypeAssertionContainer, + AstImportTypeNode, + AstIndexedAccessTypeNode, + AstIndexSignatureDeclaration, + AstInferTypeNode, + AstInterfaceDeclaration, + AstIntersectionTypeNode, + AstJSDoc, + AstJSDocAugmentsTag, + AstJSDocAuthorTag, + AstJSDocCallbackTag, + AstJSDocClassTag, + AstJSDocDeprecatedTag, + AstJSDocEnumTag, + AstJSDocFunctionType, + AstJSDocImplementsTag, + AstJSDocImportTag, + AstJSDocLink, + AstJSDocLinkCode, + AstJSDocLinkPlain, + AstJSDocMemberName, + AstJSDocNameReference, + AstJSDocNonNullableType, + AstJSDocNullableType, + AstJSDocOptionalType, + AstJSDocOverloadTag, + AstJSDocOverrideTag, + AstJSDocParameterTag, + AstJSDocPrivateTag, + AstJSDocPropertyTag, + AstJSDocProtectedTag, + AstJSDocPublicTag, + AstJSDocReadonlyTag, + AstJSDocReturnTag, + AstJSDocSatisfiesTag, + AstJSDocSeeTag, + AstJSDocSignature, + AstJSDocTemplateTag, + AstJSDocThisTag, + AstJSDocThrowsTag, + AstJSDocTypedefTag, + AstJSDocTypeExpression, + AstJSDocTypeLiteral, + AstJSDocTypeTag, + AstJSDocUnknownTag, + AstJSDocVariadicType, + AstJsxAttribute, + AstJsxAttributes, + AstJsxClosingElement, + AstJsxElement, + AstJsxExpression, + AstJsxFragment, + AstJsxNamespacedName, + AstJsxOpeningLikeElement, + AstJsxSpreadAttribute, + AstLabeledStatement, + AstLiteralTypeNode, + AstMappedTypeNode, + AstMetaProperty, + AstMethodDeclaration, + AstMethodSignature, + AstMissingDeclaration, + AstModuleBlock, + AstModuleDeclaration, + AstNamedExports, + AstNamedImports, + AstNamedTupleMember, + AstNamespaceExport, + AstNamespaceExportDeclaration, + AstNamespaceImport, + AstNewExpression, + AstNode, + AstNodeArray, + AstNonNullExpression, + AstObjectLiteralExpression, + AstOptionalTypeNode, + AstParameterDeclaration, + AstParenthesizedExpression, + AstParenthesizedTypeNode, + AstPartiallyEmittedExpression, + AstPostfixUnaryExpression, + AstPrefixUnaryExpression, + AstPropertyAccessExpression, + AstPropertyAssignment, + AstPropertyDeclaration, + AstPropertySignature, + AstQualifiedName, + AstRestTypeNode, + AstReturnStatement, + AstSatisfiesExpression, + AstSetAccessorDeclaration, + AstShorthandPropertyAssignment, + AstSourceFile, + AstSpreadAssignment, + AstSpreadElement, + AstSwitchStatement, + AstTaggedTemplateExpression, + AstTemplateExpression, + AstTemplateLiteralTypeNode, + AstTemplateLiteralTypeSpan, + AstTemplateSpan, + AstThrowStatement, + AstTryStatement, + AstTupleTypeNode, + AstTypeAliasDeclaration, + AstTypeAssertion, + AstTypeLiteralNode, + AstTypeOfExpression, + AstTypeOperatorNode, + AstTypeParameterDeclaration, + AstTypePredicateNode, + AstTypeQueryNode, + AstTypeReferenceNode, + AstUnionTypeNode, + AstVariableDeclaration, + AstVariableDeclarationList, + AstVariableStatement, + AstVoidExpression, + AstWhileStatement, + AstWithStatement, + AstYieldExpression, + AstForEachChildNodes +} from "./_namespaces/ts.ast.js"; +import { + forEach, + SyntaxKind, + isArray, +} from "./_namespaces/ts.js"; + +function visitNode(cbNode: (node: AstNode) => T, node: AstNode | undefined): T | undefined { + return node && cbNode(node); +} + +function visitNodes(cbNode: (node: AstNode) => T, cbNodes: ((node: AstNodeArray) => T | undefined) | undefined, nodes: AstNodeArray | undefined): T | undefined { + if (nodes) { + if (cbNodes) { + return cbNodes(nodes); + } + for (const node of nodes.items) { + const result = cbNode(node); + if (result) { + return result; + } + } + } +} + +type AstForEachChildFunction = (node: TNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined) => T | undefined; +type AstForEachChildTable = { [TNode in AstForEachChildNodes as TNode["kind"]]: AstForEachChildFunction; }; + +const astForEachChildTable: AstForEachChildTable = { + [SyntaxKind.QualifiedName]: function forEachChildInQualifiedName(node: AstQualifiedName, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.left) || + visitNode(cbNode, node.data.right); + }, + [SyntaxKind.TypeParameter]: function forEachChildInTypeParameter(node: AstTypeParameterDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.constraint) || + visitNode(cbNode, node.data.default) || + visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.ShorthandPropertyAssignment]: function forEachChildInShorthandPropertyAssignment(node: AstShorthandPropertyAssignment, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.questionToken) || + visitNode(cbNode, node.data.exclamationToken) || + visitNode(cbNode, node.data.equalsToken) || + visitNode(cbNode, node.data.objectAssignmentInitializer); + }, + [SyntaxKind.SpreadAssignment]: function forEachChildInSpreadAssignment(node: AstSpreadAssignment, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.Parameter]: function forEachChildInParameter(node: AstParameterDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.dotDotDotToken) || + visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.questionToken) || + visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.initializer); + }, + [SyntaxKind.PropertyDeclaration]: function forEachChildInPropertyDeclaration(node: AstPropertyDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.questionToken) || + visitNode(cbNode, node.data.exclamationToken) || + visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.initializer); + }, + [SyntaxKind.PropertySignature]: function forEachChildInPropertySignature(node: AstPropertySignature, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.questionToken) || + visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.initializer); + }, + [SyntaxKind.PropertyAssignment]: function forEachChildInPropertyAssignment(node: AstPropertyAssignment, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.questionToken) || + visitNode(cbNode, node.data.exclamationToken) || + visitNode(cbNode, node.data.initializer); + }, + [SyntaxKind.VariableDeclaration]: function forEachChildInVariableDeclaration(node: AstVariableDeclaration, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.exclamationToken) || + visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.initializer); + }, + [SyntaxKind.BindingElement]: function forEachChildInBindingElement(node: AstBindingElement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.dotDotDotToken) || + visitNode(cbNode, node.data.propertyName) || + visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.initializer); + }, + [SyntaxKind.IndexSignature]: function forEachChildInIndexSignature(node: AstIndexSignatureDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type); + }, + [SyntaxKind.ConstructorType]: function forEachChildInConstructorType(node: AstConstructorTypeNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type); + }, + [SyntaxKind.FunctionType]: function forEachChildInFunctionType(node: AstFunctionTypeNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type); + }, + [SyntaxKind.CallSignature]: forEachChildInCallOrConstructSignature, + [SyntaxKind.ConstructSignature]: forEachChildInCallOrConstructSignature, + [SyntaxKind.MethodDeclaration]: function forEachChildInMethodDeclaration(node: AstMethodDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.asteriskToken) || + visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.questionToken) || + visitNode(cbNode, node.data.exclamationToken) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.body); + }, + [SyntaxKind.MethodSignature]: function forEachChildInMethodSignature(node: AstMethodSignature, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.questionToken) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type); + }, + [SyntaxKind.Constructor]: function forEachChildInConstructor(node: AstConstructorDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.body); + }, + [SyntaxKind.GetAccessor]: function forEachChildInGetAccessor(node: AstGetAccessorDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.body); + }, + [SyntaxKind.SetAccessor]: function forEachChildInSetAccessor(node: AstSetAccessorDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.body); + }, + [SyntaxKind.FunctionDeclaration]: function forEachChildInFunctionDeclaration(node: AstFunctionDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.asteriskToken) || + visitNode(cbNode, node.data.name) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.body); + }, + [SyntaxKind.FunctionExpression]: function forEachChildInFunctionExpression(node: AstFunctionExpression, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.asteriskToken) || + visitNode(cbNode, node.data.name) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.body); + }, + [SyntaxKind.ArrowFunction]: function forEachChildInArrowFunction(node: AstArrowFunction, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.equalsGreaterThanToken) || + visitNode(cbNode, node.data.body); + }, + [SyntaxKind.ClassStaticBlockDeclaration]: function forEachChildInClassStaticBlockDeclaration(node: AstClassStaticBlockDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.body); + }, + [SyntaxKind.TypeReference]: function forEachChildInTypeReference(node: AstTypeReferenceNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.typeName) || + visitNodes(cbNode, cbNodes, node.data.typeArguments); + }, + [SyntaxKind.TypePredicate]: function forEachChildInTypePredicate(node: AstTypePredicateNode, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.assertsModifier) || + visitNode(cbNode, node.data.parameterName) || + visitNode(cbNode, node.data.type); + }, + [SyntaxKind.TypeQuery]: function forEachChildInTypeQuery(node: AstTypeQueryNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.exprName) || + visitNodes(cbNode, cbNodes, node.data.typeArguments); + }, + [SyntaxKind.TypeLiteral]: function forEachChildInTypeLiteral(node: AstTypeLiteralNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.members); + }, + [SyntaxKind.ArrayType]: function forEachChildInArrayType(node: AstArrayTypeNode, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.elementType); + }, + [SyntaxKind.TupleType]: function forEachChildInTupleType(node: AstTupleTypeNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.elements); + }, + [SyntaxKind.UnionType]: forEachChildInUnionOrIntersectionType, + [SyntaxKind.IntersectionType]: forEachChildInUnionOrIntersectionType, + [SyntaxKind.ConditionalType]: function forEachChildInConditionalType(node: AstConditionalTypeNode, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.checkType) || + visitNode(cbNode, node.data.extendsType) || + visitNode(cbNode, node.data.trueType) || + visitNode(cbNode, node.data.falseType); + }, + [SyntaxKind.InferType]: function forEachChildInInferType(node: AstInferTypeNode, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.typeParameter); + }, + [SyntaxKind.ImportType]: function forEachChildInImportType(node: AstImportTypeNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.argument) || + visitNode(cbNode, node.data.attributes) || + visitNode(cbNode, node.data.qualifier) || + visitNodes(cbNode, cbNodes, node.data.typeArguments); + }, + [SyntaxKind.ImportTypeAssertionContainer]: function forEachChildInImportTypeAssertionContainer(node: AstImportTypeAssertionContainer, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.assertClause); + }, + [SyntaxKind.ParenthesizedType]: forEachChildInParenthesizedTypeOrTypeOperator, + [SyntaxKind.TypeOperator]: forEachChildInParenthesizedTypeOrTypeOperator, + [SyntaxKind.IndexedAccessType]: function forEachChildInIndexedAccessType(node: AstIndexedAccessTypeNode, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.objectType) || + visitNode(cbNode, node.data.indexType); + }, + [SyntaxKind.MappedType]: function forEachChildInMappedType(node: AstMappedTypeNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.readonlyToken) || + visitNode(cbNode, node.data.typeParameter) || + visitNode(cbNode, node.data.nameType) || + visitNode(cbNode, node.data.questionToken) || + visitNode(cbNode, node.data.type) || + visitNodes(cbNode, cbNodes, node.data.members); + }, + [SyntaxKind.LiteralType]: function forEachChildInLiteralType(node: AstLiteralTypeNode, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.literal); + }, + [SyntaxKind.NamedTupleMember]: function forEachChildInNamedTupleMember(node: AstNamedTupleMember, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.dotDotDotToken) || + visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.questionToken) || + visitNode(cbNode, node.data.type); + }, + [SyntaxKind.ObjectBindingPattern]: forEachChildInObjectOrArrayBindingPattern, + [SyntaxKind.ArrayBindingPattern]: forEachChildInObjectOrArrayBindingPattern, + [SyntaxKind.ArrayLiteralExpression]: function forEachChildInArrayLiteralExpression(node: AstArrayLiteralExpression, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.elements); + }, + [SyntaxKind.ObjectLiteralExpression]: function forEachChildInObjectLiteralExpression(node: AstObjectLiteralExpression, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.properties); + }, + [SyntaxKind.PropertyAccessExpression]: function forEachChildInPropertyAccessExpression(node: AstPropertyAccessExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || + visitNode(cbNode, node.data.questionDotToken) || + visitNode(cbNode, node.data.name); + }, + [SyntaxKind.ElementAccessExpression]: function forEachChildInElementAccessExpression(node: AstElementAccessExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || + visitNode(cbNode, node.data.questionDotToken) || + visitNode(cbNode, node.data.argumentExpression); + }, + [SyntaxKind.CallExpression]: function forEachChildInCallExpression(node: AstCallExpression, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || + visitNode(cbNode, node.data.questionDotToken) || + visitNodes(cbNode, cbNodes, node.data.typeArguments) || + visitNodes(cbNode, cbNodes, node.data.arguments); + }, + [SyntaxKind.NewExpression]: function forEachChildInNewExpression(node: AstNewExpression, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || + visitNodes(cbNode, cbNodes, node.data.typeArguments) || + visitNodes(cbNode, cbNodes, node.data.arguments); + }, + [SyntaxKind.TaggedTemplateExpression]: function forEachChildInTaggedTemplateExpression(node: AstTaggedTemplateExpression, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tag) || + visitNode(cbNode, node.data.questionDotToken) || + visitNodes(cbNode, cbNodes, node.data.typeArguments) || + visitNode(cbNode, node.data.template); + }, + [SyntaxKind.TypeAssertionExpression]: function forEachChildInTypeAssertionExpression(node: AstTypeAssertion, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.ParenthesizedExpression]: function forEachChildInParenthesizedExpression(node: AstParenthesizedExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.DeleteExpression]: function forEachChildInDeleteExpression(node: AstDeleteExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.TypeOfExpression]: function forEachChildInTypeOfExpression(node: AstTypeOfExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.VoidExpression]: function forEachChildInVoidExpression(node: AstVoidExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.PrefixUnaryExpression]: function forEachChildInPrefixUnaryExpression(node: AstPrefixUnaryExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.operand); + }, + [SyntaxKind.YieldExpression]: function forEachChildInYieldExpression(node: AstYieldExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.asteriskToken) || + visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.AwaitExpression]: function forEachChildInAwaitExpression(node: AstAwaitExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.PostfixUnaryExpression]: function forEachChildInPostfixUnaryExpression(node: AstPostfixUnaryExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.operand); + }, + [SyntaxKind.BinaryExpression]: function forEachChildInBinaryExpression(node: AstBinaryExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.left) || + visitNode(cbNode, node.data.operatorToken) || + visitNode(cbNode, node.data.right); + }, + [SyntaxKind.AsExpression]: function forEachChildInAsExpression(node: AstAsExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || + visitNode(cbNode, node.data.type); + }, + [SyntaxKind.NonNullExpression]: function forEachChildInNonNullExpression(node: AstNonNullExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.SatisfiesExpression]: function forEachChildInSatisfiesExpression(node: AstSatisfiesExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || visitNode(cbNode, node.data.type); + }, + [SyntaxKind.MetaProperty]: function forEachChildInMetaProperty(node: AstMetaProperty, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.name); + }, + [SyntaxKind.ConditionalExpression]: function forEachChildInConditionalExpression(node: AstConditionalExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.condition) || + visitNode(cbNode, node.data.questionToken) || + visitNode(cbNode, node.data.whenTrue) || + visitNode(cbNode, node.data.colonToken) || + visitNode(cbNode, node.data.whenFalse); + }, + [SyntaxKind.SpreadElement]: function forEachChildInSpreadElement(node: AstSpreadElement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.Block]: forEachChildInBlock, + [SyntaxKind.ModuleBlock]: forEachChildInBlock, + [SyntaxKind.SourceFile]: function forEachChildInSourceFile(node: AstSourceFile, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.statements) || + visitNode(cbNode, node.data.endOfFileToken); + }, + [SyntaxKind.VariableStatement]: function forEachChildInVariableStatement(node: AstVariableStatement, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.declarationList); + }, + [SyntaxKind.VariableDeclarationList]: function forEachChildInVariableDeclarationList(node: AstVariableDeclarationList, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.declarations); + }, + [SyntaxKind.ExpressionStatement]: function forEachChildInExpressionStatement(node: AstExpressionStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.IfStatement]: function forEachChildInIfStatement(node: AstIfStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || + visitNode(cbNode, node.data.thenStatement) || + visitNode(cbNode, node.data.elseStatement); + }, + [SyntaxKind.DoStatement]: function forEachChildInDoStatement(node: AstDoStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.statement) || + visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.WhileStatement]: function forEachChildInWhileStatement(node: AstWhileStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || + visitNode(cbNode, node.data.statement); + }, + [SyntaxKind.ForStatement]: function forEachChildInForStatement(node: AstForStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.initializer) || + visitNode(cbNode, node.data.condition) || + visitNode(cbNode, node.data.incrementor) || + visitNode(cbNode, node.data.statement); + }, + [SyntaxKind.ForInStatement]: function forEachChildInForInStatement(node: AstForInStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.initializer) || + visitNode(cbNode, node.data.expression) || + visitNode(cbNode, node.data.statement); + }, + [SyntaxKind.ForOfStatement]: function forEachChildInForOfStatement(node: AstForOfStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.awaitModifier) || + visitNode(cbNode, node.data.initializer) || + visitNode(cbNode, node.data.expression) || + visitNode(cbNode, node.data.statement); + }, + [SyntaxKind.ContinueStatement]: forEachChildInContinueOrBreakStatement, + [SyntaxKind.BreakStatement]: forEachChildInContinueOrBreakStatement, + [SyntaxKind.ReturnStatement]: function forEachChildInReturnStatement(node: AstReturnStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.WithStatement]: function forEachChildInWithStatement(node: AstWithStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || + visitNode(cbNode, node.data.statement); + }, + [SyntaxKind.SwitchStatement]: function forEachChildInSwitchStatement(node: AstSwitchStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || + visitNode(cbNode, node.data.caseBlock); + }, + [SyntaxKind.CaseBlock]: function forEachChildInCaseBlock(node: AstCaseBlock, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.clauses); + }, + [SyntaxKind.CaseClause]: function forEachChildInCaseClause(node: AstCaseClause, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || + visitNodes(cbNode, cbNodes, node.data.statements); + }, + [SyntaxKind.DefaultClause]: function forEachChildInDefaultClause(node: AstDefaultClause, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.statements); + }, + [SyntaxKind.LabeledStatement]: function forEachChildInLabeledStatement(node: AstLabeledStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.label) || + visitNode(cbNode, node.data.statement); + }, + [SyntaxKind.ThrowStatement]: function forEachChildInThrowStatement(node: AstThrowStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.TryStatement]: function forEachChildInTryStatement(node: AstTryStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tryBlock) || + visitNode(cbNode, node.data.catchClause) || + visitNode(cbNode, node.data.finallyBlock); + }, + [SyntaxKind.CatchClause]: function forEachChildInCatchClause(node: AstCatchClause, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.variableDeclaration) || + visitNode(cbNode, node.data.block); + }, + [SyntaxKind.Decorator]: function forEachChildInDecorator(node: AstDecorator, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.ClassDeclaration]: forEachChildInClassDeclarationOrExpression, + [SyntaxKind.ClassExpression]: forEachChildInClassDeclarationOrExpression, + [SyntaxKind.InterfaceDeclaration]: function forEachChildInInterfaceDeclaration(node: AstInterfaceDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.heritageClauses) || + visitNodes(cbNode, cbNodes, node.data.members); + }, + [SyntaxKind.TypeAliasDeclaration]: function forEachChildInTypeAliasDeclaration(node: AstTypeAliasDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNode(cbNode, node.data.type); + }, + [SyntaxKind.EnumDeclaration]: function forEachChildInEnumDeclaration(node: AstEnumDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNodes(cbNode, cbNodes, node.data.members); + }, + [SyntaxKind.EnumMember]: function forEachChildInEnumMember(node: AstEnumMember, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.initializer); + }, + [SyntaxKind.ModuleDeclaration]: function forEachChildInModuleDeclaration(node: AstModuleDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.body); + }, + [SyntaxKind.ImportEqualsDeclaration]: function forEachChildInImportEqualsDeclaration(node: AstImportEqualsDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.moduleReference); + }, + [SyntaxKind.ImportDeclaration]: function forEachChildInImportDeclaration(node: AstImportDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.importClause) || + visitNode(cbNode, node.data.moduleSpecifier) || + visitNode(cbNode, node.data.attributes); + }, + [SyntaxKind.ImportClause]: function forEachChildInImportClause(node: AstImportClause, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.namedBindings); + }, + [SyntaxKind.ImportAttributes]: function forEachChildInImportAttributes(node: AstImportAttributes, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.elements); + }, + [SyntaxKind.ImportAttribute]: function forEachChildInImportAttribute(node: AstImportAttribute, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.value); + }, + [SyntaxKind.NamespaceExportDeclaration]: function forEachChildInNamespaceExportDeclaration(node: AstNamespaceExportDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name); + }, + [SyntaxKind.NamespaceImport]: function forEachChildInNamespaceImport(node: AstNamespaceImport, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.name); + }, + [SyntaxKind.NamespaceExport]: function forEachChildInNamespaceExport(node: AstNamespaceExport, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.name); + }, + [SyntaxKind.NamedImports]: forEachChildInNamedImportsOrExports, + [SyntaxKind.NamedExports]: forEachChildInNamedImportsOrExports, + [SyntaxKind.ExportDeclaration]: function forEachChildInExportDeclaration(node: AstExportDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.exportClause) || + visitNode(cbNode, node.data.moduleSpecifier) || + visitNode(cbNode, node.data.attributes); + }, + [SyntaxKind.ImportSpecifier]: forEachChildInImportOrExportSpecifier, + [SyntaxKind.ExportSpecifier]: forEachChildInImportOrExportSpecifier, + [SyntaxKind.ExportAssignment]: function forEachChildInExportAssignment(node: AstExportAssignment, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.TemplateExpression]: function forEachChildInTemplateExpression(node: AstTemplateExpression, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.head) || + visitNodes(cbNode, cbNodes, node.data.templateSpans); + }, + [SyntaxKind.TemplateSpan]: function forEachChildInTemplateSpan(node: AstTemplateSpan, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || + visitNode(cbNode, node.data.literal); + }, + [SyntaxKind.TemplateLiteralType]: function forEachChildInTemplateLiteralType(node: AstTemplateLiteralTypeNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.head) || + visitNodes(cbNode, cbNodes, node.data.templateSpans); + }, + [SyntaxKind.TemplateLiteralTypeSpan]: function forEachChildInTemplateLiteralTypeSpan(node: AstTemplateLiteralTypeSpan, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.type) || + visitNode(cbNode, node.data.literal); + }, + [SyntaxKind.ComputedPropertyName]: function forEachChildInComputedPropertyName(node: AstComputedPropertyName, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.HeritageClause]: function forEachChildInHeritageClause(node: AstHeritageClause, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.types); + }, + [SyntaxKind.ExpressionWithTypeArguments]: function forEachChildInExpressionWithTypeArguments(node: AstExpressionWithTypeArguments, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression) || + visitNodes(cbNode, cbNodes, node.data.typeArguments); + }, + [SyntaxKind.ExternalModuleReference]: function forEachChildInExternalModuleReference(node: AstExternalModuleReference, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.MissingDeclaration]: function forEachChildInMissingDeclaration(node: AstMissingDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers); + }, + [SyntaxKind.CommaListExpression]: function forEachChildInCommaListExpression(node: AstCommaListExpression, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.elements); + }, + [SyntaxKind.JsxElement]: function forEachChildInJsxElement(node: AstJsxElement, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.openingElement) || + visitNodes(cbNode, cbNodes, node.data.children) || + visitNode(cbNode, node.data.closingElement); + }, + [SyntaxKind.JsxFragment]: function forEachChildInJsxFragment(node: AstJsxFragment, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.openingFragment) || + visitNodes(cbNode, cbNodes, node.data.children) || + visitNode(cbNode, node.data.closingFragment); + }, + [SyntaxKind.JsxSelfClosingElement]: forEachChildInJsxOpeningOrSelfClosingElement, + [SyntaxKind.JsxOpeningElement]: forEachChildInJsxOpeningOrSelfClosingElement, + [SyntaxKind.JsxAttributes]: function forEachChildInJsxAttributes(node: AstJsxAttributes, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.properties); + }, + [SyntaxKind.JsxAttribute]: function forEachChildInJsxAttribute(node: AstJsxAttribute, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.name) || + visitNode(cbNode, node.data.initializer); + }, + [SyntaxKind.JsxSpreadAttribute]: function forEachChildInJsxSpreadAttribute(node: AstJsxSpreadAttribute, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.JsxExpression]: function forEachChildInJsxExpression(node: AstJsxExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.dotDotDotToken) || + visitNode(cbNode, node.data.expression); + }, + [SyntaxKind.JsxClosingElement]: function forEachChildInJsxClosingElement(node: AstJsxClosingElement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName); + }, + [SyntaxKind.JsxNamespacedName]: function forEachChildInJsxNamespacedName(node: AstJsxNamespacedName, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.namespace) || + visitNode(cbNode, node.data.name); + }, + [SyntaxKind.OptionalType]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.RestType]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.JSDocTypeExpression]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.JSDocNonNullableType]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.JSDocNullableType]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.JSDocOptionalType]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.JSDocVariadicType]: forEachChildInOptionalRestOrJSDocParameterModifier, + [SyntaxKind.JSDocFunctionType]: function forEachChildInJSDocFunctionType(node: AstJSDocFunctionType, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type); + }, + [SyntaxKind.JSDoc]: function forEachChildInJSDoc(node: AstJSDoc, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)) + || visitNodes(cbNode, cbNodes, node.data.tags); + }, + [SyntaxKind.JSDocSeeTag]: function forEachChildInJSDocSeeTag(node: AstJSDocSeeTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName) || + visitNode(cbNode, node.data.name) || + (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + }, + [SyntaxKind.JSDocNameReference]: function forEachChildInJSDocNameReference(node: AstJSDocNameReference, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.name); + }, + [SyntaxKind.JSDocMemberName]: function forEachChildInJSDocMemberName(node: AstJSDocMemberName, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.left) || + visitNode(cbNode, node.data.right); + }, + [SyntaxKind.JSDocParameterTag]: forEachChildInJSDocParameterOrPropertyTag, + [SyntaxKind.JSDocPropertyTag]: forEachChildInJSDocParameterOrPropertyTag, + [SyntaxKind.JSDocAuthorTag]: function forEachChildInJSDocAuthorTag(node: AstJSDocAuthorTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName) || + (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + }, + [SyntaxKind.JSDocImplementsTag]: function forEachChildInJSDocImplementsTag(node: AstJSDocImplementsTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName) || + visitNode(cbNode, node.data.class) || + (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + }, + [SyntaxKind.JSDocAugmentsTag]: function forEachChildInJSDocAugmentsTag(node: AstJSDocAugmentsTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName) || + visitNode(cbNode, node.data.class) || + (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + }, + [SyntaxKind.JSDocTemplateTag]: function forEachChildInJSDocTemplateTag(node: AstJSDocTemplateTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName) || + visitNode(cbNode, node.data.constraint) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + }, + [SyntaxKind.JSDocTypedefTag]: function forEachChildInJSDocTypedefTag(node: AstJSDocTypedefTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName) || + (node.data.typeExpression && + node.data.typeExpression.kind === SyntaxKind.JSDocTypeExpression + ? visitNode(cbNode, node.data.typeExpression) || + visitNode(cbNode, node.data.fullName) || + (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)) + : visitNode(cbNode, node.data.fullName) || + visitNode(cbNode, node.data.typeExpression) || + (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment))); + }, + [SyntaxKind.JSDocCallbackTag]: function forEachChildInJSDocCallbackTag(node: AstJSDocCallbackTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName) || + visitNode(cbNode, node.data.fullName) || + visitNode(cbNode, node.data.typeExpression) || + (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + }, + [SyntaxKind.JSDocReturnTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocTypeTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocThisTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocEnumTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocSatisfiesTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocThrowsTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocOverloadTag]: forEachChildInJSDocTypeLikeTag, + [SyntaxKind.JSDocSignature]: function forEachChildInJSDocSignature(node: AstJSDocSignature, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return forEach(node.data.typeParameters?.items, cbNode) || + forEach(node.data.parameters.items, cbNode) || + visitNode(cbNode, node.data.type); + }, + [SyntaxKind.JSDocLink]: forEachChildInJSDocLinkCodeOrPlain, + [SyntaxKind.JSDocLinkCode]: forEachChildInJSDocLinkCodeOrPlain, + [SyntaxKind.JSDocLinkPlain]: forEachChildInJSDocLinkCodeOrPlain, + [SyntaxKind.JSDocTypeLiteral]: function forEachChildInJSDocTypeLiteral(node: AstJSDocTypeLiteral, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return forEach(node.data.jsDocPropertyTags?.items, cbNode); + }, + [SyntaxKind.JSDocTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocClassTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocPublicTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocPrivateTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocProtectedTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocReadonlyTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocDeprecatedTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocOverrideTag]: forEachChildInJSDocTag, + [SyntaxKind.JSDocImportTag]: forEachChildInJSDocImportTag, + [SyntaxKind.PartiallyEmittedExpression]: forEachChildInPartiallyEmittedExpression, +}; + +// shared + +function forEachChildInCallOrConstructSignature(node: AstCallSignatureDeclaration | AstConstructSignatureDeclaration, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.parameters) || + visitNode(cbNode, node.data.type); +} + +function forEachChildInUnionOrIntersectionType(node: AstUnionTypeNode | AstIntersectionTypeNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.types); +} + +function forEachChildInParenthesizedTypeOrTypeOperator(node: AstParenthesizedTypeNode | AstTypeOperatorNode, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.type); +} + +function forEachChildInObjectOrArrayBindingPattern(node: AstBindingPattern, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.elements); +} + +function forEachChildInBlock(node: AstBlock | AstModuleBlock, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.statements); +} + +function forEachChildInContinueOrBreakStatement(node: AstContinueStatement | AstBreakStatement, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.label); +} + +function forEachChildInClassDeclarationOrExpression(node: AstClassDeclaration | AstClassExpression, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.modifiers) || + visitNode(cbNode, node.data.name) || + visitNodes(cbNode, cbNodes, node.data.typeParameters) || + visitNodes(cbNode, cbNodes, node.data.heritageClauses) || + visitNodes(cbNode, cbNodes, node.data.members); +} + +function forEachChildInNamedImportsOrExports(node: AstNamedImports | AstNamedExports, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNodes(cbNode, cbNodes, node.data.elements); +} + +function forEachChildInImportOrExportSpecifier(node: AstImportSpecifier | AstExportSpecifier, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.propertyName) || + visitNode(cbNode, node.data.name); +} + +function forEachChildInJsxOpeningOrSelfClosingElement(node: AstJsxOpeningLikeElement, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName) || + visitNodes(cbNode, cbNodes, node.data.typeArguments) || + visitNode(cbNode, node.data.attributes); +} + +function forEachChildInOptionalRestOrJSDocParameterModifier(node: AstOptionalTypeNode | AstRestTypeNode | AstJSDocTypeExpression | AstJSDocNullableType | AstJSDocNonNullableType | AstJSDocOptionalType | AstJSDocVariadicType, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.type); +} + +function forEachChildInJSDocParameterOrPropertyTag(node: AstJSDocParameterTag | AstJSDocPropertyTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName) || + (node.data.isNameFirst + ? visitNode(cbNode, node.data.name) || visitNode(cbNode, node.data.typeExpression) + : visitNode(cbNode, node.data.typeExpression) || visitNode(cbNode, node.data.name)) || + (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); +} + +function forEachChildInJSDocTypeLikeTag(node: AstJSDocReturnTag | AstJSDocTypeTag | AstJSDocThisTag | AstJSDocEnumTag | AstJSDocThrowsTag | AstJSDocOverloadTag | AstJSDocSatisfiesTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName) || + visitNode(cbNode, node.data.typeExpression) || + (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); +} + +function forEachChildInJSDocLinkCodeOrPlain(node: AstJSDocLink | AstJSDocLinkCode | AstJSDocLinkPlain, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.name); +} + +function forEachChildInJSDocTag(node: AstJSDocUnknownTag | AstJSDocClassTag | AstJSDocPublicTag | AstJSDocPrivateTag | AstJSDocProtectedTag | AstJSDocReadonlyTag | AstJSDocDeprecatedTag | AstJSDocOverrideTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName) + || (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); +} + +function forEachChildInJSDocImportTag(node: AstJSDocImportTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.tagName) + || visitNode(cbNode, node.data.importClause) + || visitNode(cbNode, node.data.moduleSpecifier) + || visitNode(cbNode, node.data.attributes) + || (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); +} + +function forEachChildInPartiallyEmittedExpression(node: AstPartiallyEmittedExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + return visitNode(cbNode, node.data.expression); +} + +/** + * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes + * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, + * embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns + * a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. + * + * @param node a given node to visit its children + * @param cbNode a callback to be invoked for all child nodes + * @param cbNodes a callback to be invoked for embedded array + * + * @remarks `forEachChild` must visit the children of a node in the order + * that they appear in the source code. The language service depends on this property to locate nodes by position. + */ +export function astForEachChild(node: AstNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { + if (node === undefined || node.kind <= SyntaxKind.LastToken) { + return; + } + const fn = (astForEachChildTable as Record>)[node.kind]; + return fn === undefined ? undefined : fn(node, cbNode, cbNodes); +} + +/** + * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes + * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; additionally, + * unlike `forEachChild`, embedded arrays are flattened and the 'cbNode' callback is invoked for each element. + * If a callback returns a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. + * + * @param node a given node to visit its children + * @param cbNode a callback to be invoked for all child nodes + * @param cbNodes a callback to be invoked for embedded array + * + * @remarks Unlike `forEachChild`, `forEachChildRecursively` handles recursively invoking the traversal on each child node found, + * and while doing so, handles traversing the structure without relying on the callstack to encode the tree structure. + * + * @internal + */ +export function astForEachChildRecursively(rootNode: AstNode, cbNode: (node: AstNode, parent: AstNode) => T | "skip" | undefined, cbNodes?: (nodes: AstNodeArray, parent: AstNode) => T | "skip" | undefined): T | undefined { + const queue: GatherEntry[] = gatherPossibleChildren(rootNode); + const parents: AstNode[] = []; // tracks parent references for elements in queue + while (parents.length < queue.length) { + parents.push(rootNode); + } + while (queue.length !== 0) { + const { kind, node, array } = queue.pop()!; + const parent = parents.pop()!; + if (kind === "array") { + if (cbNodes) { + const res = cbNodes(array, parent); + if (res) { + if (res === "skip") continue; + return res; + } + } + for (let i = array.items.length - 1; i >= 0; --i) { + queue.push(makeGatherEntry("node", array.items[i], /*array*/ undefined)); + parents.push(parent); + } + } + else { + const res = cbNode(node, parent); + if (res) { + if (res === "skip") continue; + return res; + } + if (node.kind >= SyntaxKind.FirstNode) { + // add children in reverse order to the queue, so popping gives the first child + for (const child of gatherPossibleChildren(node)) { + queue.push(child); + parents.push(node); + } + } + } + } +} + +interface AstNodeGatherEntry { + kind: "node"; + node: AstNode; + array: undefined; +} + +interface AstNodeArrayGatherEntry { + kind: "array"; + node: undefined; + array: AstNodeArray; +} + +type GatherEntry = AstNodeGatherEntry | AstNodeArrayGatherEntry; + +function makeGatherEntry(kind: "node" | "array", node: AstNode | undefined, array: AstNodeArray | undefined): GatherEntry { + return { kind, node, array } as GatherEntry; +} + +function gatherPossibleChildren(node: AstNode) { + const children: GatherEntry[] = []; + astForEachChild(node, addNodeWorkItem, addArrayWorkItem); // By using a stack above and `unshift` here, we emulate a depth-first preorder traversal + return children; + + function addNodeWorkItem(node: AstNode) { + children.unshift(makeGatherEntry("node", node, /*array*/ undefined)); + } + + function addArrayWorkItem(array: AstNodeArray) { + children.unshift(makeGatherEntry("array", /*node*/ undefined, array)); + } +} diff --git a/src/compiler/factory/astNodeFactory.ts b/src/compiler/factory/astNodeFactory.ts index 659cea94723f4..a86985a64ccc7 100644 --- a/src/compiler/factory/astNodeFactory.ts +++ b/src/compiler/factory/astNodeFactory.ts @@ -111,7 +111,7 @@ import { AstJSDocNameReference, AstJSDocNamespaceBody, AstJSDocNamespaceDeclaration, - AstJSDocNode, + AstJSDoc, AstJSDocNonNullableType, AstJSDocNullableType, AstJSDocOptionalType, @@ -835,8 +835,8 @@ export interface AstNodeFactory { updateJSDocImportTag(node: AstJSDocImportTag, tagName: AstIdentifier | undefined, importClause: AstImportClause | undefined, moduleSpecifier: AstExpression, attributes: AstImportAttributes | undefined, comment: string | AstNodeArray | undefined): AstJSDocImportTag; createJSDocText(text: string): AstJSDocText; updateJSDocText(node: AstJSDocText, text: string): AstJSDocText; - createJSDocComment(comment?: string | AstNodeArray | undefined, tags?: AstNodeArrayLike | undefined): AstJSDocNode; - updateJSDocComment(node: AstJSDocNode, comment: string | AstNodeArray | undefined, tags: AstNodeArrayLike | undefined): AstJSDocNode; + createJSDocComment(comment?: string | AstNodeArray | undefined, tags?: AstNodeArrayLike | undefined): AstJSDoc; + updateJSDocComment(node: AstJSDoc, comment: string | AstNodeArray | undefined, tags: AstNodeArrayLike | undefined): AstJSDoc; // // JSX @@ -5084,7 +5084,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no } // @api - function updateJSDocComment(node: AstJSDocNode, comment: string | AstNodeArray | undefined, tags: AstNodeArrayLike | undefined) { + function updateJSDocComment(node: AstJSDoc, comment: string | AstNodeArray | undefined, tags: AstNodeArrayLike | undefined) { return node.data.comment !== comment || !sameNodeArray(node.data.tags, tags) ? update(createJSDocComment(comment, tags), node) diff --git a/src/compiler/factory/astNodeTests.ts b/src/compiler/factory/astNodeTests.ts index 49154ccde35f7..1abb9fbfcd62c 100644 --- a/src/compiler/factory/astNodeTests.ts +++ b/src/compiler/factory/astNodeTests.ts @@ -109,7 +109,7 @@ import { JSDocMemberName, JSDocNamepathType, JSDocNameReference, - JSDocNode, + JSDoc, JSDocNonNullableType, JSDocNullableType, JSDocOptionalType, @@ -240,6 +240,8 @@ import { WhileStatement, WithStatement, YieldExpression, + AstHasModifiers, + AstHasDecorators, } from "../_namespaces/ts.ast.js"; import { canHaveJSDoc, @@ -1293,7 +1295,7 @@ export function isAstJSDocNamepathType(node: AstNode): node is AstNode { +export function isAstJSDoc(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDoc; } @@ -1508,9 +1510,51 @@ export function isAstStringLiteralLike(node: AstNode): node is AstStringLiteralL * * @internal */ -export function hasAstJSDocNodes(node: AstNode): node is AstHasJSDoc { +export function astHasJSDocNodes(node: AstNode): node is AstHasJSDoc { if (!canHaveJSDoc(node)) return false; const { data: { jsDoc } } = node; return !!jsDoc && jsDoc.length > 0; } + +/** @internal */ +export function astCanHaveModifiers(node: AstNode): node is AstHasModifiers { + const kind = node.kind; + return kind === SyntaxKind.TypeParameter + || kind === SyntaxKind.Parameter + || kind === SyntaxKind.PropertySignature + || kind === SyntaxKind.PropertyDeclaration + || kind === SyntaxKind.MethodSignature + || kind === SyntaxKind.MethodDeclaration + || kind === SyntaxKind.Constructor + || kind === SyntaxKind.GetAccessor + || kind === SyntaxKind.SetAccessor + || kind === SyntaxKind.IndexSignature + || kind === SyntaxKind.ConstructorType + || kind === SyntaxKind.FunctionExpression + || kind === SyntaxKind.ArrowFunction + || kind === SyntaxKind.ClassExpression + || kind === SyntaxKind.VariableStatement + || kind === SyntaxKind.FunctionDeclaration + || kind === SyntaxKind.ClassDeclaration + || kind === SyntaxKind.InterfaceDeclaration + || kind === SyntaxKind.TypeAliasDeclaration + || kind === SyntaxKind.EnumDeclaration + || kind === SyntaxKind.ModuleDeclaration + || kind === SyntaxKind.ImportEqualsDeclaration + || kind === SyntaxKind.ImportDeclaration + || kind === SyntaxKind.ExportAssignment + || kind === SyntaxKind.ExportDeclaration; +} + +/** @internal */ +export function astCanHaveDecorators(node: AstNode): node is AstHasDecorators { + const kind = node.kind; + return kind === SyntaxKind.Parameter + || kind === SyntaxKind.PropertyDeclaration + || kind === SyntaxKind.MethodDeclaration + || kind === SyntaxKind.GetAccessor + || kind === SyntaxKind.SetAccessor + || kind === SyntaxKind.ClassExpression + || kind === SyntaxKind.ClassDeclaration; +} diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6643fd57636ea..d240c141f3837 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -80,7 +80,7 @@ import { AstJSDocMemberName, AstJSDocNameReference, AstJSDocNamespaceDeclaration, - AstJSDocNode, + AstJSDoc, AstJSDocNullableType, AstJSDocOptionalType, AstJSDocOverloadTag, @@ -214,7 +214,7 @@ import { AstWithStatement, AstYieldExpression, createAstNodeFactory, - hasAstJSDocNodes, + astHasJSDocNodes, isAstAsyncModifier, isAstDeclareKeyword, isAstExportModifier, @@ -235,6 +235,15 @@ import { isAstStringOrNumericLiteralLike, isAstTaggedTemplateExpression, isAstTypeReferenceNode, + astForEachChild, + isAstMetaProperty, + astCanHaveModifiers, + AstHasModifiers, + isAstImportEqualsDeclaration, + isAstImportDeclaration, + isAstExportAssignment, + isAstExportDeclaration, + isAstExternalModuleReference, } from "./_namespaces/ts.ast.js"; import { addRange, @@ -401,35 +410,36 @@ export function isJSDocLikeText(text: string, start: number): boolean { export function isFileProbablyExternalModule(sourceFile: SourceFile): Node | undefined { // Try to use the first top-level import/export when available, then // fall back to looking for an 'import.meta' somewhere in the tree if necessary. - return forEach(sourceFile.statements, isAnExternalModuleIndicatorNode) || - getImportMetaIfNecessary(sourceFile); + // TODO(rbuckton): do not instantiate .node + return forEach((sourceFile as AstSourceFile["node"]).ast.data.statements.items, isAnExternalModuleIndicatorNode)?.node || + getImportMetaIfNecessary(sourceFile)?.node; } -function isAnExternalModuleIndicatorNode(node: Node) { - return canHaveModifiers(node) && hasModifierOfKind(node, SyntaxKind.ExportKeyword) - || isImportEqualsDeclaration(node) && isExternalModuleReference(node.moduleReference) - || isImportDeclaration(node) - || isExportAssignment(node) - || isExportDeclaration(node) ? node : undefined; +function isAnExternalModuleIndicatorNode(node: AstNode) { + return astCanHaveModifiers(node) && hasModifierOfKind(node, SyntaxKind.ExportKeyword) + || isAstImportEqualsDeclaration(node) && isAstExternalModuleReference(node.data.moduleReference) + || isAstImportDeclaration(node) + || isAstExportAssignment(node) + || isAstExportDeclaration(node) ? node : undefined; } function getImportMetaIfNecessary(sourceFile: SourceFile) { return sourceFile.flags & NodeFlags.PossiblyContainsImportMeta ? - walkTreeForImportMeta(sourceFile) : + walkTreeForImportMeta((sourceFile as AstSourceFile["node"]).ast) : undefined; } -function walkTreeForImportMeta(node: Node): Node | undefined { - return isImportMeta(node) ? node : forEachChild(node, walkTreeForImportMeta); +function walkTreeForImportMeta(node: AstNode): AstNode | undefined { + return isImportMeta(node) ? node : astForEachChild(node, walkTreeForImportMeta); } /** Do not use hasModifier inside the parser; it relies on parent pointers. Use this instead. */ -function hasModifierOfKind(node: HasModifiers, kind: SyntaxKind) { - return some(node.modifiers, m => m.kind === kind); +function hasModifierOfKind(node: AstHasModifiers, kind: SyntaxKind) { + return some(node.data.modifiers?.items, m => m.kind === kind); } -function isImportMeta(node: Node): boolean { - return isMetaProperty(node) && node.keywordToken === SyntaxKind.ImportKeyword && node.name.escapedText === "meta"; +function isImportMeta(node: AstNode): boolean { + return isAstMetaProperty(node) && node.data.keywordToken === SyntaxKind.ImportKeyword && node.data.name.data.escapedText === "meta"; } export interface CreateSourceFileOptions { @@ -530,7 +540,7 @@ export function parseIsolatedJSDocComment(content: string, start?: number, lengt if (result && result.jsDoc) { // because the jsDocComment was parsed out of the source file, it might // not be covered by the fixupParentReferences. - Parser.fixupParentReferences((result.jsDoc as AstJSDocNode["node"]).ast); + Parser.fixupParentReferences((result.jsDoc as AstJSDoc["node"]).ast); } return result; @@ -7902,7 +7912,7 @@ namespace Parser { return jsDoc ? { jsDoc: jsDoc.node, diagnostics } : undefined; } - export function parseJSDocComment(parent: AstHasJSDoc, start: number, length: number): AstJSDocNode | undefined { + export function parseJSDocComment(parent: AstHasJSDoc, start: number, length: number): AstJSDoc | undefined { const saveToken = currentToken; const saveParseDiagnosticsLength = parseDiagnostics.length; const saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; @@ -7935,7 +7945,7 @@ namespace Parser { CallbackParameter = 1 << 2, } - function parseJSDocCommentWorker(start = 0, length: number | undefined): AstJSDocNode | undefined { + function parseJSDocCommentWorker(start = 0, length: number | undefined): AstJSDoc | undefined { const content = sourceText; const end = length === undefined ? content.length : start + length; length = end - start; @@ -9144,11 +9154,7 @@ namespace IncrementalParser { } return; - function visitNode(node: Node | AstNode) { - if (!(node instanceof AstNode)) { - node = (node as AstNode["node"]).ast; - } - + function visitNode(node: AstNode) { let text = ""; if (aggressiveChecks && shouldCheckNode(node)) { text = oldText.substring(node.pos, node.end); @@ -9164,20 +9170,16 @@ namespace IncrementalParser { Debug.assert(text === newText.substring(node.pos, node.end)); } - forEachChild(node.node, visitNode as (node: Node) => void, visitArray as (nodes: NodeArray) => void); // TODO(rbuckton): do not instantiate .node - if (hasAstJSDocNodes(node)) { + astForEachChild(node, visitNode, visitArray); + if (astHasJSDocNodes(node)) { for (const jsDocComment of node.data.jsDoc!) { - visitNode(jsDocComment); + visitNode((jsDocComment as AstJSDoc["node"]).ast); // TODO(rbuckton): have JSDocArray store AstJSDoc entries } } checkNodePositions(node, aggressiveChecks); } - function visitArray(array: NodeArray | AstNodeArray) { - if (!(array instanceof AstNodeArray)) { - array = (array as AstNodeArray["nodes"]).ast; - } - + function visitArray(array: AstNodeArray) { setTextRangePosEnd(array, array.pos + delta, array.end + delta); for (const node of array.items) { @@ -9275,16 +9277,16 @@ namespace IncrementalParser { function checkNodePositions(node: AstNode, aggressiveChecks: boolean) { if (aggressiveChecks) { let pos = node.pos; - const visitNode = (child: Node) => { + const visitNode = (child: AstNode) => { Debug.assert(child.pos >= pos); pos = child.end; }; - if (hasAstJSDocNodes(node)) { + if (astHasJSDocNodes(node)) { for (const jsDocComment of node.data.jsDoc!) { - visitNode(jsDocComment); + visitNode((jsDocComment as AstJSDoc["node"]).ast); // TODO(rbuckton): have JSDocArray store AstJSDoc entries } } - forEachChild(node.node, visitNode); // TODO: do not instantiate .node + astForEachChild(node, visitNode); Debug.assert(pos <= node.end); } } @@ -9302,11 +9304,7 @@ namespace IncrementalParser { visitNode(sourceFile); return; - function visitNode(child: Node | AstNode) { - if (!(child instanceof AstNode)) { - child = (child as AstNode["node"]).ast; - } - + function visitNode(child: AstNode) { Debug.assert(child.pos <= child.end); if (child.pos > changeRangeOldEnd) { // Node is entirely past the change range. We need to move both its pos and @@ -9325,10 +9323,10 @@ namespace IncrementalParser { // Adjust the pos or end (or both) of the intersecting element accordingly. adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); - forEachChild(child.node, visitNode as (node: Node) => void, visitArray as (nodes: NodeArray) => void); // TODO: do not instantiate .node - if (hasAstJSDocNodes(child)) { // TODO: do not instantiate .node + astForEachChild(child, visitNode, visitArray); + if (astHasJSDocNodes(child)) { for (const jsDocComment of child.data.jsDoc!) { - visitNode((jsDocComment as AstJSDocNode["node"]).ast); + visitNode((jsDocComment as AstJSDoc["node"]).ast); } } checkNodePositions(child, aggressiveChecks); @@ -9339,11 +9337,7 @@ namespace IncrementalParser { Debug.assert(fullEnd < changeStart); } - function visitArray(array: NodeArray | AstNodeArray) { - if (!(array instanceof AstNodeArray)) { - array = (array as AstNodeArray["nodes"]).ast; - } - + function visitArray(array: AstNodeArray) { Debug.assert(array.pos <= array.end); if (array.pos > changeRangeOldEnd) { // Array is entirely after the change range. We need to move it, and move any of @@ -9408,7 +9402,7 @@ namespace IncrementalParser { let bestResult: AstNode = sourceFile; let lastNodeEntirelyBeforePosition: AstNode | undefined; - forEachChild(sourceFile.node, visit); // TODO(rbuckton): do not instantiate .node + astForEachChild(sourceFile, visit); if (lastNodeEntirelyBeforePosition) { const lastChildOfLastEntireNodeBeforePosition = getLastDescendant(lastNodeEntirelyBeforePosition); @@ -9431,11 +9425,7 @@ namespace IncrementalParser { } } - function visit(child: Node | AstNode) { - if (!(child instanceof AstNode)) { - child = (child as AstNode["node"]).ast; - } - + function visit(child: AstNode) { if (nodeIsMissing(child)) { // Missing nodes are effectively invisible to us. We never even consider them // When trying to find the nearest node before us. @@ -9459,7 +9449,7 @@ namespace IncrementalParser { // The nearest node is either this child, or one of the children inside // of it. We've already marked this child as the best so far. Recurse // in case one of the children is better. - forEachChild(child.node, visit); // TODO(rbuckton): do not instantiate .node + astForEachChild(child, visit); // Once we look at the children of this node, then there's no need to // continue any further. @@ -9570,13 +9560,13 @@ namespace IncrementalParser { current = undefined!; // Recurse into the source file to find the highest node at this position. - forEachChild(sourceFile.node, visitNode, visitArray); // TODO(rbuckton): do not instantiate .node + astForEachChild(sourceFile, visitNode, visitArray); return; - function visitNode(node: Node) { // TODO(rbuckton): use AstNode + function visitNode(node: AstNode) { if (position >= node.pos && position < node.end) { // Position was within this node. Keep searching deeper to find the node. - forEachChild(node, visitNode, visitArray); + astForEachChild(node, visitNode, visitArray); // don't proceed any further in the search. return true; @@ -9586,11 +9576,7 @@ namespace IncrementalParser { return false; } - function visitArray(array: NodeArray | AstNodeArray) { - if (!(array instanceof AstNodeArray)) { - array = (array as AstNodeArray["nodes"]).ast; - } - + function visitArray(array: AstNodeArray) { if (position >= array.pos && position < array.end) { // position was in this array. Search through this array to see if we find a // viable element. @@ -9608,7 +9594,7 @@ namespace IncrementalParser { if (child.pos < position && position < child.end) { // Position in somewhere within this child. Search in it and // stop searching in this array. - forEachChild(child.node, visitNode, visitArray); // TODO(rbuckton): do not instantiate .node + astForEachChild(child, visitNode, visitArray); return true; } } From 0f2a20fa57d858b62ebe3f2c42390f8ffe219367 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 20 Sep 2024 01:33:24 -0400 Subject: [PATCH 06/10] Unify types --- scripts/dtsBundler.mjs | 110 +- src/compiler/_namespaces/ts.ast.ts | 2 + src/compiler/_namespaces/ts.ts | 11 +- src/compiler/ast.ts | 13301 ++-------------- src/compiler/astForEachChild.ts | 5 +- src/compiler/binder.ts | 8 +- src/compiler/checker.ts | 51 +- src/compiler/emitter.ts | 6 +- src/compiler/expressionToTypeNode.ts | 4 +- src/compiler/factory/astNodeFactory.ts | 44 +- src/compiler/factory/astNodeTests.ts | 22 +- src/compiler/factory/astParenthesizerRules.ts | 11 +- src/compiler/factory/emitNode.ts | 40 +- src/compiler/factory/nodeChildren.ts | 107 + src/compiler/factory/nodeFactory.ts | 767 +- src/compiler/factory/nodeTests.ts | 4 +- src/compiler/factory/parenthesizerRules.ts | 95 +- src/compiler/factory/utilities.ts | 14 +- src/compiler/forEachChild.ts | 5 +- src/compiler/moduleSpecifiers.ts | 7 +- src/compiler/nodes.ts | 613 + src/compiler/parser.ts | 107 +- src/compiler/program.ts | 15 +- src/compiler/transformers/classFields.ts | 5 +- src/compiler/transformers/declarations.ts | 3 +- .../transformers/declarations/diagnostics.ts | 5 +- src/compiler/transformers/es2015.ts | 6 +- src/compiler/transformers/esDecorators.ts | 19 +- src/compiler/transformers/generators.ts | 3 +- src/compiler/transformers/jsx.ts | 2 +- src/compiler/types.ts | 6004 +++++-- src/compiler/utilities.ts | 88 +- src/compiler/utilitiesPublic.ts | 110 +- src/harness/harnessUtils.ts | 16 +- src/services/breakpoints.ts | 6 +- src/services/callHierarchy.ts | 4 +- ...dConvertToUnknownForNonOverlappingTypes.ts | 8 +- .../codefixes/convertFunctionToEs6Class.ts | 3 +- src/services/codefixes/convertToEsModule.ts | 9 +- .../codefixes/convertToMappedObjectType.ts | 2 +- src/services/codefixes/fixJSDocTypes.ts | 4 +- src/services/codefixes/helpers.ts | 3 +- src/services/codefixes/inferFromUsage.ts | 2 +- src/services/findAllReferences.ts | 7 +- src/services/goToDefinition.ts | 3 +- src/services/importTracker.ts | 2 +- src/services/navigationBar.ts | 7 +- ...onvertArrowFunctionOrFunctionExpression.ts | 6 +- src/services/refactors/extractSymbol.ts | 4 +- src/services/suggestionDiagnostics.ts | 7 +- src/services/symbolDisplay.ts | 3 +- src/services/textChanges.ts | 11 +- src/services/types.ts | 90 +- src/services/utilities.ts | 7 +- tests/baselines/reference/api/typescript.d.ts | 6585 +++++--- .../reference/objectRestPropertyMustBeLast.js | 2 +- 56 files changed, 12629 insertions(+), 15756 deletions(-) create mode 100644 src/compiler/nodes.ts diff --git a/scripts/dtsBundler.mjs b/scripts/dtsBundler.mjs index ade134287fe57..d915a38b56ba8 100644 --- a/scripts/dtsBundler.mjs +++ b/scripts/dtsBundler.mjs @@ -307,33 +307,61 @@ function symbolsConflict(s1, s2) { */ function verifyMatchingSymbols(decl, isInternal) { ts.visitEachChild(decl, /** @type {(node: ts.Node) => ts.Node} */ function visit(node) { - if (ts.isIdentifier(node) && ts.isPartOfTypeNode(node)) { - if (ts.isQualifiedName(node.parent) && node !== node.parent.left) { - return node; - } - if (ts.isParameter(node.parent) && node === node.parent.name) { - return node; + if (ts.isIdentifier(node)) { + let meaning = ts.SymbolFlags.None; + if (ts.isPartOfTypeNode(node)) { + if (ts.isQualifiedName(node.parent) && node !== node.parent.left) { + return node; + } + if (ts.isParameter(node.parent) && node === node.parent.name) { + return node; + } + if (ts.isNamedTupleMember(node.parent) && node === node.parent.name) { + return node; + } + meaning = ts.SymbolFlags.Type; } - if (ts.isNamedTupleMember(node.parent) && node === node.parent.name) { - return node; + else if (ts.isExpressionWithTypeArguments(node.parent) && + ts.isHeritageClause(node.parent.parent) && + ts.isClassLike(node.parent.parent.parent)) { + meaning = ts.SymbolFlags.Value; } - const symbolOfNode = typeChecker.getSymbolAtLocation(node); - if (!symbolOfNode) { - fail(`No symbol for node at ${nodeToLocation(node)}`); - } - const symbolInScope = findInScope(symbolOfNode.name); - if (!symbolInScope) { - if (symbolOfNode.declarations?.every(d => isLocalDeclaration(d) && d.getSourceFile() === decl.getSourceFile()) && !isSelfReference(node, symbolOfNode)) { - // The symbol is a local that needs to be copied into the scope. - scopeStack[scopeStack.length - 1].locals.set(symbolOfNode.name, { symbol: symbolOfNode, writeTarget: isInternal ? WriteTarget.Internal : WriteTarget.Both }); + if (meaning) { + const symbolOfNode = typeChecker.getSymbolAtLocation(node); + if (!symbolOfNode) { + fail(`No symbol for node at ${nodeToLocation(node)}`); + } + const symbolInScope = findInScope(symbolOfNode.name); + if (!symbolInScope) { + /** @type {ts.Declaration[]} */ + const declarations = []; + if (meaning === ts.SymbolFlags.Type && symbolOfNode.declarations) { + declarations.push(...symbolOfNode.declarations); + } + else if (meaning === ts.SymbolFlags.Value && symbolOfNode.valueDeclaration) { + declarations.push(symbolOfNode.valueDeclaration); + } + if (declarations.every(d => isLocalDeclaration(d) && d.getSourceFile() === decl.getSourceFile()) && !isSelfReference(node, symbolOfNode)) { + // The symbol is a local that needs to be copied into the scope. + const locals = scopeStack[scopeStack.length - 1].locals; + if (!locals.has(symbolOfNode.name)) { + locals.set(symbolOfNode.name, { symbol: symbolOfNode, writeTarget: isInternal ? WriteTarget.Internal : WriteTarget.Both }); + if (symbolOfNode.valueDeclaration) { + const statement = getDeclarationStatement(symbolOfNode.valueDeclaration); + if (statement) { + verifyMatchingSymbols(statement, isInternal); + } + } + } + } + // We didn't find the symbol in scope at all. Just allow it and we'll fail at test time. + return node; + } + + if (symbolsConflict(symbolOfNode, symbolInScope)) { + fail(`Declaration at ${nodeToLocation(decl)}\n references ${symbolOfNode.name} at ${symbolOfNode.declarations && nodeToLocation(symbolOfNode.declarations[0])},\n but containing scope contains a symbol with the same name declared at ${symbolInScope.declarations && nodeToLocation(symbolInScope.declarations[0])}`); } - // We didn't find the symbol in scope at all. Just allow it and we'll fail at test time. - return node; - } - - if (symbolsConflict(symbolOfNode, symbolInScope)) { - fail(`Declaration at ${nodeToLocation(decl)}\n references ${symbolOfNode.name} at ${symbolOfNode.declarations && nodeToLocation(symbolOfNode.declarations[0])},\n but containing scope contains a symbol with the same name declared at ${symbolInScope.declarations && nodeToLocation(symbolInScope.declarations[0])}`); } } @@ -345,9 +373,10 @@ function verifyMatchingSymbols(decl, isInternal) { * @param {ts.Declaration} decl */ function isLocalDeclaration(decl) { - return ts.canHaveModifiers(decl) - && !ts.getModifiers(decl)?.some(m => m.kind === ts.SyntaxKind.ExportKeyword) - && !!getDeclarationStatement(decl); + const statement = getDeclarationStatement(decl); + return !!statement + && ts.canHaveModifiers(statement) + && !ts.getModifiers(statement)?.some(m => m.kind === ts.SyntaxKind.ExportKeyword); } /** @@ -456,7 +485,34 @@ function emitAsNamespace(name, parent, moduleSymbol, needExportModifier) { symbol.declarations?.forEach(decl => { // We already checked that getDeclarationStatement(decl) works for each declaration. const statement = getDeclarationStatement(decl); - writeNode(/** @type {ts.Statement} */ (statement), decl.getSourceFile(), writeTarget); + if (!statement) return; + + if (writeTarget & WriteTarget.Public) { + if (!ts.isInternalDeclaration(statement)) { + const publicStatement = ts.visitEachChild(statement, node => { + // No @internal comments in the public API. + if (ts.isInternalDeclaration(node)) { + return undefined; + } + // TODO: remove after https://github.com/microsoft/TypeScript/pull/58187 is released + if (ts.canHaveModifiers(node)) { + for (const modifier of ts.getModifiers(node) ?? []) { + if (modifier.kind === ts.SyntaxKind.PrivateKeyword) { + removeAllComments(node); + break; + } + } + } + return removeDeclareConstExport(node, /*needExportModifier*/ false); + }, /*context*/ undefined); + writeNode(/** @type {ts.Statement} */ (publicStatement), decl.getSourceFile(), WriteTarget.Public); + } + } + + if (writeTarget & WriteTarget.Internal) { + const updated = ts.visitEachChild(statement, node => removeDeclareConstExport(node, childrenNeedExportModifier), /*context*/ undefined); + writeNode(/** @type {ts.Statement} */ (updated), decl.getSourceFile(), WriteTarget.Internal); + } }); }); diff --git a/src/compiler/_namespaces/ts.ast.ts b/src/compiler/_namespaces/ts.ast.ts index 11cf59bd99d2c..a94e77582a5e1 100644 --- a/src/compiler/_namespaces/ts.ast.ts +++ b/src/compiler/_namespaces/ts.ast.ts @@ -1,3 +1,5 @@ +// /** @internal */ +// export * from "../nodes.js"; /** @internal */ export * from "../ast.js"; /** @internal */ diff --git a/src/compiler/_namespaces/ts.ts b/src/compiler/_namespaces/ts.ts index 22938bf674fe4..a9caabfc7245c 100644 --- a/src/compiler/_namespaces/ts.ts +++ b/src/compiler/_namespaces/ts.ts @@ -7,6 +7,7 @@ export * from "../semver.js"; export * from "../performanceCore.js"; export * from "../tracing.js"; export * from "../types.js"; +export * from "../ast.js"; export * from "../sys.js"; export * from "../path.js"; export * from "../diagnosticInformationMap.generated.js"; @@ -14,16 +15,20 @@ export * from "../scanner.js"; export * from "../utilitiesPublic.js"; export * from "../utilities.js"; export * from "../factory/parenthesizerRules.js"; +export * from "../factory/astParenthesizerRules.js"; export * from "../factory/nodeConverters.js"; export * from "../factory/nodeFactory.js"; +export * from "../factory/astNodeFactory.js"; export * from "../factory/emitNode.js"; +export * from "../factory/astNodeTests.js"; export * from "../factory/emitHelpers.js"; export * from "../factory/nodeTests.js"; export * from "../factory/nodeChildren.js"; export * from "../factory/utilities.js"; export * from "../factory/utilitiesPublic.js"; -export * from "../forEachChild.js"; export * from "../parser.js"; +export * from "../forEachChild.js"; +export * from "../astForEachChild.js"; export * from "../commandLineParser.js"; export * from "../moduleNameResolver.js"; export * from "../binder.js"; @@ -76,7 +81,3 @@ import * as moduleSpecifiers from "./ts.moduleSpecifiers.js"; export { moduleSpecifiers }; import * as performance from "./ts.performance.js"; export { performance }; -/** @internal */ -import * as ast from "./ts.ast.js"; -/** @internal */ -export { ast }; \ No newline at end of file diff --git a/src/compiler/ast.ts b/src/compiler/ast.ts index 235c237c44a2a..2352b5169685e 100644 --- a/src/compiler/ast.ts +++ b/src/compiler/ast.ts @@ -1,104 +1,518 @@ -import { isAstParenthesizedExpression } from "./_namespaces/ts.ast.js"; -import * as ts from "./_namespaces/ts.js"; +/* eslint-disable local/jsdoc-format -- need @internal to work around issue with dtsBundler */ import { __String, + AbstractKeyword, + AccessorDeclaration, + AccessorKeyword, AmdDependency, - AssignmentOperator, - BinaryOperator, + AmpersandAmpersandEqualsToken, + ArrayBindingElement, + ArrayBindingPattern, + ArrayLiteralExpression, + ArrayTypeNode, + ArrowFunction, + AsExpression, + AssertClause, + AssertionKey, + AssertKeyword, + AssertsKeyword, + AsteriskToken, + AsyncKeyword, + AwaitExpression, + AwaitKeyword, + BarBarEqualsToken, + BigIntLiteral, + BinaryExpression, + BinaryOperatorToken, + BindingElement, + BindingName, + BindingPattern, + Block, + BooleanLiteral, + BreakOrContinueStatement, + BreakStatement, + Bundle, + CallChain, + CallChainRoot, + CallExpression, + CallSignatureDeclaration, + CaseBlock, + CaseClause, + CaseKeyword, + CaseOrDefaultClause, + CatchClause, CheckJsDirective, + ClassDeclaration, + ClassElement, + ClassExpression, + ClassLikeDeclaration, + ClassStaticBlockDeclaration, + ColonToken, + CommaListExpression, CommentDirective, - computePositionOfLineAndCharacter, + ComputedPropertyName, + ConciseBody, + ConditionalExpression, + ConditionalTypeNode, + ConfigFileSpecs, + ConstKeyword, + ConstructorDeclaration, + ConstructorTypeNode, + ConstructSignatureDeclaration, containsObjectRestOrSpread, - createMultiMap, - createScanner, + ContinueStatement, Debug, + DebuggerStatement, + Declaration, + DeclarationName, + DeclarationWithTypeParameterChildren, + DeclareKeyword, + Decorator, + DefaultClause, + DefaultKeyword, + DeleteExpression, + DestructuringAssignment, DiagnosticWithLocation, + DoStatement, + DotDotDotToken, + DotToken, + ElementAccessChain, + ElementAccessChainRoot, + ElementAccessExpression, EmitFlags, EmitNode, - emptyArray, + EmptyStatement, + EndOfFileToken, + EntityName, + EntityNameExpression, + EnumDeclaration, + EnumMember, + EqualsGreaterThanToken, + EqualsToken, + ExclamationToken, + ExportAssignment, + ExportDeclaration, + ExportKeyword, + ExportSpecifier, + Expression, + ExpressionStatement, + ExpressionWithTypeArguments, + ExternalModuleReference, + FalseLiteral, FileReference, - find, FlowNode, - forEach, - forEachChild, - getAssignmentDeclarationKind, - getLineAndCharacterOfPosition, - getLineStarts, - getNodeChildren, - getNonAssignedNameOfDeclaration, - getSourceFileOfNode, - getTextOfIdentifierOrLiteral, - getTokenPosOfNode, + ForEachChildNodes, + ForInitializer, + ForInOrOfStatement, + ForInStatement, + ForOfStatement, + ForStatement, + FunctionBody, + FunctionDeclaration, + FunctionExpression, + FunctionOrConstructorTypeNode, + FunctionTypeNode, + GetAccessorDeclaration, + getJSDocTypeTag, getTransformFlagsSubtreeExclusions, + HasChildren, + HasDecorators, + HasJSDoc, + HasLocals, + HasModifiers, + HasName, hasProperty, - hasSyntacticModifier, - hasTabstop, - idText, - isBindingPattern, - isComputedPropertyName, - isJSDocCommentContainingNode, + HeritageClause, + Identifier, + IfStatement, + ImportAttribute, + ImportAttributeName, + ImportAttributes, + ImportClause, + ImportDeclaration, + ImportEqualsDeclaration, + ImportExpression, + ImportSpecifier, + ImportTypeAssertionContainer, + ImportTypeNode, + IndexedAccessTypeNode, + IndexSignatureDeclaration, + InferTypeNode, + InKeyword, + InterfaceDeclaration, + IntersectionTypeNode, + isAstParenthesizedExpression, + IScriptSnapshot, isLogicalOrCoalescingAssignmentOperator, - isNamedExports, - isPrivateIdentifier, - isPropertyAccessExpression, - isPropertyName, - isStringOrNumericLiteralLike, + isParseTreeNode, + IterationStatement, + JSDoc, + JSDocAllType, JSDocArray, + JSDocAugmentsTag, + JSDocAuthorTag, + JSDocCallbackTag, + JSDocClassReference, + JSDocClassTag, + JSDocComment, + JSDocDeprecatedTag, + JSDocEnumTag, + JSDocFunctionType, + JSDocImplementsTag, + JSDocImportTag, + JSDocLink, + JSDocLinkCode, + JSDocLinkPlain, + JSDocMemberName, + JSDocNamepathType, + JSDocNameReference, + JSDocNamespaceBody, + JSDocNamespaceDeclaration, + JSDocNonNullableType, + JSDocNullableType, + JSDocOptionalType, + JSDocOverloadTag, + JSDocOverrideTag, + JSDocParameterTag, + JSDocParsingMode, + JSDocPrivateTag, + JSDocPropertyLikeTag, + JSDocPropertyTag, + JSDocProtectedTag, + JSDocPublicTag, + JSDocReadonlyTag, + JSDocReturnTag, + JSDocSatisfiesTag, + JSDocSeeTag, + JSDocSignature, + JSDocTag, + JSDocTemplateTag, + JSDocText, + JSDocThisTag, + JSDocThrowsTag, + JSDocType, + JSDocTypeAssertion, + JSDocTypedefTag, + JSDocTypeExpression, + JSDocTypeLiteral, + JSDocTypeTag, + JSDocUnknownTag, + JSDocUnknownType, + JSDocVariadicType, + JsonMinusNumericLiteral, + JsonObjectExpression, + JsonObjectExpressionStatement, + JsonSourceFile, + JsxAttribute, + JsxAttributeLike, + JsxAttributeName, + JsxAttributes, + JsxAttributeValue, + JsxChild, + JsxClosingElement, + JsxClosingFragment, + JsxElement, + JsxExpression, + JsxFragment, + JsxNamespacedName, + JsxOpeningElement, + JsxOpeningFragment, + JsxOpeningLikeElement, + JsxSelfClosingElement, + JsxSpreadAttribute, + JsxTagNameExpression, + JsxTagNamePropertyAccess, + JsxText, + KeywordExpression, KeywordSyntaxKind, + KeywordToken, + KeywordTypeNode, + KeywordTypeSyntaxKind, + LabeledStatement, LanguageVariant, - lastOrUndefined, + LeftHandSideExpression, + LiteralExpression, + LiteralLikeNode, + LiteralToken, + LiteralTypeNode, + MappedTypeNode, + MemberExpression, + MemberName, + MetaProperty, + MethodDeclaration, + MethodSignature, + MinusToken, + MissingDeclaration, + Modifier, ModifierFlags, + ModifierLike, ModifierSyntaxKind, modifierToFlag, + ModifierToken, + ModuleBlock, + ModuleBody, + ModuleDeclaration, + ModuleExportName, + ModuleName, + ModuleReference, + NamedDeclaration, + NamedExportBindings, + NamedExports, + NamedImportBindings, + NamedImports, + NamedTupleMember, + NamespaceBody, + NamespaceDeclaration, + NamespaceExport, + NamespaceExportDeclaration, + NamespaceImport, + NewExpression, + Node, + NodeArray, + NodeConstructor, NodeFlags, NodeId, + NonNullChain, + NonNullExpression, + NoSubstitutionTemplateLiteral, + NotEmittedStatement, + NotEmittedTypeElement, + NullLiteral, + NumericLiteral, + ObjectBindingPattern, + ObjectLiteralElement, + ObjectLiteralElementLike, + ObjectLiteralExpression, + ObjectTypeDeclaration, + OmittedExpression, + OptionalChainRoot, + OptionalTypeNode, + OuterExpression, + OuterExpressionKinds, + OutKeyword, + OverrideKeyword, PackageJsonInfo, + ParameterDeclaration, + ParenthesizedExpression, + ParenthesizedTypeNode, + PartiallyEmittedExpression, Path, - positionIsSynthesized, + PatternAmbientModule, + PlusToken, + PostfixUnaryExpression, PostfixUnaryOperator, + PrefixUnaryExpression, PrefixUnaryOperator, + PrimaryExpression, + PrivateIdentifier, + PrivateKeyword, + PropertyAccessChain, + PropertyAccessChainRoot, + PropertyAccessEntityNameExpression, + PropertyAccessExpression, + PropertyAssignment, + PropertyDeclaration, + PropertyName, + PropertyNameLiteral, + PropertySignature, + ProtectedKeyword, + PseudoLiteralToken, + PublicKeyword, PunctuationSyntaxKind, + PunctuationToken, + QualifiedName, + QuestionDotToken, + QuestionQuestionEqualsToken, + QuestionToken, + ReadonlyKeyword, ReadonlyPragmaMap, + RedirectInfo, + RegularExpressionLiteral, ResolutionMode, - Scanner, + RestTypeNode, + ReturnStatement, + SatisfiesExpression, ScriptKind, ScriptTarget, - setNodeChildren, + SemicolonClassElement, + SetAccessorDeclaration, + ShorthandPropertyAssignment, + SignatureDeclaration, + SourceFile, + SpreadAssignment, + SpreadElement, + Statement, + StaticKeyword, + StringLiteral, + StringLiteralLike, + StringLiteralLikeNode, + SuperExpression, + SwitchStatement, Symbol, SymbolTable, SyntaxKind, + SyntaxList, + SyntheticExpression, + SyntheticReferenceExpression, + TaggedTemplateExpression, + TemplateExpression, + TemplateHead, + TemplateLiteral, + TemplateLiteralLikeNode, + TemplateLiteralToken, + TemplateLiteralTypeNode, + TemplateLiteralTypeSpan, + TemplateMiddle, + TemplateSpan, + TemplateTail, + ThisExpression, + ThisTypeNode, + ThrowStatement, + Token, TokenFlags, TokenSyntaxKind, TransformFlags, + TrueLiteral, + TryStatement, + TupleTypeNode, Type, + TypeAliasDeclaration, + TypeAssertionExpression, + TypeElement, + TypeLiteralNode, + TypeNode, TypeNodeSyntaxKind, - updateSourceFile, + TypeOfExpression, + TypeOperatorNode, + TypeParameterDeclaration, + TypePredicateNode, + TypeQueryNode, + TypeReferenceNode, + UnaryExpression, + UnionOrIntersectionTypeNode, + UnionTypeNode, + UpdateExpression, + VariableDeclaration, + VariableDeclarationList, + VariableStatement, + VoidExpression, + WhileStatement, + WithStatement, + YieldExpression } from "./_namespaces/ts.js"; -/** @internal */ -export type AstNextContainer = AstHasLocals; +// dprint-ignore +class AstNodeArrayExtraFields { + /** @internal */ nodes: NodeArray | undefined = undefined; + /** @internal */ hasTrailingComma: boolean = false; + /** @internal */ transformFlags: TransformFlags = (-1 as TransformFlags); // Flags for transforms + /** @internal */ __pos: number = -1; + /** @internal */ __end: number = -1; +} -/** @internal */ -export class AstNodeId { - id: NodeId = 0; +// dprint-ignore +export class AstNodeArray { + readonly items: readonly N[] = undefined!; + + pos = -1; + end = -1; + + private _extra: AstNodeArrayExtraFields | undefined = undefined; + + constructor(items: readonly N[], hasTrailingComma = false) { + // catch any excess properties assigned to the NodeArray + Object.preventExtensions(this); + + this.items = items; + this.hasTrailingComma = hasTrailingComma; + } + + private get extra(): AstNodeArrayExtraFields { + return this._extra ??= new AstNodeArrayExtraFields(); + } + + get nodes(): NodeArray { + return this.extra.nodes ??= new NodeArray(this); + } + get hasTrailingComma(): boolean { + return this._extra?.hasTrailingComma ?? false; + } + set hasTrailingComma(value) { + if (value !== this.hasTrailingComma) { + this.extra.hasTrailingComma = value; + } + } + + /** @internal */ get transformFlags(): TransformFlags { + const extra = this.extra; + if (extra.transformFlags === (-1 as TransformFlags)) { + let transformFlags = TransformFlags.None; + for (const child of this.items) { + transformFlags |= propagateChildFlags(child); + } + extra.transformFlags = transformFlags; + } + return extra.transformFlags; + } + /** @internal */ set transformFlags(value) { + this.extra.transformFlags = value; + } + + /** @internal */ get __pos(): number | undefined { // eslint-disable-line @typescript-eslint/naming-convention + const pos = this._extra?.__pos; + return pos === -1 ? undefined : pos; + } + /** @internal */ set __pos(value) { // eslint-disable-line @typescript-eslint/naming-convention + if (value === undefined) { + if (this._extra !== undefined) { + this._extra.__pos = -1; + } + } + else { + if (value < 0) throw new RangeError(); + this.extra.__pos = value; + } + } + /** @internal */ get __end(): number | undefined { // eslint-disable-line @typescript-eslint/naming-convention + const end = this._extra?.__end; + return end === -1 ? undefined : end; + } + /** @internal */ set __end(value) { // eslint-disable-line @typescript-eslint/naming-convention + if (value === undefined) { + if (this._extra !== undefined) { + this._extra.__end = -1; + } + } + else { + if (value < 0) throw new RangeError(); + this.extra.__end = value; + } + } } -// TODO: This shouldn't be exported but not exporting breaks dtsBundler -/** @internal */ -export class AstNodeExtraFields { - id: AstNodeId = new AstNodeId(); - original: AstNode | undefined = undefined; - emitNode: EmitNode | undefined = undefined; - modifierFlagsCache: ts.ModifierFlags = ModifierFlags.None; - transformFlags: TransformFlags = (-1 as TransformFlags); - __pos: number = -1; - __end: number = -1; +/** + * Holds the id for a `Node`. The id is held by another object to support + * source file redirection. + */ +class AstNodeId { + /** @internal */ id: NodeId = 0; // Unique id (used to look up NodeLinks) +} + +// dprint-ignore +class AstNodeExtraFields { + /** @internal */ id: AstNodeId = new AstNodeId(); + /** @internal */ original: AstNode | undefined = undefined; // The original node if this is an updated node. + /** @internal */ emitNode: EmitNode | undefined = undefined; // Associated EmitNode (initialized by transforms) + /** @internal */ modifierFlagsCache: ModifierFlags = ModifierFlags.None; + /** @internal */ transformFlags: TransformFlags = (-1 as TransformFlags); // Flags for transforms + /** @internal */ __pos: number = -1; + /** @internal */ __end: number = -1; } let astNodeCloneCore: (node: AstNode) => AstNode; let astNodeShadowCore: (node: AstNode) => AstNode; -/** @internal */ +// dprint-ignore export class AstNode = Node> { static { astNodeCloneCore = node => node.cloneCore(); @@ -112,12 +526,12 @@ export class AstNode = Node> | undefined = undefined; + parent: AstNode> | undefined = undefined; // Parent node (initialized by binding) flags: NodeFlags = NodeFlags.None; pos = -1; end = -1; - constructor(kind: N["kind"], data: N["data"], nodeConstructor: NodeConstructor, flags: ts.NodeFlags = NodeFlags.None) { + constructor(kind: N["kind"], data: N["data"], nodeConstructor: NodeConstructor, flags: NodeFlags = NodeFlags.None) { // catch any excess properties assigned to the Node Object.preventExtensions(this); @@ -131,45 +545,27 @@ export class AstNode = Node> | undefined { - return this._extra?.original; - } - set original(value) { - this.extra.original = value; - } - get emitNode(): ts.EmitNode | undefined { - return this._extra?.emitNode; - } - set emitNode(value) { - this.extra.emitNode = value; - } - get transformFlags(): ts.TransformFlags { + /** @internal */ get id(): number { return this._extra?.id.id ?? 0; } + /** @internal */ set id(value) { this.extra.id.id = value; } + /** @internal */ get original(): AstNode> | undefined { return this._extra?.original; } + /** @internal */ set original(value) { this.extra.original = value; } + /** @internal */ get emitNode(): EmitNode | undefined { return this._extra?.emitNode; } + /** @internal */ set emitNode(value) { this.extra.emitNode = value; } + /** @internal */ get transformFlags(): TransformFlags { const extra = this.extra; if (extra.transformFlags === (-1 as TransformFlags)) { extra.transformFlags = this.data.computeTransformFlags(this); } return extra.transformFlags; } - set transformFlags(value) { - this.extra.transformFlags = value; - } - get modifierFlagsCache(): ts.ModifierFlags { - return this._extra?.modifierFlagsCache ?? ModifierFlags.None; - } - set modifierFlagsCache(value) { - this.extra.modifierFlagsCache = value; - } - get __pos(): number | undefined { // eslint-disable-line @typescript-eslint/naming-convention + /** @internal */ set transformFlags(value) { this.extra.transformFlags = value; } + /** @internal */ get modifierFlagsCache(): ModifierFlags { return this._extra?.modifierFlagsCache ?? ModifierFlags.None; } + /** @internal */ set modifierFlagsCache(value) { this.extra.modifierFlagsCache = value; } + /** @internal */ get __pos(): number | undefined { // eslint-disable-line @typescript-eslint/naming-convention const pos = this._extra?.__pos; return pos === -1 ? undefined : pos; } - set __pos(value) { // eslint-disable-line @typescript-eslint/naming-convention + /** @internal */ set __pos(value) { // eslint-disable-line @typescript-eslint/naming-convention if (value === undefined) { if (this._extra !== undefined) { this._extra.__pos = -1; @@ -180,11 +576,11 @@ export class AstNode = Node = Node = Node = Node = Node = Node = Node = Node = Node = N extends unknown ? AstNode : never; +export type AstNodeOneOf = N extends unknown ? AstNode : never; -/** @internal */ +// dprint-ignore export class AstData { - computeTransformFlags(node: AstNode): TransformFlags { + /** @internal */ computeTransformFlags(node: AstNode): TransformFlags { void node; return TransformFlags.None; } /** * Controls cloning the provided node. + * @internal */ cloneNode(node: AstNode): AstNode { return astNodeCloneCore(node); @@ -936,6 +1337,7 @@ export class AstData { /** * Creates a shallow, member-wise clone of this data object. + * @internal */ clone(): AstData { const clone = this.createInstance(); @@ -945,6 +1347,7 @@ export class AstData { /** * Creates a new instance of a data object with the same prototype as this object. + * @internal */ protected createInstance(): AstData { return Object.create(Object.getPrototypeOf(this)); @@ -952,6 +1355,7 @@ export class AstData { /** * Copies the properties of this object to the provided object. + * @internal */ protected copyProperties(clone: AstData): void { for (const key in this) { @@ -964,6 +1368,7 @@ export class AstData { /** * Controls creation of a shadow node for the provided node. * This is primarily used for the purpose of redirecting source files. + * @internal */ shadowNode(node: AstNode): AstNode { return astNodeShadowCore(node); @@ -972,1341 +1377,183 @@ export class AstData { /** * Creates a new data object using this object as the prototype. * This is primarily used for the purpose of redirecting source files. + * @internal */ shadow(): AstData { return Object.create(this); } } -/** @internal */ +// dprint-ignore export class AstTypeScriptNodeData extends AstData { - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsTypeScript; } } /** @internal */ -export class Node implements ts.Node { - readonly ast: AstNode> = undefined!; +export type AstHasLocals = AstNodeOneOf; +export type AstHasDecorators = AstNodeOneOf; +export type AstHasModifiers = AstNodeOneOf; +/** @internal */ +export type AstHasChildren = AstNodeOneOf; +/** @internal */ +export type AstForEachChildNodes = AstNodeOneOf; +export type AstDeclaration = AstNode; +export type AstTypeNode = AstNode>; +export type AstStatement = AstNode; +export type AstExpression = AstNode; +export type AstUnaryExpression = AstNode; +export type AstUpdateExpression = AstNode; +export type AstLeftHandSideExpression = AstNode; +export type AstMemberExpression = AstNode; +export type AstPrimaryExpression = AstNode; +export type AstKeywordExpression = AstNode>; +export type AstLiteralLikeNode = AstNode; - constructor(ast: AstNode>) { - // catch any excess properties assigned to the Node - Object.preventExtensions(this); +export interface AstLiteralLikeNodeData extends AstData { + text: string; +} - this.ast = ast; - } +export type AstStringLiteralLikeNode = AstNode; - get kind(): K { - return this.ast.kind; - } - get data(): T { - return this.ast.data; - } - get pos(): number { - return this.ast.pos; - } - set pos(value) { - this.ast.pos = value; - } - get end(): number { - return this.ast.end; - } - set end(value) { - this.ast.end = value; - } - get flags(): NodeFlags { - return this.ast.flags; - } - set flags(value) { - this.ast.flags = value; - } - get modifierFlagsCache(): ModifierFlags { - return this.ast.modifierFlagsCache; - } - set modifierFlagsCache(value) { - this.ast.modifierFlagsCache = value; - } - get transformFlags(): TransformFlags { - return this.ast.transformFlags; - } - set transformFlags(value) { - this.ast.transformFlags = value; - } - get parent(): Node { - return this.ast.parent?.node!; // TODO: remove `!` - } - set parent(value) { - this.ast.parent = value?.ast; - } - get id(): number { - return this.ast.id; - } - set id(value) { - this.ast.id = value; - } - get original(): Node | undefined { - return this.ast.original?.node; - } - set original(value) { - this.ast.original = value?.ast; - } - get emitNode(): EmitNode | undefined { - return this.ast.emitNode; - } - set emitNode(value) { - this.ast.emitNode = value; - } - get __pos(): number | undefined { // eslint-disable-line @typescript-eslint/naming-convention - return this.ast.__pos; - } - set __pos(value) { // eslint-disable-line @typescript-eslint/naming-convention - this.ast.__pos = value; - } - get __end(): number | undefined { // eslint-disable-line @typescript-eslint/naming-convention - return this.ast.__end; - } - set __end(value) { // eslint-disable-line @typescript-eslint/naming-convention - this.ast.__end = value; - } +export interface AstStringLiteralLikeNodeData extends AstLiteralLikeNodeData { + isUnterminated: boolean | undefined; + hasExtendedUnicodeEscape: boolean | undefined; +} - private assertHasRealPosition(message?: string) { - // eslint-disable-next-line local/debug-assert - Debug.assert(!positionIsSynthesized(this.pos) && !positionIsSynthesized(this.end), message || "Node must have a real position for this operation"); - } +export interface AstTemplateLiteralLikeNodeData extends AstStringLiteralLikeNodeData { + rawText: string | undefined; + /** @internal */ templateFlags: TokenFlags | undefined; +} - public getSourceFile(): ts.SourceFile { - return getSourceFileOfNode(this); - } +export type AstTemplateLiteralLikeNode = AstNode; - public getStart(sourceFile?: ts.SourceFileLike, includeJsDocComment?: boolean): number { - this.assertHasRealPosition(); - return getTokenPosOfNode(this, sourceFile, includeJsDocComment); - } +export type AstLiteralExpression = AstNode; - public getFullStart(): number { - this.assertHasRealPosition(); - return this.pos; - } +export interface AstLiteralExpressionData extends AstLiteralLikeNodeData { +} - public getEnd(): number { - this.assertHasRealPosition(); - return this.end; +// dprint-ignore +export class AstTokenData extends AstData { + /** @internal */ override computeTransformFlags(node: AstNode): TransformFlags { + switch (node.kind) { + case SyntaxKind.AsyncKeyword: + // 'async' modifier is ES2017 (async functions) or ES2018 (async generators) + return TransformFlags.ContainsES2017 | TransformFlags.ContainsES2018; + case SyntaxKind.UsingKeyword: + return TransformFlags.ContainsESNext; + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + case SyntaxKind.ReadonlyKeyword: + case SyntaxKind.AbstractKeyword: + case SyntaxKind.DeclareKeyword: + case SyntaxKind.ConstKeyword: + case SyntaxKind.AnyKeyword: + case SyntaxKind.NumberKeyword: + case SyntaxKind.BigIntKeyword: + case SyntaxKind.NeverKeyword: + case SyntaxKind.ObjectKeyword: + case SyntaxKind.InKeyword: + case SyntaxKind.OutKeyword: + case SyntaxKind.OverrideKeyword: + case SyntaxKind.StringKeyword: + case SyntaxKind.BooleanKeyword: + case SyntaxKind.SymbolKeyword: + case SyntaxKind.VoidKeyword: + case SyntaxKind.UnknownKeyword: + case SyntaxKind.UndefinedKeyword: // `undefined` is an Identifier in the expression case. + return TransformFlags.ContainsTypeScript; + case SyntaxKind.SuperKeyword: + return TransformFlags.ContainsES2015 | TransformFlags.ContainsLexicalSuper; + case SyntaxKind.StaticKeyword: + return TransformFlags.ContainsES2015; + case SyntaxKind.AccessorKeyword: + return TransformFlags.ContainsClassFields; + case SyntaxKind.ThisKeyword: + // 'this' indicates a lexical 'this' + return TransformFlags.ContainsLexicalThis; + } + return TransformFlags.None; } +} - public getWidth(sourceFile?: ts.SourceFile): number { - this.assertHasRealPosition(); - return this.getEnd() - this.getStart(sourceFile); - } +// dprint-ignore +export class AstEndOfFileTokenData extends AstTokenData { + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) +} - public getFullWidth(): number { - this.assertHasRealPosition(); - return this.end - this.pos; - } +// dprint-ignore +export class AstThisExpressionData extends AstTokenData { + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) +} - public getLeadingTriviaWidth(sourceFile?: ts.SourceFile): number { - this.assertHasRealPosition(); - return this.getStart(sourceFile) - this.pos; - } +// dprint-ignore +export class AstSuperExpressionData extends AstTokenData { + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) +} - public getFullText(sourceFile?: ts.SourceFile): string { - this.assertHasRealPosition(); - return (sourceFile || this.getSourceFile()).text.substring(this.pos, this.end); - } +export type AstBooleanLiteral = AstNodeOneOf; - public getText(sourceFile?: ts.SourceFile): string { - this.assertHasRealPosition(); - if (!sourceFile) { - sourceFile = this.getSourceFile(); - } - return sourceFile.text.substring(this.getStart(sourceFile), this.getEnd()); - } +// Punctuation - public getChildCount(sourceFile?: ts.SourceFile): number { - return this.getChildren(sourceFile).length; - } +export type AstPunctuationToken = AstNode>; +export type AstDotToken = AstNode; +export type AstDotDotDotToken = AstNode; +export type AstQuestionToken = AstNode; +export type AstExclamationToken = AstNode; +export type AstColonToken = AstNode; +export type AstEqualsToken = AstNode; +export type AstAmpersandAmpersandEqualsToken = AstNode; +export type AstBarBarEqualsToken = AstNode; +export type AstQuestionQuestionEqualsToken = AstNode; +export type AstAsteriskToken = AstNode; +export type AstEqualsGreaterThanToken = AstNode; +export type AstPlusToken = AstNode; +export type AstMinusToken = AstNode; +export type AstQuestionDotToken = AstNode; - public getChildAt(index: number, sourceFile?: ts.SourceFile): ts.Node { - return this.getChildren(sourceFile)[index]; - } +// Keywords - public getChildren(sourceFile: ts.SourceFileLike = getSourceFileOfNode(this)): readonly ts.Node[] { - this.assertHasRealPosition("Node without a real position cannot be scanned and thus has no token nodes - use forEachChild and collect the result if that's fine"); - return getNodeChildren(this, sourceFile) ?? setNodeChildren(this, sourceFile, createChildren(this, sourceFile)); - } +export type AstKeywordToken = AstNode>; +export type AstAssertsKeyword = AstNode; +export type AstAssertKeyword = AstNode; +export type AstAwaitKeyword = AstNode; +export type AstCaseKeyword = AstNode; - public getFirstToken(sourceFile?: ts.SourceFileLike): ts.Node | undefined { - this.assertHasRealPosition(); - const children = this.getChildren(sourceFile) as readonly Node[]; - if (!children.length) { - return undefined; - } +// Modifiers - const child = find(children, kid => kid.kind < SyntaxKind.FirstJSDocNode || kid.kind > SyntaxKind.LastJSDocNode)!; - return child.kind < SyntaxKind.FirstNode ? - child : - child.getFirstToken(sourceFile); - } +export type AstModifierToken = AstNode>; +export type AstAbstractKeyword = AstNode; +export type AstAccessorKeyword = AstNode; +export type AstAsyncKeyword = AstNode; +export type AstConstKeyword = AstNode; +export type AstDeclareKeyword = AstNode; +export type AstDefaultKeyword = AstNode; +export type AstExportKeyword = AstNode; +export type AstInKeyword = AstNode; +export type AstPrivateKeyword = AstNode; +export type AstProtectedKeyword = AstNode; +export type AstPublicKeyword = AstNode; +export type AstReadonlyKeyword = AstNode; +export type AstOutKeyword = AstNode; +export type AstOverrideKeyword = AstNode; +export type AstStaticKeyword = AstNode; +export type AstModifier = AstNodeOneOf; +export type AstModifierLike = AstNodeOneOf; - public getLastToken(sourceFile?: ts.SourceFileLike): ts.Node | undefined { - this.assertHasRealPosition(); - const children = this.getChildren(sourceFile) as readonly Node[]; +// dprint-ignore +export class AstIdentifierData extends AstTokenData { + escapedText: __String = undefined!; - const child = lastOrUndefined(children); - if (!child) { - return undefined; - } + /** @internal */ resolvedSymbol: Symbol = undefined!; // TransientIdentifier + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - return child.kind < SyntaxKind.FirstNode ? child : child.getLastToken(sourceFile); - } - - public forEachChild(cbNode: (node: ts.Node) => T, cbNodeArray?: (nodes: ts.NodeArray) => T): T | undefined { - return forEachChild(this, cbNode, cbNodeArray); - } -} - -Debug.registerDebugInfo(() => { - if (!ts.hasProperty(Node.prototype, "__debugKind")) { - const weakNodeTextMap = new WeakMap(); - - Object.defineProperties(Node.prototype, { - // for use with vscode-js-debug's new customDescriptionGenerator in launch.json - __tsDebuggerDisplay: { - value(this: Node) { - const nodeHeader = ts.isGeneratedIdentifier(this) ? "GeneratedIdentifier" : - ts.isIdentifier(this) ? `Identifier '${idText(this)}'` : - ts.isPrivateIdentifier(this) ? `PrivateIdentifier '${idText(this)}'` : - ts.isStringLiteral(this) ? `StringLiteral ${JSON.stringify(this.text.length < 10 ? this.text : this.text.slice(10) + "...")}` : - ts.isNumericLiteral(this) ? `NumericLiteral ${this.text}` : - ts.isBigIntLiteral(this) ? `BigIntLiteral ${this.text}n` : - ts.isTypeParameterDeclaration(this) ? "TypeParameterDeclaration" : - ts.isParameter(this) ? "ParameterDeclaration" : - ts.isConstructorDeclaration(this) ? "ConstructorDeclaration" : - ts.isGetAccessorDeclaration(this) ? "GetAccessorDeclaration" : - ts.isSetAccessorDeclaration(this) ? "SetAccessorDeclaration" : - ts.isCallSignatureDeclaration(this) ? "CallSignatureDeclaration" : - ts.isConstructSignatureDeclaration(this) ? "ConstructSignatureDeclaration" : - ts.isIndexSignatureDeclaration(this) ? "IndexSignatureDeclaration" : - ts.isTypePredicateNode(this) ? "TypePredicateNode" : - ts.isTypeReferenceNode(this) ? "TypeReferenceNode" : - ts.isFunctionTypeNode(this) ? "FunctionTypeNode" : - ts.isConstructorTypeNode(this) ? "ConstructorTypeNode" : - ts.isTypeQueryNode(this) ? "TypeQueryNode" : - ts.isTypeLiteralNode(this) ? "TypeLiteralNode" : - ts.isArrayTypeNode(this) ? "ArrayTypeNode" : - ts.isTupleTypeNode(this) ? "TupleTypeNode" : - ts.isOptionalTypeNode(this) ? "OptionalTypeNode" : - ts.isRestTypeNode(this) ? "RestTypeNode" : - ts.isUnionTypeNode(this) ? "UnionTypeNode" : - ts.isIntersectionTypeNode(this) ? "IntersectionTypeNode" : - ts.isConditionalTypeNode(this) ? "ConditionalTypeNode" : - ts.isInferTypeNode(this) ? "InferTypeNode" : - ts.isParenthesizedTypeNode(this) ? "ParenthesizedTypeNode" : - ts.isThisTypeNode(this) ? "ThisTypeNode" : - ts.isTypeOperatorNode(this) ? "TypeOperatorNode" : - ts.isIndexedAccessTypeNode(this) ? "IndexedAccessTypeNode" : - ts.isMappedTypeNode(this) ? "MappedTypeNode" : - ts.isLiteralTypeNode(this) ? "LiteralTypeNode" : - ts.isNamedTupleMember(this) ? "NamedTupleMember" : - ts.isImportTypeNode(this) ? "ImportTypeNode" : - Debug.formatSyntaxKind(this.kind); - return `${nodeHeader}${this.flags ? ` (${Debug.formatNodeFlags(this.flags)})` : ""}`; - }, - }, - __debugKind: { - get(this: Node) { - return Debug.formatSyntaxKind(this.kind); - }, - }, - __debugNodeFlags: { - get(this: Node) { - return Debug.formatNodeFlags(this.flags); - }, - }, - __debugModifierFlags: { - get(this: Node) { - return Debug.formatModifierFlags(ts.getEffectiveModifierFlagsNoCache(this)); - }, - }, - __debugTransformFlags: { - get(this: Node) { - return Debug.formatTransformFlags(this.transformFlags); - }, - }, - __debugIsParseTreeNode: { - get(this: Node) { - return ts.isParseTreeNode(this); - }, - }, - __debugEmitFlags: { - get(this: Node) { - return Debug.formatEmitFlags(ts.getEmitFlags(this)); - }, - }, - __debugGetText: { - value(this: Node, includeTrivia?: boolean) { - if (ts.nodeIsSynthesized(this)) return ""; - // avoid recomputing - let text = weakNodeTextMap.get(this); - if (text === undefined) { - const parseNode = ts.getParseTreeNode(this); - const sourceFile = parseNode && getSourceFileOfNode(parseNode); - text = sourceFile ? ts.getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : ""; - weakNodeTextMap.set(this, text); - } - return text; - }, - }, - }); - } -}); - -/** @internal */ -export type NodeConstructor = new (ast: AstNode>) => N; - -/** @internal */ -export class AstNodeArrayExtraFields { - nodes: NodeArray | undefined = undefined; - hasTrailingComma: boolean = false; - transformFlags: TransformFlags | undefined = undefined; - __pos: number | undefined = undefined; - __end: number | undefined = undefined; -} - -let astNodeArrayMaybeExtra: (nodes: AstNodeArray) => AstNodeArrayExtraFields | undefined; - -/** @internal */ -export class AstNodeArray { - static { - astNodeArrayMaybeExtra = nodes => nodes._extra; - } - - readonly items: readonly N[] = undefined!; - pos = -1; - end = -1; - - private _extra: AstNodeArrayExtraFields | undefined = undefined; - - constructor(items: readonly N[], hasTrailingComma = false) { - // catch any excess properties assigned to the NodeArray - Object.preventExtensions(this); - - this.items = items; - this.hasTrailingComma = hasTrailingComma; - } - - /** @private */ get extra(): AstNodeArrayExtraFields { - return this._extra ??= new AstNodeArrayExtraFields(); - } - - get nodes(): NodeArray { - return this.extra.nodes ??= new NodeArray(this); - } - get hasTrailingComma(): boolean { - return this._extra?.hasTrailingComma ?? false; - } - set hasTrailingComma(value) { - if (value !== this.hasTrailingComma) { - this.extra.hasTrailingComma = value; - } - } - - get transformFlags(): ts.TransformFlags { - let transformFlags = this._extra?.transformFlags; - if (transformFlags === undefined) { - transformFlags = TransformFlags.None; - for (const child of this.items) { - transformFlags |= propagateChildFlags(child); - } - this.extra.transformFlags = transformFlags; - } - return transformFlags; - } - set transformFlags(value) { - this.extra.transformFlags = value; - } -} - -/** @internal */ -export class NodeArray extends Array implements ts.NodeArray { - readonly ast: AstNodeArray; - - constructor(ast: AstNodeArray) { - super(...ast.items.map(item => item.node as N)); - this.ast = ast; - - // catch any excess properties assigned to the array - Object.preventExtensions(this); - } - - static override get [globalThis.Symbol.species](): ArrayConstructor { - return Array; - } - - get pos(): number { - return this.ast.pos; - } - set pos(value) { - this.ast.pos = value; - } - get end(): number { - return this.ast.end; - } - set end(value) { - this.ast.end = value; - } - get hasTrailingComma(): boolean { - return this.ast.hasTrailingComma; - } - set hasTrailingComma(value) { - this.ast.hasTrailingComma = value; - } - get transformFlags(): ts.TransformFlags { - return this.ast.transformFlags; - } - set transformFlags(value) { - this.ast.transformFlags = value; - } - - get __pos(): number | undefined { // eslint-disable-line @typescript-eslint/naming-convention - return astNodeArrayMaybeExtra(this.ast)?.__pos; - } - set __pos(value) { // eslint-disable-line @typescript-eslint/naming-convention - this.ast.extra.__pos = value; - } - get __end(): number | undefined { // eslint-disable-line @typescript-eslint/naming-convention - return astNodeArrayMaybeExtra(this.ast)?.__end; - } - set __end(value) { // eslint-disable-line @typescript-eslint/naming-convention - this.ast.extra.__end = value; - } -} - -Debug.registerDebugInfo(() => { - if (!("__tsDebuggerDisplay" in NodeArray.prototype)) { // eslint-disable-line local/no-in-operator - Object.defineProperties(NodeArray.prototype, { - __tsDebuggerDisplay: { - value(this: NodeArray, defaultValue: string) { - // An `Array` with extra properties is rendered as `[A, B, prop1: 1, prop2: 2]`. Most of - // these aren't immediately useful so we trim off the `prop1: ..., prop2: ...` part from the - // formatted string. - // This regex can trigger slow backtracking because of overlapping potential captures. - // We don't care, this is debug code that's only enabled with a debugger attached - - // we're just taking note of it for anyone checking regex performance in the future. - defaultValue = String(defaultValue).replace(/(?:,[\s\w]+:[^,]+)+\]$/, "]"); - return `NodeArray ${defaultValue}`; - }, - }, - }); - } -}); - -/** @internal */ -export interface JSDocContainer extends Node { - _jsdocContainerBrand: any; - - get jsDoc(): JSDocArray | undefined; - set jsDoc(value: JSDocArray | undefined); -} - -/** @internal */ -export interface FlowContainer extends Node { - _flowContainerBrand: any; - - get flowNode(): FlowNode | undefined; - set flowNode(value: FlowNode | undefined); -} - -/** @internal */ -export interface LocalsContainer extends Node { - _localsContainerBrand: any; - - get locals(): SymbolTable | undefined; - set locals(value: SymbolTable | undefined); - get nextContainer(): HasLocals | undefined; - set nextContainer(value: HasLocals | undefined); -} - -/** @internal */ -export type HasLocals = - | ArrowFunction - | Block - | CallSignatureDeclaration - | CaseBlock - | CatchClause - | ClassStaticBlockDeclaration - | ConditionalTypeNode - | ConstructorDeclaration - | ConstructorTypeNode - | ConstructSignatureDeclaration - | ForStatement - | ForInStatement - | ForOfStatement - | FunctionDeclaration - | FunctionExpression - | FunctionTypeNode - | GetAccessorDeclaration - | IndexSignatureDeclaration - | JSDocCallbackTag - | JSDocEnumTag - | JSDocFunctionType - | JSDocSignature - | JSDocTypedefTag - | MappedTypeNode - | MethodDeclaration - | MethodSignature - | ModuleDeclaration - | SetAccessorDeclaration - | SourceFile - | TypeAliasDeclaration; - -/** @internal */ -export type AstHasLocals = AstNodeOneOf; - -// NOTE: Changing the following list requires changes to: -// - `canHaveDecorators` in factory/utilities.ts -// - `updateModifiers` in factory/nodeFactory.ts -/** @internal */ -export type HasDecorators = - | ParameterDeclaration - | PropertyDeclaration - | MethodDeclaration - | GetAccessorDeclaration - | SetAccessorDeclaration - | ClassExpression - | ClassDeclaration; - -/** @internal */ -export type AstHasDecorators = AstNodeOneOf; - -// NOTE: Changing the following list requires changes to: -// - `canHaveModifiers` in factory/utilitiesPublic.ts -// - `updateModifiers` in factory/nodeFactory.ts -/** @internal */ -export type HasModifiers = - | TypeParameterDeclaration - | ParameterDeclaration - | ConstructorTypeNode - | PropertySignature - | PropertyDeclaration - | MethodSignature - | MethodDeclaration - | ConstructorDeclaration - | GetAccessorDeclaration - | SetAccessorDeclaration - | IndexSignatureDeclaration - | FunctionExpression - | ArrowFunction - | ClassExpression - | VariableStatement - | FunctionDeclaration - | ClassDeclaration - | InterfaceDeclaration - | TypeAliasDeclaration - | EnumDeclaration - | ModuleDeclaration - | ImportEqualsDeclaration - | ImportDeclaration - | ExportAssignment - | ExportDeclaration; - -/** @internal */ -export type AstHasModifiers = AstNodeOneOf; - -/** @internal */ -export type HasChildren = - | QualifiedName - | ComputedPropertyName - | TypeParameterDeclaration - | ParameterDeclaration - | Decorator - | PropertySignature - | PropertyDeclaration - | MethodSignature - | MethodDeclaration - | ConstructorDeclaration - | GetAccessorDeclaration - | SetAccessorDeclaration - | ClassStaticBlockDeclaration - | CallSignatureDeclaration - | ConstructSignatureDeclaration - | IndexSignatureDeclaration - | TypePredicateNode - | TypeReferenceNode - | FunctionTypeNode - | ConstructorTypeNode - | TypeQueryNode - | TypeLiteralNode - | ArrayTypeNode - | TupleTypeNode - | OptionalTypeNode - | RestTypeNode - | UnionTypeNode - | IntersectionTypeNode - | ConditionalTypeNode - | InferTypeNode - | ImportTypeNode - | ImportTypeAssertionContainer - | NamedTupleMember - | ParenthesizedTypeNode - | TypeOperatorNode - | IndexedAccessTypeNode - | MappedTypeNode - | LiteralTypeNode - | TemplateLiteralTypeNode - | TemplateLiteralTypeSpan - | ObjectBindingPattern - | ArrayBindingPattern - | BindingElement - | ArrayLiteralExpression - | ObjectLiteralExpression - | PropertyAccessExpression - | ElementAccessExpression - | CallExpression - | NewExpression - | TaggedTemplateExpression - | TypeAssertion - | ParenthesizedExpression - | FunctionExpression - | ArrowFunction - | DeleteExpression - | TypeOfExpression - | VoidExpression - | AwaitExpression - | PrefixUnaryExpression - | PostfixUnaryExpression - | BinaryExpression - | ConditionalExpression - | TemplateExpression - | YieldExpression - | SpreadElement - | ClassExpression - | ExpressionWithTypeArguments - | AsExpression - | NonNullExpression - | SatisfiesExpression - | MetaProperty - | TemplateSpan - | Block - | VariableStatement - | ExpressionStatement - | IfStatement - | DoStatement - | WhileStatement - | ForStatement - | ForInStatement - | ForOfStatement - | ContinueStatement - | BreakStatement - | ReturnStatement - | WithStatement - | SwitchStatement - | LabeledStatement - | ThrowStatement - | TryStatement - | VariableDeclaration - | VariableDeclarationList - | FunctionDeclaration - | ClassDeclaration - | InterfaceDeclaration - | TypeAliasDeclaration - | EnumDeclaration - | ModuleDeclaration - | ModuleBlock - | CaseBlock - | NamespaceExportDeclaration - | ImportEqualsDeclaration - | ImportDeclaration - | AssertClause - | AssertEntry - | ImportAttributes - | ImportAttribute - | ImportClause - | NamespaceImport - | NamespaceExport - | NamedImports - | ImportSpecifier - | ExportAssignment - | ExportDeclaration - | NamedExports - | ExportSpecifier - | ExternalModuleReference - | JsxElement - | JsxSelfClosingElement - | JsxOpeningElement - | JsxClosingElement - | JsxFragment - | JsxAttribute - | JsxAttributes - | JsxSpreadAttribute - | JsxExpression - | JsxNamespacedName - | CaseClause - | DefaultClause - | HeritageClause - | CatchClause - | PropertyAssignment - | ShorthandPropertyAssignment - | SpreadAssignment - | EnumMember - | SourceFile - | PartiallyEmittedExpression - | CommaListExpression; - -/** @internal */ -export type AstHasChildren = AstNodeOneOf; - -/** @internal */ -export type ForEachChildNodes = - | HasChildren - | MissingDeclaration - | JSDocTypeExpression - | JSDocNonNullableType - | JSDocNullableType - | JSDocOptionalType - | JSDocVariadicType - | JSDocFunctionType - | JSDoc - | JSDocSeeTag - | JSDocNameReference - | JSDocMemberName - | JSDocParameterTag - | JSDocPropertyTag - | JSDocAuthorTag - | JSDocImplementsTag - | JSDocAugmentsTag - | JSDocTemplateTag - | JSDocTypedefTag - | JSDocCallbackTag - | JSDocReturnTag - | JSDocTypeTag - | JSDocThisTag - | JSDocEnumTag - | JSDocSignature - | JSDocLink - | JSDocLinkCode - | JSDocLinkPlain - | JSDocTypeLiteral - | JSDocUnknownTag - | JSDocClassTag - | JSDocPublicTag - | JSDocPrivateTag - | JSDocProtectedTag - | JSDocReadonlyTag - | JSDocDeprecatedTag - | JSDocThrowsTag - | JSDocOverrideTag - | JSDocSatisfiesTag - | JSDocOverloadTag - | JSDocImportTag; - -/** @internal */ -export type AstForEachChildNodes = AstNodeOneOf; - -/** @internal */ -export interface Declaration extends Node { - readonly ast: AstDeclaration; - _declarationBrand: any; - - get symbol(): Symbol; - set symbol(value: Symbol); - get localSymbol(): Symbol | undefined; - set localSymbol(value: Symbol | undefined); -} - -/** @internal */ -export type AstDeclaration = AstNode; - -/** @internal */ -export interface TypeNode extends Node { - readonly ast: AstTypeNode; - _typeNodeBrand: any; -} - -/** @internal */ -export type AstTypeNode = AstNode>; - -/** @internal */ -export interface Statement extends JSDocContainer { - readonly ast: AstStatement; - _statementBrand: any; -} - -/** @internal */ -export type AstStatement = AstNode; - -/** @internal */ -export interface Expression extends Node { - readonly ast: AstExpression; - _expressionBrand: any; -} - -/** @internal */ -export type AstExpression = AstNode; - -/** @internal */ -export interface UnaryExpression extends Expression { - readonly ast: AstUnaryExpression; - _unaryExpressionBrand: any; -} - -/** @internal */ -export type AstUnaryExpression = AstNode; - -/** @internal */ -export interface UpdateExpression extends UnaryExpression { - readonly ast: AstUpdateExpression; - _updateExpressionBrand: any; -} - -/** @internal */ -export type AstUpdateExpression = AstNode; - -/** @internal */ -export interface LeftHandSideExpression extends UpdateExpression { - readonly ast: AstLeftHandSideExpression; - _leftHandSideExpressionBrand: any; -} - -/** @internal */ -export type AstLeftHandSideExpression = AstNode; - -/** @internal */ -export interface MemberExpression extends LeftHandSideExpression { - readonly ast: AstMemberExpression; - _memberExpressionBrand: any; -} - -/** @internal */ -export type AstMemberExpression = AstNode; - -/** @internal */ -export interface PrimaryExpression extends MemberExpression { - readonly ast: AstPrimaryExpression; - _primaryExpressionBrand: any; -} - -/** @internal */ -export type AstPrimaryExpression = AstNode; - -/** @internal */ -export interface KeywordExpression extends PrimaryExpression, KeywordToken { - readonly ast: AstKeywordExpression; - readonly kind: TKind; -} - -/** @internal */ -export type AstKeywordExpression = AstNode>; - -/** @internal */ -export interface LiteralLikeNode extends Node { - readonly ast: AstLiteralLikeNode; - readonly data: AstLiteralLikeNodeData; - - text: string; - isUnterminated?: boolean | undefined; - hasExtendedUnicodeEscape?: boolean | undefined; -} - -/** @internal */ -export type AstLiteralLikeNode = AstNode; - -/** @internal */ -export interface AstLiteralLikeNodeData extends AstData { - text: string; - isUnterminated?: boolean | undefined; - hasExtendedUnicodeEscape?: boolean | undefined; -} - -/** @internal */ -export interface TemplateLiteralLikeNode extends LiteralLikeNode { - readonly ast: AstTemplateLiteralLikeNode; - readonly data: AstTemplateLiteralLikeNodeData; - rawText?: string | undefined; - /** @internal */ - templateFlags?: TokenFlags | undefined; -} - -/** @internal */ -export interface AstTemplateLiteralLikeNodeData extends AstLiteralLikeNodeData { - rawText?: string | undefined; - /** @internal */ - templateFlags?: TokenFlags | undefined; -} - -/** @internal */ -export type AstTemplateLiteralLikeNode = AstNode; - -/** @internal */ -export interface LiteralExpression extends PrimaryExpression, LiteralLikeNode { - readonly ast: AstLiteralExpression; - readonly data: AstLiteralExpressionData; - _literalExpressionBrand: any; - - get text(): string; - set text(value: string); -} - -/** @internal */ -export type AstLiteralExpression = AstNode; - -/** @internal */ -export interface AstLiteralExpressionData extends AstLiteralLikeNodeData { -} - -/** @internal */ -export class Token extends Node implements ts.Token { - public override getChildCount(_sourceFile?: ts.SourceFile): number { - return this.getChildren().length; - } - - public override getChildAt(index: number, _sourceFile?: ts.SourceFile): ts.Node { - return this.getChildren()[index]; - } - - public override getChildren(_sourceFile?: ts.SourceFileLike): readonly ts.Node[] { - return this.kind === SyntaxKind.EndOfFileToken ? (this as Node as EndOfFileToken).jsDoc || emptyArray : emptyArray; - } - - public override getFirstToken(_sourceFile?: ts.SourceFileLike): ts.Node | undefined { - return undefined; - } - - public override getLastToken(_sourceFile?: ts.SourceFileLike): ts.Node | undefined { - return undefined; - } - - public override forEachChild(_cbNode: (node: ts.Node) => T, _cbNodeArray?: (nodes: ts.NodeArray) => T): T | undefined { - return undefined; - } -} - -/** @internal */ -export class AstTokenData extends AstData { - override computeTransformFlags(node: AstNode): TransformFlags { - switch (node.kind) { - case SyntaxKind.AsyncKeyword: - // 'async' modifier is ES2017 (async functions) or ES2018 (async generators) - return TransformFlags.ContainsES2017 | TransformFlags.ContainsES2018; - case SyntaxKind.UsingKeyword: - return TransformFlags.ContainsESNext; - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - case SyntaxKind.ReadonlyKeyword: - case SyntaxKind.AbstractKeyword: - case SyntaxKind.DeclareKeyword: - case SyntaxKind.ConstKeyword: - case SyntaxKind.AnyKeyword: - case SyntaxKind.NumberKeyword: - case SyntaxKind.BigIntKeyword: - case SyntaxKind.NeverKeyword: - case SyntaxKind.ObjectKeyword: - case SyntaxKind.InKeyword: - case SyntaxKind.OutKeyword: - case SyntaxKind.OverrideKeyword: - case SyntaxKind.StringKeyword: - case SyntaxKind.BooleanKeyword: - case SyntaxKind.SymbolKeyword: - case SyntaxKind.VoidKeyword: - case SyntaxKind.UnknownKeyword: - case SyntaxKind.UndefinedKeyword: // `undefined` is an Identifier in the expression case. - return TransformFlags.ContainsTypeScript; - case SyntaxKind.SuperKeyword: - return TransformFlags.ContainsES2015 | TransformFlags.ContainsLexicalSuper; - case SyntaxKind.StaticKeyword: - return TransformFlags.ContainsES2015; - case SyntaxKind.AccessorKeyword: - return TransformFlags.ContainsClassFields; - case SyntaxKind.ThisKeyword: - // 'this' indicates a lexical 'this' - return TransformFlags.ContainsLexicalThis; - } - return TransformFlags.None; - } -} - -/** @internal */ -export class EndOfFileToken extends Token implements JSDocContainer, ts.EndOfFileToken { - declare readonly ast: AstEndOfFileToken; - - declare _jsdocContainerBrand: any; - - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } -} - -/** @internal */ -export class AstEndOfFileTokenData extends AstTokenData { - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) -} - -/** @internal */ -export class ThisExpression extends Token implements KeywordExpression, FlowContainer, ts.ThisExpression { - declare readonly ast: AstThisExpression; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _flowContainerBrand: any; - - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ -export class AstThisExpressionData extends AstTokenData { - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) -} - -/** @internal */ -export class SuperExpression extends Token implements KeywordExpression, FlowContainer, ts.SuperExpression { - declare readonly ast: AstSuperExpression; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _flowContainerBrand: any; - - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ -export class AstSuperExpressionData extends AstTokenData { - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) -} - -/** @internal */ -export class ImportExpression extends Token implements KeywordExpression, ts.ImportExpression { - declare readonly ast: AstImportExpression; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; -} - -/** @internal */ -export class NullLiteral extends Token implements KeywordExpression, ts.NullLiteral { - declare readonly ast: AstNullLiteral; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; -} - -/** @internal */ -export class TrueLiteral extends Token implements KeywordExpression, ts.TrueLiteral { - declare readonly ast: AstTrueLiteral; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; -} - -/** @internal */ -export class FalseLiteral extends Token implements KeywordExpression, ts.FalseLiteral { - declare readonly ast: AstFalseLiteral; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; -} - -/** @internal */ -export type BooleanLiteral = - | TrueLiteral - | FalseLiteral; - -/** @internal */ -export type AstBooleanLiteral = AstNodeOneOf; - -// Punctuation - -/** @internal */ -export interface PunctuationToken extends Token {} - -/** @internal */ -export type DotToken = PunctuationToken; -/** @internal */ -export type DotDotDotToken = PunctuationToken; -/** @internal */ -export type QuestionToken = PunctuationToken; -/** @internal */ -export type ExclamationToken = PunctuationToken; -/** @internal */ -export type ColonToken = PunctuationToken; -/** @internal */ -export type EqualsToken = PunctuationToken; -/** @internal */ -export type AmpersandAmpersandEqualsToken = PunctuationToken; -/** @internal */ -export type BarBarEqualsToken = PunctuationToken; -/** @internal */ -export type QuestionQuestionEqualsToken = PunctuationToken; -/** @internal */ -export type AsteriskToken = PunctuationToken; -/** @internal */ -export type EqualsGreaterThanToken = PunctuationToken; -/** @internal */ -export type PlusToken = PunctuationToken; -/** @internal */ -export type MinusToken = PunctuationToken; -/** @internal */ -export type QuestionDotToken = PunctuationToken; - -/** @internal */ -export type AstPunctuationToken = AstNode>; - -/** @internal */ -export type AstDotToken = AstNode; -/** @internal */ -export type AstDotDotDotToken = AstNode; -/** @internal */ -export type AstQuestionToken = AstNode; -/** @internal */ -export type AstExclamationToken = AstNode; -/** @internal */ -export type AstColonToken = AstNode; -/** @internal */ -export type AstEqualsToken = AstNode; -/** @internal */ -export type AstAmpersandAmpersandEqualsToken = AstNode; -/** @internal */ -export type AstBarBarEqualsToken = AstNode; -/** @internal */ -export type AstQuestionQuestionEqualsToken = AstNode; -/** @internal */ -export type AstAsteriskToken = AstNode; -/** @internal */ -export type AstEqualsGreaterThanToken = AstNode; -/** @internal */ -export type AstPlusToken = AstNode; -/** @internal */ -export type AstMinusToken = AstNode; -/** @internal */ -export type AstQuestionDotToken = AstNode; - -// Keywords - -/** @internal */ -export interface KeywordToken extends Token {} - -/** @internal */ -export type AssertsKeyword = KeywordToken; -/** @internal */ -export type AssertKeyword = KeywordToken; -/** @internal */ -export type AwaitKeyword = KeywordToken; -/** @internal */ -export type CaseKeyword = KeywordToken; - -/** @internal */ -export type AstKeywordToken = AstNode>; - -/** @internal */ -export type AstAssertsKeyword = AstNode; -/** @internal */ -export type AstAssertKeyword = AstNode; -/** @internal */ -export type AstAwaitKeyword = AstNode; -/** @internal */ -export type AstCaseKeyword = AstNode; - -// Modifiers - -/** @internal */ -export interface ModifierToken extends KeywordToken {} - -/** @internal */ -export type AbstractKeyword = ModifierToken; -/** @internal */ -export type AccessorKeyword = ModifierToken; -/** @internal */ -export type AsyncKeyword = ModifierToken; -/** @internal */ -export type ConstKeyword = ModifierToken; -/** @internal */ -export type DeclareKeyword = ModifierToken; -/** @internal */ -export type DefaultKeyword = ModifierToken; -/** @internal */ -export type ExportKeyword = ModifierToken; -/** @internal */ -export type InKeyword = ModifierToken; -/** @internal */ -export type PrivateKeyword = ModifierToken; -/** @internal */ -export type ProtectedKeyword = ModifierToken; -/** @internal */ -export type PublicKeyword = ModifierToken; -/** @internal */ -export type ReadonlyKeyword = ModifierToken; -/** @internal */ -export type OutKeyword = ModifierToken; -/** @internal */ -export type OverrideKeyword = ModifierToken; -/** @internal */ -export type StaticKeyword = ModifierToken; - -/** @internal */ -export type AstModifierToken = AstNode>; - -/** @internal */ -export type AstAbstractKeyword = AstNode; -/** @internal */ -export type AstAccessorKeyword = AstNode; -/** @internal */ -export type AstAsyncKeyword = AstNode; -/** @internal */ -export type AstConstKeyword = AstNode; -/** @internal */ -export type AstDeclareKeyword = AstNode; -/** @internal */ -export type AstDefaultKeyword = AstNode; -/** @internal */ -export type AstExportKeyword = AstNode; -/** @internal */ -export type AstInKeyword = AstNode; -/** @internal */ -export type AstPrivateKeyword = AstNode; -/** @internal */ -export type AstProtectedKeyword = AstNode; -/** @internal */ -export type AstPublicKeyword = AstNode; -/** @internal */ -export type AstReadonlyKeyword = AstNode; -/** @internal */ -export type AstOutKeyword = AstNode; -/** @internal */ -export type AstOverrideKeyword = AstNode; -/** @internal */ -export type AstStaticKeyword = AstNode; - -/** @internal */ -export type Modifier = - | AbstractKeyword - | AccessorKeyword - | AsyncKeyword - | ConstKeyword - | DeclareKeyword - | DefaultKeyword - | ExportKeyword - | InKeyword - | PrivateKeyword - | ProtectedKeyword - | PublicKeyword - | OutKeyword - | OverrideKeyword - | ReadonlyKeyword - | StaticKeyword; - -/** @internal */ -export type AstModifier = AstNodeOneOf; - -/** @internal */ -export type ModifierLike = - | Modifier - | Decorator; - -/** @internal */ -export type AstModifierLike = AstNodeOneOf; - -/** @internal */ -export class Identifier extends Token implements PrimaryExpression, JSDocContainer, FlowContainer, Declaration, ts.Identifier { - declare readonly ast: AstIdentifier; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get escapedText(): __String { - return this.ast.data.escapedText; - } - set escapedText(value: __String) { - this.ast.data.escapedText = value; - } - get resolvedSymbol(): Symbol { - return this.ast.data.resolvedSymbol; - } - set resolvedSymbol(value: Symbol) { - this.ast.data.resolvedSymbol = value; - } - get symbol(): Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value) { - this.ast.data.flowNode = value; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value) { - this.ast.data.jsDoc = value; - } - - get text(): string { - return idText(this); - } -} - -/** @internal */ -export class AstIdentifierData extends AstTokenData { - escapedText: __String = undefined!; - resolvedSymbol: Symbol = undefined!; // TransientIdentifier - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - - override computeTransformFlags(node: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(node: AstNode): TransformFlags { let transformFlags = TransformFlags.None; if (this.escapedText === "await") { transformFlags |= TransformFlags.ContainsPossibleTopLevelAwait; @@ -2318,316 +1565,74 @@ export class AstIdentifierData extends AstTokenData { } } -/** @internal */ -export class QualifiedName extends Node implements FlowContainer, ts.QualifiedName { - declare readonly ast: AstQualifiedName; - - declare _flowContainerBrand: any; - - get left(): EntityName { - return this.ast.data.left?.node; - } - set left(value: EntityName) { - this.ast.data.left = value?.ast; - } - get right(): Identifier { - return this.ast.data.right?.node; - } - set right(value: Identifier) { - this.ast.data.right = value?.ast; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstQualifiedNameData extends AstData { left: AstEntityName = undefined!; right: AstIdentifier = undefined!; - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.left) | propagateIdentifierNameFlags(this.right); } } -/** @internal */ -export type EntityName = - | Identifier - | QualifiedName; - -/** @internal */ export type AstEntityName = AstNodeOneOf; - -/** @internal */ -export type BindingName = - | Identifier - | BindingPattern; - -/** @internal */ export type AstBindingName = AstNodeOneOf; - -/** @internal */ -export type PropertyName = - | Identifier - | StringLiteral - | NoSubstitutionTemplateLiteral - | NumericLiteral - | ComputedPropertyName - | PrivateIdentifier - | BigIntLiteral; - -/** @internal */ export type AstPropertyName = AstNodeOneOf; - -/** @internal */ -export type MemberName = - | Identifier - | PrivateIdentifier; - -/** @internal */ export type AstMemberName = AstNodeOneOf; - -/** @internal */ -export type DeclarationName = - | PropertyName - | JsxAttributeName - | StringLiteralLike - | ElementAccessExpression - | BindingPattern - | EntityNameExpression; - -/** @internal */ export type AstDeclarationName = AstNodeOneOf; -/** @internal */ -export class ComputedPropertyName extends Node implements ts.ComputedPropertyName { - declare readonly ast: AstComputedPropertyName; - - override get parent() { - return super.parent as Declaration; - } - override set parent(value) { - super.parent = value; - } - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value: Expression) { - this.ast.data.expression = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstComputedPropertyNameData extends AstData { expression: AstExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | TransformFlags.ContainsES2015 | TransformFlags.ContainsComputedPropertyName; } } -/** @internal */ -export class PrivateIdentifier extends Token implements ts.PrivateIdentifier { - declare readonly ast: AstPrivateIdentifier; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get escapedText(): __String { - return this.ast.data.escapedText; - } - set escapedText(value: __String) { - this.ast.data.escapedText = value; - } - - get text(): string { - return idText(this); - } -} - -/** @internal */ +// dprint-ignore export class AstPrivateIdentifierData extends AstTokenData { escapedText: __String = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsClassFields; } } -/** @internal */ -export class TypeParameterDeclaration extends Node implements JSDocContainer, Declaration, ts.TypeParameterDeclaration { - declare readonly ast: AstTypeParameterDeclaration; - - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as DeclarationWithTypeParameterChildren | InferTypeNode; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value: NodeArray | undefined) { - this.ast.data.modifiers = value?.ast; - } - get name(): Identifier { - return this.ast.data.name.node; - } - set name(value: Identifier) { - this.ast.data.name = value.ast; - } - get constraint(): TypeNode | undefined { - return this.ast.data.constraint?.node; - } - set constraint(value: TypeNode | undefined) { - this.ast.data.constraint = value?.ast; - } - get default(): TypeNode | undefined { - return this.ast.data.default?.node; - } - set default(value: TypeNode | undefined) { - this.ast.data.default = value?.ast; - } - get expression(): Expression | undefined { - return this.ast.data.expression?.node; - } - set expression(value: Expression | undefined) { - this.ast.data.expression = value?.ast; - } - get symbol(): Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value) { - this.ast.data.jsDoc = value; - } -} - -/** @internal */ +// dprint-ignore export class AstTypeParameterDeclarationData extends AstTypeScriptNodeData { modifiers: AstNodeArray | undefined = undefined; name: AstIdentifier = undefined!; constraint: AstTypeNode | undefined = undefined; default: AstTypeNode | undefined = undefined; - expression: AstExpression | undefined = undefined; + expression: AstExpression | undefined = undefined; // For error recovery purposes (see `isGrammarError` in utilities.ts). - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } -/** @internal */ -export class ParameterDeclaration extends Node implements Declaration, JSDocContainer, ts.ParameterDeclaration { - declare readonly ast: AstParameterDeclaration; - - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as SignatureDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value: NodeArray | undefined) { - this.ast.data.modifiers = value?.ast; - } - get dotDotDotToken(): DotDotDotToken | undefined { - return this.ast.data.dotDotDotToken?.node; - } - set dotDotDotToken(value: DotDotDotToken | undefined) { - this.ast.data.dotDotDotToken = value?.ast; - } - get name(): BindingName { // TODO(rbuckton): `name` can be undefined for JSDoc signature parameters - return this.ast.data.name?.node; - } - set name(value: BindingName) { - this.ast.data.name = value?.ast; - } - get questionToken(): QuestionToken | undefined { - return this.ast.data.questionToken?.node; - } - set questionToken(value: QuestionToken | undefined) { - this.ast.data.questionToken = value?.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value: TypeNode | undefined) { - this.ast.data.type = value?.ast; - } - get initializer(): Expression | undefined { - return this.ast.data.initializer?.node; - } - set initializer(value: Expression | undefined) { - this.ast.data.initializer = value?.ast; - } - get symbol(): Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value) { - this.ast.data.jsDoc = value; - } -} -/** @internal */ +// dprint-ignore export class AstParameterDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; - dotDotDotToken: AstDotDotDotToken | undefined = undefined; - name: AstBindingName = undefined!; // TODO(rbuckton): `name` can be undefined for JSDoc signature parameters - questionToken: AstQuestionToken | undefined = undefined; - type: AstTypeNode | undefined = undefined; - initializer: AstExpression | undefined = undefined; - - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - - override computeTransformFlags(_: AstNode): TransformFlags { + dotDotDotToken: AstDotDotDotToken | undefined = undefined; // Present on rest parameter + // TODO(rbuckton): `name` can be undefined for JSDoc signature parameters + name: AstBindingName = undefined!; // Declared parameter name. + questionToken: AstQuestionToken | undefined = undefined; // Present on optional parameter + type: AstTypeNode | undefined = undefined; // Optional type annotation + initializer: AstExpression | undefined = undefined; // Optional initializer + + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { const name = this.name; if (name?.kind === SyntaxKind.Identifier && name.data.escapedText === "this") { return TransformFlags.ContainsTypeScript; @@ -2636,37 +1641,18 @@ export class AstParameterDeclarationData extends AstData { propagateChildFlags(this.dotDotDotToken) | propagateNameFlags(this.name) | propagateChildFlags(this.questionToken) | - propagateChildFlags(this.initializer) | - (this.questionToken ?? this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | - (this.dotDotDotToken ?? this.initializer ? TransformFlags.ContainsES2015 : TransformFlags.None) | - (modifiersToFlags(this.modifiers?.items) & ModifierFlags.ParameterPropertyModifier ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None); - } -} - -/** @internal */ -export class Decorator extends Node implements ts.Decorator { - declare readonly ast: AstDecorator; - - override get parent() { - return super.parent as Declaration; - } - override set parent(value) { - super.parent = value; - } - - get expression(): LeftHandSideExpression { - return this.ast.data.expression.node; - } - set expression(value: LeftHandSideExpression) { - this.ast.data.expression = value.ast; + propagateChildFlags(this.initializer) | + (this.questionToken ?? this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + (this.dotDotDotToken ?? this.initializer ? TransformFlags.ContainsES2015 : TransformFlags.None) | + (modifiersToFlags(this.modifiers?.items) & ModifierFlags.ParameterPropertyModifier ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None); } } -/** @internal */ +// dprint-ignore export class AstDecoratorData extends AstData { expression: AstLeftHandSideExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | TransformFlags.ContainsTypeScript | TransformFlags.ContainsTypeScriptClassSyntax | @@ -2674,359 +1660,72 @@ export class AstDecoratorData extends AstData { } } -/** @internal */ -export class PropertySignature extends Node implements Declaration, JSDocContainer, ts.PropertySignature { - declare readonly ast: AstPropertySignature; - - declare _typeElementBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as TypeLiteralNode | InterfaceDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value: NodeArray | undefined) { - this.ast.data.modifiers = value?.ast; - } - get name(): PropertyName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get questionToken(): QuestionToken | undefined { - return this.ast.data.questionToken?.node; - } - set questionToken(value) { - this.ast.data.questionToken = value?.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get initializer(): Expression | undefined { - return this.ast.data.initializer?.node; - } - set initializer(value) { - this.ast.data.initializer = value?.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } -} - -/** @internal */ +// dprint-ignore export class AstPropertySignatureData extends AstTypeScriptNodeData { modifiers: AstNodeArray | undefined = undefined; - name: AstPropertyName = undefined!; - questionToken: AstQuestionToken | undefined = undefined; - type: AstTypeNode | undefined = undefined; - initializer: AstExpression | undefined = undefined; // initialized by parser (grammar error) + name: AstPropertyName = undefined!; // Declared property name. + questionToken: AstQuestionToken | undefined = undefined; // Present on optional property + type: AstTypeNode | undefined = undefined; // Optional type annotation - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ initializer: AstExpression | undefined = undefined; // initialized by parser (grammar error, see see `isGrammarError` in utilities.ts) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) } -/** @internal */ -export type SignatureDeclaration = - | CallSignatureDeclaration - | ConstructSignatureDeclaration - | MethodSignature - | IndexSignatureDeclaration - | FunctionTypeNode - | ConstructorTypeNode - | JSDocFunctionType - | FunctionDeclaration - | MethodDeclaration - | ConstructorDeclaration - | AccessorDeclaration - | FunctionExpression - | ArrowFunction; - -/** @internal */ export type AstSignatureDeclaration = AstNodeOneOf; -/** @internal */ -export class CallSignatureDeclaration extends Node implements LocalsContainer, Declaration, JSDocContainer, TypeElement, ts.CallSignatureDeclaration { - declare readonly ast: AstCallSignatureDeclaration; - - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _typeElementBrand: any; - declare _localsContainerBrand: any; - - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstCallSignatureDeclarationData extends AstTypeScriptNodeData { typeParameters: AstNodeArray | undefined = undefined; parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; - typeArguments: AstNodeArray | undefined = undefined; // quick info - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) -} - -/** @internal */ -export class ConstructSignatureDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.ConstructSignatureDeclaration { - declare readonly ast: AstConstructSignatureDeclaration; - - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _typeElementBrand: any; - declare _localsContainerBrand: any; - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // quick info + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) } -/** @internal */ +// dprint-ignore export class AstConstructSignatureDeclarationData extends AstTypeScriptNodeData { typeParameters: AstNodeArray | undefined = undefined; parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; - typeArguments: AstNodeArray | undefined = undefined; // quick info - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; -} - -/** @internal */ -export class VariableDeclaration extends Node implements JSDocContainer, Declaration, ts.VariableDeclaration { - declare readonly ast: AstVariableDeclaration; - - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as VariableDeclarationList | CatchClause; - } - override set parent(value) { - super.parent = value; - } - get name(): BindingName { - return this.ast.data.name.node; - } - set name(value: BindingName) { - this.ast.data.name = value.ast; - } - get exclamationToken(): ExclamationToken | undefined { - return this.ast.data.exclamationToken?.node; - } - set exclamationToken(value: ExclamationToken | undefined) { - this.ast.data.exclamationToken = value?.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value: TypeNode | undefined) { - this.ast.data.type = value?.ast; - } - get initializer(): Expression | undefined { - return this.ast.data.initializer?.node; - } - set initializer(value: Expression | undefined) { - this.ast.data.initializer = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // quick info + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ +// dprint-ignore export class AstVariableDeclarationData extends AstData { - name: AstBindingName = undefined!; - exclamationToken: AstExclamationToken | undefined = undefined; - type: AstTypeNode | undefined = undefined; - initializer: AstExpression | undefined = undefined; + name: AstBindingName = undefined!; // Declared variable name + exclamationToken: AstExclamationToken | undefined = undefined; // Optional definite assignment assertion + type: AstTypeNode | undefined = undefined; // Optional type annotation + initializer: AstExpression | undefined = undefined; // Optional initializer - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateNameFlags(this.name) | propagateChildFlags(this.initializer) | (this.exclamationToken ?? this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); } } -/** @internal */ -export class VariableDeclarationList extends Node implements ts.VariableDeclarationList { - declare readonly ast: AstVariableDeclarationList; - - override get parent() { - return super.parent as VariableStatement | ForStatement | ForOfStatement | ForInStatement; - } - override set parent(value) { - super.parent = value; - } - - get declarations(): NodeArray { - return this.ast.data.declarations.nodes; - } - set declarations(value) { - this.ast.data.declarations = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstVariableDeclarationListData extends AstData { declarations: AstNodeArray = undefined!; - override computeTransformFlags(node: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(node: AstNode): TransformFlags { let transformFlags = propagateChildrenFlags(this.declarations) | TransformFlags.ContainsHoistedDeclarationOrCompletion; if (node.flags & NodeFlags.BlockScoped) { @@ -3040,76 +1739,18 @@ export class AstVariableDeclarationListData extends AstData { } } -/** @internal */ -export class BindingElement extends Node implements Declaration, FlowContainer, ts.BindingElement { - declare readonly ast: AstBindingElement; - - declare _declarationBrand: any; - declare _flowContainerBrand: any; - - override get parent() { - return super.parent as BindingPattern; - } - override set parent(value) { - super.parent = value; - } - - get propertyName(): PropertyName | undefined { - return this.ast.data.propertyName?.node; - } - set propertyName(value) { - this.ast.data.propertyName = value?.ast; - } - get dotDotDotToken(): DotDotDotToken | undefined { - return this.ast.data.dotDotDotToken?.node; - } - set dotDotDotToken(value) { - this.ast.data.dotDotDotToken = value?.ast; - } - get name(): BindingName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get initializer(): Expression | undefined { - return this.ast.data.initializer?.node; - } - set initializer(value) { - this.ast.data.initializer = value?.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstBindingElementData extends AstData { - propertyName: AstPropertyName | undefined = undefined; - dotDotDotToken: AstDotDotDotToken | undefined = undefined; - name: AstBindingName = undefined!; - initializer: AstExpression | undefined = undefined; + propertyName: AstPropertyName | undefined = undefined; // Binding property name (in object binding pattern) + dotDotDotToken: AstDotDotDotToken | undefined = undefined; // Present on rest element (in object binding pattern) + name: AstBindingName = undefined!; // Declared binding element name + initializer: AstExpression | undefined = undefined; // Optional initializer - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.dotDotDotToken) | propagateNameFlags(this.propertyName) | propagateNameFlags(this.name) | @@ -3119,91 +1760,20 @@ export class AstBindingElementData extends AstData { } } -/** @internal */ -export class PropertyDeclaration extends Node implements JSDocContainer, Declaration, ts.PropertyDeclaration { - declare readonly ast: AstPropertyDeclaration; - - declare _classElementBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as ClassLikeDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): PropertyName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get questionToken(): QuestionToken | undefined { - return this.ast.data.questionToken?.node; - } - set questionToken(value) { - this.ast.data.questionToken = value?.ast; - } - get exclamationToken(): ExclamationToken | undefined { - return this.ast.data.exclamationToken?.node; - } - set exclamationToken(value) { - this.ast.data.exclamationToken = value?.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get initializer(): Expression | undefined { - return this.ast.data.initializer?.node; - } - set initializer(value) { - this.ast.data.initializer = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstPropertyDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; name: AstPropertyName = undefined!; - questionToken: AstQuestionToken | undefined = undefined; + questionToken: AstQuestionToken | undefined = undefined; // Optional field. indicates grammar error for auto-accessor generation (see `isGrammarError` in utilities.ts) exclamationToken: AstExclamationToken | undefined = undefined; - type: AstTypeNode | undefined = undefined; - initializer: AstExpression | undefined = undefined; + type: AstTypeNode | undefined = undefined; // Optional type annotation + initializer: AstExpression | undefined = undefined; // Optional initializer - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(node: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(node: AstNode): TransformFlags { const modifierFlags = modifiersToFlags(this.modifiers?.items); const isAmbient = node.flags & NodeFlags.Ambient || modifierFlags & ModifierFlags.Ambient; @@ -3216,276 +1786,69 @@ export class AstPropertyDeclarationData extends AstData { } } -/** @internal */ -export class PropertyAssignment extends Node implements ObjectLiteralElement, JSDocContainer, Declaration, ts.PropertyAssignment { - declare readonly ast: AstPropertyAssignment; - - declare _objectLiteralBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as ObjectLiteralExpression; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): PropertyName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get questionToken(): QuestionToken | undefined { - return this.ast.data.questionToken?.node; - } - set questionToken(value) { - this.ast.data.questionToken = value?.ast; - } - get exclamationToken(): ExclamationToken | undefined { - return this.ast.data.exclamationToken?.node; - } - set exclamationToken(value) { - this.ast.data.exclamationToken = value?.ast; - } - get initializer(): Expression { - return this.ast.data.initializer.node; - } - set initializer(value) { - this.ast.data.initializer = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstPropertyAssignmentData extends AstData { - modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) + modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) name: AstPropertyName = undefined!; - questionToken: AstQuestionToken | undefined = undefined; // initialized by parser (grammar error) - exclamationToken: AstExclamationToken | undefined = undefined; // initialized by parser (grammar error) + questionToken: AstQuestionToken | undefined = undefined; // initialized by parser (grammar error) + exclamationToken: AstExclamationToken | undefined = undefined; // initialized by parser (grammar error) initializer: AstExpression = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateNameFlags(this.name) | - propagateChildFlags(this.initializer); - } -} - -/** @internal */ -export class ShorthandPropertyAssignment extends Node implements ObjectLiteralElement, JSDocContainer, Declaration, ts.ShorthandPropertyAssignment { - declare readonly ast: AstShorthandPropertyAssignment; - - declare _objectLiteralBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as ObjectLiteralExpression; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): Identifier { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get questionToken(): QuestionToken | undefined { - return this.ast.data.questionToken?.node; - } - set questionToken(value) { - this.ast.data.questionToken = value?.ast; - } - get exclamationToken(): ExclamationToken | undefined { - return this.ast.data.exclamationToken?.node; - } - set exclamationToken(value) { - this.ast.data.exclamationToken = value?.ast; - } - get equalsToken(): EqualsToken | undefined { - return this.ast.data.equalsToken?.node; - } - set equalsToken(value) { - this.ast.data.equalsToken = value?.ast; - } - get objectAssignmentInitializer(): Expression | undefined { - return this.ast.data.objectAssignmentInitializer?.node; - } - set objectAssignmentInitializer(value) { - this.ast.data.objectAssignmentInitializer = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ -export class AstShorthandPropertyAssignmentData extends AstData { - modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) - name: AstIdentifier = undefined!; - questionToken: AstQuestionToken | undefined = undefined; // initialized by parser (grammar error) - exclamationToken: AstExclamationToken | undefined = undefined; // initialized by parser (grammar error) - equalsToken: AstEqualsToken | undefined = undefined; // initialized by parser (grammar error) - objectAssignmentInitializer: AstExpression | undefined = undefined; - - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - - override computeTransformFlags(_: AstNode): TransformFlags { - return propagateIdentifierNameFlags(this.name) | - propagateChildFlags(this.objectAssignmentInitializer) | - TransformFlags.ContainsES2015; - } -} - -/** @internal */ -export class SpreadAssignment extends Node implements ObjectLiteralElement, JSDocContainer, Declaration, ts.SpreadAssignment { - declare readonly ast: AstSpreadAssignment; - - declare _objectLiteralBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as ObjectLiteralExpression; - } - override set parent(value) { - super.parent = value; - } - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; + propagateChildFlags(this.initializer); } - set localSymbol(value) { - this.ast.data.localSymbol = value; +} + +// dprint-ignore +export class AstShorthandPropertyAssignmentData extends AstData { + name: AstIdentifier = undefined!; + // used when ObjectLiteralExpression is used in ObjectAssignmentPattern + // it is a grammar error to appear in actual object initializer (see `isGrammarError` in utilities.ts): + equalsToken: AstEqualsToken | undefined = undefined; // initialized by parser (grammar error) + objectAssignmentInitializer: AstExpression | undefined = undefined; + modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) + questionToken: AstQuestionToken | undefined = undefined; // initialized by parser (grammar error) + exclamationToken: AstExclamationToken | undefined = undefined; // initialized by parser (grammar error) + + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return propagateIdentifierNameFlags(this.name) | + propagateChildFlags(this.objectAssignmentInitializer) | + TransformFlags.ContainsES2015; } } -/** @internal */ +// dprint-ignore export class AstSpreadAssignmentData extends AstData { expression: AstExpression = undefined!; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | TransformFlags.ContainsES2018 | TransformFlags.ContainsObjectRestOrSpread; } } -/** @internal */ -export type BindingPattern = - | ObjectBindingPattern - | ArrayBindingPattern; - -/** @internal */ export type AstBindingPattern = AstNodeOneOf; - -/** @internal */ -export type ArrayBindingElement = - | BindingElement - | OmittedExpression; - -/** @internal */ export type AstArrayBindingElement = AstNodeOneOf; -/** @internal */ -export class ObjectBindingPattern extends Node implements ts.ObjectBindingPattern { - declare readonly ast: AstObjectBindingPattern; - - override get parent() { - return super.parent as VariableDeclaration | ParameterDeclaration | BindingElement; - } - override set parent(value) { - super.parent = value; - } - - get elements(): NodeArray { - return this.ast.data.elements.nodes; - } - set elements(value) { - this.ast.data.elements = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstObjectBindingPatternData extends AstData { elements: AstNodeArray = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildrenFlags(this.elements) | TransformFlags.ContainsES2015 | TransformFlags.ContainsBindingPattern; @@ -3496,139 +1859,18 @@ export class AstObjectBindingPatternData extends AstData { } } -/** @internal */ -export class ArrayBindingPattern extends Node implements ts.ArrayBindingPattern { - declare readonly ast: AstArrayBindingPattern; - - override get parent() { - return super.parent as VariableDeclaration | ParameterDeclaration | BindingElement; - } - override set parent(value) { - super.parent = value; - } - - get elements(): NodeArray { - return this.ast.data.elements.nodes; - } - set elements(value) { - this.ast.data.elements = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstArrayBindingPatternData extends AstData { elements: AstNodeArray = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.elements) | TransformFlags.ContainsES2015 | TransformFlags.ContainsBindingPattern; } } -/** @internal */ -export class FunctionDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.FunctionDeclaration { - declare readonly ast: AstFunctionDeclaration; - - declare _functionLikeDeclarationBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _statementBrand: any; - declare _localsContainerBrand: any; - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get asteriskToken(): AsteriskToken | undefined { - return this.ast.data.asteriskToken?.node; - } - set asteriskToken(value) { - this.ast.data.asteriskToken = value?.ast; - } - get name(): Identifier | undefined { - return this.ast.data.name?.node; - } - set name(value) { - this.ast.data.name = value?.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get body(): Block | undefined { - return this.ast.data.body?.node; - } - set body(value) { - this.ast.data.body = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } - get endFlowNode(): ts.FlowNode | undefined { - return this.ast.data.endFlowNode; - } - set endFlowNode(value) { - this.ast.data.endFlowNode = value; - } - get returnFlowNode(): ts.FlowNode | undefined { - return this.ast.data.returnFlowNode; - } - set returnFlowNode(value) { - this.ast.data.returnFlowNode = value; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; // Used for quick info, replaces typeParameters for instantiated signatures - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstFunctionDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; asteriskToken: AstAsteriskToken | undefined = undefined; @@ -3637,17 +1879,17 @@ export class AstFunctionDeclarationData extends AstData { parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; body: AstFunctionBody | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // Used for quick info, replaces typeParameters for instantiated signatures - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { if (!this.body || modifiersToFlags(this.modifiers?.items) & ModifierFlags.Ambient) { return TransformFlags.ContainsTypeScript; } @@ -3673,97 +1915,7 @@ export class AstFunctionDeclarationData extends AstData { } } -/** @internal */ -export class MethodSignature extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.MethodSignature { - declare readonly ast: AstMethodSignature; - - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _typeElementBrand: any; - declare _localsContainerBrand: any; - - override get parent() { - return super.parent as TypeLiteralNode | InterfaceDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): PropertyName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get questionToken(): QuestionToken | undefined { - return this.ast.data.questionToken?.node; - } - set questionToken(value) { - this.ast.data.questionToken = value?.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstMethodSignatureData extends AstTypeScriptNodeData { modifiers: AstNodeArray | undefined = undefined; name: AstPropertyName = undefined!; @@ -3772,144 +1924,15 @@ export class AstMethodSignatureData extends AstTypeScriptNodeData { parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; - typeArguments: AstNodeArray | undefined = undefined; // quick info - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; -} - -/** @internal */ -export class MethodDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, FlowContainer, ts.MethodDeclaration { - declare readonly ast: AstMethodDeclaration; - - declare _functionLikeDeclarationBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _classElementBrand: any; - declare _objectLiteralBrand: any; - declare _localsContainerBrand: any; - declare _flowContainerBrand: any; - - override get parent() { - return super.parent as ClassLikeDeclaration | ObjectLiteralExpression; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get asteriskToken(): AsteriskToken | undefined { - return this.ast.data.asteriskToken?.node; - } - set asteriskToken(value) { - this.ast.data.asteriskToken = value?.ast; - } - get name(): PropertyName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get questionToken(): QuestionToken | undefined { - return this.ast.data.questionToken?.node; - } - set questionToken(value) { - this.ast.data.questionToken = value?.ast; - } - get exclamationToken(): ExclamationToken | undefined { - return this.ast.data.exclamationToken?.node; - } - set exclamationToken(value) { - this.ast.data.exclamationToken = value?.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get body(): Block | undefined { - return this.ast.data.body?.node; - } - set body(value) { - this.ast.data.body = value?.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } - get endFlowNode(): ts.FlowNode | undefined { - return this.ast.data.endFlowNode; - } - set endFlowNode(value) { - this.ast.data.endFlowNode = value; - } - get returnFlowNode(): ts.FlowNode | undefined { - return this.ast.data.returnFlowNode; - } - set returnFlowNode(value) { - this.ast.data.returnFlowNode = value; - } + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // quick info + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ +// dprint-ignore export class AstMethodDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; asteriskToken: AstAsteriskToken | undefined = undefined; @@ -3920,18 +1943,18 @@ export class AstMethodDeclarationData extends AstData { parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; body: AstFunctionBody | undefined = undefined; - typeArguments: AstNodeArray | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { if (!this.body) { return TransformFlags.ContainsTypeScript; } @@ -3958,280 +1981,46 @@ export class AstMethodDeclarationData extends AstData { } } -/** @internal */ -export class ConstructorDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.ConstructorDeclaration { - declare readonly ast: AstConstructorDeclaration; - - declare _functionLikeDeclarationBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _classElementBrand: any; - declare _localsContainerBrand: any; - - override get parent() { - return super.parent as ClassLikeDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get body(): Block | undefined { - return this.ast.data.body?.node; - } - set body(value) { - this.ast.data.body = value?.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } - get endFlowNode(): ts.FlowNode | undefined { - return this.ast.data.endFlowNode; - } - set endFlowNode(value) { - this.ast.data.endFlowNode = value; - } - get returnFlowNode(): ts.FlowNode | undefined { - return this.ast.data.returnFlowNode; - } - set returnFlowNode(value) { - this.ast.data.returnFlowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstConstructorDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; body: AstFunctionBody | undefined = undefined; typeParameters: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) parameters: AstNodeArray = undefined!; - type: AstTypeNode | undefined = undefined; // initialized by parser (grammar error) - typeArguments: AstNodeArray | undefined = undefined; // quick info - - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - - override computeTransformFlags(_: AstNode): TransformFlags { - if (!this.body) { - return TransformFlags.ContainsTypeScript; - } - else { - return propagateChildrenFlags(this.modifiers) | - propagateChildrenFlags(this.parameters) | - (propagateChildFlags(this.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | - TransformFlags.ContainsES2015; - } - } -} - -/** @internal */ -export class SemicolonClassElement extends Node implements JSDocContainer, ts.SemicolonClassElement { - declare readonly ast: AstSemicolonClassElement; - - declare _classElementBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare symbol: never; - declare localSymbol: never; - - override get parent() { - return super.parent as ClassLikeDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } -} - -/** @internal */ -export class AstSemicolonClassElementData extends AstData { - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - - override computeTransformFlags(_: AstNode): TransformFlags { - return TransformFlags.None; - } -} - -/** @internal */ -export class GetAccessorDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, FlowContainer, ts.GetAccessorDeclaration { - declare readonly ast: AstGetAccessorDeclaration; - - declare _functionLikeDeclarationBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _classElementBrand: any; - declare _typeElementBrand: any; - declare _objectLiteralBrand: any; - declare _localsContainerBrand: any; - declare _flowContainerBrand: any; - - override get parent() { - return super.parent as ClassLikeDeclaration | ObjectLiteralExpression; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): PropertyName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get body(): Block | undefined { - return this.ast.data.body?.node; - } - set body(value) { - this.ast.data.body = value?.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } - get endFlowNode(): ts.FlowNode | undefined { - return this.ast.data.endFlowNode; - } - set endFlowNode(value) { - this.ast.data.endFlowNode = value; - } - get returnFlowNode(): ts.FlowNode | undefined { - return this.ast.data.returnFlowNode; + type: AstTypeNode | undefined = undefined; // initialized by parser (grammar error) + + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // quick info + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + if (!this.body) { + return TransformFlags.ContainsTypeScript; + } + else { + return propagateChildrenFlags(this.modifiers) | + propagateChildrenFlags(this.parameters) | + (propagateChildFlags(this.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | + TransformFlags.ContainsES2015; + } } - set returnFlowNode(value) { - this.ast.data.returnFlowNode = value; +} + +// dprint-ignore +export class AstSemicolonClassElementData extends AstData { + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.None; } } -/** @internal */ +// dprint-ignore export class AstGetAccessorDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; name: AstPropertyName = undefined!; @@ -4239,18 +2028,18 @@ export class AstGetAccessorDeclarationData extends AstData { typeParameters: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; - typeArguments: AstNodeArray | undefined = undefined; // quick info - - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - - override computeTransformFlags(_: AstNode): TransformFlags { + + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // quick info + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { if (!this.body) { return TransformFlags.ContainsTypeScript; } @@ -4265,119 +2054,7 @@ export class AstGetAccessorDeclarationData extends AstData { } } -/** @internal */ -export class SetAccessorDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, FlowContainer, ts.SetAccessorDeclaration { - declare readonly ast: AstSetAccessorDeclaration; - - declare _functionLikeDeclarationBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _classElementBrand: any; - declare _typeElementBrand: any; - declare _objectLiteralBrand: any; - declare _localsContainerBrand: any; - declare _flowContainerBrand: any; - - override get parent() { - return super.parent as ClassLikeDeclaration | ObjectLiteralExpression; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): PropertyName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get body(): Block | undefined { - return this.ast.data.body?.node; - } - set body(value) { - this.ast.data.body = value?.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } - get endFlowNode(): ts.FlowNode | undefined { - return this.ast.data.endFlowNode; - } - set endFlowNode(value) { - this.ast.data.endFlowNode = value; - } - get returnFlowNode(): ts.FlowNode | undefined { - return this.ast.data.returnFlowNode; - } - set returnFlowNode(value) { - this.ast.data.returnFlowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstSetAccessorDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; name: AstPropertyName = undefined!; @@ -4385,18 +2062,18 @@ export class AstSetAccessorDeclarationData extends AstData { typeParameters: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; // initialized by parser (grammar error) - typeArguments: AstNodeArray | undefined = undefined; // quick info - - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - - override computeTransformFlags(_: AstNode): TransformFlags { + + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // quick info + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { if (!this.body) { return TransformFlags.ContainsTypeScript; } @@ -4410,288 +2087,55 @@ export class AstSetAccessorDeclarationData extends AstData { } } -/** @internal */ -export type AccessorDeclaration = - | GetAccessorDeclaration - | SetAccessorDeclaration; - -/** @internal */ export type AstAccessorDeclaration = AstNodeOneOf; -/** @internal */ -export class IndexSignatureDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.IndexSignatureDeclaration { - declare readonly ast: AstIndexSignatureDeclaration; - - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _classElementBrand: any; - declare _typeElementBrand: any; - declare _localsContainerBrand: any; - - override get parent() { - return super.parent as ObjectTypeDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode { - return this.ast.data.type?.node!; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstIndexSignatureDeclarationData extends AstTypeScriptNodeData { modifiers: AstNodeArray | undefined = undefined; typeParameters: AstNodeArray | undefined = undefined; parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; - typeArguments: AstNodeArray | undefined = undefined; // quick info - - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; -} - -/** @internal */ -export class ClassStaticBlockDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.ClassStaticBlockDeclaration { - declare readonly ast: AstClassStaticBlockDeclaration; - - declare _classElementBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - override get parent() { - return super.parent as ClassLikeDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get body(): Block { - return this.ast.data.body.node; - } - set body(value) { - this.ast.data.body = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } - get endFlowNode(): ts.FlowNode | undefined { - return this.ast.data.endFlowNode; - } - set endFlowNode(value) { - this.ast.data.endFlowNode = value; - } - get returnFlowNode(): ts.FlowNode | undefined { - return this.ast.data.returnFlowNode; - } - set returnFlowNode(value) { - this.ast.data.returnFlowNode = value; - } + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // quick info + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ +// dprint-ignore export class AstClassStaticBlockDeclarationData extends AstData { body: AstBlock = undefined!; modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.body) | TransformFlags.ContainsClassFields; } } /** * @deprecated - * @internal - */ -export class ImportTypeAssertionContainer extends Node implements ts.ImportTypeAssertionContainer { - declare readonly ast: AstImportTypeAssertionContainer; - - override get parent() { - return super.parent as ImportTypeNode; - } - override set parent(value) { - super.parent = value; - } - - /** @deprecated */ - get assertClause(): ImportAttributes { - return this.ast.data.assertClause.node; - } - set assertClause(value) { - this.ast.data.assertClause = value.ast; - } - get multiLine(): boolean { - return this.ast.data.multiLine; - } - set multiLine(value) { - this.ast.data.multiLine = value; - } -} - -/** - * @deprecated - * @internal */ export type AstImportTypeAssertionContainer = AstNode; /** * @deprecated - * @internal */ export class AstImportTypeAssertionContainerData extends AstTypeScriptNodeData { assertClause: AstImportAttributes = undefined!; multiLine: boolean = false; } -/** @internal */ -export class ImportTypeNode extends Node implements ts.ImportTypeNode { - declare readonly ast: AstImportTypeNode; - - declare _typeNodeBrand: any; - - get isTypeOf(): boolean { - return this.ast.data.isTypeOf; - } - set isTypeOf(value) { - this.ast.data.isTypeOf = value; - } - get argument(): TypeNode { - return this.ast.data.argument.node; - } - set argument(value) { - this.ast.data.argument = value.ast; - } - /** @deprecated */ - get attributes(): ImportAttributes | undefined { - return this.ast.data.attributes?.node; - } - set attributes(value) { - this.ast.data.attributes = value?.ast; - } - get assertions(): ImportTypeAssertionContainer | undefined { - return this.ast.data.assertions?.node; - } - set assertions(value) { - this.ast.data.assertions = value?.ast; - } - get qualifier(): Identifier | QualifiedName | undefined { - return this.ast.data.qualifier?.node; - } - set qualifier(value) { - this.ast.data.qualifier = value?.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstImportTypeNodeData extends AstTypeScriptNodeData { isTypeOf: boolean = false; argument: AstTypeNode = undefined!; @@ -4701,735 +2145,149 @@ export class AstImportTypeNodeData extends AstTypeScriptNodeData { typeArguments: AstNodeArray | undefined = undefined; } -/** @internal */ -export interface KeywordTypeNode extends KeywordToken, TypeNode { - readonly ast: AstKeywordTypeNode; - readonly kind: TKind; - _typeNodeBrand: any; -} - -/** @internal */ -export type AstKeywordTypeNode = AstNode>; - -/** @internal */ -export class ThisTypeNode extends Node implements ts.ThisTypeNode { - declare readonly ast: AstThisTypeNode; - - declare _typeNodeBrand: any; -} +export type AstKeywordTypeNode = AstNode>; -/** @internal */ +// dprint-ignore export class AstThisTypeNodeData extends AstTypeScriptNodeData { } -/** @internal */ -export type FunctionOrConstructorTypeNode = - | FunctionTypeNode - | ConstructorTypeNode; - -/** @internal */ export type AstFunctionOrConstructorTypeNode = AstNodeOneOf; -/** @internal */ -export class FunctionTypeNode extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.FunctionTypeNode { - declare readonly ast: AstFunctionTypeNode; - - declare _typeNodeBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstFunctionTypeNodeData extends AstTypeScriptNodeData { modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) typeParameters: AstNodeArray | undefined = undefined; parameters: AstNodeArray = undefined!; type: AstTypeNode = undefined!; - typeArguments: AstNodeArray | undefined = undefined; // quick info - - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; -} - -/** @internal */ -export class ConstructorTypeNode extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.ConstructorTypeNode { - declare readonly ast: AstConstructorTypeNode; - - declare _typeNodeBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // quick info + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ +// dprint-ignore export class AstConstructorTypeNodeData extends AstTypeScriptNodeData { modifiers: AstNodeArray | undefined = undefined; typeParameters: AstNodeArray | undefined = undefined; parameters: AstNodeArray = undefined!; type: AstTypeNode = undefined!; - typeArguments: AstNodeArray | undefined = undefined; // quick info - - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; -} - -/** @internal */ -export class TypeReferenceNode extends Node implements ts.TypeReferenceNode { - declare readonly ast: AstTypeReferenceNode; - - declare _typeNodeBrand: any; - get typeName(): Identifier | QualifiedName { - return this.ast.data.typeName.node; - } - set typeName(value) { - this.ast.data.typeName = value.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // quick info + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ +// dprint-ignore export class AstTypeReferenceNodeData extends AstTypeScriptNodeData { typeName: AstEntityName = undefined!; - typeArguments: AstNodeArray | undefined = undefined; -} - -/** @internal */ -export class TypePredicateNode extends Node implements ts.TypePredicateNode { - declare readonly ast: AstTypePredicateNode; - - declare _typeNodeBrand: any; - - override get parent() { - return super.parent as SignatureDeclaration | JSDocTypeExpression; - } - override set parent(value) { - super.parent = value; - } - - get assertsModifier(): AssertsKeyword | undefined { - return this.ast.data.assertsModifier?.node; - } - set assertsModifier(value) { - this.ast.data.assertsModifier = value?.ast; - } - get parameterName(): Identifier | ThisTypeNode { - return this.ast.data.parameterName.node; - } - set parameterName(value) { - this.ast.data.parameterName = value.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } -} - -/** @internal */ -export class AstTypePredicateNodeData extends AstTypeScriptNodeData { - assertsModifier: AstAssertsKeyword | undefined = undefined; - parameterName: AstIdentifier | AstThisTypeNode = undefined!; - type: AstTypeNode | undefined = undefined; -} - -/** @internal */ -export class TypeQueryNode extends Node implements ts.TypeQueryNode { - declare readonly ast: AstTypeQueryNode; - - declare _typeNodeBrand: any; - - get exprName(): Identifier | QualifiedName { - return this.ast.data.exprName.node; - } - set exprName(value) { - this.ast.data.exprName = value.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } + typeArguments: AstNodeArray | undefined = undefined; } -/** @internal */ +// dprint-ignore +export class AstTypePredicateNodeData extends AstTypeScriptNodeData { + assertsModifier: AstAssertsKeyword | undefined = undefined; + parameterName: AstIdentifier | AstThisTypeNode = undefined!; + type: AstTypeNode | undefined = undefined; +} + +// dprint-ignore export class AstTypeQueryNodeData extends AstTypeScriptNodeData { exprName: AstEntityName = undefined!; typeArguments: AstNodeArray | undefined = undefined; } -/** @internal */ -export class TypeLiteralNode extends Node implements Declaration, ts.TypeLiteralNode { - declare readonly ast: AstTypeLiteralNode; - - declare _typeNodeBrand: any; - declare _declarationBrand: any; - - get members(): NodeArray { - return this.ast.data.members.nodes; - } - set members(value) { - this.ast.data.members = value.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstTypeLiteralNodeData extends AstTypeScriptNodeData { members: AstNodeArray = undefined!; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) -} - -/** @internal */ -export class ArrayTypeNode extends Node implements ts.ArrayTypeNode { - declare readonly ast: AstArrayTypeNode; - - declare _typeNodeBrand: any; - get elementType(): TypeNode { - return this.ast.data.elementType.node; - } - set elementType(value) { - this.ast.data.elementType = value.ast; - } + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } -/** @internal */ +// dprint-ignore export class AstArrayTypeNodeData extends AstTypeScriptNodeData { elementType: AstTypeNode = undefined!; } -/** @internal */ -export class TupleTypeNode extends Node implements ts.TupleTypeNode { - declare readonly ast: AstTupleTypeNode; - - declare _typeNodeBrand: any; - - get elements(): NodeArray { - return this.ast.data.elements.nodes; - } - set elements(value: NodeArray) { - this.ast.data.elements = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstTupleTypeNodeData extends AstTypeScriptNodeData { elements: AstNodeArray = undefined!; } -/** @internal */ -export class NamedTupleMember extends Node implements JSDocContainer, Declaration, ts.NamedTupleMember { - declare readonly ast: AstNamedTupleMember; - - declare _typeNodeBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - get dotDotDotToken(): DotDotDotToken | undefined { - return this.ast.data.dotDotDotToken?.node; - } - set dotDotDotToken(value) { - this.ast.data.dotDotDotToken = value?.ast; - } - get name(): Identifier { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get questionToken(): QuestionToken | undefined { - return this.ast.data.questionToken?.node; - } - set questionToken(value) { - this.ast.data.questionToken = value?.ast; - } - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstNamedTupleMemberData extends AstTypeScriptNodeData { dotDotDotToken: AstDotDotDotToken | undefined = undefined; name: AstIdentifier = undefined!; questionToken: AstQuestionToken | undefined = undefined; type: AstTypeNode = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) -} - -/** @internal */ -export class OptionalTypeNode extends Node implements ts.OptionalTypeNode { - declare readonly ast: AstOptionalTypeNode; - - declare _typeNodeBrand: any; - - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } -/** @internal */ +// dprint-ignore export class AstOptionalTypeNodeData extends AstTypeScriptNodeData { type: AstTypeNode = undefined!; } -/** @internal */ -export class RestTypeNode extends Node implements ts.RestTypeNode { - declare readonly ast: AstRestTypeNode; - - declare _typeNodeBrand: any; - - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstRestTypeNodeData extends AstTypeScriptNodeData { type: AstTypeNode = undefined!; } -/** @internal */ -export type UnionOrIntersectionTypeNode = - | UnionTypeNode - | IntersectionTypeNode; - -/** @internal */ export type AstUnionOrIntersectionTypeNode = AstNodeOneOf; -/** @internal */ -export class UnionTypeNode extends Node implements ts.UnionTypeNode { - declare readonly ast: AstUnionTypeNode; - - declare _typeNodeBrand: any; - - get types(): NodeArray { - return this.ast.data.types.nodes; - } - set types(value) { - this.ast.data.types = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstUnionTypeNodeData extends AstTypeScriptNodeData { types: AstNodeArray = undefined!; } -/** @internal */ -export class IntersectionTypeNode extends Node implements ts.IntersectionTypeNode { - declare readonly ast: AstIntersectionTypeNode; - - declare _typeNodeBrand: any; - - get types(): NodeArray { - return this.ast.data.types.nodes; - } - set types(value) { - this.ast.data.types = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstIntersectionTypeNodeData extends AstTypeScriptNodeData { types: AstNodeArray = undefined!; } -/** @internal */ -export class ConditionalTypeNode extends Node implements LocalsContainer, ts.ConditionalTypeNode { - declare readonly ast: AstConditionalTypeNode; - - declare _typeNodeBrand: any; - declare _localsContainerBrand: any; - - get checkType(): TypeNode { - return this.ast.data.checkType.node; - } - set checkType(value) { - this.ast.data.checkType = value.ast; - } - get extendsType(): TypeNode { - return this.ast.data.extendsType.node; - } - set extendsType(value) { - this.ast.data.extendsType = value.ast; - } - get trueType(): TypeNode { - return this.ast.data.trueType.node; - } - set trueType(value) { - this.ast.data.trueType = value.ast; - } - get falseType(): TypeNode { - return this.ast.data.falseType.node; - } - set falseType(value) { - this.ast.data.falseType = value.ast; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstConditionalTypeNodeData extends AstTypeScriptNodeData { checkType: AstTypeNode = undefined!; extendsType: AstTypeNode = undefined!; trueType: AstTypeNode = undefined!; falseType: AstTypeNode = undefined!; - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; -} - -/** @internal */ -export class InferTypeNode extends Node implements ts.InferTypeNode { - declare readonly ast: AstInferTypeNode; - - declare _typeNodeBrand: any; - get typeParameter(): TypeParameterDeclaration { - return this.ast.data.typeParameter.node; - } - set typeParameter(value) { - this.ast.data.typeParameter = value.ast; - } + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ +// dprint-ignore export class AstInferTypeNodeData extends AstTypeScriptNodeData { typeParameter: AstTypeParameterDeclaration = undefined!; } -/** @internal */ -export class ParenthesizedTypeNode extends Node implements ts.ParenthesizedTypeNode { - declare readonly ast: AstParenthesizedTypeNode; - - declare _typeNodeBrand: any; - - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstParenthesizedTypeNodeData extends AstTypeScriptNodeData { type: AstTypeNode = undefined!; } -/** @internal */ -export class TypeOperatorNode extends Node implements ts.TypeOperatorNode { - declare readonly ast: AstTypeOperatorNode; - - declare _typeNodeBrand: any; - - get operator(): ts.SyntaxKind.KeyOfKeyword | ts.SyntaxKind.ReadonlyKeyword | ts.SyntaxKind.UniqueKeyword { - return this.ast.data.operator; - } - set operator(value) { - this.ast.data.operator = value; - } - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstTypeOperatorNodeData extends AstTypeScriptNodeData { operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword = undefined!; type: AstTypeNode = undefined!; } -/** @internal */ -export class IndexedAccessTypeNode extends Node implements ts.IndexedAccessTypeNode { - declare readonly ast: AstIndexedAccessTypeNode; - - declare _typeNodeBrand: any; - - get objectType(): TypeNode { - return this.ast.data.objectType.node; - } - set objectType(value) { - this.ast.data.objectType = value.ast; - } - get indexType(): TypeNode { - return this.ast.data.indexType.node; - } - set indexType(value) { - this.ast.data.indexType = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstIndexedAccessTypeNodeData extends AstTypeScriptNodeData { objectType: AstTypeNode = undefined!; indexType: AstTypeNode = undefined!; } -/** @internal */ -export class MappedTypeNode extends Node implements Declaration, LocalsContainer, ts.MappedTypeNode { - declare readonly ast: AstMappedTypeNode; - - declare _typeNodeBrand: any; - declare _declarationBrand: any; - declare _localsContainerBrand: any; - - get readonlyToken(): PlusToken | MinusToken | ReadonlyKeyword | undefined { - return this.ast.data.readonlyToken?.node; - } - set readonlyToken(value) { - this.ast.data.readonlyToken = value?.ast; - } - get typeParameter(): TypeParameterDeclaration { - return this.ast.data.typeParameter.node; - } - set typeParameter(value) { - this.ast.data.typeParameter = value.ast; - } - get nameType(): TypeNode | undefined { - return this.ast.data.nameType?.node; - } - set nameType(value) { - this.ast.data.nameType = value?.ast; - } - get questionToken(): QuestionToken | PlusToken | MinusToken | undefined { - return this.ast.data.questionToken?.node; - } - set questionToken(value) { - this.ast.data.questionToken = value?.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get members(): NodeArray | undefined { - return this.ast.data.members?.nodes; - } - set members(value) { - this.ast.data.members = value?.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstMappedTypeNodeData extends AstTypeScriptNodeData { readonlyToken: AstReadonlyKeyword | AstPlusToken | AstMinusToken | undefined = undefined; typeParameter: AstTypeParameterDeclaration = undefined!; @@ -5437,155 +2295,45 @@ export class AstMappedTypeNodeData extends AstTypeScriptNodeData { questionToken: AstQuestionToken | AstPlusToken | AstMinusToken | undefined = undefined; type: AstTypeNode | undefined = undefined; members: AstNodeArray | undefined = undefined; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; -} - -/** @internal */ -export class LiteralTypeNode extends Node implements ts.LiteralTypeNode { - declare readonly ast: AstLiteralTypeNode; - declare _typeNodeBrand: any; - - get literal(): NullLiteral | TrueLiteral | FalseLiteral | PrefixUnaryExpression | LiteralExpression { - return this.ast.data.literal.node; - } - set literal(value) { - this.ast.data.literal = value.ast; - } + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ +// dprint-ignore export class AstLiteralTypeNodeData extends AstTypeScriptNodeData { literal: AstNullLiteral | AstBooleanLiteral | AstLiteralExpression | AstPrefixUnaryExpression = undefined!; } -/** @internal */ -export type PropertyNameLiteral = - | Identifier - | StringLiteralLike - | NumericLiteral - | JsxNamespacedName - | BigIntLiteral; - -/** @internal */ export type AstPropertyNameLiteral = AstNodeOneOf; -/** @internal */ -export class TemplateLiteralTypeNode extends Node implements ts.TemplateLiteralTypeNode { - declare readonly ast: AstTemplateLiteralTypeNode; - - declare _typeNodeBrand: any; - - get head(): TemplateHead { - return this.ast.data.head.node; - } - set head(value) { - this.ast.data.head = value.ast; - } - get templateSpans(): NodeArray { - return this.ast.data.templateSpans.nodes; - } - set templateSpans(value) { - this.ast.data.templateSpans = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstTemplateLiteralTypeNodeData extends AstTypeScriptNodeData { head: AstTemplateHead = undefined!; templateSpans: AstNodeArray = undefined!; } -/** @internal */ -export class TemplateLiteralTypeSpan extends Node implements ts.TemplateLiteralTypeSpan { - declare readonly ast: AstTemplateLiteralTypeSpan; - - declare _typeNodeBrand: any; - - override get parent() { - return super.parent as TemplateLiteralTypeNode; - } - override set parent(value) { - super.parent = value; - } - - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } - get literal(): TemplateMiddle | TemplateTail { - return this.ast.data.literal.node; - } - set literal(value) { - this.ast.data.literal = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstTemplateLiteralTypeSpanData extends AstTypeScriptNodeData { type: AstTypeNode = undefined!; literal: AstTemplateMiddle | AstTemplateTail = undefined!; } -/** @internal */ -export type Literal = - | NumericLiteral - | BigIntLiteral - | StringLiteral - | JsxText - | RegularExpressionLiteral - | NoSubstitutionTemplateLiteral; - -/** @internal */ -export type AstLiteral = AstNodeOneOf; - -/** @internal */ -export class OmittedExpression extends Node implements ts.OmittedExpression { - declare readonly ast: AstOmittedExpression; - - declare _expressionBrand: any; -} - -/** @internal */ +// dprint-ignore export class AstOmittedExpressionData extends AstData { - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; } } -/** @internal */ -export class PrefixUnaryExpression extends Node implements ts.PrefixUnaryExpression { - declare readonly ast: AstPrefixUnaryExpression; - - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get operator(): ts.PrefixUnaryOperator { - return this.ast.data.operator; - } - set operator(value) { - this.ast.data.operator = value; - } - get operand(): UnaryExpression { - return this.ast.data.operand.node; - } - set operand(value) { - this.ast.data.operand = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstPrefixUnaryExpressionData extends AstData { operator: PrefixUnaryOperator = undefined!; operand: AstUnaryExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.operand); // Only set this flag for non-generated identifiers and non-"local" names. See the // comment in `visitPreOrPostfixUnaryExpression` in module.ts @@ -5602,34 +2350,12 @@ export class AstPrefixUnaryExpressionData extends AstData { } } -/** @internal */ -export class PostfixUnaryExpression extends Node implements ts.PostfixUnaryExpression { - declare readonly ast: AstPostfixUnaryExpression; - - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get operand(): LeftHandSideExpression { - return this.ast.data.operand.node; - } - set operand(value) { - this.ast.data.operand = value.ast; - } - get operator(): ts.PostfixUnaryOperator { - return this.ast.data.operator; - } - set operator(value) { - this.ast.data.operator = value; - } -} - -/** @internal */ +// dprint-ignore export class AstPostfixUnaryExpressionData extends AstData { operand: AstLeftHandSideExpression = undefined!; operator: PostfixUnaryOperator = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.operand); // Only set this flag for non-generated identifiers and non-"local" names. See the // comment in `visitPreOrPostfixUnaryExpression` in module.ts @@ -5639,104 +2365,44 @@ export class AstPostfixUnaryExpressionData extends AstData { !this.operand.emitNode.autoGenerate && !(this.operand.emitNode.flags & EmitFlags.LocalName)) ) { - transformFlags |= TransformFlags.ContainsUpdateExpressionForIdentifier; - } - return transformFlags; - } -} - -/** @internal */ -export class DeleteExpression extends Node implements ts.DeleteExpression { - declare readonly ast: AstDeleteExpression; - - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get expression(): UnaryExpression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } -} - -/** @internal */ -export class AstDeleteExpressionData extends AstData { - expression: AstUnaryExpression = undefined!; - - override computeTransformFlags(_: AstNode): TransformFlags { - return propagateChildFlags(this.expression); - } -} - -/** @internal */ -export class TypeOfExpression extends Node implements ts.TypeOfExpression { - declare readonly ast: AstTypeOfExpression; - - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get expression(): UnaryExpression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; + transformFlags |= TransformFlags.ContainsUpdateExpressionForIdentifier; + } + return transformFlags; } } -/** @internal */ -export class AstTypeOfExpressionData extends AstData { +// dprint-ignore +export class AstDeleteExpressionData extends AstData { expression: AstUnaryExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression); } } -/** @internal */ -export class VoidExpression extends Node implements ts.VoidExpression { - declare readonly ast: AstVoidExpression; - - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; +// dprint-ignore +export class AstTypeOfExpressionData extends AstData { + expression: AstUnaryExpression = undefined!; - get expression(): UnaryExpression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression); } } -/** @internal */ +// dprint-ignore export class AstVoidExpressionData extends AstData { expression: AstUnaryExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression); } } -/** @internal */ -export class AwaitExpression extends Node implements ts.AwaitExpression { - declare readonly ast: AstAwaitExpression; - - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get expression(): UnaryExpression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstAwaitExpressionData extends AstData { expression: AstUnaryExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | TransformFlags.ContainsES2017 | TransformFlags.ContainsES2018 | @@ -5744,32 +2410,12 @@ export class AstAwaitExpressionData extends AstData { } } -/** @internal */ -export class YieldExpression extends Node implements ts.YieldExpression { - declare readonly ast: AstYieldExpression; - - declare _expressionBrand: any; - - get asteriskToken(): AsteriskToken | undefined { - return this.ast.data.asteriskToken?.node; - } - set asteriskToken(value) { - this.ast.data.asteriskToken = value?.ast; - } - get expression(): Expression | undefined { - return this.ast.data.expression?.node; - } - set expression(value) { - this.ast.data.expression = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstYieldExpressionData extends AstData { asteriskToken: AstAsteriskToken | undefined = undefined; expression: AstExpression | undefined = undefined; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | propagateChildFlags(this.asteriskToken) | TransformFlags.ContainsES2015 | @@ -5778,70 +2424,20 @@ export class AstYieldExpressionData extends AstData { } } -/** @internal */ -export type BinaryOperatorToken = Token; - -/** @internal */ export type AstBinaryOperatorToken = AstNode; -/** @internal */ -export class BinaryExpression extends Node implements JSDocContainer, Declaration, ts.BinaryExpression { - declare readonly ast: AstBinaryExpression; - - declare _expressionBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - get left(): Expression { - return this.ast.data.left.node; - } - set left(value) { - this.ast.data.left = value.ast; - } - get operatorToken(): BinaryOperatorToken { - return this.ast.data.operatorToken.node; - } - set operatorToken(value) { - this.ast.data.operatorToken = value.ast; - } - get right(): Expression { - return this.ast.data.right.node; - } - set right(value) { - this.ast.data.right = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstBinaryExpressionData extends AstData { left: AstExpression = undefined!; operatorToken: AstBinaryOperatorToken = undefined!; right: AstExpression = undefined!; - cachedLiteralKind: SyntaxKind | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ cachedLiteralKind: SyntaxKind | undefined = undefined; + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { const operatorKind = this.operatorToken.kind; let transformFlags = propagateChildFlags(this.left) | propagateChildFlags(this.operatorToken) | @@ -5875,72 +2471,9 @@ export class AstBinaryExpressionData extends AstData { } } -/** @internal */ -export type AssignmentOperatorToken = Token; - -/** @internal */ -export interface AssignmentExpression extends BinaryExpression { - readonly left: LeftHandSideExpression; - readonly operatorToken: TOperator; -} - -/** @internal */ -export interface ObjectDestructuringAssignment extends AssignmentExpression { - readonly left: ObjectLiteralExpression; -} - -/** @internal */ -export interface ArrayDestructuringAssignment extends AssignmentExpression { - readonly left: ArrayLiteralExpression; -} - -/** @internal */ -export type DestructuringAssignment = - | ObjectDestructuringAssignment - | ArrayDestructuringAssignment; - -/** @internal */ export type AstDestructuringAssignment = AstNodeOneOf; -/** @internal */ -export class ConditionalExpression extends Node implements ts.ConditionalExpression { - declare readonly ast: AstConditionalExpression; - - declare _expressionBrand: any; - - get condition(): Expression { - return this.ast.data.condition.node; - } - set condition(value) { - this.ast.data.condition = value.ast; - } - get questionToken(): QuestionToken { - return this.ast.data.questionToken.node; - } - set questionToken(value) { - this.ast.data.questionToken = value.ast; - } - get whenTrue(): Expression { - return this.ast.data.whenTrue.node; - } - set whenTrue(value) { - this.ast.data.whenTrue = value.ast; - } - get colonToken(): ColonToken { - return this.ast.data.colonToken.node; - } - set colonToken(value) { - this.ast.data.colonToken = value.ast; - } - get whenFalse(): Expression { - return this.ast.data.whenFalse.node; - } - set whenFalse(value) { - this.ast.data.whenFalse = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstConditionalExpressionData extends AstData { condition: AstExpression = undefined!; questionToken: AstQuestionToken = undefined!; @@ -5948,7 +2481,7 @@ export class AstConditionalExpressionData extends AstData { colonToken: AstColonToken = undefined!; whenFalse: AstExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.condition) | propagateChildFlags(this.questionToken) | propagateChildFlags(this.whenTrue) | @@ -5957,135 +2490,10 @@ export class AstConditionalExpressionData extends AstData { } } -/** @internal */ -export type FunctionBody = Block; - -/** @internal */ export type AstFunctionBody = AstNodeOneOf; - -/** @internal */ -export type ConciseBody = - | FunctionBody - | Expression; - -/** @internal */ export type AstConciseBody = AstNodeOneOf; -/** @internal */ -export class FunctionExpression extends Node implements JSDocContainer, Declaration, LocalsContainer, FlowContainer, ts.FunctionExpression { - declare readonly ast: AstFunctionExpression; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _functionLikeDeclarationBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - declare _flowContainerBrand: any; - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get asteriskToken(): AsteriskToken | undefined { - return this.ast.data.asteriskToken?.node; - } - set asteriskToken(value) { - this.ast.data.asteriskToken = value?.ast; - } - get name(): Identifier | undefined { - return this.ast.data.name?.node; - } - set name(value) { - this.ast.data.name = value?.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - /** @internal */ get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - /** @internal */ set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get body(): Block { - return this.ast.data.body.node; - } - set body(value) { - this.ast.data.body = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } - get endFlowNode(): ts.FlowNode | undefined { - return this.ast.data.endFlowNode; - } - set endFlowNode(value) { - this.ast.data.endFlowNode = value; - } - get returnFlowNode(): ts.FlowNode | undefined { - return this.ast.data.returnFlowNode; - } - set returnFlowNode(value) { - this.ast.data.returnFlowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstFunctionExpressionData extends AstData { modifiers: AstNodeArray | undefined = undefined; asteriskToken: AstAsteriskToken | undefined = undefined; @@ -6093,19 +2501,19 @@ export class AstFunctionExpressionData extends AstData { typeParameters: AstNodeArray | undefined = undefined; parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; - body: AstFunctionBody = undefined!; - /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // Used for quick info, replaces typeParameters for instantiated signatures + body: AstFunctionBody = undefined!; // Required, whereas the member inherited from FunctionDeclaration is optional - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // Used for quick info, replaces typeParameters for instantiated signatures + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { const isAsync = modifiersToFlags(this.modifiers?.items) & ModifierFlags.Async; const isGenerator = !!this.asteriskToken; const isAsyncGenerator = isAsync && isGenerator; @@ -6125,114 +2533,7 @@ export class AstFunctionExpressionData extends AstData { } } -/** @internal */ -export type ImmediatelyInvokedFunctionExpression = CallExpression & { readonly expression: FunctionExpression; }; - -/** @internal */ -export class ArrowFunction extends Node implements JSDocContainer, Declaration, LocalsContainer, FlowContainer, ts.ArrowFunction { - declare readonly ast: AstArrowFunction; - - declare _expressionBrand: any; - declare _functionLikeDeclarationBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - declare _flowContainerBrand: any; - declare name: never; - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get equalsGreaterThanToken(): EqualsGreaterThanToken { - return this.ast.data.equalsGreaterThanToken.node; - } - set equalsGreaterThanToken(value) { - this.ast.data.equalsGreaterThanToken = value.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get body(): Block | Expression { - return this.ast.data.body.node; - } - set body(value) { - this.ast.data.body = value.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } - get endFlowNode(): ts.FlowNode | undefined { - return this.ast.data.endFlowNode; - } - set endFlowNode(value) { - this.ast.data.endFlowNode = value; - } - get returnFlowNode(): ts.FlowNode | undefined { - return this.ast.data.returnFlowNode; - } - set returnFlowNode(value) { - this.ast.data.returnFlowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstArrowFunctionData extends AstData { modifiers: AstNodeArray | undefined = undefined; equalsGreaterThanToken: AstEqualsGreaterThanToken = undefined!; @@ -6242,16 +2543,16 @@ export class AstArrowFunctionData extends AstData { body: AstConciseBody = undefined!; typeArguments: AstNodeArray | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ returnFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { const isAsync = modifiersToFlags(this.modifiers?.items) & ModifierFlags.Async; return propagateChildrenFlags(this.modifiers) | propagateChildrenFlags(this.typeParameters) | @@ -6265,817 +2566,207 @@ export class AstArrowFunctionData extends AstData { } } -/** @internal */ -export type ImmediatelyInvokedArrowFunction = CallExpression & { readonly expression: ParenthesizedExpression & { readonly expression: ArrowFunction; }; }; - -/** @internal */ -export class RegularExpressionLiteral extends Token implements ts.RegularExpressionLiteral { - declare readonly ast: AstRegularExpressionLiteral; - - declare _literalExpressionBrand: any; - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } - get isUnterminated(): boolean | undefined { - return this.ast.data.isUnterminated; - } - set isUnterminated(value) { - this.ast.data.isUnterminated = value; - } - get hasExtendedUnicodeEscape(): boolean | undefined { - return this.ast.data.hasExtendedUnicodeEscape; - } - set hasExtendedUnicodeEscape(value) { - this.ast.data.hasExtendedUnicodeEscape = value; - } -} - -/** @internal */ +// dprint-ignore export class AstRegularExpressionLiteralData extends AstTokenData { text: string = ""; isUnterminated: boolean | undefined = undefined; hasExtendedUnicodeEscape: boolean | undefined = undefined; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; } } -/** @internal */ -export class StringLiteral extends Token implements LiteralExpression, Declaration, ts.StringLiteral { - declare readonly ast: AstStringLiteral; - - declare _literalExpressionBrand: any; - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _declarationBrand: any; - - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } - get singleQuote(): boolean | undefined { - return this.ast.data.singleQuote; - } - set singleQuote(value) { - this.ast.data.singleQuote = value; - } - get isUnterminated(): boolean { - return this.ast.data.isUnterminated; - } - set isUnterminated(value) { - this.ast.data.isUnterminated = value; - } - get hasExtendedUnicodeEscape(): boolean { - return this.ast.data.hasExtendedUnicodeEscape; - } - set hasExtendedUnicodeEscape(value) { - this.ast.data.hasExtendedUnicodeEscape = value; - } - get textSourceNode(): Identifier | PrivateIdentifier | NumericLiteral | BigIntLiteral | JsxNamespacedName | StringLiteralLike | undefined { - return this.ast.data.textSourceNode?.node; - } - set textSourceNode(value) { - this.ast.data.textSourceNode = value?.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstStringLiteralData extends AstTokenData { text: string = ""; singleQuote: boolean | undefined = undefined; isUnterminated: boolean = false; - hasExtendedUnicodeEscape: boolean = false; - - textSourceNode?: AstNode | undefined; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - - override computeTransformFlags(_: AstNode): TransformFlags { - return this.hasExtendedUnicodeEscape ? TransformFlags.ContainsES2015 : TransformFlags.None; - } -} - -/** @internal */ -export class NoSubstitutionTemplateLiteral extends Token implements Declaration, ts.NoSubstitutionTemplateLiteral { - declare readonly ast: AstNoSubstitutionTemplateLiteral; - - declare _literalExpressionBrand: any; - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _declarationBrand: any; - - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } - get rawText(): string | undefined { - return this.ast.data.rawText; - } - set rawText(value) { - this.ast.data.rawText = value; - } - get isUnterminated(): boolean | undefined { - return this.ast.data.isUnterminated; - } - set isUnterminated(value) { - this.ast.data.isUnterminated = value; - } - get hasExtendedUnicodeEscape(): boolean | undefined { - return this.ast.data.hasExtendedUnicodeEscape; - } - set hasExtendedUnicodeEscape(value) { - this.ast.data.hasExtendedUnicodeEscape = value; - } - get templateFlags(): ts.TokenFlags { - return this.ast.data.templateFlags; - } - set templateFlags(value) { - this.ast.data.templateFlags = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ -export class AstNoSubstitutionTemplateLiteralData extends AstTokenData { - text: string = ""; - rawText: string | undefined = undefined; - isUnterminated: boolean | undefined = undefined; - hasExtendedUnicodeEscape: boolean | undefined = undefined; - templateFlags: ts.TokenFlags = TokenFlags.None; - - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - - override computeTransformFlags(_: AstNode): TransformFlags { - return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); - } -} - -/** @internal */ -export type PseudoLiteralToken = - | TemplateHead - | TemplateMiddle - | TemplateTail; - -/** @internal */ -export type AstPseudoLiteralToken = AstNodeOneOf; - -/** @internal */ -export type TemplateLiteralToken = - | NoSubstitutionTemplateLiteral - | PseudoLiteralToken; - -/** @internal */ -export type AstTemplateLiteralToken = AstNodeOneOf; - -/** @internal */ -export type StringLiteralLike = - | StringLiteral - | NoSubstitutionTemplateLiteral; - -/** @internal */ -export type AstStringLiteralLike = AstNodeOneOf; - -/** @internal */ -export class NumericLiteral extends Token implements Declaration, ts.NumericLiteral { - declare readonly ast: AstNumericLiteral; + hasExtendedUnicodeEscape: boolean = false; - declare _literalExpressionBrand: any; - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _declarationBrand: any; + /** @internal */ textSourceNode?: AstNode | undefined; + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } - get numericLiteralFlags(): ts.TokenFlags { - return this.ast.data.numericLiteralFlags; - } - set numericLiteralFlags(value) { - this.ast.data.numericLiteralFlags = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return this.hasExtendedUnicodeEscape ? TransformFlags.ContainsES2015 : TransformFlags.None; } } -/** @internal */ -export class AstNumericLiteralData extends AstTokenData { +// dprint-ignore +export class AstNoSubstitutionTemplateLiteralData extends AstTokenData { text: string = ""; - numericLiteralFlags: ts.TokenFlags = TokenFlags.None; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + rawText: string | undefined = undefined; + isUnterminated: boolean | undefined = undefined; + hasExtendedUnicodeEscape: boolean | undefined = undefined; - override computeTransformFlags(_: AstNode): TransformFlags { - return this.numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier ? TransformFlags.ContainsES2015 : TransformFlags.None; + /** @internal */ templateFlags: TokenFlags = TokenFlags.None; + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); } } -/** @internal */ -export class BigIntLiteral extends Token implements ts.BigIntLiteral { - declare readonly ast: AstBigIntLiteral; +export type AstPseudoLiteralToken = AstNodeOneOf; +export type AstTemplateLiteralToken = AstNodeOneOf; +export type AstStringLiteralLike = AstNodeOneOf; + +// dprint-ignore +export class AstNumericLiteralData extends AstTokenData { + text: string = ""; - declare _literalExpressionBrand: any; - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; + /** @internal */ numericLiteralFlags: TokenFlags = TokenFlags.None; + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return this.numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier ? TransformFlags.ContainsES2015 : TransformFlags.None; } } -/** @internal */ +// dprint-ignore export class AstBigIntLiteralData extends AstTokenData { text: string = ""; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsES2020; } } -/** @internal */ -export type LiteralToken = - | NumericLiteral - | BigIntLiteral - | StringLiteral - | JsxText - | RegularExpressionLiteral - | NoSubstitutionTemplateLiteral; - -/** @internal */ export type AstLiteralToken = AstNodeOneOf; -/** @internal */ -export class TemplateHead extends Token implements ts.TemplateHead { - declare readonly ast: AstTemplateHead; - - override get parent() { - return super.parent as TemplateExpression | TemplateLiteralTypeNode; - } - override set parent(value) { - super.parent = value; - } - - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } - get isUnterminated(): boolean | undefined { - return this.ast.data.isUnterminated; - } - set isUnterminated(value) { - this.ast.data.isUnterminated = value; - } - get hasExtendedUnicodeEscape(): boolean | undefined { - return this.ast.data.hasExtendedUnicodeEscape; - } - set hasExtendedUnicodeEscape(value) { - this.ast.data.hasExtendedUnicodeEscape = value; - } - get rawText(): string | undefined { - return this.ast.data.rawText; - } - set rawText(value) { - this.ast.data.rawText = value; - } - get templateFlags(): ts.TokenFlags { - return this.ast.data.templateFlags; - } - set templateFlags(value) { - this.ast.data.templateFlags = value; - } -} - -/** @internal */ +// dprint-ignore export class AstTemplateHeadData extends AstTokenData { text = ""; isUnterminated: boolean | undefined = undefined; hasExtendedUnicodeEscape: boolean | undefined = undefined; rawText: string | undefined = undefined; - templateFlags: ts.TokenFlags = TokenFlags.None; - - override computeTransformFlags(_: AstNode): TransformFlags { - return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); - } -} - -/** @internal */ -export class TemplateMiddle extends Token implements ts.TemplateMiddle { - declare readonly ast: AstTemplateMiddle; - override get parent() { - return super.parent as TemplateSpan | TemplateLiteralTypeSpan; - } - override set parent(value) { - super.parent = value; - } + /** @internal */ templateFlags: TokenFlags = TokenFlags.None; - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } - get isUnterminated(): boolean | undefined { - return this.ast.data.isUnterminated; - } - set isUnterminated(value) { - this.ast.data.isUnterminated = value; - } - get hasExtendedUnicodeEscape(): boolean | undefined { - return this.ast.data.hasExtendedUnicodeEscape; - } - set hasExtendedUnicodeEscape(value) { - this.ast.data.hasExtendedUnicodeEscape = value; - } - get rawText(): string | undefined { - return this.ast.data.rawText; - } - set rawText(value) { - this.ast.data.rawText = value; - } - get templateFlags(): ts.TokenFlags { - return this.ast.data.templateFlags; - } - set templateFlags(value) { - this.ast.data.templateFlags = value; + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); } } -/** @internal */ +// dprint-ignore export class AstTemplateMiddleData extends AstTokenData { text = ""; isUnterminated: boolean | undefined = undefined; hasExtendedUnicodeEscape: boolean | undefined = undefined; rawText: string | undefined = undefined; - templateFlags: ts.TokenFlags = TokenFlags.None; - - override computeTransformFlags(_: AstNode): TransformFlags { - return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); - } -} -/** @internal */ -export class TemplateTail extends Token implements ts.TemplateTail { - declare readonly ast: AstTemplateTail; - - override get parent() { - return super.parent as TemplateSpan | TemplateLiteralTypeSpan; - } - override set parent(value) { - super.parent = value; - } + /** @internal */ templateFlags: TokenFlags = TokenFlags.None; - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } - get isUnterminated(): boolean | undefined { - return this.ast.data.isUnterminated; - } - set isUnterminated(value) { - this.ast.data.isUnterminated = value; - } - get hasExtendedUnicodeEscape(): boolean | undefined { - return this.ast.data.hasExtendedUnicodeEscape; - } - set hasExtendedUnicodeEscape(value) { - this.ast.data.hasExtendedUnicodeEscape = value; - } - get rawText(): string | undefined { - return this.ast.data.rawText; - } - set rawText(value) { - this.ast.data.rawText = value; - } - get templateFlags(): ts.TokenFlags { - return this.ast.data.templateFlags; - } - set templateFlags(value) { - this.ast.data.templateFlags = value; + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); } } -/** @internal */ +// dprint-ignore export class AstTemplateTailData extends AstTokenData { text = ""; isUnterminated: boolean | undefined = undefined; hasExtendedUnicodeEscape: boolean | undefined = undefined; rawText: string | undefined = undefined; - templateFlags: ts.TokenFlags = TokenFlags.None; - - override computeTransformFlags(_: AstNode): TransformFlags { - return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); - } -} - -/** @internal */ -export class TemplateExpression extends Node implements ts.TemplateExpression { - declare readonly ast: AstTemplateExpression; - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; + /** @internal */ templateFlags: TokenFlags = TokenFlags.None; - get head(): TemplateHead { - return this.ast.data.head.node; - } - set head(value) { - this.ast.data.head = value.ast; - } - get templateSpans(): NodeArray { - return this.ast.data.templateSpans.nodes; - } - set templateSpans(value) { - this.ast.data.templateSpans = value.ast; + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); } } -/** @internal */ +// dprint-ignore export class AstTemplateExpressionData extends AstData { head: AstTemplateHead = undefined!; templateSpans: AstNodeArray = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.head) | propagateChildrenFlags(this.templateSpans) | TransformFlags.ContainsES2015; } } -/** @internal */ -export class TemplateSpan extends Node implements ts.TemplateSpan { - declare readonly ast: AstTemplateSpan; - - override get parent() { - return super.parent as TemplateExpression; - } - override set parent(value) { - super.parent = value; - } - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get literal(): TemplateMiddle | TemplateTail { - return this.ast.data.literal.node; - } - set literal(value) { - this.ast.data.literal = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstTemplateSpanData extends AstData { expression: AstExpression = undefined!; literal: AstTemplateMiddle | AstTemplateTail = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | propagateChildFlags(this.literal) | TransformFlags.ContainsES2015; } } -/** @internal */ -export class ParenthesizedExpression extends Node implements JSDocContainer, ts.ParenthesizedExpression { - declare readonly ast: AstParenthesizedExpression; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _jsdocContainerBrand: any; - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } -} - -/** @internal */ +// dprint-ignore export class AstParenthesizedExpressionData extends AstData { expression: AstExpression = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression); } } -/** @internal */ -export interface JSDocTypeAssertion extends ParenthesizedExpression { - readonly ast: AstJSDocTypeAssertion; - readonly _jsDocTypeAssertionBrand: never; -} - /** @internal */ export type AstJSDocTypeAssertion = AstNode; -/** @internal */ -export class ArrayLiteralExpression extends Node implements ts.ArrayLiteralExpression { - declare readonly ast: AstArrayLiteralExpression; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get elements(): NodeArray { - return this.ast.data.elements.nodes; - } - set elements(value: NodeArray) { - this.ast.data.elements = value.ast; - } - get multiLine(): boolean | undefined { - return this.ast.data.multiLine; - } - set multiLine(value) { - this.ast.data.multiLine = value; - } -} - -/** @internal */ +// dprint-ignore export class AstArrayLiteralExpressionData extends AstData { elements: AstNodeArray = undefined!; - multiLine: boolean | undefined = undefined; - - override computeTransformFlags(_: AstNode): TransformFlags { - return propagateChildrenFlags(this.elements); - } -} - -/** @internal */ -export class SpreadElement extends Node implements ts.SpreadElement { - declare readonly ast: AstSpreadElement; - declare _expressionBrand: any; + /** @internal */ multiLine: boolean | undefined = undefined; - override get parent() { - return super.parent as ArrayLiteralExpression | CallExpression | NewExpression; - } - override set parent(value) { - super.parent = value; - } - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildrenFlags(this.elements); } } -/** @internal */ +// dprint-ignore export class AstSpreadElementData extends AstData { expression: AstExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | TransformFlags.ContainsES2015 | TransformFlags.ContainsRestOrSpread; } } -/** @internal */ -export interface ObjectLiteralElement extends Declaration { - /** @internal */ readonly ast: AstObjectLiteralElement; - _objectLiteralBrand: any; -} - -/** @internal */ export type AstObjectLiteralElement = AstNode; - -/** @internal */ -export type ObjectLiteralElementLike = - | PropertyAssignment - | ShorthandPropertyAssignment - | SpreadAssignment - | MethodDeclaration - | AccessorDeclaration; - -/** @internal */ export type AstObjectLiteralElementLike = AstNodeOneOf; -/** @internal */ -export class ObjectLiteralExpression extends Node implements JSDocContainer, Declaration, ts.ObjectLiteralExpression { - declare readonly ast: AstObjectLiteralExpression; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - get properties(): NodeArray { - return this.ast.data.properties.nodes; - } - set properties(value) { - this.ast.data.properties = value.ast; - } - get multiLine(): boolean | undefined { - return this.ast.data.multiLine; - } - set multiLine(value) { - this.ast.data.multiLine = value; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstObjectLiteralExpressionData extends AstData { properties: AstNodeArray = undefined!; - multiLine: boolean | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ multiLine: boolean | undefined = undefined; + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.properties); } } -/** @internal */ -export class PropertyAccessExpression extends Node implements JSDocContainer, Declaration, FlowContainer, ts.PropertyAccessExpression { - declare readonly ast: AstPropertyAccessExpression; - - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get expression(): LeftHandSideExpression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get questionDotToken(): QuestionDotToken | undefined { - return this.ast.data.questionDotToken?.node; - } - set questionDotToken(value) { - this.ast.data.questionDotToken = value?.ast; - } - get name(): Identifier | PrivateIdentifier { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstPropertyAccessExpressionData extends AstData { expression: AstLeftHandSideExpression = undefined!; questionDotToken: AstQuestionDotToken | undefined = undefined; name: AstMemberName = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(node: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(node: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.expression) | propagateChildFlags(this.questionDotToken) | (this.name.kind === SyntaxKind.Identifier ? @@ -7094,120 +2785,31 @@ export class AstPropertyAccessExpressionData extends AstData { } } -/** @internal */ -export interface PropertyAccessEntityNameExpression extends PropertyAccessExpression { - _propertyAccessExpressionLikeQualifiedNameBrand?: any; - readonly ast: AstPropertyAccessEntityNameExpression; - readonly data: AstPropertyAccessEntityNameExpressionData; - readonly expression: EntityNameExpression; - readonly name: Identifier; -} - -/** @internal */ export type AstPropertyAccessEntityNameExpression = AstNode; -/** @internal */ export interface AstPropertyAccessEntityNameExpressionData extends AstPropertyAccessExpressionData { expression: AstEntityNameExpression; name: AstIdentifier; } -/** @internal */ -export type EntityNameExpression = - | Identifier - | PropertyAccessEntityNameExpression; -/** @internal */ export type AstEntityNameExpression = AstNodeOneOf; - -/** @internal */ -export interface PropertyAccessChain extends PropertyAccessExpression { - _optionalChainBrand: any; - readonly ast: AstPropertyAccessChain; - readonly name: MemberName; -} - -/** @internal */ export type AstPropertyAccessChain = AstNode; - -/** @internal */ -export interface PropertyAccessChainRoot extends PropertyAccessChain { - readonly questionDotToken: QuestionDotToken; -} - /** @internal */ export type AstPropertyAccessChainRoot = AstNode; -/** @internal */ -export class ElementAccessExpression extends Node implements JSDocContainer, Declaration, FlowContainer, ts.ElementAccessExpression { - declare readonly ast: AstElementAccessExpression; - - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get expression(): LeftHandSideExpression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get questionDotToken(): QuestionDotToken | undefined { - return this.ast.data.questionDotToken?.node; - } - set questionDotToken(value) { - this.ast.data.questionDotToken = value?.ast; - } - get argumentExpression(): Expression { - return this.ast.data.argumentExpression.node; - } - set argumentExpression(value) { - this.ast.data.argumentExpression = value.ast; - } - - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstElementAccessExpressionData extends AstData { expression: AstLeftHandSideExpression = undefined!; questionDotToken: AstQuestionDotToken | undefined = undefined; argumentExpression: AstExpression = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(node: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(node: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.expression) | propagateChildFlags(this.questionDotToken) | propagateChildFlags(this.argumentExpression); @@ -7224,82 +2826,21 @@ export class AstElementAccessExpressionData extends AstData { } } -/** @internal */ -export interface ElementAccessChain extends ElementAccessExpression { - readonly ast: AstElementAccessChain; - _optionalChainBrand: any; -} - -/** @internal */ export type AstElementAccessChain = AstNode; - -/** @internal */ -export interface ElementAccessChainRoot extends ElementAccessChain { - readonly questionDotToken: QuestionDotToken; -} - -/** @internal */ -export type AstElementAccessChainRoot = AstNode; - -/** @internal */ -export class CallExpression extends Node implements Declaration, ts.CallExpression { - declare readonly ast: AstCallExpression; - - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _declarationBrand: any; - - get expression(): LeftHandSideExpression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get questionDotToken(): QuestionDotToken | undefined { - return this.ast.data.questionDotToken?.node; - } - set questionDotToken(value) { - this.ast.data.questionDotToken = value?.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get arguments(): NodeArray { - return this.ast.data.arguments.nodes; - } - set arguments(value) { - this.ast.data.arguments = value.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - /** @internal */ +export type AstElementAccessChainRoot = AstNode; + +// dprint-ignore export class AstCallExpressionData extends AstData { expression: AstLeftHandSideExpression = undefined!; questionDotToken: AstQuestionDotToken | undefined = undefined; typeArguments: AstNodeArray | undefined = undefined; arguments: AstNodeArray = undefined!; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(node: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(node: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.expression) | propagateChildFlags(this.questionDotToken) | propagateChildrenFlags(this.typeArguments) | @@ -7324,123 +2865,34 @@ export class AstCallExpressionData extends AstData { } } -/** @internal */ -export interface CallChain extends CallExpression { - readonly ast: AstCallChain; - _optionalChainBrand: any; -} - -/** @internal */ export type AstCallChain = AstNode; - -/** @internal */ -export interface CallChainRoot extends CallChain { - readonly questionDotToken: QuestionDotToken; -} - /** @internal */ export type AstCallChainRoot = AstNode; - -/** @internal */ -export type OptionalChainRoot = - | PropertyAccessChainRoot - | ElementAccessChainRoot - | CallChainRoot; - /** @internal */ export type AstOptionalChainRoot = AstNodeOneOf; -/** @internal */ -export class ExpressionWithTypeArguments extends Node implements ts.ExpressionWithTypeArguments { - declare readonly ast: AstExpressionWithTypeArguments; - - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _typeNodeBrand: any; - - get expression(): LeftHandSideExpression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstExpressionWithTypeArgumentsData extends AstData { expression: AstLeftHandSideExpression = undefined!; typeArguments: AstNodeArray | undefined = undefined; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | propagateChildrenFlags(this.typeArguments) | TransformFlags.ContainsES2015; } } -/** @internal */ -export class NewExpression extends Node implements Declaration, ts.NewExpression { - declare readonly ast: AstNewExpression; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _declarationBrand: any; - - get expression(): LeftHandSideExpression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get arguments(): NodeArray | undefined { - return this.ast.data.arguments?.nodes; - } - set arguments(value) { - this.ast.data.arguments = value?.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstNewExpressionData extends AstData { expression: AstLeftHandSideExpression = undefined!; typeArguments: AstNodeArray | undefined = undefined; arguments: AstNodeArray | undefined = undefined; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.expression) | propagateChildrenFlags(this.typeArguments) | propagateChildrenFlags(this.arguments) | @@ -7452,58 +2904,16 @@ export class AstNewExpressionData extends AstData { } } -/** @internal */ -export type TemplateLiteral = - | TemplateExpression - | NoSubstitutionTemplateLiteral; - -/** @internal */ export type AstTemplateLiteral = AstNodeOneOf; -/** @internal */ -export class TaggedTemplateExpression extends Node implements ts.TaggedTemplateExpression { - declare readonly ast: AstTaggedTemplateExpression; - - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get tag(): LeftHandSideExpression { - return this.ast.data.tag.node; - } - set tag(value) { - this.ast.data.tag = value.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get template(): NoSubstitutionTemplateLiteral | TemplateExpression { - return this.ast.data.template.node; - } - set template(value) { - this.ast.data.template = value.ast; - } - get questionDotToken(): QuestionDotToken | undefined { - return this.ast.data.questionDotToken?.node; - } - set questionDotToken(value) { - this.ast.data.questionDotToken = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstTaggedTemplateExpressionData extends AstData { tag: AstLeftHandSideExpression = undefined!; typeArguments: AstNodeArray | undefined = undefined; template: AstTemplateLiteral = undefined!; questionDotToken: AstQuestionDotToken | undefined = undefined; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.tag) | propagateChildrenFlags(this.typeArguments) | propagateChildFlags(this.template) | @@ -7518,179 +2928,62 @@ export class AstTaggedTemplateExpressionData extends AstData { } } -/** @internal */ -export class AsExpression extends Node implements ts.AsExpression { - declare readonly ast: AstAsExpression; - - declare _expressionBrand: any; - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstAsExpressionData extends AstData { expression: AstExpression = undefined!; type: AstTypeNode = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | propagateChildFlags(this.type) | TransformFlags.ContainsTypeScript; } } -/** @internal */ -export class TypeAssertion extends Node implements ts.TypeAssertion { - declare readonly ast: AstTypeAssertion; - - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } - get expression(): UnaryExpression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstTypeAssertionData extends AstData { type: AstTypeNode = undefined!; expression: AstUnaryExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | propagateChildFlags(this.type) | TransformFlags.ContainsTypeScript; } } -/** @internal */ -export class SatisfiesExpression extends Node implements ts.SatisfiesExpression { - declare readonly ast: AstSatisfiesExpression; - - declare _expressionBrand: any; - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstSatisfiesExpressionData extends AstData { expression: AstExpression = undefined!; type: AstTypeNode = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | propagateChildFlags(this.type) | TransformFlags.ContainsTypeScript; } } -/** @internal */ -export class NonNullExpression extends Node implements ts.NonNullExpression { - declare readonly ast: AstNonNullExpression; - - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value: Expression) { - this.ast.data.expression = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstNonNullExpressionData extends AstData { expression: AstExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | TransformFlags.ContainsTypeScript; } } -/** @internal */ -export interface NonNullChain extends NonNullExpression { - readonly ast: AstNonNullChain; - _optionalChainBrand: any; -} - -/** @internal */ export type AstNonNullChain = AstNode; -/** @internal */ -export class MetaProperty extends Node implements FlowContainer, ts.MetaProperty { - declare readonly ast: AstMetaProperty; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _flowContainerBrand: any; - - get keywordToken(): SyntaxKind.ImportKeyword | SyntaxKind.NewKeyword { - return this.ast.data.keywordToken; - } - set keywordToken(value: SyntaxKind.ImportKeyword | SyntaxKind.NewKeyword) { - this.ast.data.keywordToken = value; - } - get name(): Identifier { - return this.ast.data.name.node; - } - set name(value: Identifier) { - this.ast.data.name = value.ast; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstMetaPropertyData extends AstData { keywordToken: SyntaxKind.NewKeyword | SyntaxKind.ImportKeyword = undefined!; name: AstIdentifier = undefined!; - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.name); switch (this.keywordToken) { case SyntaxKind.NewKeyword: @@ -7706,44 +2999,13 @@ export class AstMetaPropertyData extends AstData { } } -/** @internal */ -export class JsxElement extends Node implements ts.JsxElement { - declare readonly ast: AstJsxElement; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get openingElement(): JsxOpeningElement { - return this.ast.data.openingElement.node; - } - set openingElement(value: JsxOpeningElement) { - this.ast.data.openingElement = value.ast; - } - get children(): NodeArray { - return this.ast.data.children.nodes; - } - set children(value: NodeArray) { - this.ast.data.children = value.ast; - } - get closingElement(): JsxClosingElement { - return this.ast.data.closingElement.node; - } - set closingElement(value: JsxClosingElement) { - this.ast.data.closingElement = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJsxElementData extends AstData { openingElement: AstJsxOpeningElement = undefined!; children: AstNodeArray = undefined!; closingElement: AstJsxClosingElement = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.openingElement) | propagateChildrenFlags(this.children) | propagateChildFlags(this.closingElement) | @@ -7751,177 +3013,48 @@ export class AstJsxElementData extends AstData { } } -/** @internal */ -export type JsxOpeningLikeElement = - | JsxSelfClosingElement - | JsxOpeningElement; - -/** @internal */ export type AstJsxOpeningLikeElement = AstNodeOneOf; - -/** @internal */ -export type JsxAttributeLike = - | JsxAttribute - | JsxSpreadAttribute; - -/** @internal */ export type AstJsxAttributeLike = AstNodeOneOf; - -/** @internal */ -export type JsxAttributeName = - | Identifier - | JsxNamespacedName; - -/** @internal */ export type AstJsxAttributeName = AstNodeOneOf; - -/** @internal */ -export type JsxTagNameExpression = - | Identifier - | ThisExpression - | JsxTagNamePropertyAccess - | JsxNamespacedName; - -/** @internal */ export type AstJsxTagNameExpression = AstNodeOneOf; - -/** @internal */ -export interface JsxTagNamePropertyAccess extends PropertyAccessExpression { - readonly ast: AstJsxTagNamePropertyAccess; - readonly data: AstJsxTagNamePropertyAccessData; - readonly expression: Identifier | ThisExpression | JsxTagNamePropertyAccess; -} - -/** @internal */ export type AstJsxTagNamePropertyAccess = AstNode; -/** @internal */ export interface AstJsxTagNamePropertyAccessData extends AstPropertyAccessExpressionData { expression: AstIdentifier | AstThisExpression | AstJsxTagNamePropertyAccess; } -/** @internal */ -export class JsxAttributes extends Node implements Declaration, ts.JsxAttributes { - declare readonly ast: AstJsxAttributes; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - declare _declarationBrand: any; - - override get parent() { - return super.parent as JsxOpeningLikeElement; - } - override set parent(value) { - super.parent = value; - } - - get properties(): NodeArray { - return this.ast.data.properties.nodes; - } - set properties(value) { - this.ast.data.properties = value.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstJsxAttributesData extends AstData { properties: AstNodeArray = undefined!; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.properties) | TransformFlags.ContainsJsx; } } -/** @internal */ -export class JsxNamespacedName extends Node implements ts.JsxNamespacedName { - declare readonly ast: AstJsxNamespacedName; - - get name(): Identifier { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get namespace(): Identifier { - return this.ast.data.namespace.node; - } - set namespace(value) { - this.ast.data.namespace = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJsxNamespacedNameData extends AstData { name: AstIdentifier = undefined!; namespace: AstIdentifier = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.namespace) | propagateChildFlags(this.name) | TransformFlags.ContainsJsx; } } -/** @internal */ -export class JsxOpeningElement extends Node implements ts.JsxOpeningElement { - declare readonly ast: AstJsxOpeningElement; - - declare _expressionBrand: any; - - override get parent() { - return super.parent as JsxElement; - } - override set parent(value) { - super.parent = value; - } - - get tagName(): JsxTagNameExpression { - return this.ast.data.tagName.node; - } - set tagName(value) { - this.ast.data.tagName = value.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get attributes(): JsxAttributes { - return this.ast.data.attributes.node; - } - set attributes(value) { - this.ast.data.attributes = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJsxOpeningElementData extends AstData { tagName: AstJsxTagNameExpression = undefined!; typeArguments: AstNodeArray | undefined = undefined; attributes: AstJsxAttributes = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.tagName) | propagateChildrenFlags(this.typeArguments) | propagateChildFlags(this.attributes) | @@ -7933,73 +3066,23 @@ export class AstJsxOpeningElementData extends AstData { } } -/** @internal */ -export class JsxClosingElement extends Node implements ts.JsxClosingElement { - declare readonly ast: AstJsxClosingElement; - - override get parent() { - return super.parent as JsxElement; - } - override set parent(value) { - super.parent = value; - } - - get tagName(): JsxTagNameExpression { - return this.ast.data.tagName.node; - } - set tagName(value) { - this.ast.data.tagName = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJsxClosingElementData extends AstData { tagName: AstJsxTagNameExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.tagName) | TransformFlags.ContainsJsx; } } -/** @internal */ -export class JsxSelfClosingElement extends Node implements ts.JsxSelfClosingElement { - declare readonly ast: AstJsxSelfClosingElement; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get tagName(): JsxTagNameExpression { - return this.ast.data.tagName.node; - } - set tagName(value) { - this.ast.data.tagName = value.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get attributes(): JsxAttributes { - return this.ast.data.attributes.node; - } - set attributes(value) { - this.ast.data.attributes = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJsxSelfClosingElementData extends AstData { tagName: AstJsxTagNameExpression = undefined!; typeArguments: AstNodeArray | undefined = undefined; attributes: AstJsxAttributes = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.tagName) | propagateChildrenFlags(this.typeArguments) | propagateChildFlags(this.attributes) | @@ -8011,514 +3094,144 @@ export class AstJsxSelfClosingElementData extends AstData { } } -/** @internal */ -export class JsxFragment extends Node implements ts.JsxFragment { - declare readonly ast: AstJsxFragment; - - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get openingFragment(): JsxOpeningFragment { - return this.ast.data.openingFragment.node; - } - set openingFragment(value: JsxOpeningFragment) { - this.ast.data.openingFragment = value.ast; - } - get children(): NodeArray { - return this.ast.data.children.nodes; - } - set children(value: NodeArray) { - this.ast.data.children = value.ast; - } - get closingFragment(): JsxClosingFragment { - return this.ast.data.closingFragment.node; - } - set closingFragment(value: JsxClosingFragment) { - this.ast.data.closingFragment = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJsxFragmentData extends AstData { openingFragment: AstJsxOpeningFragment = undefined!; children: AstNodeArray = undefined!; closingFragment: AstJsxClosingFragment = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.openingFragment) | propagateChildrenFlags(this.children) | propagateChildFlags(this.closingFragment) | TransformFlags.ContainsJsx; } -} - -/** @internal */ -export class JsxOpeningFragment extends Node implements ts.JsxOpeningFragment { - declare readonly ast: AstJsxOpeningFragment; - - declare _expressionBrand: any; // TODO: is this accurate? - - override get parent() { - return super.parent as JsxFragment; - } - override set parent(value) { - super.parent = value; - } -} - -/** @internal */ -export class AstJsxOpeningFragmentData extends AstData { - override computeTransformFlags(_: AstNode): TransformFlags { - return TransformFlags.ContainsJsx; - } -} - -/** @internal */ -export class JsxClosingFragment extends Node implements ts.JsxClosingFragment { - declare readonly ast: AstJsxClosingFragment; - - declare _expressionBrand: any; // TODO: is this accurate? - - override get parent() { - return super.parent as JsxFragment; - } - override set parent(value) { - super.parent = value; - } -} - -/** @internal */ -export class AstJsxClosingFragmentData extends AstData { - override computeTransformFlags(_: AstNode): TransformFlags { - return TransformFlags.ContainsJsx; - } -} - -/** @internal */ -export class JsxAttribute extends Node implements Declaration, ts.JsxAttribute { - declare readonly ast: AstJsxAttribute; - - declare _declarationBrand: any; - - override get parent() { - return super.parent as JsxAttributes; - } - override set parent(value) { - super.parent = value; - } - - get name(): JsxAttributeName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get initializer(): JsxAttributeValue | undefined { - return this.ast.data.initializer?.node; - } - set initializer(value) { - this.ast.data.initializer = value?.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; +} + +// dprint-ignore +export class AstJsxOpeningFragmentData extends AstData { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.ContainsJsx; } - set localSymbol(value) { - this.ast.data.localSymbol = value; +} + +// dprint-ignore +export class AstJsxClosingFragmentData extends AstData { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return TransformFlags.ContainsJsx; } } -/** @internal */ +// dprint-ignore export class AstJsxAttributeData extends AstData { name: AstJsxAttributeName = undefined!; initializer: AstJsxAttributeValue | undefined = undefined; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.name) | propagateChildFlags(this.initializer) | TransformFlags.ContainsJsx; } } -/** @internal */ -export type JsxAttributeValue = - | StringLiteral - | JsxExpression - | JsxElement - | JsxSelfClosingElement - | JsxFragment; - -/** @internal */ export type AstJsxAttributeValue = AstNodeOneOf; -/** @internal */ -export class JsxSpreadAttribute extends Node implements ts.JsxSpreadAttribute { - declare readonly ast: AstJsxSpreadAttribute; - - declare _objectLiteralBrand: any; - declare _declarationBrand: any; - declare symbol: never; - declare localSymbol: never; - - override get parent() { - return super.parent as JsxAttributes; - } - override set parent(value) { - super.parent = value; - } - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJsxSpreadAttributeData extends AstData { expression: AstExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | TransformFlags.ContainsJsx; } } -/** @internal */ -export class JsxExpression extends Node implements ts.JsxExpression { - declare readonly ast: AstJsxExpression; - - declare _expressionBrand: any; // TODO: is this accurate? - - override get parent() { - return super.parent as JsxElement | JsxFragment | JsxAttributeLike; - } - override set parent(value) { - super.parent = value; - } - - get dotDotDotToken(): DotDotDotToken | undefined { - return this.ast.data.dotDotDotToken?.node; - } - set dotDotDotToken(value) { - this.ast.data.dotDotDotToken = value?.ast; - } - get expression(): Expression | undefined { - return this.ast.data.expression?.node; - } - set expression(value) { - this.ast.data.expression = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJsxExpressionData extends AstData { dotDotDotToken: AstDotDotDotToken | undefined = undefined; expression: AstExpression | undefined = undefined; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.dotDotDotToken) | propagateChildFlags(this.expression) | TransformFlags.ContainsJsx; } } -/** @internal */ -export class JsxText extends Token implements ts.JsxText, LiteralLikeNode { - declare readonly ast: AstJsxText; - - override get parent() { - return super.parent as JsxElement | JsxFragment; - } - override set parent(value) { - super.parent = value; - } - - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } - get isUnterminated(): boolean | undefined { - return this.ast.data.isUnterminated; - } - set isUnterminated(value) { - this.ast.data.isUnterminated = value; - } - get hasExtendedUnicodeEscape(): boolean | undefined { - return this.ast.data.hasExtendedUnicodeEscape; - } - set hasExtendedUnicodeEscape(value) { - this.ast.data.hasExtendedUnicodeEscape = value; - } - get containsOnlyTriviaWhiteSpaces(): boolean { - return this.ast.data.containsOnlyTriviaWhiteSpaces; - } - set containsOnlyTriviaWhiteSpaces(value) { - this.ast.data.containsOnlyTriviaWhiteSpaces = value; - } -} - -/** @internal */ +// dprint-ignore export class AstJsxTextData extends AstData { text = ""; isUnterminated: boolean | undefined = undefined; hasExtendedUnicodeEscape: boolean | undefined = undefined; containsOnlyTriviaWhiteSpaces: boolean = false; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsJsx; } } -/** @internal */ -export type JsxChild = - | JsxText - | JsxExpression - | JsxElement - | JsxSelfClosingElement - | JsxFragment; - -/** @internal */ export type AstJsxChild = AstNodeOneOf; - -/** @internal */ -export type IterationStatement = - | DoStatement - | WhileStatement - | ForStatement - | ForInOrOfStatement; - -/** @internal */ export type AstIterationStatement = AstNodeOneOf; -/** @internal */ -export class EmptyStatement extends Node implements JSDocContainer, ts.EmptyStatement { - declare readonly ast: AstEmptyStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } -} - -/** @internal */ +// dprint-ignore export class AstEmptyStatementData extends AstData { - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; } } -/** @internal */ -export class DebuggerStatement extends Node implements JSDocContainer, FlowContainer, ts.DebuggerStatement { - declare readonly ast: AstDebuggerStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstDebuggerStatementData extends AstData { - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; } } -/** @internal */ -export class MissingDeclaration extends Node implements JSDocContainer, Declaration, ts.MissingDeclaration { - declare readonly ast: AstMissingDeclaration; - - declare _declarationBrand: any; - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get name(): Identifier | undefined { - return this.ast.data.name?.node; - } - set name(value) { - this.ast.data.name = value?.ast; - } - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstMissingDeclarationData extends AstData { name: AstIdentifier | undefined = undefined; modifiers: AstNodeArray | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; } } -/** @internal */ -export class Block extends Node implements JSDocContainer, LocalsContainer, ts.Block { - declare readonly ast: AstBlock; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - - get statements(): NodeArray { - return this.ast.data.statements.nodes; - } - set statements(value) { - this.ast.data.statements = value.ast; - } - get multiLine(): boolean | undefined { - return this.ast.data.multiLine; - } - set multiLine(value) { - this.ast.data.multiLine = value; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstBlockData extends AstData { statements: AstNodeArray = undefined!; - multiLine: boolean | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; + /** @internal */ multiLine: boolean | undefined = undefined; + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.statements); } } -/** @internal */ -export class VariableStatement extends Node implements JSDocContainer, FlowContainer, ts.VariableStatement { - declare readonly ast: AstVariableStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get declarationList(): VariableDeclarationList { - return this.ast.data.declarationList.node; - } - set declarationList(value) { - this.ast.data.declarationList = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstVariableStatementData extends AstData { modifiers: AstNodeArray | undefined = undefined; declarationList: AstVariableDeclarationList = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildrenFlags(this.modifiers) | propagateChildFlags(this.declarationList); if (modifiersToFlags(this.modifiers?.items) & ModifierFlags.Ambient) { @@ -8528,281 +3241,77 @@ export class AstVariableStatementData extends AstData { } } -/** @internal */ -export class ExpressionStatement extends Node implements JSDocContainer, FlowContainer, ts.ExpressionStatement { - declare readonly ast: AstExpressionStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstExpressionStatementData extends AstData { expression: AstExpression = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - - override computeTransformFlags(_: AstNode): TransformFlags { - return propagateChildFlags(this.expression); - } -} - -/** @internal */ -export interface PrologueDirective extends ExpressionStatement { - readonly expression: StringLiteral; -} - -/** @internal */ -export class IfStatement extends Node implements JSDocContainer, FlowContainer, ts.IfStatement { - declare readonly ast: AstIfStatement; - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get thenStatement(): Statement { - return this.ast.data.thenStatement.node; - } - set thenStatement(value) { - this.ast.data.thenStatement = value.ast; - } - get elseStatement(): Statement | undefined { - return this.ast.data.elseStatement?.node; - } - set elseStatement(value) { - this.ast.data.elseStatement = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + return propagateChildFlags(this.expression); } } -/** @internal */ +// dprint-ignore export class AstIfStatementData extends AstData { expression: AstExpression = undefined!; thenStatement: AstStatement = undefined!; elseStatement: AstStatement | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | propagateChildFlags(this.thenStatement) | propagateChildFlags(this.elseStatement); } } -/** @internal */ -export class DoStatement extends Node implements JSDocContainer, FlowContainer, ts.DoStatement { - declare readonly ast: AstDoStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get statement(): Statement { - return this.ast.data.statement.node; - } - set statement(value) { - this.ast.data.statement = value.ast; - } - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstDoStatementData extends AstData { statement: AstStatement = undefined!; expression: AstExpression = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.statement) | propagateChildFlags(this.expression); } } -/** @internal */ -export class WhileStatement extends Node implements JSDocContainer, FlowContainer, ts.WhileStatement { - declare readonly ast: AstWhileStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get statement(): Statement { - return this.ast.data.statement.node; - } - set statement(value) { - this.ast.data.statement = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstWhileStatementData extends AstData { expression: AstExpression = undefined!; statement: AstStatement = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | propagateChildFlags(this.statement); } } -/** @internal */ -export type ForInitializer = - | VariableDeclarationList - | Expression; - -/** @internal */ export type AstForInitializer = AstNodeOneOf; -/** @internal */ -export class ForStatement extends Node implements JSDocContainer, LocalsContainer, FlowContainer, ts.ForStatement { - declare readonly ast: AstForStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - declare _flowContainerBrand: any; - - get initializer(): ForInitializer | undefined { - return this.ast.data.initializer?.node; - } - set initializer(value) { - this.ast.data.initializer = value?.ast; - } - get condition(): Expression | undefined { - return this.ast.data.condition?.node; - } - set condition(value) { - this.ast.data.condition = value?.ast; - } - get incrementor(): Expression | undefined { - return this.ast.data.incrementor?.node; - } - set incrementor(value) { - this.ast.data.incrementor = value?.ast; - } - get statement(): Statement { - return this.ast.data.statement.node; - } - set statement(value) { - this.ast.data.statement = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstForStatementData extends AstData { initializer: AstForInitializer | undefined = undefined; condition: AstExpression | undefined = undefined; incrementor: AstExpression | undefined = undefined; statement: AstStatement = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.initializer) | propagateChildFlags(this.condition) | propagateChildFlags(this.incrementor) | @@ -8810,157 +3319,39 @@ export class AstForStatementData extends AstData { } } -/** @internal */ -export type ForInOrOfStatement = - | ForInStatement - | ForOfStatement; - -/** @internal */ export type AstForInOrOfStatement = AstNodeOneOf; -/** @internal */ -export class ForInStatement extends Node implements JSDocContainer, LocalsContainer, FlowContainer, ts.ForInStatement { - declare readonly ast: AstForInStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - declare _flowContainerBrand: any; - - get initializer(): ForInitializer { - return this.ast.data.initializer.node; - } - set initializer(value) { - this.ast.data.initializer = value.ast; - } - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get statement(): Statement { - return this.ast.data.statement.node; - } - set statement(value) { - this.ast.data.statement = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstForInStatementData extends AstData { initializer: AstForInitializer = undefined!; expression: AstExpression = undefined!; statement: AstStatement = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.initializer) | - propagateChildFlags(this.expression) | - propagateChildFlags(this.statement); - } -} - -/** @internal */ -export class ForOfStatement extends Node implements JSDocContainer, LocalsContainer, FlowContainer, ts.ForOfStatement { - declare readonly ast: AstForOfStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - declare _flowContainerBrand: any; - - get awaitModifier(): AwaitKeyword | undefined { - return this.ast.data.awaitModifier?.node; - } - set awaitModifier(value) { - this.ast.data.awaitModifier = value?.ast; - } - get initializer(): ForInitializer { - return this.ast.data.initializer.node; - } - set initializer(value) { - this.ast.data.initializer = value.ast; - } - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get statement(): Statement { - return this.ast.data.statement.node; - } - set statement(value) { - this.ast.data.statement = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; + propagateChildFlags(this.expression) | + propagateChildFlags(this.statement); } } -/** @internal */ +// dprint-ignore export class AstForOfStatementData extends AstData { awaitModifier: AstAwaitKeyword | undefined = undefined; initializer: AstForInitializer = undefined!; expression: AstExpression = undefined!; statement: AstStatement = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.awaitModifier) | propagateChildFlags(this.initializer) | propagateChildFlags(this.expression) | @@ -8973,130 +3364,42 @@ export class AstForOfStatementData extends AstData { } } -/** @internal */ -export class BreakStatement extends Node implements JSDocContainer, FlowContainer, ts.BreakStatement { - declare readonly ast: AstBreakStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get label(): Identifier | undefined { - return this.ast.data.label?.node; - } - set label(value) { - this.ast.data.label = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstBreakStatementData extends AstData { label: AstIdentifier | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; } } -/** @internal */ -export class ContinueStatement extends Node implements JSDocContainer, FlowContainer, ts.ContinueStatement { - declare readonly ast: AstContinueStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get label(): Identifier | undefined { - return this.ast.data.label?.node; - } - set label(value) { - this.ast.data.label = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ -export type BreakOrContinueStatement = - | BreakStatement - | ContinueStatement; - -/** @internal */ export type AstBreakOrContinueStatement = AstNodeOneOf; -/** @internal */ +// dprint-ignore export class AstContinueStatementData extends AstData { label: AstIdentifier | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; } } -/** @internal */ -export class ReturnStatement extends Node implements JSDocContainer, FlowContainer, ts.ReturnStatement { - declare readonly ast: AstReturnStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get expression(): Expression | undefined { - return this.ast.data.expression?.node; - } - set expression(value) { - this.ast.data.expression = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstReturnStatementData extends AstData { expression: AstExpression | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { // return in an ES2018 async generator must be awaited return propagateChildFlags(this.expression) | TransformFlags.ContainsES2018 | @@ -9104,644 +3407,170 @@ export class AstReturnStatementData extends AstData { } } -/** @internal */ -export class WithStatement extends Node implements JSDocContainer, FlowContainer, ts.WithStatement { - declare readonly ast: AstWithStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get statement(): Statement { - return this.ast.data.statement.node; - } - set statement(value) { - this.ast.data.statement = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstWithStatementData extends AstData { expression: AstExpression = undefined!; statement: AstStatement = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | propagateChildFlags(this.statement); } } -/** @internal */ -export class SwitchStatement extends Node implements JSDocContainer, FlowContainer, ts.SwitchStatement { - declare readonly ast: AstSwitchStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get caseBlock(): CaseBlock { - return this.ast.data.caseBlock.node; - } - set caseBlock(value) { - this.ast.data.caseBlock = value.ast; - } - get possiblyExhaustive(): boolean { - return this.ast.data.possiblyExhaustive; - } - set possiblyExhaustive(value) { - this.ast.data.possiblyExhaustive = value; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstSwitchStatementData extends AstData { expression: AstExpression = undefined!; caseBlock: AstCaseBlock = undefined!; - possiblyExhaustive: boolean = false; + possiblyExhaustive: boolean | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | propagateChildFlags(this.caseBlock); } } -/** @internal */ -export class CaseBlock extends Node implements LocalsContainer, ts.CaseBlock { - declare readonly ast: AstCaseBlock; - - declare _localsContainerBrand: any; - - override get parent() { - return super.parent as SwitchStatement; - } - override set parent(value) { - super.parent = value; - } - - get clauses(): NodeArray { - return this.ast.data.clauses.nodes; - } - set clauses(value) { - this.ast.data.clauses = value.ast; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstCaseBlockData extends AstData { clauses: AstNodeArray = undefined!; - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.clauses); } } -/** @internal */ -export class CaseClause extends Node implements JSDocContainer, ts.CaseClause { - declare readonly ast: AstCaseClause; - - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as CaseBlock; - } - override set parent(value) { - super.parent = value; - } - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get statements(): NodeArray { - return this.ast.data.statements.nodes; - } - set statements(value) { - this.ast.data.statements = value.ast; - } - get fallthroughFlowNode(): ts.FlowNode | undefined { - return this.ast.data.fallthroughFlowNode; - } - set fallthroughFlowNode(value) { - this.ast.data.fallthroughFlowNode = value; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } -} - -/** @internal */ +// dprint-ignore export class AstCaseClauseData extends AstData { expression: AstExpression = undefined!; statements: AstNodeArray = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - fallthroughFlowNode?: FlowNode | undefined; + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ fallthroughFlowNode?: FlowNode | undefined; // initialized by binding - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | propagateChildrenFlags(this.statements); } } -/** @internal */ -export class DefaultClause extends Node implements ts.DefaultClause { - declare readonly ast: AstDefaultClause; - - override get parent() { - return super.parent as CaseBlock; - } - override set parent(value) { - super.parent = value; - } - - get statements(): NodeArray { - return this.ast.data.statements.nodes; - } - set statements(value) { - this.ast.data.statements = value.ast; - } - get fallthroughFlowNode(): ts.FlowNode | undefined { - return this.ast.data.fallthroughFlowNode; - } - set fallthroughFlowNode(value) { - this.ast.data.fallthroughFlowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstDefaultClauseData extends AstData { statements: AstNodeArray = undefined!; - fallthroughFlowNode?: FlowNode | undefined = undefined; + /** @internal */ fallthroughFlowNode?: FlowNode | undefined = undefined; // initialized by binding - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.statements); } } -/** @internal */ -export type CaseOrDefaultClause = - | CaseClause - | DefaultClause; - -/** @internal */ export type AstCaseOrDefaultClause = AstNodeOneOf; -/** @internal */ -export class LabeledStatement extends Node implements JSDocContainer, FlowContainer, ts.LabeledStatement { - declare readonly ast: AstLabeledStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get label(): Identifier { - return this.ast.data.label.node; - } - set label(value) { - this.ast.data.label = value.ast; - } - get statement(): Statement { - return this.ast.data.statement.node; - } - set statement(value) { - this.ast.data.statement = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstLabeledStatementData extends AstData { label: AstIdentifier = undefined!; statement: AstStatement = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.label) | propagateChildFlags(this.statement); } } -/** @internal */ -export class ThrowStatement extends Node implements JSDocContainer, FlowContainer, ts.ThrowStatement { - declare readonly ast: AstThrowStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstThrowStatementData extends AstData { expression: AstExpression = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression); } } -/** @internal */ -export class TryStatement extends Node implements JSDocContainer, FlowContainer, ts.TryStatement { - declare readonly ast: AstTryStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _flowContainerBrand: any; - - get tryBlock(): Block { - return this.ast.data.tryBlock.node; - } - set tryBlock(value) { - this.ast.data.tryBlock = value.ast; - } - get catchClause(): CatchClause | undefined { - return this.ast.data.catchClause?.node; - } - set catchClause(value) { - this.ast.data.catchClause = value?.ast; - } - get finallyBlock(): Block | undefined { - return this.ast.data.finallyBlock?.node; - } - set finallyBlock(value) { - this.ast.data.finallyBlock = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get flowNode(): FlowNode | undefined { - return this.ast.data.flowNode; - } - set flowNode(value: FlowNode | undefined) { - this.ast.data.flowNode = value; - } -} - -/** @internal */ +// dprint-ignore export class AstTryStatementData extends AstData { tryBlock: AstBlock = undefined!; catchClause: AstCatchClause | undefined = undefined; finallyBlock: AstBlock | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.tryBlock) | propagateChildFlags(this.catchClause) | propagateChildFlags(this.finallyBlock); } } -/** @internal */ -export class CatchClause extends Node implements LocalsContainer, ts.CatchClause { - declare readonly ast: AstCatchClause; - - declare _localsContainerBrand: any; - - override get parent() { - return super.parent as TryStatement; - } - override set parent(value) { - super.parent = value; - } - - get variableDeclaration(): VariableDeclaration | undefined { - return this.ast.data.variableDeclaration?.node; - } - set variableDeclaration(value) { - this.ast.data.variableDeclaration = value?.ast; - } - get block(): Block { - return this.ast.data.block.node; - } - set block(value) { - this.ast.data.block = value.ast; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstCatchClauseData extends AstData { variableDeclaration: AstVariableDeclaration | undefined = undefined; block: AstBlock = undefined!; - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.variableDeclaration) | propagateChildFlags(this.block) | (!this.variableDeclaration ? TransformFlags.ContainsES2019 : TransformFlags.None); } } -/** @internal */ -export type ObjectTypeDeclaration = - | ClassLikeDeclaration - | InterfaceDeclaration - | TypeLiteralNode; - -/** @internal */ export type AstObjectTypeDeclaration = AstNodeOneOf; - -/** @internal */ -export type DeclarationWithTypeParameterChildren = - | SignatureDeclaration - | ClassLikeDeclaration - | InterfaceDeclaration - | TypeAliasDeclaration - | JSDocTemplateTag; - -/** @internal */ export type AstDeclarationWithTypeParameterChildren = AstNodeOneOf; - -/** @internal */ -export type ClassElement = - | PropertyDeclaration - | MethodDeclaration - | ConstructorDeclaration - | SemicolonClassElement - | AccessorDeclaration - | IndexSignatureDeclaration - | ClassStaticBlockDeclaration; - -/** @internal */ export type AstClassElement = AstNodeOneOf; - -/** @internal */ -export type ClassLikeDeclaration = - | ClassDeclaration - | ClassExpression; - -/** @internal */ export type AstClassLikeDeclaration = AstNodeOneOf; -/** @internal */ -export class ClassDeclaration extends Node implements JSDocContainer, Declaration, ts.ClassDeclaration { - declare readonly ast: AstClassDeclaration; - - declare _declarationBrand: any; - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): Identifier | undefined { - return this.ast.data.name?.node; - } - set name(value) { - this.ast.data.name = value?.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get heritageClauses(): NodeArray | undefined { - return this.ast.data.heritageClauses?.nodes; - } - set heritageClauses(value) { - this.ast.data.heritageClauses = value?.ast; - } - get members(): NodeArray { - return this.ast.data.members.nodes; - } - set members(value: NodeArray) { - this.ast.data.members = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstClassDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; + /** May be undefined in `export default class { ... }`. */ name: AstIdentifier | undefined = undefined; typeParameters: AstNodeArray | undefined = undefined; heritageClauses: AstNodeArray | undefined = undefined; members: AstNodeArray = undefined!; - - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - - override computeTransformFlags(_: AstNode): TransformFlags { - if (modifiersToFlags(this.modifiers?.items) & ModifierFlags.Ambient) { - return TransformFlags.ContainsTypeScript; - } - else { - let transformFlags = propagateChildrenFlags(this.modifiers) | - propagateNameFlags(this.name) | - propagateChildrenFlags(this.typeParameters) | - propagateChildrenFlags(this.heritageClauses) | - propagateChildrenFlags(this.members) | - (this.typeParameters ? TransformFlags.ContainsTypeScript : TransformFlags.None) | - TransformFlags.ContainsES2015; - if (transformFlags & TransformFlags.ContainsTypeScriptClassSyntax) { - transformFlags |= TransformFlags.ContainsTypeScript; - } - return transformFlags; - } - } -} - -/** @internal */ -export class ClassExpression extends Node implements JSDocContainer, Declaration, ts.ClassExpression { - declare readonly ast: AstClassExpression; - - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _primaryExpressionBrand: any; - declare _memberExpressionBrand: any; - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): Identifier | undefined { - return this.ast.data.name?.node; - } - set name(value) { - this.ast.data.name = value?.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get heritageClauses(): NodeArray | undefined { - return this.ast.data.heritageClauses?.nodes; - } - set heritageClauses(value) { - this.ast.data.heritageClauses = value?.ast; - } - get members(): NodeArray { - return this.ast.data.members.nodes; - } - set members(value) { - this.ast.data.members = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; + + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + if (modifiersToFlags(this.modifiers?.items) & ModifierFlags.Ambient) { + return TransformFlags.ContainsTypeScript; + } + else { + let transformFlags = propagateChildrenFlags(this.modifiers) | + propagateNameFlags(this.name) | + propagateChildrenFlags(this.typeParameters) | + propagateChildrenFlags(this.heritageClauses) | + propagateChildrenFlags(this.members) | + (this.typeParameters ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + TransformFlags.ContainsES2015; + if (transformFlags & TransformFlags.ContainsTypeScriptClassSyntax) { + transformFlags |= TransformFlags.ContainsTypeScript; + } + return transformFlags; + } } } -/** @internal */ +// dprint-ignore export class AstClassExpressionData extends AstData { modifiers: AstNodeArray | undefined = undefined; name: AstIdentifier | undefined = undefined; @@ -9749,11 +3578,11 @@ export class AstClassExpressionData extends AstData { heritageClauses: AstNodeArray | undefined = undefined; members: AstNodeArray = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.modifiers) | propagateNameFlags(this.name) | propagateChildrenFlags(this.typeParameters) | @@ -9764,83 +3593,9 @@ export class AstClassExpressionData extends AstData { } } -/** @internal */ -export interface TypeElement extends Declaration { - readonly ast: AstTypeElement; - _typeElementBrand: any; -} - -/** @internal */ export type AstTypeElement = AstNode; -// type TypeElement = -// | CallSignatureDeclaration -// | ConstructSignatureDeclaration -// | MethodSignature -// | IndexSignatureDeclaration -// | PropertySignature -// | AccessorDeclaration -// ; - -/** @internal */ -export class InterfaceDeclaration extends Node implements JSDocContainer, Declaration, ts.InterfaceDeclaration { - declare readonly ast: AstInterfaceDeclaration; - - declare _declarationBrand: any; - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): Identifier { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get heritageClauses(): NodeArray | undefined { - return this.ast.data.heritageClauses?.nodes; - } - set heritageClauses(value) { - this.ast.data.heritageClauses = value?.ast; - } - get members(): NodeArray { - return this.ast.data.members.nodes; - } - set members(value) { - this.ast.data.members = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstInterfaceDeclarationData extends AstTypeScriptNodeData { modifiers: AstNodeArray | undefined = undefined; name: AstIdentifier = undefined!; @@ -9848,42 +3603,17 @@ export class AstInterfaceDeclarationData extends AstTypeScriptNodeData { heritageClauses: AstNodeArray | undefined = undefined; members: AstNodeArray = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) -} - -/** @internal */ -export class HeritageClause extends Node implements ts.HeritageClause { - declare readonly ast: AstHeritageClause; - - override get parent() { - return super.parent as InterfaceDeclaration | ClassLikeDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get token(): ts.SyntaxKind.ExtendsKeyword | ts.SyntaxKind.ImplementsKeyword { - return this.ast.data.token; - } - set token(value) { - this.ast.data.token = value; - } - get types(): NodeArray { - return this.ast.data.types.nodes; - } - set types(value) { - this.ast.data.types = value.ast; - } + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } -/** @internal */ +// dprint-ignore export class AstHeritageClauseData extends AstData { token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword = undefined!; types: AstNodeArray = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { switch (this.token) { case SyntaxKind.ExtendsKeyword: return propagateChildrenFlags(this.types) | TransformFlags.ContainsES2015; @@ -9895,142 +3625,31 @@ export class AstHeritageClauseData extends AstData { } } -/** @internal */ -export class TypeAliasDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.TypeAliasDeclaration { - declare readonly ast: AstTypeAliasDeclaration; - - declare _declarationBrand: any; - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): Identifier { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstTypeAliasDeclarationData extends AstTypeScriptNodeData { modifiers: AstNodeArray | undefined = undefined; name: AstIdentifier = undefined!; typeParameters: AstNodeArray | undefined = undefined; type: AstTypeNode = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; -} -/** @internal */ -export class EnumDeclaration extends Node implements JSDocContainer, Declaration, ts.EnumDeclaration { - declare readonly ast: AstEnumDeclaration; - - declare _declarationBrand: any; - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): Identifier { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get members(): NodeArray { - return this.ast.data.members.nodes; - } - set members(value) { - this.ast.data.members = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ +// dprint-ignore export class AstEnumDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; name: AstIdentifier = undefined!; members: AstNodeArray = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildrenFlags(this.modifiers) | propagateChildFlags(this.name) | propagateChildrenFlags(this.members) | @@ -10040,163 +3659,38 @@ export class AstEnumDeclarationData extends AstData { } } -/** @internal */ -export class EnumMember extends Node implements JSDocContainer, Declaration, ts.EnumMember { - declare readonly ast: AstEnumMember; - - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as EnumDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get name(): PropertyName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get initializer(): Expression | undefined { - return this.ast.data.initializer?.node; - } - set initializer(value) { - this.ast.data.initializer = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstEnumMemberData extends AstData { name: AstPropertyName = undefined!; initializer: AstExpression | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.name) | propagateChildFlags(this.initializer) | TransformFlags.ContainsTypeScript; } } -/** @internal */ -export type ModuleName = - | Identifier - | StringLiteral; - -/** @internal */ export type AstModuleName = AstNodeOneOf; - -/** @internal */ -export type ModuleBody = - | NamespaceBody - | JSDocNamespaceBody; - -/** @internal */ export type AstModuleBody = AstNodeOneOf; -/** @internal */ -export class ModuleDeclaration extends Node implements JSDocContainer, Declaration, LocalsContainer, ts.ModuleDeclaration { - declare readonly ast: AstModuleDeclaration; - - declare _declarationBrand: any; - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - - override get parent() { - return super.parent as ModuleBlock | SourceFile; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): ModuleName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get body(): ModuleBody | JSDocNamespaceDeclaration | undefined { - return this.ast.data.body?.node; - } - set body(value) { - this.ast.data.body = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstModuleDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; name: AstModuleName = undefined!; body: AstModuleBody | AstJSDocNamespaceDeclaration | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { if (modifiersToFlags(this.modifiers?.items) & ModifierFlags.Ambient) { return TransformFlags.ContainsTypeScript; } @@ -10211,292 +3705,84 @@ export class AstModuleDeclarationData extends AstData { } } -/** @internal */ -export type NamespaceBody = - | ModuleBlock - | NamespaceDeclaration; - -/** @internal */ export type AstNamespaceBody = AstNodeOneOf; -/** @internal */ -export interface NamespaceDeclaration extends ModuleDeclaration { - readonly ast: AstNamespaceDeclaration; - readonly data: AstNamespaceDeclarationData; - readonly name: Identifier; - readonly body: NamespaceBody; -} - -/** @internal */ export type AstNamespaceDeclaration = AstNode; -/** @internal */ export interface AstNamespaceDeclarationData extends AstModuleDeclarationData { name: AstIdentifier; body: AstNamespaceBody; } -/** @internal */ -export type JSDocNamespaceBody = - | Identifier - | JSDocNamespaceDeclaration; - -/** @internal */ export type AstJSDocNamespaceBody = AstNodeOneOf; -/** @internal */ -export interface JSDocNamespaceDeclaration extends ModuleDeclaration { - readonly ast: AstJSDocNamespaceDeclaration; - readonly data: AstJSDocNamespaceDeclarationData; - readonly name: Identifier; - readonly body: JSDocNamespaceBody | undefined; -} - -/** @internal */ export type AstJSDocNamespaceDeclaration = AstNode; -/** @internal */ export interface AstJSDocNamespaceDeclarationData extends AstModuleDeclarationData { name: AstIdentifier; body: AstJSDocNamespaceBody | undefined; } -/** @internal */ -export class ModuleBlock extends Node implements JSDocContainer, ts.ModuleBlock { - declare readonly ast: AstModuleBlock; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as ModuleDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get statements(): NodeArray { - return this.ast.data.statements.nodes; - } - set statements(value) { - this.ast.data.statements = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } -} - -/** @internal */ +// dprint-ignore export class AstModuleBlockData extends AstData { statements: AstNodeArray = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.statements); } } -/** @internal */ -export type ModuleReference = - | EntityName - | ExternalModuleReference; - -/** @internal */ export type AstModuleReference = AstNodeOneOf; -/** @internal */ -export class ImportEqualsDeclaration extends Node implements JSDocContainer, Declaration, ts.ImportEqualsDeclaration { - declare readonly ast: AstImportEqualsDeclaration; - - declare _declarationBrand: any; - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as ModuleBlock | SourceFile; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get name(): Identifier { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get isTypeOnly(): boolean { - return this.ast.data.isTypeOnly; - } - set isTypeOnly(value) { - this.ast.data.isTypeOnly = value; - } - get moduleReference(): ModuleReference { - return this.ast.data.moduleReference.node; - } - set moduleReference(value) { - this.ast.data.moduleReference = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstImportEqualsDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; name: AstIdentifier = undefined!; isTypeOnly: boolean = undefined!; moduleReference: AstModuleReference = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildrenFlags(this.modifiers) | propagateIdentifierNameFlags(this.name) | - propagateChildFlags(this.moduleReference); - - if (this.moduleReference.kind !== SyntaxKind.ExternalModuleReference) { - transformFlags |= TransformFlags.ContainsTypeScript; - } - - return transformFlags & ~TransformFlags.ContainsPossibleTopLevelAwait; // Import= declaration is always parsed in an Await context - } -} - -/** @internal */ -export class ExternalModuleReference extends Node implements ts.ExternalModuleReference { - declare readonly ast: AstExternalModuleReference; - - override get parent() { - return super.parent as ImportEqualsDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } -} - -/** @internal */ -export class AstExternalModuleReferenceData extends AstData { - expression: AstExpression = undefined!; - - override computeTransformFlags(_: AstNode): TransformFlags { - // always parsed in an Await context - return propagateChildFlags(this.expression) & ~TransformFlags.ContainsPossibleTopLevelAwait; - } -} - -/** @internal */ -export class ImportDeclaration extends Node implements JSDocContainer, Declaration, ts.ImportDeclaration { - declare readonly ast: AstImportDeclaration; - - declare _declarationBrand: any; - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as ModuleBlock | SourceFile; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get importClause(): ImportClause | undefined { - return this.ast.data.importClause?.node; - } - set importClause(value) { - this.ast.data.importClause = value?.ast; - } - get moduleSpecifier(): Expression { - return this.ast.data.moduleSpecifier.node; - } - set moduleSpecifier(value) { - this.ast.data.moduleSpecifier = value.ast; - } - get attributes(): ImportAttributes | undefined { - return this.ast.data.attributes?.node; - } - set attributes(value) { - this.ast.data.attributes = value?.ast; - } - /** @deprecated */ - get assertClause(): ImportAttributes | undefined { - return this.ast.data.attributes?.node; - } - set assertClause(value) { - this.ast.data.attributes = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; + propagateChildFlags(this.moduleReference); + + if (this.moduleReference.kind !== SyntaxKind.ExternalModuleReference) { + transformFlags |= TransformFlags.ContainsTypeScript; + } + + return transformFlags & ~TransformFlags.ContainsPossibleTopLevelAwait; // Import= declaration is always parsed in an Await context } - set localSymbol(value) { - this.ast.data.localSymbol = value; +} + +// dprint-ignore +export class AstExternalModuleReferenceData extends AstData { + expression: AstExpression = undefined!; + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + // always parsed in an Await context + return propagateChildFlags(this.expression) & ~TransformFlags.ContainsPossibleTopLevelAwait; } } -/** @internal */ +// dprint-ignore export class AstImportDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; importClause: AstImportClause | undefined = undefined; + /** If this is not a StringLiteral it will be a grammar error. */ moduleSpecifier: AstExpression = undefined!; attributes: AstImportAttributes | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.importClause) | propagateChildFlags(this.moduleSpecifier); transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context @@ -10504,77 +3790,19 @@ export class AstImportDeclarationData extends AstData { } } -/** @internal */ -export type NamedImportBindings = - | NamespaceImport - | NamedImports; - -/** @internal */ export type AstNamedImportBindings = AstNodeOneOf; - -/** @internal */ -export type NamedExportBindings = - | NamespaceExport - | NamedExports; - -/** @internal */ export type AstNamedExportBindings = AstNodeOneOf; -/** @internal */ -export class ImportClause extends Node implements Declaration, ts.ImportClause { - declare readonly ast: AstImportClause; - - declare _declarationBrand: any; - - override get parent() { - return super.parent as ImportDeclaration | JSDocImportTag; - } - override set parent(value) { - super.parent = value; - } - - get isTypeOnly(): boolean { - return this.ast.data.isTypeOnly; - } - set isTypeOnly(value) { - this.ast.data.isTypeOnly = value; - } - get name(): Identifier | undefined { - return this.ast.data.name?.node; - } - set name(value) { - this.ast.data.name = value?.ast; - } - get namedBindings(): NamedImportBindings | undefined { - return this.ast.data.namedBindings?.node; - } - set namedBindings(value) { - this.ast.data.namedBindings = value?.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstImportClauseData extends AstData { isTypeOnly: boolean = false; - name: AstIdentifier | undefined = undefined; + name: AstIdentifier | undefined = undefined; // Default binding namedBindings: AstNamedImportBindings | undefined = undefined; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.name) | propagateChildFlags(this.namedBindings); if (this.isTypeOnly) { @@ -10585,210 +3813,57 @@ export class AstImportClauseData extends AstData { } } -/** @internal */ -export type AssertionKey = - | Identifier - | StringLiteral; - -/** @internal */ export type AstAssertionKey = AstNodeOneOf; - -/** - * @deprecated - * @internal - */ -export type AssertEntry = ImportAttribute; - -/** - * @deprecated - * @internal - */ +/** @deprecated */ export type AstAssertEntry = AstImportAttribute; - -/** @internal */ -export type ImportAttributeName = - | Identifier - | StringLiteral; - -/** @internal */ export type AstImportAttributeName = AstNodeOneOf; -/** @internal */ -export class ImportAttribute extends Node implements ts.ImportAttribute { - declare readonly ast: AstImportAttribute; - - override get parent() { - return super.parent as ImportAttributes; - } - override set parent(value) { - super.parent = value; - } - - get name(): ImportAttributeName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get value(): Expression { - return this.ast.data.value.node; - } - set value(value) { - this.ast.data.value = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstImportAttributeData extends AstData { name: AstImportAttributeName = undefined!; value: AstExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsESNext; } } -/** - * @deprecated - * @internal - */ -export type AssertClause = ImportAttributes; - -/** - * @deprecated - * @internal - */ +/** @deprecated */ export type AstAssertClause = AstNode; -/** @internal */ -export class ImportAttributes extends Node implements ts.ImportAttributes { - declare readonly ast: AstImportAttributes; - - override get parent() { - return super.parent as ImportDeclaration | ExportDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get token(): ts.SyntaxKind.WithKeyword | ts.SyntaxKind.AssertKeyword { - return this.ast.data.token; - } - set token(value) { - this.ast.data.token = value; - } - get elements(): NodeArray { - return this.ast.data.elements.nodes; - } - set elements(value) { - this.ast.data.elements = value.ast; - } - get multiLine(): boolean | undefined { - return this.ast.data.multiLine; - } - set multiLine(value) { - this.ast.data.multiLine = value; - } -} - -/** @internal */ +// dprint-ignore export class AstImportAttributesData extends AstData { token: SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword = SyntaxKind.WithKeyword; elements: AstNodeArray = undefined!; multiLine: boolean | undefined = undefined; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsESNext; } } -/** @internal */ -export class NamespaceImport extends Node implements Declaration, ts.NamespaceImport { - declare readonly ast: AstNamespaceImport; - - declare _declarationBrand: any; - - override get parent() { - return super.parent as ImportClause; - } - override set parent(value) { - super.parent = value; - } - - get name(): Identifier { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstNamespaceImportData extends AstData { name: AstIdentifier = undefined!; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.name); transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } } -/** @internal */ -export class NamespaceExport extends Node implements Declaration, ts.NamespaceExport { - declare readonly ast: AstNamespaceExport; - - declare _declarationBrand: any; - - override get parent() { - return super.parent as ExportDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get name(): ModuleExportName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstNamespaceExportData extends AstData { name: AstModuleExportName = undefined!; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.name) | TransformFlags.ContainsES2020; transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context @@ -10796,133 +3871,22 @@ export class AstNamespaceExportData extends AstData { } } -/** @internal */ -export class NamespaceExportDeclaration extends Node implements JSDocContainer, Declaration, ts.NamespaceExportDeclaration { - declare readonly ast: AstNamespaceExportDeclaration; - - declare _declarationBrand: any; - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - - get name(): Identifier { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstNamespaceExportDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) name: AstIdentifier = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateIdentifierNameFlags(this.name) | TransformFlags.ContainsTypeScript; } } -/** @internal */ -export class ExportDeclaration extends Node implements JSDocContainer, Declaration, ts.ExportDeclaration { - declare readonly ast: AstExportDeclaration; - - declare _declarationBrand: any; - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as SourceFile | ModuleBlock; - } - override set parent(value) { - super.parent = value; - } - - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get isTypeOnly(): boolean { - return this.ast.data.isTypeOnly; - } - set isTypeOnly(value) { - this.ast.data.isTypeOnly = value; - } - get exportClause(): NamedExportBindings | undefined { - return this.ast.data.exportClause?.node; - } - set exportClause(value) { - this.ast.data.exportClause = value?.ast; - } - get moduleSpecifier(): Expression | undefined { - return this.ast.data.moduleSpecifier?.node; - } - set moduleSpecifier(value) { - this.ast.data.moduleSpecifier = value?.ast; - } - get attributes(): ImportAttributes | undefined { - return this.ast.data.attributes?.node; - } - set attributes(value) { - this.ast.data.attributes = value?.ast; - } - /** @deprecated */ - get assertClause(): ImportAttributes | undefined { - return this.ast.data.attributes?.node; - } - set assertClause(value) { - this.ast.data.attributes = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstExportDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; isTypeOnly = false; @@ -10930,11 +3894,11 @@ export class AstExportDeclarationData extends AstData { moduleSpecifier: AstExpression | undefined = undefined; attributes: AstImportAttributes | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildrenFlags(this.modifiers) | propagateChildFlags(this.exportClause) | propagateChildFlags(this.moduleSpecifier); @@ -10943,121 +3907,38 @@ export class AstExportDeclarationData extends AstData { } } -/** @internal */ -export class NamedImports extends Node implements ts.NamedImports { - declare readonly ast: AstNamedImports; - - override get parent() { - return super.parent as ImportClause; - } - override set parent(value) { - super.parent = value; - } - - get elements(): NodeArray { - return this.ast.data.elements.nodes; - } - set elements(value) { - this.ast.data.elements = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstNamedImportsData extends AstData { elements: AstNodeArray = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildrenFlags(this.elements); transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } } -/** @internal */ -export class NamedExports extends Node implements ts.NamedExports { - declare readonly ast: AstNamedExports; - - override get parent() { - return super.parent as ExportDeclaration; - } - override set parent(value) { - super.parent = value; - } - - get elements(): NodeArray { - return this.ast.data.elements.nodes; - } - set elements(value) { - this.ast.data.elements = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstNamedExportsData extends AstData { elements: AstNodeArray = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildrenFlags(this.elements); transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } } -/** @internal */ -export class ImportSpecifier extends Node implements Declaration, ts.ImportSpecifier { - declare readonly ast: AstImportSpecifier; - - declare _declarationBrand: any; - - override get parent() { - return super.parent as NamedImports; - } - override set parent(value) { - super.parent = value; - } - - get propertyName(): ModuleExportName | undefined { - return this.ast.data.propertyName?.node; - } - set propertyName(value) { - this.ast.data.propertyName = value?.ast; - } - get name(): Identifier { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get isTypeOnly(): boolean { - return this.ast.data.isTypeOnly; - } - set isTypeOnly(value) { - this.ast.data.isTypeOnly = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstImportSpecifierData extends AstData { propertyName: AstModuleExportName | undefined = undefined; name: AstIdentifier = undefined!; isTypeOnly = false; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildFlags(this.propertyName) | propagateChildFlags(this.name); transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context @@ -11065,2338 +3946,576 @@ export class AstImportSpecifierData extends AstData { } } -/** @internal */ -export class ExportSpecifier extends Node implements Declaration, JSDocContainer, ts.ExportSpecifier { - declare readonly ast: AstExportSpecifier; - - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - - override get parent() { - return super.parent as NamedExports; - } - override set parent(value) { - super.parent = value; - } - - get isTypeOnly(): boolean { - return this.ast.data.isTypeOnly; - } - set isTypeOnly(value) { - this.ast.data.isTypeOnly = value; - } - get propertyName(): ModuleExportName | undefined { - return this.ast.data.propertyName?.node; - } - set propertyName(value) { - this.ast.data.propertyName = value?.ast; - } - get name(): ModuleExportName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstExportSpecifierData extends AstData { isTypeOnly = false; propertyName: AstModuleExportName | undefined = undefined; name: AstModuleExportName = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - - override computeTransformFlags(_: AstNode): TransformFlags { - let transformFlags = propagateChildFlags(this.propertyName) | - propagateChildFlags(this.name); - transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - return transformFlags; - } -} - -/** @internal */ -export type ModuleExportName = - | Identifier - | StringLiteral; - -/** @internal */ -export type AstModuleExportName = AstNodeOneOf; - -/** @internal */ -export class ExportAssignment extends Node implements JSDocContainer, Declaration, ts.ExportAssignment { - declare readonly ast: AstExportAssignment; - - declare _declarationBrand: any; - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - declare name: never; - - override get parent() { - return super.parent as SourceFile; - } - override set parent(value) { - super.parent = value; - } + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - get modifiers(): NodeArray | undefined { - return this.ast.data.modifiers?.nodes; - } - set modifiers(value) { - this.ast.data.modifiers = value?.ast; - } - get isExportEquals(): boolean | undefined { - return this.ast.data.isExportEquals; - } - set isExportEquals(value) { - this.ast.data.isExportEquals = value; - } - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value) { - this.ast.data.expression = value.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { + let transformFlags = propagateChildFlags(this.propertyName) | + propagateChildFlags(this.name); + transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context + return transformFlags; } } -/** @internal */ +export type AstModuleExportName = AstNodeOneOf; + +// dprint-ignore export class AstExportAssignmentData extends AstData { modifiers: AstNodeArray | undefined = undefined; isExportEquals: boolean | undefined = undefined; expression: AstExpression = undefined!; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { let transformFlags = propagateChildrenFlags(this.modifiers) | propagateChildFlags(this.expression); transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } } -/** @internal */ -export class JSDocTypeExpression extends Node implements ts.JSDocTypeExpression { - declare readonly ast: AstJSDocTypeExpression; - - declare _typeNodeBrand: any; - - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocTypeExpressionData extends AstData { type: AstTypeNode = undefined!; } -/** @internal */ -export class JSDocNameReference extends Node implements ts.JSDocNameReference { - declare readonly ast: AstJSDocNameReference; - - get name(): EntityName | JSDocMemberName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocNameReferenceData extends AstData { name: AstEntityName | AstJSDocMemberName = undefined!; } -/** @internal */ -export class JSDocMemberName extends Node implements ts.JSDocMemberName { - declare readonly ast: AstJSDocMemberName; - - get left(): EntityName | JSDocMemberName { - return this.ast.data.left.node; - } - set left(value) { - this.ast.data.left = value.ast; - } - get right(): Identifier { - return this.ast.data.right.node; - } - set right(value) { - this.ast.data.right = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocMemberNameData extends AstData { left: AstEntityName | AstJSDocMemberName = undefined!; right: AstIdentifier = undefined!; } -/** @internal */ -export type JSDocType = - | JSDocAllType - | JSDocUnknownType - | JSDocNonNullableType - | JSDocNullableType - | JSDocOptionalType - | JSDocFunctionType - | JSDocVariadicType - | JSDocNamepathType; - -/** @internal */ export type AstJSDocType = AstNodeOneOf; -/** @internal */ -export class JSDocAllType extends Node implements ts.JSDocAllType { - declare readonly ast: AstJSDocAllType; - - declare _jsDocTypeBrand: any; - declare _typeNodeBrand: any; -} - -/** @internal */ +// dprint-ignore export class AstJSDocAllTypeData extends AstData { } -/** @internal */ -export class JSDocUnknownType extends Node implements ts.JSDocUnknownType { - declare readonly ast: AstJSDocUnknownType; - - declare _jsDocTypeBrand: any; - declare _typeNodeBrand: any; -} - -/** @internal */ +// dprint-ignore export class AstJSDocUnknownTypeData extends AstData { } -/** @internal */ -export class JSDocNonNullableType extends Node implements ts.JSDocNonNullableType { - declare readonly ast: AstJSDocNonNullableType; - - declare _jsDocTypeBrand: any; - declare _typeNodeBrand: any; - - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } - get postfix(): boolean { - return this.ast.data.postfix; - } - set postfix(value) { - this.ast.data.postfix = value; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocNonNullableTypeData extends AstData { type: AstTypeNode = undefined!; postfix = false; } -/** @internal */ -export class JSDocNullableType extends Node implements ts.JSDocNullableType { - declare readonly ast: AstJSDocNullableType; - - declare _jsDocTypeBrand: any; - declare _typeNodeBrand: any; - - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } - get postfix(): boolean { - return this.ast.data.postfix; - } - set postfix(value) { - this.ast.data.postfix = value; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocNullableTypeData extends AstData { type: AstTypeNode = undefined!; postfix = false; } -/** @internal */ -export class JSDocOptionalType extends Node implements ts.JSDocOptionalType { - declare readonly ast: AstJSDocOptionalType; - - declare _jsDocTypeBrand: any; - declare _typeNodeBrand: any; - - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocOptionalTypeData extends AstData { type: AstTypeNode = undefined!; } -/** @internal */ -export class JSDocFunctionType extends Node implements Declaration, LocalsContainer, ts.JSDocFunctionType { - declare readonly ast: AstJSDocFunctionType; - - declare _jsDocTypeBrand: any; - declare _typeNodeBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - declare name: never; - - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): TypeNode | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get typeArguments(): NodeArray | undefined { - return this.ast.data.typeArguments?.nodes; - } - set typeArguments(value) { - this.ast.data.typeArguments = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocFunctionTypeData extends AstData { typeParameters: AstNodeArray | undefined = undefined; parameters: AstNodeArray = undefined!; type: AstTypeNode | undefined = undefined; - typeArguments: AstNodeArray | undefined = undefined; // quick info - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; -} - -/** @internal */ -export class JSDocVariadicType extends Node implements ts.JSDocVariadicType { - declare readonly ast: AstJSDocVariadicType; - - declare _jsDocTypeBrand: any; - declare _typeNodeBrand: any; - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } + /** @internal */ typeArguments: AstNodeArray | undefined = undefined; // quick info + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ +// dprint-ignore export class AstJSDocVariadicTypeData extends AstData { type: AstTypeNode = undefined!; } -/** @internal */ -export class JSDocNamepathType extends Node implements ts.JSDocNamepathType { - declare readonly ast: AstJSDocNamepathType; - - declare _jsDocTypeBrand: any; - declare _typeNodeBrand: any; - - get type(): TypeNode { - return this.ast.data.type.node; - } - set type(value) { - this.ast.data.type = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocNamepathTypeData extends AstData { type: AstTypeNode = undefined!; } -/** @internal */ -export class JSDoc extends Node implements ts.JSDoc { - declare readonly ast: AstJSDoc; - - override get parent() { - return super.parent as HasJSDoc; - } - override set parent(value) { - super.parent = value; - } - - get tags(): NodeArray | undefined { - return this.ast.data.tags?.nodes; - } - set tags(value) { - this.ast.data.tags = value?.ast; - } - get comment(): string | NodeArray | undefined { - const comment = this.ast.data.comment; - return typeof comment === "string" ? comment : comment?.nodes; - } - set comment(value) { - this.ast.data.comment = typeof value === "string" ? value : value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocData extends AstData { comment: string | AstNodeArray | undefined = undefined; tags: AstNodeArray | undefined = undefined; } -/** @internal */ -export type HasJSDoc = - | AccessorDeclaration - | ArrowFunction - | BinaryExpression - | Block - | BreakStatement - | CallSignatureDeclaration - | CaseClause - | ClassLikeDeclaration - | ClassStaticBlockDeclaration - | ConstructorDeclaration - | ConstructorTypeNode - | ConstructSignatureDeclaration - | ContinueStatement - | DebuggerStatement - | DoStatement - | ElementAccessExpression - | EmptyStatement - | EndOfFileToken - | EnumDeclaration - | EnumMember - | ExportAssignment - | ExportDeclaration - | ExportSpecifier - | ExpressionStatement - | ForInStatement - | ForOfStatement - | ForStatement - | FunctionDeclaration - | FunctionExpression - | FunctionTypeNode - | Identifier - | IfStatement - | ImportDeclaration - | ImportEqualsDeclaration - | IndexSignatureDeclaration - | InterfaceDeclaration - | JSDocFunctionType - | JSDocSignature - | LabeledStatement - | MethodDeclaration - | MethodSignature - | ModuleDeclaration - | NamedTupleMember - | NamespaceExportDeclaration - | ObjectLiteralExpression - | ParameterDeclaration - | ParenthesizedExpression - | PropertyAccessExpression - | PropertyAssignment - | PropertyDeclaration - | PropertySignature - | ReturnStatement - | SemicolonClassElement - | ShorthandPropertyAssignment - | SpreadAssignment - | SwitchStatement - | ThrowStatement - | TryStatement - | TypeAliasDeclaration - | TypeParameterDeclaration - | VariableDeclaration - | VariableStatement - | WhileStatement - | WithStatement; - -/** @internal */ export type AstHasJSDoc = AstNodeOneOf; - -/** @internal */ -export type JSDocTag = - | JSDocUnknownTag - | JSDocAugmentsTag - | JSDocImplementsTag - | JSDocAuthorTag - | JSDocDeprecatedTag - | JSDocClassTag - | JSDocPublicTag - | JSDocPrivateTag - | JSDocProtectedTag - | JSDocReadonlyTag - | JSDocOverrideTag - | JSDocEnumTag - | JSDocThisTag - | JSDocTemplateTag - | JSDocSeeTag - | JSDocReturnTag - | JSDocTypeTag - | JSDocTypedefTag - | JSDocCallbackTag - | JSDocOverloadTag - | JSDocThrowsTag - | JSDocPropertyTag - | JSDocParameterTag - | JSDocSatisfiesTag - | JSDocImportTag; - -/** @internal */ export type AstJSDocTag = AstNodeOneOf; -/** @internal */ -export class JSDocLink extends Node implements ts.JSDocLink { - declare readonly ast: AstJSDocLink; - - get name(): EntityName | JSDocMemberName | undefined { - return this.ast.data.name?.node; - } - set name(value) { - this.ast.data.name = value?.ast; - } - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocLinkData extends AstData { name: AstEntityName | AstJSDocMemberName | undefined = undefined; text = ""; } -/** @internal */ -export class JSDocLinkCode extends Node implements ts.JSDocLinkCode { - declare readonly ast: AstJSDocLinkCode; - - get name(): EntityName | JSDocMemberName | undefined { - return this.ast.data.name?.node; - } - set name(value) { - this.ast.data.name = value?.ast; - } - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocLinkCodeData extends AstData { name: AstEntityName | AstJSDocMemberName | undefined = undefined; text = ""; } -/** @internal */ -export class JSDocLinkPlain extends Node implements ts.JSDocLinkPlain { - declare readonly ast: AstJSDocLinkPlain; - - get name(): EntityName | JSDocMemberName | undefined { - return this.ast.data.name?.node; - } - set name(value) { - this.ast.data.name = value?.ast; - } - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocLinkPlainData extends AstData { name: AstEntityName | AstJSDocMemberName | undefined = undefined; text = ""; } -/** @internal */ -export type JSDocComment = - | JSDocText - | JSDocLink - | JSDocLinkCode - | JSDocLinkPlain; - -/** @internal */ export type AstJSDocComment = AstNodeOneOf; -/** @internal */ -export class JSDocText extends Node implements ts.JSDocText { - declare readonly ast: AstJSDocText; - - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocTextData extends AstData { text = ""; } -/** @internal */ -export class BaseJSDocTag extends Node implements ts.JSDocTag { - declare readonly ast: AstBaseJSDocTag; - - override get parent() { - return super.parent as JSDoc | JSDocTypeLiteral; - } - override set parent(value) { - super.parent = value; - } - - get tagName(): Identifier { - return this.ast.data.tagName.node; - } - set tagName(value) { - this.ast.data.tagName = value.ast; - } - get comment(): string | NodeArray | undefined { - const comment = this.ast.data.comment; - return typeof comment === "string" ? comment : comment?.nodes; - } - set comment(value) { - this.ast.data.comment = typeof value === "string" ? value : value?.ast; - } -} - -/** @internal */ -export type AstBaseJSDocTag = AstNode>; +export type AstBaseJSDocTag = AstNode>; -/** @internal */ +// dprint-ignore export class AstJSDocTagData extends AstData { tagName: AstIdentifier = undefined!; comment: string | AstNodeArray | undefined = undefined; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; } } -/** @internal */ -export class JSDocUnknownTag extends BaseJSDocTag implements ts.JSDocUnknownTag { - declare readonly ast: AstJSDocUnknownTag; -} - -/** @internal */ +// dprint-ignore export class AstJSDocUnknownTagData extends AstJSDocTagData { } -/** @internal */ -export interface JSDocClassReference extends ExpressionWithTypeArguments { - readonly ast: AstJSDocClassReference; - readonly data: AstJSDocClassReferenceData; - readonly expression: Identifier | PropertyAccessEntityNameExpression; -} - -/** @internal */ export type AstJSDocClassReference = AstNode; -/** @internal */ export interface AstJSDocClassReferenceData extends AstExpressionWithTypeArgumentsData { expression: AstIdentifier | AstPropertyAccessEntityNameExpression; } -/** @internal */ -export class JSDocAugmentsTag extends BaseJSDocTag implements ts.JSDocAugmentsTag { - declare readonly ast: AstJSDocAugmentsTag; - get class(): JSDocClassReference { - return this.ast.data.class.node; - } - set class(value) { - this.ast.data.class = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocAugmentsTagData extends AstJSDocTagData { class: AstJSDocClassReference = undefined!; } -/** @internal */ -export class JSDocImplementsTag extends BaseJSDocTag implements ts.JSDocImplementsTag { - declare readonly ast: AstJSDocImplementsTag; - get class(): JSDocClassReference { - return this.ast.data.class.node; - } - set class(value) { - this.ast.data.class = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocImplementsTagData extends AstJSDocTagData { class: AstJSDocClassReference = undefined!; } -/** @internal */ -export class JSDocAuthorTag extends BaseJSDocTag implements ts.JSDocAuthorTag { - declare readonly ast: AstJSDocAuthorTag; -} - -/** @internal */ +// dprint-ignore export class AstJSDocAuthorTagData extends AstJSDocTagData { } -/** @internal */ -export class JSDocDeprecatedTag extends BaseJSDocTag implements ts.JSDocDeprecatedTag { - declare readonly ast: AstJSDocDeprecatedTag; -} - -/** @internal */ +// dprint-ignore export class AstJSDocDeprecatedTagData extends AstJSDocTagData { } -/** @internal */ -export class JSDocClassTag extends BaseJSDocTag implements ts.JSDocClassTag { - declare readonly ast: AstJSDocClassTag; -} - -/** @internal */ +// dprint-ignore export class AstJSDocClassTagData extends AstJSDocTagData { } -/** @internal */ -export class JSDocPublicTag extends BaseJSDocTag implements ts.JSDocPublicTag { - declare readonly ast: AstJSDocPublicTag; -} - -/** @internal */ +// dprint-ignore export class AstJSDocPublicTagData extends AstJSDocTagData { } -/** @internal */ -export class JSDocPrivateTag extends BaseJSDocTag implements ts.JSDocPrivateTag { - declare readonly ast: AstJSDocPrivateTag; -} - -/** @internal */ +// dprint-ignore export class AstJSDocPrivateTagData extends AstJSDocTagData { } -/** @internal */ -export class JSDocProtectedTag extends BaseJSDocTag implements ts.JSDocProtectedTag { - declare readonly ast: AstJSDocProtectedTag; -} - -/** @internal */ +// dprint-ignore export class AstJSDocProtectedTagData extends AstJSDocTagData { } -/** @internal */ -export class JSDocReadonlyTag extends BaseJSDocTag implements ts.JSDocReadonlyTag { - declare readonly ast: AstJSDocReadonlyTag; -} - -/** @internal */ -export class AstJSDocReadonlyTagData extends AstJSDocTagData { -} - -/** @internal */ -export class JSDocOverrideTag extends BaseJSDocTag implements ts.JSDocOverrideTag { - declare readonly ast: AstJSDocOverrideTag; -} - -/** @internal */ -export class AstJSDocOverrideTagData extends AstJSDocTagData { -} - -/** @internal */ -export class JSDocEnumTag extends BaseJSDocTag implements Declaration, LocalsContainer, ts.JSDocEnumTag { - declare readonly ast: AstJSDocEnumTag; - declare _declarationBrand: any; - declare _localsContainerBrand: any; - - override get parent() { - return super.parent as JSDoc; - } - override set parent(value) { - super.parent = value; - } - - get typeExpression(): JSDocTypeExpression { - return this.ast.data.typeExpression.node; - } - set typeExpression(value) { - this.ast.data.typeExpression = value.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ -export class AstJSDocEnumTagData extends AstJSDocTagData { - typeExpression: AstJSDocTypeExpression = undefined!; - - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; +// dprint-ignore +export class AstJSDocReadonlyTagData extends AstJSDocTagData { } -/** @internal */ -export class JSDocThisTag extends BaseJSDocTag implements ts.JSDocThisTag { - declare readonly ast: AstJSDocThisTag; - get typeExpression(): JSDocTypeExpression { - return this.ast.data.typeExpression.node; - } - set typeExpression(value) { - this.ast.data.typeExpression = value.ast; - } +// dprint-ignore +export class AstJSDocOverrideTagData extends AstJSDocTagData { } -/** @internal */ -export class AstJSDocThisTagData extends AstJSDocTagData { +// dprint-ignore +export class AstJSDocEnumTagData extends AstJSDocTagData { typeExpression: AstJSDocTypeExpression = undefined!; + + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ -export class JSDocTemplateTag extends BaseJSDocTag implements ts.JSDocTemplateTag { - declare readonly ast: AstJSDocTemplateTag; - get constraint(): JSDocTypeExpression | undefined { - return this.ast.data.constraint?.node; - } - set constraint(value) { - this.ast.data.constraint = value?.ast; - } - get typeParameters(): NodeArray { - return this.ast.data.typeParameters.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value.ast; - } +// dprint-ignore +export class AstJSDocThisTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression = undefined!; } -/** @internal */ +// dprint-ignore export class AstJSDocTemplateTagData extends AstJSDocTagData { constraint: AstJSDocTypeExpression | undefined = undefined; typeParameters: AstNodeArray = undefined!; } -/** @internal */ -export class JSDocSeeTag extends BaseJSDocTag implements ts.JSDocSeeTag { - declare readonly ast: AstJSDocSeeTag; - get name(): JSDocNameReference | undefined { - return this.ast.data.name?.node; - } - set name(value) { - this.ast.data.name = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocSeeTagData extends AstJSDocTagData { name: AstJSDocNameReference | undefined = undefined; } -/** @internal */ -export class JSDocReturnTag extends BaseJSDocTag implements ts.JSDocReturnTag { - declare readonly ast: AstJSDocReturnTag; - get typeExpression(): JSDocTypeExpression | undefined { - return this.ast.data.typeExpression?.node; - } - set typeExpression(value) { - this.ast.data.typeExpression = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocReturnTagData extends AstJSDocTagData { typeExpression: AstJSDocTypeExpression | undefined = undefined; } -/** @internal */ -export class JSDocTypeTag extends BaseJSDocTag implements ts.JSDocTypeTag { - declare readonly ast: AstJSDocTypeTag; - get typeExpression(): JSDocTypeExpression { - return this.ast.data.typeExpression.node; - } - set typeExpression(value) { - this.ast.data.typeExpression = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocTypeTagData extends AstJSDocTagData { typeExpression: AstJSDocTypeExpression = undefined!; } -/** @internal */ -export class JSDocTypedefTag extends BaseJSDocTag implements Declaration, LocalsContainer, ts.JSDocTypedefTag { - declare readonly ast: AstJSDocTypedefTag; - declare _declarationBrand: any; - declare _localsContainerBrand: any; - - override get parent() { - return super.parent as JSDoc; - } - override set parent(value) { - super.parent = value; - } - - get fullName(): Identifier | JSDocNamespaceDeclaration | undefined { - return this.ast.data.fullName?.node; - } - set fullName(value) { - this.ast.data.fullName = value?.ast; - } - get name(): Identifier | undefined { - return this.ast.data.name?.node; - } - set name(value) { - this.ast.data.name = value?.ast; - } - get typeExpression(): JSDocTypeLiteral | JSDocTypeExpression | undefined { - return this.ast.data.typeExpression?.node; - } - set typeExpression(value) { - this.ast.data.typeExpression = value?.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocTypedefTagData extends AstJSDocTagData { typeExpression: AstJSDocTypeExpression | AstJSDocTypeLiteral | undefined = undefined; fullName: AstJSDocNamespaceDeclaration | AstIdentifier | undefined = undefined; name: AstIdentifier | undefined = undefined; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; -} - -/** @internal */ -export class JSDocCallbackTag extends BaseJSDocTag implements Declaration, LocalsContainer, ts.JSDocCallbackTag { - declare readonly ast: AstJSDocCallbackTag; - declare _declarationBrand: any; - declare _localsContainerBrand: any; - - override get parent() { - return super.parent as JSDoc; - } - override set parent(value) { - super.parent = value; - } - - get fullName(): Identifier | JSDocNamespaceDeclaration | undefined { - return this.ast.data.fullName?.node; - } - set fullName(value) { - this.ast.data.fullName = value?.ast; - } - get name(): Identifier | undefined { - return this.ast.data.name?.node; - } - set name(value) { - this.ast.data.name = value?.ast; - } - get typeExpression(): JSDocSignature { - return this.ast.data.typeExpression.node; - } - set typeExpression(value) { - this.ast.data.typeExpression = value.ast; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ +// dprint-ignore export class AstJSDocCallbackTagData extends AstJSDocTagData { fullName: AstJSDocNamespaceDeclaration | AstIdentifier | undefined = undefined; name: AstIdentifier | undefined = undefined; typeExpression: AstJSDocSignature = undefined!; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; -} - -/** @internal */ -export class JSDocOverloadTag extends BaseJSDocTag implements ts.JSDocOverloadTag { - declare readonly ast: AstJSDocOverloadTag; - - override get parent() { - return super.parent as JSDoc; - } - override set parent(value) { - super.parent = value; - } - - get typeExpression(): JSDocSignature { - return this.ast.data.typeExpression.node; - } - set typeExpression(value) { - this.ast.data.typeExpression = value.ast; - } + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ +// dprint-ignore export class AstJSDocOverloadTagData extends AstJSDocTagData { typeExpression: AstJSDocSignature = undefined!; } -/** @internal */ -export class JSDocThrowsTag extends BaseJSDocTag implements ts.JSDocThrowsTag { - declare readonly ast: AstJSDocThrowsTag; - get typeExpression(): JSDocTypeExpression | undefined { - return this.ast.data.typeExpression?.node; - } - set typeExpression(value) { - this.ast.data.typeExpression = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocThrowsTagData extends AstJSDocTagData { typeExpression: AstJSDocTypeExpression | undefined = undefined; } -/** @internal */ -export class JSDocSignature extends Node implements Declaration, LocalsContainer, ts.JSDocSignature { - declare readonly ast: AstJSDocSignature; - - declare _jsDocTypeBrand: any; - declare _typeNodeBrand: any; - declare _declarationBrand: any; - declare _jsdocContainerBrand: any; - declare _localsContainerBrand: any; - - get typeParameters(): NodeArray | undefined { - return this.ast.data.typeParameters?.nodes; - } - set typeParameters(value) { - this.ast.data.typeParameters = value?.ast; - } - get parameters(): NodeArray { - return this.ast.data.parameters.nodes; - } - set parameters(value) { - this.ast.data.parameters = value.ast; - } - get type(): JSDocReturnTag | undefined { - return this.ast.data.type?.node; - } - set type(value) { - this.ast.data.type = value?.ast; - } - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value) { - this.ast.data.jsDoc = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocSignatureData extends AstData { typeParameters: AstNodeArray | undefined = undefined; parameters: AstNodeArray = undefined!; type: AstJSDocReturnTag | undefined = undefined; - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; -} - -/** @internal */ -export class JSDocPropertyTag extends BaseJSDocTag implements Declaration, ts.JSDocPropertyTag { - declare readonly ast: AstJSDocPropertyTag; - declare _declarationBrand: any; - - override get parent() { - return super.parent as JSDoc; - } - override set parent(value) { - super.parent = value; - } - - get name(): Identifier | QualifiedName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get typeExpression(): JSDocTypeExpression | undefined { - return this.ast.data.typeExpression?.node; - } - set typeExpression(value) { - this.ast.data.typeExpression = value?.ast; - } - get isNameFirst(): boolean { - return this.ast.data.isNameFirst; - } - set isNameFirst(value) { - this.ast.data.isNameFirst = value; - } - get isBracketed(): boolean { - return this.ast.data.isBracketed; - } - set isBracketed(value) { - this.ast.data.isBracketed = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } -/** @internal */ +// dprint-ignore export class AstJSDocPropertyTagData extends AstJSDocTagData { typeExpression: AstJSDocTypeExpression | undefined = undefined; name: AstEntityName = undefined!; + /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ isNameFirst = false; isBracketed = false; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) -} - -/** @internal */ -export class JSDocParameterTag extends BaseJSDocTag implements Declaration, ts.JSDocParameterTag { - declare readonly ast: AstJSDocParameterTag; - declare _declarationBrand: any; - - override get parent() { - return super.parent as JSDoc; - } - override set parent(value) { - super.parent = value; - } - - get name(): Identifier | QualifiedName { - return this.ast.data.name.node; - } - set name(value) { - this.ast.data.name = value.ast; - } - get typeExpression(): JSDocTypeExpression | undefined { - return this.ast.data.typeExpression?.node; - } - set typeExpression(value) { - this.ast.data.typeExpression = value?.ast; - } - get isNameFirst(): boolean { - return this.ast.data.isNameFirst; - } - set isNameFirst(value) { - this.ast.data.isNameFirst = value; - } - get isBracketed(): boolean { - return this.ast.data.isBracketed; - } - set isBracketed(value) { - this.ast.data.isBracketed = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } -/** @internal */ +// dprint-ignore export class AstJSDocParameterTagData extends AstJSDocTagData { typeExpression: AstJSDocTypeExpression | undefined = undefined; name: AstEntityName = undefined!; + /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ isNameFirst = false; isBracketed = false; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } -/** @internal */ -export type JSDocPropertyLikeTag = - | JSDocPropertyTag - | JSDocParameterTag; - -/** @internal */ export type AstJSDocPropertyLikeTag = AstNodeOneOf; -/** @internal */ -export class JSDocTypeLiteral extends Node implements Declaration, ts.JSDocTypeLiteral { - declare readonly ast: AstJSDocTypeLiteral; - - declare _jsDocTypeBrand: any; - declare _typeNodeBrand: any; - declare _declarationBrand: any; - - get jsDocPropertyTags(): NodeArray | undefined { - return this.ast.data.jsDocPropertyTags?.nodes; - } - set jsDocPropertyTags(value) { - this.ast.data.jsDocPropertyTags = value?.ast; - } - get isArrayType(): boolean { - return this.ast.data.isArrayType; - } - set isArrayType(value) { - this.ast.data.isArrayType = value; - } - get symbol(): ts.Symbol { - return this.ast.data.symbol; - } - set symbol(value) { - this.ast.data.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value) { - this.ast.data.localSymbol = value; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocTypeLiteralData extends AstData { jsDocPropertyTags: AstNodeArray | undefined = undefined; + /** If true, then this type literal represents an *array* of its type. */ isArrayType = false; - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) -} -/** @internal */ -export class JSDocSatisfiesTag extends BaseJSDocTag implements ts.JSDocSatisfiesTag { - declare readonly ast: AstJSDocSatisfiesTag; - get typeExpression(): JSDocTypeExpression { - return this.ast.data.typeExpression.node; - } - set typeExpression(value) { - this.ast.data.typeExpression = value.ast; - } + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } -/** @internal */ +// dprint-ignore export class AstJSDocSatisfiesTagData extends AstJSDocTagData { typeExpression: AstJSDocTypeExpression = undefined!; } -/** @internal */ -export class JSDocImportTag extends BaseJSDocTag implements ts.JSDocImportTag { - declare readonly ast: AstJSDocImportTag; - - override get parent() { - return super.parent as JSDoc; - } - override set parent(value) { - super.parent = value; - } - - get importClause(): ImportClause | undefined { - return this.ast.data.importClause?.node; - } - set importClause(value) { - this.ast.data.importClause = value?.ast; - } - get moduleSpecifier(): Expression { - return this.ast.data.moduleSpecifier.node; - } - set moduleSpecifier(value) { - this.ast.data.moduleSpecifier = value.ast; - } - get attributes(): ImportAttributes | undefined { - return this.ast.data.attributes?.node; - } - set attributes(value) { - this.ast.data.attributes = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstJSDocImportTagData extends AstJSDocTagData { importClause: AstImportClause | undefined = undefined; moduleSpecifier: AstExpression = undefined!; attributes: AstImportAttributes | undefined = undefined; } -/** @internal */ -export class SyntheticExpression extends Node implements ts.SyntheticExpression { - declare readonly ast: AstSyntheticExpression; - declare _expressionBrand: any; - - get isSpread(): boolean { - return this.ast.data.isSpread; - } - set isSpread(value: boolean) { - this.ast.data.isSpread = value; - } - get type(): ts.Type { - return this.ast.data.type; - } - set type(value: ts.Type) { - this.ast.data.type = value; - } - get tupleNameSource(): ParameterDeclaration | NamedTupleMember | undefined { - return this.ast.data.tupleNameSource?.node; - } - set tupleNameSource(value: ParameterDeclaration | NamedTupleMember | undefined) { - this.ast.data.tupleNameSource = value?.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstSyntheticExpressionData extends AstData { isSpread = false; type: Type = undefined!; tupleNameSource: AstParameterDeclaration | AstNamedTupleMember | undefined = undefined; } -/** @internal */ -export class Bundle extends Node implements ts.Bundle { - declare readonly ast: AstBundle; - - get sourceFiles(): readonly SourceFile[] { - return this.ast.data.sourceFiles; - } - set sourceFiles(value: readonly SourceFile[]) { - this.ast.data.sourceFiles = value; - } - get syntheticFileReferences(): readonly FileReference[] | undefined { - return this.ast.data.syntheticFileReferences; - } - set syntheticFileReferences(value: readonly FileReference[] | undefined) { - this.ast.data.syntheticFileReferences = value; - } - get syntheticTypeReferences(): readonly FileReference[] | undefined { - return this.ast.data.syntheticTypeReferences; - } - set syntheticTypeReferences(value: readonly FileReference[] | undefined) { - this.ast.data.syntheticTypeReferences = value; - } - get syntheticLibReferences(): readonly FileReference[] | undefined { - return this.ast.data.syntheticLibReferences; - } - set syntheticLibReferences(value: readonly FileReference[] | undefined) { - this.ast.data.syntheticLibReferences = value; - } - get hasNoDefaultLib(): boolean | undefined { - return this.ast.data.hasNoDefaultLib; - } - set hasNoDefaultLib(value: boolean | undefined) { - this.ast.data.hasNoDefaultLib = value; - } -} - -/** @internal */ +// dprint-ignore export class AstBundleData extends AstData { sourceFiles: readonly SourceFile[] = undefined!; - syntheticFileReferences?: readonly FileReference[]; - syntheticTypeReferences?: readonly FileReference[]; - syntheticLibReferences?: readonly FileReference[]; - hasNoDefaultLib?: boolean; -} - -/** @internal */ -export class SyntaxList extends Node implements ts.SyntaxList { - get _children(): readonly Node[] { - return this.ast.data._children; - } - set _children(value: readonly Node[]) { - this.ast.data._children = value; - } -} - -/** @internal */ -export class AstSyntaxListData extends AstData { - _children!: readonly Node[]; -} - -/** @internal */ -export class NotEmittedStatement extends Node implements ts.NotEmittedStatement { - declare readonly ast: AstNotEmittedStatement; - - declare _statementBrand: any; - declare _jsdocContainerBrand: any; - - get jsDoc(): JSDocArray | undefined { - return this.ast.data.jsDoc; - } - set jsDoc(value: JSDocArray | undefined) { - this.ast.data.jsDoc = value; - } -} - -/** @internal */ -export class AstNotEmittedStatementData extends AstData { - jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) -} - -/** @internal */ -export class NotEmittedTypeElement extends Node implements ts.NotEmittedTypeElement { - declare readonly ast: AstNotEmittedTypeElement; - - declare _typeElementBrand: any; - declare _declarationBrand: any; - - get name(): PropertyName | undefined { - return this.ast.data.name?.node; - } - set name(value: PropertyName | undefined) { - this.ast.data.name = value?.ast; - } - get questionToken(): QuestionToken | undefined { - return this.ast.data.questionToken?.node; - } - set questionToken(value: QuestionToken | undefined) { - this.ast.data.questionToken = value?.ast; - } - get symbol(): Symbol { - return this.ast.data.symbol; - } - set symbol(value: Symbol) { - this.ast.data.symbol = value; - } - get localSymbol(): Symbol | undefined { - return this.ast.data.localSymbol; - } - set localSymbol(value: Symbol | undefined) { - this.ast.data.localSymbol = value; - } + /** @internal */ syntheticFileReferences?: readonly FileReference[]; + /** @internal */ syntheticTypeReferences?: readonly FileReference[]; + /** @internal */ syntheticLibReferences?: readonly FileReference[]; + /** @internal */ hasNoDefaultLib?: boolean; } -/** @internal */ -export class AstNotEmittedTypeElementData extends AstData { - name: AstPropertyName | undefined = undefined; - questionToken: AstQuestionToken | undefined = undefined; - symbol: Symbol = undefined!; - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) +// dprint-ignore +export class AstSyntaxListData extends AstData { + /** @internal */ _children!: readonly Node[]; } -/** @internal */ -export class PartiallyEmittedExpression extends Node implements ts.PartiallyEmittedExpression { - declare readonly ast: AstPartiallyEmittedExpression; - - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; +// dprint-ignore +export class AstNotEmittedStatementData extends AstData { + /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) +} - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value: Expression) { - this.ast.data.expression = value.ast; - } +// dprint-ignore +export class AstNotEmittedTypeElementData extends AstData { + /** @internal */ symbol: Symbol = undefined!; + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } -/** @internal */ +// dprint-ignore export class AstPartiallyEmittedExpressionData extends AstData { expression: AstExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression); } } -/** @internal */ -export class CommaListExpression extends Node implements ts.CommaListExpression { - declare readonly ast: AstCommaListExpression; - - declare _expressionBrand: any; - - get elements(): NodeArray { - return this.ast.data.elements.nodes; - } - set elements(value: NodeArray) { - this.ast.data.elements = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstCommaListExpressionData extends AstData { elements: AstNodeArray = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.elements); } } /** @internal */ -export class SyntheticReferenceExpression extends Node implements ts.SyntheticReferenceExpression { - declare readonly ast: AstSyntheticReferenceExpression; - - declare _leftHandSideExpressionBrand: any; - declare _updateExpressionBrand: any; - declare _unaryExpressionBrand: any; - declare _expressionBrand: any; - - get expression(): Expression { - return this.ast.data.expression.node; - } - set expression(value: Expression) { - this.ast.data.expression = value.ast; - } - get thisArg(): Expression { - return this.ast.data.thisArg.node; - } - set thisArg(value: Expression) { - this.ast.data.thisArg = value.ast; - } -} - -/** @internal */ +// dprint-ignore export class AstSyntheticReferenceExpressionData extends AstData { expression: AstExpression = undefined!; thisArg: AstExpression = undefined!; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression) | propagateChildFlags(this.thisArg); } } -/** @internal */ -export class SourceFile extends Node implements Declaration, LocalsContainer, ts.SourceFile { - declare readonly ast: AstSourceFile; - - declare _declarationBrand: any; - declare _localsContainerBrand: any; - - get statements(): NodeArray { - return this.ast.data.statements.nodes; - } - set statements(value) { - this.ast.data.statements = value.ast; - } - get endOfFileToken(): EndOfFileToken { - return this.ast.data.endOfFileToken.node; - } - set endOfFileToken(value) { - this.ast.data.endOfFileToken = value.ast; - } - get fileName(): string { - return this.ast.data.fileName; - } - set fileName(value) { - this.ast.data.fileName = value; - } - - get path(): ts.Path { - return this.ast.data.path; - } - set path(value) { - this.ast.data.path = value; - } - get text(): string { - return this.ast.data.text; - } - set text(value) { - this.ast.data.text = value; - } - get resolvedPath(): ts.Path { - return this.ast.data.resolvedPath; - } - set resolvedPath(value) { - this.ast.data.resolvedPath = value; - } - get originalFileName(): string { - return this.ast.data.originalFileName; - } - set originalFileName(value) { - this.ast.data.originalFileName = value; - } - get amdDependencies(): ts.AmdDependency[] { - return this.ast.data.amdDependencies; - } - set amdDependencies(value) { - this.ast.data.amdDependencies = value; - } - get moduleName(): string | undefined { - return this.ast.data.moduleName; - } - set moduleName(value) { - this.ast.data.moduleName = value; - } - get referencedFiles(): readonly ts.FileReference[] { - return this.ast.data.referencedFiles; - } - set referencedFiles(value) { - this.ast.data.referencedFiles = value; - } - get typeReferenceDirectives(): readonly ts.FileReference[] { - return this.ast.data.typeReferenceDirectives; - } - set typeReferenceDirectives(value) { - this.ast.data.typeReferenceDirectives = value; - } - get libReferenceDirectives(): readonly ts.FileReference[] { - return this.ast.data.libReferenceDirectives; - } - set libReferenceDirectives(value) { - this.ast.data.libReferenceDirectives = value; - } - get languageVariant(): ts.LanguageVariant { - return this.ast.data.languageVariant; - } - set languageVariant(value) { - this.ast.data.languageVariant = value; - } - get isDeclarationFile(): boolean { - return this.ast.data.isDeclarationFile; - } - set isDeclarationFile(value) { - this.ast.data.isDeclarationFile = value; - } - get renamedDependencies(): Map { - return this.ast.data.renamedDependencies; - } - set renamedDependencies(value) { - this.ast.data.renamedDependencies = value; - } - get hasNoDefaultLib(): boolean { - return this.ast.data.hasNoDefaultLib; - } - set hasNoDefaultLib(value) { - this.ast.data.hasNoDefaultLib = value; - } - get languageVersion(): ts.ScriptTarget { - return this.ast.data.languageVersion; - } - set languageVersion(value) { - this.ast.data.languageVersion = value; - } - get impliedNodeFormat(): ts.ResolutionMode { - return this.ast.data.impliedNodeFormat; - } - set impliedNodeFormat(value) { - this.ast.data.impliedNodeFormat = value; - } - get scriptKind(): ts.ScriptKind { - return this.ast.data.scriptKind; - } - set scriptKind(value) { - this.ast.data.scriptKind = value; - } - get pragmas(): ts.ReadonlyPragmaMap { - return this.ast.data.pragmas; - } - set pragmas(value) { - this.ast.data.pragmas = value; - } - get externalModuleIndicator(): true | Node | undefined { - return this.ast.data.externalModuleIndicator; - } - set externalModuleIndicator(value) { - this.ast.data.externalModuleIndicator = value; - } - get commonJsModuleIndicator(): Node | undefined { - return this.ast.data.commonJsModuleIndicator; - } - set commonJsModuleIndicator(value) { - this.ast.data.commonJsModuleIndicator = value; - } - get identifiers(): Map { - return this.ast.data.identifiers; - } - set identifiers(value) { - this.ast.data.identifiers = value; - } - get parseDiagnostics(): ts.DiagnosticWithLocation[] { - return this.ast.data.parseDiagnostics; - } - set parseDiagnostics(value) { - this.ast.data.parseDiagnostics = value; - } - get bindDiagnostics(): ts.DiagnosticWithLocation[] { - return this.ast.data.bindDiagnostics; - } - set bindDiagnostics(value) { - this.ast.data.bindDiagnostics = value; - } - get bindSuggestionDiagnostics(): ts.DiagnosticWithLocation[] | undefined { - return this.ast.data.bindSuggestionDiagnostics; - } - set bindSuggestionDiagnostics(value) { - this.ast.data.bindSuggestionDiagnostics = value; - } - get lineMap(): readonly number[] { - return this.ast.data.lineMap; - } - set lineMap(value) { - this.ast.data.lineMap = value; - } - get jsDocDiagnostics(): ts.DiagnosticWithLocation[] | undefined { - return this.ast.data.jsDocDiagnostics; - } - set jsDocDiagnostics(value) { - this.ast.data.jsDocDiagnostics = value; - } - get commentDirectives(): ts.CommentDirective[] | undefined { - return this.ast.data.commentDirectives; - } - set commentDirectives(value) { - this.ast.data.commentDirectives = value; - } - get checkJsDirective(): ts.CheckJsDirective | undefined { - return this.ast.data.checkJsDirective; - } - set checkJsDirective(value) { - this.ast.data.checkJsDirective = value; - } - get version(): string { - return this.ast.data.version; - } - set version(value) { - this.ast.data.version = value; - } - get symbol(): ts.Symbol { - return this.ast.data.declaration.symbol; - } - set symbol(value) { - this.ast.data.declaration.symbol = value; - } - get localSymbol(): ts.Symbol | undefined { - return this.ast.data.declaration.localSymbol; - } - set localSymbol(value) { - this.ast.data.declaration.localSymbol = value; - } - get locals(): ts.SymbolTable | undefined { - return this.ast.data.locals; - } - set locals(value) { - this.ast.data.locals = value; - } - get redirectInfo(): ts.RedirectInfo | undefined { - return this.ast.data.redirectInfo; - } - set redirectInfo(value) { - this.ast.data.redirectInfo = value; - } - get packageJsonLocations(): readonly string[] | undefined { - return this.ast.data.packageJsonLocations; - } - set packageJsonLocations(value) { - this.ast.data.packageJsonLocations = value; - } - get packageJsonScope(): ts.PackageJsonInfo | undefined { - return this.ast.data.packageJsonScope; - } - set packageJsonScope(value) { - this.ast.data.packageJsonScope = value; - } - get setExternalModuleIndicator(): ((file: ts.SourceFile) => void) | undefined { - return this.ast.data.setExternalModuleIndicator; - } - set setExternalModuleIndicator(value) { - this.ast.data.setExternalModuleIndicator = value; - } - get jsGlobalAugmentations(): ts.SymbolTable | undefined { - return this.ast.data.jsGlobalAugmentations; - } - set jsGlobalAugmentations(value) { - this.ast.data.jsGlobalAugmentations = value; - } - get nodeCount(): number { - return this.ast.data.nodeCount; - } - set nodeCount(value) { - this.ast.data.nodeCount = value; - } - get identifierCount(): number { - return this.ast.data.identifierCount; - } - set identifierCount(value) { - this.ast.data.identifierCount = value; - } - get symbolCount(): number { - return this.ast.data.symbolCount; - } - set symbolCount(value) { - this.ast.data.symbolCount = value; - } - get additionalSyntacticDiagnostics(): readonly ts.DiagnosticWithLocation[] | undefined { - return this.ast.data.additionalSyntacticDiagnostics; - } - set additionalSyntacticDiagnostics(value) { - this.ast.data.additionalSyntacticDiagnostics = value; - } - get classifiableNames(): ReadonlySet | undefined { - return this.ast.data.classifiableNames; - } - set classifiableNames(value) { - this.ast.data.classifiableNames = value; - } - get imports(): readonly ts.StringLiteralLike[] { - return this.ast.data.imports; - } - set imports(value) { - this.ast.data.imports = value; - } - get moduleAugmentations(): readonly (ts.Identifier | ts.StringLiteral)[] { - return this.ast.data.moduleAugmentations; - } - set moduleAugmentations(value) { - this.ast.data.moduleAugmentations = value; - } - get patternAmbientModules(): ts.PatternAmbientModule[] | undefined { - return this.ast.data.patternAmbientModules; - } - set patternAmbientModules(value) { - this.ast.data.patternAmbientModules = value; - } - get ambientModuleNames(): readonly string[] { - return this.ast.data.ambientModuleNames; - } - set ambientModuleNames(value) { - this.ast.data.ambientModuleNames = value; - } - get localJsxNamespace(): ts.__String | undefined { - return this.ast.data.localJsxNamespace; - } - set localJsxNamespace(value) { - this.ast.data.localJsxNamespace = value; - } - get localJsxFragmentNamespace(): ts.__String | undefined { - return this.ast.data.localJsxFragmentNamespace; - } - set localJsxFragmentNamespace(value) { - this.ast.data.localJsxFragmentNamespace = value; - } - get localJsxFactory(): ts.EntityName | undefined { - return this.ast.data.localJsxFactory; - } - set localJsxFactory(value) { - this.ast.data.localJsxFactory = value; - } - get localJsxFragmentFactory(): ts.EntityName | undefined { - return this.ast.data.localJsxFragmentFactory; - } - set localJsxFragmentFactory(value) { - this.ast.data.localJsxFragmentFactory = value; - } - get endFlowNode(): ts.FlowNode | undefined { - return this.ast.data.endFlowNode; - } - set endFlowNode(value) { - this.ast.data.endFlowNode = value; - } - get jsDocParsingMode(): ts.JSDocParsingMode | undefined { - return this.ast.data.jsDocParsingMode; - } - set jsDocParsingMode(value) { - this.ast.data.jsDocParsingMode = value; - } - - get scriptSnapshot(): any { - return this.ast.data.scriptSnapshot; - } - set scriptSnapshot(value) { - this.ast.data.scriptSnapshot = value; - } - get nameTable(): Map | undefined { - return this.ast.data.nameTable; - } - set nameTable(value) { - this.ast.data.nameTable = value; - } - - get nextContainer(): HasLocals | undefined { - return this.ast.data.nextContainer?.node; - } - set nextContainer(value) { - this.ast.data.nextContainer = value?.ast; - } - - get extendedSourceFiles(): string[] | undefined { - return this.ast.data.extendedSourceFiles; - } - set extendedSourceFiles(value) { - this.ast.data.extendedSourceFiles = value; - } - get configFileSpecs(): ts.ConfigFileSpecs | undefined { - return this.ast.data.configFileSpecs; - } - set configFileSpecs(value) { - this.ast.data.configFileSpecs = value; - } - - public update(newText: string, textChangeRange: ts.TextChangeRange): ts.SourceFile { - return updateSourceFile(this, newText, textChangeRange); - } - - public getLineAndCharacterOfPosition(position: number): ts.LineAndCharacter { - return getLineAndCharacterOfPosition(this, position); - } - - public getLineStarts(): readonly number[] { - return getLineStarts(this); - } - - public getPositionOfLineAndCharacter(line: number, character: number, allowEdits?: true): number { - return computePositionOfLineAndCharacter(getLineStarts(this), line, character, this.text, allowEdits); - } - - public getLineEndOfPosition(pos: number): number { - const { line } = this.getLineAndCharacterOfPosition(pos); - const lineStarts = this.getLineStarts(); - - let lastCharPos: number | undefined; - if (line + 1 >= lineStarts.length) { - lastCharPos = this.getEnd(); - } - if (!lastCharPos) { - lastCharPos = lineStarts[line + 1] - 1; - } - - const fullText = this.getFullText(); - // if the new line is "\r\n", we should return the last non-new-line-character position - return fullText[lastCharPos] === "\n" && fullText[lastCharPos - 1] === "\r" ? lastCharPos - 1 : lastCharPos; - } - - public getNamedDeclarations(): Map { - if (!this.ast.data.namedDeclarations) { - this.ast.data.namedDeclarations = this.computeNamedDeclarations(); - } - - return this.ast.data.namedDeclarations; - } - - private computeNamedDeclarations(): Map { - const result = createMultiMap(); - - this.forEachChild(visit); - - return result; - - function addDeclaration(declaration: ts.Declaration) { - const name = getDeclarationName(declaration); - if (name) { - result.add(name, declaration); - } - } - - function getDeclarations(name: string) { - let declarations = result.get(name); - if (!declarations) { - result.set(name, declarations = []); - } - return declarations; - } - - function getDeclarationName(declaration: ts.Declaration) { - const name = getNonAssignedNameOfDeclaration(declaration); - return name && (isComputedPropertyName(name) && isPropertyAccessExpression(name.expression) ? (name.expression.name as MemberName).text - : isPropertyName(name) ? getNameFromPropertyName(name) : undefined); - } - - function visit(node: ts.Node): void { - switch (node.kind) { - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.FunctionExpression: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - const functionDeclaration = node as ts.FunctionLikeDeclaration; - const declarationName = getDeclarationName(functionDeclaration); - - if (declarationName) { - const declarations = getDeclarations(declarationName); - const lastDeclaration = lastOrUndefined(declarations); - - // Check whether this declaration belongs to an "overload group". - if (lastDeclaration && functionDeclaration.parent === lastDeclaration.parent && functionDeclaration.symbol === lastDeclaration.symbol) { - // Overwrite the last declaration if it was an overload - // and this one is an implementation. - if (functionDeclaration.body && !(lastDeclaration as ts.FunctionLikeDeclaration).body) { - declarations[declarations.length - 1] = functionDeclaration; - } - } - else { - declarations.push(functionDeclaration); - } - } - forEachChild(node, visit); - break; - - case SyntaxKind.ClassDeclaration: - case SyntaxKind.ClassExpression: - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.TypeAliasDeclaration: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.ModuleDeclaration: - case SyntaxKind.ImportEqualsDeclaration: - case SyntaxKind.ExportSpecifier: - case SyntaxKind.ImportSpecifier: - case SyntaxKind.ImportClause: - case SyntaxKind.NamespaceImport: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.TypeLiteral: - addDeclaration(node as ts.Declaration); - forEachChild(node, visit); - break; - - case SyntaxKind.Parameter: - // Only consider parameter properties - if (!hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) { - break; - } - // falls through - - case SyntaxKind.VariableDeclaration: - case SyntaxKind.BindingElement: { - const decl = node as ts.VariableDeclaration; - if (isBindingPattern(decl.name)) { - forEachChild(decl.name, visit); - break; - } - if (decl.initializer) { - visit(decl.initializer); - } - } - // falls through - case SyntaxKind.EnumMember: - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - addDeclaration(node as ts.Declaration); - break; - - case SyntaxKind.ExportDeclaration: - // Handle named exports case e.g.: - // export {a, b as B} from "mod"; - const exportDeclaration = node as ts.ExportDeclaration; - if (exportDeclaration.exportClause) { - if (isNamedExports(exportDeclaration.exportClause)) { - forEach(exportDeclaration.exportClause.elements, visit); - } - else { - visit(exportDeclaration.exportClause.name); - } - } - break; - - case SyntaxKind.ImportDeclaration: - const importClause = (node as ImportDeclaration).importClause; - if (importClause) { - // Handle default import case e.g.: - // import d from "mod"; - if (importClause.name) { - addDeclaration(importClause.name); - } - - // Handle named bindings in imports e.g.: - // import * as NS from "mod"; - // import {a, b as B} from "mod"; - if (importClause.namedBindings) { - if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - addDeclaration(importClause.namedBindings); - } - else { - forEach(importClause.namedBindings.elements, visit); - } - } - } - break; - - case SyntaxKind.BinaryExpression: - if (getAssignmentDeclarationKind(node as ts.BinaryExpression) !== ts.AssignmentDeclarationKind.None) { - addDeclaration(node as ts.BinaryExpression); - } - // falls through - - default: - forEachChild(node, visit); - } - } - } -} - -/** @internal */ +// dprint-ignore export class AstDeclarationData { - symbol: Symbol = undefined!; // initialized by binder (Declaration) - localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) + /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } -/** @internal */ +// dprint-ignore export class AstSourceFileData extends AstData { declaration: AstDeclarationData = new AstDeclarationData(); statements: AstNodeArray = undefined!; endOfFileToken: AstEndOfFileToken = undefined!; text = ""; fileName = ""; - path = "" as Path; + /** @internal */ path = "" as Path; + /** + * Resolved path can be different from path property, + * when file is included through project reference is mapped to its output instead of source + * in that case resolvedPath = path to output file + * path = input file's path + * + * @internal + */ resolvedPath = "" as Path; + /** + * Original file name that can be different from fileName, + * when file is included through project reference is mapped to its output instead of source + * in that case originalFileName = name of input file + * fileName = output file's name + * + * @internal + */ originalFileName = ""; - languageVersion: ts.ScriptTarget = ScriptTarget.ES5; + languageVersion: ScriptTarget = ScriptTarget.ES5; languageVariant: LanguageVariant = 0; - scriptKind: ScriptKind = 0; + /** @internal */ scriptKind: ScriptKind = 0; isDeclarationFile = false; + /** + * lib.d.ts should have a reference comment like + * + * /// + * + * If any other file has this comment, it signals not to include lib.d.ts + * because this containing file is intended to act as a default library. + */ hasNoDefaultLib = false; - locals: SymbolTable | undefined = undefined; - nextContainer: AstNextContainer | undefined = undefined; - endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) - nodeCount = 0; - identifierCount = 0; - symbolCount = 0; + /** @internal */ locals: SymbolTable | undefined = undefined; + /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + /** @internal */ endFlowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + /** @internal */ nodeCount = 0; + /** @internal */ identifierCount = 0; + /** @internal */ symbolCount = 0; + /** + * File-level diagnostics reported by the parser (includes diagnostics about /// references + * as well as code diagnostics). + * @internal + */ parseDiagnostics: DiagnosticWithLocation[] = undefined!; + /** + * File-level diagnostics reported by the binder. + * @internal + */ bindDiagnostics: DiagnosticWithLocation[] = undefined!; - bindSuggestionDiagnostics: DiagnosticWithLocation[] | undefined = undefined; - lineMap: readonly number[] = undefined!; + /** @internal */ bindSuggestionDiagnostics: DiagnosticWithLocation[] | undefined = undefined; + // Stores a line map for the file. + // This field should never be used directly to obtain line map, use getLineMap function instead. + /** @internal */ lineMap: readonly number[] = undefined!; + /** + * The first "most obvious" node that makes a file an external module. + * This is intended to be the first top-level import/export, + * but could be arbitrarily nested (e.g. `import.meta`). + * + * @internal + */ externalModuleIndicator: Node | true | undefined = undefined; - setExternalModuleIndicator?: ((file: ts.SourceFile) => void) | undefined = undefined; - pragmas: ReadonlyPragmaMap = undefined!; - checkJsDirective: CheckJsDirective | undefined = undefined; + /** + * The callback used to set the external module indicator - this is saved to + * be later reused during incremental reparsing, which otherwise lacks the information + * to set this field + * + * @internal + */ + setExternalModuleIndicator?: ((file: SourceFile) => void) | undefined = undefined; + /** @internal */ pragmas: ReadonlyPragmaMap = undefined!; + /** @internal */ checkJsDirective: CheckJsDirective | undefined = undefined; referencedFiles: readonly FileReference[] = undefined!; typeReferenceDirectives: readonly FileReference[] = undefined!; libReferenceDirectives: readonly FileReference[] = undefined!; amdDependencies: AmdDependency[] = undefined!; - commentDirectives: CommentDirective[] | undefined = undefined; + // Comments containing @ts-* directives, in order. + /** @internal */ commentDirectives: CommentDirective[] | undefined = undefined; + /** + * Map from a string to an interned string + * @internal + */ identifiers: Map = undefined!; - packageJsonLocations?: readonly string[] | undefined = undefined; - packageJsonScope?: PackageJsonInfo | undefined = undefined; - imports: readonly ts.StringLiteralLike[] = undefined!; - moduleAugmentations: readonly (ts.Identifier | ts.StringLiteral)[] = undefined!; - ambientModuleNames: readonly string[] = undefined!; - classifiableNames?: ReadonlySet<__String> | undefined = undefined; + /** @internal */ packageJsonLocations?: readonly string[] | undefined = undefined; + /** @internal */ packageJsonScope?: PackageJsonInfo | undefined = undefined; + /** @internal */ imports: readonly StringLiteralLike[] = undefined!; + // Identifier only if `declare global` + /** @internal */ moduleAugmentations: readonly (Identifier | StringLiteral)[] = undefined!; + /** @internal */ ambientModuleNames: readonly string[] = undefined!; + /** @internal */ classifiableNames?: ReadonlySet<__String> | undefined = undefined; + /** + * When `module` is `Node16` or `NodeNext`, this field controls whether the + * source file in question is an ESNext-output-format file, or a CommonJS-output-format + * module. This is derived by the module resolver as it looks up the file, since + * it is derived from either the file extension of the module, or the containing + * `package.json` context, and affects both checking and emit. + * + * It is _public_ so that (pre)transformers can set this field, + * since it switches the builtin `node` module transform. Generally speaking, if unset, + * the field is treated as though it is `ModuleKind.CommonJS`. + * + * Note that this field is only set by the module resolution process when + * `moduleResolution` is `Node16` or `NodeNext`, which is implied by the `module` setting + * of `Node16` or `NodeNext`, respectively, but may be overriden (eg, by a `moduleResolution` + * of `node`). If so, this field will be unset and source files will be considered to be + * CommonJS-output-format by the node module transformer and type checker, regardless of extension or context. + */ impliedNodeFormat: ResolutionMode | undefined = undefined; moduleName: string | undefined = undefined; + /** + * this map is used by transpiler to supply alternative names for dependencies (i.e. in case of bundling) + * @internal + */ renamedDependencies: Map = undefined!; + /** + * The first node that causes this file to be a CommonJS module + * @internal + */ commonJsModuleIndicator: Node | undefined = undefined; - version: string = undefined!; - redirectInfo?: ts.RedirectInfo | undefined = undefined; + /** @internal */ version: string = undefined!; + /** + * If two source files are for the same version of the same package, one will redirect to the other. + * (See `createRedirectSourceFile` in program.ts.) + * The redirect will have this set. The redirected-to source file will be in `redirectTargetsMap`. + * + * @internal + */ + redirectInfo?: RedirectInfo | undefined = undefined; + /** + * JS identifier-declarations that are intended to merge with globals + * @internal + */ jsGlobalAugmentations?: SymbolTable | undefined = undefined; - additionalSyntacticDiagnostics?: readonly DiagnosticWithLocation[] | undefined = undefined; - patternAmbientModules?: ts.PatternAmbientModule[] | undefined = undefined; - localJsxNamespace?: __String | undefined = undefined; - localJsxFragmentNamespace?: __String | undefined = undefined; - localJsxFactory?: ts.EntityName | undefined = undefined; - localJsxFragmentFactory?: ts.EntityName | undefined = undefined; - jsDocParsingMode?: ts.JSDocParsingMode | undefined = undefined; + // Stores additional file-level diagnostics reported by the program + /** @internal */ additionalSyntacticDiagnostics?: readonly DiagnosticWithLocation[] | undefined = undefined; + /** @internal */ patternAmbientModules?: PatternAmbientModule[] | undefined = undefined; + /** @internal */ localJsxNamespace?: __String | undefined = undefined; + /** @internal */ localJsxFragmentNamespace?: __String | undefined = undefined; + /** @internal */ localJsxFactory?: EntityName | undefined = undefined; + /** @internal */ localJsxFragmentFactory?: EntityName | undefined = undefined; + /** @internal */ jsDocParsingMode?: JSDocParsingMode | undefined = undefined; + /** + * File-level JSDoc diagnostics reported by the JSDoc parser + * @internal + */ jsDocDiagnostics: DiagnosticWithLocation[] | undefined = undefined; - namedDeclarations: Map | undefined = undefined; + namedDeclarations: Map | undefined = undefined; - // TODO: fix type - scriptSnapshot: any = undefined; - nameTable: Map<__String, number> | undefined = undefined; + /** @internal */ scriptSnapshot: IScriptSnapshot | undefined = undefined; + /** @internal */ nameTable: Map<__String, number> | undefined = undefined; // TsConfigSourceFile - extendedSourceFiles?: string[]; - configFileSpecs?: ts.ConfigFileSpecs; + /** @internal */ extendedSourceFiles?: string[]; + /** @internal */ configFileSpecs?: ConfigFileSpecs; - override computeTransformFlags(_: AstNode): TransformFlags { + /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.statements) | propagateChildFlags(this.endOfFileToken); } override cloneNode(node: AstNode): AstNode { if (this.redirectInfo) { - const clone = (this.redirectInfo.redirectTarget as SourceFile).ast.shadow() as AstSourceFile; + const clone = this.redirectInfo.redirectTarget.ast.shadow() as AstSourceFile; this.copyProperties(clone.data); clone.emitNode = undefined; return clone; @@ -13405,486 +4524,237 @@ export class AstSourceFileData extends AstData { } } -/** @internal */ export type AstToken = AstNode>; -/** @internal */ export type AstEndOfFileToken = AstNode; -/** @internal */ export type AstThisExpression = AstNode; -/** @internal */ export type AstSuperExpression = AstNode; -/** @internal */ export type AstImportExpression = AstNode; -/** @internal */ export type AstNullLiteral = AstNode; -/** @internal */ export type AstTrueLiteral = AstNode; -/** @internal */ export type AstFalseLiteral = AstNode; -/** @internal */ export type AstIdentifier = AstNode; -/** @internal */ export type AstQualifiedName = AstNode; -/** @internal */ export type AstComputedPropertyName = AstNode; -/** @internal */ export type AstPrivateIdentifier = AstNode; -/** @internal */ export type AstTypeParameterDeclaration = AstNode; -/** @internal */ export type AstParameterDeclaration = AstNode; -/** @internal */ export type AstDecorator = AstNode; -/** @internal */ export type AstPropertySignature = AstNode; -/** @internal */ export type AstCallSignatureDeclaration = AstNode; -/** @internal */ export type AstConstructSignatureDeclaration = AstNode; -/** @internal */ export type AstVariableDeclaration = AstNode; -/** @internal */ export type AstVariableDeclarationList = AstNode; -/** @internal */ export type AstBindingElement = AstNode; -/** @internal */ export type AstPropertyDeclaration = AstNode; -/** @internal */ export type AstPropertyAssignment = AstNode; -/** @internal */ export type AstShorthandPropertyAssignment = AstNode; -/** @internal */ export type AstSpreadAssignment = AstNode; -/** @internal */ export type AstObjectBindingPattern = AstNode; -/** @internal */ export type AstArrayBindingPattern = AstNode; -/** @internal */ export type AstFunctionDeclaration = AstNode; -/** @internal */ export type AstMethodSignature = AstNode; -/** @internal */ export type AstMethodDeclaration = AstNode; -/** @internal */ export type AstConstructorDeclaration = AstNode; -/** @internal */ export type AstSemicolonClassElement = AstNode; -/** @internal */ export type AstGetAccessorDeclaration = AstNode; -/** @internal */ export type AstSetAccessorDeclaration = AstNode; -/** @internal */ export type AstIndexSignatureDeclaration = AstNode; -/** @internal */ export type AstClassStaticBlockDeclaration = AstNode; -/** @internal */ export type AstImportTypeNode = AstNode; -/** @internal */ export type AstThisTypeNode = AstNode; -/** @internal */ export type AstFunctionTypeNode = AstNode; -/** @internal */ export type AstConstructorTypeNode = AstNode; -/** @internal */ export type AstTypeReferenceNode = AstNode; -/** @internal */ export type AstTypePredicateNode = AstNode; -/** @internal */ export type AstTypeQueryNode = AstNode; -/** @internal */ export type AstTypeLiteralNode = AstNode; -/** @internal */ export type AstArrayTypeNode = AstNode; -/** @internal */ export type AstTupleTypeNode = AstNode; -/** @internal */ export type AstNamedTupleMember = AstNode; -/** @internal */ export type AstOptionalTypeNode = AstNode; -/** @internal */ export type AstRestTypeNode = AstNode; -/** @internal */ export type AstUnionTypeNode = AstNode; -/** @internal */ export type AstIntersectionTypeNode = AstNode; -/** @internal */ export type AstConditionalTypeNode = AstNode; -/** @internal */ export type AstInferTypeNode = AstNode; -/** @internal */ export type AstParenthesizedTypeNode = AstNode; -/** @internal */ export type AstTypeOperatorNode = AstNode; -/** @internal */ export type AstIndexedAccessTypeNode = AstNode; -/** @internal */ export type AstMappedTypeNode = AstNode; -/** @internal */ export type AstLiteralTypeNode = AstNode; -/** @internal */ export type AstStringLiteral = AstNode; -/** @internal */ export type AstTemplateLiteralTypeNode = AstNode; -/** @internal */ export type AstTemplateLiteralTypeSpan = AstNode; -/** @internal */ export type AstOmittedExpression = AstNode; -/** @internal */ export type AstPrefixUnaryExpression = AstNode; -/** @internal */ export type AstPostfixUnaryExpression = AstNode; -/** @internal */ export type AstDeleteExpression = AstNode; -/** @internal */ export type AstTypeOfExpression = AstNode; -/** @internal */ export type AstVoidExpression = AstNode; -/** @internal */ export type AstAwaitExpression = AstNode; -/** @internal */ export type AstYieldExpression = AstNode; -/** @internal */ export type AstBinaryExpression = AstNode; -/** @internal */ export type AstConditionalExpression = AstNode; -/** @internal */ export type AstFunctionExpression = AstNode; -/** @internal */ export type AstArrowFunction = AstNode; -/** @internal */ export type AstRegularExpressionLiteral = AstNode; -/** @internal */ export type AstNoSubstitutionTemplateLiteral = AstNode; -/** @internal */ export type AstNumericLiteral = AstNode; -/** @internal */ export type AstBigIntLiteral = AstNode; -/** @internal */ export type AstTemplateHead = AstNode; -/** @internal */ export type AstTemplateMiddle = AstNode; -/** @internal */ export type AstTemplateTail = AstNode; -/** @internal */ export type AstTemplateExpression = AstNode; -/** @internal */ export type AstTemplateSpan = AstNode; -/** @internal */ export type AstParenthesizedExpression = AstNode; -/** @internal */ export type AstArrayLiteralExpression = AstNode; -/** @internal */ export type AstSpreadElement = AstNode; -/** @internal */ export type AstObjectLiteralExpression = AstNode; -/** @internal */ export type AstPropertyAccessExpression = AstNode; -/** @internal */ export type AstElementAccessExpression = AstNode; -/** @internal */ export type AstCallExpression = AstNode; -/** @internal */ export type AstExpressionWithTypeArguments = AstNode; -/** @internal */ export type AstNewExpression = AstNode; -/** @internal */ export type AstTaggedTemplateExpression = AstNode; -/** @internal */ export type AstAsExpression = AstNode; -/** @internal */ -export type AstTypeAssertion = AstNode; -/** @internal */ +export type AstTypeAssertion = AstNode; export type AstSatisfiesExpression = AstNode; -/** @internal */ export type AstNonNullExpression = AstNode; -/** @internal */ export type AstMetaProperty = AstNode; -/** @internal */ export type AstJsxElement = AstNode; -/** @internal */ export type AstJsxAttributes = AstNode; -/** @internal */ export type AstJsxNamespacedName = AstNode; -/** @internal */ export type AstJsxOpeningElement = AstNode; -/** @internal */ export type AstJsxSelfClosingElement = AstNode; -/** @internal */ export type AstJsxFragment = AstNode; -/** @internal */ export type AstJsxOpeningFragment = AstNode; -/** @internal */ export type AstJsxClosingFragment = AstNode; -/** @internal */ export type AstJsxAttribute = AstNode; -/** @internal */ export type AstJsxSpreadAttribute = AstNode; -/** @internal */ export type AstJsxClosingElement = AstNode; -/** @internal */ export type AstJsxExpression = AstNode; -/** @internal */ export type AstJsxText = AstNode; -/** @internal */ export type AstEmptyStatement = AstNode; -/** @internal */ export type AstDebuggerStatement = AstNode; -/** @internal */ export type AstMissingDeclaration = AstNode; -/** @internal */ export type AstBlock = AstNode; -/** @internal */ export type AstVariableStatement = AstNode; -/** @internal */ export type AstExpressionStatement = AstNode; -/** @internal */ export type AstIfStatement = AstNode; -/** @internal */ export type AstDoStatement = AstNode; -/** @internal */ export type AstWhileStatement = AstNode; -/** @internal */ export type AstForStatement = AstNode; -/** @internal */ export type AstForInStatement = AstNode; -/** @internal */ export type AstForOfStatement = AstNode; -/** @internal */ export type AstBreakStatement = AstNode; -/** @internal */ export type AstContinueStatement = AstNode; -/** @internal */ export type AstReturnStatement = AstNode; -/** @internal */ export type AstWithStatement = AstNode; -/** @internal */ export type AstSwitchStatement = AstNode; -/** @internal */ export type AstCaseBlock = AstNode; -/** @internal */ export type AstCaseClause = AstNode; -/** @internal */ export type AstDefaultClause = AstNode; -/** @internal */ export type AstLabeledStatement = AstNode; -/** @internal */ export type AstThrowStatement = AstNode; -/** @internal */ export type AstTryStatement = AstNode; -/** @internal */ export type AstCatchClause = AstNode; -/** @internal */ export type AstClassDeclaration = AstNode; -/** @internal */ export type AstClassExpression = AstNode; -/** @internal */ export type AstInterfaceDeclaration = AstNode; -/** @internal */ export type AstHeritageClause = AstNode; -/** @internal */ export type AstTypeAliasDeclaration = AstNode; -/** @internal */ export type AstEnumMember = AstNode; -/** @internal */ export type AstEnumDeclaration = AstNode; -/** @internal */ export type AstModuleDeclaration = AstNode; -/** @internal */ export type AstModuleBlock = AstNode; -/** @internal */ export type AstImportEqualsDeclaration = AstNode; -/** @internal */ export type AstExternalModuleReference = AstNode; -/** @internal */ export type AstImportDeclaration = AstNode; -/** @internal */ export type AstImportClause = AstNode; -/** @internal */ export type AstImportAttribute = AstNode; -/** @internal */ export type AstImportAttributes = AstNode; -/** @internal */ export type AstNamespaceImport = AstNode; -/** @internal */ export type AstNamespaceExport = AstNode; -/** @internal */ export type AstNamespaceExportDeclaration = AstNode; -/** @internal */ export type AstExportDeclaration = AstNode; -/** @internal */ export type AstNamedImports = AstNode; -/** @internal */ export type AstNamedExports = AstNode; -/** @internal */ export type AstImportSpecifier = AstNode; -/** @internal */ export type AstExportSpecifier = AstNode; -/** @internal */ export type AstExportAssignment = AstNode; -/** @internal */ export type AstJSDocTypeExpression = AstNode; -/** @internal */ export type AstJSDocNameReference = AstNode; -/** @internal */ export type AstJSDocMemberName = AstNode; -/** @internal */ export type AstJSDocAllType = AstNode; -/** @internal */ export type AstJSDocUnknownType = AstNode; -/** @internal */ export type AstJSDocNonNullableType = AstNode; -/** @internal */ export type AstJSDocNullableType = AstNode; -/** @internal */ export type AstJSDocOptionalType = AstNode; -/** @internal */ export type AstJSDocFunctionType = AstNode; -/** @internal */ export type AstJSDocVariadicType = AstNode; -/** @internal */ export type AstJSDocNamepathType = AstNode; -/** @internal */ export type AstJSDoc = AstNode; -/** @internal */ export type AstJSDocLink = AstNode; -/** @internal */ export type AstJSDocLinkCode = AstNode; -/** @internal */ export type AstJSDocLinkPlain = AstNode; -/** @internal */ export type AstJSDocText = AstNode; -/** @internal */ export type AstJSDocUnknownTag = AstNode; -/** @internal */ export type AstJSDocAugmentsTag = AstNode; -/** @internal */ export type AstJSDocImplementsTag = AstNode; -/** @internal */ export type AstJSDocAuthorTag = AstNode; -/** @internal */ export type AstJSDocDeprecatedTag = AstNode; -/** @internal */ export type AstJSDocClassTag = AstNode; -/** @internal */ export type AstJSDocPublicTag = AstNode; -/** @internal */ export type AstJSDocPrivateTag = AstNode; -/** @internal */ export type AstJSDocProtectedTag = AstNode; -/** @internal */ export type AstJSDocReadonlyTag = AstNode; -/** @internal */ export type AstJSDocOverrideTag = AstNode; -/** @internal */ export type AstJSDocEnumTag = AstNode; -/** @internal */ export type AstJSDocThisTag = AstNode; -/** @internal */ export type AstJSDocTemplateTag = AstNode; -/** @internal */ export type AstJSDocSeeTag = AstNode; -/** @internal */ export type AstJSDocReturnTag = AstNode; -/** @internal */ export type AstJSDocTypeTag = AstNode; -/** @internal */ export type AstJSDocTypedefTag = AstNode; -/** @internal */ export type AstJSDocCallbackTag = AstNode; -/** @internal */ export type AstJSDocOverloadTag = AstNode; -/** @internal */ export type AstJSDocThrowsTag = AstNode; -/** @internal */ export type AstJSDocSignature = AstNode; -/** @internal */ export type AstJSDocPropertyTag = AstNode; -/** @internal */ export type AstJSDocParameterTag = AstNode; -/** @internal */ export type AstJSDocTypeLiteral = AstNode; -/** @internal */ export type AstJSDocSatisfiesTag = AstNode; -/** @internal */ export type AstJSDocImportTag = AstNode; -/** @internal */ export type AstSourceFile = AstNode; -/** @internal */ export type AstSyntheticExpression = AstNode; -/** @internal */ export type AstBundle = AstNode; -/** @internal */ export type AstSyntaxList = AstNode; -/** @internal */ export type AstNotEmittedStatement = AstNode; -/** @internal */ export type AstNotEmittedTypeElement = AstNode; -/** @internal */ export type AstPartiallyEmittedExpression = AstNode; -/** @internal */ export type AstCommaListExpression = AstNode; /** @internal */ export type AstSyntheticReferenceExpression = AstNode; // JSON -/** @internal */ -export interface JsonMinusNumericLiteral extends PrefixUnaryExpression { - readonly ast: AstJsonMinusNumericLiteral; - readonly data: AstJsonMinusNumericLiteralData; - - readonly operator: SyntaxKind.MinusToken; - readonly operand: NumericLiteral; -} - -/** @internal */ export interface AstJsonMinusNumericLiteralData extends AstPrefixUnaryExpressionData { operator: SyntaxKind.MinusToken; operand: AstNumericLiteral; } -/** @internal */ export type AstJsonMinusNumericLiteral = AstNode; -/** @internal */ -export type JsonObjectExpression = - | ObjectLiteralExpression - | ArrayLiteralExpression - | JsonMinusNumericLiteral - | NumericLiteral - | StringLiteral - | BooleanLiteral - | NullLiteral; - -/** @internal */ export type AstJsonObjectExpression = AstNodeOneOf; -/** @internal */ -export interface JsonObjectExpressionStatement extends ExpressionStatement { - readonly ast: AstJsonObjectExpressionStatement; - readonly data: AstJsonObjectExpressionStatementData; - readonly expression: JsonObjectExpression; -} - -/** @internal */ export type AstJsonObjectExpressionStatement = AstNode; -/** @internal */ export interface AstJsonObjectExpressionStatementData extends AstExpressionStatementData { expression: AstJsonObjectExpression; } -/** @internal */ -export interface JsonSourceFile extends SourceFile { - readonly ast: AstJsonSourceFile; - readonly data: AstJsonSourceFileData; - readonly statements: NodeArray; -} - -/** @internal */ export type AstJsonSourceFile = AstNode; -/** @internal */ export interface AstJsonSourceFileData extends AstSourceFileData { statements: AstNodeArray; } @@ -13905,7 +4775,7 @@ function propagatePropertyNameFlagsOfChild(node: AstPropertyName, transformFlags function propagateChildFlags(child: AstNode | undefined): TransformFlags { if (!child) return TransformFlags.None; const childFlags = child.transformFlags & ~getTransformFlagsSubtreeExclusions(child.kind); - return isNamedDeclaration(child) && child.data.name && isAstPropertyName(child.data.name) ? propagatePropertyNameFlagsOfChild(child.data.name, childFlags) : childFlags; + return astCanHaveName(child) && child.data.name && isAstPropertyName(child.data.name) ? propagatePropertyNameFlagsOfChild(child.data.name, childFlags) : childFlags; } function propagateChildrenFlags(children: AstNodeArray | undefined): TransformFlags { @@ -13926,69 +4796,57 @@ function getTransformFlagsOfTemplateLiteralLike(templateFlags: TokenFlags) { } /** @internal */ -export type NamedDeclaration = - | FunctionDeclaration - | FunctionExpression - | ClassExpression - | ClassDeclaration - | MethodDeclaration - | GetAccessorDeclaration - | SetAccessorDeclaration - | PropertyDeclaration - | InterfaceDeclaration - | MethodSignature - | PropertySignature - | TypeAliasDeclaration - | EnumDeclaration - | EnumMember - | ModuleDeclaration - | VariableDeclaration - | ParameterDeclaration - | BindingElement - | TypeParameterDeclaration - | ImportEqualsDeclaration - | NamespaceExportDeclaration - | ImportClause - | NamespaceImport - | NamespaceExport - | ImportSpecifier - | ExportSpecifier - | JSDocTypedefTag - | JSDocCallbackTag; +export type AstNamedDeclaration = AstNodeOneOf; /** @internal */ -export type AstNamedDeclaration = AstNodeOneOf; +export type AstHasName = AstNodeOneOf; -function isNamedDeclaration(node: AstNode): node is AstNamedDeclaration { +function astCanHaveName(node: AstNode): node is AstHasName { switch (node.kind) { + case SyntaxKind.BindingElement: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.EnumMember: + case SyntaxKind.ExportSpecifier: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: - case SyntaxKind.ClassExpression: - case SyntaxKind.ClassDeclaration: - case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.PropertyDeclaration: + case SyntaxKind.ImportAttribute: + case SyntaxKind.ImportClause: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ImportSpecifier: case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.JSDocCallbackTag: + case SyntaxKind.JSDocLink: + case SyntaxKind.JSDocLinkCode: + case SyntaxKind.JSDocLinkPlain: + case SyntaxKind.JSDocNameReference: + case SyntaxKind.JSDocParameterTag: + case SyntaxKind.JSDocPropertyTag: + case SyntaxKind.JSDocSeeTag: + case SyntaxKind.JSDocTypedefTag: + case SyntaxKind.JsxAttribute: + case SyntaxKind.JsxNamespacedName: + case SyntaxKind.MetaProperty: + case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - case SyntaxKind.PropertySignature: - case SyntaxKind.TypeAliasDeclaration: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.EnumMember: + case SyntaxKind.MissingDeclaration: case SyntaxKind.ModuleDeclaration: - case SyntaxKind.VariableDeclaration: - case SyntaxKind.Parameter: - case SyntaxKind.BindingElement: - case SyntaxKind.TypeParameter: - case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.NamedTupleMember: + case SyntaxKind.NamespaceExport: case SyntaxKind.NamespaceExportDeclaration: - case SyntaxKind.ImportClause: case SyntaxKind.NamespaceImport: - case SyntaxKind.NamespaceExport: - case SyntaxKind.ImportSpecifier: - case SyntaxKind.ExportSpecifier: - case SyntaxKind.JSDocTypedefTag: - case SyntaxKind.JSDocCallbackTag: + case SyntaxKind.Parameter: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.PropertyAssignment: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.SetAccessor: + case SyntaxKind.ShorthandPropertyAssignment: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.TypeParameter: + case SyntaxKind.VariableDeclaration: return true; } return false; @@ -14029,105 +4887,6 @@ function isNoSubstitutionTemplateLiteral(template: AstTemplateLiteral): template return template.kind === SyntaxKind.NoSubstitutionTemplateLiteral; } -// copied from services/utilities.ts -function getNameFromPropertyName(name: ts.PropertyName): string | undefined { - return name.kind === SyntaxKind.ComputedPropertyName - // treat computed property names where expression is string/numeric literal as just string/numeric literal - ? isStringOrNumericLiteralLike(name.expression) ? name.expression.text : undefined - : isPrivateIdentifier(name) ? idText(name) : getTextOfIdentifierOrLiteral(name); -} - -// copied form services/services.ts -let _scanner: Scanner | undefined; - -function scanner() { - _scanner ??= createScanner(ScriptTarget.Latest, /*skipTrivia*/ true); - return _scanner; -} - -function createChildren(node: Node, sourceFile: ts.SourceFileLike | undefined): readonly ts.Node[] { - const children: ts.Node[] = []; - - if (isJSDocCommentContainingNode(node)) { - /** Don't add trivia for "tokens" since this is in a comment. */ - node.forEachChild(child => { - children.push(child); - }); - return children; - } - - scanner().setText((sourceFile || node.getSourceFile()).text); - let pos = node.pos; - const processNode = (child: ts.Node) => { - addSyntheticNodes(children, pos, child.pos, node); - children.push(child); - pos = child.end; - }; - const processNodes = (nodes: ts.NodeArray) => { - addSyntheticNodes(children, pos, nodes.pos, node); - children.push(createSyntaxList(nodes, node)); - pos = nodes.end; - }; - // jsDocComments need to be the first children - forEach((node as ts.Node as ts.JSDocContainer).jsDoc, processNode); - // For syntactic classifications, all trivia are classified together, including jsdoc comments. - // For that to work, the jsdoc comments should still be the leading trivia of the first child. - // Restoring the scanner position ensures that. - pos = node.pos; - node.forEachChild(processNode, processNodes); - addSyntheticNodes(children, pos, node.end, node); - scanner().setText(undefined); - return children; -} - -function createNode(kind: TKind, pos: number, end: number, parent: ts.Node): ts.Node { - const astNode = kind === SyntaxKind.StringLiteral ? AstNode.StringLiteral() : AstNode.Token(kind); - astNode.pos = pos; - astNode.end = end; - astNode.parent = (parent as Node).ast; - astNode.flags = parent.flags & NodeFlags.ContextFlags; - return astNode.node; -} - -function addSyntheticNodes(nodes: ts.Node[], pos: number, end: number, parent: ts.Node): void { - scanner().resetTokenState(pos); - while (pos < end) { - const token = scanner().scan(); - const textPos = scanner().getTokenEnd(); - if (textPos <= end) { - Debug.assert(ts.isTokenKind(token)); - if (token === SyntaxKind.Identifier) { - if (hasTabstop(parent)) { - continue; - } - Debug.fail(`Did not expect ${Debug.formatSyntaxKind(parent.kind)} to have an ${Debug.formatSyntaxKind(token)} in its trivia`); - } - nodes.push(createNode(token as TokenSyntaxKind, pos, textPos, parent)); - } - pos = textPos; - if (token === SyntaxKind.EndOfFileToken) { - break; - } - } -} - -function createSyntaxList(nodes: ts.NodeArray, parent: ts.Node): ts.Node { - const list = AstNode.SyntaxList(); - list.pos = nodes.pos; - list.end = nodes.end; - list.parent = (parent as Node).ast; - const children: ts.Node[] = []; - let pos = nodes.pos; - for (const node of nodes) { - addSyntheticNodes(children, pos, node.pos, parent); - children.push(node); - pos = node.end; - } - addSyntheticNodes(children, pos, nodes.end, parent); - list.data._children = children as Node[]; - return list.node; -} - /** @internal */ export function getAstSourceFileNodeOfNode(node: AstNode | undefined): AstSourceFile | undefined { while (node && node.kind !== SyntaxKind.SourceFile) { @@ -14142,7 +4901,7 @@ export function getAstParseTreeNode(node: AstNode | undefined, nodeTest?: (node: return node; } while (node) { - if (ts.isParseTreeNode(node)) { + if (isParseTreeNode(node)) { return !nodeTest || nodeTest(node) ? node : undefined; } node = node.original; @@ -14154,776 +4913,38 @@ export function getAstParseTreeNode(node: AstNode | undefined, nodeTest?: (node: export function isAstJSDocTypeAssertion(node: AstNode): node is AstJSDocTypeAssertion { return isAstParenthesizedExpression(node) && !!(node.flags & NodeFlags.JavaScriptFile) - && !!ts.getJSDocTypeTag(node.node); // TODO: don't invoke node + && !!getJSDocTypeTag(node.node); // TODO: don't invoke node } -/** @internal */ -export type OuterExpression = - | ParenthesizedExpression - | TypeAssertion - | SatisfiesExpression - | AsExpression - | NonNullExpression - | ExpressionWithTypeArguments - | PartiallyEmittedExpression; - /** @internal */ export type AstOuterExpression = AstNodeOneOf; /** @internal */ -export function isAstOuterExpression(node: AstNode, kinds: ts.OuterExpressionKinds = ts.OuterExpressionKinds.All): node is AstOuterExpression { +export function isAstOuterExpression(node: AstNode, kinds: OuterExpressionKinds = OuterExpressionKinds.All): node is AstOuterExpression { switch (node.kind) { case SyntaxKind.ParenthesizedExpression: - if (kinds & ts.OuterExpressionKinds.ExcludeJSDocTypeAssertion && isAstJSDocTypeAssertion(node)) { + if (kinds & OuterExpressionKinds.ExcludeJSDocTypeAssertion && isAstJSDocTypeAssertion(node)) { return false; } - return (kinds & ts.OuterExpressionKinds.Parentheses) !== 0; + return (kinds & OuterExpressionKinds.Parentheses) !== 0; case SyntaxKind.TypeAssertionExpression: case SyntaxKind.AsExpression: case SyntaxKind.SatisfiesExpression: - return (kinds & ts.OuterExpressionKinds.TypeAssertions) !== 0; + return (kinds & OuterExpressionKinds.TypeAssertions) !== 0; case SyntaxKind.ExpressionWithTypeArguments: - return (kinds & ts.OuterExpressionKinds.ExpressionsWithTypeArguments) !== 0; + return (kinds & OuterExpressionKinds.ExpressionsWithTypeArguments) !== 0; case SyntaxKind.NonNullExpression: - return (kinds & ts.OuterExpressionKinds.NonNullAssertions) !== 0; + return (kinds & OuterExpressionKinds.NonNullAssertions) !== 0; case SyntaxKind.PartiallyEmittedExpression: - return (kinds & ts.OuterExpressionKinds.PartiallyEmittedExpressions) !== 0; + return (kinds & OuterExpressionKinds.PartiallyEmittedExpressions) !== 0; } return false; } /** @internal */ -export function skipAstOuterExpressions(node: AstNode, kinds: ts.OuterExpressionKinds = ts.OuterExpressionKinds.All): AstNode { +export function skipAstOuterExpressions(node: AstNode, kinds: OuterExpressionKinds = OuterExpressionKinds.All): AstNode { while (isAstOuterExpression(node, kinds)) { node = node.data.expression; } return node; } - -/** @internal */ -export interface NodeType { - [SyntaxKind.Unknown]: Token; - [SyntaxKind.EndOfFileToken]: EndOfFileToken; - [SyntaxKind.SingleLineCommentTrivia]: Token; - [SyntaxKind.MultiLineCommentTrivia]: Token; - [SyntaxKind.NewLineTrivia]: Token; - [SyntaxKind.WhitespaceTrivia]: Token; - [SyntaxKind.ShebangTrivia]: Token; - [SyntaxKind.ConflictMarkerTrivia]: Token; - [SyntaxKind.NonTextFileMarkerTrivia]: never; - [SyntaxKind.NumericLiteral]: NumericLiteral; - [SyntaxKind.BigIntLiteral]: BigIntLiteral; - [SyntaxKind.StringLiteral]: StringLiteral; - [SyntaxKind.JsxText]: JsxText; - [SyntaxKind.JsxTextAllWhiteSpaces]: never; - [SyntaxKind.RegularExpressionLiteral]: RegularExpressionLiteral; - [SyntaxKind.NoSubstitutionTemplateLiteral]: NoSubstitutionTemplateLiteral; - [SyntaxKind.TemplateHead]: TemplateHead; - [SyntaxKind.TemplateMiddle]: TemplateMiddle; - [SyntaxKind.TemplateTail]: TemplateTail; - [SyntaxKind.OpenBraceToken]: Token; - [SyntaxKind.CloseBraceToken]: Token; - [SyntaxKind.OpenParenToken]: Token; - [SyntaxKind.CloseParenToken]: Token; - [SyntaxKind.OpenBracketToken]: Token; - [SyntaxKind.CloseBracketToken]: Token; - [SyntaxKind.DotToken]: Token; - [SyntaxKind.DotDotDotToken]: Token; - [SyntaxKind.SemicolonToken]: Token; - [SyntaxKind.CommaToken]: Token; - [SyntaxKind.QuestionDotToken]: Token; - [SyntaxKind.LessThanToken]: Token; - [SyntaxKind.LessThanSlashToken]: Token; - [SyntaxKind.GreaterThanToken]: Token; - [SyntaxKind.LessThanEqualsToken]: Token; - [SyntaxKind.GreaterThanEqualsToken]: Token; - [SyntaxKind.EqualsEqualsToken]: Token; - [SyntaxKind.ExclamationEqualsToken]: Token; - [SyntaxKind.EqualsEqualsEqualsToken]: Token; - [SyntaxKind.ExclamationEqualsEqualsToken]: Token; - [SyntaxKind.EqualsGreaterThanToken]: Token; - [SyntaxKind.PlusToken]: Token; - [SyntaxKind.MinusToken]: Token; - [SyntaxKind.AsteriskToken]: Token; - [SyntaxKind.AsteriskAsteriskToken]: Token; - [SyntaxKind.SlashToken]: Token; - [SyntaxKind.PercentToken]: Token; - [SyntaxKind.PlusPlusToken]: Token; - [SyntaxKind.MinusMinusToken]: Token; - [SyntaxKind.LessThanLessThanToken]: Token; - [SyntaxKind.GreaterThanGreaterThanToken]: Token; - [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: Token; - [SyntaxKind.AmpersandToken]: Token; - [SyntaxKind.BarToken]: Token; - [SyntaxKind.CaretToken]: Token; - [SyntaxKind.ExclamationToken]: Token; - [SyntaxKind.TildeToken]: Token; - [SyntaxKind.AmpersandAmpersandToken]: Token; - [SyntaxKind.BarBarToken]: Token; - [SyntaxKind.QuestionToken]: Token; - [SyntaxKind.ColonToken]: Token; - [SyntaxKind.AtToken]: Token; - [SyntaxKind.QuestionQuestionToken]: Token; - [SyntaxKind.BacktickToken]: Token; - [SyntaxKind.HashToken]: Token; - [SyntaxKind.EqualsToken]: Token; - [SyntaxKind.PlusEqualsToken]: Token; - [SyntaxKind.MinusEqualsToken]: Token; - [SyntaxKind.AsteriskEqualsToken]: Token; - [SyntaxKind.AsteriskAsteriskEqualsToken]: Token; - [SyntaxKind.SlashEqualsToken]: Token; - [SyntaxKind.PercentEqualsToken]: Token; - [SyntaxKind.LessThanLessThanEqualsToken]: Token; - [SyntaxKind.GreaterThanGreaterThanEqualsToken]: Token; - [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: Token; - [SyntaxKind.AmpersandEqualsToken]: Token; - [SyntaxKind.BarEqualsToken]: Token; - [SyntaxKind.BarBarEqualsToken]: Token; - [SyntaxKind.AmpersandAmpersandEqualsToken]: Token; - [SyntaxKind.QuestionQuestionEqualsToken]: Token; - [SyntaxKind.CaretEqualsToken]: Token; - [SyntaxKind.Identifier]: Identifier; - [SyntaxKind.PrivateIdentifier]: PrivateIdentifier; - [SyntaxKind.JSDocCommentTextToken]: never; - [SyntaxKind.BreakKeyword]: Token; - [SyntaxKind.CaseKeyword]: Token; - [SyntaxKind.CatchKeyword]: Token; - [SyntaxKind.ClassKeyword]: Token; - [SyntaxKind.ConstKeyword]: Token; - [SyntaxKind.ContinueKeyword]: Token; - [SyntaxKind.DebuggerKeyword]: Token; - [SyntaxKind.DefaultKeyword]: Token; - [SyntaxKind.DeleteKeyword]: Token; - [SyntaxKind.DoKeyword]: Token; - [SyntaxKind.ElseKeyword]: Token; - [SyntaxKind.EnumKeyword]: Token; - [SyntaxKind.ExportKeyword]: Token; - [SyntaxKind.ExtendsKeyword]: Token; - [SyntaxKind.FalseKeyword]: FalseLiteral; - [SyntaxKind.FinallyKeyword]: Token; - [SyntaxKind.ForKeyword]: Token; - [SyntaxKind.FunctionKeyword]: Token; - [SyntaxKind.IfKeyword]: Token; - [SyntaxKind.ImportKeyword]: ImportExpression; - [SyntaxKind.InKeyword]: Token; - [SyntaxKind.InstanceOfKeyword]: Token; - [SyntaxKind.NewKeyword]: Token; - [SyntaxKind.NullKeyword]: NullLiteral; - [SyntaxKind.ReturnKeyword]: Token; - [SyntaxKind.SuperKeyword]: SuperExpression; - [SyntaxKind.SwitchKeyword]: Token; - [SyntaxKind.ThisKeyword]: ThisExpression; - [SyntaxKind.ThrowKeyword]: Token; - [SyntaxKind.TrueKeyword]: TrueLiteral; - [SyntaxKind.TryKeyword]: Token; - [SyntaxKind.TypeOfKeyword]: Token; - [SyntaxKind.VarKeyword]: Token; - [SyntaxKind.VoidKeyword]: Token; - [SyntaxKind.WhileKeyword]: Token; - [SyntaxKind.WithKeyword]: Token; - [SyntaxKind.ImplementsKeyword]: Token; - [SyntaxKind.InterfaceKeyword]: Token; - [SyntaxKind.LetKeyword]: Token; - [SyntaxKind.PackageKeyword]: Token; - [SyntaxKind.PrivateKeyword]: Token; - [SyntaxKind.ProtectedKeyword]: Token; - [SyntaxKind.PublicKeyword]: Token; - [SyntaxKind.StaticKeyword]: Token; - [SyntaxKind.YieldKeyword]: Token; - [SyntaxKind.AbstractKeyword]: Token; - [SyntaxKind.AccessorKeyword]: Token; - [SyntaxKind.AsKeyword]: Token; - [SyntaxKind.AssertsKeyword]: Token; - [SyntaxKind.AssertKeyword]: Token; - [SyntaxKind.AnyKeyword]: Token; - [SyntaxKind.AsyncKeyword]: Token; - [SyntaxKind.AwaitKeyword]: Token; - [SyntaxKind.BooleanKeyword]: Token; - [SyntaxKind.ConstructorKeyword]: Token; - [SyntaxKind.DeclareKeyword]: Token; - [SyntaxKind.GetKeyword]: Token; - [SyntaxKind.InferKeyword]: Token; - [SyntaxKind.IntrinsicKeyword]: Token; - [SyntaxKind.IsKeyword]: Token; - [SyntaxKind.KeyOfKeyword]: Token; - [SyntaxKind.ModuleKeyword]: Token; - [SyntaxKind.NamespaceKeyword]: Token; - [SyntaxKind.NeverKeyword]: Token; - [SyntaxKind.OutKeyword]: Token; - [SyntaxKind.ReadonlyKeyword]: Token; - [SyntaxKind.RequireKeyword]: Token; - [SyntaxKind.NumberKeyword]: Token; - [SyntaxKind.ObjectKeyword]: Token; - [SyntaxKind.SatisfiesKeyword]: Token; - [SyntaxKind.SetKeyword]: Token; - [SyntaxKind.StringKeyword]: Token; - [SyntaxKind.SymbolKeyword]: Token; - [SyntaxKind.TypeKeyword]: Token; - [SyntaxKind.UndefinedKeyword]: Token; - [SyntaxKind.UniqueKeyword]: Token; - [SyntaxKind.UnknownKeyword]: Token; - [SyntaxKind.UsingKeyword]: Token; - [SyntaxKind.FromKeyword]: Token; - [SyntaxKind.GlobalKeyword]: Token; - [SyntaxKind.BigIntKeyword]: Token; - [SyntaxKind.OverrideKeyword]: Token; - [SyntaxKind.OfKeyword]: Token; - [SyntaxKind.QualifiedName]: QualifiedName; - [SyntaxKind.ComputedPropertyName]: ComputedPropertyName; - [SyntaxKind.Decorator]: Decorator; - [SyntaxKind.TypeParameter]: TypeParameterDeclaration; - [SyntaxKind.CallSignature]: CallSignatureDeclaration; - [SyntaxKind.ConstructSignature]: ConstructSignatureDeclaration; - [SyntaxKind.VariableDeclaration]: VariableDeclaration; - [SyntaxKind.VariableDeclarationList]: VariableDeclarationList; - [SyntaxKind.Parameter]: ParameterDeclaration; - [SyntaxKind.BindingElement]: BindingElement; - [SyntaxKind.PropertySignature]: PropertySignature; - [SyntaxKind.PropertyDeclaration]: PropertyDeclaration; - [SyntaxKind.PropertyAssignment]: PropertyAssignment; - [SyntaxKind.ShorthandPropertyAssignment]: ShorthandPropertyAssignment; - [SyntaxKind.SpreadAssignment]: SpreadAssignment; - [SyntaxKind.ObjectBindingPattern]: ObjectBindingPattern; - [SyntaxKind.ArrayBindingPattern]: ArrayBindingPattern; - [SyntaxKind.FunctionDeclaration]: FunctionDeclaration; - [SyntaxKind.MethodSignature]: MethodSignature; - [SyntaxKind.MethodDeclaration]: MethodDeclaration; - [SyntaxKind.Constructor]: ConstructorDeclaration; - [SyntaxKind.SemicolonClassElement]: SemicolonClassElement; - [SyntaxKind.GetAccessor]: GetAccessorDeclaration; - [SyntaxKind.SetAccessor]: SetAccessorDeclaration; - [SyntaxKind.IndexSignature]: IndexSignatureDeclaration; - [SyntaxKind.ClassStaticBlockDeclaration]: ClassStaticBlockDeclaration; - [SyntaxKind.ImportTypeAssertionContainer]: ImportTypeAssertionContainer; - [SyntaxKind.ImportType]: ImportTypeNode; - [SyntaxKind.ThisType]: ThisTypeNode; - [SyntaxKind.FunctionType]: FunctionTypeNode; - [SyntaxKind.ConstructorType]: ConstructorTypeNode; - [SyntaxKind.TypeReference]: TypeReferenceNode; - [SyntaxKind.TypePredicate]: TypePredicateNode; - [SyntaxKind.TypeQuery]: TypeQueryNode; - [SyntaxKind.TypeLiteral]: TypeLiteralNode; - [SyntaxKind.ArrayType]: ArrayTypeNode; - [SyntaxKind.TupleType]: TupleTypeNode; - [SyntaxKind.NamedTupleMember]: NamedTupleMember; - [SyntaxKind.OptionalType]: OptionalTypeNode; - [SyntaxKind.RestType]: RestTypeNode; - [SyntaxKind.UnionType]: UnionTypeNode; - [SyntaxKind.IntersectionType]: IntersectionTypeNode; - [SyntaxKind.ConditionalType]: ConditionalTypeNode; - [SyntaxKind.InferType]: InferTypeNode; - [SyntaxKind.ParenthesizedType]: ParenthesizedTypeNode; - [SyntaxKind.TypeOperator]: TypeOperatorNode; - [SyntaxKind.IndexedAccessType]: IndexedAccessTypeNode; - [SyntaxKind.MappedType]: MappedTypeNode; - [SyntaxKind.LiteralType]: LiteralTypeNode; - [SyntaxKind.TemplateLiteralType]: TemplateLiteralTypeNode; - [SyntaxKind.TemplateLiteralTypeSpan]: TemplateLiteralTypeSpan; - [SyntaxKind.OmittedExpression]: OmittedExpression; - [SyntaxKind.PrefixUnaryExpression]: PrefixUnaryExpression; - [SyntaxKind.PostfixUnaryExpression]: PostfixUnaryExpression; - [SyntaxKind.DeleteExpression]: DeleteExpression; - [SyntaxKind.TypeOfExpression]: TypeOfExpression; - [SyntaxKind.VoidExpression]: VoidExpression; - [SyntaxKind.AwaitExpression]: AwaitExpression; - [SyntaxKind.YieldExpression]: YieldExpression; - [SyntaxKind.BinaryExpression]: BinaryExpression; - [SyntaxKind.ConditionalExpression]: ConditionalExpression; - [SyntaxKind.FunctionExpression]: FunctionExpression; - [SyntaxKind.ArrowFunction]: ArrowFunction; - [SyntaxKind.TemplateExpression]: TemplateExpression; - [SyntaxKind.TemplateSpan]: TemplateSpan; - [SyntaxKind.ParenthesizedExpression]: ParenthesizedExpression; - [SyntaxKind.ArrayLiteralExpression]: ArrayLiteralExpression; - [SyntaxKind.SpreadElement]: SpreadElement; - [SyntaxKind.ObjectLiteralExpression]: ObjectLiteralExpression; - [SyntaxKind.PropertyAccessExpression]: PropertyAccessExpression; - [SyntaxKind.ElementAccessExpression]: ElementAccessExpression; - [SyntaxKind.CallExpression]: CallExpression; - [SyntaxKind.ExpressionWithTypeArguments]: ExpressionWithTypeArguments; - [SyntaxKind.NewExpression]: NewExpression; - [SyntaxKind.TaggedTemplateExpression]: TaggedTemplateExpression; - [SyntaxKind.AsExpression]: AsExpression; - [SyntaxKind.TypeAssertionExpression]: TypeAssertion; - [SyntaxKind.SyntheticExpression]: SyntheticExpression; - [SyntaxKind.SatisfiesExpression]: SatisfiesExpression; - [SyntaxKind.NonNullExpression]: NonNullExpression; - [SyntaxKind.MetaProperty]: MetaProperty; - [SyntaxKind.JsxElement]: JsxElement; - [SyntaxKind.JsxAttributes]: JsxAttributes; - [SyntaxKind.JsxNamespacedName]: JsxNamespacedName; - [SyntaxKind.JsxOpeningElement]: JsxOpeningElement; - [SyntaxKind.JsxSelfClosingElement]: JsxSelfClosingElement; - [SyntaxKind.JsxFragment]: JsxFragment; - [SyntaxKind.JsxOpeningFragment]: JsxOpeningFragment; - [SyntaxKind.JsxClosingFragment]: JsxClosingFragment; - [SyntaxKind.JsxAttribute]: JsxAttribute; - [SyntaxKind.JsxSpreadAttribute]: JsxSpreadAttribute; - [SyntaxKind.JsxClosingElement]: JsxClosingElement; - [SyntaxKind.JsxExpression]: JsxExpression; - [SyntaxKind.EmptyStatement]: EmptyStatement; - [SyntaxKind.DebuggerStatement]: DebuggerStatement; - [SyntaxKind.MissingDeclaration]: MissingDeclaration; - [SyntaxKind.Block]: Block; - [SyntaxKind.VariableStatement]: VariableStatement; - [SyntaxKind.ExpressionStatement]: ExpressionStatement; - [SyntaxKind.IfStatement]: IfStatement; - [SyntaxKind.DoStatement]: DoStatement; - [SyntaxKind.WhileStatement]: WhileStatement; - [SyntaxKind.ForStatement]: ForStatement; - [SyntaxKind.ForInStatement]: ForInStatement; - [SyntaxKind.ForOfStatement]: ForOfStatement; - [SyntaxKind.BreakStatement]: BreakStatement; - [SyntaxKind.ContinueStatement]: ContinueStatement; - [SyntaxKind.ReturnStatement]: ReturnStatement; - [SyntaxKind.WithStatement]: WithStatement; - [SyntaxKind.SwitchStatement]: SwitchStatement; - [SyntaxKind.CaseBlock]: CaseBlock; - [SyntaxKind.CaseClause]: CaseClause; - [SyntaxKind.DefaultClause]: DefaultClause; - [SyntaxKind.LabeledStatement]: LabeledStatement; - [SyntaxKind.ThrowStatement]: ThrowStatement; - [SyntaxKind.TryStatement]: TryStatement; - [SyntaxKind.CatchClause]: CatchClause; - [SyntaxKind.ClassDeclaration]: ClassDeclaration; - [SyntaxKind.ClassExpression]: ClassExpression; - [SyntaxKind.InterfaceDeclaration]: InterfaceDeclaration; - [SyntaxKind.HeritageClause]: HeritageClause; - [SyntaxKind.TypeAliasDeclaration]: TypeAliasDeclaration; - [SyntaxKind.EnumMember]: EnumMember; - [SyntaxKind.EnumDeclaration]: EnumDeclaration; - [SyntaxKind.ModuleDeclaration]: ModuleDeclaration; - [SyntaxKind.ModuleBlock]: ModuleBlock; - [SyntaxKind.ImportEqualsDeclaration]: ImportEqualsDeclaration; - [SyntaxKind.ExternalModuleReference]: ExternalModuleReference; - [SyntaxKind.ImportDeclaration]: ImportDeclaration; - [SyntaxKind.ImportClause]: ImportClause; - [SyntaxKind.ImportAttribute]: ImportAttribute; - [SyntaxKind.ImportAttributes]: ImportAttributes; - [SyntaxKind.NamespaceImport]: NamespaceImport; - [SyntaxKind.NamespaceExport]: NamespaceExport; - [SyntaxKind.NamespaceExportDeclaration]: NamespaceExportDeclaration; - [SyntaxKind.ExportDeclaration]: ExportDeclaration; - [SyntaxKind.NamedImports]: NamedImports; - [SyntaxKind.NamedExports]: NamedExports; - [SyntaxKind.ImportSpecifier]: ImportSpecifier; - [SyntaxKind.ExportSpecifier]: ExportSpecifier; - [SyntaxKind.ExportAssignment]: ExportAssignment; - [SyntaxKind.JSDocTypeExpression]: JSDocTypeExpression; - [SyntaxKind.JSDocNameReference]: JSDocNameReference; - [SyntaxKind.JSDocMemberName]: JSDocMemberName; - [SyntaxKind.JSDocAllType]: JSDocAllType; - [SyntaxKind.JSDocUnknownType]: JSDocUnknownType; - [SyntaxKind.JSDocNonNullableType]: JSDocNonNullableType; - [SyntaxKind.JSDocNullableType]: JSDocNullableType; - [SyntaxKind.JSDocOptionalType]: JSDocOptionalType; - [SyntaxKind.JSDocFunctionType]: JSDocFunctionType; - [SyntaxKind.JSDocVariadicType]: JSDocVariadicType; - [SyntaxKind.JSDocNamepathType]: JSDocNamepathType; - [SyntaxKind.JSDoc]: JSDoc; - [SyntaxKind.JSDocLink]: JSDocLink; - [SyntaxKind.JSDocLinkCode]: JSDocLinkCode; - [SyntaxKind.JSDocLinkPlain]: JSDocLinkPlain; - [SyntaxKind.JSDocText]: JSDocText; - [SyntaxKind.JSDocTag]: JSDocUnknownTag; - [SyntaxKind.JSDocAugmentsTag]: JSDocAugmentsTag; - [SyntaxKind.JSDocImplementsTag]: JSDocImplementsTag; - [SyntaxKind.JSDocAuthorTag]: JSDocAuthorTag; - [SyntaxKind.JSDocDeprecatedTag]: JSDocDeprecatedTag; - [SyntaxKind.JSDocClassTag]: JSDocClassTag; - [SyntaxKind.JSDocPublicTag]: JSDocPublicTag; - [SyntaxKind.JSDocPrivateTag]: JSDocPrivateTag; - [SyntaxKind.JSDocProtectedTag]: JSDocProtectedTag; - [SyntaxKind.JSDocReadonlyTag]: JSDocReadonlyTag; - [SyntaxKind.JSDocOverrideTag]: JSDocOverrideTag; - [SyntaxKind.JSDocEnumTag]: JSDocEnumTag; - [SyntaxKind.JSDocThisTag]: JSDocThisTag; - [SyntaxKind.JSDocTemplateTag]: JSDocTemplateTag; - [SyntaxKind.JSDocSeeTag]: JSDocSeeTag; - [SyntaxKind.JSDocReturnTag]: JSDocReturnTag; - [SyntaxKind.JSDocTypeTag]: JSDocTypeTag; - [SyntaxKind.JSDocTypedefTag]: JSDocTypedefTag; - [SyntaxKind.JSDocCallbackTag]: JSDocCallbackTag; - [SyntaxKind.JSDocOverloadTag]: JSDocOverloadTag; - [SyntaxKind.JSDocThrowsTag]: JSDocThrowsTag; - [SyntaxKind.JSDocSignature]: JSDocSignature; - [SyntaxKind.JSDocPropertyTag]: JSDocPropertyTag; - [SyntaxKind.JSDocParameterTag]: JSDocParameterTag; - [SyntaxKind.JSDocTypeLiteral]: JSDocTypeLiteral; - [SyntaxKind.JSDocSatisfiesTag]: JSDocSatisfiesTag; - [SyntaxKind.JSDocImportTag]: JSDocImportTag; - [SyntaxKind.SourceFile]: SourceFile; - [SyntaxKind.Bundle]: Bundle; - [SyntaxKind.SyntaxList]: SyntaxList; - [SyntaxKind.NotEmittedStatement]: NotEmittedStatement; - [SyntaxKind.NotEmittedTypeElement]: NotEmittedTypeElement; - [SyntaxKind.PartiallyEmittedExpression]: PartiallyEmittedExpression; - [SyntaxKind.CommaListExpression]: CommaListExpression; - [SyntaxKind.SyntheticReferenceExpression]: SyntheticReferenceExpression; - [SyntaxKind.Count]: never; - [SyntaxKind.NonTextFileMarkerTrivia]: never; -} - -/** @internal @knipignore */ -export interface AstNodeType { - [SyntaxKind.Unknown]: AstToken; - [SyntaxKind.EndOfFileToken]: AstEndOfFileToken; - [SyntaxKind.SingleLineCommentTrivia]: AstToken; - [SyntaxKind.MultiLineCommentTrivia]: AstToken; - [SyntaxKind.NewLineTrivia]: AstToken; - [SyntaxKind.WhitespaceTrivia]: AstToken; - [SyntaxKind.ShebangTrivia]: AstToken; - [SyntaxKind.ConflictMarkerTrivia]: AstToken; - [SyntaxKind.NonTextFileMarkerTrivia]: never; - [SyntaxKind.NumericLiteral]: AstNumericLiteral; - [SyntaxKind.BigIntLiteral]: AstBigIntLiteral; - [SyntaxKind.StringLiteral]: AstStringLiteral; - [SyntaxKind.JsxText]: AstJsxText; - [SyntaxKind.JsxTextAllWhiteSpaces]: never; - [SyntaxKind.RegularExpressionLiteral]: AstRegularExpressionLiteral; - [SyntaxKind.NoSubstitutionTemplateLiteral]: AstNoSubstitutionTemplateLiteral; - [SyntaxKind.TemplateHead]: AstTemplateHead; - [SyntaxKind.TemplateMiddle]: AstTemplateMiddle; - [SyntaxKind.TemplateTail]: AstTemplateTail; - [SyntaxKind.OpenBraceToken]: AstToken; - [SyntaxKind.CloseBraceToken]: AstToken; - [SyntaxKind.OpenParenToken]: AstToken; - [SyntaxKind.CloseParenToken]: AstToken; - [SyntaxKind.OpenBracketToken]: AstToken; - [SyntaxKind.CloseBracketToken]: AstToken; - [SyntaxKind.DotToken]: AstDotToken; - [SyntaxKind.DotDotDotToken]: AstDotDotDotToken; - [SyntaxKind.SemicolonToken]: AstToken; - [SyntaxKind.CommaToken]: AstToken; - [SyntaxKind.QuestionDotToken]: AstQuestionDotToken; - [SyntaxKind.LessThanToken]: AstToken; - [SyntaxKind.LessThanSlashToken]: AstToken; - [SyntaxKind.GreaterThanToken]: AstToken; - [SyntaxKind.LessThanEqualsToken]: AstToken; - [SyntaxKind.GreaterThanEqualsToken]: AstToken; - [SyntaxKind.EqualsEqualsToken]: AstToken; - [SyntaxKind.ExclamationEqualsToken]: AstToken; - [SyntaxKind.EqualsEqualsEqualsToken]: AstToken; - [SyntaxKind.ExclamationEqualsEqualsToken]: AstToken; - [SyntaxKind.EqualsGreaterThanToken]: AstEqualsGreaterThanToken; - [SyntaxKind.PlusToken]: AstPlusToken; - [SyntaxKind.MinusToken]: AstMinusToken; - [SyntaxKind.AsteriskToken]: AstAsteriskToken; - [SyntaxKind.AsteriskAsteriskToken]: AstToken; - [SyntaxKind.SlashToken]: AstToken; - [SyntaxKind.PercentToken]: AstToken; - [SyntaxKind.PlusPlusToken]: AstToken; - [SyntaxKind.MinusMinusToken]: AstToken; - [SyntaxKind.LessThanLessThanToken]: AstToken; - [SyntaxKind.GreaterThanGreaterThanToken]: AstToken; - [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: AstToken; - [SyntaxKind.AmpersandToken]: AstToken; - [SyntaxKind.BarToken]: AstToken; - [SyntaxKind.CaretToken]: AstToken; - [SyntaxKind.ExclamationToken]: AstExclamationToken; - [SyntaxKind.TildeToken]: AstToken; - [SyntaxKind.AmpersandAmpersandToken]: AstToken; - [SyntaxKind.BarBarToken]: AstToken; - [SyntaxKind.QuestionToken]: AstQuestionToken; - [SyntaxKind.ColonToken]: AstColonToken; - [SyntaxKind.AtToken]: AstToken; - [SyntaxKind.QuestionQuestionToken]: AstToken; - [SyntaxKind.BacktickToken]: AstToken; - [SyntaxKind.HashToken]: AstToken; - [SyntaxKind.EqualsToken]: AstEqualsToken; - [SyntaxKind.PlusEqualsToken]: AstToken; - [SyntaxKind.MinusEqualsToken]: AstToken; - [SyntaxKind.AsteriskEqualsToken]: AstToken; - [SyntaxKind.AsteriskAsteriskEqualsToken]: AstToken; - [SyntaxKind.SlashEqualsToken]: AstToken; - [SyntaxKind.PercentEqualsToken]: AstToken; - [SyntaxKind.LessThanLessThanEqualsToken]: AstToken; - [SyntaxKind.GreaterThanGreaterThanEqualsToken]: AstToken; - [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: AstToken; - [SyntaxKind.AmpersandEqualsToken]: AstToken; - [SyntaxKind.BarEqualsToken]: AstToken; - [SyntaxKind.BarBarEqualsToken]: AstBarBarEqualsToken; - [SyntaxKind.AmpersandAmpersandEqualsToken]: AstAmpersandAmpersandEqualsToken; - [SyntaxKind.QuestionQuestionEqualsToken]: AstQuestionQuestionEqualsToken; - [SyntaxKind.CaretEqualsToken]: AstToken; - [SyntaxKind.Identifier]: AstIdentifier; - [SyntaxKind.PrivateIdentifier]: AstPrivateIdentifier; - [SyntaxKind.JSDocCommentTextToken]: never; - [SyntaxKind.BreakKeyword]: AstToken; - [SyntaxKind.CaseKeyword]: AstCaseKeyword; - [SyntaxKind.CatchKeyword]: AstToken; - [SyntaxKind.ClassKeyword]: AstToken; - [SyntaxKind.ConstKeyword]: AstToken; - [SyntaxKind.ContinueKeyword]: AstToken; - [SyntaxKind.DebuggerKeyword]: AstToken; - [SyntaxKind.DefaultKeyword]: AstDefaultKeyword; - [SyntaxKind.DeleteKeyword]: AstToken; - [SyntaxKind.DoKeyword]: AstToken; - [SyntaxKind.ElseKeyword]: AstToken; - [SyntaxKind.EnumKeyword]: AstToken; - [SyntaxKind.ExportKeyword]: AstExportKeyword; - [SyntaxKind.ExtendsKeyword]: AstToken; - [SyntaxKind.FalseKeyword]: AstFalseLiteral; - [SyntaxKind.FinallyKeyword]: AstToken; - [SyntaxKind.ForKeyword]: AstToken; - [SyntaxKind.FunctionKeyword]: AstToken; - [SyntaxKind.IfKeyword]: AstToken; - [SyntaxKind.ImportKeyword]: AstImportExpression; - [SyntaxKind.InKeyword]: AstInKeyword; - [SyntaxKind.InstanceOfKeyword]: AstToken; - [SyntaxKind.NewKeyword]: AstToken; - [SyntaxKind.NullKeyword]: AstNullLiteral; - [SyntaxKind.ReturnKeyword]: AstToken; - [SyntaxKind.SuperKeyword]: AstSuperExpression; - [SyntaxKind.SwitchKeyword]: AstToken; - [SyntaxKind.ThisKeyword]: AstThisExpression; - [SyntaxKind.ThrowKeyword]: AstToken; - [SyntaxKind.TrueKeyword]: AstTrueLiteral; - [SyntaxKind.TryKeyword]: AstToken; - [SyntaxKind.TypeOfKeyword]: AstToken; - [SyntaxKind.VarKeyword]: AstToken; - [SyntaxKind.VoidKeyword]: AstToken; - [SyntaxKind.WhileKeyword]: AstToken; - [SyntaxKind.WithKeyword]: AstToken; - [SyntaxKind.ImplementsKeyword]: AstToken; - [SyntaxKind.InterfaceKeyword]: AstToken; - [SyntaxKind.LetKeyword]: AstToken; - [SyntaxKind.PackageKeyword]: AstToken; - [SyntaxKind.PrivateKeyword]: AstPrivateKeyword; - [SyntaxKind.ProtectedKeyword]: AstProtectedKeyword; - [SyntaxKind.PublicKeyword]: AstPublicKeyword; - [SyntaxKind.StaticKeyword]: AstStaticKeyword; - [SyntaxKind.YieldKeyword]: AstToken; - [SyntaxKind.AbstractKeyword]: AstAbstractKeyword; - [SyntaxKind.AccessorKeyword]: AstAccessorKeyword; - [SyntaxKind.AsKeyword]: AstToken; - [SyntaxKind.AssertsKeyword]: AstAssertsKeyword; - [SyntaxKind.AssertKeyword]: AstAssertKeyword; - [SyntaxKind.AnyKeyword]: AstToken; - [SyntaxKind.AsyncKeyword]: AstAsyncKeyword; - [SyntaxKind.AwaitKeyword]: AstAwaitKeyword; - [SyntaxKind.BooleanKeyword]: AstToken; - [SyntaxKind.ConstructorKeyword]: AstToken; - [SyntaxKind.DeclareKeyword]: AstDeclareKeyword; - [SyntaxKind.GetKeyword]: AstToken; - [SyntaxKind.InferKeyword]: AstToken; - [SyntaxKind.IntrinsicKeyword]: AstToken; - [SyntaxKind.IsKeyword]: AstToken; - [SyntaxKind.KeyOfKeyword]: AstToken; - [SyntaxKind.ModuleKeyword]: AstToken; - [SyntaxKind.NamespaceKeyword]: AstToken; - [SyntaxKind.NeverKeyword]: AstToken; - [SyntaxKind.OutKeyword]: AstOutKeyword; - [SyntaxKind.ReadonlyKeyword]: AstReadonlyKeyword; - [SyntaxKind.RequireKeyword]: AstToken; - [SyntaxKind.NumberKeyword]: AstToken; - [SyntaxKind.ObjectKeyword]: AstToken; - [SyntaxKind.SatisfiesKeyword]: AstToken; - [SyntaxKind.SetKeyword]: AstToken; - [SyntaxKind.StringKeyword]: AstToken; - [SyntaxKind.SymbolKeyword]: AstToken; - [SyntaxKind.TypeKeyword]: AstToken; - [SyntaxKind.UndefinedKeyword]: AstToken; - [SyntaxKind.UniqueKeyword]: AstToken; - [SyntaxKind.UnknownKeyword]: AstToken; - [SyntaxKind.UsingKeyword]: AstToken; - [SyntaxKind.FromKeyword]: AstToken; - [SyntaxKind.GlobalKeyword]: AstToken; - [SyntaxKind.BigIntKeyword]: AstToken; - [SyntaxKind.OverrideKeyword]: AstOverrideKeyword; - [SyntaxKind.OfKeyword]: AstToken; - [SyntaxKind.QualifiedName]: AstQualifiedName; - [SyntaxKind.ComputedPropertyName]: AstComputedPropertyName; - [SyntaxKind.Decorator]: AstDecorator; - [SyntaxKind.TypeParameter]: AstTypeParameterDeclaration; - [SyntaxKind.CallSignature]: AstCallSignatureDeclaration; - [SyntaxKind.ConstructSignature]: AstConstructSignatureDeclaration; - [SyntaxKind.VariableDeclaration]: AstVariableDeclaration; - [SyntaxKind.VariableDeclarationList]: AstVariableDeclarationList; - [SyntaxKind.Parameter]: AstParameterDeclaration; - [SyntaxKind.BindingElement]: AstBindingElement; - [SyntaxKind.PropertySignature]: AstPropertySignature; - [SyntaxKind.PropertyDeclaration]: AstPropertyDeclaration; - [SyntaxKind.PropertyAssignment]: AstPropertyAssignment; - [SyntaxKind.ShorthandPropertyAssignment]: AstShorthandPropertyAssignment; - [SyntaxKind.SpreadAssignment]: AstSpreadAssignment; - [SyntaxKind.ObjectBindingPattern]: AstObjectBindingPattern; - [SyntaxKind.ArrayBindingPattern]: AstArrayBindingPattern; - [SyntaxKind.FunctionDeclaration]: AstFunctionDeclaration; - [SyntaxKind.MethodSignature]: AstMethodSignature; - [SyntaxKind.MethodDeclaration]: AstMethodDeclaration; - [SyntaxKind.Constructor]: AstConstructorDeclaration; - [SyntaxKind.SemicolonClassElement]: AstSemicolonClassElement; - [SyntaxKind.GetAccessor]: AstGetAccessorDeclaration; - [SyntaxKind.SetAccessor]: AstSetAccessorDeclaration; - [SyntaxKind.IndexSignature]: AstIndexSignatureDeclaration; - [SyntaxKind.ClassStaticBlockDeclaration]: AstClassStaticBlockDeclaration; - [SyntaxKind.ImportTypeAssertionContainer]: AstImportTypeAssertionContainer; - [SyntaxKind.ImportType]: AstImportTypeNode; - [SyntaxKind.ThisType]: AstThisTypeNode; - [SyntaxKind.FunctionType]: AstFunctionTypeNode; - [SyntaxKind.ConstructorType]: AstConstructorTypeNode; - [SyntaxKind.TypeReference]: AstTypeReferenceNode; - [SyntaxKind.TypePredicate]: AstTypePredicateNode; - [SyntaxKind.TypeQuery]: AstTypeQueryNode; - [SyntaxKind.TypeLiteral]: AstTypeLiteralNode; - [SyntaxKind.ArrayType]: AstArrayTypeNode; - [SyntaxKind.TupleType]: AstTupleTypeNode; - [SyntaxKind.NamedTupleMember]: AstNamedTupleMember; - [SyntaxKind.OptionalType]: AstOptionalTypeNode; - [SyntaxKind.RestType]: AstRestTypeNode; - [SyntaxKind.UnionType]: AstUnionTypeNode; - [SyntaxKind.IntersectionType]: AstIntersectionTypeNode; - [SyntaxKind.ConditionalType]: AstConditionalTypeNode; - [SyntaxKind.InferType]: AstInferTypeNode; - [SyntaxKind.ParenthesizedType]: AstParenthesizedTypeNode; - [SyntaxKind.TypeOperator]: AstTypeOperatorNode; - [SyntaxKind.IndexedAccessType]: AstIndexedAccessTypeNode; - [SyntaxKind.MappedType]: AstMappedTypeNode; - [SyntaxKind.LiteralType]: AstLiteralTypeNode; - [SyntaxKind.TemplateLiteralType]: AstTemplateLiteralTypeNode; - [SyntaxKind.TemplateLiteralTypeSpan]: AstTemplateLiteralTypeSpan; - [SyntaxKind.OmittedExpression]: AstOmittedExpression; - [SyntaxKind.PrefixUnaryExpression]: AstPrefixUnaryExpression; - [SyntaxKind.PostfixUnaryExpression]: AstPostfixUnaryExpression; - [SyntaxKind.DeleteExpression]: AstDeleteExpression; - [SyntaxKind.TypeOfExpression]: AstTypeOfExpression; - [SyntaxKind.VoidExpression]: AstVoidExpression; - [SyntaxKind.AwaitExpression]: AstAwaitExpression; - [SyntaxKind.YieldExpression]: AstYieldExpression; - [SyntaxKind.BinaryExpression]: AstBinaryExpression; - [SyntaxKind.ConditionalExpression]: AstConditionalExpression; - [SyntaxKind.FunctionExpression]: AstFunctionExpression; - [SyntaxKind.ArrowFunction]: AstArrowFunction; - [SyntaxKind.TemplateExpression]: AstTemplateExpression; - [SyntaxKind.TemplateSpan]: AstTemplateSpan; - [SyntaxKind.ParenthesizedExpression]: AstParenthesizedExpression; - [SyntaxKind.ArrayLiteralExpression]: AstArrayLiteralExpression; - [SyntaxKind.SpreadElement]: AstSpreadElement; - [SyntaxKind.ObjectLiteralExpression]: AstObjectLiteralExpression; - [SyntaxKind.PropertyAccessExpression]: AstPropertyAccessExpression; - [SyntaxKind.ElementAccessExpression]: AstElementAccessExpression; - [SyntaxKind.CallExpression]: AstCallExpression; - [SyntaxKind.ExpressionWithTypeArguments]: AstExpressionWithTypeArguments; - [SyntaxKind.NewExpression]: AstNewExpression; - [SyntaxKind.TaggedTemplateExpression]: AstTaggedTemplateExpression; - [SyntaxKind.AsExpression]: AstAsExpression; - [SyntaxKind.TypeAssertionExpression]: AstTypeAssertion; - [SyntaxKind.SyntheticExpression]: AstSyntheticExpression; - [SyntaxKind.SatisfiesExpression]: AstSatisfiesExpression; - [SyntaxKind.NonNullExpression]: AstNonNullExpression; - [SyntaxKind.MetaProperty]: AstMetaProperty; - [SyntaxKind.JsxElement]: AstJsxElement; - [SyntaxKind.JsxAttributes]: AstJsxAttributes; - [SyntaxKind.JsxNamespacedName]: AstJsxNamespacedName; - [SyntaxKind.JsxOpeningElement]: AstJsxOpeningElement; - [SyntaxKind.JsxSelfClosingElement]: AstJsxSelfClosingElement; - [SyntaxKind.JsxFragment]: AstJsxFragment; - [SyntaxKind.JsxOpeningFragment]: AstJsxOpeningFragment; - [SyntaxKind.JsxClosingFragment]: AstJsxClosingFragment; - [SyntaxKind.JsxAttribute]: AstJsxAttribute; - [SyntaxKind.JsxSpreadAttribute]: AstJsxSpreadAttribute; - [SyntaxKind.JsxClosingElement]: AstJsxClosingElement; - [SyntaxKind.JsxExpression]: AstJsxExpression; - [SyntaxKind.EmptyStatement]: AstEmptyStatement; - [SyntaxKind.DebuggerStatement]: AstDebuggerStatement; - [SyntaxKind.MissingDeclaration]: AstMissingDeclaration; - [SyntaxKind.Block]: AstBlock; - [SyntaxKind.VariableStatement]: AstVariableStatement; - [SyntaxKind.ExpressionStatement]: AstExpressionStatement; - [SyntaxKind.IfStatement]: AstIfStatement; - [SyntaxKind.DoStatement]: AstDoStatement; - [SyntaxKind.WhileStatement]: AstWhileStatement; - [SyntaxKind.ForStatement]: AstForStatement; - [SyntaxKind.ForInStatement]: AstForInStatement; - [SyntaxKind.ForOfStatement]: AstForOfStatement; - [SyntaxKind.BreakStatement]: AstBreakStatement; - [SyntaxKind.ContinueStatement]: AstContinueStatement; - [SyntaxKind.ReturnStatement]: AstReturnStatement; - [SyntaxKind.WithStatement]: AstWithStatement; - [SyntaxKind.SwitchStatement]: AstSwitchStatement; - [SyntaxKind.CaseBlock]: AstCaseBlock; - [SyntaxKind.CaseClause]: AstCaseClause; - [SyntaxKind.DefaultClause]: AstDefaultClause; - [SyntaxKind.LabeledStatement]: AstLabeledStatement; - [SyntaxKind.ThrowStatement]: AstThrowStatement; - [SyntaxKind.TryStatement]: AstTryStatement; - [SyntaxKind.CatchClause]: AstCatchClause; - [SyntaxKind.ClassDeclaration]: AstClassDeclaration; - [SyntaxKind.ClassExpression]: AstClassExpression; - [SyntaxKind.InterfaceDeclaration]: AstInterfaceDeclaration; - [SyntaxKind.HeritageClause]: AstHeritageClause; - [SyntaxKind.TypeAliasDeclaration]: AstTypeAliasDeclaration; - [SyntaxKind.EnumMember]: AstEnumMember; - [SyntaxKind.EnumDeclaration]: AstEnumDeclaration; - [SyntaxKind.ModuleDeclaration]: AstModuleDeclaration; - [SyntaxKind.ModuleBlock]: AstModuleBlock; - [SyntaxKind.ImportEqualsDeclaration]: AstImportEqualsDeclaration; - [SyntaxKind.ExternalModuleReference]: AstExternalModuleReference; - [SyntaxKind.ImportDeclaration]: AstImportDeclaration; - [SyntaxKind.ImportClause]: AstImportClause; - [SyntaxKind.ImportAttribute]: AstImportAttribute; - [SyntaxKind.ImportAttributes]: AstImportAttributes; - [SyntaxKind.NamespaceImport]: AstNamespaceImport; - [SyntaxKind.NamespaceExport]: AstNamespaceExport; - [SyntaxKind.NamespaceExportDeclaration]: AstNamespaceExportDeclaration; - [SyntaxKind.ExportDeclaration]: AstExportDeclaration; - [SyntaxKind.NamedImports]: AstNamedImports; - [SyntaxKind.NamedExports]: AstNamedExports; - [SyntaxKind.ImportSpecifier]: AstImportSpecifier; - [SyntaxKind.ExportSpecifier]: AstExportSpecifier; - [SyntaxKind.ExportAssignment]: AstExportAssignment; - [SyntaxKind.JSDocTypeExpression]: AstJSDocTypeExpression; - [SyntaxKind.JSDocNameReference]: AstJSDocNameReference; - [SyntaxKind.JSDocMemberName]: AstJSDocMemberName; - [SyntaxKind.JSDocAllType]: AstJSDocAllType; - [SyntaxKind.JSDocUnknownType]: AstJSDocUnknownType; - [SyntaxKind.JSDocNonNullableType]: AstJSDocNonNullableType; - [SyntaxKind.JSDocNullableType]: AstJSDocNullableType; - [SyntaxKind.JSDocOptionalType]: AstJSDocOptionalType; - [SyntaxKind.JSDocFunctionType]: AstJSDocFunctionType; - [SyntaxKind.JSDocVariadicType]: AstJSDocVariadicType; - [SyntaxKind.JSDocNamepathType]: AstJSDocNamepathType; - [SyntaxKind.JSDoc]: AstJSDoc; - [SyntaxKind.JSDocLink]: AstJSDocLink; - [SyntaxKind.JSDocLinkCode]: AstJSDocLinkCode; - [SyntaxKind.JSDocLinkPlain]: AstJSDocLinkPlain; - [SyntaxKind.JSDocText]: AstJSDocText; - [SyntaxKind.JSDocTag]: AstJSDocUnknownTag; - [SyntaxKind.JSDocAugmentsTag]: AstJSDocAugmentsTag; - [SyntaxKind.JSDocImplementsTag]: AstJSDocImplementsTag; - [SyntaxKind.JSDocAuthorTag]: AstJSDocAuthorTag; - [SyntaxKind.JSDocDeprecatedTag]: AstJSDocDeprecatedTag; - [SyntaxKind.JSDocClassTag]: AstJSDocClassTag; - [SyntaxKind.JSDocPublicTag]: AstJSDocPublicTag; - [SyntaxKind.JSDocPrivateTag]: AstJSDocPrivateTag; - [SyntaxKind.JSDocProtectedTag]: AstJSDocProtectedTag; - [SyntaxKind.JSDocReadonlyTag]: AstJSDocReadonlyTag; - [SyntaxKind.JSDocOverrideTag]: AstJSDocOverrideTag; - [SyntaxKind.JSDocEnumTag]: AstJSDocEnumTag; - [SyntaxKind.JSDocThisTag]: AstJSDocThisTag; - [SyntaxKind.JSDocTemplateTag]: AstJSDocTemplateTag; - [SyntaxKind.JSDocSeeTag]: AstJSDocSeeTag; - [SyntaxKind.JSDocReturnTag]: AstJSDocReturnTag; - [SyntaxKind.JSDocTypeTag]: AstJSDocTypeTag; - [SyntaxKind.JSDocTypedefTag]: AstJSDocTypedefTag; - [SyntaxKind.JSDocCallbackTag]: AstJSDocCallbackTag; - [SyntaxKind.JSDocOverloadTag]: AstJSDocOverloadTag; - [SyntaxKind.JSDocThrowsTag]: AstJSDocThrowsTag; - [SyntaxKind.JSDocSignature]: AstJSDocSignature; - [SyntaxKind.JSDocPropertyTag]: AstJSDocPropertyTag; - [SyntaxKind.JSDocParameterTag]: AstJSDocParameterTag; - [SyntaxKind.JSDocTypeLiteral]: AstJSDocTypeLiteral; - [SyntaxKind.JSDocSatisfiesTag]: AstJSDocSatisfiesTag; - [SyntaxKind.JSDocImportTag]: AstJSDocImportTag; - [SyntaxKind.SourceFile]: AstSourceFile; - [SyntaxKind.Bundle]: AstBundle; - [SyntaxKind.SyntaxList]: AstSyntaxList; - [SyntaxKind.NotEmittedStatement]: AstNotEmittedStatement; - [SyntaxKind.NotEmittedTypeElement]: AstNotEmittedTypeElement; - [SyntaxKind.PartiallyEmittedExpression]: AstPartiallyEmittedExpression; - [SyntaxKind.CommaListExpression]: AstCommaListExpression; - [SyntaxKind.SyntheticReferenceExpression]: AstSyntheticReferenceExpression; - [SyntaxKind.Count]: never; - [SyntaxKind.NonTextFileMarkerTrivia]: never; -} diff --git a/src/compiler/astForEachChild.ts b/src/compiler/astForEachChild.ts index 3bc5a3fa76a73..f182752c23fd7 100644 --- a/src/compiler/astForEachChild.ts +++ b/src/compiler/astForEachChild.ts @@ -38,6 +38,7 @@ import { AstExpressionStatement, AstExpressionWithTypeArguments, AstExternalModuleReference, + AstForEachChildNodes, AstForInStatement, AstForOfStatement, AstForStatement, @@ -174,12 +175,8 @@ import { AstWhileStatement, AstWithStatement, AstYieldExpression, - AstForEachChildNodes -} from "./_namespaces/ts.ast.js"; -import { forEach, SyntaxKind, - isArray, } from "./_namespaces/ts.js"; function visitNode(cbNode: (node: AstNode) => T, node: AstNode | undefined): T | undefined { diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 7f61986a80fb8..347970f24f55c 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -120,6 +120,7 @@ import { HasFlowNode, hasJSDocNodes, HasLocals, + hasName, hasSyntacticModifier, Identifier, identifierToKeywordKind, @@ -1012,7 +1013,8 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { const isImmediatelyInvoked = ( containerFlags & ContainerFlags.IsFunctionExpression && !hasSyntacticModifier(node, ModifierFlags.Async) && - !(node as FunctionLikeDeclaration).asteriskToken && + // TODO(rbuckton): unchecked cast can result in wrong map deopt due to missing `asteriskToken` property + !(node as Extract).asteriskToken && !!getImmediatelyInvokedFunctionExpression(node) ) || node.kind === SyntaxKind.ClassStaticBlockDeclaration; // A non-async, non-generator IIFE is considered part of the containing control flow. Return statements behave @@ -2646,7 +2648,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { function checkStrictModeFunctionName(node: FunctionLikeDeclaration) { if (inStrictMode && !(node.flags & NodeFlags.Ambient)) { // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a strict mode FunctionDeclaration or FunctionExpression (13.1)) - checkStrictModeEvalOrArguments(node, node.name); + checkStrictModeEvalOrArguments(node, isNamedDeclaration(node) ? node.name : undefined); } } @@ -3720,7 +3722,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { node.flowNode = currentFlow; } checkStrictModeFunctionName(node); - const bindingName = node.name ? node.name.escapedText : InternalSymbolName.Function; + const bindingName = hasName(node) ? node.name.escapedText : InternalSymbolName.Function; return bindAnonymousDeclaration(node, SymbolFlags.Function, bindingName); } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 438e46eca11b6..47c09f9814c20 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1065,7 +1065,7 @@ import { TupleTypeReference, Type, TypeAliasDeclaration, - TypeAssertion, + TypeAssertionExpression, TypeChecker, TypeCheckerHost, TypeComparer, @@ -1121,6 +1121,10 @@ import { WideningContext, WithStatement, YieldExpression, + canHaveName, + hasName, + canHaveQuestionToken, + hasAsteriskToken, } from "./_namespaces/ts.js"; import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers.js"; import * as performance from "./_namespaces/ts.performance.js"; @@ -14639,7 +14643,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function isTypeInvalidDueToUnionDiscriminant(contextualType: Type, obj: ObjectLiteralExpression | JsxAttributes): boolean { const list = obj.properties as NodeArray; return list.some(property => { - const nameType = property.name && (isJsxNamespacedName(property.name) ? getStringLiteralType(getTextOfJsxAttributeName(property.name)) : getLiteralTypeFromPropertyName(property.name)); + const nameType = !isSpreadAssignment(property) && !isJsxSpreadAttribute(property) && (isJsxNamespacedName(property.name) ? getStringLiteralType(getTextOfJsxAttributeName(property.name)) : getLiteralTypeFromPropertyName(property.name)); const name = nameType && isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined; const expected = name === undefined ? undefined : getTypeOfPropertyOfType(contextualType, name); return !!expected && isLiteralType(expected) && !isTypeAssignableTo(getTypeOfNode(property), expected); @@ -22477,8 +22481,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (prop.valueDeclaration && findAncestor(prop.valueDeclaration, d => d === objectLiteralDeclaration) && getSourceFileOfNode(objectLiteralDeclaration) === getSourceFileOfNode(errorNode)) { const propDeclaration = prop.valueDeclaration as ObjectLiteralElementLike; Debug.assertNode(propDeclaration, isObjectLiteralElementLike); + Debug.assertNotNode(propDeclaration, isSpreadAssignment); + Debug.assertNotNode(propDeclaration, isJsxSpreadAttribute); - const name = propDeclaration.name!; + const name = propDeclaration.name; errorNode = name; if (isIdentifier(name)) { @@ -31852,7 +31858,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } } - if (element.name) { + if (!isSpreadAssignment(element) && !isJsxSpreadAttribute(element)) { const nameType = getLiteralTypeFromPropertyName(element.name); // We avoid calling getApplicableIndexInfo here because it performs potentially expensive intersection reduction. return mapType(type, t => findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType)?.type, /*noReductions*/ true); @@ -32847,7 +32853,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // As otherwise they may not be checked until exports for the type at this position are retrieved, // which may never occur. for (const elem of node.properties) { - if (elem.name && isComputedPropertyName(elem.name)) { + if (canHaveName(elem) && isComputedPropertyName(elem.name)) { checkComputedPropertyName(elem.name); } } @@ -32855,7 +32861,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { let offset = 0; for (const memberDecl of node.properties) { let member = getSymbolOfDeclaration(memberDecl); - const computedNameType = memberDecl.name && memberDecl.name.kind === SyntaxKind.ComputedPropertyName ? + const computedNameType = canHaveName(memberDecl) && memberDecl.name.kind === SyntaxKind.ComputedPropertyName ? checkComputedPropertyName(memberDecl.name) : undefined; if ( memberDecl.kind === SyntaxKind.PropertyAssignment || @@ -34980,9 +34986,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // If the template didn't end in a backtick, or its beginning occurred right prior to EOF, // then this might actually turn out to be a TemplateHead in the future; // so we consider the call to be incomplete. - const templateLiteral = node.template as LiteralExpression; - Debug.assert(templateLiteral.kind === SyntaxKind.NoSubstitutionTemplateLiteral); - callIsIncomplete = !!templateLiteral.isUnterminated; + Debug.assert(node.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral); + callIsIncomplete = !!node.template.isUnterminated; } } else if (node.kind === SyntaxKind.Decorator) { @@ -37989,9 +37994,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function createClassMemberDecoratorContextTypeForNode(node: MethodDeclaration | AccessorDeclaration | PropertyDeclaration, thisType: Type, valueType: Type) { + const name = node.name; const isStatic = hasStaticModifier(node); - const isPrivate = isPrivateIdentifier(node.name); - const nameType = isPrivate ? getStringLiteralType(idText(node.name)) : getLiteralTypeFromPropertyName(node.name); + const isPrivate = isPrivateIdentifier(name); + const nameType = isPrivate ? getStringLiteralType(idText(name)) : getLiteralTypeFromPropertyName(name); const contextType = isMethodDeclaration(node) ? createClassMethodDecoratorContextType(thisType, valueType) : isGetAccessorDeclaration(node) ? createClassGetterDecoratorContextType(thisType, valueType) : isSetAccessorDeclaration(node) ? createClassSetterDecoratorContextType(thisType, valueType) : @@ -40901,7 +40907,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { getReturnTypeOfSingleNonGenericCallSignature(checkNonNullExpression(expr.expression)); } else if (isAssertionExpression(expr) && !isConstTypeReference(expr.type)) { - return getTypeFromTypeNode((expr as TypeAssertion).type); + return getTypeFromTypeNode((expr as TypeAssertionExpression).type); } else if (isLiteralExpression(node) || isBooleanLiteral(node)) { return checkExpression(node); @@ -42241,7 +42247,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const isConstructor = (symbol.flags & SymbolFlags.Constructor) !== 0; function reportImplementationExpectedError(node: SignatureDeclaration): void { - if (node.name && nodeIsMissing(node.name)) { + if (canHaveName(node) && node.name && nodeIsMissing(node.name)) { return; } @@ -42258,10 +42264,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // In this case the subsequent node is not really consecutive (.pos !== node.end), and we must ignore it here. if (subsequentNode && subsequentNode.pos === node.end) { if (subsequentNode.kind === node.kind) { - const errorNode: Node = (subsequentNode as FunctionLikeDeclaration).name || subsequentNode; - const subsequentName = (subsequentNode as FunctionLikeDeclaration).name; + const subsequentName = tryCast(subsequentNode, canHaveName)?.name; + const errorNode: Node = subsequentName ?? subsequentNode; if ( - node.name && subsequentName && ( + hasName(node) && subsequentName && ( // both are private identifiers isPrivateIdentifier(node.name) && isPrivateIdentifier(subsequentName) && node.name.escapedText === subsequentName.escapedText || // Both are computed property names @@ -42284,12 +42290,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return; } if (nodeIsPresent((subsequentNode as FunctionLikeDeclaration).body)) { - error(errorNode, Diagnostics.Function_implementation_name_must_be_0, declarationNameToString(node.name)); + error(errorNode, Diagnostics.Function_implementation_name_must_be_0, declarationNameToString(canHaveName(node) ? node.name : undefined)); return; } } } - const errorNode: Node = node.name || node; + const errorNode: Node = tryCast(node, canHaveName)?.name ?? node; if (isConstructor) { error(errorNode, Diagnostics.Constructor_implementation_is_missing); } @@ -42405,7 +42411,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // Abstract methods can't have an implementation -- in particular, they don't need one. if ( lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body && - !hasSyntacticModifier(lastSeenNonAmbientDeclaration, ModifierFlags.Abstract) && !lastSeenNonAmbientDeclaration.questionToken + !hasSyntacticModifier(lastSeenNonAmbientDeclaration, ModifierFlags.Abstract) && + !(canHaveQuestionToken(lastSeenNonAmbientDeclaration) && lastSeenNonAmbientDeclaration.questionToken) ) { reportImplementationExpectedError(lastSeenNonAmbientDeclaration); } @@ -44221,7 +44228,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // Don't validate for-in initializer as it is already an error const widenedType = getWidenedTypeForVariableLikeDeclaration(node); if (needCheckInitializer) { - const initializerType = checkExpressionCached(node.initializer); + const initializerType = checkExpressionCached(node.initializer!); if (strictNullChecks && needCheckWidenedType) { checkNonNullNonVoidType(initializerType, node); } @@ -47634,7 +47641,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const validForTypeAttributes = isExclusivelyTypeOnlyImportOrExport(declaration); const override = getResolutionModeOverride(node, validForTypeAttributes ? grammarErrorOnNode : undefined); - const isImportAttributes = declaration.attributes.token === SyntaxKind.WithKeyword; + const isImportAttributes = node.token === SyntaxKind.WithKeyword; if (validForTypeAttributes && override) { return; // Other grammar checks do not apply to type-only imports with resolution mode assertions } @@ -51477,7 +51484,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function checkGrammarForGenerator(node: FunctionLikeDeclaration) { - if (node.asteriskToken) { + if (hasAsteriskToken(node)) { Debug.assert( node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.FunctionExpression || diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e63bfd783ced2..095951ee357ca 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -401,7 +401,7 @@ import { TryStatement, TupleTypeNode, TypeAliasDeclaration, - TypeAssertion, + TypeAssertionExpression, TypeLiteralNode, TypeNode, TypeOfExpression, @@ -1935,7 +1935,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri case SyntaxKind.TaggedTemplateExpression: return emitTaggedTemplateExpression(node as TaggedTemplateExpression); case SyntaxKind.TypeAssertionExpression: - return emitTypeAssertionExpression(node as TypeAssertion); + return emitTypeAssertionExpression(node as TypeAssertionExpression); case SyntaxKind.ParenthesizedExpression: return emitParenthesizedExpression(node as ParenthesizedExpression); case SyntaxKind.FunctionExpression: @@ -2718,7 +2718,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri emitExpression(node.template); } - function emitTypeAssertionExpression(node: TypeAssertion) { + function emitTypeAssertionExpression(node: TypeAssertionExpression) { writePunctuation("<"); emit(node.type); writePunctuation(">"); diff --git a/src/compiler/expressionToTypeNode.ts b/src/compiler/expressionToTypeNode.ts index 1c6e045f0f0bd..44cda61b999d4 100644 --- a/src/compiler/expressionToTypeNode.ts +++ b/src/compiler/expressionToTypeNode.ts @@ -59,7 +59,7 @@ import { SyntacticTypeNodeBuilderContext, SyntacticTypeNodeBuilderResolver, SyntaxKind, - TypeAssertion, + TypeAssertionExpression, TypeNode, TypeParameterDeclaration, UnionTypeNode, @@ -263,7 +263,7 @@ export function createSyntacticTypeNodeBuilder( return typeFromFunctionLikeExpression(node as ArrowFunction | FunctionExpression, context); case SyntaxKind.TypeAssertionExpression: case SyntaxKind.AsExpression: - const asExpression = node as AsExpression | TypeAssertion; + const asExpression = node as AsExpression | TypeAssertionExpression; return typeFromTypeAssertion(asExpression.expression, asExpression.type, context, requiresAddingUndefined); case SyntaxKind.PrefixUnaryExpression: const unaryExpression = node as PrefixUnaryExpression; diff --git a/src/compiler/factory/astNodeFactory.ts b/src/compiler/factory/astNodeFactory.ts index a86985a64ccc7..6a532abf9604a 100644 --- a/src/compiler/factory/astNodeFactory.ts +++ b/src/compiler/factory/astNodeFactory.ts @@ -92,6 +92,7 @@ import { AstInferTypeNode, AstInterfaceDeclaration, AstIntersectionTypeNode, + AstJSDoc, AstJSDocAllType, AstJSDocAugmentsTag, AstJSDocAuthorTag, @@ -111,7 +112,6 @@ import { AstJSDocNameReference, AstJSDocNamespaceBody, AstJSDocNamespaceDeclaration, - AstJSDoc, AstJSDocNonNullableType, AstJSDocNullableType, AstJSDocOptionalType, @@ -277,7 +277,22 @@ import { AstWhileStatement, AstWithStatement, AstYieldExpression, + BinaryOperator, + cast, + CharacterCodes, createAstParenthesizerRules, + createScanner, + Debug, + EmitFlags, + escapeLeadingUnderscores, + FileReference, + getCommentRange, + getIdentifierAutoGenerate, + getIdentifierTypeArguments, + getSourceMapRange, + getSyntheticLeadingComments, + getSyntheticTrailingComments, + identity, isAstBinaryExpression, isAstCallChain, isAstCommaListExpression, @@ -294,40 +309,22 @@ import { isAstPropertyAccessChain, isAstQuestionToken, isAstVariableDeclaration, - LiteralToken, - MetaProperty, - Node, - nullAstParenthesizerRules, - SourceFile, -} from "../_namespaces/ts.ast.js"; -import { - BinaryOperator, - cast, - CharacterCodes, - createScanner, - Debug, - EmitFlags, - escapeLeadingUnderscores, - FileReference, - getCommentRange, - getIdentifierAutoGenerate, - getIdentifierTypeArguments, - getSourceMapRange, - getSyntheticLeadingComments, - getSyntheticTrailingComments, - identity, isParseTreeNode, KeywordSyntaxKind, KeywordTypeSyntaxKind, LanguageVariant, lastOrUndefined, + LiteralToken, memoize, mergeEmitNode, + MetaProperty, ModifierFlags, ModifierSyntaxKind, + Node, NodeFactoryFlags, NodeFlags, nodeIsSynthesized, + nullAstParenthesizerRules, OuterExpressionKinds, PostfixUnaryOperator, PrefixUnaryOperator, @@ -343,6 +340,7 @@ import { setIdentifierTypeArguments, setTextRange, some, + SourceFile, startsWith, SyntaxKind, TokenFlags, diff --git a/src/compiler/factory/astNodeTests.ts b/src/compiler/factory/astNodeTests.ts index 1abb9fbfcd62c..6a891f0b8b424 100644 --- a/src/compiler/factory/astNodeTests.ts +++ b/src/compiler/factory/astNodeTests.ts @@ -13,7 +13,9 @@ import { AstDeclareKeyword, AstElementAccessChain, AsteriskToken, + AstHasDecorators, AstHasJSDoc, + AstHasModifiers, AstLeftHandSideExpression, AstNode, AstNonNullChain, @@ -33,6 +35,7 @@ import { Bundle, CallExpression, CallSignatureDeclaration, + canHaveJSDoc, CaseBlock, CaseClause, CaseKeyword, @@ -93,6 +96,8 @@ import { InferTypeNode, InterfaceDeclaration, IntersectionTypeNode, + isLeftHandSideExpressionKind, + JSDoc, JSDocAllType, JSDocAugmentsTag, JSDocAuthorTag, @@ -109,7 +114,6 @@ import { JSDocMemberName, JSDocNamepathType, JSDocNameReference, - JSDoc, JSDocNonNullableType, JSDocNullableType, JSDocOptionalType, @@ -167,6 +171,7 @@ import { NamespaceImport, NewExpression, Node, + NodeFlags, NonNullExpression, NoSubstitutionTemplateLiteral, NotEmittedStatement, @@ -175,6 +180,7 @@ import { ObjectLiteralExpression, OmittedExpression, OptionalTypeNode, + OuterExpressionKinds, OverrideKeyword, ParameterDeclaration, ParenthesizedExpression, @@ -207,6 +213,7 @@ import { StringLiteral, SuperExpression, SwitchStatement, + SyntaxKind, SyntaxList, SyntheticExpression, SyntheticReferenceExpression, @@ -224,7 +231,7 @@ import { TryStatement, TupleTypeNode, TypeAliasDeclaration, - TypeAssertion, + TypeAssertionExpression, TypeLiteralNode, TypeOfExpression, TypeOperatorNode, @@ -240,15 +247,6 @@ import { WhileStatement, WithStatement, YieldExpression, - AstHasModifiers, - AstHasDecorators, -} from "../_namespaces/ts.ast.js"; -import { - canHaveJSDoc, - isLeftHandSideExpressionKind, - NodeFlags, - OuterExpressionKinds, - SyntaxKind, } from "../_namespaces/ts.js"; // Literals @@ -700,7 +698,7 @@ export function isAstTaggedTemplateExpression(node: AstNode): node is AstNode { +export function isAstTypeAssertionExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeAssertionExpression; } diff --git a/src/compiler/factory/astParenthesizerRules.ts b/src/compiler/factory/astParenthesizerRules.ts index 1fa10e23920fa..a57fd4bfdf867 100644 --- a/src/compiler/factory/astParenthesizerRules.ts +++ b/src/compiler/factory/astParenthesizerRules.ts @@ -36,10 +36,7 @@ import { isAstTypeOperatorNode, isAstUnionTypeNode, skipAstOuterExpressions, -} from "../_namespaces/ts.ast.js"; -import { Associativity, - ast, BinaryOperator, compareValues, Comparison, @@ -75,7 +72,7 @@ export interface AstParenthesizerRules { parenthesizeLeftSideOfAccess(expression: AstExpression, optionalChain?: boolean): AstLeftHandSideExpression; parenthesizeOperandOfPostfixUnary(operand: AstExpression): AstLeftHandSideExpression; parenthesizeOperandOfPrefixUnary(operand: AstExpression): AstUnaryExpression; - parenthesizeExpressionsOfCommaDelimitedList(elements: AstNodeArrayLike): AstNodeArray; + parenthesizeExpressionsOfCommaDelimitedList(elements: AstNodeArrayLike): AstNodeArray; parenthesizeExpressionForDisallowedComma(expression: AstExpression): AstExpression; parenthesizeExpressionOfExpressionStatement(expression: AstExpression): AstExpression; parenthesizeConciseBodyOfArrowFunction(body: AstExpression): AstExpression; @@ -487,7 +484,7 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth emittedExpression, setTextRange(factory.createParenthesizedExpression(callee), callee), emittedExpression.data.typeArguments, - emittedExpression.data.arguments!, + emittedExpression.data.arguments, ); return factory.restoreOuterExpressions(expression, updated, OuterExpressionKinds.PartiallyEmittedExpressions); } @@ -667,8 +664,8 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth if (isAstNamedTupleMember(type)) return hasJSDocPostfixQuestion(type.data.type); if (isAstFunctionTypeNode(type) || isAstConstructorTypeNode(type) || isAstTypeOperatorNode(type)) return hasJSDocPostfixQuestion(type.data.type); if (isAstConditionalTypeNode(type)) return hasJSDocPostfixQuestion(type.data.falseType); - if (isAstUnionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types!.items)); - if (isAstIntersectionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types!.items)); + if (isAstUnionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types.items)); + if (isAstIntersectionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types.items)); if (isAstInferTypeNode(type)) return !!type.data.typeParameter.data.constraint && hasJSDocPostfixQuestion(type.data.typeParameter.data.constraint); return false; } diff --git a/src/compiler/factory/emitNode.ts b/src/compiler/factory/emitNode.ts index 303deef85f013..bc9b6a8af6cb1 100644 --- a/src/compiler/factory/emitNode.ts +++ b/src/compiler/factory/emitNode.ts @@ -2,12 +2,16 @@ import { AccessExpression, append, appendIfUnique, - ast, + AstIdentifier, + AstNode, + AstPrivateIdentifier, AutoGenerateInfo, Debug, EmitFlags, EmitHelper, EmitNode, + getAstParseTreeNode, + getAstSourceFileNodeOfNode, getParseTreeNode, getSourceFileOfNode, Identifier, @@ -34,7 +38,7 @@ import { * various transient transformation properties. * @internal */ -export function getOrCreateEmitNode(node: Node | ast.AstNode): EmitNode { +export function getOrCreateEmitNode(node: Node | AstNode): EmitNode { if (!node.emitNode) { if (isParseTreeNode(node)) { // To avoid holding onto transformation artifacts, we keep track of any @@ -44,8 +48,8 @@ export function getOrCreateEmitNode(node: Node | ast.AstNode): EmitNod return node.emitNode = { annotatedNodes: [node] } as EmitNode; } - if (node instanceof ast.AstNode) { - const sourceFile = ast.getAstSourceFileNodeOfNode(ast.getAstParseTreeNode(ast.getAstSourceFileNodeOfNode(node))) ?? Debug.fail("Could not determine parsed source file."); + if (node instanceof AstNode) { + const sourceFile = getAstSourceFileNodeOfNode(getAstParseTreeNode(getAstSourceFileNodeOfNode(node))) ?? Debug.fail("Could not determine parsed source file."); getOrCreateEmitNode(sourceFile).annotatedNodes!.push(node.node); } else { @@ -98,8 +102,8 @@ export function removeAllComments(node: T): T { */ export function setEmitFlags(node: T, emitFlags: EmitFlags): T; /** @internal */ -export function setEmitFlags>(node: T, emitFlags: EmitFlags): T; -export function setEmitFlags>(node: T, emitFlags: EmitFlags) { +export function setEmitFlags(node: T, emitFlags: EmitFlags): T; +export function setEmitFlags(node: T, emitFlags: EmitFlags) { getOrCreateEmitNode(node).flags = emitFlags; return node; } @@ -141,8 +145,8 @@ export function addInternalEmitFlags(node: T, emitFlags: Interna */ export function getSourceMapRange(node: Node): SourceMapRange; /** @internal */ -export function getSourceMapRange(node: Node | ast.AstNode): SourceMapRange; // eslint-disable-line @typescript-eslint/unified-signatures -export function getSourceMapRange(node: Node | ast.AstNode): SourceMapRange { +export function getSourceMapRange(node: Node | AstNode): SourceMapRange; // eslint-disable-line @typescript-eslint/unified-signatures +export function getSourceMapRange(node: Node | AstNode): SourceMapRange { return node.emitNode?.sourceMapRange ?? node; } @@ -195,8 +199,8 @@ export function setStartsOnNewLine(node: T, newLine: boolean): T */ export function getCommentRange(node: Node): TextRange; /** @internal */ -export function getCommentRange(node: Node | ast.AstNode): TextRange; // eslint-disable-line @typescript-eslint/unified-signatures -export function getCommentRange(node: Node | ast.AstNode): TextRange { +export function getCommentRange(node: Node | AstNode): TextRange; // eslint-disable-line @typescript-eslint/unified-signatures +export function getCommentRange(node: Node | AstNode): TextRange { return node.emitNode?.commentRange ?? node; } @@ -210,8 +214,8 @@ export function setCommentRange(node: T, range: TextRange): T { export function getSyntheticLeadingComments(node: Node): SynthesizedComment[] | undefined; /** @internal */ -export function getSyntheticLeadingComments(node: Node | ast.AstNode): SynthesizedComment[] | undefined; // eslint-disable-line @typescript-eslint/unified-signatures -export function getSyntheticLeadingComments(node: Node | ast.AstNode): SynthesizedComment[] | undefined { +export function getSyntheticLeadingComments(node: Node | AstNode): SynthesizedComment[] | undefined; // eslint-disable-line @typescript-eslint/unified-signatures +export function getSyntheticLeadingComments(node: Node | AstNode): SynthesizedComment[] | undefined { return node.emitNode?.leadingComments; } @@ -226,8 +230,8 @@ export function addSyntheticLeadingComment(node: T, kind: Syntax export function getSyntheticTrailingComments(node: Node): SynthesizedComment[] | undefined; /** @internal */ -export function getSyntheticTrailingComments(node: Node | ast.AstNode): SynthesizedComment[] | undefined; // eslint-disable-line @typescript-eslint/unified-signatures -export function getSyntheticTrailingComments(node: Node | ast.AstNode): SynthesizedComment[] | undefined { +export function getSyntheticTrailingComments(node: Node | AstNode): SynthesizedComment[] | undefined; // eslint-disable-line @typescript-eslint/unified-signatures +export function getSyntheticTrailingComments(node: Node | AstNode): SynthesizedComment[] | undefined { return node.emitNode?.trailingComments; } @@ -370,24 +374,24 @@ export function getTypeNode(node: T): TypeNode | undefined { } /** @internal */ -export function setIdentifierTypeArguments(node: T, typeArguments: NodeArray | undefined): T { +export function setIdentifierTypeArguments(node: T, typeArguments: NodeArray | undefined): T { getOrCreateEmitNode(node).identifierTypeArguments = typeArguments; return node; } /** @internal */ -export function getIdentifierTypeArguments(node: Identifier | ast.AstIdentifier): NodeArray | undefined { +export function getIdentifierTypeArguments(node: Identifier | AstIdentifier): NodeArray | undefined { return node.emitNode?.identifierTypeArguments; } /** @internal */ -export function setIdentifierAutoGenerate(node: T, autoGenerate: AutoGenerateInfo | undefined): T { +export function setIdentifierAutoGenerate(node: T, autoGenerate: AutoGenerateInfo | undefined): T { getOrCreateEmitNode(node).autoGenerate = autoGenerate; return node; } /** @internal @knipignore */ -export function getIdentifierAutoGenerate(node: Identifier | PrivateIdentifier | ast.AstIdentifier | ast.AstPrivateIdentifier): AutoGenerateInfo | undefined { +export function getIdentifierAutoGenerate(node: Identifier | PrivateIdentifier | AstIdentifier | AstPrivateIdentifier): AutoGenerateInfo | undefined { return node.emitNode?.autoGenerate; } diff --git a/src/compiler/factory/nodeChildren.ts b/src/compiler/factory/nodeChildren.ts index da8e074415e00..3751851f7637b 100644 --- a/src/compiler/factory/nodeChildren.ts +++ b/src/compiler/factory/nodeChildren.ts @@ -1,11 +1,25 @@ import { + AstNode, + createScanner, Debug, emptyArray, + forEach, + forEachChild, + getSourceFileOfNode, + hasTabstop, + isJSDocCommentContainingNode, isNodeKind, + isTokenKind, + JSDocContainer, Node, + NodeArray, + NodeFlags, + Scanner, + ScriptTarget, SourceFileLike, SyntaxKind, SyntaxList, + TokenSyntaxKind, } from "../_namespaces/ts.js"; const sourceFileToNodeChildren = new WeakMap>(); @@ -59,3 +73,96 @@ export function transferSourceFileChildren(sourceFile: SourceFileLike, targetSou sourceFileToNodeChildren.set(targetSourceFile, map); } } + + +// copied form services/services.ts +let _scanner: Scanner | undefined; + +function scanner() { + _scanner ??= createScanner(ScriptTarget.Latest, /*skipTrivia*/ true); + return _scanner; +} + +/** @internal */ +export function createChildren(node: Node, sourceFile: SourceFileLike | undefined): readonly Node[] { + const children: Node[] = []; + + if (isJSDocCommentContainingNode(node)) { + /** Don't add trivia for "tokens" since this is in a comment. */ + forEachChild(node, child => { + children.push(child); + }); + return children; + } + + scanner().setText((sourceFile || getSourceFileOfNode(node)).text); + let pos = node.pos; + const processNode = (child: Node) => { + addSyntheticNodes(children, pos, child.pos, node); + children.push(child); + pos = child.end; + }; + const processNodes = (nodes: NodeArray) => { + addSyntheticNodes(children, pos, nodes.pos, node); + children.push(createSyntaxList(nodes, node)); + pos = nodes.end; + }; + // jsDocComments need to be the first children + forEach((node as JSDocContainer).jsDoc, processNode); + // For syntactic classifications, all trivia are classified together, including jsdoc comments. + // For that to work, the jsdoc comments should still be the leading trivia of the first child. + // Restoring the scanner position ensures that. + pos = node.pos; + forEachChild(node, processNode, processNodes); + addSyntheticNodes(children, pos, node.end, node); + scanner().setText(undefined); + return children; +} + +function createNode(kind: TKind, pos: number, end: number, parent: Node): Node { + const astNode = kind === SyntaxKind.StringLiteral ? AstNode.StringLiteral() : AstNode.Token(kind); + astNode.pos = pos; + astNode.end = end; + astNode.parent = parent.ast; + astNode.flags = parent.flags & NodeFlags.ContextFlags; + return astNode.node; +} + +function addSyntheticNodes(nodes: Node[], pos: number, end: number, parent: Node): void { + scanner().resetTokenState(pos); + while (pos < end) { + const token = scanner().scan(); + const textPos = scanner().getTokenEnd(); + if (textPos <= end) { + Debug.assert(isTokenKind(token)); + if (token === SyntaxKind.Identifier) { + if (hasTabstop(parent)) { + continue; + } + Debug.fail(`Did not expect ${Debug.formatSyntaxKind(parent.kind)} to have an ${Debug.formatSyntaxKind(token)} in its trivia`); + } + nodes.push(createNode(token as TokenSyntaxKind, pos, textPos, parent)); + } + pos = textPos; + if (token === SyntaxKind.EndOfFileToken) { + break; + } + } +} + +function createSyntaxList(nodes: NodeArray, parent: Node): Node { + const list = AstNode.SyntaxList(); + list.pos = nodes.pos; + list.end = nodes.end; + list.parent = parent.ast; + const children: Node[] = []; + let pos = nodes.pos; + for (const node of nodes) { + addSyntheticNodes(children, pos, node.pos, parent); + children.push(node); + pos = node.end; + } + addSyntheticNodes(children, pos, nodes.end, parent); + list.data._children = children; + return list.node; +} diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index d5d2079d4e98b..4e7d4c3548728 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -1,4 +1,3 @@ -import * as ast from "../_namespaces/ts.ast.js"; import { AccessorDeclaration, addRange, @@ -15,6 +14,7 @@ import { AssertionKey, AssertsKeyword, AsteriskToken, + AstNodeArray, AwaitExpression, AwaitKeyword, BigIntLiteral, @@ -24,6 +24,7 @@ import { BindingElement, BindingName, Block, + BooleanLiteral, BreakStatement, Bundle, CallBinding, @@ -48,6 +49,7 @@ import { ConstructorTypeNode, ConstructSignatureDeclaration, ContinueStatement, + createAstNodeFactory, createNodeConverters, createParenthesizerRules, Debug, @@ -245,7 +247,6 @@ import { KeywordTypeSyntaxKind, LabeledStatement, LeftHandSideExpression, - LiteralExpression, LiteralToken, LiteralTypeNode, MappedTypeNode, @@ -292,7 +293,6 @@ import { NumericLiteral, objectAllocator, ObjectBindingPattern, - ObjectLiteralElement, ObjectLiteralElementLike, ObjectLiteralExpression, OmittedExpression, @@ -382,7 +382,7 @@ import { TupleTypeNode, Type, TypeAliasDeclaration, - TypeAssertion, + TypeAssertionExpression, TypeElement, TypeLiteralNode, TypeNode, @@ -436,7 +436,7 @@ export function addNodeFactoryPatcher(fn: (factory: NodeFactory) => void): void * @internal */ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: Node) => void): NodeFactory { - const astFactory = ast.createAstNodeFactory(flags, onFinishNode && (ast => onFinishNode(ast.node))); + const astFactory = createAstNodeFactory(flags, onFinishNode && (ast => onFinishNode(ast.node))); // Lazily load the parenthesizer, node converters, and some factory methods until they are used. const parenthesizerRules = memoize(() => flags & NodeFactoryFlags.NoParenthesizerRules ? nullParenthesizerRules : createParenthesizerRules(factory)); @@ -1023,11 +1023,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createNodeArray(elements?: readonly T[], hasTrailingComma?: boolean): NodeArray { - if (elements instanceof ast.NodeArray) { + if (elements instanceof NodeArray) { return elements; } - return new ast.AstNodeArray(elements?.map(element => (element as Node as ast.Node).ast) ?? [], hasTrailingComma).nodes as readonly Node[] as NodeArray; + return new AstNodeArray(elements?.map(element => element.ast) ?? [], hasTrailingComma).nodes as NodeArray; } // @@ -1052,7 +1052,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createStringLiteralFromNode(sourceNode: PropertyNameLiteral | PrivateIdentifier): StringLiteral { const node = astFactory.createStringLiteral(getTextOfIdentifierOrLiteral(sourceNode), /*isSingleQuote*/ undefined).node; - node.textSourceNode = sourceNode as ast.PropertyNameLiteral | ast.PrivateIdentifier; + node.textSourceNode = sourceNode; return node; } @@ -1264,22 +1264,22 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createQualifiedName(left: EntityName, right: string | Identifier): QualifiedName { - return astFactory.createQualifiedName(asNode(left).ast, typeof right === "string" ? right : asNode(right).ast).node; + return astFactory.createQualifiedName(left.ast, typeof right === "string" ? right : right.ast).node; } // @api function updateQualifiedName(node: QualifiedName, left: EntityName, right: Identifier): QualifiedName { - return astFactory.updateQualifiedName(asNode(node).ast, asNode(left).ast, asNode(right).ast).node; + return astFactory.updateQualifiedName(node.ast, left.ast, right.ast).node; } // @api function createComputedPropertyName(expression: Expression): ComputedPropertyName { - return astFactory.createComputedPropertyName(asNode(expression).ast).node; + return astFactory.createComputedPropertyName(expression.ast).node; } // @api function updateComputedPropertyName(node: ComputedPropertyName, expression: Expression): ComputedPropertyName { - return astFactory.updateComputedPropertyName(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateComputedPropertyName(node.ast, expression.ast).node; } // @@ -1288,12 +1288,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createTypeParameterDeclaration(modifiers: readonly Modifier[] | undefined, name: string | Identifier, constraint?: TypeNode, defaultType?: TypeNode): TypeParameterDeclaration { - return astFactory.createTypeParameterDeclaration(asNodeArray(modifiers)?.ast, asName(name).ast, asNode(constraint)?.ast, asNode(defaultType)?.ast).node; + return astFactory.createTypeParameterDeclaration(asNodeArray(modifiers)?.ast, asName(name).ast, constraint?.ast, defaultType?.ast).node; } // @api function updateTypeParameterDeclaration(node: TypeParameterDeclaration, modifiers: readonly Modifier[] | undefined, name: Identifier, constraint: TypeNode | undefined, defaultType: TypeNode | undefined): TypeParameterDeclaration { - return astFactory.updateTypeParameterDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNode(constraint)?.ast, asNode(defaultType)?.ast).node; + return astFactory.updateTypeParameterDeclaration(node.ast, asNodeArray(modifiers)?.ast, name.ast, constraint?.ast, defaultType?.ast).node; } // @api @@ -1306,7 +1306,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: initializer?: Expression, ): ParameterDeclaration { // NOTE: JSDoc parameters don't have names and we currently passed `undefined!` - return astFactory.createParameterDeclaration(asNodeArray(modifiers)?.ast, asNode(dotDotDotToken)?.ast, asName(name)?.ast, asNode(questionToken)?.ast, asNode(type)?.ast, asNode(initializer)?.ast).node; + return astFactory.createParameterDeclaration(asNodeArray(modifiers)?.ast, dotDotDotToken?.ast, asName(name)?.ast, questionToken?.ast, type?.ast, initializer?.ast).node; } // @api @@ -1319,17 +1319,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: type: TypeNode | undefined, initializer: Expression | undefined, ): ParameterDeclaration { - return astFactory.updateParameterDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(dotDotDotToken)?.ast, asName(name)?.ast, asNode(questionToken)?.ast, asNode(type)?.ast, asNode(initializer)?.ast).node; + return astFactory.updateParameterDeclaration(node.ast, asNodeArray(modifiers)?.ast, dotDotDotToken?.ast, asName(name)?.ast, questionToken?.ast, type?.ast, initializer?.ast).node; } // @api function createDecorator(expression: Expression): Decorator { - return astFactory.createDecorator(asNode(expression).ast).node; + return astFactory.createDecorator(expression.ast).node; } // @api function updateDecorator(node: Decorator, expression: Expression): Decorator { - return astFactory.updateDecorator((node as ast.Decorator).ast, asNode(expression).ast).node; + return astFactory.updateDecorator(node.ast, expression.ast).node; } // @@ -1343,7 +1343,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: questionToken: QuestionToken | undefined, type: TypeNode | undefined, ): PropertySignature { - return astFactory.createPropertySignature(asNodeArray(modifiers)?.ast, asName(name).ast, asNode(questionToken)?.ast, asNode(type)?.ast).node; + return astFactory.createPropertySignature(asNodeArray(modifiers)?.ast, asName(name).ast, questionToken?.ast, type?.ast).node; } // @api @@ -1354,7 +1354,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: questionToken: QuestionToken | undefined, type: TypeNode | undefined, ): PropertySignature { - return astFactory.updatePropertySignature(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNode(questionToken)?.ast, asNode(type)?.ast).node; + return astFactory.updatePropertySignature(node.ast, asNodeArray(modifiers)?.ast, name.ast, questionToken?.ast, type?.ast).node; } // @api @@ -1365,7 +1365,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: type: TypeNode | undefined, initializer: Expression | undefined, ): PropertyDeclaration { - return astFactory.createPropertyDeclaration(asNodeArray(modifiers)?.ast, asName(name).ast, asNode(questionOrExclamationToken)?.ast, asNode(type)?.ast, asNode(initializer)?.ast).node; + return astFactory.createPropertyDeclaration(asNodeArray(modifiers)?.ast, asName(name).ast, questionOrExclamationToken?.ast, type?.ast, initializer?.ast).node; } // @api @@ -1377,7 +1377,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: type: TypeNode | undefined, initializer: Expression | undefined, ): PropertyDeclaration { - return astFactory.updatePropertyDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asName(name).ast, asNode(questionOrExclamationToken)?.ast, asNode(type)?.ast, asNode(initializer)?.ast).node; + return astFactory.updatePropertyDeclaration(node.ast, asNodeArray(modifiers)?.ast, asName(name).ast, questionOrExclamationToken?.ast, type?.ast, initializer?.ast).node; } // @api @@ -1389,7 +1389,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, ): MethodSignature { - return astFactory.createMethodSignature(asNodeArray(modifiers)?.ast, asName(name).ast, asNode(questionToken)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; + return astFactory.createMethodSignature(asNodeArray(modifiers)?.ast, asName(name).ast, questionToken?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast).node; } // @api @@ -1402,7 +1402,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: NodeArray, type: TypeNode | undefined, ): MethodSignature { - return astFactory.updateMethodSignature(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNode(questionToken)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; + return astFactory.updateMethodSignature(node.ast, asNodeArray(modifiers)?.ast, name.ast, questionToken?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast).node; } // @api @@ -1416,7 +1416,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: type: TypeNode | undefined, body: Block | undefined, ): MethodDeclaration { - return astFactory.createMethodDeclaration(asNodeArray(modifiers)?.ast, asNode(asteriskToken)?.ast, asName(name).ast, asNode(questionToken)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body)?.ast).node; + return astFactory.createMethodDeclaration(asNodeArray(modifiers)?.ast, asteriskToken?.ast, asName(name).ast, questionToken?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast, body?.ast).node; } // @api @@ -1431,14 +1431,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: type: TypeNode | undefined, body: Block | undefined, ): MethodDeclaration { - return astFactory.updateMethodDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(asteriskToken)?.ast, asNode(name).ast, asNode(questionToken)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body)?.ast).node; + return astFactory.updateMethodDeclaration(node.ast, asNodeArray(modifiers)?.ast, asteriskToken?.ast, name.ast, questionToken?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast, body?.ast).node; } // @api function createClassStaticBlockDeclaration( body: Block, ): ClassStaticBlockDeclaration { - return astFactory.createClassStaticBlockDeclaration(asNode(body).ast).node; + return astFactory.createClassStaticBlockDeclaration(body.ast).node; } // @api @@ -1446,7 +1446,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: node: ClassStaticBlockDeclaration, body: Block, ): ClassStaticBlockDeclaration { - return astFactory.updateClassStaticBlockDeclaration(asNode(node).ast, asNode(body).ast).node; + return astFactory.updateClassStaticBlockDeclaration(node.ast, body.ast).node; } // @api @@ -1455,7 +1455,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: readonly ParameterDeclaration[], body: Block | undefined, ): ConstructorDeclaration { - return astFactory.createConstructorDeclaration(asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, asNode(body)?.ast).node; + return astFactory.createConstructorDeclaration(asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, body?.ast).node; } // @api @@ -1465,7 +1465,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: readonly ParameterDeclaration[], body: Block | undefined, ): ConstructorDeclaration { - return astFactory.updateConstructorDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, asNode(body)?.ast).node; + return astFactory.updateConstructorDeclaration(node.ast, asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, body?.ast).node; } // @api @@ -1476,7 +1476,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: type: TypeNode | undefined, body: Block | undefined, ): GetAccessorDeclaration { - return astFactory.createGetAccessorDeclaration(asNodeArray(modifiers)?.ast, asName(name)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body)?.ast).node; + return astFactory.createGetAccessorDeclaration(asNodeArray(modifiers)?.ast, asName(name)?.ast, asNodeArray(parameters).ast, type?.ast, body?.ast).node; } // @api @@ -1488,7 +1488,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: type: TypeNode | undefined, body: Block | undefined, ): GetAccessorDeclaration { - return astFactory.updateGetAccessorDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body)?.ast).node; + return astFactory.updateGetAccessorDeclaration(node.ast, asNodeArray(modifiers)?.ast, name.ast, asNodeArray(parameters).ast, type?.ast, body?.ast).node; } // @api @@ -1498,7 +1498,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: readonly ParameterDeclaration[], body: Block | undefined, ): SetAccessorDeclaration { - return astFactory.createSetAccessorDeclaration(asNodeArray(modifiers)?.ast, asName(name)?.ast, asNodeArray(parameters).ast, asNode(body)?.ast).node; + return astFactory.createSetAccessorDeclaration(asNodeArray(modifiers)?.ast, asName(name)?.ast, asNodeArray(parameters).ast, body?.ast).node; } // @api @@ -1509,7 +1509,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: readonly ParameterDeclaration[], body: Block | undefined, ): SetAccessorDeclaration { - return astFactory.updateSetAccessorDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNodeArray(parameters).ast, asNode(body)?.ast).node; + return astFactory.updateSetAccessorDeclaration(node.ast, asNodeArray(modifiers)?.ast, name.ast, asNodeArray(parameters).ast, body?.ast).node; } // @api @@ -1518,7 +1518,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, ): CallSignatureDeclaration { - return astFactory.createCallSignature(asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; + return astFactory.createCallSignature(asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast).node; } // @api @@ -1528,7 +1528,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: NodeArray, type: TypeNode | undefined, ): CallSignatureDeclaration { - return astFactory.updateCallSignature(asNode(node).ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; + return astFactory.updateCallSignature(node.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast).node; } // @api @@ -1537,7 +1537,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, ): ConstructSignatureDeclaration { - return astFactory.createConstructSignature(asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; + return astFactory.createConstructSignature(asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast).node; } // @api @@ -1547,7 +1547,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: NodeArray, type: TypeNode | undefined, ): ConstructSignatureDeclaration { - return astFactory.updateConstructSignature(asNode(node).ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; + return astFactory.updateConstructSignature(node.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast).node; } // @api @@ -1556,7 +1556,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: readonly ParameterDeclaration[], type: TypeNode | undefined, ): IndexSignatureDeclaration { - return astFactory.createIndexSignature(asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; + return astFactory.createIndexSignature(asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, type?.ast).node; } // @api @@ -1566,17 +1566,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: readonly ParameterDeclaration[], type: TypeNode, ): IndexSignatureDeclaration { - return astFactory.updateIndexSignature(asNode(node).ast, asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, asNode(type).ast).node; + return astFactory.updateIndexSignature(node.ast, asNodeArray(modifiers)?.ast, asNodeArray(parameters).ast, type.ast).node; } // @api function createTemplateLiteralTypeSpan(type: TypeNode, literal: TemplateMiddle | TemplateTail): TemplateLiteralTypeSpan { - return astFactory.createTemplateLiteralTypeSpan(asNode(type).ast, asNode(literal).ast).node; + return astFactory.createTemplateLiteralTypeSpan(type.ast, literal.ast).node; } // @api function updateTemplateLiteralTypeSpan(node: TemplateLiteralTypeSpan, type: TypeNode, literal: TemplateMiddle | TemplateTail): TemplateLiteralTypeSpan { - return astFactory.updateTemplateLiteralTypeSpan(asNode(node).ast, asNode(type).ast, asNode(literal).ast).node; + return astFactory.updateTemplateLiteralTypeSpan(node.ast, type.ast, literal.ast).node; } // @@ -1590,12 +1590,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createTypePredicateNode(assertsModifier: AssertsKeyword | undefined, parameterName: Identifier | ThisTypeNode | string, type: TypeNode | undefined): TypePredicateNode { - return astFactory.createTypePredicateNode(asNode(assertsModifier)?.ast, asName(parameterName).ast, asNode(type)?.ast).node; + return astFactory.createTypePredicateNode(assertsModifier?.ast, asName(parameterName).ast, type?.ast).node; } // @api function updateTypePredicateNode(node: TypePredicateNode, assertsModifier: AssertsKeyword | undefined, parameterName: Identifier | ThisTypeNode, type: TypeNode | undefined): TypePredicateNode { - return astFactory.updateTypePredicateNode(asNode(node).ast, asNode(assertsModifier)?.ast, asName(parameterName).ast, asNode(type)?.ast).node; + return astFactory.updateTypePredicateNode(node.ast, assertsModifier?.ast, asName(parameterName).ast, type?.ast).node; } // @api @@ -1605,7 +1605,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateTypeReferenceNode(node: TypeReferenceNode, typeName: EntityName, typeArguments: NodeArray | undefined): TypeReferenceNode { - return astFactory.updateTypeReferenceNode(asNode(node).ast, asNode(typeName).ast, asNodeArray(typeArguments)?.ast).node; + return astFactory.updateTypeReferenceNode(node.ast, typeName.ast, asNodeArray(typeArguments)?.ast).node; } // @api @@ -1614,7 +1614,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: readonly ParameterDeclaration[], type: TypeNode, ): FunctionTypeNode { - return astFactory.createFunctionTypeNode(asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type).ast).node; + return astFactory.createFunctionTypeNode(asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type.ast).node; } // @api @@ -1624,7 +1624,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: NodeArray, type: TypeNode, ): FunctionTypeNode { - return astFactory.updateFunctionTypeNode(asNode(node).ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type).ast).node; + return astFactory.updateFunctionTypeNode(node.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type.ast).node; } // @api @@ -1640,7 +1640,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: readonly ParameterDeclaration[], type: TypeNode, ): ConstructorTypeNode { - return astFactory.createConstructorTypeNode(asNodeArray(modifiers)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type).ast).node; + return astFactory.createConstructorTypeNode(asNodeArray(modifiers)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type.ast).node; } /** @deprecated */ @@ -1666,7 +1666,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: parameters: NodeArray, type: TypeNode, ): ConstructorTypeNode { - return astFactory.updateConstructorTypeNode(asNode(node).ast, asNodeArray(modifiers)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type).ast).node; + return astFactory.updateConstructorTypeNode(node.ast, asNodeArray(modifiers)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type.ast).node; } /** @deprecated */ @@ -1681,12 +1681,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createTypeQueryNode(exprName: EntityName, typeArguments?: readonly TypeNode[]): TypeQueryNode { - return astFactory.createTypeQueryNode(asNode(exprName).ast, asNodeArray(typeArguments)?.ast).node; + return astFactory.createTypeQueryNode(exprName.ast, asNodeArray(typeArguments)?.ast).node; } // @api function updateTypeQueryNode(node: TypeQueryNode, exprName: EntityName, typeArguments?: readonly TypeNode[]): TypeQueryNode { - return astFactory.updateTypeQueryNode(asNode(node).ast, asNode(exprName).ast, asNodeArray(typeArguments)?.ast).node; + return astFactory.updateTypeQueryNode(node.ast, exprName.ast, asNodeArray(typeArguments)?.ast).node; } // @api @@ -1696,17 +1696,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateTypeLiteralNode(node: TypeLiteralNode, members: NodeArray): TypeLiteralNode { - return astFactory.updateTypeLiteralNode(asNode(node).ast, asNodeArray(members).ast).node; + return astFactory.updateTypeLiteralNode(node.ast, asNodeArray(members).ast).node; } // @api function createArrayTypeNode(elementType: TypeNode): ArrayTypeNode { - return astFactory.createArrayTypeNode(asNode(elementType).ast).node; + return astFactory.createArrayTypeNode(elementType.ast).node; } // @api function updateArrayTypeNode(node: ArrayTypeNode, elementType: TypeNode): ArrayTypeNode { - return astFactory.updateArrayTypeNode(asNode(node).ast, asNode(elementType).ast).node; + return astFactory.updateArrayTypeNode(node.ast, elementType.ast).node; } // @api @@ -1716,37 +1716,37 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateTupleTypeNode(node: TupleTypeNode, elements: readonly (TypeNode | NamedTupleMember)[]): TupleTypeNode { - return astFactory.updateTupleTypeNode(asNode(node).ast, asNodeArray(elements).ast).node; + return astFactory.updateTupleTypeNode(node.ast, asNodeArray(elements).ast).node; } // @api function createNamedTupleMember(dotDotDotToken: DotDotDotToken | undefined, name: Identifier, questionToken: QuestionToken | undefined, type: TypeNode): NamedTupleMember { - return astFactory.createNamedTupleMember(asNode(dotDotDotToken)?.ast, asNode(name).ast, asNode(questionToken)?.ast, asNode(type).ast).node; + return astFactory.createNamedTupleMember(dotDotDotToken?.ast, name.ast, questionToken?.ast, type.ast).node; } // @api function updateNamedTupleMember(node: NamedTupleMember, dotDotDotToken: DotDotDotToken | undefined, name: Identifier, questionToken: QuestionToken | undefined, type: TypeNode): NamedTupleMember { - return astFactory.updateNamedTupleMember(asNode(node).ast, asNode(dotDotDotToken)?.ast, asNode(name).ast, asNode(questionToken)?.ast, asNode(type).ast).node; + return astFactory.updateNamedTupleMember(node.ast, dotDotDotToken?.ast, name.ast, questionToken?.ast, type.ast).node; } // @api function createOptionalTypeNode(type: TypeNode): OptionalTypeNode { - return astFactory.createOptionalTypeNode(asNode(type).ast).node; + return astFactory.createOptionalTypeNode(type.ast).node; } // @api function updateOptionalTypeNode(node: OptionalTypeNode, type: TypeNode): OptionalTypeNode { - return astFactory.updateOptionalTypeNode(asNode(node).ast, asNode(type).ast).node; + return astFactory.updateOptionalTypeNode(node.ast, type.ast).node; } // @api function createRestTypeNode(type: TypeNode): RestTypeNode { - return astFactory.createRestTypeNode(asNode(type).ast).node; + return astFactory.createRestTypeNode(type.ast).node; } // @api function updateRestTypeNode(node: RestTypeNode, type: TypeNode): RestTypeNode { - return astFactory.updateRestTypeNode(asNode(node).ast, asNode(type).ast).node; + return astFactory.updateRestTypeNode(node.ast, type.ast).node; } // @api @@ -1756,7 +1756,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateUnionTypeNode(node: UnionTypeNode, types: NodeArray): UnionTypeNode { - return astFactory.updateUnionTypeNode(asNode(node).ast, asNodeArray(types).ast).node; + return astFactory.updateUnionTypeNode(node.ast, asNodeArray(types).ast).node; } // @api @@ -1766,37 +1766,37 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateIntersectionTypeNode(node: IntersectionTypeNode, types: NodeArray): IntersectionTypeNode { - return astFactory.updateIntersectionTypeNode(asNode(node).ast, asNodeArray(types).ast).node; + return astFactory.updateIntersectionTypeNode(node.ast, asNodeArray(types).ast).node; } // @api function createConditionalTypeNode(checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode { - return astFactory.createConditionalTypeNode(asNode(checkType).ast, asNode(extendsType).ast, asNode(trueType).ast, asNode(falseType).ast).node; + return astFactory.createConditionalTypeNode(checkType.ast, extendsType.ast, trueType.ast, falseType.ast).node; } // @api function updateConditionalTypeNode(node: ConditionalTypeNode, checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode { - return astFactory.updateConditionalTypeNode(asNode(node).ast, asNode(checkType).ast, asNode(extendsType).ast, asNode(trueType).ast, asNode(falseType).ast).node; + return astFactory.updateConditionalTypeNode(node.ast, checkType.ast, extendsType.ast, trueType.ast, falseType.ast).node; } // @api function createInferTypeNode(typeParameter: TypeParameterDeclaration): InferTypeNode { - return astFactory.createInferTypeNode(asNode(typeParameter).ast).node; + return astFactory.createInferTypeNode(typeParameter.ast).node; } // @api function updateInferTypeNode(node: InferTypeNode, typeParameter: TypeParameterDeclaration): InferTypeNode { - return astFactory.updateInferTypeNode(asNode(node).ast, asNode(typeParameter).ast).node; + return astFactory.updateInferTypeNode(node.ast, typeParameter.ast).node; } // @api function createTemplateLiteralType(head: TemplateHead, templateSpans: readonly TemplateLiteralTypeSpan[]): TemplateLiteralTypeNode { - return astFactory.createTemplateLiteralType(asNode(head).ast, asNodeArray(templateSpans).ast).node; + return astFactory.createTemplateLiteralType(head.ast, asNodeArray(templateSpans).ast).node; } // @api function updateTemplateLiteralType(node: TemplateLiteralTypeNode, head: TemplateHead, templateSpans: readonly TemplateLiteralTypeSpan[]): TemplateLiteralTypeNode { - return astFactory.updateTemplateLiteralType(asNode(node).ast, asNode(head).ast, asNodeArray(templateSpans).ast).node; + return astFactory.updateTemplateLiteralType(node.ast, head.ast, asNodeArray(templateSpans).ast).node; } // @api @@ -1807,7 +1807,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: typeArguments?: readonly TypeNode[], isTypeOf = false, ): ImportTypeNode { - return astFactory.createImportTypeNode(asNode(argument).ast, asNode(attributes)?.ast, asNode(qualifier)?.ast, asNodeArray(typeArguments)?.ast, isTypeOf).node; + return astFactory.createImportTypeNode(argument.ast, attributes?.ast, qualifier?.ast, asNodeArray(typeArguments)?.ast, isTypeOf).node; } // @api @@ -1819,17 +1819,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: typeArguments: readonly TypeNode[] | undefined, isTypeOf: boolean = node.isTypeOf, ): ImportTypeNode { - return astFactory.updateImportTypeNode(asNode(node).ast, asNode(argument).ast, asNode(attributes)?.ast, asNode(qualifier)?.ast, asNodeArray(typeArguments)?.ast, isTypeOf).node; + return astFactory.updateImportTypeNode(node.ast, argument.ast, attributes?.ast, qualifier?.ast, asNodeArray(typeArguments)?.ast, isTypeOf).node; } // @api function createParenthesizedType(type: TypeNode): ParenthesizedTypeNode { - return astFactory.createParenthesizedType(asNode(type).ast).node; + return astFactory.createParenthesizedType(type.ast).node; } // @api function updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode { - return astFactory.updateParenthesizedType(asNode(node).ast, asNode(type).ast).node; + return astFactory.updateParenthesizedType(node.ast, type.ast).node; } // @api @@ -1839,42 +1839,42 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: TypeNode): TypeOperatorNode { - return astFactory.createTypeOperatorNode(operator, asNode(type).ast).node; + return astFactory.createTypeOperatorNode(operator, type.ast).node; } // @api function updateTypeOperatorNode(node: TypeOperatorNode, type: TypeNode): TypeOperatorNode { - return astFactory.updateTypeOperatorNode(asNode(node).ast, asNode(type).ast).node; + return astFactory.updateTypeOperatorNode(node.ast, type.ast).node; } // @api function createIndexedAccessTypeNode(objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode { - return astFactory.createIndexedAccessTypeNode(asNode(objectType).ast, asNode(indexType).ast).node; + return astFactory.createIndexedAccessTypeNode(objectType.ast, indexType.ast).node; } // @api function updateIndexedAccessTypeNode(node: IndexedAccessTypeNode, objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode { - return astFactory.updateIndexedAccessTypeNode(asNode(node).ast, asNode(objectType).ast, asNode(indexType).ast).node; + return astFactory.updateIndexedAccessTypeNode(node.ast, objectType.ast, indexType.ast).node; } // @api function createMappedTypeNode(readonlyToken: ReadonlyKeyword | PlusToken | MinusToken | undefined, typeParameter: TypeParameterDeclaration, nameType: TypeNode | undefined, questionToken: QuestionToken | PlusToken | MinusToken | undefined, type: TypeNode | undefined, members: readonly TypeElement[] | undefined): MappedTypeNode { - return astFactory.createMappedTypeNode(asNode(readonlyToken)?.ast, asNode(typeParameter).ast, asNode(nameType)?.ast, asNode(questionToken)?.ast, asNode(type)?.ast, asNodeArray(members)?.ast).node; + return astFactory.createMappedTypeNode(readonlyToken?.ast, typeParameter.ast, nameType?.ast, questionToken?.ast, type?.ast, asNodeArray(members)?.ast).node; } // @api function updateMappedTypeNode(node: MappedTypeNode, readonlyToken: ReadonlyKeyword | PlusToken | MinusToken | undefined, typeParameter: TypeParameterDeclaration, nameType: TypeNode | undefined, questionToken: QuestionToken | PlusToken | MinusToken | undefined, type: TypeNode | undefined, members: readonly TypeElement[] | undefined): MappedTypeNode { - return astFactory.updateMappedTypeNode(asNode(node).ast, asNode(readonlyToken)?.ast, asNode(typeParameter).ast, asNode(nameType)?.ast, asNode(questionToken)?.ast, asNode(type)?.ast, asNodeArray(members)?.ast).node; + return astFactory.updateMappedTypeNode(node.ast, readonlyToken?.ast, typeParameter.ast, nameType?.ast, questionToken?.ast, type?.ast, asNodeArray(members)?.ast).node; } // @api function createLiteralTypeNode(literal: LiteralTypeNode["literal"]): LiteralTypeNode { - return astFactory.createLiteralTypeNode(asNode(literal).ast).node; + return astFactory.createLiteralTypeNode(literal.ast).node; } // @api function updateLiteralTypeNode(node: LiteralTypeNode, literal: LiteralTypeNode["literal"]): LiteralTypeNode { - return astFactory.updateLiteralTypeNode(asNode(node).ast, asNode(literal).ast).node; + return astFactory.updateLiteralTypeNode(node.ast, literal.ast).node; } // @@ -1888,7 +1888,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateObjectBindingPattern(node: ObjectBindingPattern, elements: readonly BindingElement[]): ObjectBindingPattern { - return astFactory.updateObjectBindingPattern(asNode(node).ast, asNodeArray(elements).ast).node; + return astFactory.updateObjectBindingPattern(node.ast, asNodeArray(elements).ast).node; } // @api @@ -1898,17 +1898,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateArrayBindingPattern(node: ArrayBindingPattern, elements: readonly ArrayBindingElement[]): ArrayBindingPattern { - return astFactory.updateArrayBindingPattern(asNode(node).ast, asNodeArray(elements).ast).node; + return astFactory.updateArrayBindingPattern(node.ast, asNodeArray(elements).ast).node; } // @api function createBindingElement(dotDotDotToken: DotDotDotToken | undefined, propertyName: string | PropertyName | undefined, name: string | BindingName, initializer?: Expression): BindingElement { - return astFactory.createBindingElement(asNode(dotDotDotToken)?.ast, asName(propertyName)?.ast, asName(name).ast, asNode(initializer)?.ast).node; + return astFactory.createBindingElement(dotDotDotToken?.ast, asName(propertyName)?.ast, asName(name).ast, initializer?.ast).node; } // @api function updateBindingElement(node: BindingElement, dotDotDotToken: DotDotDotToken | undefined, propertyName: PropertyName | undefined, name: BindingName, initializer: Expression | undefined): BindingElement { - return astFactory.updateBindingElement(asNode(node).ast, asNode(dotDotDotToken)?.ast, asNode(propertyName)?.ast, asNode(name).ast, asNode(initializer)?.ast).node; + return astFactory.updateBindingElement(node.ast, dotDotDotToken?.ast, propertyName?.ast, name.ast, initializer?.ast).node; } // @@ -1922,7 +1922,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateArrayLiteralExpression(node: ArrayLiteralExpression, elements: readonly Expression[]): ArrayLiteralExpression { - return astFactory.updateArrayLiteralExpression(asNode(node).ast, asNodeArray(elements).ast).node; + return astFactory.updateArrayLiteralExpression(node.ast, asNodeArray(elements).ast).node; } // @api @@ -1932,107 +1932,107 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateObjectLiteralExpression(node: ObjectLiteralExpression, properties: readonly ObjectLiteralElementLike[]): ObjectLiteralExpression { - return astFactory.updateObjectLiteralExpression(asNode(node).ast, asNodeArray(properties).ast).node; + return astFactory.updateObjectLiteralExpression(node.ast, asNodeArray(properties).ast).node; } // @api function createPropertyAccessExpression(expression: Expression, name: string | Identifier | PrivateIdentifier): PropertyAccessExpression { - return astFactory.createPropertyAccessExpression(asNode(expression).ast, asName(name).ast).node; + return astFactory.createPropertyAccessExpression(expression.ast, asName(name).ast).node; } // @api function updatePropertyAccessExpression(node: PropertyAccessExpression, expression: Expression, name: Identifier | PrivateIdentifier): PropertyAccessExpression { - return astFactory.updatePropertyAccessExpression(asNode(node).ast, asNode(expression).ast, asNode(name).ast).node; + return astFactory.updatePropertyAccessExpression(node.ast, expression.ast, name.ast).node; } // @api function createPropertyAccessChain(expression: Expression, questionDotToken: QuestionDotToken | undefined, name: string | Identifier | PrivateIdentifier): PropertyAccessChain { - return astFactory.createPropertyAccessChain(asNode(expression).ast, asNode(questionDotToken)?.ast, asName(name).ast).node; + return astFactory.createPropertyAccessChain(expression.ast, questionDotToken?.ast, asName(name).ast).node; } // @api function updatePropertyAccessChain(node: PropertyAccessChain, expression: Expression, questionDotToken: QuestionDotToken | undefined, name: Identifier | PrivateIdentifier): PropertyAccessChain { - return astFactory.updatePropertyAccessChain(asNode(node).ast, asNode(expression).ast, asNode(questionDotToken)?.ast, asNode(name).ast).node; + return astFactory.updatePropertyAccessChain(node.ast, expression.ast, questionDotToken?.ast, name.ast).node; } // @api function createElementAccessExpression(expression: Expression, index: number | Expression): ElementAccessExpression { - return astFactory.createElementAccessExpression(asNode(expression).ast, asExpression(index).ast).node; + return astFactory.createElementAccessExpression(expression.ast, asExpression(index).ast).node; } // @api function updateElementAccessExpression(node: ElementAccessExpression, expression: Expression, argumentExpression: Expression): ElementAccessExpression { - return astFactory.updateElementAccessExpression(asNode(node).ast, asNode(expression).ast, asNode(argumentExpression).ast).node; + return astFactory.updateElementAccessExpression(node.ast, expression.ast, argumentExpression.ast).node; } // @api function createElementAccessChain(expression: Expression, questionDotToken: QuestionDotToken | undefined, index: number | Expression): ElementAccessChain { - return astFactory.createElementAccessChain(asNode(expression).ast, asNode(questionDotToken)?.ast, asExpression(index).ast).node; + return astFactory.createElementAccessChain(expression.ast, questionDotToken?.ast, asExpression(index).ast).node; } // @api function updateElementAccessChain(node: ElementAccessChain, expression: Expression, questionDotToken: QuestionDotToken | undefined, argumentExpression: Expression): ElementAccessChain { - return astFactory.updateElementAccessChain(asNode(node).ast, asNode(expression).ast, asNode(questionDotToken)?.ast, asNode(argumentExpression).ast).node; + return astFactory.updateElementAccessChain(node.ast, expression.ast, questionDotToken?.ast, argumentExpression.ast).node; } // @api function createCallExpression(expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined): CallExpression { - return astFactory.createCallExpression(asNode(expression).ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray)?.ast).node; + return astFactory.createCallExpression(expression.ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray)?.ast).node; } // @api function updateCallExpression(node: CallExpression, expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[]): CallExpression { - return astFactory.updateCallExpression(asNode(node).ast, asNode(expression).ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray).ast).node; + return astFactory.updateCallExpression(node.ast, expression.ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray).ast).node; } // @api function createCallChain(expression: Expression, questionDotToken: QuestionDotToken | undefined, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined): CallChain { - return astFactory.createCallChain(asNode(expression).ast, asNode(questionDotToken)?.ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray)?.ast).node; + return astFactory.createCallChain(expression.ast, questionDotToken?.ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray)?.ast).node; } // @api function updateCallChain(node: CallChain, expression: Expression, questionDotToken: QuestionDotToken | undefined, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[]): CallChain { - return astFactory.updateCallChain(asNode(node).ast, asNode(expression).ast, asNode(questionDotToken)?.ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray).ast).node; + return astFactory.updateCallChain(node.ast, expression.ast, questionDotToken?.ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray).ast).node; } // @api function createNewExpression(expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined): NewExpression { - return astFactory.createNewExpression(asNode(expression).ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray)?.ast).node; + return astFactory.createNewExpression(expression.ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray)?.ast).node; } // @api function updateNewExpression(node: NewExpression, expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined): NewExpression { - return astFactory.updateNewExpression(asNode(node).ast, asNode(expression).ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray)?.ast).node; + return astFactory.updateNewExpression(node.ast, expression.ast, asNodeArray(typeArguments)?.ast, asNodeArray(argumentsArray)?.ast).node; } // @api function createTaggedTemplateExpression(tag: Expression, typeArguments: readonly TypeNode[] | undefined, template: TemplateLiteral): TaggedTemplateExpression { - return astFactory.createTaggedTemplateExpression(asNode(tag).ast, asNodeArray(typeArguments)?.ast, asNode(template).ast).node; + return astFactory.createTaggedTemplateExpression(tag.ast, asNodeArray(typeArguments)?.ast, template.ast).node; } // @api function updateTaggedTemplateExpression(node: TaggedTemplateExpression, tag: Expression, typeArguments: readonly TypeNode[] | undefined, template: TemplateLiteral): TaggedTemplateExpression { - return astFactory.updateTaggedTemplateExpression(asNode(node).ast, asNode(tag).ast, asNodeArray(typeArguments)?.ast, asNode(template).ast).node; + return astFactory.updateTaggedTemplateExpression(node.ast, tag.ast, asNodeArray(typeArguments)?.ast, template.ast).node; } // @api - function createTypeAssertion(type: TypeNode, expression: Expression): TypeAssertion { - return astFactory.createTypeAssertion(asNode(type).ast, asNode(expression).ast).node; + function createTypeAssertion(type: TypeNode, expression: Expression): TypeAssertionExpression { + return astFactory.createTypeAssertion(type.ast, expression.ast).node; } // @api - function updateTypeAssertion(node: TypeAssertion, type: TypeNode, expression: Expression): TypeAssertion { - return astFactory.updateTypeAssertion(asNode(node).ast, asNode(type).ast, asNode(expression).ast).node; + function updateTypeAssertion(node: TypeAssertionExpression, type: TypeNode, expression: Expression): TypeAssertionExpression { + return astFactory.updateTypeAssertion(node.ast, type.ast, expression.ast).node; } // @api function createParenthesizedExpression(expression: Expression): ParenthesizedExpression { - return astFactory.createParenthesizedExpression(asNode(expression).ast).node; + return astFactory.createParenthesizedExpression(expression.ast).node; } // @api function updateParenthesizedExpression(node: ParenthesizedExpression, expression: Expression): ParenthesizedExpression { - return astFactory.updateParenthesizedExpression(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateParenthesizedExpression(node.ast, expression.ast).node; } // @api @@ -2045,7 +2045,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: type: TypeNode | undefined, body: Block, ): FunctionExpression { - return astFactory.createFunctionExpression(asNodeArray(modifiers)?.ast, asNode(asteriskToken)?.ast, asName(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters)?.ast, asNode(type)?.ast, asNode(body).ast).node; + return astFactory.createFunctionExpression(asNodeArray(modifiers)?.ast, asteriskToken?.ast, asName(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters)?.ast, type?.ast, body.ast).node; } // @api @@ -2059,7 +2059,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: type: TypeNode | undefined, body: Block, ): FunctionExpression { - return astFactory.updateFunctionExpression(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(asteriskToken)?.ast, asNode(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body).ast).node; + return astFactory.updateFunctionExpression(node.ast, asNodeArray(modifiers)?.ast, asteriskToken?.ast, name?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast, body.ast).node; } // @api @@ -2071,7 +2071,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: equalsGreaterThanToken: EqualsGreaterThanToken | undefined, body: ConciseBody, ): ArrowFunction { - return astFactory.createArrowFunction(asNodeArray(modifiers)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(equalsGreaterThanToken)?.ast, asNode(body).ast).node; + return astFactory.createArrowFunction(asNodeArray(modifiers)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast, equalsGreaterThanToken?.ast, body.ast).node; } // @api @@ -2084,82 +2084,82 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: equalsGreaterThanToken: EqualsGreaterThanToken, body: ConciseBody, ): ArrowFunction { - return astFactory.updateArrowFunction(asNode(node).ast, asNodeArray(modifiers)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(equalsGreaterThanToken).ast, asNode(body).ast).node; + return astFactory.updateArrowFunction(node.ast, asNodeArray(modifiers)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast, equalsGreaterThanToken.ast, body.ast).node; } // @api function createDeleteExpression(expression: Expression): DeleteExpression { - return astFactory.createDeleteExpression(asNode(expression).ast).node; + return astFactory.createDeleteExpression(expression.ast).node; } // @api function updateDeleteExpression(node: DeleteExpression, expression: Expression): DeleteExpression { - return astFactory.updateDeleteExpression(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateDeleteExpression(node.ast, expression.ast).node; } // @api function createTypeOfExpression(expression: Expression): TypeOfExpression { - return astFactory.createTypeOfExpression(asNode(expression).ast).node; + return astFactory.createTypeOfExpression(expression.ast).node; } // @api function updateTypeOfExpression(node: TypeOfExpression, expression: Expression): TypeOfExpression { - return astFactory.updateTypeOfExpression(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateTypeOfExpression(node.ast, expression.ast).node; } // @api function createVoidExpression(expression: Expression): VoidExpression { - return astFactory.createVoidExpression(asNode(expression).ast).node; + return astFactory.createVoidExpression(expression.ast).node; } // @api function updateVoidExpression(node: VoidExpression, expression: Expression): VoidExpression { - return astFactory.updateVoidExpression(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateVoidExpression(node.ast, expression.ast).node; } // @api function createAwaitExpression(expression: Expression): AwaitExpression { - return astFactory.createAwaitExpression(asNode(expression).ast).node; + return astFactory.createAwaitExpression(expression.ast).node; } // @api function updateAwaitExpression(node: AwaitExpression, expression: Expression): AwaitExpression { - return astFactory.updateAwaitExpression(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateAwaitExpression(node.ast, expression.ast).node; } // @api function createPrefixUnaryExpression(operator: PrefixUnaryOperator, operand: Expression): PrefixUnaryExpression { - return astFactory.createPrefixUnaryExpression(operator, asNode(operand).ast).node; + return astFactory.createPrefixUnaryExpression(operator, operand.ast).node; } // @api function updatePrefixUnaryExpression(node: PrefixUnaryExpression, operand: Expression): PrefixUnaryExpression { - return astFactory.updatePrefixUnaryExpression(asNode(node).ast, asNode(operand).ast).node; + return astFactory.updatePrefixUnaryExpression(node.ast, operand.ast).node; } // @api function createPostfixUnaryExpression(operand: Expression, operator: PostfixUnaryOperator): PostfixUnaryExpression { - return astFactory.createPostfixUnaryExpression(asNode(operand).ast, operator).node; + return astFactory.createPostfixUnaryExpression(operand.ast, operator).node; } // @api function updatePostfixUnaryExpression(node: PostfixUnaryExpression, operand: Expression): PostfixUnaryExpression { - return astFactory.updatePostfixUnaryExpression(asNode(node).ast, asNode(operand).ast).node; + return astFactory.updatePostfixUnaryExpression(node.ast, operand.ast).node; } // @api function createBinaryExpression(left: Expression, operator: BinaryOperator | BinaryOperatorToken, right: Expression): BinaryExpression { - return astFactory.createBinaryExpression(asNode(left).ast, asToken(operator).ast, asNode(right).ast).node; + return astFactory.createBinaryExpression(left.ast, asToken(operator).ast, right.ast).node; } // @api function updateBinaryExpression(node: BinaryExpression, left: Expression, operator: BinaryOperatorToken, right: Expression): BinaryExpression { - return astFactory.updateBinaryExpression(asNode(node).ast, asNode(left).ast, asNode(operator).ast, asNode(right).ast).node; + return astFactory.updateBinaryExpression(node.ast, left.ast, operator.ast, right.ast).node; } // @api function createConditionalExpression(condition: Expression, questionToken: QuestionToken | undefined, whenTrue: Expression, colonToken: ColonToken | undefined, whenFalse: Expression): ConditionalExpression { - return astFactory.createConditionalExpression(asNode(condition).ast, asNode(questionToken)?.ast, asNode(whenTrue).ast, asNode(colonToken)?.ast, asNode(whenFalse).ast).node; + return astFactory.createConditionalExpression(condition.ast, questionToken?.ast, whenTrue.ast, colonToken?.ast, whenFalse.ast).node; } // @api @@ -2171,17 +2171,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: colonToken: Token, whenFalse: Expression, ): ConditionalExpression { - return astFactory.updateConditionalExpression(asNode(node).ast, asNode(condition).ast, asNode(questionToken).ast, asNode(whenTrue).ast, asNode(colonToken).ast, asNode(whenFalse).ast).node; + return astFactory.updateConditionalExpression(node.ast, condition.ast, questionToken.ast, whenTrue.ast, colonToken.ast, whenFalse.ast).node; } // @api function createTemplateExpression(head: TemplateHead, templateSpans: readonly TemplateSpan[]): TemplateExpression { - return astFactory.createTemplateExpression(asNode(head).ast, asNodeArray(templateSpans).ast).node; + return astFactory.createTemplateExpression(head.ast, asNodeArray(templateSpans).ast).node; } // @api function updateTemplateExpression(node: TemplateExpression, head: TemplateHead, templateSpans: readonly TemplateSpan[]): TemplateExpression { - return astFactory.updateTemplateExpression(asNode(node).ast, asNode(head).ast, asNodeArray(templateSpans).ast).node; + return astFactory.updateTemplateExpression(node.ast, head.ast, asNodeArray(templateSpans).ast).node; } // @api @@ -2211,22 +2211,22 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createYieldExpression(asteriskToken: AsteriskToken | undefined, expression: Expression | undefined): YieldExpression { - return astFactory.createYieldExpression(asNode(asteriskToken)?.ast, asNode(expression)?.ast).node; + return astFactory.createYieldExpression(asteriskToken?.ast, expression?.ast).node; } // @api function updateYieldExpression(node: YieldExpression, asteriskToken: AsteriskToken | undefined, expression: Expression | undefined): YieldExpression { - return astFactory.updateYieldExpression(asNode(node).ast, asNode(asteriskToken)?.ast, asNode(expression)?.ast).node; + return astFactory.updateYieldExpression(node.ast, asteriskToken?.ast, expression?.ast).node; } // @api function createSpreadElement(expression: Expression): SpreadElement { - return astFactory.createSpreadElement(asNode(expression).ast).node; + return astFactory.createSpreadElement(expression.ast).node; } // @api function updateSpreadElement(node: SpreadElement, expression: Expression): SpreadElement { - return astFactory.updateSpreadElement(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateSpreadElement(node.ast, expression.ast).node; } // @api @@ -2249,7 +2249,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: heritageClauses: readonly HeritageClause[] | undefined, members: readonly ClassElement[], ): ClassExpression { - return astFactory.updateClassExpression(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(heritageClauses)?.ast, asNodeArray(members).ast).node; + return astFactory.updateClassExpression(node.ast, asNodeArray(modifiers)?.ast, name?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(heritageClauses)?.ast, asNodeArray(members).ast).node; } // @api @@ -2259,62 +2259,62 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createExpressionWithTypeArguments(expression: Expression, typeArguments: readonly TypeNode[] | undefined): ExpressionWithTypeArguments { - return astFactory.createExpressionWithTypeArguments(asNode(expression).ast, asNodeArray(typeArguments)?.ast).node; + return astFactory.createExpressionWithTypeArguments(expression.ast, asNodeArray(typeArguments)?.ast).node; } // @api function updateExpressionWithTypeArguments(node: ExpressionWithTypeArguments, expression: Expression, typeArguments: readonly TypeNode[] | undefined): ExpressionWithTypeArguments { - return astFactory.updateExpressionWithTypeArguments(asNode(node).ast, asNode(expression).ast, asNodeArray(typeArguments)?.ast).node; + return astFactory.updateExpressionWithTypeArguments(node.ast, expression.ast, asNodeArray(typeArguments)?.ast).node; } // @api function createAsExpression(expression: Expression, type: TypeNode): AsExpression { - return astFactory.createAsExpression(asNode(expression).ast, asNode(type).ast).node; + return astFactory.createAsExpression(expression.ast, type.ast).node; } // @api function updateAsExpression(node: AsExpression, expression: Expression, type: TypeNode): AsExpression { - return astFactory.updateAsExpression(asNode(node).ast, asNode(expression).ast, asNode(type).ast).node; + return astFactory.updateAsExpression(node.ast, expression.ast, type.ast).node; } // @api function createNonNullExpression(expression: Expression): NonNullExpression { - return astFactory.createNonNullExpression(asNode(expression).ast).node; + return astFactory.createNonNullExpression(expression.ast).node; } // @api function updateNonNullExpression(node: NonNullExpression, expression: Expression): NonNullExpression { - return astFactory.updateNonNullExpression(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateNonNullExpression(node.ast, expression.ast).node; } // @api function createSatisfiesExpression(expression: Expression, type: TypeNode): SatisfiesExpression { - return astFactory.createSatisfiesExpression(asNode(expression).ast, asNode(type).ast).node; + return astFactory.createSatisfiesExpression(expression.ast, type.ast).node; } // @api function updateSatisfiesExpression(node: SatisfiesExpression, expression: Expression, type: TypeNode): SatisfiesExpression { - return astFactory.updateSatisfiesExpression(asNode(node).ast, asNode(expression).ast, asNode(type).ast).node; + return astFactory.updateSatisfiesExpression(node.ast, expression.ast, type.ast).node; } // @api function createNonNullChain(expression: Expression): NonNullChain { - return astFactory.createNonNullChain(asNode(expression).ast).node; + return astFactory.createNonNullChain(expression.ast).node; } // @api function updateNonNullChain(node: NonNullChain, expression: Expression): NonNullChain { - return astFactory.updateNonNullChain(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateNonNullChain(node.ast, expression.ast).node; } // @api function createMetaProperty(keywordToken: MetaProperty["keywordToken"], name: Identifier): MetaProperty { - return astFactory.createMetaProperty(keywordToken, asNode(name).ast).node; + return astFactory.createMetaProperty(keywordToken, name.ast).node; } // @api function updateMetaProperty(node: MetaProperty, name: Identifier): MetaProperty { - return astFactory.updateMetaProperty(asNode(node).ast, asNode(name).ast).node; + return astFactory.updateMetaProperty(node.ast, name.ast).node; } // @@ -2323,12 +2323,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createTemplateSpan(expression: Expression, literal: TemplateMiddle | TemplateTail): TemplateSpan { - return astFactory.createTemplateSpan(asNode(expression).ast, asNode(literal).ast).node; + return astFactory.createTemplateSpan(expression.ast, literal.ast).node; } // @api function updateTemplateSpan(node: TemplateSpan, expression: Expression, literal: TemplateMiddle | TemplateTail): TemplateSpan { - return astFactory.updateTemplateSpan(asNode(node).ast, asNode(expression).ast, asNode(literal).ast).node; + return astFactory.updateTemplateSpan(node.ast, expression.ast, literal.ast).node; } // @api @@ -2347,17 +2347,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateBlock(node: Block, statements: readonly Statement[]): Block { - return astFactory.updateBlock(asNode(node).ast, asNodeArray(statements).ast).node; + return astFactory.updateBlock(node.ast, asNodeArray(statements).ast).node; } // @api function createVariableStatement(modifiers: readonly ModifierLike[] | undefined, declarationList: VariableDeclarationList | readonly VariableDeclaration[]): VariableStatement { - return astFactory.createVariableStatement(asNodeArray(modifiers)?.ast, isArray(declarationList) ? asNodeArray(declarationList).ast : asNode(declarationList).ast).node; + return astFactory.createVariableStatement(asNodeArray(modifiers)?.ast, isArray(declarationList) ? asNodeArray(declarationList).ast : declarationList.ast).node; } // @api function updateVariableStatement(node: VariableStatement, modifiers: readonly ModifierLike[] | undefined, declarationList: VariableDeclarationList): VariableStatement { - return astFactory.updateVariableStatement(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(declarationList).ast).node; + return astFactory.updateVariableStatement(node.ast, asNodeArray(modifiers)?.ast, declarationList.ast).node; } // @api @@ -2367,72 +2367,72 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createExpressionStatement(expression: Expression): ExpressionStatement { - return astFactory.createExpressionStatement(asNode(expression).ast).node; + return astFactory.createExpressionStatement(expression.ast).node; } // @api function updateExpressionStatement(node: ExpressionStatement, expression: Expression): ExpressionStatement { - return astFactory.updateExpressionStatement(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateExpressionStatement(node.ast, expression.ast).node; } // @api function createIfStatement(expression: Expression, thenStatement: Statement, elseStatement?: Statement): IfStatement { - return astFactory.createIfStatement(asNode(expression).ast, asNode(thenStatement).ast, asNode(elseStatement)?.ast).node; + return astFactory.createIfStatement(expression.ast, thenStatement.ast, elseStatement?.ast).node; } // @api function updateIfStatement(node: IfStatement, expression: Expression, thenStatement: Statement, elseStatement: Statement | undefined): IfStatement { - return astFactory.updateIfStatement(asNode(node).ast, asNode(expression).ast, asNode(thenStatement).ast, asNode(elseStatement)?.ast).node; + return astFactory.updateIfStatement(node.ast, expression.ast, thenStatement.ast, elseStatement?.ast).node; } // @api function createDoStatement(statement: Statement, expression: Expression): DoStatement { - return astFactory.createDoStatement(asNode(statement).ast, asNode(expression).ast).node; + return astFactory.createDoStatement(statement.ast, expression.ast).node; } // @api function updateDoStatement(node: DoStatement, statement: Statement, expression: Expression): DoStatement { - return astFactory.updateDoStatement(asNode(node).ast, asNode(statement).ast, asNode(expression).ast).node; + return astFactory.updateDoStatement(node.ast, statement.ast, expression.ast).node; } // @api function createWhileStatement(expression: Expression, statement: Statement): WhileStatement { - return astFactory.createWhileStatement(asNode(expression).ast, asNode(statement).ast).node; + return astFactory.createWhileStatement(expression.ast, statement.ast).node; } // @api function updateWhileStatement(node: WhileStatement, expression: Expression, statement: Statement): WhileStatement { - return astFactory.updateWhileStatement(asNode(node).ast, asNode(expression).ast, asNode(statement).ast).node; + return astFactory.updateWhileStatement(node.ast, expression.ast, statement.ast).node; } // @api function createForStatement(initializer: ForInitializer | undefined, condition: Expression | undefined, incrementor: Expression | undefined, statement: Statement): ForStatement { - return astFactory.createForStatement(asNode(initializer)?.ast, asNode(condition)?.ast, asNode(incrementor)?.ast, asNode(statement).ast).node; + return astFactory.createForStatement(initializer?.ast, condition?.ast, incrementor?.ast, statement.ast).node; } // @api function updateForStatement(node: ForStatement, initializer: ForInitializer | undefined, condition: Expression | undefined, incrementor: Expression | undefined, statement: Statement): ForStatement { - return astFactory.updateForStatement(asNode(node).ast, asNode(initializer)?.ast, asNode(condition)?.ast, asNode(incrementor)?.ast, asNode(statement).ast).node; + return astFactory.updateForStatement(node.ast, initializer?.ast, condition?.ast, incrementor?.ast, statement.ast).node; } // @api function createForInStatement(initializer: ForInitializer, expression: Expression, statement: Statement): ForInStatement { - return astFactory.createForInStatement(asNode(initializer).ast, asNode(expression).ast, asNode(statement).ast).node; + return astFactory.createForInStatement(initializer.ast, expression.ast, statement.ast).node; } // @api function updateForInStatement(node: ForInStatement, initializer: ForInitializer, expression: Expression, statement: Statement): ForInStatement { - return astFactory.updateForInStatement(asNode(node).ast, asNode(initializer).ast, asNode(expression).ast, asNode(statement).ast).node; + return astFactory.updateForInStatement(node.ast, initializer.ast, expression.ast, statement.ast).node; } // @api function createForOfStatement(awaitModifier: AwaitKeyword | undefined, initializer: ForInitializer, expression: Expression, statement: Statement): ForOfStatement { - return astFactory.createForOfStatement(asNode(awaitModifier)?.ast, asNode(initializer).ast, asNode(expression).ast, asNode(statement).ast).node; + return astFactory.createForOfStatement(awaitModifier?.ast, initializer.ast, expression.ast, statement.ast).node; } // @api function updateForOfStatement(node: ForOfStatement, awaitModifier: AwaitKeyword | undefined, initializer: ForInitializer, expression: Expression, statement: Statement): ForOfStatement { - return astFactory.updateForOfStatement(asNode(node).ast, asNode(awaitModifier)?.ast, asNode(initializer).ast, asNode(expression).ast, asNode(statement).ast).node; + return astFactory.updateForOfStatement(node.ast, awaitModifier?.ast, initializer.ast, expression.ast, statement.ast).node; } // @api @@ -2442,7 +2442,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateContinueStatement(node: ContinueStatement, label: Identifier | undefined): ContinueStatement { - return astFactory.updateContinueStatement(asNode(node).ast, asNode(label)?.ast).node; + return astFactory.updateContinueStatement(node.ast, label?.ast).node; } // @api @@ -2452,67 +2452,67 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateBreakStatement(node: BreakStatement, label: Identifier | undefined): BreakStatement { - return astFactory.updateBreakStatement(asNode(node).ast, asNode(label)?.ast).node; + return astFactory.updateBreakStatement(node.ast, label?.ast).node; } // @api function createReturnStatement(expression?: Expression): ReturnStatement { - return astFactory.createReturnStatement(asNode(expression)?.ast).node; + return astFactory.createReturnStatement(expression?.ast).node; } // @api function updateReturnStatement(node: ReturnStatement, expression: Expression | undefined): ReturnStatement { - return astFactory.updateReturnStatement(asNode(node).ast, asNode(expression)?.ast).node; + return astFactory.updateReturnStatement(node.ast, expression?.ast).node; } // @api function createWithStatement(expression: Expression, statement: Statement): WithStatement { - return astFactory.createWithStatement(asNode(expression).ast, asNode(statement).ast).node; + return astFactory.createWithStatement(expression.ast, statement.ast).node; } // @api function updateWithStatement(node: WithStatement, expression: Expression, statement: Statement): WithStatement { - return astFactory.updateWithStatement(asNode(node).ast, asNode(expression).ast, asNode(statement).ast).node; + return astFactory.updateWithStatement(node.ast, expression.ast, statement.ast).node; } // @api function createSwitchStatement(expression: Expression, caseBlock: CaseBlock): SwitchStatement { - return astFactory.createSwitchStatement(asNode(expression).ast, asNode(caseBlock).ast).node; + return astFactory.createSwitchStatement(expression.ast, caseBlock.ast).node; } // @api function updateSwitchStatement(node: SwitchStatement, expression: Expression, caseBlock: CaseBlock): SwitchStatement { - return astFactory.updateSwitchStatement(asNode(node).ast, asNode(expression).ast, asNode(caseBlock).ast).node; + return astFactory.updateSwitchStatement(node.ast, expression.ast, caseBlock.ast).node; } // @api function createLabeledStatement(label: string | Identifier, statement: Statement): LabeledStatement { - return astFactory.createLabeledStatement(asName(label).ast, asNode(statement).ast).node; + return astFactory.createLabeledStatement(asName(label).ast, statement.ast).node; } // @api function updateLabeledStatement(node: LabeledStatement, label: Identifier, statement: Statement): LabeledStatement { - return astFactory.updateLabeledStatement(asNode(node).ast, asNode(label).ast, asNode(statement).ast).node; + return astFactory.updateLabeledStatement(node.ast, label.ast, statement.ast).node; } // @api function createThrowStatement(expression: Expression): ThrowStatement { - return astFactory.createThrowStatement(asNode(expression).ast).node; + return astFactory.createThrowStatement(expression.ast).node; } // @api function updateThrowStatement(node: ThrowStatement, expression: Expression): ThrowStatement { - return astFactory.updateThrowStatement(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateThrowStatement(node.ast, expression.ast).node; } // @api function createTryStatement(tryBlock: Block, catchClause: CatchClause | undefined, finallyBlock: Block | undefined): TryStatement { - return astFactory.createTryStatement(asNode(tryBlock).ast, asNode(catchClause)?.ast, asNode(finallyBlock)?.ast).node; + return astFactory.createTryStatement(tryBlock.ast, catchClause?.ast, finallyBlock?.ast).node; } // @api function updateTryStatement(node: TryStatement, tryBlock: Block, catchClause: CatchClause | undefined, finallyBlock: Block | undefined): TryStatement { - return astFactory.updateTryStatement(asNode(node).ast, asNode(tryBlock).ast, asNode(catchClause)?.ast, asNode(finallyBlock)?.ast).node; + return astFactory.updateTryStatement(node.ast, tryBlock.ast, catchClause?.ast, finallyBlock?.ast).node; } // @api @@ -2522,12 +2522,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createVariableDeclaration(name: string | BindingName, exclamationToken: ExclamationToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): VariableDeclaration { - return astFactory.createVariableDeclaration(asName(name).ast, asNode(exclamationToken)?.ast, asNode(type)?.ast, asNode(initializer)?.ast).node; + return astFactory.createVariableDeclaration(asName(name).ast, exclamationToken?.ast, type?.ast, initializer?.ast).node; } // @api function updateVariableDeclaration(node: VariableDeclaration, name: BindingName, exclamationToken: ExclamationToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): VariableDeclaration { - return astFactory.updateVariableDeclaration(asNode(node).ast, asNode(name).ast, asNode(exclamationToken)?.ast, asNode(type)?.ast, asNode(initializer)?.ast).node; + return astFactory.updateVariableDeclaration(node.ast, name.ast, exclamationToken?.ast, type?.ast, initializer?.ast).node; } // @api @@ -2537,7 +2537,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateVariableDeclarationList(node: VariableDeclarationList, declarations: readonly VariableDeclaration[]): VariableDeclarationList { - return astFactory.updateVariableDeclarationList(asNode(node).ast, asNodeArray(declarations).ast).node; + return astFactory.updateVariableDeclarationList(node.ast, asNodeArray(declarations).ast).node; } // @api @@ -2550,7 +2550,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: type: TypeNode | undefined, body: Block | undefined, ): FunctionDeclaration { - return astFactory.createFunctionDeclaration(asNodeArray(modifiers)?.ast, asNode(asteriskToken)?.ast, asName(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body)?.ast).node; + return astFactory.createFunctionDeclaration(asNodeArray(modifiers)?.ast, asteriskToken?.ast, asName(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast, body?.ast).node; } // @api @@ -2564,7 +2564,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: type: TypeNode | undefined, body: Block | undefined, ): FunctionDeclaration { - return astFactory.updateFunctionDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(asteriskToken)?.ast, asNode(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast, asNode(body)?.ast).node; + return astFactory.updateFunctionDeclaration(node.ast, asNodeArray(modifiers)?.ast, asteriskToken?.ast, name?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast, body?.ast).node; } // @api @@ -2587,7 +2587,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: heritageClauses: readonly HeritageClause[] | undefined, members: readonly ClassElement[], ): ClassDeclaration { - return astFactory.updateClassDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name)?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(heritageClauses)?.ast, asNodeArray(members).ast).node; + return astFactory.updateClassDeclaration(node.ast, asNodeArray(modifiers)?.ast, name?.ast, asNodeArray(typeParameters)?.ast, asNodeArray(heritageClauses)?.ast, asNodeArray(members).ast).node; } // @api @@ -2610,7 +2610,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: heritageClauses: readonly HeritageClause[] | undefined, members: readonly TypeElement[], ): InterfaceDeclaration { - return astFactory.updateInterfaceDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNodeArray(typeParameters)?.ast, asNodeArray(heritageClauses)?.ast, asNodeArray(members).ast).node; + return astFactory.updateInterfaceDeclaration(node.ast, asNodeArray(modifiers)?.ast, name.ast, asNodeArray(typeParameters)?.ast, asNodeArray(heritageClauses)?.ast, asNodeArray(members).ast).node; } // @api @@ -2620,7 +2620,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: typeParameters: readonly TypeParameterDeclaration[] | undefined, type: TypeNode, ): TypeAliasDeclaration { - return astFactory.createTypeAliasDeclaration(asNodeArray(modifiers)?.ast, asName(name).ast, asNodeArray(typeParameters)?.ast, asNode(type).ast).node; + return astFactory.createTypeAliasDeclaration(asNodeArray(modifiers)?.ast, asName(name).ast, asNodeArray(typeParameters)?.ast, type.ast).node; } // @api @@ -2631,7 +2631,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: typeParameters: readonly TypeParameterDeclaration[] | undefined, type: TypeNode, ): TypeAliasDeclaration { - return astFactory.updateTypeAliasDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNodeArray(typeParameters)?.ast, asNode(type).ast).node; + return astFactory.updateTypeAliasDeclaration(node.ast, asNodeArray(modifiers)?.ast, name.ast, asNodeArray(typeParameters)?.ast, type.ast).node; } // @api @@ -2650,7 +2650,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: name: Identifier, members: readonly EnumMember[], ): EnumDeclaration { - return astFactory.updateEnumDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNodeArray(members).ast).node; + return astFactory.updateEnumDeclaration(node.ast, asNodeArray(modifiers)?.ast, name.ast, asNodeArray(members).ast).node; } // @api @@ -2660,7 +2660,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: body: ModuleBody | undefined, flags = NodeFlags.None, ): ModuleDeclaration { - return astFactory.createModuleDeclaration(asNodeArray(modifiers)?.ast, asNode(name).ast, asNode(body)?.ast, flags).node; + return astFactory.createModuleDeclaration(asNodeArray(modifiers)?.ast, name.ast, body?.ast, flags).node; } // @api @@ -2670,7 +2670,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: name: ModuleName, body: ModuleBody | undefined, ): ModuleDeclaration { - return astFactory.updateModuleDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(name).ast, asNode(body)?.ast).node; + return astFactory.updateModuleDeclaration(node.ast, asNodeArray(modifiers)?.ast, name.ast, body?.ast).node; } // @api @@ -2680,7 +2680,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateModuleBlock(node: ModuleBlock, statements: readonly Statement[]) { - return astFactory.updateModuleBlock(asNode(node).ast, asNodeArray(statements).ast).node; + return astFactory.updateModuleBlock(node.ast, asNodeArray(statements).ast).node; } // @api @@ -2690,7 +2690,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateCaseBlock(node: CaseBlock, clauses: readonly CaseOrDefaultClause[]): CaseBlock { - return astFactory.updateCaseBlock(asNode(node).ast, asNodeArray(clauses).ast).node; + return astFactory.updateCaseBlock(node.ast, asNodeArray(clauses).ast).node; } // @api @@ -2700,7 +2700,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration { - return astFactory.updateNamespaceExportDeclaration(asNode(node).ast, asNode(name).ast).node; + return astFactory.updateNamespaceExportDeclaration(node.ast, name.ast).node; } // @api @@ -2710,7 +2710,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: name: string | Identifier, moduleReference: ModuleReference, ): ImportEqualsDeclaration { - return astFactory.createImportEqualsDeclaration(asNodeArray(modifiers)?.ast, isTypeOnly, asName(name).ast, asNode(moduleReference).ast).node; + return astFactory.createImportEqualsDeclaration(asNodeArray(modifiers)?.ast, isTypeOnly, asName(name).ast, moduleReference.ast).node; } // @api @@ -2721,7 +2721,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: name: Identifier, moduleReference: ModuleReference, ): ImportEqualsDeclaration { - return astFactory.updateImportEqualsDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, isTypeOnly, asNode(name).ast, asNode(moduleReference).ast).node; + return astFactory.updateImportEqualsDeclaration(node.ast, asNodeArray(modifiers)?.ast, isTypeOnly, name.ast, moduleReference.ast).node; } // @api @@ -2731,7 +2731,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: moduleSpecifier: Expression, attributes: ImportAttributes | undefined, ): ImportDeclaration { - return astFactory.createImportDeclaration(asNodeArray(modifiers)?.ast, asNode(importClause)?.ast, asNode(moduleSpecifier).ast, asNode(attributes)?.ast).node; + return astFactory.createImportDeclaration(asNodeArray(modifiers)?.ast, importClause?.ast, moduleSpecifier.ast, attributes?.ast).node; } // @api @@ -2742,17 +2742,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: moduleSpecifier: Expression, attributes: ImportAttributes | undefined, ): ImportDeclaration { - return astFactory.updateImportDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(importClause)?.ast, asNode(moduleSpecifier).ast, asNode(attributes)?.ast).node; + return astFactory.updateImportDeclaration(node.ast, asNodeArray(modifiers)?.ast, importClause?.ast, moduleSpecifier.ast, attributes?.ast).node; } // @api function createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause { - return astFactory.createImportClause(isTypeOnly, asNode(name)?.ast, asNode(namedBindings)?.ast).node; + return astFactory.createImportClause(isTypeOnly, name?.ast, namedBindings?.ast).node; } // @api function updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause { - return astFactory.updateImportClause(asNode(node).ast, isTypeOnly, asNode(name)?.ast, asNode(namedBindings)?.ast).node; + return astFactory.updateImportClause(node.ast, isTypeOnly, name?.ast, namedBindings?.ast).node; } // @api @@ -2762,27 +2762,27 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateAssertClause(node: AssertClause, elements: readonly AssertEntry[], multiLine?: boolean): AssertClause { - return astFactory.updateAssertClause(asNode(node).ast, asNodeArray(elements).ast, multiLine).node; + return astFactory.updateAssertClause(node.ast, asNodeArray(elements).ast, multiLine).node; } // @api function createAssertEntry(name: AssertionKey, value: Expression) { - return astFactory.createAssertEntry(asNode(name).ast, asNode(value).ast).node; + return astFactory.createAssertEntry(name.ast, value.ast).node; } // @api function updateAssertEntry(node: AssertEntry, name: AssertionKey, value: Expression) { - return astFactory.updateAssertEntry(asNode(node).ast, asNode(name).ast, asNode(value).ast).node; + return astFactory.updateAssertEntry(node.ast, name.ast, value.ast).node; } // @api function createImportTypeAssertionContainer(clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer { - return astFactory.createImportTypeAssertionContainer(asNode(clause).ast, multiLine).node; + return astFactory.createImportTypeAssertionContainer(clause.ast, multiLine).node; } // @api function updateImportTypeAssertionContainer(node: ImportTypeAssertionContainer, clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer { - return astFactory.updateImportTypeAssertionContainer(asNode(node).ast, asNode(clause).ast, multiLine).node; + return astFactory.updateImportTypeAssertionContainer(node.ast, clause.ast, multiLine).node; } // @api @@ -2794,37 +2794,37 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateImportAttributes(node: ImportAttributes, elements: readonly ImportAttribute[], multiLine?: boolean): ImportAttributes { - return astFactory.updateImportAttributes(asNode(node).ast, asNodeArray(elements).ast, multiLine).node; + return astFactory.updateImportAttributes(node.ast, asNodeArray(elements).ast, multiLine).node; } // @api function createImportAttribute(name: ImportAttributeName, value: Expression) { - return astFactory.createImportAttribute(asNode(name).ast, asNode(value).ast).node; + return astFactory.createImportAttribute(name.ast, value.ast).node; } // @api function updateImportAttribute(node: ImportAttribute, name: ImportAttributeName, value: Expression) { - return astFactory.updateImportAttribute(asNode(node).ast, asNode(name).ast, asNode(value).ast).node; + return astFactory.updateImportAttribute(node.ast, name.ast, value.ast).node; } // @api function createNamespaceImport(name: Identifier): NamespaceImport { - return astFactory.createNamespaceImport(asNode(name).ast).node; + return astFactory.createNamespaceImport(name.ast).node; } // @api function updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport { - return astFactory.updateNamespaceImport(asNode(node).ast, asNode(name).ast).node; + return astFactory.updateNamespaceImport(node.ast, name.ast).node; } // @api function createNamespaceExport(name: ModuleExportName): NamespaceExport { - return astFactory.createNamespaceExport(asNode(name).ast).node; + return astFactory.createNamespaceExport(name.ast).node; } // @api function updateNamespaceExport(node: NamespaceExport, name: ModuleExportName): NamespaceExport { - return astFactory.updateNamespaceExport(asNode(node).ast, asNode(name).ast).node; + return astFactory.updateNamespaceExport(node.ast, name.ast).node; } // @api @@ -2834,17 +2834,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateNamedImports(node: NamedImports, elements: readonly ImportSpecifier[]): NamedImports { - return astFactory.updateNamedImports(asNode(node).ast, asNodeArray(elements).ast).node; + return astFactory.updateNamedImports(node.ast, asNodeArray(elements).ast).node; } // @api function createImportSpecifier(isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier): ImportSpecifier { - return astFactory.createImportSpecifier(isTypeOnly, asNode(propertyName)?.ast, asNode(name).ast).node; + return astFactory.createImportSpecifier(isTypeOnly, propertyName?.ast, name.ast).node; } // @api function updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier): ImportSpecifier { - return astFactory.updateImportSpecifier(asNode(node).ast, isTypeOnly, asNode(propertyName)?.ast, asNode(name).ast).node; + return astFactory.updateImportSpecifier(node.ast, isTypeOnly, propertyName?.ast, name.ast).node; } // @api @@ -2853,7 +2853,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: isExportEquals: boolean | undefined, expression: Expression, ): ExportAssignment { - return astFactory.createExportAssignment(asNodeArray(modifiers)?.ast, isExportEquals, asNode(expression).ast).node; + return astFactory.createExportAssignment(asNodeArray(modifiers)?.ast, isExportEquals, expression.ast).node; } // @api @@ -2862,7 +2862,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: modifiers: readonly ModifierLike[] | undefined, expression: Expression, ): ExportAssignment { - return astFactory.updateExportAssignment(asNode(node).ast, asNodeArray(modifiers)?.ast, asNode(expression).ast).node; + return astFactory.updateExportAssignment(node.ast, asNodeArray(modifiers)?.ast, expression.ast).node; } // @api @@ -2873,7 +2873,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: moduleSpecifier?: Expression, attributes?: ImportAttributes, ): ExportDeclaration { - return astFactory.createExportDeclaration(asNodeArray(modifiers)?.ast, isTypeOnly, asNode(exportClause)?.ast, asNode(moduleSpecifier)?.ast, asNode(attributes)?.ast).node; + return astFactory.createExportDeclaration(asNodeArray(modifiers)?.ast, isTypeOnly, exportClause?.ast, moduleSpecifier?.ast, attributes?.ast).node; } // @api @@ -2885,7 +2885,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: moduleSpecifier: Expression | undefined, attributes: ImportAttributes | undefined, ): ExportDeclaration { - return astFactory.updateExportDeclaration(asNode(node).ast, asNodeArray(modifiers)?.ast, isTypeOnly, asNode(exportClause)?.ast, asNode(moduleSpecifier)?.ast, asNode(attributes)?.ast).node; + return astFactory.updateExportDeclaration(node.ast, asNodeArray(modifiers)?.ast, isTypeOnly, exportClause?.ast, moduleSpecifier?.ast, attributes?.ast).node; } // @api @@ -2895,7 +2895,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports { - return astFactory.updateNamedExports(asNode(node).ast, asNodeArray(elements).ast).node; + return astFactory.updateNamedExports(node.ast, asNodeArray(elements).ast).node; } // @api @@ -2905,7 +2905,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateExportSpecifier(node: ExportSpecifier, isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: ModuleExportName): ExportSpecifier { - return astFactory.updateExportSpecifier(asNode(node).ast, isTypeOnly, asNode(propertyName)?.ast, asNode(name).ast).node; + return astFactory.updateExportSpecifier(node.ast, isTypeOnly, propertyName?.ast, name.ast).node; } // @api @@ -2919,12 +2919,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createExternalModuleReference(expression: Expression): ExternalModuleReference { - return astFactory.createExternalModuleReference(asNode(expression).ast).node; + return astFactory.createExternalModuleReference(expression.ast).node; } // @api function updateExternalModuleReference(node: ExternalModuleReference, expression: Expression): ExternalModuleReference { - return astFactory.updateExternalModuleReference(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateExternalModuleReference(node.ast, expression.ast).node; } // @@ -2943,63 +2943,63 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createJSDocNonNullableType(type: TypeNode, postfix = false): JSDocNonNullableType { - return astFactory.createJSDocNonNullableType(asNode(type).ast, postfix).node; + return astFactory.createJSDocNonNullableType(type.ast, postfix).node; } // @api function updateJSDocNonNullableType(node: JSDocNonNullableType, type: TypeNode): JSDocNonNullableType { - return astFactory.updateJSDocNonNullableType(asNode(node).ast, asNode(type).ast).node; + return astFactory.updateJSDocNonNullableType(node.ast, type.ast).node; } // @api function createJSDocNullableType(type: TypeNode, postfix = false): JSDocNullableType { - return astFactory.createJSDocNullableType(asNode(type).ast, postfix).node; + return astFactory.createJSDocNullableType(type.ast, postfix).node; } // @api function updateJSDocNullableType(node: JSDocNullableType, type: TypeNode): JSDocNullableType { - return astFactory.updateJSDocNullableType(asNode(node).ast, asNode(type).ast).node; + return astFactory.updateJSDocNullableType(node.ast, type.ast).node; } // @api function createJSDocOptionalType(type: TypeNode): JSDocOptionalType { - return astFactory.createJSDocOptionalType(asNode(type).ast).node; + return astFactory.createJSDocOptionalType(type.ast).node; } // @api function updateJSDocOptionalType(node: JSDocOptionalType, type: TypeNode): JSDocOptionalType { - return astFactory.updateJSDocOptionalType(asNode(node).ast, asNode(type).ast).node; + return astFactory.updateJSDocOptionalType(node.ast, type.ast).node; } // @api function createJSDocVariadicType(type: TypeNode): JSDocVariadicType { - return astFactory.createJSDocVariadicType(asNode(type).ast).node; + return astFactory.createJSDocVariadicType(type.ast).node; } // @api function updateJSDocVariadicType(node: JSDocVariadicType, type: TypeNode): JSDocVariadicType { - return astFactory.updateJSDocVariadicType(asNode(node).ast, asNode(type).ast).node; + return astFactory.updateJSDocVariadicType(node.ast, type.ast).node; } // @api function createJSDocNamepathType(type: TypeNode): JSDocNamepathType { // NOTE: 'type' can be undefined when this is called by parser. - return astFactory.createJSDocNamepathType(asNode(type)?.ast).node; + return astFactory.createJSDocNamepathType(type?.ast).node; } // @api function updateJSDocNamepathType(node: JSDocNamepathType, type: TypeNode): JSDocNamepathType { - return astFactory.updateJSDocNamepathType(asNode(node).ast, asNode(type).ast).node; + return astFactory.updateJSDocNamepathType(node.ast, type.ast).node; } // @api function createJSDocFunctionType(parameters: readonly ParameterDeclaration[], type: TypeNode | undefined): JSDocFunctionType { - return astFactory.createJSDocFunctionType(asNodeArray(parameters).ast, asNode(type)?.ast).node; + return astFactory.createJSDocFunctionType(asNodeArray(parameters).ast, type?.ast).node; } // @api function updateJSDocFunctionType(node: JSDocFunctionType, parameters: readonly ParameterDeclaration[], type: TypeNode | undefined): JSDocFunctionType { - return astFactory.updateJSDocFunctionType(asNode(node).ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; + return astFactory.updateJSDocFunctionType(node.ast, asNodeArray(parameters).ast, type?.ast).node; } // @api @@ -3009,266 +3009,266 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateJSDocTypeLiteral(node: JSDocTypeLiteral, propertyTags: readonly JSDocPropertyLikeTag[] | undefined, isArrayType: boolean): JSDocTypeLiteral { - return astFactory.updateJSDocTypeLiteral(asNode(node).ast, asNodeArray(propertyTags)?.ast, isArrayType).node; + return astFactory.updateJSDocTypeLiteral(node.ast, asNodeArray(propertyTags)?.ast, isArrayType).node; } // @api function createJSDocTypeExpression(type: TypeNode): JSDocTypeExpression { - return astFactory.createJSDocTypeExpression(asNode(type).ast).node; + return astFactory.createJSDocTypeExpression(type.ast).node; } // @api function updateJSDocTypeExpression(node: JSDocTypeExpression, type: TypeNode): JSDocTypeExpression { - return astFactory.updateJSDocTypeExpression(asNode(node).ast, asNode(type).ast).node; + return astFactory.updateJSDocTypeExpression(node.ast, type.ast).node; } // @api function createJSDocSignature(typeParameters: readonly JSDocTemplateTag[] | undefined, parameters: readonly JSDocParameterTag[], type?: JSDocReturnTag): JSDocSignature { - return astFactory.createJSDocSignature(asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; + return astFactory.createJSDocSignature(asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast).node; } // @api function updateJSDocSignature(node: JSDocSignature, typeParameters: readonly JSDocTemplateTag[] | undefined, parameters: readonly JSDocParameterTag[], type: JSDocReturnTag | undefined): JSDocSignature { - return astFactory.updateJSDocSignature(asNode(node).ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, asNode(type)?.ast).node; + return astFactory.updateJSDocSignature(node.ast, asNodeArray(typeParameters)?.ast, asNodeArray(parameters).ast, type?.ast).node; } // @api function createJSDocTemplateTag(tagName: Identifier | undefined, constraint: JSDocTypeExpression | undefined, typeParameters: readonly TypeParameterDeclaration[], comment?: string | NodeArray): JSDocTemplateTag { - return astFactory.createJSDocTemplateTag(asNode(tagName)?.ast, asNode(constraint)?.ast, asNodeArray(typeParameters).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocTemplateTag(tagName?.ast, constraint?.ast, asNodeArray(typeParameters).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocTemplateTag(node: JSDocTemplateTag, tagName: Identifier | undefined, constraint: JSDocTypeExpression | undefined, typeParameters: readonly TypeParameterDeclaration[], comment: string | NodeArray | undefined): JSDocTemplateTag { - return astFactory.updateJSDocTemplateTag(asNode(node).ast, asNode(tagName)?.ast, asNode(constraint)?.ast, asNodeArray(typeParameters).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocTemplateTag(node.ast, tagName?.ast, constraint?.ast, asNodeArray(typeParameters).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocTypedefTag(tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, fullName?: Identifier | JSDocNamespaceDeclaration, comment?: string | NodeArray): JSDocTypedefTag { - return astFactory.createJSDocTypedefTag(asNode(tagName)?.ast, asNode(typeExpression)?.ast, asNode(fullName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocTypedefTag(tagName?.ast, typeExpression?.ast, fullName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocTypedefTag(node: JSDocTypedefTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, fullName: Identifier | JSDocNamespaceDeclaration | undefined, comment: string | NodeArray | undefined): JSDocTypedefTag { - return astFactory.updateJSDocTypedefTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression)?.ast, asNode(fullName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocTypedefTag(node.ast, tagName?.ast, typeExpression?.ast, fullName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocParameterTag(tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression?: JSDocTypeExpression, isNameFirst?: boolean, comment?: string | NodeArray): JSDocParameterTag { - return astFactory.createJSDocParameterTag(asNode(tagName)?.ast, asNode(name).ast, isBracketed, asNode(typeExpression)?.ast, isNameFirst, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocParameterTag(tagName?.ast, name.ast, isBracketed, typeExpression?.ast, isNameFirst, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocParameterTag(node: JSDocParameterTag, tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression: JSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | NodeArray | undefined): JSDocParameterTag { - return astFactory.updateJSDocParameterTag(asNode(node).ast, asNode(tagName)?.ast, asNode(name).ast, isBracketed, asNode(typeExpression)?.ast, isNameFirst, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocParameterTag(node.ast, tagName?.ast, name.ast, isBracketed, typeExpression?.ast, isNameFirst, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocPropertyTag(tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression?: JSDocTypeExpression, isNameFirst?: boolean, comment?: string | NodeArray): JSDocPropertyTag { - return astFactory.createJSDocPropertyTag(asNode(tagName)?.ast, asNode(name).ast, isBracketed, asNode(typeExpression)?.ast, isNameFirst, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocPropertyTag(tagName?.ast, name.ast, isBracketed, typeExpression?.ast, isNameFirst, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocPropertyTag(node: JSDocPropertyTag, tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression: JSDocTypeExpression | undefined, isNameFirst: boolean, comment: string | NodeArray | undefined): JSDocPropertyTag { - return astFactory.updateJSDocPropertyTag(asNode(node).ast, asNode(tagName)?.ast, asNode(name).ast, isBracketed, asNode(typeExpression)?.ast, isNameFirst, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocPropertyTag(node.ast, tagName?.ast, name.ast, isBracketed, typeExpression?.ast, isNameFirst, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocCallbackTag(tagName: Identifier | undefined, typeExpression: JSDocSignature, fullName?: Identifier | JSDocNamespaceDeclaration, comment?: string | NodeArray): JSDocCallbackTag { - return astFactory.createJSDocCallbackTag(asNode(tagName)?.ast, asNode(typeExpression).ast, asNode(fullName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocCallbackTag(tagName?.ast, typeExpression.ast, fullName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocCallbackTag(node: JSDocCallbackTag, tagName: Identifier | undefined, typeExpression: JSDocSignature, fullName: Identifier | JSDocNamespaceDeclaration | undefined, comment: string | NodeArray | undefined): JSDocCallbackTag { - return astFactory.updateJSDocCallbackTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression).ast, asNode(fullName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocCallbackTag(node.ast, tagName?.ast, typeExpression.ast, fullName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocOverloadTag(tagName: Identifier | undefined, typeExpression: JSDocSignature, comment?: string | NodeArray): JSDocOverloadTag { - return astFactory.createJSDocOverloadTag(asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocOverloadTag(tagName?.ast, typeExpression.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocOverloadTag(node: JSDocOverloadTag, tagName: Identifier | undefined, typeExpression: JSDocSignature, comment: string | NodeArray | undefined): JSDocOverloadTag { - return astFactory.updateJSDocOverloadTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocOverloadTag(node.ast, tagName?.ast, typeExpression.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocAugmentsTag(tagName: Identifier | undefined, className: JSDocClassReference, comment?: string | NodeArray): JSDocAugmentsTag { - return astFactory.createJSDocAugmentsTag(asNode(tagName)?.ast, asNode(className).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocAugmentsTag(tagName?.ast, className.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocAugmentsTag(node: JSDocAugmentsTag, tagName: Identifier | undefined, className: JSDocClassReference, comment: string | NodeArray | undefined): JSDocAugmentsTag { - return astFactory.updateJSDocAugmentsTag(asNode(node).ast, asNode(tagName)?.ast, asNode(className).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocAugmentsTag(node.ast, tagName?.ast, className.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocImplementsTag(tagName: Identifier | undefined, className: JSDocClassReference, comment?: string | NodeArray): JSDocImplementsTag { - return astFactory.createJSDocImplementsTag(asNode(tagName)?.ast, asNode(className).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocImplementsTag(tagName?.ast, className.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocSeeTag(tagName: Identifier | undefined, name: JSDocNameReference | undefined, comment?: string | NodeArray): JSDocSeeTag { - return astFactory.createJSDocSeeTag(asNode(tagName)?.ast, asNode(name)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocSeeTag(tagName?.ast, name?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocSeeTag(node: JSDocSeeTag, tagName: Identifier | undefined, name: JSDocNameReference | undefined, comment?: string | NodeArray): JSDocSeeTag { - return astFactory.updateJSDocSeeTag(asNode(node).ast, asNode(tagName)?.ast, asNode(name)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocSeeTag(node.ast, tagName?.ast, name?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocNameReference(name: EntityName | JSDocMemberName): JSDocNameReference { - return astFactory.createJSDocNameReference(asNode(name).ast).node; + return astFactory.createJSDocNameReference(name.ast).node; } // @api function updateJSDocNameReference(node: JSDocNameReference, name: EntityName | JSDocMemberName): JSDocNameReference { - return astFactory.updateJSDocNameReference(asNode(node).ast, asNode(name).ast).node; + return astFactory.updateJSDocNameReference(node.ast, name.ast).node; } // @api function createJSDocMemberName(left: EntityName | JSDocMemberName, right: Identifier): JSDocMemberName { - return astFactory.createJSDocMemberName(asNode(left).ast, asNode(right).ast).node; + return astFactory.createJSDocMemberName(left.ast, right.ast).node; } // @api function updateJSDocMemberName(node: JSDocMemberName, left: EntityName | JSDocMemberName, right: Identifier): JSDocMemberName { - return astFactory.updateJSDocMemberName(asNode(node).ast, asNode(left).ast, asNode(right).ast).node; + return astFactory.updateJSDocMemberName(node.ast, left.ast, right.ast).node; } // @api function createJSDocLink(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLink { - return astFactory.createJSDocLink(asNode(name)?.ast, text).node; + return astFactory.createJSDocLink(name?.ast, text).node; } // @api function updateJSDocLink(node: JSDocLink, name: EntityName | JSDocMemberName | undefined, text: string): JSDocLink { - return astFactory.updateJSDocLink(asNode(node).ast, asNode(name)?.ast, text).node; + return astFactory.updateJSDocLink(node.ast, name?.ast, text).node; } // @api function createJSDocLinkCode(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkCode { - return astFactory.createJSDocLinkCode(asNode(name)?.ast, text).node; + return astFactory.createJSDocLinkCode(name?.ast, text).node; } // @api function updateJSDocLinkCode(node: JSDocLinkCode, name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkCode { - return astFactory.updateJSDocLinkCode(asNode(node).ast, asNode(name)?.ast, text).node; + return astFactory.updateJSDocLinkCode(node.ast, name?.ast, text).node; } // @api function createJSDocLinkPlain(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkPlain { - return astFactory.createJSDocLinkPlain(asNode(name)?.ast, text).node; + return astFactory.createJSDocLinkPlain(name?.ast, text).node; } // @api function updateJSDocLinkPlain(node: JSDocLinkPlain, name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkPlain { - return astFactory.updateJSDocLinkPlain(asNode(node).ast, asNode(name)?.ast, text).node; + return astFactory.updateJSDocLinkPlain(node.ast, name?.ast, text).node; } // @api function updateJSDocImplementsTag(node: JSDocImplementsTag, tagName: Identifier | undefined, className: JSDocClassReference, comment: string | NodeArray | undefined): JSDocImplementsTag { - return astFactory.updateJSDocImplementsTag(asNode(node).ast, asNode(tagName)?.ast, asNode(className).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocImplementsTag(node.ast, tagName?.ast, className.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocAuthorTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocAuthorTag { - return astFactory.createJSDocAuthorTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocAuthorTag(tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocAuthorTag(node: JSDocAuthorTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocAuthorTag { - return astFactory.updateJSDocAuthorTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocAuthorTag(node.ast, tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocClassTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocClassTag { - return astFactory.createJSDocClassTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocClassTag(tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocClassTag(node: JSDocClassTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocClassTag { - return astFactory.updateJSDocClassTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocClassTag(node.ast, tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocPublicTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocPublicTag { - return astFactory.createJSDocPublicTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocPublicTag(tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocPublicTag(node: JSDocPublicTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocPublicTag { - return astFactory.updateJSDocPublicTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocPublicTag(node.ast, tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocPrivateTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocPrivateTag { - return astFactory.createJSDocPrivateTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocPrivateTag(tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocPrivateTag(node: JSDocPrivateTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocPrivateTag { - return astFactory.updateJSDocPrivateTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocPrivateTag(node.ast, tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocProtectedTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocProtectedTag { - return astFactory.createJSDocProtectedTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocProtectedTag(tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocProtectedTag(node: JSDocProtectedTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocProtectedTag { - return astFactory.updateJSDocProtectedTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocProtectedTag(node.ast, tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocReadonlyTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocReadonlyTag { - return astFactory.createJSDocReadonlyTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocReadonlyTag(tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocReadonlyTag(node: JSDocReadonlyTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocReadonlyTag { - return astFactory.updateJSDocReadonlyTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocReadonlyTag(node.ast, tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocOverrideTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocOverrideTag { - return astFactory.createJSDocOverrideTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocOverrideTag(tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocOverrideTag(node: JSDocOverrideTag, tagName: Identifier | undefined, comment: string | NodeArray | undefined): JSDocOverrideTag { - return astFactory.updateJSDocOverrideTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocOverrideTag(node.ast, tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocDeprecatedTag(tagName: Identifier | undefined, comment?: string | NodeArray): JSDocDeprecatedTag { - return astFactory.createJSDocDeprecatedTag(asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocDeprecatedTag(tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocDeprecatedTag(node: JSDocDeprecatedTag, tagName: Identifier | undefined, comment?: string | NodeArray): JSDocDeprecatedTag { - return astFactory.updateJSDocDeprecatedTag(asNode(node).ast, asNode(tagName)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocDeprecatedTag(node.ast, tagName?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocUnknownTag(tagName: Identifier, comment?: string | NodeArray): JSDocUnknownTag { - return astFactory.createJSDocUnknownTag(asNode(tagName).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocUnknownTag(tagName.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocUnknownTag(node: JSDocUnknownTag, tagName: Identifier, comment: string | NodeArray | undefined): JSDocUnknownTag { - return astFactory.updateJSDocUnknownTag(asNode(node).ast, asNode(tagName).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocUnknownTag(node.ast, tagName.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocImportTag(tagName: Identifier | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes?: ImportAttributes, comment?: string | NodeArray): JSDocImportTag { - return astFactory.createJSDocImportTag(asNode(tagName)?.ast, asNode(importClause)?.ast, asNode(moduleSpecifier).ast, asNode(attributes)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocImportTag(tagName?.ast, importClause?.ast, moduleSpecifier.ast, attributes?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } function updateJSDocImportTag(node: JSDocImportTag, tagName: Identifier | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes: ImportAttributes | undefined, comment: string | NodeArray | undefined): JSDocImportTag { - return astFactory.updateJSDocImportTag(asNode(node).ast, asNode(tagName)?.ast, asNode(importClause)?.ast, asNode(moduleSpecifier).ast, asNode(attributes)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocImportTag(node.ast, tagName?.ast, importClause?.ast, moduleSpecifier.ast, attributes?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api @@ -3278,7 +3278,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateJSDocText(node: JSDocText, text: string): JSDocText { - return astFactory.updateJSDocText(asNode(node).ast, text).node; + return astFactory.updateJSDocText(node.ast, text).node; } // @api @@ -3288,67 +3288,67 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateJSDocComment(node: JSDoc, comment: string | NodeArray | undefined, tags: readonly JSDocTag[] | undefined): JSDoc { - return astFactory.updateJSDocComment(asNode(node).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast, asNodeArray(tags)?.ast).node; + return astFactory.updateJSDocComment(node.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast, asNodeArray(tags)?.ast).node; } // @api function createJSDocTypeTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string | NodeArray): JSDocTypeTag { - return astFactory.createJSDocTypeTag(asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocTypeTag(tagName?.ast, typeExpression.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocTypeTag(node: JSDocTypeTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment: string | NodeArray | undefined): JSDocTypeTag { - return astFactory.updateJSDocTypeTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocTypeTag(node.ast, tagName?.ast, typeExpression.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocReturnTag(tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: string | NodeArray): JSDocReturnTag { - return astFactory.createJSDocReturnTag(asNode(tagName)?.ast, asNode(typeExpression)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocReturnTag(tagName?.ast, typeExpression?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocReturnTag(node: JSDocReturnTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, comment: string | NodeArray | undefined): JSDocReturnTag { - return astFactory.updateJSDocReturnTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocReturnTag(node.ast, tagName?.ast, typeExpression?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocThisTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string | NodeArray): JSDocThisTag { - return astFactory.createJSDocThisTag(asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocThisTag(tagName?.ast, typeExpression.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocThisTag(node: JSDocThisTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, comment: string | NodeArray | undefined): JSDocThisTag { - return astFactory.updateJSDocThisTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocThisTag(node.ast, tagName?.ast, typeExpression?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocThrowsTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, comment?: string | NodeArray): JSDocThrowsTag { - return astFactory.createJSDocThrowsTag(asNode(tagName)?.ast, asNode(typeExpression)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocThrowsTag(tagName?.ast, typeExpression?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocThrowsTag(node: JSDocThrowsTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression | undefined, comment: string | NodeArray | undefined): JSDocThrowsTag { - return astFactory.updateJSDocThrowsTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression)?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocThrowsTag(node.ast, tagName?.ast, typeExpression?.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocEnumTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string | NodeArray) { - return astFactory.createJSDocEnumTag(asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocEnumTag(tagName?.ast, typeExpression.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocEnumTag(node: JSDocEnumTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment: string | NodeArray | undefined) { - return astFactory.updateJSDocEnumTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocEnumTag(node.ast, tagName?.ast, typeExpression.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function createJSDocSatisfiesTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string | NodeArray) { - return astFactory.createJSDocSatisfiesTag(asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.createJSDocSatisfiesTag(tagName?.ast, typeExpression.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @api function updateJSDocSatisfiesTag(node: JSDocSatisfiesTag, tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment: string | NodeArray | undefined) { - return astFactory.updateJSDocSatisfiesTag(asNode(node).ast, asNode(tagName)?.ast, asNode(typeExpression).ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; + return astFactory.updateJSDocSatisfiesTag(node.ast, tagName?.ast, typeExpression.ast, typeof comment === "string" ? comment : asNodeArray(comment)?.ast).node; } // @@ -3357,52 +3357,52 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createJsxElement(openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement): JsxElement { - return astFactory.createJsxElement(asNode(openingElement).ast, asNodeArray(children).ast, asNode(closingElement).ast).node; + return astFactory.createJsxElement(openingElement.ast, asNodeArray(children).ast, closingElement.ast).node; } // @api function updateJsxElement(node: JsxElement, openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement): JsxElement { - return astFactory.updateJsxElement(asNode(node).ast, asNode(openingElement).ast, asNodeArray(children).ast, asNode(closingElement).ast).node; + return astFactory.updateJsxElement(node.ast, openingElement.ast, asNodeArray(children).ast, closingElement.ast).node; } // @api function createJsxSelfClosingElement(tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes): JsxSelfClosingElement { - return astFactory.createJsxSelfClosingElement(asNode(tagName).ast, asNodeArray(typeArguments)?.ast, asNode(attributes).ast).node; + return astFactory.createJsxSelfClosingElement(tagName.ast, asNodeArray(typeArguments)?.ast, attributes.ast).node; } // @api function updateJsxSelfClosingElement(node: JsxSelfClosingElement, tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes): JsxSelfClosingElement { - return astFactory.updateJsxSelfClosingElement(asNode(node).ast, asNode(tagName).ast, asNodeArray(typeArguments)?.ast, asNode(attributes).ast).node; + return astFactory.updateJsxSelfClosingElement(node.ast, tagName.ast, asNodeArray(typeArguments)?.ast, attributes.ast).node; } // @api function createJsxOpeningElement(tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes): JsxOpeningElement { - return astFactory.createJsxOpeningElement(asNode(tagName).ast, asNodeArray(typeArguments)?.ast, asNode(attributes).ast).node; + return astFactory.createJsxOpeningElement(tagName.ast, asNodeArray(typeArguments)?.ast, attributes.ast).node; } // @api function updateJsxOpeningElement(node: JsxOpeningElement, tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes): JsxOpeningElement { - return astFactory.updateJsxOpeningElement(asNode(node).ast, asNode(tagName).ast, asNodeArray(typeArguments)?.ast, asNode(attributes).ast).node; + return astFactory.updateJsxOpeningElement(node.ast, tagName.ast, asNodeArray(typeArguments)?.ast, attributes.ast).node; } // @api function createJsxClosingElement(tagName: JsxTagNameExpression): JsxClosingElement { - return astFactory.createJsxClosingElement(asNode(tagName).ast).node; + return astFactory.createJsxClosingElement(tagName.ast).node; } // @api function updateJsxClosingElement(node: JsxClosingElement, tagName: JsxTagNameExpression): JsxClosingElement { - return astFactory.updateJsxClosingElement(asNode(node).ast, asNode(tagName).ast).node; + return astFactory.updateJsxClosingElement(node.ast, tagName.ast).node; } // @api function createJsxFragment(openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment): JsxFragment { - return astFactory.createJsxFragment(asNode(openingFragment).ast, asNodeArray(children).ast, asNode(closingFragment).ast).node; + return astFactory.createJsxFragment(openingFragment.ast, asNodeArray(children).ast, closingFragment.ast).node; } // @api function updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment): JsxFragment { - return astFactory.updateJsxFragment(asNode(node).ast, asNode(openingFragment).ast, asNodeArray(children).ast, asNode(closingFragment).ast).node; + return astFactory.updateJsxFragment(node.ast, openingFragment.ast, asNodeArray(children).ast, closingFragment.ast).node; } // @api @@ -3412,7 +3412,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateJsxText(node: JsxText, text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText { - return astFactory.updateJsxText(asNode(node).ast, text, containsOnlyTriviaWhiteSpaces).node; + return astFactory.updateJsxText(node.ast, text, containsOnlyTriviaWhiteSpaces).node; } // @api @@ -3427,12 +3427,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createJsxAttribute(name: JsxAttributeName, initializer: JsxAttributeValue | undefined): JsxAttribute { - return astFactory.createJsxAttribute(asNode(name).ast, asNode(initializer)?.ast).node; + return astFactory.createJsxAttribute(name.ast, initializer?.ast).node; } // @api function updateJsxAttribute(node: JsxAttribute, name: JsxAttributeName, initializer: JsxAttributeValue | undefined): JsxAttribute { - return astFactory.updateJsxAttribute(asNode(node).ast, asNode(name).ast, asNode(initializer)?.ast).node; + return astFactory.updateJsxAttribute(node.ast, name.ast, initializer?.ast).node; } // @api @@ -3442,37 +3442,37 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateJsxAttributes(node: JsxAttributes, properties: readonly JsxAttributeLike[]): JsxAttributes { - return astFactory.updateJsxAttributes(asNode(node).ast, asNodeArray(properties).ast).node; + return astFactory.updateJsxAttributes(node.ast, asNodeArray(properties).ast).node; } // @api function createJsxSpreadAttribute(expression: Expression): JsxSpreadAttribute { - return astFactory.createJsxSpreadAttribute(asNode(expression).ast).node; + return astFactory.createJsxSpreadAttribute(expression.ast).node; } // @api function updateJsxSpreadAttribute(node: JsxSpreadAttribute, expression: Expression): JsxSpreadAttribute { - return astFactory.updateJsxSpreadAttribute(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateJsxSpreadAttribute(node.ast, expression.ast).node; } // @api function createJsxExpression(dotDotDotToken: DotDotDotToken | undefined, expression: Expression | undefined): JsxExpression { - return astFactory.createJsxExpression(asNode(dotDotDotToken)?.ast, asNode(expression)?.ast).node; + return astFactory.createJsxExpression(dotDotDotToken?.ast, expression?.ast).node; } // @api function updateJsxExpression(node: JsxExpression, expression: Expression | undefined): JsxExpression { - return astFactory.updateJsxExpression(asNode(node).ast, asNode(expression)?.ast).node; + return astFactory.updateJsxExpression(node.ast, expression?.ast).node; } // @api function createJsxNamespacedName(namespace: Identifier, name: Identifier): JsxNamespacedName { - return astFactory.createJsxNamespacedName(asNode(namespace).ast, asNode(name).ast).node; + return astFactory.createJsxNamespacedName(namespace.ast, name.ast).node; } // @api function updateJsxNamespacedName(node: JsxNamespacedName, namespace: Identifier, name: Identifier): JsxNamespacedName { - return astFactory.updateJsxNamespacedName(asNode(node).ast, asNode(namespace).ast, asNode(name).ast).node; + return astFactory.updateJsxNamespacedName(node.ast, namespace.ast, name.ast).node; } // @@ -3481,12 +3481,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createCaseClause(expression: Expression, statements: readonly Statement[]): CaseClause { - return astFactory.createCaseClause(asNode(expression).ast, asNodeArray(statements).ast).node; + return astFactory.createCaseClause(expression.ast, asNodeArray(statements).ast).node; } // @api function updateCaseClause(node: CaseClause, expression: Expression, statements: readonly Statement[]): CaseClause { - return astFactory.updateCaseClause(asNode(node).ast, asNode(expression).ast, asNodeArray(statements).ast).node; + return astFactory.updateCaseClause(node.ast, expression.ast, asNodeArray(statements).ast).node; } // @api @@ -3496,7 +3496,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateDefaultClause(node: DefaultClause, statements: readonly Statement[]): DefaultClause { - return astFactory.updateDefaultClause(asNode(node).ast, asNodeArray(statements).ast).node; + return astFactory.updateDefaultClause(node.ast, asNodeArray(statements).ast).node; } // @api @@ -3506,17 +3506,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateHeritageClause(node: HeritageClause, types: readonly ExpressionWithTypeArguments[]): HeritageClause { - return astFactory.updateHeritageClause(asNode(node).ast, asNodeArray(types).ast).node; + return astFactory.updateHeritageClause(node.ast, asNodeArray(types).ast).node; } // @api function createCatchClause(variableDeclaration: string | BindingName | VariableDeclaration | undefined, block: Block): CatchClause { - return astFactory.createCatchClause(asVariableDeclaration(variableDeclaration)?.ast, asNode(block).ast).node; + return astFactory.createCatchClause(asVariableDeclaration(variableDeclaration)?.ast, block.ast).node; } // @api function updateCatchClause(node: CatchClause, variableDeclaration: VariableDeclaration | undefined, block: Block): CatchClause { - return astFactory.updateCatchClause(asNode(node).ast, asNode(variableDeclaration)?.ast, asNode(block).ast).node; + return astFactory.updateCatchClause(node.ast, variableDeclaration?.ast, block.ast).node; } // @@ -3525,32 +3525,32 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createPropertyAssignment(name: string | PropertyName, initializer: Expression): PropertyAssignment { - return astFactory.createPropertyAssignment(asName(name)?.ast, asNode(initializer).ast).node; + return astFactory.createPropertyAssignment(asName(name)?.ast, initializer.ast).node; } // @api function updatePropertyAssignment(node: PropertyAssignment, name: PropertyName, initializer: Expression): PropertyAssignment { - return astFactory.updatePropertyAssignment(asNode(node).ast, asNode(name).ast, asNode(initializer).ast).node; + return astFactory.updatePropertyAssignment(node.ast, name.ast, initializer.ast).node; } // @api function createShorthandPropertyAssignment(name: string | Identifier, objectAssignmentInitializer?: Expression): ShorthandPropertyAssignment { - return astFactory.createShorthandPropertyAssignment(asName(name).ast, asNode(objectAssignmentInitializer)?.ast).node; + return astFactory.createShorthandPropertyAssignment(asName(name).ast, objectAssignmentInitializer?.ast).node; } // @api function updateShorthandPropertyAssignment(node: ShorthandPropertyAssignment, name: Identifier, objectAssignmentInitializer: Expression | undefined): ShorthandPropertyAssignment { - return astFactory.updateShorthandPropertyAssignment(asNode(node).ast, asNode(name).ast, asNode(objectAssignmentInitializer)?.ast).node; + return astFactory.updateShorthandPropertyAssignment(node.ast, name.ast, objectAssignmentInitializer?.ast).node; } // @api function createSpreadAssignment(expression: Expression): SpreadAssignment { - return astFactory.createSpreadAssignment(asNode(expression).ast).node; + return astFactory.createSpreadAssignment(expression.ast).node; } // @api function updateSpreadAssignment(node: SpreadAssignment, expression: Expression): SpreadAssignment { - return astFactory.updateSpreadAssignment(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updateSpreadAssignment(node.ast, expression.ast).node; } // @@ -3559,12 +3559,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createEnumMember(name: string | PropertyName, initializer?: Expression): EnumMember { - return astFactory.createEnumMember(asName(name).ast, asNode(initializer)?.ast).node; + return astFactory.createEnumMember(asName(name).ast, initializer?.ast).node; } // @api function updateEnumMember(node: EnumMember, name: PropertyName, initializer: Expression | undefined): EnumMember { - return astFactory.updateEnumMember(asNode(node).ast, asNode(name).ast, asNode(initializer)?.ast).node; + return astFactory.updateEnumMember(node.ast, name.ast, initializer?.ast).node; } // @@ -3577,7 +3577,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: endOfFileToken: EndOfFileToken, flags: NodeFlags, ): SourceFile { - return astFactory.createSourceFile(asNodeArray(statements).ast, asNode(endOfFileToken).ast, flags).node; + return astFactory.createSourceFile(asNodeArray(statements).ast, endOfFileToken.ast, flags).node; } // @api @@ -3596,7 +3596,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: libReferenceDirectives = node.libReferenceDirectives, ): SourceFile { return astFactory.updateSourceFile( - asNode(node).ast, + node.ast, asNodeArray(statements).ast, isDeclarationFile, referencedFiles, @@ -3608,12 +3608,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createBundle(sourceFiles: readonly SourceFile[]): Bundle { - return astFactory.createBundle(sourceFiles as readonly ast.SourceFile[]).node; + return astFactory.createBundle(sourceFiles).node; } // @api function updateBundle(node: Bundle, sourceFiles: readonly SourceFile[]): Bundle { - return astFactory.updateBundle(asNode(node).ast, sourceFiles as readonly ast.SourceFile[]).node; + return astFactory.updateBundle(node.ast, sourceFiles).node; } // @@ -3622,12 +3622,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function createSyntheticExpression(type: Type, isSpread = false, tupleNameSource?: ParameterDeclaration | NamedTupleMember): SyntheticExpression { - return astFactory.createSyntheticExpression(type, isSpread, asNode(tupleNameSource)?.ast).node; + return astFactory.createSyntheticExpression(type, isSpread, tupleNameSource?.ast).node; } // @api function createSyntaxList(children: readonly Node[]): SyntaxList { - return astFactory.createSyntaxList(children as readonly ast.Node[]).node; + return astFactory.createSyntaxList(children).node; } // @@ -3642,7 +3642,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: */ // @api function createNotEmittedStatement(original: Node): NotEmittedStatement { - return astFactory.createNotEmittedStatement(asNode(original).ast).node; + return astFactory.createNotEmittedStatement(original.ast).node; } /** @@ -3654,12 +3654,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: */ // @api function createPartiallyEmittedExpression(expression: Expression, original?: Node): PartiallyEmittedExpression { - return astFactory.createPartiallyEmittedExpression(asNode(expression).ast, asNode(original)?.ast).node; + return astFactory.createPartiallyEmittedExpression(expression.ast, original?.ast).node; } // @api function updatePartiallyEmittedExpression(node: PartiallyEmittedExpression, expression: Expression): PartiallyEmittedExpression { - return astFactory.updatePartiallyEmittedExpression(asNode(node).ast, asNode(expression).ast).node; + return astFactory.updatePartiallyEmittedExpression(node.ast, expression.ast).node; } // @api @@ -3674,23 +3674,23 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: // @api function updateCommaListExpression(node: CommaListExpression, elements: readonly Expression[]): CommaListExpression { - return astFactory.updateCommaListExpression(asNode(node).ast, asNodeArray(elements).ast).node; + return astFactory.updateCommaListExpression(node.ast, asNodeArray(elements).ast).node; } // @api function createSyntheticReferenceExpression(expression: Expression, thisArg: Expression): SyntheticReferenceExpression { - return astFactory.createSyntheticReferenceExpression(asNode(expression).ast, asNode(thisArg).ast).node; + return astFactory.createSyntheticReferenceExpression(expression.ast, thisArg.ast).node; } // @api function updateSyntheticReferenceExpression(node: SyntheticReferenceExpression, expression: Expression, thisArg: Expression): SyntheticReferenceExpression { - return astFactory.updateSyntheticReferenceExpression(asNode(node).ast, asNode(expression).ast, asNode(thisArg).ast).node; + return astFactory.updateSyntheticReferenceExpression(node.ast, expression.ast, thisArg.ast).node; } // @api function cloneNode(node: T): T; function cloneNode(node: Node | undefined) { - return node && astFactory.cloneNode(asNode(node).ast).node as Node | undefined; + return node && astFactory.cloneNode(node.ast).node as Node | undefined; } // compound nodes @@ -4418,54 +4418,29 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: } } - type ToNode = Expression extends T ? ast.Expression : - Statement extends T ? ast.Statement : - TypeNode extends T ? ast.TypeNode : - TypeElement extends T ? ast.TypeElement : - ClassElement extends T ? ast.ClassElement : - ObjectLiteralElement extends T ? ast.ObjectLiteralElement : - PropertyAccessChain extends T ? ast.PropertyAccessChain : - ElementAccessChain extends T ? ast.ElementAccessChain : - CallChain extends T ? ast.CallChain : - NonNullChain extends T ? ast.NonNullChain : - ModuleBody extends T ? ast.ModuleBody : - LiteralExpression extends T ? ast.LiteralExpression : - JSDocNamespaceDeclaration extends T ? ast.JSDocNamespaceDeclaration : - JSDocPropertyLikeTag extends T ? ast.JSDocPropertyLikeTag : - JSDocClassReference extends T ? ast.JSDocClassReference : - JsxNamespacedName extends T ? ast.JsxNamespacedName : - ast.NodeType[T["kind"]]; - - function asNode(node: T): ToNode; - function asNode(node: T | undefined): ToNode | undefined; - function asNode(node: Node | undefined): ast.Node | undefined { - return node as ast.Node | undefined; - } - - function asNodeArray(array: readonly T[]): ast.NodeArray>; - function asNodeArray(array: readonly T[] | undefined): ast.NodeArray> | undefined; - function asNodeArray(array: readonly Node[] | undefined): ast.NodeArray | undefined { - return array ? createNodeArray(array) as ast.NodeArray : undefined; - } - - function asName(name: string | T): ToNode | ast.Identifier; - function asName(name: string | T | undefined): ToNode | ast.Identifier | undefined; + function asNodeArray(array: readonly T[]): NodeArray; + function asNodeArray(array: readonly T[] | undefined): NodeArray | undefined; + function asNodeArray(array: readonly Node[] | undefined): NodeArray | undefined { + return array ? createNodeArray(array) : undefined; + } + + function asName(name: string | T): T | Identifier; + function asName(name: string | T | undefined): T | Identifier | undefined; function asName(name: string | DeclarationName | Identifier | BindingName | PropertyName | NoSubstitutionTemplateLiteral | EntityName | ThisTypeNode | undefined) { - return typeof name === "string" ? createIdentifier(name) as ast.Identifier : - name as Node as ast.Node as ToNode; + return typeof name === "string" ? createIdentifier(name) : name; } - function asExpression(value: string | number | boolean | T): ToNode | ast.StringLiteral | ast.NumericLiteral | ast.BooleanLiteral; - function asExpression(value: string | number | boolean | T | undefined): ToNode | ast.StringLiteral | ast.NumericLiteral | ast.BooleanLiteral | undefined; - function asExpression(value: string | number | boolean | Expression | undefined): ast.Expression | undefined | ast.StringLiteral | ast.NumericLiteral | ast.BooleanLiteral | undefined { - return typeof value === "string" ? createStringLiteral(value) as ast.StringLiteral : - typeof value === "number" ? createNumericLiteral(value) as ast.NumericLiteral : - typeof value === "boolean" ? value ? createTrue() as ast.TrueLiteral : createFalse() as ast.FalseLiteral : - value as ast.Expression; + function asExpression(value: string | number | boolean | T): T | StringLiteral | NumericLiteral | BooleanLiteral; + function asExpression(value: string | number | boolean | T | undefined): T | StringLiteral | NumericLiteral | BooleanLiteral | undefined; + function asExpression(value: string | number | boolean | Expression | undefined): Expression | undefined | StringLiteral | NumericLiteral | BooleanLiteral | undefined { + return typeof value === "string" ? createStringLiteral(value) : + typeof value === "number" ? createNumericLiteral(value) : + typeof value === "boolean" ? value ? createTrue() : createFalse() : + value as Expression; } - function asToken(value: TKind | Token): ast.Token { - return (typeof value === "number" ? createToken(value) : value) as ast.Token; + function asToken(value: TKind | Token): Token { + return typeof value === "number" ? createToken(value) : value; } function asVariableDeclaration(variableDeclaration: string | BindingName | VariableDeclaration | undefined) { @@ -4475,9 +4450,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (node: /*exclamationToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined, - ) as ast.VariableDeclaration; + ); } - return variableDeclaration as ast.BindingName | ast.VariableDeclaration | undefined; + return variableDeclaration; } } diff --git a/src/compiler/factory/nodeTests.ts b/src/compiler/factory/nodeTests.ts index 8aa4bb02e83d2..ba20a858f5bf3 100644 --- a/src/compiler/factory/nodeTests.ts +++ b/src/compiler/factory/nodeTests.ts @@ -212,7 +212,7 @@ import { TryStatement, TupleTypeNode, TypeAliasDeclaration, - TypeAssertion, + TypeAssertionExpression, TypeLiteralNode, TypeOfExpression, TypeOperatorNode, @@ -601,7 +601,7 @@ export function isTaggedTemplateExpression(node: Node): node is TaggedTemplateEx return node.kind === SyntaxKind.TaggedTemplateExpression; } -export function isTypeAssertionExpression(node: Node): node is TypeAssertion { +export function isTypeAssertionExpression(node: Node): node is TypeAssertionExpression { return node.kind === SyntaxKind.TypeAssertionExpression; } diff --git a/src/compiler/factory/parenthesizerRules.ts b/src/compiler/factory/parenthesizerRules.ts index 093b69a79df74..3f56288e155aa 100644 --- a/src/compiler/factory/parenthesizerRules.ts +++ b/src/compiler/factory/parenthesizerRules.ts @@ -1,36 +1,21 @@ import { - ast, BinaryOperator, - CallChain, cast, - ClassElement, ConciseBody, - ElementAccessChain, Expression, identity, isLeftHandSideExpression, isNodeArray, isUnaryExpression, - JSDocClassReference, - JSDocNamespaceDeclaration, - JSDocPropertyLikeTag, - JsxNamespacedName, LeftHandSideExpression, - LiteralExpression, - ModuleBody, NamedTupleMember, Node, NodeArray, NodeFactory, - NonNullChain, - ObjectLiteralElement, ParenthesizerRules, - PropertyAccessChain, - Statement, SyntaxKind, - TypeElement, TypeNode, - UnaryExpression, + UnaryExpression } from "../_namespaces/ts.js"; /** @internal */ @@ -94,43 +79,43 @@ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRul } function parenthesizeLeftSideOfBinary(binaryOperator: SyntaxKind, leftSide: Expression): Expression { - return astRules.parenthesizeLeftSideOfBinary(binaryOperator, asNode(leftSide).ast).node; + return astRules.parenthesizeLeftSideOfBinary(binaryOperator, leftSide.ast).node; } function parenthesizeRightSideOfBinary(binaryOperator: SyntaxKind, leftSide: Expression | undefined, rightSide: Expression): Expression { - return astRules.parenthesizeRightSideOfBinary(binaryOperator, asNode(leftSide)?.ast, asNode(rightSide).ast).node; + return astRules.parenthesizeRightSideOfBinary(binaryOperator, leftSide?.ast, rightSide.ast).node; } function parenthesizeExpressionOfComputedPropertyName(expression: Expression): Expression { - return astRules.parenthesizeExpressionOfComputedPropertyName(asNode(expression).ast).node; + return astRules.parenthesizeExpressionOfComputedPropertyName(expression.ast).node; } function parenthesizeConditionOfConditionalExpression(condition: Expression): Expression { - return astRules.parenthesizeConditionOfConditionalExpression(asNode(condition).ast).node; + return astRules.parenthesizeConditionOfConditionalExpression(condition.ast).node; } function parenthesizeBranchOfConditionalExpression(branch: Expression): Expression { - return astRules.parenthesizeBranchOfConditionalExpression(asNode(branch).ast).node; + return astRules.parenthesizeBranchOfConditionalExpression(branch.ast).node; } function parenthesizeExpressionOfExportDefault(expression: Expression): Expression { - return astRules.parenthesizeExpressionOfExportDefault(asNode(expression).ast).node; + return astRules.parenthesizeExpressionOfExportDefault(expression.ast).node; } function parenthesizeExpressionOfNew(expression: Expression): LeftHandSideExpression { - return astRules.parenthesizeExpressionOfNew(asNode(expression).ast).node; + return astRules.parenthesizeExpressionOfNew(expression.ast).node; } function parenthesizeLeftSideOfAccess(expression: Expression, optionalChain?: boolean): LeftHandSideExpression { - return astRules.parenthesizeLeftSideOfAccess(asNode(expression).ast, optionalChain).node; + return astRules.parenthesizeLeftSideOfAccess(expression.ast, optionalChain).node; } function parenthesizeOperandOfPostfixUnary(operand: Expression): LeftHandSideExpression { - return astRules.parenthesizeOperandOfPostfixUnary(asNode(operand).ast).node; + return astRules.parenthesizeOperandOfPostfixUnary(operand.ast).node; } function parenthesizeOperandOfPrefixUnary(operand: Expression): UnaryExpression { - return astRules.parenthesizeOperandOfPrefixUnary(asNode(operand).ast).node; + return astRules.parenthesizeOperandOfPrefixUnary(operand.ast).node; } function parenthesizeExpressionsOfCommaDelimitedList(elements: NodeArray): NodeArray { @@ -138,29 +123,29 @@ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRul } function parenthesizeExpressionForDisallowedComma(expression: Expression): Expression { - return astRules.parenthesizeExpressionForDisallowedComma(asNode(expression).ast).node; + return astRules.parenthesizeExpressionForDisallowedComma(expression.ast).node; } function parenthesizeExpressionOfExpressionStatement(expression: Expression): Expression { - return astRules.parenthesizeExpressionOfExpressionStatement(asNode(expression).ast).node; + return astRules.parenthesizeExpressionOfExpressionStatement(expression.ast).node; } function parenthesizeConciseBodyOfArrowFunction(body: Expression): Expression; function parenthesizeConciseBodyOfArrowFunction(body: ConciseBody): ConciseBody; function parenthesizeConciseBodyOfArrowFunction(body: ConciseBody): ConciseBody { - return astRules.parenthesizeConciseBodyOfArrowFunction(asNode(body).ast).node; + return astRules.parenthesizeConciseBodyOfArrowFunction(body.ast).node; } function parenthesizeCheckTypeOfConditionalType(checkType: TypeNode): TypeNode { - return astRules.parenthesizeCheckTypeOfConditionalType(asNode(checkType).ast).node; + return astRules.parenthesizeCheckTypeOfConditionalType(checkType.ast).node; } function parenthesizeExtendsTypeOfConditionalType(extendsType: TypeNode): TypeNode { - return astRules.parenthesizeExtendsTypeOfConditionalType(asNode(extendsType).ast).node; + return astRules.parenthesizeExtendsTypeOfConditionalType(extendsType.ast).node; } function parenthesizeConstituentTypeOfUnionType(type: TypeNode): TypeNode { - return astRules.parenthesizeConstituentTypeOfUnionType(asNode(type).ast).node; + return astRules.parenthesizeConstituentTypeOfUnionType(type.ast).node; } function parenthesizeConstituentTypesOfUnionType(members: readonly TypeNode[]): NodeArray { @@ -168,7 +153,7 @@ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRul } function parenthesizeConstituentTypeOfIntersectionType(type: TypeNode): TypeNode { - return astRules.parenthesizeConstituentTypeOfIntersectionType(asNode(type).ast).node; + return astRules.parenthesizeConstituentTypeOfIntersectionType(type.ast).node; } function parenthesizeConstituentTypesOfIntersectionType(members: readonly TypeNode[]): NodeArray { @@ -176,15 +161,15 @@ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRul } function parenthesizeOperandOfTypeOperator(type: TypeNode) { - return astRules.parenthesizeOperandOfTypeOperator(asNode(type).ast).node; + return astRules.parenthesizeOperandOfTypeOperator(type.ast).node; } function parenthesizeOperandOfReadonlyTypeOperator(type: TypeNode) { - return astRules.parenthesizeOperandOfReadonlyTypeOperator(asNode(type).ast).node; + return astRules.parenthesizeOperandOfReadonlyTypeOperator(type.ast).node; } function parenthesizeNonArrayTypeOfPostfixType(type: TypeNode) { - return astRules.parenthesizeNonArrayTypeOfPostfixType(asNode(type).ast).node; + return astRules.parenthesizeNonArrayTypeOfPostfixType(type.ast).node; } function parenthesizeElementTypesOfTupleType(types: readonly (TypeNode | NamedTupleMember)[]): NodeArray { @@ -192,49 +177,25 @@ export function createParenthesizerRules(factory: NodeFactory): ParenthesizerRul } function parenthesizeElementTypeOfTupleType(type: TypeNode | NamedTupleMember): TypeNode { - return astRules.parenthesizeElementTypeOfTupleType(asNode(type).ast).node; + return astRules.parenthesizeElementTypeOfTupleType(type.ast).node; } function parenthesizeTypeOfOptionalType(type: TypeNode): TypeNode { - return astRules.parenthesizeTypeOfOptionalType(asNode(type).ast).node; + return astRules.parenthesizeTypeOfOptionalType(type.ast).node; } function parenthesizeLeadingTypeArgument(node: TypeNode) { - return astRules.parenthesizeLeadingTypeArgument(asNode(node).ast).node; + return astRules.parenthesizeLeadingTypeArgument(node.ast).node; } function parenthesizeTypeArguments(typeArguments: NodeArray | undefined): NodeArray | undefined { return astRules.parenthesizeTypeArguments(asNodeArray(typeArguments)?.ast)?.nodes; } - type ToNode = Expression extends T ? ast.Expression : - Statement extends T ? ast.Statement : - TypeNode extends T ? ast.TypeNode : - TypeElement extends T ? ast.TypeElement : - ClassElement extends T ? ast.ClassElement : - ObjectLiteralElement extends T ? ast.ObjectLiteralElement : - PropertyAccessChain extends T ? ast.PropertyAccessChain : - ElementAccessChain extends T ? ast.ElementAccessChain : - CallChain extends T ? ast.CallChain : - NonNullChain extends T ? ast.NonNullChain : - ModuleBody extends T ? ast.ModuleBody : - LiteralExpression extends T ? ast.LiteralExpression : - JSDocNamespaceDeclaration extends T ? ast.JSDocNamespaceDeclaration : - JSDocPropertyLikeTag extends T ? ast.JSDocPropertyLikeTag : - JSDocClassReference extends T ? ast.JSDocClassReference : - JsxNamespacedName extends T ? ast.JsxNamespacedName : - ast.NodeType[T["kind"]]; - - function asNode(node: T): ToNode; - function asNode(node: T | undefined): ToNode | undefined; - function asNode(node: Node | undefined): ast.Node | undefined { - return node as ast.Node | undefined; - } - - function asNodeArray(array: readonly T[]): ast.NodeArray>; - function asNodeArray(array: readonly T[] | undefined): ast.NodeArray> | undefined; - function asNodeArray(array: readonly Node[] | undefined): ast.NodeArray | undefined { - return array ? factory.createNodeArray(array) as ast.NodeArray : undefined; + function asNodeArray(array: readonly T[]): NodeArray; + function asNodeArray(array: readonly T[] | undefined): NodeArray | undefined; + function asNodeArray(array: readonly Node[] | undefined): NodeArray | undefined { + return array ? factory.createNodeArray(array) : undefined; } } diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index 9f7cc54ef7508..7818c1af0403a 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -126,7 +126,6 @@ import { MethodDeclaration, MinusToken, Modifier, - ModifiersArray, ModuleKind, ModuleName, MultiplicativeOperator, @@ -463,7 +462,7 @@ function createExpressionForMethodDeclaration(factory: NodeFactory, method: Meth /** @internal */ export function createExpressionForObjectLiteralElementLike(factory: NodeFactory, node: ObjectLiteralExpression, property: ObjectLiteralElementLike, receiver: Expression): Expression | undefined { - if (property.name && isPrivateIdentifier(property.name)) { + if (!isSpreadAssignment(property) && property.name && isPrivateIdentifier(property.name)) { Debug.failBadSyntaxKind(property.name, "Private identifiers are not allowed in object literals."); } switch (property.kind) { @@ -1048,10 +1047,13 @@ export function tryGetPropertyNameOfBindingOrAssignmentElement(bindingElement: B case SyntaxKind.SpreadAssignment: // `a` in `({ ...a } = ...)` - if (bindingElement.name && isPrivateIdentifier(bindingElement.name)) { - return Debug.failBadSyntaxKind(bindingElement.name); + if (isPropertyName(bindingElement.expression)) { + if (isPrivateIdentifier(bindingElement.expression)) { + return Debug.failBadSyntaxKind(bindingElement.expression); + } + return bindingElement.expression; } - return bindingElement.name; + break; } const target = getTargetOfBindingOrAssignmentElement(bindingElement); @@ -1606,7 +1608,7 @@ export function formatGeneratedName(privateName: boolean, prefix: string | Gener * * @internal */ -export function createAccessorPropertyBackingField(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, initializer: Expression | undefined): PropertyDeclaration { +export function createAccessorPropertyBackingField(factory: NodeFactory, node: PropertyDeclaration, modifiers: NodeArray | undefined, initializer: Expression | undefined): PropertyDeclaration { return factory.updatePropertyDeclaration( node, modifiers, diff --git a/src/compiler/forEachChild.ts b/src/compiler/forEachChild.ts index 7c4b92a142864..11ebac8d1678e 100644 --- a/src/compiler/forEachChild.ts +++ b/src/compiler/forEachChild.ts @@ -162,7 +162,7 @@ import { TryStatement, TupleTypeNode, TypeAliasDeclaration, - TypeAssertion, + TypeAssertionExpression, TypeLiteralNode, TypeOfExpression, TypeOperatorNode, @@ -307,7 +307,6 @@ const forEachChildTable: ForEachChildTable = { }, [SyntaxKind.Constructor]: function forEachChildInConstructor(node: ConstructorDeclaration, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { return visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || visitNodes(cbNode, cbNodes, node.typeParameters) || visitNodes(cbNode, cbNodes, node.parameters) || visitNode(cbNode, node.type) || @@ -450,7 +449,7 @@ const forEachChildTable: ForEachChildTable = { visitNodes(cbNode, cbNodes, node.typeArguments) || visitNode(cbNode, node.template); }, - [SyntaxKind.TypeAssertionExpression]: function forEachChildInTypeAssertionExpression(node: TypeAssertion, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { + [SyntaxKind.TypeAssertionExpression]: function forEachChildInTypeAssertionExpression(node: TypeAssertionExpression, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined { return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); }, diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index ac433ba8fed10..22a9c751181a9 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -100,6 +100,7 @@ import { NodeModulePathParts, normalizePath, PackageJsonPathFields, + PartialSourceFile, pathContainsNodeModules, pathIsBareSpecifier, pathIsRelative, @@ -183,7 +184,7 @@ export function getModuleSpecifierPreferences( { importModuleSpecifierPreference, importModuleSpecifierEnding, autoImportSpecifierExcludeRegexes }: UserPreferences, host: Pick, compilerOptions: CompilerOptions, - importingSourceFile: Pick, + importingSourceFile: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, oldImportSpecifier?: string, ): ModuleSpecifierPreferences { const filePreferredEnding = getPreferredEnding(); @@ -431,7 +432,7 @@ export function getModuleSpecifiersWithCacheInfo( /** @internal */ export function getLocalModuleSpecifierBetweenFileNames( - importingFile: Pick, + importingFile: PartialSourceFile<"impliedNodeFormat">, targetFileName: string, compilerOptions: CompilerOptions, host: ModuleSpecifierResolutionHost, @@ -1459,7 +1460,7 @@ function isPathRelativeToParent(path: string): boolean { return startsWith(path, ".."); } -function getDefaultResolutionModeForFile(file: Pick, host: Pick, compilerOptions: CompilerOptions) { +function getDefaultResolutionModeForFile(file: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, host: Pick, compilerOptions: CompilerOptions) { return isFullSourceFile(file) ? host.getDefaultResolutionModeForFile(file) : getDefaultResolutionModeForFileWorker(file, compilerOptions); } diff --git a/src/compiler/nodes.ts b/src/compiler/nodes.ts new file mode 100644 index 0000000000000..b09cc1f4d3af1 --- /dev/null +++ b/src/compiler/nodes.ts @@ -0,0 +1,613 @@ +import { + ArrayBindingPattern, + ArrayLiteralExpression, + ArrayTypeNode, + ArrowFunction, + AsExpression, + AstTokenData, + AwaitExpression, + BigIntLiteral, + BinaryExpression, + BindingElement, + Block, + BreakStatement, + Bundle, + CallExpression, + CallSignatureDeclaration, + CaseBlock, + CaseClause, + CatchClause, + ClassDeclaration, + ClassExpression, + ClassStaticBlockDeclaration, + CommaListExpression, + ComputedPropertyName, + ConditionalExpression, + ConditionalTypeNode, + ConstructorDeclaration, + ConstructorTypeNode, + ConstructSignatureDeclaration, + ContinueStatement, + DebuggerStatement, + Decorator, + DefaultClause, + DeleteExpression, + DoStatement, + ElementAccessExpression, + EmptyStatement, + EndOfFileToken, + EnumDeclaration, + EnumMember, + ExportAssignment, + ExportDeclaration, + ExportSpecifier, + ExpressionStatement, + ExpressionWithTypeArguments, + ExternalModuleReference, + FalseLiteral, + ForInStatement, + ForOfStatement, + ForStatement, + FunctionDeclaration, + FunctionExpression, + FunctionTypeNode, + GetAccessorDeclaration, + HasLocals, + HasName, + HeritageClause, + Identifier, + IfStatement, + ImportAttribute, + ImportClause, + ImportDeclaration, + ImportEqualsDeclaration, + ImportExpression, + ImportSpecifier, + ImportTypeAssertionContainer, + ImportTypeNode, + IndexedAccessTypeNode, + IndexSignatureDeclaration, + InferTypeNode, + InterfaceDeclaration, + IntersectionTypeNode, + IsFunctionLike, + JSDoc, + JSDocAllType, + JSDocAugmentsTag, + JSDocAuthorTag, + JSDocCallbackTag, + JSDocClassTag, + JSDocDeprecatedTag, + JSDocEnumTag, + JSDocFunctionType, + JSDocImplementsTag, + JSDocImportTag, + JSDocLink, + JSDocLinkCode, + JSDocLinkPlain, + JSDocMemberName, + JSDocNamepathType, + JSDocNameReference, + JSDocNonNullableType, + JSDocNullableType, + JSDocOptionalType, + JSDocOverloadTag, + JSDocOverrideTag, + JSDocParameterTag, + JSDocPrivateTag, + JSDocPropertyTag, + JSDocProtectedTag, + JSDocPublicTag, + JSDocReadonlyTag, + JSDocReturnTag, + JSDocSatisfiesTag, + JSDocSeeTag, + JSDocSignature, + JSDocTemplateTag, + JSDocText, + JSDocThisTag, + JSDocThrowsTag, + JSDocTypedefTag, + JSDocTypeExpression, + JSDocTypeLiteral, + JSDocTypeTag, + JSDocUnknownTag, + JSDocUnknownType, + JSDocVariadicType, + JsxAttribute, + JsxAttributes, + JsxClosingElement, + JsxClosingFragment, + JsxElement, + JsxExpression, + JsxFragment, + JsxNamespacedName, + JsxOpeningElement, + JsxOpeningFragment, + JsxSelfClosingElement, + JsxSpreadAttribute, + JsxText, + LabeledStatement, + LiteralTypeNode, + MappedTypeNode, + MetaProperty, + MethodDeclaration, + MethodSignature, + MissingDeclaration, + ModuleBlock, + ModuleDeclaration, + NamedExports, + NamedImports, + NamedTupleMember, + NamespaceExport, + NamespaceExportDeclaration, + NamespaceImport, + NewExpression, + NonNullExpression, + NoSubstitutionTemplateLiteral, + NotEmittedStatement, + NotEmittedTypeElement, + NullLiteral, + NumericLiteral, + ObjectBindingPattern, + ObjectLiteralExpression, + OmittedExpression, + OptionalTypeNode, + ParameterDeclaration, + ParenthesizedExpression, + ParenthesizedTypeNode, + PartiallyEmittedExpression, + PostfixUnaryExpression, + PrefixUnaryExpression, + PrivateIdentifier, + PropertyAccessExpression, + PropertyAssignment, + PropertyDeclaration, + PropertySignature, + QualifiedName, + RegularExpressionLiteral, + RestTypeNode, + ReturnStatement, + SatisfiesExpression, + SemicolonClassElement, + SetAccessorDeclaration, + ShorthandPropertyAssignment, + SourceFile, + SpreadAssignment, + SpreadElement, + StringLiteral, + SuperExpression, + SwitchStatement, + SyntaxKind, + SyntaxList, + SyntheticExpression, + SyntheticReferenceExpression, + TaggedTemplateExpression, + TemplateExpression, + TemplateHead, TemplateLiteralTypeNode, TemplateLiteralTypeSpan, TemplateMiddle, TemplateSpan, TemplateTail, + ThisExpression, + ThisTypeNode, + ThrowStatement, + Token, + TrueLiteral, + TryStatement, + TupleTypeNode, + TypeAliasDeclaration, + TypeAssertionExpression, + TypeLiteralNode, + TypeOfExpression, + TypeOperatorNode, + TypeParameterDeclaration, + TypePredicateNode, + TypeQueryNode, + TypeReferenceNode, + UnionTypeNode, + VariableDeclaration, + VariableDeclarationList, + VariableStatement, + VoidExpression, + WhileStatement, + WithStatement, + YieldExpression +} from "./_namespaces/ts.js"; + +{ + // eslint-disable-next-line @typescript-eslint/naming-convention + type _ = [ + __Expect>, + __Expect, IsFunctionLike>, + ]; +} + +{ + // eslint-disable-next-line @typescript-eslint/naming-convention + type _ = [ + __Expect>, + __Expect, HasLocals>, + ]; +} + +{ + // eslint-disable-next-line @typescript-eslint/naming-convention + type _ = [ + __Expect>, + __Expect, HasName>, + ]; +} + +// Registry + +/** + * A mapping of all `SyntaxKind` values to their associated `Node` subtypes. + */ +export interface NodeMap { + [SyntaxKind.Unknown]: Token; + [SyntaxKind.EndOfFileToken]: EndOfFileToken; + [SyntaxKind.SingleLineCommentTrivia]: Token; + [SyntaxKind.MultiLineCommentTrivia]: Token; + [SyntaxKind.NewLineTrivia]: Token; + [SyntaxKind.WhitespaceTrivia]: Token; + [SyntaxKind.ShebangTrivia]: Token; + [SyntaxKind.ConflictMarkerTrivia]: Token; + [SyntaxKind.NonTextFileMarkerTrivia]: never; + [SyntaxKind.NumericLiteral]: NumericLiteral; + [SyntaxKind.BigIntLiteral]: BigIntLiteral; + [SyntaxKind.StringLiteral]: StringLiteral; + [SyntaxKind.JsxText]: JsxText; + [SyntaxKind.JsxTextAllWhiteSpaces]: never; + [SyntaxKind.RegularExpressionLiteral]: RegularExpressionLiteral; + [SyntaxKind.NoSubstitutionTemplateLiteral]: NoSubstitutionTemplateLiteral; + [SyntaxKind.TemplateHead]: TemplateHead; + [SyntaxKind.TemplateMiddle]: TemplateMiddle; + [SyntaxKind.TemplateTail]: TemplateTail; + [SyntaxKind.OpenBraceToken]: Token; + [SyntaxKind.CloseBraceToken]: Token; + [SyntaxKind.OpenParenToken]: Token; + [SyntaxKind.CloseParenToken]: Token; + [SyntaxKind.OpenBracketToken]: Token; + [SyntaxKind.CloseBracketToken]: Token; + [SyntaxKind.DotToken]: Token; + [SyntaxKind.DotDotDotToken]: Token; + [SyntaxKind.SemicolonToken]: Token; + [SyntaxKind.CommaToken]: Token; + [SyntaxKind.QuestionDotToken]: Token; + [SyntaxKind.LessThanToken]: Token; + [SyntaxKind.LessThanSlashToken]: Token; + [SyntaxKind.GreaterThanToken]: Token; + [SyntaxKind.LessThanEqualsToken]: Token; + [SyntaxKind.GreaterThanEqualsToken]: Token; + [SyntaxKind.EqualsEqualsToken]: Token; + [SyntaxKind.ExclamationEqualsToken]: Token; + [SyntaxKind.EqualsEqualsEqualsToken]: Token; + [SyntaxKind.ExclamationEqualsEqualsToken]: Token; + [SyntaxKind.EqualsGreaterThanToken]: Token; + [SyntaxKind.PlusToken]: Token; + [SyntaxKind.MinusToken]: Token; + [SyntaxKind.AsteriskToken]: Token; + [SyntaxKind.AsteriskAsteriskToken]: Token; + [SyntaxKind.SlashToken]: Token; + [SyntaxKind.PercentToken]: Token; + [SyntaxKind.PlusPlusToken]: Token; + [SyntaxKind.MinusMinusToken]: Token; + [SyntaxKind.LessThanLessThanToken]: Token; + [SyntaxKind.GreaterThanGreaterThanToken]: Token; + [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: Token; + [SyntaxKind.AmpersandToken]: Token; + [SyntaxKind.BarToken]: Token; + [SyntaxKind.CaretToken]: Token; + [SyntaxKind.ExclamationToken]: Token; + [SyntaxKind.TildeToken]: Token; + [SyntaxKind.AmpersandAmpersandToken]: Token; + [SyntaxKind.BarBarToken]: Token; + [SyntaxKind.QuestionToken]: Token; + [SyntaxKind.ColonToken]: Token; + [SyntaxKind.AtToken]: Token; + [SyntaxKind.QuestionQuestionToken]: Token; + [SyntaxKind.BacktickToken]: Token; + [SyntaxKind.HashToken]: Token; + [SyntaxKind.EqualsToken]: Token; + [SyntaxKind.PlusEqualsToken]: Token; + [SyntaxKind.MinusEqualsToken]: Token; + [SyntaxKind.AsteriskEqualsToken]: Token; + [SyntaxKind.AsteriskAsteriskEqualsToken]: Token; + [SyntaxKind.SlashEqualsToken]: Token; + [SyntaxKind.PercentEqualsToken]: Token; + [SyntaxKind.LessThanLessThanEqualsToken]: Token; + [SyntaxKind.GreaterThanGreaterThanEqualsToken]: Token; + [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: Token; + [SyntaxKind.AmpersandEqualsToken]: Token; + [SyntaxKind.BarEqualsToken]: Token; + [SyntaxKind.BarBarEqualsToken]: Token; + [SyntaxKind.AmpersandAmpersandEqualsToken]: Token; + [SyntaxKind.QuestionQuestionEqualsToken]: Token; + [SyntaxKind.CaretEqualsToken]: Token; + [SyntaxKind.Identifier]: Identifier; + [SyntaxKind.PrivateIdentifier]: PrivateIdentifier; + /** @internal */ + [SyntaxKind.JSDocCommentTextToken]: never; + [SyntaxKind.BreakKeyword]: Token; + [SyntaxKind.CaseKeyword]: Token; + [SyntaxKind.CatchKeyword]: Token; + [SyntaxKind.ClassKeyword]: Token; + [SyntaxKind.ConstKeyword]: Token; + [SyntaxKind.ContinueKeyword]: Token; + [SyntaxKind.DebuggerKeyword]: Token; + [SyntaxKind.DefaultKeyword]: Token; + [SyntaxKind.DeleteKeyword]: Token; + [SyntaxKind.DoKeyword]: Token; + [SyntaxKind.ElseKeyword]: Token; + [SyntaxKind.EnumKeyword]: Token; + [SyntaxKind.ExportKeyword]: Token; + [SyntaxKind.ExtendsKeyword]: Token; + [SyntaxKind.FalseKeyword]: FalseLiteral; + [SyntaxKind.FinallyKeyword]: Token; + [SyntaxKind.ForKeyword]: Token; + [SyntaxKind.FunctionKeyword]: Token; + [SyntaxKind.IfKeyword]: Token; + [SyntaxKind.ImportKeyword]: ImportExpression; + [SyntaxKind.InKeyword]: Token; + [SyntaxKind.InstanceOfKeyword]: Token; + [SyntaxKind.NewKeyword]: Token; + [SyntaxKind.NullKeyword]: NullLiteral; + [SyntaxKind.ReturnKeyword]: Token; + [SyntaxKind.SuperKeyword]: SuperExpression; + [SyntaxKind.SwitchKeyword]: Token; + [SyntaxKind.ThisKeyword]: ThisExpression; + [SyntaxKind.ThrowKeyword]: Token; + [SyntaxKind.TrueKeyword]: TrueLiteral; + [SyntaxKind.TryKeyword]: Token; + [SyntaxKind.TypeOfKeyword]: Token; + [SyntaxKind.VarKeyword]: Token; + [SyntaxKind.VoidKeyword]: Token; + [SyntaxKind.WhileKeyword]: Token; + [SyntaxKind.WithKeyword]: Token; + [SyntaxKind.ImplementsKeyword]: Token; + [SyntaxKind.InterfaceKeyword]: Token; + [SyntaxKind.LetKeyword]: Token; + [SyntaxKind.PackageKeyword]: Token; + [SyntaxKind.PrivateKeyword]: Token; + [SyntaxKind.ProtectedKeyword]: Token; + [SyntaxKind.PublicKeyword]: Token; + [SyntaxKind.StaticKeyword]: Token; + [SyntaxKind.YieldKeyword]: Token; + [SyntaxKind.AbstractKeyword]: Token; + [SyntaxKind.AccessorKeyword]: Token; + [SyntaxKind.AsKeyword]: Token; + [SyntaxKind.AssertsKeyword]: Token; + [SyntaxKind.AssertKeyword]: Token; + [SyntaxKind.AnyKeyword]: Token; + [SyntaxKind.AsyncKeyword]: Token; + [SyntaxKind.AwaitKeyword]: Token; + [SyntaxKind.BooleanKeyword]: Token; + [SyntaxKind.ConstructorKeyword]: Token; + [SyntaxKind.DeclareKeyword]: Token; + [SyntaxKind.GetKeyword]: Token; + [SyntaxKind.InferKeyword]: Token; + [SyntaxKind.IntrinsicKeyword]: Token; + [SyntaxKind.IsKeyword]: Token; + [SyntaxKind.KeyOfKeyword]: Token; + [SyntaxKind.ModuleKeyword]: Token; + [SyntaxKind.NamespaceKeyword]: Token; + [SyntaxKind.NeverKeyword]: Token; + [SyntaxKind.OutKeyword]: Token; + [SyntaxKind.ReadonlyKeyword]: Token; + [SyntaxKind.RequireKeyword]: Token; + [SyntaxKind.NumberKeyword]: Token; + [SyntaxKind.ObjectKeyword]: Token; + [SyntaxKind.SatisfiesKeyword]: Token; + [SyntaxKind.SetKeyword]: Token; + [SyntaxKind.StringKeyword]: Token; + [SyntaxKind.SymbolKeyword]: Token; + [SyntaxKind.TypeKeyword]: Token; + [SyntaxKind.UndefinedKeyword]: Token; + [SyntaxKind.UniqueKeyword]: Token; + [SyntaxKind.UnknownKeyword]: Token; + [SyntaxKind.UsingKeyword]: Token; + [SyntaxKind.FromKeyword]: Token; + [SyntaxKind.GlobalKeyword]: Token; + [SyntaxKind.BigIntKeyword]: Token; + [SyntaxKind.OverrideKeyword]: Token; + [SyntaxKind.OfKeyword]: Token; + [SyntaxKind.QualifiedName]: QualifiedName; + [SyntaxKind.ComputedPropertyName]: ComputedPropertyName; + [SyntaxKind.Decorator]: Decorator; + [SyntaxKind.TypeParameter]: TypeParameterDeclaration; + [SyntaxKind.CallSignature]: CallSignatureDeclaration; + [SyntaxKind.ConstructSignature]: ConstructSignatureDeclaration; + [SyntaxKind.VariableDeclaration]: VariableDeclaration; + [SyntaxKind.VariableDeclarationList]: VariableDeclarationList; + [SyntaxKind.Parameter]: ParameterDeclaration; + [SyntaxKind.BindingElement]: BindingElement; + [SyntaxKind.PropertySignature]: PropertySignature; + [SyntaxKind.PropertyDeclaration]: PropertyDeclaration; + [SyntaxKind.PropertyAssignment]: PropertyAssignment; + [SyntaxKind.ShorthandPropertyAssignment]: ShorthandPropertyAssignment; + [SyntaxKind.SpreadAssignment]: SpreadAssignment; + [SyntaxKind.ObjectBindingPattern]: ObjectBindingPattern; + [SyntaxKind.ArrayBindingPattern]: ArrayBindingPattern; + [SyntaxKind.FunctionDeclaration]: FunctionDeclaration; + [SyntaxKind.MethodSignature]: MethodSignature; + [SyntaxKind.MethodDeclaration]: MethodDeclaration; + [SyntaxKind.Constructor]: ConstructorDeclaration; + [SyntaxKind.SemicolonClassElement]: SemicolonClassElement; + [SyntaxKind.GetAccessor]: GetAccessorDeclaration; + [SyntaxKind.SetAccessor]: SetAccessorDeclaration; + [SyntaxKind.IndexSignature]: IndexSignatureDeclaration; + [SyntaxKind.ClassStaticBlockDeclaration]: ClassStaticBlockDeclaration; + [SyntaxKind.ImportTypeAssertionContainer]: ImportTypeAssertionContainer; + [SyntaxKind.ImportType]: ImportTypeNode; + [SyntaxKind.ThisType]: ThisTypeNode; + [SyntaxKind.FunctionType]: FunctionTypeNode; + [SyntaxKind.ConstructorType]: ConstructorTypeNode; + [SyntaxKind.TypeReference]: TypeReferenceNode; + [SyntaxKind.TypePredicate]: TypePredicateNode; + [SyntaxKind.TypeQuery]: TypeQueryNode; + [SyntaxKind.TypeLiteral]: TypeLiteralNode; + [SyntaxKind.ArrayType]: ArrayTypeNode; + [SyntaxKind.TupleType]: TupleTypeNode; + [SyntaxKind.NamedTupleMember]: NamedTupleMember; + [SyntaxKind.OptionalType]: OptionalTypeNode; + [SyntaxKind.RestType]: RestTypeNode; + [SyntaxKind.UnionType]: UnionTypeNode; + [SyntaxKind.IntersectionType]: IntersectionTypeNode; + [SyntaxKind.ConditionalType]: ConditionalTypeNode; + [SyntaxKind.InferType]: InferTypeNode; + [SyntaxKind.ParenthesizedType]: ParenthesizedTypeNode; + [SyntaxKind.TypeOperator]: TypeOperatorNode; + [SyntaxKind.IndexedAccessType]: IndexedAccessTypeNode; + [SyntaxKind.MappedType]: MappedTypeNode; + [SyntaxKind.LiteralType]: LiteralTypeNode; + [SyntaxKind.TemplateLiteralType]: TemplateLiteralTypeNode; + [SyntaxKind.TemplateLiteralTypeSpan]: TemplateLiteralTypeSpan; + [SyntaxKind.OmittedExpression]: OmittedExpression; + [SyntaxKind.PrefixUnaryExpression]: PrefixUnaryExpression; + [SyntaxKind.PostfixUnaryExpression]: PostfixUnaryExpression; + [SyntaxKind.DeleteExpression]: DeleteExpression; + [SyntaxKind.TypeOfExpression]: TypeOfExpression; + [SyntaxKind.VoidExpression]: VoidExpression; + [SyntaxKind.AwaitExpression]: AwaitExpression; + [SyntaxKind.YieldExpression]: YieldExpression; + [SyntaxKind.BinaryExpression]: BinaryExpression; + [SyntaxKind.ConditionalExpression]: ConditionalExpression; + [SyntaxKind.FunctionExpression]: FunctionExpression; + [SyntaxKind.ArrowFunction]: ArrowFunction; + [SyntaxKind.TemplateExpression]: TemplateExpression; + [SyntaxKind.TemplateSpan]: TemplateSpan; + [SyntaxKind.ParenthesizedExpression]: ParenthesizedExpression; + [SyntaxKind.ArrayLiteralExpression]: ArrayLiteralExpression; + [SyntaxKind.SpreadElement]: SpreadElement; + [SyntaxKind.ObjectLiteralExpression]: ObjectLiteralExpression; + [SyntaxKind.PropertyAccessExpression]: PropertyAccessExpression; + [SyntaxKind.ElementAccessExpression]: ElementAccessExpression; + [SyntaxKind.CallExpression]: CallExpression; + [SyntaxKind.ExpressionWithTypeArguments]: ExpressionWithTypeArguments; + [SyntaxKind.NewExpression]: NewExpression; + [SyntaxKind.TaggedTemplateExpression]: TaggedTemplateExpression; + [SyntaxKind.AsExpression]: AsExpression; + [SyntaxKind.TypeAssertionExpression]: TypeAssertionExpression; + [SyntaxKind.SyntheticExpression]: SyntheticExpression; + [SyntaxKind.SatisfiesExpression]: SatisfiesExpression; + [SyntaxKind.NonNullExpression]: NonNullExpression; + [SyntaxKind.MetaProperty]: MetaProperty; + [SyntaxKind.JsxElement]: JsxElement; + [SyntaxKind.JsxAttributes]: JsxAttributes; + [SyntaxKind.JsxNamespacedName]: JsxNamespacedName; + [SyntaxKind.JsxOpeningElement]: JsxOpeningElement; + [SyntaxKind.JsxSelfClosingElement]: JsxSelfClosingElement; + [SyntaxKind.JsxFragment]: JsxFragment; + [SyntaxKind.JsxOpeningFragment]: JsxOpeningFragment; + [SyntaxKind.JsxClosingFragment]: JsxClosingFragment; + [SyntaxKind.JsxAttribute]: JsxAttribute; + [SyntaxKind.JsxSpreadAttribute]: JsxSpreadAttribute; + [SyntaxKind.JsxClosingElement]: JsxClosingElement; + [SyntaxKind.JsxExpression]: JsxExpression; + [SyntaxKind.EmptyStatement]: EmptyStatement; + [SyntaxKind.DebuggerStatement]: DebuggerStatement; + [SyntaxKind.MissingDeclaration]: MissingDeclaration; + [SyntaxKind.Block]: Block; + [SyntaxKind.VariableStatement]: VariableStatement; + [SyntaxKind.ExpressionStatement]: ExpressionStatement; + [SyntaxKind.IfStatement]: IfStatement; + [SyntaxKind.DoStatement]: DoStatement; + [SyntaxKind.WhileStatement]: WhileStatement; + [SyntaxKind.ForStatement]: ForStatement; + [SyntaxKind.ForInStatement]: ForInStatement; + [SyntaxKind.ForOfStatement]: ForOfStatement; + [SyntaxKind.BreakStatement]: BreakStatement; + [SyntaxKind.ContinueStatement]: ContinueStatement; + [SyntaxKind.ReturnStatement]: ReturnStatement; + [SyntaxKind.WithStatement]: WithStatement; + [SyntaxKind.SwitchStatement]: SwitchStatement; + [SyntaxKind.CaseBlock]: CaseBlock; + [SyntaxKind.CaseClause]: CaseClause; + [SyntaxKind.DefaultClause]: DefaultClause; + [SyntaxKind.LabeledStatement]: LabeledStatement; + [SyntaxKind.ThrowStatement]: ThrowStatement; + [SyntaxKind.TryStatement]: TryStatement; + [SyntaxKind.CatchClause]: CatchClause; + [SyntaxKind.ClassDeclaration]: ClassDeclaration; + [SyntaxKind.ClassExpression]: ClassExpression; + [SyntaxKind.InterfaceDeclaration]: InterfaceDeclaration; + [SyntaxKind.HeritageClause]: HeritageClause; + [SyntaxKind.TypeAliasDeclaration]: TypeAliasDeclaration; + [SyntaxKind.EnumMember]: EnumMember; + [SyntaxKind.EnumDeclaration]: EnumDeclaration; + [SyntaxKind.ModuleDeclaration]: ModuleDeclaration; + [SyntaxKind.ModuleBlock]: ModuleBlock; + [SyntaxKind.ImportEqualsDeclaration]: ImportEqualsDeclaration; + [SyntaxKind.ExternalModuleReference]: ExternalModuleReference; + [SyntaxKind.ImportDeclaration]: ImportDeclaration; + [SyntaxKind.ImportClause]: ImportClause; + [SyntaxKind.ImportAttribute]: ImportAttribute; + [SyntaxKind.ImportAttributes]: ImportAttributes; + [SyntaxKind.NamespaceImport]: NamespaceImport; + [SyntaxKind.NamespaceExport]: NamespaceExport; + [SyntaxKind.NamespaceExportDeclaration]: NamespaceExportDeclaration; + [SyntaxKind.ExportDeclaration]: ExportDeclaration; + [SyntaxKind.NamedImports]: NamedImports; + [SyntaxKind.NamedExports]: NamedExports; + [SyntaxKind.ImportSpecifier]: ImportSpecifier; + [SyntaxKind.ExportSpecifier]: ExportSpecifier; + [SyntaxKind.ExportAssignment]: ExportAssignment; + [SyntaxKind.JSDocTypeExpression]: JSDocTypeExpression; + [SyntaxKind.JSDocNameReference]: JSDocNameReference; + [SyntaxKind.JSDocMemberName]: JSDocMemberName; + [SyntaxKind.JSDocAllType]: JSDocAllType; + [SyntaxKind.JSDocUnknownType]: JSDocUnknownType; + [SyntaxKind.JSDocNonNullableType]: JSDocNonNullableType; + [SyntaxKind.JSDocNullableType]: JSDocNullableType; + [SyntaxKind.JSDocOptionalType]: JSDocOptionalType; + [SyntaxKind.JSDocFunctionType]: JSDocFunctionType; + [SyntaxKind.JSDocVariadicType]: JSDocVariadicType; + [SyntaxKind.JSDocNamepathType]: JSDocNamepathType; + [SyntaxKind.JSDoc]: JSDoc; + [SyntaxKind.JSDocLink]: JSDocLink; + [SyntaxKind.JSDocLinkCode]: JSDocLinkCode; + [SyntaxKind.JSDocLinkPlain]: JSDocLinkPlain; + [SyntaxKind.JSDocText]: JSDocText; + [SyntaxKind.JSDocTag]: JSDocUnknownTag; + [SyntaxKind.JSDocAugmentsTag]: JSDocAugmentsTag; + [SyntaxKind.JSDocImplementsTag]: JSDocImplementsTag; + [SyntaxKind.JSDocAuthorTag]: JSDocAuthorTag; + [SyntaxKind.JSDocDeprecatedTag]: JSDocDeprecatedTag; + [SyntaxKind.JSDocClassTag]: JSDocClassTag; + [SyntaxKind.JSDocPublicTag]: JSDocPublicTag; + [SyntaxKind.JSDocPrivateTag]: JSDocPrivateTag; + [SyntaxKind.JSDocProtectedTag]: JSDocProtectedTag; + [SyntaxKind.JSDocReadonlyTag]: JSDocReadonlyTag; + [SyntaxKind.JSDocOverrideTag]: JSDocOverrideTag; + [SyntaxKind.JSDocEnumTag]: JSDocEnumTag; + [SyntaxKind.JSDocThisTag]: JSDocThisTag; + [SyntaxKind.JSDocTemplateTag]: JSDocTemplateTag; + [SyntaxKind.JSDocSeeTag]: JSDocSeeTag; + [SyntaxKind.JSDocReturnTag]: JSDocReturnTag; + [SyntaxKind.JSDocTypeTag]: JSDocTypeTag; + [SyntaxKind.JSDocTypedefTag]: JSDocTypedefTag; + [SyntaxKind.JSDocCallbackTag]: JSDocCallbackTag; + [SyntaxKind.JSDocOverloadTag]: JSDocOverloadTag; + [SyntaxKind.JSDocThrowsTag]: JSDocThrowsTag; + [SyntaxKind.JSDocSignature]: JSDocSignature; + [SyntaxKind.JSDocPropertyTag]: JSDocPropertyTag; + [SyntaxKind.JSDocParameterTag]: JSDocParameterTag; + [SyntaxKind.JSDocTypeLiteral]: JSDocTypeLiteral; + [SyntaxKind.JSDocSatisfiesTag]: JSDocSatisfiesTag; + [SyntaxKind.JSDocImportTag]: JSDocImportTag; + [SyntaxKind.SourceFile]: SourceFile; + [SyntaxKind.Bundle]: Bundle; + [SyntaxKind.SyntaxList]: SyntaxList; + [SyntaxKind.NotEmittedStatement]: NotEmittedStatement; + [SyntaxKind.NotEmittedTypeElement]: NotEmittedTypeElement; + [SyntaxKind.PartiallyEmittedExpression]: PartiallyEmittedExpression; + [SyntaxKind.CommaListExpression]: CommaListExpression; + /** @internal */ + [SyntaxKind.SyntheticReferenceExpression]: SyntheticReferenceExpression; + [SyntaxKind.Count]: never; + [SyntaxKind.NonTextFileMarkerTrivia]: never; +} + +/** + * The set of all `Node` subtypes. + */ +export type Nodes = NodeMap[keyof NodeMap]; + +type __Expect = never; // eslint-disable-line @typescript-eslint/naming-convention diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index d240c141f3837..24ac27de383a5 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1,4 +1,8 @@ import { + addRange, + addRelatedInfo, + append, + AssertionLevel, AstAccessorDeclaration, AstArrayBindingElement, AstArrayBindingPattern, @@ -17,6 +21,7 @@ import { AstBooleanLiteral, AstBreakOrContinueStatement, AstCallSignatureDeclaration, + astCanHaveModifiers, AstCaseBlock, AstCaseClause, AstCaseOrDefaultClause, @@ -46,6 +51,7 @@ import { AstExpression, AstExpressionStatement, AstExpressionWithTypeArguments, + astForEachChild, AstForInitializer, AstForInOrOfStatement, AstForStatement, @@ -53,6 +59,8 @@ import { AstFunctionExpression, AstFunctionOrConstructorTypeNode, AstHasJSDoc, + astHasJSDocNodes, + AstHasModifiers, AstHeritageClause, AstIdentifier, AstIfStatement, @@ -67,6 +75,7 @@ import { AstInferTypeNode, AstInterfaceDeclaration, AstIterationStatement, + AstJSDoc, AstJSDocAllType, AstJSDocAugmentsTag, AstJSDocAuthorTag, @@ -80,7 +89,6 @@ import { AstJSDocMemberName, AstJSDocNameReference, AstJSDocNamespaceDeclaration, - AstJSDoc, AstJSDocNullableType, AstJSDocOptionalType, AstJSDocOverloadTag, @@ -213,47 +221,8 @@ import { AstWhileStatement, AstWithStatement, AstYieldExpression, - createAstNodeFactory, - astHasJSDocNodes, - isAstAsyncModifier, - isAstDeclareKeyword, - isAstExportModifier, - isAstExpressionWithTypeArguments, - isAstFunctionTypeNode, - isAstIdentifier, - isAstJSDocFunctionType, - isAstJSDocNullableType, - isAstJSDocReturnTag, - isAstJSDocTypeTag, - isAstJsxNamespacedName, - isAstJsxOpeningElement, - isAstJsxOpeningFragment, - isAstLeftHandSideExpression, - isAstNonNullExpression, - isAstPrivateIdentifier, - isAstSetAccessorDeclaration, - isAstStringOrNumericLiteralLike, - isAstTaggedTemplateExpression, - isAstTypeReferenceNode, - astForEachChild, - isAstMetaProperty, - astCanHaveModifiers, - AstHasModifiers, - isAstImportEqualsDeclaration, - isAstImportDeclaration, - isAstExportAssignment, - isAstExportDeclaration, - isAstExternalModuleReference, -} from "./_namespaces/ts.ast.js"; -import { - addRange, - addRelatedInfo, - append, - AssertionLevel, - ast, attachFileToDiagnostics, canHaveJSDoc, - canHaveModifiers, CharacterCodes, CommentDirective, commentPragmas, @@ -261,6 +230,7 @@ import { concatenate, containsParseError, convertToJson, + createAstNodeFactory, createDetachedDiagnostic, createNodeFactory, createScanner, @@ -281,7 +251,6 @@ import { findIndex, firstOrUndefined, forEach, - forEachChild, getAnyExtensionFromPath, getBaseFileName, getBinaryOperatorPrecedence, @@ -292,21 +261,40 @@ import { getLeadingCommentRanges, getSpellingSuggestion, getTextOfNodeFromSourceText, - HasModifiers, identity, isArray, isAssignmentOperator, + isAstAsyncModifier, + isAstDeclareKeyword, + isAstExportAssignment, + isAstExportDeclaration, + isAstExportModifier, + isAstExpressionWithTypeArguments, + isAstExternalModuleReference, + isAstFunctionTypeNode, + isAstIdentifier, + isAstImportDeclaration, + isAstImportEqualsDeclaration, + isAstJSDocFunctionType, + isAstJSDocNullableType, + isAstJSDocReturnTag, + isAstJSDocTypeTag, + isAstJsxNamespacedName, + isAstJsxOpeningElement, + isAstJsxOpeningFragment, + isAstLeftHandSideExpression, + isAstMetaProperty, + isAstNonNullExpression, + isAstPrivateIdentifier, + isAstSetAccessorDeclaration, + isAstStringOrNumericLiteralLike, + isAstTaggedTemplateExpression, + isAstTypeReferenceNode, isClassMemberModifier, - isExportAssignment, - isExportDeclaration, - isExternalModuleReference, isIdentifierText, - isImportDeclaration, - isImportEqualsDeclaration, isKeyword, isKeywordOrPunctuation, isLiteralKind, - isMetaProperty, isModifierKind, isTemplateLiteralKind, JSDoc, @@ -325,7 +313,6 @@ import { ModuleKind, Mutable, Node, - NodeArray, NodeFactory, NodeFactoryFlags, NodeFlags, @@ -411,7 +398,7 @@ export function isFileProbablyExternalModule(sourceFile: SourceFile): Node | und // Try to use the first top-level import/export when available, then // fall back to looking for an 'import.meta' somewhere in the tree if necessary. // TODO(rbuckton): do not instantiate .node - return forEach((sourceFile as AstSourceFile["node"]).ast.data.statements.items, isAnExternalModuleIndicatorNode)?.node || + return forEach(sourceFile.ast.data.statements.items, isAnExternalModuleIndicatorNode)?.node || getImportMetaIfNecessary(sourceFile)?.node; } @@ -425,7 +412,7 @@ function isAnExternalModuleIndicatorNode(node: AstNode) { function getImportMetaIfNecessary(sourceFile: SourceFile) { return sourceFile.flags & NodeFlags.PossiblyContainsImportMeta ? - walkTreeForImportMeta((sourceFile as AstSourceFile["node"]).ast) : + walkTreeForImportMeta(sourceFile.ast) : undefined; } @@ -521,7 +508,7 @@ export function isExternalModule(file: SourceFile): boolean { // becoming detached from any SourceFile). It is recommended that this SourceFile not // be used once 'update' is called on it. export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks = false): SourceFile { - const newSourceFile = IncrementalParser.updateSourceFile((sourceFile as AstSourceFile["node"]).ast, newText, textChangeRange, aggressiveChecks); + const newSourceFile = IncrementalParser.updateSourceFile(sourceFile.ast, newText, textChangeRange, aggressiveChecks); // Because new source file node is created, it may not have the flag PossiblyContainDynamicImport. This is the case if there is no new edit to add dynamic import. // We will manually port the flag to the new source file. newSourceFile.flags |= sourceFile.flags & NodeFlags.PermanentlySetIncrementalFlags; @@ -540,7 +527,7 @@ export function parseIsolatedJSDocComment(content: string, start?: number, lengt if (result && result.jsDoc) { // because the jsDocComment was parsed out of the source file, it might // not be covered by the fixupParentReferences. - Parser.fixupParentReferences((result.jsDoc as AstJSDoc["node"]).ast); + Parser.fixupParentReferences(result.jsDoc.ast); } return result; @@ -9173,7 +9160,7 @@ namespace IncrementalParser { astForEachChild(node, visitNode, visitArray); if (astHasJSDocNodes(node)) { for (const jsDocComment of node.data.jsDoc!) { - visitNode((jsDocComment as AstJSDoc["node"]).ast); // TODO(rbuckton): have JSDocArray store AstJSDoc entries + visitNode(jsDocComment.ast); // TODO(rbuckton): have JSDocArray store AstJSDoc entries } } checkNodePositions(node, aggressiveChecks); @@ -9283,7 +9270,7 @@ namespace IncrementalParser { }; if (astHasJSDocNodes(node)) { for (const jsDocComment of node.data.jsDoc!) { - visitNode((jsDocComment as AstJSDoc["node"]).ast); // TODO(rbuckton): have JSDocArray store AstJSDoc entries + visitNode(jsDocComment.ast); // TODO(rbuckton): have JSDocArray store AstJSDoc entries } } astForEachChild(node, visitNode); @@ -9326,7 +9313,7 @@ namespace IncrementalParser { astForEachChild(child, visitNode, visitArray); if (astHasJSDocNodes(child)) { for (const jsDocComment of child.data.jsDoc!) { - visitNode((jsDocComment as AstJSDoc["node"]).ast); + visitNode(jsDocComment.ast); } } checkNodePositions(child, aggressiveChecks); @@ -9417,7 +9404,7 @@ namespace IncrementalParser { while (true) { const lastChild = getLastChild(node.node); // TODO(rbuckton): do not instantiate .node if (lastChild) { - node = (lastChild as AstNode["node"]).ast; + node = lastChild.ast; } else { return node; @@ -9858,9 +9845,9 @@ function getNamedPragmaArguments(pragma: PragmaDefinition, text: string | undefi } /** @internal */ -export function tagNamesAreEquivalent(lhs: JsxTagNameExpression | ast.AstJsxTagNameExpression, rhs: JsxTagNameExpression | ast.AstJsxTagNameExpression): boolean { - if (!(lhs instanceof AstNode)) lhs = (lhs as AstJsxTagNameExpression["node"]).ast; - if (!(rhs instanceof AstNode)) rhs = (rhs as AstJsxTagNameExpression["node"]).ast; +export function tagNamesAreEquivalent(lhs: JsxTagNameExpression | AstJsxTagNameExpression, rhs: JsxTagNameExpression | AstJsxTagNameExpression): boolean { + if (!(lhs instanceof AstNode)) lhs = lhs.ast; + if (!(rhs instanceof AstNode)) rhs = rhs.ast; if (lhs.kind !== rhs.kind) { return false; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index ad18f43b29e35..d007322d7144a 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -333,6 +333,7 @@ import { WriteFileCallback, WriteFileCallbackData, writeFileEnsuringDirectories, + PartialSourceFile, } from "./_namespaces/ts.js"; import * as performance from "./_namespaces/ts.performance.js"; @@ -888,7 +889,7 @@ export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number, compilerOptions?: CompilerOptions): ResolutionMode { // we ensure all elements of file.imports and file.moduleAugmentations have the relevant parent pointers set during program setup, // so it's safe to use them even pre-bind - return getModeForUsageLocationWorker(file, getModuleNameStringLiteralAt(file, index), compilerOptions); + return getModeForUsageLocationWorker(file as PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, getModuleNameStringLiteralAt(file, index), compilerOptions); } /** @internal */ @@ -944,7 +945,7 @@ export function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLi return getModeForUsageLocationWorker(file, usage, compilerOptions); } -function getModeForUsageLocationWorker(file: Pick, usage: StringLiteralLike, compilerOptions?: CompilerOptions) { +function getModeForUsageLocationWorker(file: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, usage: StringLiteralLike, compilerOptions?: CompilerOptions) { if (isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent) || isJSDocImportTag(usage.parent)) { const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent); if (isTypeOnly) { @@ -966,7 +967,7 @@ function getModeForUsageLocationWorker(file: Pick, usage: StringLiteralLike, compilerOptions?: CompilerOptions): ResolutionMode { +function getEmitSyntaxForUsageLocationWorker(file: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, usage: StringLiteralLike, compilerOptions?: CompilerOptions): ResolutionMode { if (!compilerOptions) { // This should always be provided, but we try to fail somewhat // gracefully to allow projects like ts-node time to update. @@ -5204,7 +5205,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg } } -function shouldTransformImportCallWorker(sourceFile: Pick, options: CompilerOptions): boolean { +function shouldTransformImportCallWorker(sourceFile: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): boolean { const moduleKind = getEmitModuleKind(options); if (ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext || moduleKind === ModuleKind.Preserve) { return false; @@ -5212,11 +5213,11 @@ function shouldTransformImportCallWorker(sourceFile: Pick, options: CompilerOptions): ModuleKind { +export function getEmitModuleFormatOfFileWorker(sourceFile: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ModuleKind { return getImpliedNodeFormatForEmitWorker(sourceFile, options) ?? getEmitModuleKind(options); } /** @internal Prefer `program.getImpliedNodeFormatForEmit` when possible. */ -export function getImpliedNodeFormatForEmitWorker(sourceFile: Pick, options: CompilerOptions): ResolutionMode { +export function getImpliedNodeFormatForEmitWorker(sourceFile: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode { const moduleKind = getEmitModuleKind(options); if (ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext) { return sourceFile.impliedNodeFormat; @@ -5238,7 +5239,7 @@ export function getImpliedNodeFormatForEmitWorker(sourceFile: Pick, options: CompilerOptions): ResolutionMode { +export function getDefaultResolutionModeForFileWorker(sourceFile: PartialSourceFile<"impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode { return importSyntaxAffectsModuleResolution(options) ? getImpliedNodeFormatForEmitWorker(sourceFile, options) : undefined; } diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 7d8bc6f8eab22..5bc306d4eb9ca 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -16,6 +16,7 @@ import { BindingElement, Bundle, CallExpression, + canHaveAsteriskToken, chainBundle, ClassDeclaration, ClassElement, @@ -851,7 +852,7 @@ export function transformClassFields(context: TransformationContext): (x: Source functionName, factory.createFunctionExpression( filter(node.modifiers, (m): m is Modifier => isModifier(m) && !isStaticModifier(m) && !isAccessorModifier(m)), - node.asteriskToken, + tryCast(node, canHaveAsteriskToken)?.asteriskToken, functionName, /*typeParameters*/ undefined, visitParameterList(node.parameters, visitor, context), @@ -3300,7 +3301,7 @@ export function transformClassFields(context: TransformationContext): (x: Source // constructor references in static property initializers. const declaration = resolver.getReferencedValueDeclaration(node); if (declaration) { - const classAlias = classAliases[declaration.id!]; // TODO: GH#18217 + const classAlias = classAliases[declaration.id]; // TODO: GH#18217 if (classAlias) { const clone = factory.cloneNode(classAlias); setSourceMapRange(clone, node); diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index ba19f34fe0af9..a53391fb3d49a 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -10,6 +10,7 @@ import { Bundle, CallSignatureDeclaration, canHaveModifiers, + canHaveName, canProduceDiagnostics, ClassDeclaration, compact, @@ -683,7 +684,7 @@ export function transformDeclarations(context: TransformationContext): Transform return visitNode(type, visitDeclarationSubtree, isTypeNode); } - errorNameNode = node.name; + errorNameNode = canHaveName(node) ? node.name : undefined; let oldDiag: typeof getSymbolAccessibilityDiagnostic; if (!suppressNewDiagnosticContexts) { oldDiag = getSymbolAccessibilityDiagnostic; diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index 7e2978d9c59b8..b90f578f0000e 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -31,6 +31,7 @@ import { getAllAccessorDeclarations, getNameOfDeclaration, getTextOfNode, + hasName, hasSyntacticModifier, ImportEqualsDeclaration, IndexSignatureDeclaration, @@ -733,7 +734,7 @@ export function createGetIsolatedDeclarationErrors(resolver: EmitResolver): (nod function addParentDeclarationRelatedInfo(node: Node, diag: DiagnosticWithLocation) { const parentDeclaration = findNearestDeclaration(node); if (parentDeclaration) { - const targetStr = isExportAssignment(parentDeclaration) || !parentDeclaration.name ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); + const targetStr = isExportAssignment(parentDeclaration) || !hasName(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); } return diag; @@ -791,7 +792,7 @@ export function createGetIsolatedDeclarationErrors(resolver: EmitResolver): (nod const parentDeclaration = findNearestDeclaration(node); let diag: DiagnosticWithLocation; if (parentDeclaration) { - const targetStr = isExportAssignment(parentDeclaration) || !parentDeclaration.name ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); + const targetStr = isExportAssignment(parentDeclaration) || !hasName(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); const parent = findAncestor(node.parent, n => isExportAssignment(n) || (isStatement(n) ? "quit" : !isParenthesizedExpression(n) && !isTypeAssertionExpression(n) && !isAsExpression(n))); if (parentDeclaration === parent) { diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 8d87fa4e255d4..5e55197fd6854 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -17,6 +17,7 @@ import { BreakOrContinueStatement, Bundle, CallExpression, + canHaveAsteriskToken, CaseBlock, CaseClause, cast, @@ -76,6 +77,7 @@ import { getSourceMapRange, getSuperCallFromStatement, getUseDefineForClassFields, + hasName, hasStaticModifier, hasSyntacticModifier, Identifier, @@ -2527,7 +2529,7 @@ export function transformES2015(context: TransformationContext): (x: SourceFile setTextRange( factory.createFunctionExpression( /*modifiers*/ undefined, - node.asteriskToken, + tryCast(node, canHaveAsteriskToken)?.asteriskToken, name, /*typeParameters*/ undefined, parameters, @@ -3318,7 +3320,7 @@ export function transformES2015(context: TransformationContext): (x: SourceFile if ( (property.transformFlags & TransformFlags.ContainsYield && hierarchyFacts & HierarchyFacts.AsyncFunctionBody) - || (hasComputed = Debug.checkDefined(property.name).kind === SyntaxKind.ComputedPropertyName) + || (hasComputed = cast(property, hasName).name.kind === SyntaxKind.ComputedPropertyName) ) { numInitialProperties = i; break; diff --git a/src/compiler/transformers/esDecorators.ts b/src/compiler/transformers/esDecorators.ts index 7609ab957a0c5..e1b2b7c9f0866 100644 --- a/src/compiler/transformers/esDecorators.ts +++ b/src/compiler/transformers/esDecorators.ts @@ -131,7 +131,6 @@ import { Modifier, ModifierFlags, ModifierLike, - ModifiersArray, moveRangePastDecorators, moveRangePastModifiers, Node, @@ -1238,7 +1237,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc >( member: TNode, classInfo: ClassInfo | undefined, - createDescriptor?: (node: TNode & { readonly name: PrivateIdentifier; }, modifiers: ModifiersArray | undefined) => Expression, + createDescriptor?: (node: TNode & { readonly name: PrivateIdentifier; }, modifiers: NodeArray | undefined) => Expression, ) { let referencedName: Expression | undefined; let name: PropertyName | undefined; @@ -2273,7 +2272,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc /** * Creates a `value`, `get`, or `set` method for a pseudo-{@link PropertyDescriptor} object created for a private element. */ - function createDescriptorMethod(original: Node, name: PrivateIdentifier, modifiers: ModifiersArray | undefined, asteriskToken: AsteriskToken | undefined, kind: "value" | "get" | "set", parameters: readonly ParameterDeclaration[], body: Block | undefined) { + function createDescriptorMethod(original: Node, name: PrivateIdentifier, modifiers: NodeArray | undefined, asteriskToken: AsteriskToken | undefined, kind: "value" | "get" | "set", parameters: readonly ParameterDeclaration[], body: Block | undefined) { const func = factory.createFunctionExpression( modifiers, asteriskToken, @@ -2300,7 +2299,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc /** * Creates a pseudo-{@link PropertyDescriptor} object used when decorating a private {@link MethodDeclaration}. */ - function createMethodDescriptorObject(node: PrivateIdentifierMethodDeclaration, modifiers: ModifiersArray | undefined) { + function createMethodDescriptorObject(node: PrivateIdentifierMethodDeclaration, modifiers: NodeArray | undefined) { return factory.createObjectLiteralExpression([ createDescriptorMethod( node, @@ -2317,7 +2316,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc /** * Creates a pseudo-{@link PropertyDescriptor} object used when decorating a private {@link GetAccessorDeclaration}. */ - function createGetAccessorDescriptorObject(node: PrivateIdentifierGetAccessorDeclaration, modifiers: ModifiersArray | undefined) { + function createGetAccessorDescriptorObject(node: PrivateIdentifierGetAccessorDeclaration, modifiers: NodeArray | undefined) { return factory.createObjectLiteralExpression([ createDescriptorMethod( node, @@ -2334,7 +2333,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc /** * Creates a pseudo-{@link PropertyDescriptor} object used when decorating a private {@link SetAccessorDeclaration}. */ - function createSetAccessorDescriptorObject(node: PrivateIdentifierSetAccessorDeclaration, modifiers: ModifiersArray | undefined) { + function createSetAccessorDescriptorObject(node: PrivateIdentifierSetAccessorDeclaration, modifiers: NodeArray | undefined) { return factory.createObjectLiteralExpression([ createDescriptorMethod( node, @@ -2351,7 +2350,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc /** * Creates a pseudo-{@link PropertyDescriptor} object used when decorating an `accessor` {@link PropertyDeclaration} with a private name. */ - function createAccessorPropertyDescriptorObject(node: PrivateIdentifierPropertyDeclaration, modifiers: ModifiersArray | undefined) { + function createAccessorPropertyDescriptorObject(node: PrivateIdentifierPropertyDeclaration, modifiers: NodeArray | undefined) { // { // get() { return this.${privateName}; }, // set(value) { this.${privateName} = value; }, @@ -2406,7 +2405,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc * @param name The name for the resulting declaration. * @param descriptorName The name of the descriptor variable. */ - function createMethodDescriptorForwarder(modifiers: ModifiersArray | undefined, name: PropertyName, descriptorName: Identifier) { + function createMethodDescriptorForwarder(modifiers: NodeArray | undefined, name: PropertyName, descriptorName: Identifier) { // strip off all but the `static` modifier modifiers = visitNodes(modifiers, node => isStaticModifier(node) ? node : undefined, isModifier); return factory.createGetAccessorDeclaration( @@ -2431,7 +2430,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc * @param name The name for the resulting declaration. * @param descriptorName The name of the descriptor variable. */ - function createGetAccessorDescriptorForwarder(modifiers: ModifiersArray | undefined, name: PropertyName, descriptorName: Identifier) { + function createGetAccessorDescriptorForwarder(modifiers: NodeArray | undefined, name: PropertyName, descriptorName: Identifier) { // strip off all but the `static` modifier modifiers = visitNodes(modifiers, node => isStaticModifier(node) ? node : undefined, isModifier); return factory.createGetAccessorDeclaration( @@ -2460,7 +2459,7 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc * @param name The name for the resulting declaration. * @param descriptorName The name of the descriptor variable. */ - function createSetAccessorDescriptorForwarder(modifiers: ModifiersArray | undefined, name: PropertyName, descriptorName: Identifier) { + function createSetAccessorDescriptorForwarder(modifiers: NodeArray | undefined, name: PropertyName, descriptorName: Identifier) { // strip off all but the `static` modifier modifiers = visitNodes(modifiers, node => isStaticModifier(node) ? node : undefined, isModifier); return factory.createSetAccessorDeclaration( diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index 4031cb704665a..302b8e97e1c59 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -34,6 +34,7 @@ import { getNonAssignmentOperatorForCompoundAssignment, getOriginalNode, getOriginalNodeId, + hasAsteriskToken, Identifier, idText, IfStatement, @@ -422,7 +423,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF else if (inGeneratorFunctionBody) { return visitJavaScriptInGeneratorFunctionBody(node); } - else if (isFunctionLikeDeclaration(node) && node.asteriskToken) { + else if (isFunctionLikeDeclaration(node) && hasAsteriskToken(node)) { return visitGenerator(node); } else if (transformFlags & TransformFlags.ContainsGenerator) { diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index bcb0cbf8ee2cc..cd725170807e1 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -314,7 +314,7 @@ export function transformJsx(context: TransformationContext): (x: SourceFile | B function visitJsxOpeningLikeElementJSX(node: JsxOpeningLikeElement, children: readonly JsxChild[] | undefined, isChild: boolean, location: TextRange) { const tagName = getTagName(node); const childrenProp = children && children.length ? convertJsxChildrenToChildrenPropAssignment(children) : undefined; - const keyAttr = find(node.attributes.properties, p => !!p.name && isIdentifier(p.name) && p.name.escapedText === "key") as JsxAttribute | undefined; + const keyAttr = find(node.attributes.properties, p => !isJsxSpreadAttribute(p) && isIdentifier(p.name) && p.name.escapedText === "key") as JsxAttribute | undefined; const attrs = keyAttr ? filter(node.attributes.properties, p => p !== keyAttr) : node.attributes.properties; const objectProperties = length(attrs) ? transformJsxAttributesToObjectProps(attrs, childrenProp) : factory.createObjectLiteralExpression(childrenProp ? [childrenProp] : emptyArray); // When there are no attributes, React wants {} diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 091e5410ed41b..b258399e5f344 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1,20 +1,555 @@ +/* eslint-disable @typescript-eslint/adjacent-overload-signatures */ import { - ast, + AstArrayBindingPattern, + AstArrayBindingPatternData, + AstArrayLiteralExpression, + AstArrayLiteralExpressionData, + AstArrayTypeNode, + AstArrayTypeNodeData, + AstArrowFunction, + AstArrowFunctionData, + AstAsExpression, + AstAsExpressionData, + AstAwaitExpression, + AstAwaitExpressionData, + AstBaseJSDocTag, + AstBigIntLiteral, + AstBigIntLiteralData, + AstBinaryExpression, + AstBinaryExpressionData, + AstBindingElement, + AstBindingElementData, + AstBlock, + AstBlockData, + AstBreakStatement, + AstBreakStatementData, + AstBundle, + AstBundleData, + AstCallChain, + AstCallExpression, + AstCallExpressionData, + AstCallSignatureDeclaration, + AstCallSignatureDeclarationData, + AstCaseBlock, + AstCaseBlockData, + AstCaseClause, + AstCaseClauseData, + AstCatchClause, + AstCatchClauseData, + AstClassDeclaration, + AstClassDeclarationData, + AstClassElement, + AstClassExpression, + AstClassExpressionData, + AstClassStaticBlockDeclaration, + AstClassStaticBlockDeclarationData, + AstCommaListExpression, + AstCommaListExpressionData, + AstComputedPropertyName, + AstComputedPropertyNameData, + AstConditionalExpression, + AstConditionalExpressionData, + AstConditionalTypeNode, + AstConditionalTypeNodeData, + AstConstructorDeclaration, + AstConstructorDeclarationData, + AstConstructorTypeNode, + AstConstructorTypeNodeData, + AstConstructSignatureDeclaration, + AstConstructSignatureDeclarationData, + AstContinueStatement, + AstContinueStatementData, + AstData, + AstDebuggerStatement, + AstDebuggerStatementData, + AstDeclaration, + AstDeclarationData, + AstDecorator, + AstDecoratorData, + AstDefaultClause, + AstDefaultClauseData, + AstDeleteExpression, + AstDeleteExpressionData, + AstDoStatement, + AstDoStatementData, + AstElementAccessChain, + AstElementAccessExpression, + AstElementAccessExpressionData, + AstEmptyStatement, + AstEmptyStatementData, + AstEndOfFileToken, + AstEndOfFileTokenData, + AstEnumDeclaration, + AstEnumDeclarationData, + AstEnumMember, + AstEnumMemberData, + AstExportAssignment, + AstExportAssignmentData, + AstExportDeclaration, + AstExportDeclarationData, + AstExportSpecifier, + AstExportSpecifierData, + AstExpression, + AstExpressionStatement, + AstExpressionStatementData, + AstExpressionWithTypeArguments, + AstExpressionWithTypeArgumentsData, + AstExternalModuleReference, + AstExternalModuleReferenceData, + AstFalseLiteral, + AstForInStatement, + AstForInStatementData, + AstForOfStatement, + AstForOfStatementData, + AstForStatement, + AstForStatementData, + AstFunctionDeclaration, + AstFunctionDeclarationData, + AstFunctionExpression, + AstFunctionExpressionData, + AstFunctionTypeNode, + AstFunctionTypeNodeData, + AstGetAccessorDeclaration, + AstGetAccessorDeclarationData, + AstHeritageClause, + AstHeritageClauseData, + AstIdentifier, + AstIdentifierData, + AstIfStatement, + AstIfStatementData, + AstImportAttribute, + AstImportAttributeData, + AstImportAttributes, + AstImportAttributesData, + AstImportClause, + AstImportClauseData, + AstImportDeclaration, + AstImportDeclarationData, + AstImportEqualsDeclaration, + AstImportEqualsDeclarationData, + AstImportExpression, + AstImportSpecifier, + AstImportSpecifierData, + AstImportTypeAssertionContainer, + AstImportTypeAssertionContainerData, + AstImportTypeNode, + AstImportTypeNodeData, + AstIndexedAccessTypeNode, + AstIndexedAccessTypeNodeData, + AstIndexSignatureDeclaration, + AstIndexSignatureDeclarationData, + AstInferTypeNode, + AstInferTypeNodeData, + AstInterfaceDeclaration, + AstInterfaceDeclarationData, + AstIntersectionTypeNode, + AstIntersectionTypeNodeData, + AstJSDoc, + AstJSDocAllType, + AstJSDocAllTypeData, + AstJSDocAugmentsTag, + AstJSDocAugmentsTagData, + AstJSDocAuthorTag, + AstJSDocAuthorTagData, + AstJSDocCallbackTag, + AstJSDocCallbackTagData, + AstJSDocClassReference, + AstJSDocClassReferenceData, + AstJSDocClassTag, + AstJSDocClassTagData, + AstJSDocData, + AstJSDocDeprecatedTag, + AstJSDocDeprecatedTagData, + AstJSDocEnumTag, + AstJSDocEnumTagData, + AstJSDocFunctionType, + AstJSDocFunctionTypeData, + AstJSDocImplementsTag, + AstJSDocImplementsTagData, + AstJSDocImportTag, + AstJSDocImportTagData, + AstJSDocLink, + AstJSDocLinkCode, + AstJSDocLinkCodeData, + AstJSDocLinkData, + AstJSDocLinkPlain, + AstJSDocLinkPlainData, + AstJSDocMemberName, + AstJSDocMemberNameData, + AstJSDocNamepathType, + AstJSDocNamepathTypeData, + AstJSDocNameReference, + AstJSDocNameReferenceData, + AstJSDocNamespaceDeclaration, + AstJSDocNamespaceDeclarationData, + AstJSDocNonNullableType, + AstJSDocNonNullableTypeData, + AstJSDocNullableType, + AstJSDocNullableTypeData, + AstJSDocOptionalType, + AstJSDocOptionalTypeData, + AstJSDocOverloadTag, + AstJSDocOverloadTagData, + AstJSDocOverrideTag, + AstJSDocOverrideTagData, + AstJSDocParameterTag, + AstJSDocParameterTagData, + AstJSDocPrivateTag, + AstJSDocPrivateTagData, + AstJSDocPropertyLikeTag, + AstJSDocPropertyTag, + AstJSDocPropertyTagData, + AstJSDocProtectedTag, + AstJSDocProtectedTagData, + AstJSDocPublicTag, + AstJSDocPublicTagData, + AstJSDocReadonlyTag, + AstJSDocReadonlyTagData, + AstJSDocReturnTag, + AstJSDocReturnTagData, + AstJSDocSatisfiesTag, + AstJSDocSatisfiesTagData, + AstJSDocSeeTag, + AstJSDocSeeTagData, + AstJSDocSignature, + AstJSDocSignatureData, + AstJSDocTagData, + AstJSDocTemplateTag, + AstJSDocTemplateTagData, + AstJSDocText, + AstJSDocTextData, + AstJSDocThisTag, + AstJSDocThisTagData, + AstJSDocThrowsTag, + AstJSDocThrowsTagData, + AstJSDocTypedefTag, + AstJSDocTypedefTagData, + AstJSDocTypeExpression, + AstJSDocTypeExpressionData, + AstJSDocTypeLiteral, + AstJSDocTypeLiteralData, + AstJSDocTypeTag, + AstJSDocTypeTagData, + AstJSDocUnknownTag, + AstJSDocUnknownTagData, + AstJSDocUnknownType, + AstJSDocUnknownTypeData, + AstJSDocVariadicType, + AstJSDocVariadicTypeData, + AstJsonMinusNumericLiteral, + AstJsonMinusNumericLiteralData, + AstJsonObjectExpressionStatement, + AstJsonObjectExpressionStatementData, + AstJsonSourceFile, + AstJsonSourceFileData, + AstJsxAttribute, + AstJsxAttributeData, + AstJsxAttributes, + AstJsxAttributesData, + AstJsxClosingElement, + AstJsxClosingElementData, + AstJsxClosingFragment, + AstJsxClosingFragmentData, + AstJsxElement, + AstJsxElementData, + AstJsxExpression, + AstJsxExpressionData, + AstJsxFragment, + AstJsxFragmentData, + AstJsxNamespacedName, + AstJsxNamespacedNameData, + AstJsxOpeningElement, + AstJsxOpeningElementData, + AstJsxOpeningFragment, + AstJsxOpeningFragmentData, + AstJsxSelfClosingElement, + AstJsxSelfClosingElementData, + AstJsxSpreadAttribute, + AstJsxSpreadAttributeData, + AstJsxTagNamePropertyAccess, + AstJsxTagNamePropertyAccessData, + AstJsxText, + AstJsxTextData, + AstKeywordExpression, + AstKeywordTypeNode, + AstLabeledStatement, + AstLabeledStatementData, + AstLeftHandSideExpression, + AstLiteralExpression, + AstLiteralExpressionData, + AstLiteralLikeNode, + AstLiteralLikeNodeData, + AstLiteralTypeNode, + AstLiteralTypeNodeData, + AstMappedTypeNode, + AstMappedTypeNodeData, + AstMemberExpression, + AstMetaProperty, + AstMetaPropertyData, + AstMethodDeclaration, + AstMethodDeclarationData, + AstMethodSignature, + AstMethodSignatureData, + AstMissingDeclaration, + AstMissingDeclarationData, + AstModuleBlock, + AstModuleBlockData, + AstModuleDeclaration, + AstModuleDeclarationData, + AstNamedExports, + AstNamedExportsData, + AstNamedImports, + AstNamedImportsData, + AstNamedTupleMember, + AstNamedTupleMemberData, + AstNamespaceDeclaration, + AstNamespaceDeclarationData, + AstNamespaceExport, + AstNamespaceExportData, + AstNamespaceExportDeclaration, + AstNamespaceExportDeclarationData, + AstNamespaceImport, + AstNamespaceImportData, + AstNewExpression, + AstNewExpressionData, + AstNode, + AstNodeArray, + AstNonNullChain, + AstNonNullExpression, + AstNonNullExpressionData, + AstNoSubstitutionTemplateLiteral, + AstNoSubstitutionTemplateLiteralData, + AstNotEmittedStatement, + AstNotEmittedStatementData, + AstNotEmittedTypeElement, + AstNotEmittedTypeElementData, + AstNullLiteral, + AstNumericLiteral, + AstNumericLiteralData, + AstObjectBindingPattern, + AstObjectBindingPatternData, + AstObjectLiteralElement, + AstObjectLiteralExpression, + AstObjectLiteralExpressionData, + AstOmittedExpression, + AstOmittedExpressionData, + AstOptionalTypeNode, + AstOptionalTypeNodeData, + AstParameterDeclaration, + AstParameterDeclarationData, + AstParenthesizedExpression, + AstParenthesizedExpressionData, + AstParenthesizedTypeNode, + AstParenthesizedTypeNodeData, + AstPartiallyEmittedExpression, + AstPartiallyEmittedExpressionData, + AstPostfixUnaryExpression, + AstPostfixUnaryExpressionData, + AstPrefixUnaryExpression, + AstPrefixUnaryExpressionData, + AstPrimaryExpression, + AstPrivateIdentifier, + AstPrivateIdentifierData, + AstPropertyAccessChain, + AstPropertyAccessExpression, + AstPropertyAccessExpressionData, + AstPropertyAssignment, + AstPropertyAssignmentData, + AstPropertyDeclaration, + AstPropertyDeclarationData, + AstPropertySignature, + AstPropertySignatureData, + AstQualifiedName, + AstQualifiedNameData, + AstRegularExpressionLiteral, + AstRegularExpressionLiteralData, + AstRestTypeNode, + AstRestTypeNodeData, + AstReturnStatement, + AstReturnStatementData, + AstSatisfiesExpression, + AstSatisfiesExpressionData, + AstSemicolonClassElement, + AstSemicolonClassElementData, + AstSetAccessorDeclaration, + AstSetAccessorDeclarationData, + AstShorthandPropertyAssignment, + AstShorthandPropertyAssignmentData, + AstSourceFile, + AstSourceFileData, + AstSpreadAssignment, + AstSpreadAssignmentData, + AstSpreadElement, + AstSpreadElementData, + AstStatement, + AstStringLiteral, + AstStringLiteralData, + AstStringLiteralLikeNode, + AstStringLiteralLikeNodeData, + AstSuperExpression, + AstSuperExpressionData, + AstSwitchStatement, + AstSwitchStatementData, + AstSyntaxListData, + AstSyntheticExpression, + AstSyntheticExpressionData, + AstSyntheticReferenceExpression, + AstSyntheticReferenceExpressionData, + AstTaggedTemplateExpression, + AstTaggedTemplateExpressionData, + AstTemplateExpression, + AstTemplateExpressionData, + AstTemplateHead, + AstTemplateHeadData, + AstTemplateLiteralLikeNode, + AstTemplateLiteralLikeNodeData, + AstTemplateLiteralTypeNode, + AstTemplateLiteralTypeNodeData, + AstTemplateLiteralTypeSpan, + AstTemplateLiteralTypeSpanData, + AstTemplateMiddle, + AstTemplateMiddleData, + AstTemplateSpan, + AstTemplateSpanData, + AstTemplateTail, + AstTemplateTailData, + AstThisExpression, + AstThisExpressionData, + AstThisTypeNode, + AstThisTypeNodeData, + AstThrowStatement, + AstThrowStatementData, + AstTokenData, + AstTrueLiteral, + AstTryStatement, + AstTryStatementData, + AstTupleTypeNode, + AstTupleTypeNodeData, + AstTypeAliasDeclaration, + AstTypeAliasDeclarationData, + AstTypeAssertion, + AstTypeAssertionData, + AstTypeElement, + AstTypeLiteralNode, + AstTypeLiteralNodeData, + AstTypeNode, + AstTypeOfExpression, + AstTypeOfExpressionData, + AstTypeOperatorNode, + AstTypeOperatorNodeData, + AstTypeParameterDeclaration, + AstTypeParameterDeclarationData, + AstTypePredicateNode, + AstTypePredicateNodeData, + AstTypeQueryNode, + AstTypeQueryNodeData, + AstTypeReferenceNode, + AstTypeReferenceNodeData, + AstUnaryExpression, + AstUnionTypeNode, + AstUnionTypeNodeData, + AstUpdateExpression, + AstVariableDeclaration, + AstVariableDeclarationData, + AstVariableDeclarationList, + AstVariableDeclarationListData, + AstVariableStatement, + AstVariableStatementData, + AstVoidExpression, + AstVoidExpressionData, + AstWhileStatement, + AstWhileStatementData, + AstWithStatement, + AstWithStatementData, + AstYieldExpression, + AstYieldExpressionData, + AstNodeFactory, + computePositionOfLineAndCharacter, + createChildren, + createMultiMap, CreateSourceFileOptions, + Debug, EmitHelperFactory, + emptyArray, + find, + forEach, + forEachChild, + getAssignmentDeclarationKind, GetCanonicalFileName, + getEffectiveModifierFlagsNoCache, + getEmitFlags, + getLineAndCharacterOfPosition, + getLineStarts, + getNodeChildren, + getNonAssignedNameOfDeclaration, + getParseTreeNode, + getSourceFileOfNode, + getSourceTextOfNodeFromSourceFile, + getTextOfIdentifierOrLiteral, + getTokenPosOfNode, + hasProperty, + hasSyntacticModifier, + idText, + isArrayTypeNode, + isBigIntLiteral, + isBindingPattern, + isCallSignatureDeclaration, + isComputedPropertyName, + isConditionalTypeNode, + isConstructorDeclaration, + isConstructorTypeNode, + isConstructSignatureDeclaration, + isFunctionTypeNode, + isGeneratedIdentifier, + isGetAccessorDeclaration, + isIdentifier, + isImportTypeNode, + isIndexedAccessTypeNode, + isIndexSignatureDeclaration, + isInferTypeNode, + isIntersectionTypeNode, + isLiteralTypeNode, + isMappedTypeNode, + isNamedExports, + isNamedTupleMember, + isNumericLiteral, + isOptionalTypeNode, + isParameter, + isParenthesizedTypeNode, + isParseTreeNode, + isPrivateIdentifier, + isPropertyAccessExpression, + isPropertyName, + isRestTypeNode, + isSetAccessorDeclaration, + isStringLiteral, + isStringOrNumericLiteralLike, + isThisTypeNode, + isTupleTypeNode, + isTypeLiteralNode, + isTypeOperatorNode, + isTypeParameterDeclaration, + isTypePredicateNode, + isTypeQueryNode, + isTypeReferenceNode, + isUnionTypeNode, + lastOrUndefined, MapLike, ModeAwareCache, ModeAwareCacheKey, ModuleResolutionCache, MultiMap, NodeFactoryFlags, + nodeIsSynthesized, OptionsNameMap, PackageJsonInfo, PackageJsonInfoCache, Pattern, + positionIsSynthesized, + setNodeChildren, SymlinkCache, ThisContainer, + updateSourceFile, } from "./_namespaces/ts.js"; // branded string type used to store absolute, normalized and canonicalized paths @@ -693,7 +1228,6 @@ export type KeywordTypeSyntaxKind = | SyntaxKind.UnknownKeyword | SyntaxKind.VoidKeyword; -/** @internal */ export type TypeNodeSyntaxKind = | KeywordTypeSyntaxKind | SyntaxKind.TypePredicate @@ -936,24 +1470,240 @@ export const enum PredicateSemantics { /** @internal */ export type NodeId = number; -export interface Node extends ReadonlyTextRange { - readonly kind: SyntaxKind; - readonly flags: NodeFlags; - /** @internal */ modifierFlagsCache: ModifierFlags; - /** @internal */ readonly transformFlags: TransformFlags; // Flags for transforms - /** @internal */ id?: NodeId | undefined; // Unique id (used to look up NodeLinks) - readonly parent: Node; // Parent node (initialized by binding) - /** @internal */ original?: Node | undefined; // The original node if this is an updated node. - /** @internal */ emitNode?: EmitNode | undefined; // Associated EmitNode (initialized by transforms) - // NOTE: `symbol` and `localSymbol` have been moved to `Declaration` - // `locals` and `nextContainer` have been moved to `LocalsContainer` - // `flowNode` has been moved to `FlowContainer` - // see: https://github.com/microsoft/TypeScript/pull/51682 -} +export type NodeConstructor = new (ast: AstNode>) => N; // TODO: don't use indexed access type + +// dprint-ignore +export class Node< + K extends SyntaxKind = SyntaxKind, + T extends AstData = AstData +> implements ReadonlyTextRange { + readonly ast: AstNode> = undefined!; + + constructor(ast: AstNode>) { + this.ast = ast; + Object.preventExtensions(this); + } + + get kind(): K { return this.ast.kind; } + get data(): T { return this.ast.data; } + get pos(): number { return this.ast.pos; } + get end(): number { return this.ast.end; } + get flags(): NodeFlags { return this.ast.flags; } + get parent(): Node { return this.ast.parent?.node!; } + + /** @internal */ set pos(value) { this.ast.pos = value; } + /** @internal */ set end(value) { this.ast.end = value; } + /** @internal */ set flags(value) { this.ast.flags = value; } + /** @internal */ set parent(value) { this.ast.parent = value?.ast; } + /** @internal */ get modifierFlagsCache(): ModifierFlags { return this.ast.modifierFlagsCache; } + /** @internal */ set modifierFlagsCache(value) { this.ast.modifierFlagsCache = value; } + /** @internal */ get transformFlags(): TransformFlags { return this.ast.transformFlags; } + /** @internal */ set transformFlags(value) { this.ast.transformFlags = value; } + /** @internal */ get id(): number { return this.ast.id; } + /** @internal */ set id(value) { this.ast.id = value; } + /** @internal */ get original(): Node | undefined { return this.ast.original?.node; } + /** @internal */ set original(value) { this.ast.original = value?.ast; } + /** @internal */ get emitNode(): EmitNode | undefined { return this.ast.emitNode; } + /** @internal */ set emitNode(value) { this.ast.emitNode = value; } + /** @internal */ get __pos(): number | undefined { return this.ast.__pos; } // eslint-disable-line @typescript-eslint/naming-convention + /** @internal */ set __pos(value) { this.ast.__pos = value; } // eslint-disable-line @typescript-eslint/naming-convention + /** @internal */ get __end(): number | undefined { return this.ast.__end; } // eslint-disable-line @typescript-eslint/naming-convention + /** @internal */ set __end(value) { this.ast.__end = value; } // eslint-disable-line @typescript-eslint/naming-convention + + /** @internal @private */ _assertHasRealPosition(message?: string): void { + // eslint-disable-next-line local/debug-assert + Debug.assert(!positionIsSynthesized(this.pos) && !positionIsSynthesized(this.end), message || "Node must have a real position for this operation"); + } + + getSourceFile(): SourceFile { + return getSourceFileOfNode(this); + } + + getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number { + this._assertHasRealPosition(); + return getTokenPosOfNode(this, sourceFile, includeJsDocComment); + } + + getFullStart(): number { + this._assertHasRealPosition(); + return this.pos; + } + + getEnd(): number { + this._assertHasRealPosition(); + return this.end; + } + + getWidth(sourceFile?: SourceFileLike): number { + this._assertHasRealPosition(); + return this.getEnd() - this.getStart(sourceFile); + } + + getFullWidth(): number { + this._assertHasRealPosition(); + return this.end - this.pos; + } + + getLeadingTriviaWidth(sourceFile?: SourceFileLike): number { + this._assertHasRealPosition(); + return this.getStart(sourceFile) - this.pos; + } + + getFullText(sourceFile?: SourceFileLike): string { + this._assertHasRealPosition(); + sourceFile ??= this.getSourceFile(); + return sourceFile.text.substring(this.pos, this.end); + } + + getText(sourceFile?: SourceFileLike): string { + this._assertHasRealPosition(); + sourceFile ??= this.getSourceFile(); + return sourceFile.text.substring(this.getStart(sourceFile), this.getEnd()); + } + + getChildCount(sourceFile?: SourceFileLike): number { + return this.getChildren(sourceFile).length; + } + + getChildAt(index: number, sourceFile?: SourceFileLike): Node { + return this.getChildren(sourceFile)[index]; + } + + getChildren(sourceFile?: SourceFileLike): readonly Node[] { + this._assertHasRealPosition("Node without a real position cannot be scanned and thus has no token nodes - use forEachChild and collect the result if that's fine"); + sourceFile ??= this.getSourceFile(); + return getNodeChildren(this, sourceFile) ?? setNodeChildren(this, sourceFile, createChildren(this, sourceFile)); + } + + getFirstToken(sourceFile?: SourceFileLike): Node | undefined { + this._assertHasRealPosition(); + sourceFile ??= this.getSourceFile(); + const children = this.getChildren(sourceFile); + if (!children.length) { + return undefined; + } + + const child = find(children, kid => kid.kind < SyntaxKind.FirstJSDocNode || kid.kind > SyntaxKind.LastJSDocNode); + return !child || child.kind < SyntaxKind.FirstNode ? + child : + child.getFirstToken(sourceFile); + } + + getLastToken(sourceFile?: SourceFileLike): Node | undefined { + this._assertHasRealPosition(); + const children = this.getChildren(sourceFile); + const child = lastOrUndefined(children); + if (!child) { + return undefined; + } + + return child.kind < SyntaxKind.FirstNode ? child : child.getLastToken(sourceFile); + } + + forEachChild(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined { + return forEachChild(this, cbNode, cbNodeArray); + } +} + +Debug.registerDebugInfo(() => { + if (!hasProperty(Node.prototype, "__debugKind")) { + const weakNodeTextMap = new WeakMap(); + + Object.defineProperties(Node.prototype, { + // for use with vscode-js-debug's new customDescriptionGenerator in launch.json + __tsDebuggerDisplay: { + value(this: Node) { // TODO(rbuckton): This is probably no longer needed now that every node has a unique class + const nodeHeader = isGeneratedIdentifier(this) ? "GeneratedIdentifier" : + isIdentifier(this) ? `Identifier '${idText(this)}'` : + isPrivateIdentifier(this) ? `PrivateIdentifier '${idText(this)}'` : + isStringLiteral(this) ? `StringLiteral ${JSON.stringify(this.text.length < 10 ? this.text : this.text.slice(10) + "...")}` : + isNumericLiteral(this) ? `NumericLiteral ${this.text}` : + isBigIntLiteral(this) ? `BigIntLiteral ${this.text}n` : + isTypeParameterDeclaration(this) ? "TypeParameterDeclaration" : + isParameter(this) ? "ParameterDeclaration" : + isConstructorDeclaration(this) ? "ConstructorDeclaration" : + isGetAccessorDeclaration(this) ? "GetAccessorDeclaration" : + isSetAccessorDeclaration(this) ? "SetAccessorDeclaration" : + isCallSignatureDeclaration(this) ? "CallSignatureDeclaration" : + isConstructSignatureDeclaration(this) ? "ConstructSignatureDeclaration" : + isIndexSignatureDeclaration(this) ? "IndexSignatureDeclaration" : + isTypePredicateNode(this) ? "TypePredicateNode" : + isTypeReferenceNode(this) ? "TypeReferenceNode" : + isFunctionTypeNode(this) ? "FunctionTypeNode" : + isConstructorTypeNode(this) ? "ConstructorTypeNode" : + isTypeQueryNode(this) ? "TypeQueryNode" : + isTypeLiteralNode(this) ? "TypeLiteralNode" : + isArrayTypeNode(this) ? "ArrayTypeNode" : + isTupleTypeNode(this) ? "TupleTypeNode" : + isOptionalTypeNode(this) ? "OptionalTypeNode" : + isRestTypeNode(this) ? "RestTypeNode" : + isUnionTypeNode(this) ? "UnionTypeNode" : + isIntersectionTypeNode(this) ? "IntersectionTypeNode" : + isConditionalTypeNode(this) ? "ConditionalTypeNode" : + isInferTypeNode(this) ? "InferTypeNode" : + isParenthesizedTypeNode(this) ? "ParenthesizedTypeNode" : + isThisTypeNode(this) ? "ThisTypeNode" : + isTypeOperatorNode(this) ? "TypeOperatorNode" : + isIndexedAccessTypeNode(this) ? "IndexedAccessTypeNode" : + isMappedTypeNode(this) ? "MappedTypeNode" : + isLiteralTypeNode(this) ? "LiteralTypeNode" : + isNamedTupleMember(this) ? "NamedTupleMember" : + isImportTypeNode(this) ? "ImportTypeNode" : + Debug.formatSyntaxKind(this.kind); + return `${nodeHeader}${this.flags ? ` (${Debug.formatNodeFlags(this.flags)})` : ""}`; + }, + }, + __debugKind: { + get(this: Node) { + return Debug.formatSyntaxKind(this.kind); + }, + }, + __debugNodeFlags: { + get(this: Node) { + return Debug.formatNodeFlags(this.flags); + }, + }, + __debugModifierFlags: { + get(this: Node) { + return Debug.formatModifierFlags(getEffectiveModifierFlagsNoCache(this)); + }, + }, + __debugTransformFlags: { + get(this: Node) { + return Debug.formatTransformFlags(this.transformFlags); + }, + }, + __debugIsParseTreeNode: { + get(this: Node) { + return isParseTreeNode(this); + }, + }, + __debugEmitFlags: { + get(this: Node) { + return Debug.formatEmitFlags(getEmitFlags(this)); + }, + }, + __debugGetText: { + value(this: Node, includeTrivia?: boolean) { + if (nodeIsSynthesized(this)) return ""; + // avoid recomputing + let text = weakNodeTextMap.get(this); + if (text === undefined) { + const parseNode = getParseTreeNode(this); + const sourceFile = parseNode && getSourceFileOfNode(parseNode); + text = sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : ""; + weakNodeTextMap.set(this, text); + } + return text; + }, + }, + }); + } +}); export interface JSDocContainer extends Node { _jsdocContainerBrand: any; - /** @internal */ jsDoc?: JSDocArray | undefined; // JSDoc that directly precedes this node + /** @internal */ jsDoc: JSDocArray | undefined; } /** @internal */ @@ -963,13 +1713,13 @@ export interface JSDocArray extends Array { export interface LocalsContainer extends Node { _localsContainerBrand: any; - /** @internal */ locals?: SymbolTable | undefined; // Locals associated with node (initialized by binding) - /** @internal */ nextContainer?: HasLocals | undefined; // Next container in declaration order (initialized by binding) + /** @internal */ locals: SymbolTable | undefined; // Locals associated with node (initialized by binding) + /** @internal */ nextContainer: HasLocals | undefined; // Next container in declaration order (initialized by binding) } export interface FlowContainer extends Node { _flowContainerBrand: any; - /** @internal */ flowNode?: FlowNode | undefined; // Associated FlowNode (initialized by binding) + /** @internal */ flowNode: FlowNode | undefined; // Associated FlowNode (initialized by binding) } /** @internal */ @@ -1106,7 +1856,7 @@ export type HasChildren = | CallExpression | NewExpression | TaggedTemplateExpression - | TypeAssertion + | TypeAssertionExpression | ParenthesizedExpression | FunctionExpression | ArrowFunction @@ -1583,18 +2333,88 @@ export interface MutableNodeArray extends Array, TextRange { /** @internal */ transformFlags: TransformFlags; // Flags for transforms, possibly undefined } -export interface NodeArray extends ReadonlyArray, ReadonlyTextRange { - readonly hasTrailingComma: boolean; - /** @internal */ transformFlags: TransformFlags; // Flags for transforms, possibly undefined -} +const ReadonlyArray = Array as new (...items: readonly T[]) => readonly T[]; -// TODO(rbuckton): Constraint 'TKind' to 'TokenSyntaxKind' -export interface Token extends Node { - readonly kind: TKind; +// dprint-ignore +export class NodeArray extends ReadonlyArray { + readonly ast: AstNodeArray = undefined!; + + constructor(ast: AstNodeArray) { + super(...ast.items.map(item => item.node as N)); + this.ast = ast; + Object.preventExtensions(this); + } + + static get [globalThis.Symbol.species](): ArrayConstructor { return Array; } + + get pos(): number { return this.ast.pos; } + get end(): number { return this.ast.end; } + get hasTrailingComma(): boolean { return this.ast.hasTrailingComma; } + + /** @internal */ set pos(value) { this.ast.pos = value; } + /** @internal */ set end(value) { this.ast.end = value; } + /** @internal */ set hasTrailingComma(value) { this.ast.hasTrailingComma = value; } + /** @internal */ get transformFlags(): TransformFlags { return this.ast.transformFlags; } + /** @internal */ set transformFlags(value) { this.ast.transformFlags = value; } + /** @internal */ get __pos(): number | undefined { return this.ast.__pos; } // eslint-disable-line @typescript-eslint/naming-convention + /** @internal */ set __pos(value) { this.ast.__pos = value; } // eslint-disable-line @typescript-eslint/naming-convention + /** @internal */ get __end(): number | undefined { return this.ast.__end; } // eslint-disable-line @typescript-eslint/naming-convention + /** @internal */ set __end(value) { this.ast.__end = value; } // eslint-disable-line @typescript-eslint/naming-convention +} + +Debug.registerDebugInfo(() => { + if (!("__tsDebuggerDisplay" in NodeArray.prototype)) { // eslint-disable-line local/no-in-operator + Object.defineProperties(NodeArray.prototype, { + __tsDebuggerDisplay: { + value(this: NodeArray, defaultValue: string) { + // An `Array` with extra properties is rendered as `[A, B, prop1: 1, prop2: 2]`. Most of + // these aren't immediately useful so we trim off the `prop1: ..., prop2: ...` part from the + // formatted string. + // This regex can trigger slow backtracking because of overlapping potential captures. + // We don't care, this is debug code that's only enabled with a debugger attached - + // we're just taking note of it for anyone checking regex performance in the future. + defaultValue = String(defaultValue).replace(/(?:,[\s\w]+:[^,]+)+\]$/, "]"); + return `NodeArray ${defaultValue}`; + }, + }, + }); + } +}); + +// dprint-ignore +export class Token extends Node { + override getChildCount(_sourceFile?: SourceFileLike): number { + return this.getChildren().length; + } + + override getChildAt(index: number, _sourceFile?: SourceFileLike): Node { + return this.getChildren()[index]; + } + + override getChildren(_sourceFile?: SourceFileLike): readonly Node[] { + return this.kind === SyntaxKind.EndOfFileToken ? (this as Node as EndOfFileToken).jsDoc ?? emptyArray : emptyArray; + } + + override getFirstToken(_sourceFile?: SourceFileLike): Node | undefined { + return undefined; + } + + override getLastToken(_sourceFile?: SourceFileLike): Node | undefined { + return undefined; + } + + override forEachChild(_cbNode: (node: Node) => T | undefined, _cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined { + return undefined; + } } -export interface EndOfFileToken extends Token, JSDocContainer { - readonly kind: SyntaxKind.EndOfFileToken; +// dprint-ignore +export class EndOfFileToken extends Token implements JSDocContainer { + declare _jsdocContainerBrand: any; + declare readonly ast: AstEndOfFileToken; + + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } } // Punctuation @@ -1680,6 +2500,11 @@ export type ClassMemberModifier = export type ModifiersArray = NodeArray; +export interface KeywordExpression extends PrimaryExpression, KeywordToken { + readonly ast: AstKeywordExpression; + readonly kind: TKind; +} + // dprint-ignore export const enum GeneratedIdentifierFlags { // Kinds @@ -1697,18 +2522,37 @@ export const enum GeneratedIdentifierFlags { AllowNameSubstitution = 1 << 6, // Used by `module.ts` to indicate generated nodes which can have substitutions performed upon them (as they were generated by an earlier transform phase) } -export interface Identifier extends PrimaryExpression, Declaration, JSDocContainer, FlowContainer { - readonly kind: SyntaxKind.Identifier; - /** - * Prefer to use `id.unescapedText`. (Note: This is available only in services, not internally to the TypeScript compiler.) +// dprint-ignore +export class Identifier extends Token implements PrimaryExpression, Declaration, JSDocContainer, FlowContainer { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstIdentifier; + + /** + * Prefer to use {@link text}. * Text of identifier, but if the identifier begins with two underscores, this will begin with three. */ - readonly escapedText: __String; -} + get escapedText(): __String { return this.ast.data.escapedText; } + get text(): string { return idText(this); } -// Transient identifier node (marked by id === -1) -export interface TransientIdentifier extends Identifier { - resolvedSymbol: Symbol; + /** @internal */ set escapedText(value: __String) { this.ast.data.escapedText = value; } + /** @internal */ get resolvedSymbol(): Symbol { return this.ast.data.resolvedSymbol; } + /** @internal */ set resolvedSymbol(value: Symbol) { this.ast.data.resolvedSymbol = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value) { this.ast.data.flowNode = value; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value) { this.ast.data.jsDoc = value; } } // dprint-ignore @@ -1725,10 +2569,18 @@ export interface GeneratedIdentifier extends Identifier { readonly emitNode: EmitNode & { autoGenerate: AutoGenerateInfo; }; } -export interface QualifiedName extends Node, FlowContainer { - readonly kind: SyntaxKind.QualifiedName; - readonly left: EntityName; - readonly right: Identifier; +// dprint-ignore +export class QualifiedName extends Node implements FlowContainer { + declare _flowContainerBrand: any; + declare readonly ast: AstQualifiedName; + + get left(): EntityName { return this.ast.data.left?.node; } + get right(): Identifier { return this.ast.data.right?.node; } + + /** @internal */ set left(value: EntityName) { this.ast.data.left = value?.ast; } + /** @internal */ set right(value: Identifier) { this.ast.data.right = value?.ast; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value) { this.ast.data.flowNode = value; } } export type EntityName = Identifier | QualifiedName; @@ -1754,14 +2606,64 @@ export type DeclarationName = export interface Declaration extends Node { _declarationBrand: any; + readonly ast: AstDeclaration; /** @internal */ symbol: Symbol; // Symbol declared by node (initialized by binding) - /** @internal */ localSymbol?: Symbol | undefined; // Local symbol declared by node (initialized by binding only for exported nodes) + /** @internal */ localSymbol: Symbol | undefined; // Local symbol declared by node (initialized by binding only for exported nodes) } export interface NamedDeclaration extends Declaration { readonly name?: DeclarationName | undefined; } +// NOTE: Changing the following list requires changes to: +// - `canHaveName` in utilitiesPublic.ts +/** @internal */ +export type HasName = + | FunctionDeclaration + | FunctionExpression + | ClassExpression + | ClassDeclaration + | MethodDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration + | PropertyDeclaration + | InterfaceDeclaration + | MethodSignature + | PropertySignature + | TypeAliasDeclaration + | EnumDeclaration + | EnumMember + | ModuleDeclaration + | VariableDeclaration + | ParameterDeclaration + | BindingElement + | TypeParameterDeclaration + | ImportEqualsDeclaration + | NamespaceExportDeclaration + | ImportClause + | NamespaceImport + | NamespaceExport + | ImportSpecifier + | ExportSpecifier + | JSDocTypedefTag + | JSDocCallbackTag + | PropertyAssignment + | ShorthandPropertyAssignment + | NamedTupleMember + | PropertyAccessExpression + | MetaProperty + | ImportAttribute + | JsxAttribute + | JsxNamespacedName + | JSDocNameReference + | JSDocLink + | JSDocLinkCode + | JSDocLinkPlain + | JSDocParameterTag + | JSDocSeeTag + | JSDocPropertyTag + | MissingDeclaration; + /** @internal */ export interface DynamicNamedDeclaration extends NamedDeclaration { readonly name: ComputedPropertyName; @@ -1789,21 +2691,37 @@ export interface LateBoundElementAccessExpression extends ElementAccessExpressio } export interface DeclarationStatement extends NamedDeclaration, Statement { + readonly ast: AstNode; readonly name?: Identifier | StringLiteral | NumericLiteral | undefined; } -export interface ComputedPropertyName extends Node { - readonly kind: SyntaxKind.ComputedPropertyName; - readonly parent: Declaration; - readonly expression: Expression; +// dprint-ignore +export class ComputedPropertyName extends Node { + declare readonly ast: AstComputedPropertyName; + + override get parent(): Declaration { return super.parent as Declaration; } + + get expression(): Expression { return this.ast.data.expression.node; } + + /** @internal */ override set parent(value: Declaration) { super.parent = value; } + /** @internal */ set expression(value: Expression) { this.ast.data.expression = value.ast; } } // Typed as a PrimaryExpression due to its presence in BinaryExpressions (#field in expr) -export interface PrivateIdentifier extends PrimaryExpression { - readonly kind: SyntaxKind.PrivateIdentifier; - // escaping not strictly necessary - // avoids gotchas in transforms and utils - readonly escapedText: __String; +// dprint-ignore +export class PrivateIdentifier extends Token { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstPrivateIdentifier; + + get escapedText(): __String { return this.ast.data.escapedText; } + get text(): string { return idText(this); } + + /** @internal */ set escapedText(value: __String) { this.ast.data.escapedText = value; } } /** @internal */ @@ -1817,26 +2735,51 @@ export interface LateBoundName extends ComputedPropertyName { readonly expression: EntityNameExpression; } -export interface Decorator extends Node { - readonly kind: SyntaxKind.Decorator; - readonly parent: NamedDeclaration; - readonly expression: LeftHandSideExpression; +// dprint-ignore +export class Decorator extends Node { + declare readonly ast: AstDecorator; + + override get parent(): Declaration { return super.parent as Declaration; } + + get expression(): LeftHandSideExpression { return this.ast.data.expression.node; } + + /** @internal */ override set parent(value: Declaration) { super.parent = value; } + /** @internal */ set expression(value: LeftHandSideExpression) { this.ast.data.expression = value.ast; } } -export interface TypeParameterDeclaration extends NamedDeclaration, JSDocContainer { - readonly kind: SyntaxKind.TypeParameter; - readonly parent: DeclarationWithTypeParameterChildren | InferTypeNode; - readonly modifiers?: NodeArray | undefined; - readonly name: Identifier; - /** Note: Consider calling `getEffectiveConstraintOfTypeParameter` */ - readonly constraint?: TypeNode | undefined; - readonly default?: TypeNode | undefined; +// dprint-ignore +export class TypeParameterDeclaration extends Node implements Declaration, JSDocContainer { + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstTypeParameterDeclaration; + + override get parent(): DeclarationWithTypeParameterChildren | InferTypeNode { return super.parent as DeclarationWithTypeParameterChildren | InferTypeNode; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): Identifier { return this.ast.data.name.node; } + /** + * NOTE: Consider calling `getEffectiveConstraintOfTypeParameter` + */ + get constraint(): TypeNode | undefined { return this.ast.data.constraint?.node; } + get default(): TypeNode | undefined { return this.ast.data.default?.node; } - // For error recovery purposes (see `isGrammarError` in utilities.ts). - expression?: Expression | undefined; + /** @internal */ override set parent(value: DeclarationWithTypeParameterChildren | InferTypeNode) { super.parent = value; } + /** @internal */ set modifiers(value: NodeArray | undefined) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value: Identifier) { this.ast.data.name = value.ast; } + /** @internal */ set constraint(value: TypeNode | undefined) { this.ast.data.constraint = value?.ast; } + /** @internal */ set default(value: TypeNode | undefined) { this.ast.data.default = value?.ast; } + /** @internal */ get expression(): Expression | undefined { return this.ast.data.expression?.node; } + /** @internal */ set expression(value: Expression | undefined) { this.ast.data.expression = value?.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value) { this.ast.data.jsDoc = value; } } export interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { + readonly ast: AstNode; readonly kind: SignatureDeclaration["kind"]; readonly name?: PropertyName | undefined; readonly typeParameters?: NodeArray | undefined; @@ -1860,84 +2803,268 @@ export type SignatureDeclaration = | FunctionExpression | ArrowFunction; -export interface CallSignatureDeclaration extends SignatureDeclarationBase, TypeElement, LocalsContainer { - readonly kind: SyntaxKind.CallSignature; +// dprint-ignore +export class CallSignatureDeclaration extends Node implements SignatureDeclarationBase, TypeElement, LocalsContainer { + declare _signatureDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _typeElementBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstCallSignatureDeclaration; + + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } -export interface ConstructSignatureDeclaration extends SignatureDeclarationBase, TypeElement, LocalsContainer { - readonly kind: SyntaxKind.ConstructSignature; +// dprint-ignore +export class ConstructSignatureDeclaration extends Node implements SignatureDeclarationBase, TypeElement, LocalsContainer { + declare _signatureDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _typeElementBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstConstructSignatureDeclaration; + + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } export type BindingName = Identifier | BindingPattern; // dprint-ignore -export interface VariableDeclaration extends NamedDeclaration, JSDocContainer { - readonly kind: SyntaxKind.VariableDeclaration; - readonly parent: VariableDeclarationList | CatchClause; - readonly name: BindingName; // Declared variable name - readonly exclamationToken?: ExclamationToken | undefined; // Optional definite assignment assertion - readonly type?: TypeNode | undefined; // Optional type annotation - readonly initializer?: Expression | undefined; // Optional initializer +export class VariableDeclaration extends Node implements Declaration, JSDocContainer { + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstVariableDeclaration; + + override get parent() { return super.parent as VariableDeclarationList | CatchClause; } + + /** + * Declared variable name + */ + get name(): BindingName { return this.ast.data.name.node; } + /** + * Optional definite assignment assertion + */ + get exclamationToken(): ExclamationToken | undefined { return this.ast.data.exclamationToken?.node; } + /** + * Optional type annotation + */ + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + /** + * Optional initializer + */ + get initializer(): Expression | undefined { return this.ast.data.initializer?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set name(value: BindingName) { this.ast.data.name = value.ast; } + /** @internal */ set exclamationToken(value: ExclamationToken | undefined) { this.ast.data.exclamationToken = value?.ast; } + /** @internal */ set type(value: TypeNode | undefined) { this.ast.data.type = value?.ast; } + /** @internal */ set initializer(value: Expression | undefined) { this.ast.data.initializer = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } + /** @internal */ export type InitializedVariableDeclaration = VariableDeclaration & { readonly initializer: Expression; }; -export interface VariableDeclarationList extends Node { - readonly kind: SyntaxKind.VariableDeclarationList; - readonly parent: VariableStatement | ForStatement | ForOfStatement | ForInStatement; - readonly declarations: NodeArray; +// dprint-ignore +export class VariableDeclarationList extends Node { + declare readonly ast: AstVariableDeclarationList; + + override get parent() { return super.parent as VariableStatement | ForStatement | ForOfStatement | ForInStatement; } + + get declarations(): NodeArray { return this.ast.data.declarations.nodes; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set declarations(value) { this.ast.data.declarations = value.ast; } } // dprint-ignore -export interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { - readonly kind: SyntaxKind.Parameter; - readonly parent: SignatureDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly dotDotDotToken?: DotDotDotToken | undefined; // Present on rest parameter +export class ParameterDeclaration extends Node implements Declaration, JSDocContainer { + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstParameterDeclaration; + + override get parent(): SignatureDeclaration { return super.parent as SignatureDeclaration; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get dotDotDotToken(): DotDotDotToken | undefined { return this.ast.data.dotDotDotToken?.node; } + // TODO(rbuckton): `name` can be undefined for JSDoc signature parameters + get name(): BindingName { return this.ast.data.name?.node; } + get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + get initializer(): Expression | undefined { return this.ast.data.initializer?.node; } + + /** @internal */ override set parent(value: SignatureDeclaration) { super.parent = value; } + /** @internal */ set modifiers(value: NodeArray | undefined) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set dotDotDotToken(value: DotDotDotToken | undefined) { this.ast.data.dotDotDotToken = value?.ast; } // TODO(rbuckton): `name` can be undefined for JSDoc signature parameters - readonly name: BindingName; // Declared parameter name. - readonly questionToken?: QuestionToken | undefined; // Present on optional parameter - readonly type?: TypeNode | undefined; // Optional type annotation - readonly initializer?: Expression | undefined; // Optional initializer + /** @internal */ set name(value: BindingName) { this.ast.data.name = value?.ast; } + /** @internal */ set questionToken(value: QuestionToken | undefined) { this.ast.data.questionToken = value?.ast; } + /** @internal */ set type(value: TypeNode | undefined) { this.ast.data.type = value?.ast; } + /** @internal */ set initializer(value: Expression | undefined) { this.ast.data.initializer = value?.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value) { this.ast.data.jsDoc = value; } } // dprint-ignore -export interface BindingElement extends NamedDeclaration, FlowContainer { - readonly kind: SyntaxKind.BindingElement; - readonly parent: BindingPattern; - readonly propertyName?: PropertyName | undefined; // Binding property name (in object binding pattern) - readonly dotDotDotToken?: DotDotDotToken | undefined; // Present on rest element (in object binding pattern) - readonly name: BindingName; // Declared binding element name - readonly initializer?: Expression | undefined; // Optional initializer +export class BindingElement extends Node implements Declaration, FlowContainer { + declare _declarationBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstBindingElement; + + override get parent() { return super.parent as BindingPattern; } + + /** + * Binding property name (in object binding pattern) + */ + get propertyName(): PropertyName | undefined { return this.ast.data.propertyName?.node; } + /** + * Present on rest element (in object binding pattern) + */ + get dotDotDotToken(): DotDotDotToken | undefined { return this.ast.data.dotDotDotToken?.node; } + /** + * Declared binding element name + */ + get name(): BindingName { return this.ast.data.name.node; } + /** + * Optional initializer + */ + get initializer(): Expression | undefined { return this.ast.data.initializer?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set propertyName(value) { this.ast.data.propertyName = value?.ast; } + /** @internal */ set dotDotDotToken(value) { this.ast.data.dotDotDotToken = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set initializer(value) { this.ast.data.initializer = value?.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } /** @internal */ export type BindingElementGrandparent = BindingElement["parent"]["parent"]; // dprint-ignore -export interface PropertySignature extends TypeElement, JSDocContainer { - readonly kind: SyntaxKind.PropertySignature; - readonly parent: TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: PropertyName; // Declared property name - readonly questionToken?: QuestionToken | undefined; // Present on optional property - readonly type?: TypeNode | undefined; // Optional type annotation +export class PropertySignature extends Node implements TypeElement, JSDocContainer { + declare _typeElementBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstPropertySignature; + + override get parent() { return super.parent as TypeLiteralNode | InterfaceDeclaration; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + /** + * Declared property name + */ + get name(): PropertyName { return this.ast.data.name.node; } + /** + * Present on optional property + */ + get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } + /** + * Optional type annotation + */ + get type(): TypeNode | undefined { return this.ast.data.type?.node; } - // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) - /** @internal */ readonly initializer?: Expression | undefined; // A property signature cannot have an initializer + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value: NodeArray | undefined) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set questionToken(value) { this.ast.data.questionToken = value?.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ get initializer(): Expression | undefined { return this.ast.data.initializer?.node; } + /** @internal */ set initializer(value) { this.ast.data.initializer = value?.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } } // dprint-ignore -export interface PropertyDeclaration extends ClassElement, JSDocContainer { - readonly kind: SyntaxKind.PropertyDeclaration; - readonly parent: ClassLikeDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: PropertyName; - readonly questionToken?: QuestionToken | undefined; // Present for use with reporting a grammar error for auto-accessors (see `isGrammarError` in utilities.ts) - readonly exclamationToken?: ExclamationToken | undefined; - readonly type?: TypeNode | undefined; - readonly initializer?: Expression | undefined; // Optional initializer +export class PropertyDeclaration extends Node implements ClassElement, JSDocContainer { + declare _classElementBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstPropertyDeclaration; + + override get parent() { return super.parent as ClassLikeDeclaration; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): PropertyName { return this.ast.data.name.node; } + /** + * Optional field. Disallowed for auto-accessors and only used to report a grammar error (see `isGrammarError` in utilities.ts) + */ + get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } + get exclamationToken(): ExclamationToken | undefined { return this.ast.data.exclamationToken?.node; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + /** + * Optional initializer + */ + get initializer(): Expression | undefined { return this.ast.data.initializer?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set questionToken(value) { this.ast.data.questionToken = value?.ast; } + /** @internal */ set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ set initializer(value) { this.ast.data.initializer = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export interface AutoAccessorPropertyDeclaration extends PropertyDeclaration { @@ -1979,6 +3106,9 @@ export type InitializedPropertyDeclaration = PropertyDeclaration & { readonly in export interface ObjectLiteralElement extends NamedDeclaration { _objectLiteralBrand: any; + readonly ast: AstObjectLiteralElement; + + // TODO(rbuckton): remove this? readonly name?: PropertyName | undefined; } @@ -1990,37 +3120,85 @@ export type ObjectLiteralElementLike = | MethodDeclaration | AccessorDeclaration; -export interface PropertyAssignment extends ObjectLiteralElement, JSDocContainer { - readonly kind: SyntaxKind.PropertyAssignment; - readonly parent: ObjectLiteralExpression; - readonly name: PropertyName; - readonly initializer: Expression; +// dprint-ignore +export class PropertyAssignment extends Node implements ObjectLiteralElement, Declaration, JSDocContainer { + declare _objectLiteralBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstPropertyAssignment; + + override get parent() { return super.parent as ObjectLiteralExpression; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): PropertyName { return this.ast.data.name.node; } + get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } + get exclamationToken(): ExclamationToken | undefined { return this.ast.data.exclamationToken?.node; } + get initializer(): Expression { return this.ast.data.initializer.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set questionToken(value) { this.ast.data.questionToken = value?.ast; } + /** @internal */ set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } + /** @internal */ set initializer(value) { this.ast.data.initializer = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } +} - // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) - /** @internal */ readonly modifiers?: NodeArray | undefined; // property assignment cannot have decorators or modifiers - /** @internal */ readonly questionToken?: QuestionToken | undefined; // property assignment cannot have a question token - /** @internal */ readonly exclamationToken?: ExclamationToken | undefined; // property assignment cannot have an exclamation token +// dprint-ignore +export class ShorthandPropertyAssignment extends Node implements ObjectLiteralElement, Declaration, JSDocContainer { + declare _objectLiteralBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstShorthandPropertyAssignment; + + override get parent() { return super.parent as ObjectLiteralExpression; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): Identifier { return this.ast.data.name.node; } + get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } + get exclamationToken(): ExclamationToken | undefined { return this.ast.data.exclamationToken?.node; } + get equalsToken(): EqualsToken | undefined { return this.ast.data.equalsToken?.node; } + get objectAssignmentInitializer(): Expression | undefined { return this.ast.data.objectAssignmentInitializer?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set questionToken(value) { this.ast.data.questionToken = value?.ast; } + /** @internal */ set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } + /** @internal */ set equalsToken(value) { this.ast.data.equalsToken = value?.ast; } + /** @internal */ set objectAssignmentInitializer(value) { this.ast.data.objectAssignmentInitializer = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface ShorthandPropertyAssignment extends ObjectLiteralElement, JSDocContainer { - readonly kind: SyntaxKind.ShorthandPropertyAssignment; - readonly parent: ObjectLiteralExpression; - readonly name: Identifier; - // used when ObjectLiteralExpression is used in ObjectAssignmentPattern - // it is a grammar error to appear in actual object initializer (see `isGrammarError` in utilities.ts): - readonly equalsToken?: EqualsToken | undefined; - readonly objectAssignmentInitializer?: Expression | undefined; +// dprint-ignore +export class SpreadAssignment extends Node implements ObjectLiteralElement, JSDocContainer { + declare _objectLiteralBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstSpreadAssignment; - // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) - /** @internal */ readonly modifiers?: NodeArray | undefined; // shorthand property assignment cannot have decorators or modifiers - /** @internal */ readonly questionToken?: QuestionToken | undefined; // shorthand property assignment cannot have a question token - /** @internal */ readonly exclamationToken?: ExclamationToken | undefined; // shorthand property assignment cannot have an exclamation token -} + override get parent() { return super.parent as ObjectLiteralExpression; } + + get expression(): Expression { return this.ast.data.expression.node; } -export interface SpreadAssignment extends ObjectLiteralElement, JSDocContainer { - readonly kind: SyntaxKind.SpreadAssignment; - readonly parent: ObjectLiteralExpression; - readonly expression: Expression; + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export type VariableLikeDeclaration = @@ -2036,16 +3214,28 @@ export type VariableLikeDeclaration = | JSDocPropertyTag | JSDocParameterTag; -export interface ObjectBindingPattern extends Node { - readonly kind: SyntaxKind.ObjectBindingPattern; - readonly parent: VariableDeclaration | ParameterDeclaration | BindingElement; - readonly elements: NodeArray; +// dprint-ignore +export class ObjectBindingPattern extends Node { + declare readonly ast: AstObjectBindingPattern; + + override get parent() { return super.parent as VariableDeclaration | ParameterDeclaration | BindingElement; } + + get elements(): NodeArray { return this.ast.data.elements.nodes; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set elements(value) { this.ast.data.elements = value.ast; } } -export interface ArrayBindingPattern extends Node { - readonly kind: SyntaxKind.ArrayBindingPattern; - readonly parent: VariableDeclaration | ParameterDeclaration | BindingElement; - readonly elements: NodeArray; +// dprint-ignore +export class ArrayBindingPattern extends Node { + declare readonly ast: AstArrayBindingPattern; + + override get parent() { return super.parent as VariableDeclaration | ParameterDeclaration | BindingElement; } + + get elements(): NodeArray { return this.ast.data.elements.nodes; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set elements(value) { this.ast.data.elements = value.ast; } } export type BindingPattern = ObjectBindingPattern | ArrayBindingPattern; @@ -2079,21 +3269,115 @@ export type FunctionLikeDeclaration = | ConstructorDeclaration | FunctionExpression | ArrowFunction; + /** @deprecated Use SignatureDeclaration */ export type FunctionLike = SignatureDeclaration; -export interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement, LocalsContainer { - readonly kind: SyntaxKind.FunctionDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name?: Identifier | undefined; - readonly body?: FunctionBody | undefined; +// NOTE: Changing the following list requires changes to: +// - `canHaveQuestionToken` in utilitiesPublic.ts +/** @internal */ +export type HasQuestionToken = + | ParameterDeclaration + | PropertySignature + | PropertyDeclaration + | MethodSignature + | MethodDeclaration + | ShorthandPropertyAssignment + | MappedTypeNode + | NamedTupleMember + | ConditionalExpression + | PropertyAssignment; + +// NOTE: Changing the following list requires changes to: +// - `canHaveAsteriskToken` in utilitiesPublic.ts +/** @internal */ +export type HasAsteriskToken = + | FunctionDeclaration + | FunctionExpression + | MethodDeclaration + | YieldExpression; + +// dprint-ignore +export class FunctionDeclaration extends Node implements FunctionLikeDeclarationBase, DeclarationStatement, LocalsContainer { + declare _functionLikeDeclarationBrand: any; + declare _signatureDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _statementBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstFunctionDeclaration; + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get asteriskToken(): AsteriskToken | undefined { return this.ast.data.asteriskToken?.node; } + get name(): Identifier | undefined { return this.ast.data.name?.node; } + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + get body(): Block | undefined { return this.ast.data.body?.node; } + + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value?.ast; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ set body(value) { this.ast.data.body = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + /** @internal */ get endFlowNode(): FlowNode | undefined { return this.ast.data.endFlowNode; } + /** @internal */ set endFlowNode(value) { this.ast.data.endFlowNode = value; } + /** @internal */ get returnFlowNode(): FlowNode | undefined { return this.ast.data.returnFlowNode; } + /** @internal */ set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } } -export interface MethodSignature extends SignatureDeclarationBase, TypeElement, LocalsContainer { - readonly kind: SyntaxKind.MethodSignature; - readonly parent: TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: PropertyName; + +// dprint-ignore +export class MethodSignature extends Node implements SignatureDeclarationBase, TypeElement, LocalsContainer { + declare _signatureDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _typeElementBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstMethodSignature; + + override get parent() { return super.parent as TypeLiteralNode | InterfaceDeclaration; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): PropertyName { return this.ast.data.name.node; } + get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set questionToken(value) { this.ast.data.questionToken = value?.ast; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } // Note that a MethodDeclaration is considered both a ClassElement and an ObjectLiteralElement. @@ -2105,136 +3389,422 @@ export interface MethodSignature extends SignatureDeclarationBase, TypeElement, // Because of this, it may be necessary to determine what sort of MethodDeclaration you have // at later stages of the compiler pipeline. In that case, you can either check the parent kind // of the method, or use helpers like isObjectLiteralMethodDeclaration -export interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.MethodDeclaration; - readonly parent: ClassLikeDeclaration | ObjectLiteralExpression; - readonly modifiers?: NodeArray | undefined; - readonly name: PropertyName; - readonly body?: FunctionBody | undefined; - - // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) - /** @internal */ readonly exclamationToken?: ExclamationToken | undefined; // A method cannot have an exclamation token +// dprint-ignore +export class MethodDeclaration extends Node implements FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, LocalsContainer, FlowContainer { + declare _functionLikeDeclarationBrand: any; + declare _signatureDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _classElementBrand: any; + declare _objectLiteralBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstMethodDeclaration; + + override get parent() { return super.parent as ClassLikeDeclaration | ObjectLiteralExpression; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get asteriskToken(): AsteriskToken | undefined { return this.ast.data.asteriskToken?.node; } + get name(): PropertyName { return this.ast.data.name.node; } + get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + get body(): Block | undefined { return this.ast.data.body?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set questionToken(value) { this.ast.data.questionToken = value?.ast; } + /** + * used only to report grammar errors (see `isGrammarError` in utilities.ts) + * @internal + */ + get exclamationToken(): ExclamationToken | undefined { return this.ast.data.exclamationToken?.node; } + /** @internal */ set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ set body(value) { this.ast.data.body = value?.ast; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } + /** @internal */ get endFlowNode(): FlowNode | undefined { return this.ast.data.endFlowNode; } + /** @internal */ set endFlowNode(value) { this.ast.data.endFlowNode = value; } + /** @internal */ get returnFlowNode(): FlowNode | undefined { return this.ast.data.returnFlowNode; } + /** @internal */ set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } } -export interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElement, JSDocContainer, LocalsContainer { - readonly kind: SyntaxKind.Constructor; - readonly parent: ClassLikeDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly body?: FunctionBody | undefined; - - // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) - /** @internal */ readonly typeParameters?: NodeArray | undefined; // A constructor cannot have type parameters - /** @internal */ readonly type?: TypeNode | undefined; // A constructor cannot have a return type annotation +// dprint-ignore +export class ConstructorDeclaration extends Node implements FunctionLikeDeclarationBase, ClassElement, JSDocContainer, LocalsContainer { + declare _functionLikeDeclarationBrand: any; + declare _signatureDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _classElementBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstConstructorDeclaration; + + override get parent() { return super.parent as ClassLikeDeclaration; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get body(): Block | undefined { return this.ast.data.body?.node; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set body(value) { this.ast.data.body = value?.ast; } + /** @internal */ get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ get type(): TypeNode | undefined { return this.ast.data.type?.node; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + /** @internal */ get endFlowNode(): FlowNode | undefined { return this.ast.data.endFlowNode; } + /** @internal */ set endFlowNode(value) { this.ast.data.endFlowNode = value; } + /** @internal */ get returnFlowNode(): FlowNode | undefined { return this.ast.data.returnFlowNode; } + /** @internal */ set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } } /** For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. */ -export interface SemicolonClassElement extends ClassElement, JSDocContainer { - readonly kind: SyntaxKind.SemicolonClassElement; - readonly parent: ClassLikeDeclaration; +// dprint-ignore +export class SemicolonClassElement extends Node implements ClassElement, JSDocContainer { + declare _classElementBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare symbol: never; + declare localSymbol: never; + declare readonly ast: AstSemicolonClassElement; + + override get parent() { return super.parent as ClassLikeDeclaration; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } } // See the comment on MethodDeclaration for the intuition behind GetAccessorDeclaration being a // ClassElement and an ObjectLiteralElement. -export interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.GetAccessor; - readonly parent: ClassLikeDeclaration | ObjectLiteralExpression | TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: PropertyName; - readonly body?: FunctionBody | undefined; - - // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) - /** @internal */ readonly typeParameters?: NodeArray | undefined; // A get accessor cannot have type parameters +// dprint-ignore +export class GetAccessorDeclaration extends Node implements FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { + declare _functionLikeDeclarationBrand: any; + declare _signatureDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _classElementBrand: any; + declare _typeElementBrand: any; + declare _objectLiteralBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstGetAccessorDeclaration; + + override get parent() { return super.parent as ClassLikeDeclaration | ObjectLiteralExpression | InterfaceDeclaration | TypeLiteralNode; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): PropertyName { return this.ast.data.name.node; } + get body(): Block | undefined { return this.ast.data.body?.node; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set body(value) { this.ast.data.body = value?.ast; } + /** @internal */ get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } + /** @internal */ get endFlowNode(): FlowNode | undefined { return this.ast.data.endFlowNode; } + /** @internal */ set endFlowNode(value) { this.ast.data.endFlowNode = value; } + /** @internal */ get returnFlowNode(): FlowNode | undefined { return this.ast.data.returnFlowNode; } + /** @internal */ set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } } // See the comment on MethodDeclaration for the intuition behind SetAccessorDeclaration being a // ClassElement and an ObjectLiteralElement. -export interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.SetAccessor; - readonly parent: ClassLikeDeclaration | ObjectLiteralExpression | TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: PropertyName; - readonly body?: FunctionBody | undefined; - - // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) - /** @internal */ readonly typeParameters?: NodeArray | undefined; // A set accessor cannot have type parameters - /** @internal */ readonly type?: TypeNode | undefined; // A set accessor cannot have a return type +// dprint-ignore +export class SetAccessorDeclaration extends Node implements FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { + declare _functionLikeDeclarationBrand: any; + declare _signatureDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _classElementBrand: any; + declare _typeElementBrand: any; + declare _objectLiteralBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstSetAccessorDeclaration; + + override get parent() { return super.parent as ClassLikeDeclaration | ObjectLiteralExpression | InterfaceDeclaration | TypeLiteralNode; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): PropertyName { return this.ast.data.name.node; } + get body(): Block | undefined { return this.ast.data.body?.node; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set body(value) { this.ast.data.body = value?.ast; } + /** @internal */ get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ get type(): TypeNode | undefined { return this.ast.data.type?.node; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } + /** @internal */ get endFlowNode(): FlowNode | undefined { return this.ast.data.endFlowNode; } + /** @internal */ set endFlowNode(value) { this.ast.data.endFlowNode = value; } + /** @internal */ get returnFlowNode(): FlowNode | undefined { return this.ast.data.returnFlowNode; } + /** @internal */ set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } } export type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; -export interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement, LocalsContainer { - readonly kind: SyntaxKind.IndexSignature; - readonly parent: ObjectTypeDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly type: TypeNode; -} - -export interface ClassStaticBlockDeclaration extends ClassElement, JSDocContainer, LocalsContainer { - readonly kind: SyntaxKind.ClassStaticBlockDeclaration; - readonly parent: ClassDeclaration | ClassExpression; - readonly body: Block; - - /** @internal */ endFlowNode?: FlowNode | undefined; - /** @internal */ returnFlowNode?: FlowNode | undefined; - - // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) - /** @internal */ readonly modifiers?: NodeArray | undefined; +// dprint-ignore +export class IndexSignatureDeclaration extends Node implements SignatureDeclarationBase, ClassElement, TypeElement, LocalsContainer { + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _classElementBrand: any; + declare _typeElementBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstIndexSignatureDeclaration; + + override get parent() { return super.parent as ObjectTypeDeclaration; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): TypeNode { return this.ast.data.type?.node!; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } -export interface TypeNode extends Node { +// dprint-ignore +export class ClassStaticBlockDeclaration extends Node implements ClassElement, JSDocContainer, LocalsContainer { + declare _signatureDeclarationBrand: any; + declare _classElementBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstClassStaticBlockDeclaration; + + override get parent() { return super.parent as ClassLikeDeclaration; } + + get body(): Block { return this.ast.data.body.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set body(value) { this.ast.data.body = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + /** @internal */ get endFlowNode(): FlowNode | undefined { return this.ast.data.endFlowNode; } + /** @internal */ set endFlowNode(value) { this.ast.data.endFlowNode = value; } + /** @internal */ get returnFlowNode(): FlowNode | undefined { return this.ast.data.returnFlowNode; } + /** @internal */ set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } +} + +export interface TypeNode extends Node { _typeNodeBrand: any; + readonly ast: AstTypeNode; } -/** @internal */ -export interface TypeNode extends Node { - readonly kind: TypeNodeSyntaxKind; -} - -export interface KeywordTypeNode extends KeywordToken, TypeNode { +export interface KeywordTypeNode extends KeywordToken, TypeNode { + readonly ast: AstKeywordTypeNode; readonly kind: TKind; } /** @deprecated */ -export interface ImportTypeAssertionContainer extends Node { - readonly kind: SyntaxKind.ImportTypeAssertionContainer; - readonly parent: ImportTypeNode; - /** @deprecated */ readonly assertClause: AssertClause; - readonly multiLine?: boolean | undefined; +// dprint-ignore +export class ImportTypeAssertionContainer extends Node { + declare readonly ast: AstImportTypeAssertionContainer; + + override get parent() { return super.parent as ImportTypeNode; } + + /** @deprecated */ + get assertClause(): ImportAttributes { return this.ast.data.assertClause.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set assertClause(value) { this.ast.data.assertClause = value.ast; } + /** @internal */ get multiLine(): boolean { return this.ast.data.multiLine; } + /** @internal */ set multiLine(value) { this.ast.data.multiLine = value; } } -export interface ImportTypeNode extends NodeWithTypeArguments { - readonly kind: SyntaxKind.ImportType; - readonly isTypeOf: boolean; - readonly argument: TypeNode; - /** @deprecated */ readonly assertions?: ImportTypeAssertionContainer | undefined; - readonly attributes?: ImportAttributes | undefined; - readonly qualifier?: EntityName | undefined; +// dprint-ignore +export class ImportTypeNode extends Node implements TypeNode, NodeWithTypeArguments { + declare _typeNodeBrand: any; + declare readonly ast: AstImportTypeNode; + + get isTypeOf(): boolean { return this.ast.data.isTypeOf; } + get argument(): TypeNode { return this.ast.data.argument.node; } + get attributes(): ImportAttributes | undefined { return this.ast.data.attributes?.node; } + /** @deprecated */ + get assertions(): ImportTypeAssertionContainer | undefined { return this.ast.data.assertions?.node; } + get qualifier(): EntityName | undefined { return this.ast.data.qualifier?.node; } + get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + + /** @internal */ set isTypeOf(value) { this.ast.data.isTypeOf = value; } + /** @internal */ set argument(value) { this.ast.data.argument = value.ast; } + /** @internal */ set attributes(value) { this.ast.data.attributes = value?.ast; } + /** @internal */ set assertions(value) { this.ast.data.assertions = value?.ast; } + /** @internal */ set qualifier(value) { this.ast.data.qualifier = value?.ast; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } } /** @internal */ export type LiteralImportTypeNode = ImportTypeNode & { readonly argument: LiteralTypeNode & { readonly literal: StringLiteral; }; }; -export interface ThisTypeNode extends TypeNode { - readonly kind: SyntaxKind.ThisType; +// dprint-ignore +export class ThisTypeNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstThisTypeNode; } export type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; export interface FunctionOrConstructorTypeNodeBase extends TypeNode, SignatureDeclarationBase { + readonly ast: AstNode; readonly kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType; readonly type: TypeNode; } -export interface FunctionTypeNode extends FunctionOrConstructorTypeNodeBase, LocalsContainer { - readonly kind: SyntaxKind.FunctionType; - - // A function type cannot have modifiers - /** @internal */ readonly modifiers?: NodeArray | undefined; +// dprint-ignore +export class FunctionTypeNode extends Node implements FunctionOrConstructorTypeNodeBase, LocalsContainer { + declare _signatureDeclarationBrand: any; + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstFunctionTypeNode; + + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): TypeNode { return this.ast.data.type.node; } + + /** @internal */ get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value.ast; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } -export interface ConstructorTypeNode extends FunctionOrConstructorTypeNodeBase, LocalsContainer { - readonly kind: SyntaxKind.ConstructorType; - readonly modifiers?: NodeArray | undefined; +// dprint-ignore +export class ConstructorTypeNode extends Node implements FunctionOrConstructorTypeNodeBase, LocalsContainer { + declare readonly ast: AstConstructorTypeNode; + + declare _signatureDeclarationBrand: any; + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): TypeNode { return this.ast.data.type.node; } + + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value.ast; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } export interface NodeWithTypeArguments extends TypeNode { @@ -2243,147 +3813,321 @@ export interface NodeWithTypeArguments extends TypeNode { export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; -export interface TypeReferenceNode extends NodeWithTypeArguments { - readonly kind: SyntaxKind.TypeReference; - readonly typeName: EntityName; +// dprint-ignore +export class TypeReferenceNode extends Node implements NodeWithTypeArguments { + declare _typeNodeBrand: any; + declare readonly ast: AstTypeReferenceNode; + + get typeName(): Identifier | QualifiedName { return this.ast.data.typeName.node; } + get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + + /** @internal */ set typeName(value) { this.ast.data.typeName = value.ast; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } } -export interface TypePredicateNode extends TypeNode { - readonly kind: SyntaxKind.TypePredicate; - readonly parent: SignatureDeclaration | JSDocTypeExpression; - readonly assertsModifier?: AssertsKeyword | undefined; - readonly parameterName: Identifier | ThisTypeNode; - readonly type?: TypeNode | undefined; +// dprint-ignore +export class TypePredicateNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstTypePredicateNode; + + override get parent() { return super.parent as SignatureDeclaration | JSDocTypeExpression; } + + get assertsModifier(): AssertsKeyword | undefined { return this.ast.data.assertsModifier?.node; } + get parameterName(): Identifier | ThisTypeNode { return this.ast.data.parameterName.node; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set assertsModifier(value) { this.ast.data.assertsModifier = value?.ast; } + /** @internal */ set parameterName(value) { this.ast.data.parameterName = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } } -export interface TypeQueryNode extends NodeWithTypeArguments { - readonly kind: SyntaxKind.TypeQuery; - readonly exprName: EntityName; +// dprint-ignore +export class TypeQueryNode extends Node implements NodeWithTypeArguments { + declare _typeNodeBrand: any; + declare readonly ast: AstTypeQueryNode; + + get exprName(): Identifier | QualifiedName { return this.ast.data.exprName.node; } + get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + + /** @internal */ set exprName(value) { this.ast.data.exprName = value.ast; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } } // A TypeLiteral is the declaration node for an anonymous symbol. -export interface TypeLiteralNode extends TypeNode, Declaration { - readonly kind: SyntaxKind.TypeLiteral; - readonly members: NodeArray; -} +// dprint-ignore +export class TypeLiteralNode extends Node implements TypeNode, Declaration { + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare readonly ast: AstTypeLiteralNode; -export interface ArrayTypeNode extends TypeNode { - readonly kind: SyntaxKind.ArrayType; - readonly elementType: TypeNode; -} + get members(): NodeArray { return this.ast.data.members.nodes; } -export interface TupleTypeNode extends TypeNode { - readonly kind: SyntaxKind.TupleType; - readonly elements: NodeArray; + /** @internal */ set members(value) { this.ast.data.members = value.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface NamedTupleMember extends TypeNode, Declaration, JSDocContainer { - readonly kind: SyntaxKind.NamedTupleMember; - readonly dotDotDotToken?: DotDotDotToken | undefined; - readonly name: Identifier; - readonly questionToken?: QuestionToken | undefined; - readonly type: TypeNode; -} +// dprint-ignore +export class ArrayTypeNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstArrayTypeNode; -export interface OptionalTypeNode extends TypeNode { - readonly kind: SyntaxKind.OptionalType; - readonly type: TypeNode; -} + get elementType(): TypeNode { return this.ast.data.elementType.node; } -export interface RestTypeNode extends TypeNode { - readonly kind: SyntaxKind.RestType; - readonly type: TypeNode; + /** @internal */ set elementType(value) { this.ast.data.elementType = value.ast; } } -export type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; +// dprint-ignore +export class TupleTypeNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstTupleTypeNode; -export interface UnionTypeNode extends TypeNode { - readonly kind: SyntaxKind.UnionType; - readonly types: NodeArray; -} + get elements(): NodeArray { return this.ast.data.elements.nodes; } -export interface IntersectionTypeNode extends TypeNode { - readonly kind: SyntaxKind.IntersectionType; - readonly types: NodeArray; + /** @internal */ set elements(value: NodeArray) { this.ast.data.elements = value.ast; } } -export interface ConditionalTypeNode extends TypeNode, LocalsContainer { - readonly kind: SyntaxKind.ConditionalType; - readonly checkType: TypeNode; - readonly extendsType: TypeNode; - readonly trueType: TypeNode; - readonly falseType: TypeNode; +// dprint-ignore +export class NamedTupleMember extends Node implements TypeNode, Declaration, JSDocContainer { + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstNamedTupleMember; + + get dotDotDotToken(): DotDotDotToken | undefined { return this.ast.data.dotDotDotToken?.node; } + get name(): Identifier { return this.ast.data.name.node; } + get questionToken(): QuestionToken | undefined { return this.ast.data.questionToken?.node; } + get type(): TypeNode { return this.ast.data.type.node; } + + /** @internal */ set dotDotDotToken(value) { this.ast.data.dotDotDotToken = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set questionToken(value) { this.ast.data.questionToken = value?.ast; } + /** @internal */ set type(value) { this.ast.data.type = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface InferTypeNode extends TypeNode { - readonly kind: SyntaxKind.InferType; - readonly typeParameter: TypeParameterDeclaration; -} +// dprint-ignore +export class OptionalTypeNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstOptionalTypeNode; -export interface ParenthesizedTypeNode extends TypeNode { - readonly kind: SyntaxKind.ParenthesizedType; - readonly type: TypeNode; -} + get type(): TypeNode { return this.ast.data.type.node; } -export interface TypeOperatorNode extends TypeNode { - readonly kind: SyntaxKind.TypeOperator; - readonly operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; - readonly type: TypeNode; + /** @internal */ set type(value) { this.ast.data.type = value.ast; } } -/** @internal @knipignore */ -export interface UniqueTypeOperatorNode extends TypeOperatorNode { - readonly operator: SyntaxKind.UniqueKeyword; -} +// dprint-ignore +export class RestTypeNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstRestTypeNode; -export interface IndexedAccessTypeNode extends TypeNode { - readonly kind: SyntaxKind.IndexedAccessType; - readonly objectType: TypeNode; - readonly indexType: TypeNode; -} + get type(): TypeNode { return this.ast.data.type.node; } -export interface MappedTypeNode extends TypeNode, Declaration, LocalsContainer { - readonly kind: SyntaxKind.MappedType; - readonly readonlyToken?: ReadonlyKeyword | PlusToken | MinusToken | undefined; - readonly typeParameter: TypeParameterDeclaration; - readonly nameType?: TypeNode | undefined; - readonly questionToken?: QuestionToken | PlusToken | MinusToken | undefined; - readonly type?: TypeNode | undefined; - /** Used only to produce grammar errors */ - readonly members?: NodeArray | undefined; + /** @internal */ set type(value) { this.ast.data.type = value.ast; } } -export interface LiteralTypeNode extends TypeNode { - readonly kind: SyntaxKind.LiteralType; - readonly literal: NullLiteral | BooleanLiteral | LiteralExpression | PrefixUnaryExpression; -} +export type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; -export interface StringLiteral extends LiteralExpression, Declaration { - readonly kind: SyntaxKind.StringLiteral; - /** @internal */ - readonly textSourceNode?: Identifier | StringLiteralLike | NumericLiteral | PrivateIdentifier | JsxNamespacedName | BigIntLiteral | undefined; // Allows a StringLiteral to get its text from another node (used by transforms). - /** - * Note: this is only set when synthesizing a node, not during parsing. - * +// dprint-ignore +export class UnionTypeNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstUnionTypeNode; + + get types(): NodeArray { return this.ast.data.types.nodes; } + + /** @internal */ set types(value) { this.ast.data.types = value.ast; } +} + +// dprint-ignore +export class IntersectionTypeNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstIntersectionTypeNode; + + get types(): NodeArray { return this.ast.data.types.nodes; } + + /** @internal */ set types(value) { this.ast.data.types = value.ast; } +} + +// dprint-ignore +export class ConditionalTypeNode extends Node implements TypeNode, LocalsContainer { + declare _typeNodeBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstConditionalTypeNode; + + get checkType(): TypeNode { return this.ast.data.checkType.node; } + get extendsType(): TypeNode { return this.ast.data.extendsType.node; } + get trueType(): TypeNode { return this.ast.data.trueType.node; } + get falseType(): TypeNode { return this.ast.data.falseType.node; } + + /** @internal */ set checkType(value) { this.ast.data.checkType = value.ast; } + /** @internal */ set extendsType(value) { this.ast.data.extendsType = value.ast; } + /** @internal */ set trueType(value) { this.ast.data.trueType = value.ast; } + /** @internal */ set falseType(value) { this.ast.data.falseType = value.ast; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } +} + +// dprint-ignore +export class InferTypeNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstInferTypeNode; + + get typeParameter(): TypeParameterDeclaration { return this.ast.data.typeParameter.node; } + + /** @internal */ set typeParameter(value) { this.ast.data.typeParameter = value.ast; } +} + +// dprint-ignore +export class ParenthesizedTypeNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstParenthesizedTypeNode; + + get type(): TypeNode { return this.ast.data.type.node; } + + /** @internal */ set type(value) { this.ast.data.type = value.ast; } +} + +// dprint-ignore +export class TypeOperatorNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstTypeOperatorNode; + + get operator(): SyntaxKind.KeyOfKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.UniqueKeyword { return this.ast.data.operator; } + get type(): TypeNode { return this.ast.data.type.node; } + + /** @internal */ set operator(value) { this.ast.data.operator = value; } + /** @internal */ set type(value) { this.ast.data.type = value.ast; } +} + +/** @internal @knipignore */ +export interface UniqueTypeOperatorNode extends TypeOperatorNode { + readonly operator: SyntaxKind.UniqueKeyword; +} + +// dprint-ignore +export class IndexedAccessTypeNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstIndexedAccessTypeNode; + + get objectType(): TypeNode { return this.ast.data.objectType.node; } + get indexType(): TypeNode { return this.ast.data.indexType.node; } + + /** @internal */ set objectType(value) { this.ast.data.objectType = value.ast; } + /** @internal */ set indexType(value) { this.ast.data.indexType = value.ast; } +} + +// dprint-ignore +export class MappedTypeNode extends Node implements TypeNode, Declaration, LocalsContainer { + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstMappedTypeNode; + + get readonlyToken(): PlusToken | MinusToken | ReadonlyKeyword | undefined { return this.ast.data.readonlyToken?.node; } + get typeParameter(): TypeParameterDeclaration { return this.ast.data.typeParameter.node; } + get nameType(): TypeNode | undefined { return this.ast.data.nameType?.node; } + get questionToken(): QuestionToken | PlusToken | MinusToken | undefined { return this.ast.data.questionToken?.node; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + get members(): NodeArray | undefined { return this.ast.data.members?.nodes; } + + /** @internal */ set readonlyToken(value) { this.ast.data.readonlyToken = value?.ast; } + /** @internal */ set typeParameter(value) { this.ast.data.typeParameter = value.ast; } + /** @internal */ set nameType(value) { this.ast.data.nameType = value?.ast; } + /** @internal */ set questionToken(value) { this.ast.data.questionToken = value?.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ set members(value) { this.ast.data.members = value?.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } +} + +// dprint-ignore +export class LiteralTypeNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstLiteralTypeNode; + + get literal(): NullLiteral | TrueLiteral | FalseLiteral | PrefixUnaryExpression | LiteralExpression { return this.ast.data.literal.node; } + + /** @internal */ set literal(value) { this.ast.data.literal = value.ast; } +} + +// TODO(rbuckton): Move string literal adjacent to tokens and other literals. +// dprint-ignore +export class StringLiteral extends Token implements LiteralExpression, StringLiteralLikeNode, Declaration { + declare _literalExpressionBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare readonly ast: AstStringLiteral; + + get text(): string { return this.ast.data.text; } + get isUnterminated(): boolean { return this.ast.data.isUnterminated; } + get hasExtendedUnicodeEscape(): boolean { return this.ast.data.hasExtendedUnicodeEscape; } + + /** @internal */ set text(value) { this.ast.data.text = value; } + /** + * NOTE: This is only set when synthesizing a node, not during parsing. * @internal */ - readonly singleQuote?: boolean | undefined; + get singleQuote(): boolean | undefined { return this.ast.data.singleQuote; } + /** @internal */ set singleQuote(value) { this.ast.data.singleQuote = value; } + /** @internal */ set isUnterminated(value) { this.ast.data.isUnterminated = value; } + /** @internal */ set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + /** @internal */ get textSourceNode(): Identifier | PrivateIdentifier | NumericLiteral | BigIntLiteral | JsxNamespacedName | StringLiteralLike | undefined { return this.ast.data.textSourceNode?.node; } + /** @internal */ set textSourceNode(value) { this.ast.data.textSourceNode = value?.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral; export type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral | JsxNamespacedName | BigIntLiteral; -export interface TemplateLiteralTypeNode extends TypeNode { - readonly kind: SyntaxKind.TemplateLiteralType; - readonly head: TemplateHead; - readonly templateSpans: NodeArray; +// dprint-ignore +export class TemplateLiteralTypeNode extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstTemplateLiteralTypeNode; + + get head(): TemplateHead { return this.ast.data.head.node; } + get templateSpans(): NodeArray { return this.ast.data.templateSpans.nodes; } + + /** @internal */ set head(value) { this.ast.data.head = value.ast; } + /** @internal */ set templateSpans(value) { this.ast.data.templateSpans = value.ast; } } -export interface TemplateLiteralTypeSpan extends TypeNode { - readonly kind: SyntaxKind.TemplateLiteralTypeSpan; - readonly parent: TemplateLiteralTypeNode; - readonly type: TypeNode; - readonly literal: TemplateMiddle | TemplateTail; +// dprint-ignore +export class TemplateLiteralTypeSpan extends Node { + declare _typeNodeBrand: any; + declare readonly ast: AstTemplateLiteralTypeSpan; + + override get parent() { return super.parent as TemplateLiteralTypeNode; } + + get type(): TypeNode { return this.ast.data.type.node; } + get literal(): TemplateMiddle | TemplateTail { return this.ast.data.literal.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set type(value) { this.ast.data.type = value.ast; } + /** @internal */ set literal(value) { this.ast.data.literal = value.ast; } } // Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing. @@ -2395,27 +4139,41 @@ export interface TemplateLiteralTypeSpan extends TypeNode { export interface Expression extends Node { _expressionBrand: any; + readonly ast: AstExpression; } -export interface OmittedExpression extends Expression { - readonly kind: SyntaxKind.OmittedExpression; +// dprint-ignore +export class OmittedExpression extends Node implements Expression { + declare _expressionBrand: any; + declare readonly ast: AstOmittedExpression; } // Represents an expression that is elided as part of a transformation to emit comments on a // not-emitted node. The 'expression' property of a PartiallyEmittedExpression should be emitted. -export interface PartiallyEmittedExpression extends LeftHandSideExpression { - readonly kind: SyntaxKind.PartiallyEmittedExpression; - readonly expression: Expression; +// dprint-ignore +export class PartiallyEmittedExpression extends Node implements LeftHandSideExpression { + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstPartiallyEmittedExpression; + + get expression(): Expression { return this.ast.data.expression.node; } + + /** @internal */ set expression(value: Expression) { this.ast.data.expression = value.ast; } } export interface UnaryExpression extends Expression { _unaryExpressionBrand: any; + readonly ast: AstUnaryExpression; } -/** Deprecated, please use UpdateExpression */ +/** @deprecated use UpdateExpression instead */ export type IncrementExpression = UpdateExpression; + export interface UpdateExpression extends UnaryExpression { _updateExpressionBrand: any; + readonly ast: AstUpdateExpression; } // see: https://tc39.github.io/ecma262/#prod-UpdateExpression @@ -2428,10 +4186,18 @@ export type PrefixUnaryOperator = | SyntaxKind.TildeToken | SyntaxKind.ExclamationToken; -export interface PrefixUnaryExpression extends UpdateExpression { - readonly kind: SyntaxKind.PrefixUnaryExpression; - readonly operator: PrefixUnaryOperator; - readonly operand: UnaryExpression; +// dprint-ignore +export class PrefixUnaryExpression extends Node implements UpdateExpression { + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstPrefixUnaryExpression; + + get operator(): PrefixUnaryOperator { return this.ast.data.operator; } + get operand(): UnaryExpression { return this.ast.data.operand.node; } + + /** @internal */ set operator(value) { this.ast.data.operator = value; } + /** @internal */ set operand(value) { this.ast.data.operand = value.ast; } } // see: https://tc39.github.io/ecma262/#prod-UpdateExpression @@ -2439,81 +4205,182 @@ export type PostfixUnaryOperator = | SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken; -export interface PostfixUnaryExpression extends UpdateExpression { - readonly kind: SyntaxKind.PostfixUnaryExpression; - readonly operand: LeftHandSideExpression; - readonly operator: PostfixUnaryOperator; +// dprint-ignore +export class PostfixUnaryExpression extends Node implements UpdateExpression { + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstPostfixUnaryExpression; + + get operand(): LeftHandSideExpression { return this.ast.data.operand.node; } + get operator(): PostfixUnaryOperator { return this.ast.data.operator; } + + /** @internal */ set operand(value) { this.ast.data.operand = value.ast; } + /** @internal */ set operator(value) { this.ast.data.operator = value; } } export interface LeftHandSideExpression extends UpdateExpression { _leftHandSideExpressionBrand: any; + readonly ast: AstLeftHandSideExpression; } export interface MemberExpression extends LeftHandSideExpression { _memberExpressionBrand: any; + readonly ast: AstMemberExpression; } export interface PrimaryExpression extends MemberExpression { _primaryExpressionBrand: any; + readonly ast: AstPrimaryExpression; } -export interface NullLiteral extends PrimaryExpression { - readonly kind: SyntaxKind.NullKeyword; +// TODO(rbuckton): Move literal token nodes adjacent to other tokens and literals. +// dprint-ignore +export class NullLiteral extends Token implements KeywordExpression { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstNullLiteral; } -export interface TrueLiteral extends PrimaryExpression { - readonly kind: SyntaxKind.TrueKeyword; +// TODO(rbuckton): Move literal token nodes adjacent to other tokens and literals. +// dprint-ignore +export class TrueLiteral extends Token implements KeywordExpression { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstTrueLiteral; } -export interface FalseLiteral extends PrimaryExpression { - readonly kind: SyntaxKind.FalseKeyword; +// TODO(rbuckton): Move literal token nodes adjacent to other tokens and literals. +// dprint-ignore +export class FalseLiteral extends Token implements KeywordExpression { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstFalseLiteral; } export type BooleanLiteral = TrueLiteral | FalseLiteral; -export interface ThisExpression extends PrimaryExpression, FlowContainer { - readonly kind: SyntaxKind.ThisKeyword; +// dprint-ignore +export class ThisExpression extends Token implements KeywordExpression, FlowContainer { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstThisExpression; + + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface SuperExpression extends PrimaryExpression, FlowContainer { - readonly kind: SyntaxKind.SuperKeyword; +// dprint-ignore +export class SuperExpression extends Token implements KeywordExpression, FlowContainer { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstSuperExpression; + + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface ImportExpression extends PrimaryExpression { - readonly kind: SyntaxKind.ImportKeyword; +// dprint-ignore +export class ImportExpression extends Token implements KeywordExpression { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstImportExpression; } -export interface DeleteExpression extends UnaryExpression { - readonly kind: SyntaxKind.DeleteExpression; - readonly expression: UnaryExpression; +// dprint-ignore +export class DeleteExpression extends Node implements UnaryExpression { + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstDeleteExpression; + + get expression(): UnaryExpression { return this.ast.data.expression.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } } -export interface TypeOfExpression extends UnaryExpression { - readonly kind: SyntaxKind.TypeOfExpression; - readonly expression: UnaryExpression; +// dprint-ignore +export class TypeOfExpression extends Node implements UnaryExpression { + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstTypeOfExpression; + + get expression(): UnaryExpression { return this.ast.data.expression.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } } -export interface VoidExpression extends UnaryExpression { - readonly kind: SyntaxKind.VoidExpression; - readonly expression: UnaryExpression; +// dprint-ignore +export class VoidExpression extends Node implements UnaryExpression { + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstVoidExpression; + + get expression(): UnaryExpression { return this.ast.data.expression.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } } -export interface AwaitExpression extends UnaryExpression { - readonly kind: SyntaxKind.AwaitExpression; - readonly expression: UnaryExpression; +// dprint-ignore +export class AwaitExpression extends Node implements UnaryExpression { + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstAwaitExpression; + + get expression(): UnaryExpression { return this.ast.data.expression.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } } -export interface YieldExpression extends Expression { - readonly kind: SyntaxKind.YieldExpression; - readonly asteriskToken?: AsteriskToken | undefined; - readonly expression?: Expression | undefined; +// dprint-ignore +export class YieldExpression extends Node implements Expression { + declare _expressionBrand: any; + declare readonly ast: AstYieldExpression; + + get asteriskToken(): AsteriskToken | undefined { return this.ast.data.asteriskToken?.node; } + get expression(): Expression | undefined { return this.ast.data.expression?.node; } + + /** @internal */ set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } + /** @internal */ set expression(value) { this.ast.data.expression = value?.ast; } } -export interface SyntheticExpression extends Expression { - readonly kind: SyntaxKind.SyntheticExpression; - readonly isSpread: boolean; - readonly type: Type; - readonly tupleNameSource?: ParameterDeclaration | NamedTupleMember | undefined; +// dprint-ignore +export class SyntheticExpression extends Node implements Expression { + declare _expressionBrand: any; + declare readonly ast: AstSyntheticExpression; + + get isSpread(): boolean { return this.ast.data.isSpread; } + get type(): Type { return this.ast.data.type; } + get tupleNameSource(): ParameterDeclaration | NamedTupleMember | undefined { return this.ast.data.tupleNameSource?.node; } + + /** @internal */ set isSpread(value: boolean) { this.ast.data.isSpread = value; } + /** @internal */ set type(value: Type) { this.ast.data.type = value; } + /** @internal */ set tupleNameSource(value: ParameterDeclaration | NamedTupleMember | undefined) { this.ast.data.tupleNameSource = value?.ast; } } // see: https://tc39.github.io/ecma262/#prod-ExponentiationExpression @@ -2645,11 +4512,26 @@ export type LogicalOrCoalescingAssignmentOperator = export type BinaryOperatorToken = Token; -export interface BinaryExpression extends Expression, Declaration, JSDocContainer { - readonly kind: SyntaxKind.BinaryExpression; - readonly left: Expression; - readonly operatorToken: BinaryOperatorToken; - readonly right: Expression; +// dprint-ignore +export class BinaryExpression extends Node implements Expression, Declaration, JSDocContainer { + declare _expressionBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstBinaryExpression; + + get left(): Expression { return this.ast.data.left.node; } + get operatorToken(): BinaryOperatorToken { return this.ast.data.operatorToken.node; } + get right(): Expression { return this.ast.data.right.node; } + + /** @internal */ set left(value) { this.ast.data.left = value.ast; } + /** @internal */ set operatorToken(value) { this.ast.data.operatorToken = value.ast; } + /** @internal */ set right(value) { this.ast.data.right = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export type AssignmentOperatorToken = Token; @@ -2732,59 +4614,195 @@ export type AssignmentPattern = ObjectLiteralExpression | ArrayLiteralExpression export type BindingOrAssignmentPattern = ObjectBindingOrAssignmentPattern | ArrayBindingOrAssignmentPattern; -export interface ConditionalExpression extends Expression { - readonly kind: SyntaxKind.ConditionalExpression; - readonly condition: Expression; - readonly questionToken: QuestionToken; - readonly whenTrue: Expression; - readonly colonToken: ColonToken; - readonly whenFalse: Expression; +export interface InstanceofExpression extends BinaryExpression { + readonly operatorToken: Token; } -export type FunctionBody = Block; -export type ConciseBody = FunctionBody | Expression; +// dprint-ignore +export class ConditionalExpression extends Node implements Expression { + declare _expressionBrand: any; + declare readonly ast: AstConditionalExpression; -export interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.FunctionExpression; - readonly modifiers?: NodeArray | undefined; - readonly name?: Identifier | undefined; - readonly body: FunctionBody; // Required, whereas the member inherited from FunctionDeclaration is optional + get condition(): Expression { return this.ast.data.condition.node; } + get questionToken(): QuestionToken { return this.ast.data.questionToken.node; } + get whenTrue(): Expression { return this.ast.data.whenTrue.node; } + get colonToken(): ColonToken { return this.ast.data.colonToken.node; } + get whenFalse(): Expression { return this.ast.data.whenFalse.node; } + + /** @internal */ set condition(value) { this.ast.data.condition = value.ast; } + /** @internal */ set questionToken(value) { this.ast.data.questionToken = value.ast; } + /** @internal */ set whenTrue(value) { this.ast.data.whenTrue = value.ast; } + /** @internal */ set colonToken(value) { this.ast.data.colonToken = value.ast; } + /** @internal */ set whenFalse(value) { this.ast.data.whenFalse = value.ast; } } -export interface ArrowFunction extends Expression, FunctionLikeDeclarationBase, JSDocContainer, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.ArrowFunction; - readonly modifiers?: NodeArray | undefined; - readonly equalsGreaterThanToken: EqualsGreaterThanToken; - readonly body: ConciseBody; - readonly name: never; +export type FunctionBody = Block; +export type ConciseBody = FunctionBody | Expression; + +// dprint-ignore +export class FunctionExpression extends Node implements PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer, LocalsContainer, FlowContainer { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _functionLikeDeclarationBrand: any; + declare _signatureDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstFunctionExpression; + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get asteriskToken(): AsteriskToken | undefined { return this.ast.data.asteriskToken?.node; } + get name(): Identifier | undefined { return this.ast.data.name?.node; } + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + get body(): Block { return this.ast.data.body.node; } + + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value?.ast; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ set body(value) { this.ast.data.body = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } + /** @internal */ get endFlowNode(): FlowNode | undefined { return this.ast.data.endFlowNode; } + /** @internal */ set endFlowNode(value) { this.ast.data.endFlowNode = value; } + /** @internal */ get returnFlowNode(): FlowNode | undefined { return this.ast.data.returnFlowNode; } + /** @internal */ set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } } +// dprint-ignore +export class ArrowFunction extends Node implements Expression, FunctionLikeDeclarationBase, JSDocContainer, LocalsContainer, FlowContainer { + declare _expressionBrand: any; + declare _functionLikeDeclarationBrand: any; + declare _signatureDeclarationBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstArrowFunction; + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get equalsGreaterThanToken(): EqualsGreaterThanToken { return this.ast.data.equalsGreaterThanToken.node; } + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + get body(): Block | Expression { return this.ast.data.body.node; } + + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set equalsGreaterThanToken(value) { this.ast.data.equalsGreaterThanToken = value.ast; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ set body(value) { this.ast.data.body = value.ast; } + /** @internal */ get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } + /** @internal */ get endFlowNode(): FlowNode | undefined { return this.ast.data.endFlowNode; } + /** @internal */ set endFlowNode(value) { this.ast.data.endFlowNode = value; } + /** @internal */ get returnFlowNode(): FlowNode | undefined { return this.ast.data.returnFlowNode; } + /** @internal */ set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } +} + +// TODO(rbuckton): Move adjacent to tokens and other literals. // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, // or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters. // For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1". export interface LiteralLikeNode extends Node { - text: string; - isUnterminated?: boolean | undefined; - hasExtendedUnicodeEscape?: boolean | undefined; + readonly ast: AstLiteralLikeNode; + readonly data: AstLiteralLikeNodeData; + + get text(): string; + + /** @internal */ set text(value: string); } -export interface TemplateLiteralLikeNode extends LiteralLikeNode { - rawText?: string | undefined; - /** @internal */ - templateFlags?: TokenFlags | undefined; +// TODO(rbuckton): Move adjacent to tokens and other literals. +export interface StringLiteralLikeNode extends LiteralLikeNode { + readonly ast: AstStringLiteralLikeNode; + readonly data: AstStringLiteralLikeNodeData; + + get isUnterminated(): boolean | undefined; + get hasExtendedUnicodeEscape(): boolean | undefined; + + /** @internal */ set isUnterminated(value: boolean | undefined); + /** @internal */ set hasExtendedUnicodeEscape(value: boolean | undefined); } +// TODO(rbuckton): Move adjacent to tokens and other literals. +export interface TemplateLiteralLikeNode extends StringLiteralLikeNode { + readonly ast: AstTemplateLiteralLikeNode; + readonly data: AstTemplateLiteralLikeNodeData; + + get rawText(): string | undefined; + + /** @internal */ set rawText(value: string | undefined); + /** @internal */ get templateFlags(): TokenFlags | undefined; + /** @internal */ set templateFlags(value: TokenFlags | undefined); +} + +// TODO(rbuckton): Move adjacent to tokens and other literals. // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, // or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters. // For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1". export interface LiteralExpression extends LiteralLikeNode, PrimaryExpression { _literalExpressionBrand: any; + readonly ast: AstLiteralExpression; + readonly data: AstLiteralExpressionData; } -export interface RegularExpressionLiteral extends LiteralExpression { - readonly kind: SyntaxKind.RegularExpressionLiteral; -} - +// TODO(rbuckton): Move adjacent to tokens and other literals. +// dprint-ignore +export class RegularExpressionLiteral extends Token implements StringLiteralLikeNode { + declare _literalExpressionBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstRegularExpressionLiteral; + + get text(): string { return this.ast.data.text; } + get isUnterminated(): boolean | undefined { return this.ast.data.isUnterminated; } + get hasExtendedUnicodeEscape(): boolean | undefined { return this.ast.data.hasExtendedUnicodeEscape; } + + /** @internal */ set text(value) { this.ast.data.text = value; } + /** @internal */ set isUnterminated(value) { this.ast.data.isUnterminated = value; } + /** @internal */ set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } +} + +// TODO(rbuckton): Move adjacent to tokens and other literals. // dprint-ignore /** @internal */ export const enum RegularExpressionFlags { @@ -2801,12 +4819,37 @@ export const enum RegularExpressionFlags { Modifiers = IgnoreCase | Multiline | DotAll, } -export interface NoSubstitutionTemplateLiteral extends LiteralExpression, TemplateLiteralLikeNode, Declaration { - readonly kind: SyntaxKind.NoSubstitutionTemplateLiteral; - /** @internal */ - templateFlags?: TokenFlags | undefined; -} - +// TODO(rbuckton): Move adjacent to tokens and other literals. +// dprint-ignore +export class NoSubstitutionTemplateLiteral extends Token implements LiteralExpression, TemplateLiteralLikeNode, Declaration { + declare _literalExpressionBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare readonly ast: AstNoSubstitutionTemplateLiteral; + + get text(): string { return this.ast.data.text; } + get rawText(): string | undefined { return this.ast.data.rawText; } + get isUnterminated(): boolean | undefined { return this.ast.data.isUnterminated; } + get hasExtendedUnicodeEscape(): boolean | undefined { return this.ast.data.hasExtendedUnicodeEscape; } + + /** @internal */ set text(value) { this.ast.data.text = value; } + /** @internal */ set rawText(value) { this.ast.data.rawText = value; } + /** @internal */ set isUnterminated(value) { this.ast.data.isUnterminated = value; } + /** @internal */ set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + /** @internal */ get templateFlags(): TokenFlags { return this.ast.data.templateFlags; } + /** @internal */ set templateFlags(value) { this.ast.data.templateFlags = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +// TODO(rbuckton): Move adjacent to tokens and other literals. // dprint-ignore export const enum TokenFlags { None = 0, @@ -2851,16 +4894,47 @@ export const enum TokenFlags { IsInvalid = Octal | ContainsLeadingZero | ContainsInvalidSeparator | ContainsInvalidEscape, } -export interface NumericLiteral extends LiteralExpression, Declaration { - readonly kind: SyntaxKind.NumericLiteral; - /** @internal */ - readonly numericLiteralFlags: TokenFlags; -} +// TODO(rbuckton): Move adjacent to tokens and other literals. +// dprint-ignore +export class NumericLiteral extends Token implements LiteralExpression, LiteralLikeNode, Declaration { + declare _literalExpressionBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare readonly ast: AstNumericLiteral; + + get text(): string { return this.ast.data.text; } + + /** @internal */ set text(value) { this.ast.data.text = value; } + /** @internal */ get numericLiteralFlags(): TokenFlags { return this.ast.data.numericLiteralFlags; } + /** @internal */ set numericLiteralFlags(value) { this.ast.data.numericLiteralFlags = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } +} + +// TODO(rbuckton): Move adjacent to tokens and other literals. +// dprint-ignore +export class BigIntLiteral extends Token implements LiteralExpression, LiteralLikeNode { + declare _literalExpressionBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstBigIntLiteral; -export interface BigIntLiteral extends LiteralExpression { - readonly kind: SyntaxKind.BigIntLiteral; + get text(): string { return this.ast.data.text; } + /** @internal */ set text(value) { this.ast.data.text = value; } } +// TODO(rbuckton): Move adjacent to tokens and other literals. export type LiteralToken = | NumericLiteral | BigIntLiteral @@ -2869,40 +4943,95 @@ export type LiteralToken = | RegularExpressionLiteral | NoSubstitutionTemplateLiteral; -export interface TemplateHead extends TemplateLiteralLikeNode { - readonly kind: SyntaxKind.TemplateHead; - readonly parent: TemplateExpression | TemplateLiteralTypeNode; - /** @internal */ - templateFlags?: TokenFlags | undefined; +// TODO(rbuckton): Move adjacent to tokens and other literals. +// dprint-ignore +export class TemplateHead extends Token implements TemplateLiteralLikeNode { + declare readonly ast: AstTemplateHead; + + override get parent() { return super.parent as TemplateExpression | TemplateLiteralTypeNode; } + + get text(): string { return this.ast.data.text; } + get isUnterminated(): boolean | undefined { return this.ast.data.isUnterminated; } + get hasExtendedUnicodeEscape(): boolean | undefined { return this.ast.data.hasExtendedUnicodeEscape; } + get rawText(): string | undefined { return this.ast.data.rawText; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set text(value) { this.ast.data.text = value; } + /** @internal */ set isUnterminated(value) { this.ast.data.isUnterminated = value; } + /** @internal */ set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + /** @internal */ set rawText(value) { this.ast.data.rawText = value; } + /** @internal */ get templateFlags(): TokenFlags { return this.ast.data.templateFlags; } + /** @internal */ set templateFlags(value) { this.ast.data.templateFlags = value; } } -export interface TemplateMiddle extends TemplateLiteralLikeNode { - readonly kind: SyntaxKind.TemplateMiddle; - readonly parent: TemplateSpan | TemplateLiteralTypeSpan; - /** @internal */ - templateFlags?: TokenFlags | undefined; +// TODO(rbuckton): Move adjacent to tokens and other literals. +// dprint-ignore +export class TemplateMiddle extends Token implements TemplateLiteralLikeNode { + declare readonly ast: AstTemplateMiddle; + + override get parent() { return super.parent as TemplateSpan | TemplateLiteralTypeSpan; } + + get text(): string { return this.ast.data.text; } + get isUnterminated(): boolean | undefined { return this.ast.data.isUnterminated; } + get hasExtendedUnicodeEscape(): boolean | undefined { return this.ast.data.hasExtendedUnicodeEscape; } + get rawText(): string | undefined { return this.ast.data.rawText; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set text(value) { this.ast.data.text = value; } + /** @internal */ set isUnterminated(value) { this.ast.data.isUnterminated = value; } + /** @internal */ set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + /** @internal */ set rawText(value) { this.ast.data.rawText = value; } + /** @internal */ get templateFlags(): TokenFlags { return this.ast.data.templateFlags; } + /** @internal */ set templateFlags(value) { this.ast.data.templateFlags = value; } } -export interface TemplateTail extends TemplateLiteralLikeNode { - readonly kind: SyntaxKind.TemplateTail; - readonly parent: TemplateSpan | TemplateLiteralTypeSpan; - /** @internal */ - templateFlags?: TokenFlags | undefined; +// TODO(rbuckton): Move adjacent to tokens and other literals. +// dprint-ignore +export class TemplateTail extends Token implements TemplateLiteralLikeNode { + declare readonly ast: AstTemplateTail; + + override get parent() { return super.parent as TemplateSpan | TemplateLiteralTypeSpan; } + + get text(): string { return this.ast.data.text; } + get isUnterminated(): boolean | undefined { return this.ast.data.isUnterminated; } + get hasExtendedUnicodeEscape(): boolean | undefined { return this.ast.data.hasExtendedUnicodeEscape; } + get rawText(): string | undefined { return this.ast.data.rawText; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set text(value) { this.ast.data.text = value; } + /** @internal */ set isUnterminated(value) { this.ast.data.isUnterminated = value; } + /** @internal */ set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + /** @internal */ set rawText(value) { this.ast.data.rawText = value; } + /** @internal */ get templateFlags(): TokenFlags { return this.ast.data.templateFlags; } + /** @internal */ set templateFlags(value) { this.ast.data.templateFlags = value; } } +// TODO(rbuckton): Move adjacent to tokens and other literals. export type PseudoLiteralToken = | TemplateHead | TemplateMiddle | TemplateTail; +// TODO(rbuckton): Move adjacent to tokens and other literals. export type TemplateLiteralToken = | NoSubstitutionTemplateLiteral | PseudoLiteralToken; -export interface TemplateExpression extends PrimaryExpression { - readonly kind: SyntaxKind.TemplateExpression; - readonly head: TemplateHead; - readonly templateSpans: NodeArray; +// dprint-ignore +export class TemplateExpression extends Node implements PrimaryExpression { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstTemplateExpression; + + get head(): TemplateHead { return this.ast.data.head.node; } + get templateSpans(): NodeArray { return this.ast.data.templateSpans.nodes; } + + /** @internal */ set head(value) { this.ast.data.head = value.ast; } + /** @internal */ set templateSpans(value) { this.ast.data.templateSpans = value.ast; } } export type TemplateLiteral = @@ -2911,16 +5040,36 @@ export type TemplateLiteral = // Each of these corresponds to a substitution expression and a template literal, in that order. // The template literal must have kind TemplateMiddleLiteral or TemplateTailLiteral. -export interface TemplateSpan extends Node { - readonly kind: SyntaxKind.TemplateSpan; - readonly parent: TemplateExpression; - readonly expression: Expression; - readonly literal: TemplateMiddle | TemplateTail; +// dprint-ignore +export class TemplateSpan extends Node { + declare readonly ast: AstTemplateSpan; + + override get parent() { return super.parent as TemplateExpression; } + + get expression(): Expression { return this.ast.data.expression.node; } + get literal(): TemplateMiddle | TemplateTail { return this.ast.data.literal.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set literal(value) { this.ast.data.literal = value.ast; } } -export interface ParenthesizedExpression extends PrimaryExpression, JSDocContainer { - readonly kind: SyntaxKind.ParenthesizedExpression; - readonly expression: Expression; +// dprint-ignore +export class ParenthesizedExpression extends Node implements PrimaryExpression, JSDocContainer { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstParenthesizedExpression; + + get expression(): Expression { return this.ast.data.expression.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } } /** @internal */ @@ -2928,19 +5077,37 @@ export interface JSDocTypeAssertion extends ParenthesizedExpression { readonly _jsDocTypeAssertionBrand: never; } -export interface ArrayLiteralExpression extends PrimaryExpression { - readonly kind: SyntaxKind.ArrayLiteralExpression; - readonly elements: NodeArray; - /** @internal */ - multiLine?: boolean | undefined; +// dprint-ignore +export class ArrayLiteralExpression extends Node implements PrimaryExpression { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstArrayLiteralExpression; + + get elements(): NodeArray { return this.ast.data.elements.nodes; } + + /** @internal */ set elements(value: NodeArray) { this.ast.data.elements = value.ast; } + /** @internal */ get multiLine(): boolean | undefined { return this.ast.data.multiLine; } + /** @internal */ set multiLine(value) { this.ast.data.multiLine = value; } } -export interface SpreadElement extends Expression { - readonly kind: SyntaxKind.SpreadElement; - readonly parent: ArrayLiteralExpression | CallExpression | NewExpression; - readonly expression: Expression; +// dprint-ignore +export class SpreadElement extends Node implements Expression { + declare _expressionBrand: any; + declare readonly ast: AstSpreadElement; + + override get parent() { return super.parent as ArrayLiteralExpression | CallExpression | NewExpression; } + + get expression(): Expression { return this.ast.data.expression.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } } +// TODO(rbuckton): Is this still needed? /** * This interface is a base interface for ObjectLiteralExpression and JSXAttributes to extend from. JSXAttributes is similar to * ObjectLiteralExpression in that it contains array of properties; however, JSXAttributes' properties can only be @@ -2948,25 +5115,67 @@ export interface SpreadElement extends Expression { * ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.) */ export interface ObjectLiteralExpressionBase extends PrimaryExpression, Declaration { + readonly ast: AstNode; readonly properties: NodeArray; } // An ObjectLiteralExpression is the declaration node for an anonymous symbol. -export interface ObjectLiteralExpression extends ObjectLiteralExpressionBase, JSDocContainer { - readonly kind: SyntaxKind.ObjectLiteralExpression; - /** @internal */ - multiLine?: boolean | undefined; +// dprint-ignore +export class ObjectLiteralExpression extends Node implements ObjectLiteralExpressionBase, JSDocContainer { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstObjectLiteralExpression; + + get properties(): NodeArray { return this.ast.data.properties.nodes; } + + /** @internal */ set properties(value) { this.ast.data.properties = value.ast; } + /** @internal */ get multiLine(): boolean | undefined { return this.ast.data.multiLine; } + /** @internal */ set multiLine(value) { this.ast.data.multiLine = value; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression; export type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression; export type AccessExpression = PropertyAccessExpression | ElementAccessExpression; -export interface PropertyAccessExpression extends MemberExpression, NamedDeclaration, JSDocContainer, FlowContainer { - readonly kind: SyntaxKind.PropertyAccessExpression; - readonly expression: LeftHandSideExpression; - readonly questionDotToken?: QuestionDotToken | undefined; - readonly name: MemberName; +// dprint-ignore +export class PropertyAccessExpression extends Node implements MemberExpression, NamedDeclaration, JSDocContainer, FlowContainer { + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstPropertyAccessExpression; + + get expression(): LeftHandSideExpression { return this.ast.data.expression.node; } + get questionDotToken(): QuestionDotToken | undefined { return this.ast.data.questionDotToken?.node; } + get name(): Identifier | PrivateIdentifier { return this.ast.data.name.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } /** @internal */ @@ -2974,8 +5183,15 @@ export interface PrivateIdentifierPropertyAccessExpression extends PropertyAcces readonly name: PrivateIdentifier; } +export interface JsxTagNamePropertyAccess extends PropertyAccessExpression { + readonly ast: AstJsxTagNamePropertyAccess; + readonly data: AstJsxTagNamePropertyAccessData; + readonly expression: Identifier | ThisExpression | JsxTagNamePropertyAccess; +} + export interface PropertyAccessChain extends PropertyAccessExpression { _optionalChainBrand: any; + readonly ast: AstPropertyAccessChain; readonly name: MemberName; } @@ -2995,15 +5211,38 @@ export interface PropertyAccessEntityNameExpression extends PropertyAccessExpres readonly name: Identifier; } -export interface ElementAccessExpression extends MemberExpression, Declaration, JSDocContainer, FlowContainer { - readonly kind: SyntaxKind.ElementAccessExpression; - readonly expression: LeftHandSideExpression; - readonly questionDotToken?: QuestionDotToken | undefined; - readonly argumentExpression: Expression; +// dprint-ignore +export class ElementAccessExpression extends Node implements MemberExpression, Declaration, JSDocContainer, FlowContainer { + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstElementAccessExpression; + + get expression(): LeftHandSideExpression { return this.ast.data.expression.node; } + get questionDotToken(): QuestionDotToken | undefined { return this.ast.data.questionDotToken?.node; } + get argumentExpression(): Expression { return this.ast.data.argumentExpression.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } + /** @internal */ set argumentExpression(value) { this.ast.data.argumentExpression = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } export interface ElementAccessChain extends ElementAccessExpression { _optionalChainBrand: any; + readonly ast: AstElementAccessChain; } /** @internal */ @@ -3018,16 +5257,33 @@ export interface SuperElementAccessExpression extends ElementAccessExpression { // see: https://tc39.github.io/ecma262/#prod-SuperProperty export type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; -export interface CallExpression extends LeftHandSideExpression, Declaration { - readonly kind: SyntaxKind.CallExpression; - readonly expression: LeftHandSideExpression; - readonly questionDotToken?: QuestionDotToken | undefined; - readonly typeArguments?: NodeArray | undefined; - readonly arguments: NodeArray; +// dprint-ignore +export class CallExpression extends Node implements LeftHandSideExpression, Declaration { + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare readonly ast: AstCallExpression; + + get expression(): LeftHandSideExpression { return this.ast.data.expression.node; } + get questionDotToken(): QuestionDotToken | undefined { return this.ast.data.questionDotToken?.node; } + get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + get arguments(): NodeArray { return this.ast.data.arguments.nodes; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ set arguments(value) { this.ast.data.arguments = value.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export interface CallChain extends CallExpression { _optionalChainBrand: any; + readonly ast: AstCallChain; } /** @internal */ @@ -3101,28 +5357,65 @@ export interface ImportCall extends CallExpression { readonly expression: ImportExpression; } -export interface ExpressionWithTypeArguments extends MemberExpression, NodeWithTypeArguments { - readonly kind: SyntaxKind.ExpressionWithTypeArguments; - readonly expression: LeftHandSideExpression; -} +// dprint-ignore +export class ExpressionWithTypeArguments extends Node implements MemberExpression, NodeWithTypeArguments { + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _typeNodeBrand: any; + declare readonly ast: AstExpressionWithTypeArguments; -export interface NewExpression extends PrimaryExpression, Declaration { - readonly kind: SyntaxKind.NewExpression; - readonly expression: LeftHandSideExpression; - readonly typeArguments?: NodeArray | undefined; - readonly arguments?: NodeArray | undefined; + get expression(): LeftHandSideExpression { return this.ast.data.expression.node; } + get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } } -export interface TaggedTemplateExpression extends MemberExpression { - readonly kind: SyntaxKind.TaggedTemplateExpression; - readonly tag: LeftHandSideExpression; - readonly typeArguments?: NodeArray | undefined; - readonly template: TemplateLiteral; - /** @internal */ questionDotToken?: QuestionDotToken | undefined; // NOTE: Invalid syntax, only used to report a grammar error. +// dprint-ignore +export class NewExpression extends Node implements PrimaryExpression, Declaration { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare readonly ast: AstNewExpression; + + get expression(): LeftHandSideExpression { return this.ast.data.expression.node; } + get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + get arguments(): NodeArray | undefined { return this.ast.data.arguments?.nodes; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ set arguments(value) { this.ast.data.arguments = value?.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface InstanceofExpression extends BinaryExpression { - readonly operatorToken: Token; +// dprint-ignore +export class TaggedTemplateExpression extends Node implements MemberExpression { + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstTaggedTemplateExpression; + + get tag(): LeftHandSideExpression { return this.ast.data.tag.node; } + get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + get template(): NoSubstitutionTemplateLiteral | TemplateExpression { return this.ast.data.template.node; } + + /** @internal */ set tag(value) { this.ast.data.tag = value.ast; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ set template(value) { this.ast.data.template = value.ast; } + /** @internal */ get questionDotToken(): QuestionDotToken | undefined { return this.ast.data.questionDotToken?.node; } + /** @internal */ set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } } export type CallLikeExpression = @@ -3133,43 +5426,86 @@ export type CallLikeExpression = | JsxOpeningLikeElement | InstanceofExpression; -export interface AsExpression extends Expression { - readonly kind: SyntaxKind.AsExpression; - readonly expression: Expression; - readonly type: TypeNode; -} +// dprint-ignore +export class AsExpression extends Node implements Expression { + declare _expressionBrand: any; + declare readonly ast: AstAsExpression; -export interface TypeAssertion extends UnaryExpression { - readonly kind: SyntaxKind.TypeAssertionExpression; - readonly type: TypeNode; - readonly expression: UnaryExpression; + get expression(): Expression { return this.ast.data.expression.node; } + get type(): TypeNode { return this.ast.data.type.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value.ast; } } -export interface SatisfiesExpression extends Expression { - readonly kind: SyntaxKind.SatisfiesExpression; - readonly expression: Expression; - readonly type: TypeNode; +// dprint-ignore +export class TypeAssertionExpression extends Node implements UnaryExpression { + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstTypeAssertion; + + get type(): TypeNode { return this.ast.data.type.node; } + get expression(): UnaryExpression { return this.ast.data.expression.node; } + + /** @internal */ set type(value) { this.ast.data.type = value.ast; } + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } } +/** @deprecated Use `TypeAssertionExpression` instead */ +export type TypeAssertion = TypeAssertionExpression; + export type AssertionExpression = - | TypeAssertion + | TypeAssertionExpression | AsExpression; -export interface NonNullExpression extends LeftHandSideExpression { - readonly kind: SyntaxKind.NonNullExpression; - readonly expression: Expression; +// dprint-ignore +export class SatisfiesExpression extends Node implements Expression { + declare _expressionBrand: any; + declare readonly ast: AstSatisfiesExpression; + + get expression(): Expression { return this.ast.data.expression.node; } + get type(): TypeNode { return this.ast.data.type.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value.ast; } +} + +// dprint-ignore +export class NonNullExpression extends Node implements LeftHandSideExpression { + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstNonNullExpression; + + get expression(): Expression { return this.ast.data.expression.node; } + + /** @internal */ set expression(value: Expression) { this.ast.data.expression = value.ast; } } export interface NonNullChain extends NonNullExpression { _optionalChainBrand: any; + readonly ast: AstNonNullChain; } -// NOTE: MetaProperty is really a MemberExpression, but we consider it a PrimaryExpression -// for the same reasons we treat NewExpression as a PrimaryExpression. -export interface MetaProperty extends PrimaryExpression, FlowContainer { - readonly kind: SyntaxKind.MetaProperty; - readonly keywordToken: SyntaxKind.NewKeyword | SyntaxKind.ImportKeyword; - readonly name: Identifier; +// dprint-ignore +export class MetaProperty extends Node implements PrimaryExpression, FlowContainer { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstMetaProperty; + + get keywordToken(): SyntaxKind.ImportKeyword | SyntaxKind.NewKeyword { return this.ast.data.keywordToken; } + get name(): Identifier { return this.ast.data.name.node; } + + /** @internal */ set keywordToken(value: SyntaxKind.ImportKeyword | SyntaxKind.NewKeyword) { this.ast.data.keywordToken = value; } + /** @internal */ set name(value: Identifier) { this.ast.data.name = value.ast; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value) { this.ast.data.flowNode = value; } } /** @internal */ @@ -3179,11 +5515,23 @@ export interface ImportMetaProperty extends MetaProperty { } /// A JSX expression of the form ... -export interface JsxElement extends PrimaryExpression { - readonly kind: SyntaxKind.JsxElement; - readonly openingElement: JsxOpeningElement; - readonly children: NodeArray; - readonly closingElement: JsxClosingElement; +// dprint-ignore +export class JsxElement extends Node implements PrimaryExpression { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstJsxElement; + + get openingElement(): JsxOpeningElement { return this.ast.data.openingElement.node; } + get children(): NodeArray { return this.ast.data.children.nodes; } + get closingElement(): JsxClosingElement { return this.ast.data.closingElement.node; } + + /** @internal */ set openingElement(value: JsxOpeningElement) { this.ast.data.openingElement = value.ast; } + /** @internal */ set children(value: NodeArray) { this.ast.data.children = value.ast; } + /** @internal */ set closingElement(value: JsxClosingElement) { this.ast.data.closingElement = value.ast; } } /// Either the opening tag in a ... pair or the lone in a self-closing form @@ -3205,65 +5553,142 @@ export type JsxTagNameExpression = | JsxTagNamePropertyAccess | JsxNamespacedName; -export interface JsxTagNamePropertyAccess extends PropertyAccessExpression { - readonly expression: Identifier | ThisExpression | JsxTagNamePropertyAccess; -} +// dprint-ignore +export class JsxAttributes extends Node implements PrimaryExpression, Declaration { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare readonly ast: AstJsxAttributes; -export interface JsxAttributes extends PrimaryExpression, Declaration { - readonly kind: SyntaxKind.JsxAttributes; - readonly properties: NodeArray; - readonly parent: JsxOpeningLikeElement; + override get parent() { return super.parent as JsxOpeningLikeElement; } + + get properties(): NodeArray { return this.ast.data.properties.nodes; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set properties(value) { this.ast.data.properties = value.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface JsxNamespacedName extends Node { - readonly kind: SyntaxKind.JsxNamespacedName; - readonly name: Identifier; - readonly namespace: Identifier; +// dprint-ignore +export class JsxNamespacedName extends Node { + declare readonly ast: AstJsxNamespacedName; + + get name(): Identifier { return this.ast.data.name.node; } + get namespace(): Identifier { return this.ast.data.namespace.node; } + + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set namespace(value) { this.ast.data.namespace = value.ast; } } +// TODO(rbuckton): Is this actually an expression or just a part of JsxElement? /// The opening element of a ... JsxElement -export interface JsxOpeningElement extends Expression { - readonly kind: SyntaxKind.JsxOpeningElement; - readonly parent: JsxElement; - readonly tagName: JsxTagNameExpression; - readonly typeArguments?: NodeArray | undefined; - readonly attributes: JsxAttributes; +// dprint-ignore +export class JsxOpeningElement extends Node implements Expression { + declare _expressionBrand: any; + declare readonly ast: AstJsxOpeningElement; + + override get parent() { return super.parent as JsxElement; } + + get tagName(): JsxTagNameExpression { return this.ast.data.tagName.node; } + get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + get attributes(): JsxAttributes { return this.ast.data.attributes.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set tagName(value) { this.ast.data.tagName = value.ast; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ set attributes(value) { this.ast.data.attributes = value.ast; } } /// A JSX expression of the form -export interface JsxSelfClosingElement extends PrimaryExpression { - readonly kind: SyntaxKind.JsxSelfClosingElement; - readonly tagName: JsxTagNameExpression; - readonly typeArguments?: NodeArray | undefined; - readonly attributes: JsxAttributes; +// dprint-ignore +export class JsxSelfClosingElement extends Node implements PrimaryExpression { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstJsxSelfClosingElement; + + get tagName(): JsxTagNameExpression { return this.ast.data.tagName.node; } + get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + get attributes(): JsxAttributes { return this.ast.data.attributes.node; } + + /** @internal */ set tagName(value) { this.ast.data.tagName = value.ast; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ set attributes(value) { this.ast.data.attributes = value.ast; } } /// A JSX expression of the form <>... -export interface JsxFragment extends PrimaryExpression { - readonly kind: SyntaxKind.JsxFragment; - readonly openingFragment: JsxOpeningFragment; - readonly children: NodeArray; - readonly closingFragment: JsxClosingFragment; +// dprint-ignore +export class JsxFragment extends Node implements PrimaryExpression { + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstJsxFragment; + + get openingFragment(): JsxOpeningFragment { return this.ast.data.openingFragment.node; } + get children(): NodeArray { return this.ast.data.children.nodes; } + get closingFragment(): JsxClosingFragment { return this.ast.data.closingFragment.node; } + + /** @internal */ set openingFragment(value: JsxOpeningFragment) { this.ast.data.openingFragment = value.ast; } + /** @internal */ set children(value: NodeArray) { this.ast.data.children = value.ast; } + /** @internal */ set closingFragment(value: JsxClosingFragment) { this.ast.data.closingFragment = value.ast; } } +// TODO(rbuckton): Is this actually an expression or just a part of JsxFragment? /// The opening element of a <>... JsxFragment -export interface JsxOpeningFragment extends Expression { - readonly kind: SyntaxKind.JsxOpeningFragment; - readonly parent: JsxFragment; +// dprint-ignore +export class JsxOpeningFragment extends Node implements Expression { + declare _expressionBrand: any; + declare readonly ast: AstJsxOpeningFragment; + + override get parent() { return super.parent as JsxFragment; } + + /** @internal */ override set parent(value) { super.parent = value; } } +// TODO(rbuckton): Is this actually an expression or just a part of JsxFragment? /// The closing element of a <>... JsxFragment -export interface JsxClosingFragment extends Expression { - readonly kind: SyntaxKind.JsxClosingFragment; - readonly parent: JsxFragment; +// dprint-ignore +export class JsxClosingFragment extends Node implements Expression { + declare _expressionBrand: any; + declare readonly ast: AstJsxClosingFragment; + + override get parent() { return super.parent as JsxFragment; } + + /** @internal */ override set parent(value) { super.parent = value; } } -export interface JsxAttribute extends Declaration { - readonly kind: SyntaxKind.JsxAttribute; - readonly parent: JsxAttributes; - readonly name: JsxAttributeName; - /// JSX attribute initializers are optional; is sugar for - readonly initializer?: JsxAttributeValue | undefined; +// dprint-ignore +export class JsxAttribute extends Node implements Declaration { + declare readonly ast: AstJsxAttribute; + + declare _declarationBrand: any; + + override get parent() { return super.parent as JsxAttributes; } + + get name(): JsxAttributeName { return this.ast.data.name.node; } + // JSX attribute initializers are optional; is sugar for + get initializer(): JsxAttributeValue | undefined { return this.ast.data.initializer?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set initializer(value) { this.ast.data.initializer = value?.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export type JsxAttributeValue = @@ -3273,29 +5698,69 @@ export type JsxAttributeValue = | JsxSelfClosingElement | JsxFragment; -export interface JsxSpreadAttribute extends ObjectLiteralElement { - readonly kind: SyntaxKind.JsxSpreadAttribute; - readonly parent: JsxAttributes; - readonly expression: Expression; +// TODO(rbuckton): Does this need to implement ObjectLiteralElement? +// dprint-ignore +export class JsxSpreadAttribute extends Node implements ObjectLiteralElement { + declare _objectLiteralBrand: any; + declare _declarationBrand: any; + declare readonly ast: AstJsxSpreadAttribute; + + /** @internal*/ declare symbol: never; // not actually a declaration + /** @internal*/ declare localSymbol: never; // not actually a declaration + + override get parent() { return super.parent as JsxAttributes; } + + get expression(): Expression { return this.ast.data.expression.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } } -export interface JsxClosingElement extends Node { - readonly kind: SyntaxKind.JsxClosingElement; - readonly parent: JsxElement; - readonly tagName: JsxTagNameExpression; +// TODO(rbuckton): Move adjacent to JsxOpeningElement +// dprint-ignore +export class JsxClosingElement extends Node { + declare readonly ast: AstJsxClosingElement; + + override get parent() { return super.parent as JsxElement; } + + get tagName(): JsxTagNameExpression { return this.ast.data.tagName.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set tagName(value) { this.ast.data.tagName = value.ast; } } -export interface JsxExpression extends Expression { - readonly kind: SyntaxKind.JsxExpression; - readonly parent: JsxElement | JsxFragment | JsxAttributeLike; - readonly dotDotDotToken?: Token | undefined; - readonly expression?: Expression | undefined; +// TODO(rbuckton): Is this actually an expression? +// dprint-ignore +export class JsxExpression extends Node implements Expression { + declare _expressionBrand: any; + declare readonly ast: AstJsxExpression; + + override get parent() { return super.parent as JsxElement | JsxFragment | JsxAttributeLike; } + + get dotDotDotToken(): DotDotDotToken | undefined { return this.ast.data.dotDotDotToken?.node; } + get expression(): Expression | undefined { return this.ast.data.expression?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set dotDotDotToken(value) { this.ast.data.dotDotDotToken = value?.ast; } + /** @internal */ set expression(value) { this.ast.data.expression = value?.ast; } } -export interface JsxText extends LiteralLikeNode { - readonly kind: SyntaxKind.JsxText; - readonly parent: JsxElement | JsxFragment; - readonly containsOnlyTriviaWhiteSpaces: boolean; +// dprint-ignore +export class JsxText extends Token implements LiteralLikeNode { + declare readonly ast: AstJsxText; + + override get parent() { return super.parent as JsxElement | JsxFragment; } + + get text(): string { return this.ast.data.text; } + get isUnterminated(): boolean | undefined { return this.ast.data.isUnterminated; } + get hasExtendedUnicodeEscape(): boolean | undefined { return this.ast.data.hasExtendedUnicodeEscape; } + get containsOnlyTriviaWhiteSpaces(): boolean { return this.ast.data.containsOnlyTriviaWhiteSpaces; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set text(value) { this.ast.data.text = value; } + /** @internal */ set isUnterminated(value) { this.ast.data.isUnterminated = value; } + /** @internal */ set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + /** @internal */ set containsOnlyTriviaWhiteSpaces(value) { this.ast.data.containsOnlyTriviaWhiteSpaces = value; } } export type JsxChild = @@ -3305,49 +5770,111 @@ export type JsxChild = | JsxSelfClosingElement | JsxFragment; -export interface Statement extends Node, JSDocContainer { +export interface Statement extends JSDocContainer { _statementBrand: any; + readonly ast: AstStatement; } // Represents a statement that is elided as part of a transformation to emit comments on a // not-emitted node. -export interface NotEmittedStatement extends Statement { - readonly kind: SyntaxKind.NotEmittedStatement; +// dprint-ignore +export class NotEmittedStatement extends Node implements Statement { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstNotEmittedStatement; + + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } } -export interface NotEmittedTypeElement extends TypeElement { - readonly kind: SyntaxKind.NotEmittedTypeElement; +// TODO(rbuckton): Move adjacent to other type elements +// dprint-ignore +export class NotEmittedTypeElement extends Node implements TypeElement { + declare _typeElementBrand: any; + declare _declarationBrand: any; + declare readonly ast: AstNotEmittedTypeElement; + + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value: Symbol) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value: Symbol | undefined) { this.ast.data.localSymbol = value; } } /** * A list of comma-separated expressions. This node is only created by transformations. */ -export interface CommaListExpression extends Expression { - readonly kind: SyntaxKind.CommaListExpression; - readonly elements: NodeArray; +// dprint-ignore +export class CommaListExpression extends Node implements Expression { + declare _expressionBrand: any; + declare readonly ast: AstCommaListExpression; + + get elements(): NodeArray { return this.ast.data.elements.nodes; } + + /** @internal */ set elements(value: NodeArray) { this.ast.data.elements = value.ast; } } /** @internal */ -export interface SyntheticReferenceExpression extends LeftHandSideExpression { - readonly kind: SyntaxKind.SyntheticReferenceExpression; - readonly expression: Expression; - readonly thisArg: Expression; -} +// dprint-ignore +export class SyntheticReferenceExpression extends Node implements LeftHandSideExpression { + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstSyntheticReferenceExpression; -export interface EmptyStatement extends Statement { - readonly kind: SyntaxKind.EmptyStatement; + get expression(): Expression { return this.ast.data.expression.node; } + /** @internal */ set expression(value: Expression) { this.ast.data.expression = value.ast; } + get thisArg(): Expression { return this.ast.data.thisArg.node; } + /** @internal */ set thisArg(value: Expression) { this.ast.data.thisArg = value.ast; } } -export interface DebuggerStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.DebuggerStatement; +// dprint-ignore +export class EmptyStatement extends Node implements Statement, JSDocContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstEmptyStatement; + + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } } -export interface MissingDeclaration extends DeclarationStatement, PrimaryExpression { - readonly kind: SyntaxKind.MissingDeclaration; - readonly name?: Identifier | undefined; +// dprint-ignore +export class DebuggerStatement extends Node implements Statement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstDebuggerStatement; - // The following properties are used only to report grammar errors - /** @internal */ readonly modifiers?: NodeArray | undefined; + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } +} + +// dprint-ignore +export class MissingDeclaration extends Node implements DeclarationStatement { + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstMissingDeclaration; + + get name(): Identifier | undefined { return this.ast.data.name?.node; } + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + + /** @internal */ set name(value) { this.ast.data.name = value?.ast; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export type BlockLike = @@ -3356,21 +5883,58 @@ export type BlockLike = | ModuleBlock | CaseOrDefaultClause; -export interface Block extends Statement, LocalsContainer { - readonly kind: SyntaxKind.Block; - readonly statements: NodeArray; - /** @internal */ multiLine?: boolean | undefined; +// dprint-ignore +export class Block extends Node implements Statement, LocalsContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstBlock; + + get statements(): NodeArray { return this.ast.data.statements.nodes; } + + /** @internal */ set statements(value) { this.ast.data.statements = value.ast; } + /** @internal */ get multiLine(): boolean | undefined { return this.ast.data.multiLine; } + /** @internal */ set multiLine(value) { this.ast.data.multiLine = value; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } -export interface VariableStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.VariableStatement; - readonly modifiers?: NodeArray | undefined; - readonly declarationList: VariableDeclarationList; +// dprint-ignore +export class VariableStatement extends Node implements Statement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstVariableStatement; + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get declarationList(): VariableDeclarationList { return this.ast.data.declarationList.node; } + + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set declarationList(value) { this.ast.data.declarationList = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface ExpressionStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.ExpressionStatement; - readonly expression: Expression; +// dprint-ignore +export class ExpressionStatement extends Node implements Statement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstExpressionStatement; + + get expression(): Expression { return this.ast.data.expression.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } /** @internal */ @@ -3378,135 +5942,368 @@ export interface PrologueDirective extends ExpressionStatement { readonly expression: StringLiteral; } -export interface IfStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.IfStatement; - readonly expression: Expression; - readonly thenStatement: Statement; - readonly elseStatement?: Statement | undefined; +// dprint-ignore +export class IfStatement extends Node implements Statement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstIfStatement; + + get expression(): Expression { return this.ast.data.expression.node; } + get thenStatement(): Statement { return this.ast.data.thenStatement.node; } + get elseStatement(): Statement | undefined { return this.ast.data.elseStatement?.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set thenStatement(value) { this.ast.data.thenStatement = value.ast; } + /** @internal */ set elseStatement(value) { this.ast.data.elseStatement = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } export interface IterationStatement extends Statement { readonly statement: Statement; } -export interface DoStatement extends IterationStatement, FlowContainer { - readonly kind: SyntaxKind.DoStatement; - readonly expression: Expression; +// dprint-ignore +export class DoStatement extends Node implements IterationStatement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstDoStatement; + + get statement(): Statement { return this.ast.data.statement.node; } + get expression(): Expression { return this.ast.data.expression.node; } + + /** @internal */ set statement(value) { this.ast.data.statement = value.ast; } + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface WhileStatement extends IterationStatement, FlowContainer { - readonly kind: SyntaxKind.WhileStatement; - readonly expression: Expression; +// dprint-ignore +export class WhileStatement extends Node implements IterationStatement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstWhileStatement; + + get expression(): Expression { return this.ast.data.expression.node; } + get statement(): Statement { return this.ast.data.statement.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set statement(value) { this.ast.data.statement = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } export type ForInitializer = | VariableDeclarationList | Expression; -export interface ForStatement extends IterationStatement, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.ForStatement; - readonly initializer?: ForInitializer | undefined; - readonly condition?: Expression | undefined; - readonly incrementor?: Expression | undefined; +// dprint-ignore +export class ForStatement extends Node implements IterationStatement, LocalsContainer, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstForStatement; + + get initializer(): ForInitializer | undefined { return this.ast.data.initializer?.node; } + get condition(): Expression | undefined { return this.ast.data.condition?.node; } + get incrementor(): Expression | undefined { return this.ast.data.incrementor?.node; } + get statement(): Statement { return this.ast.data.statement.node; } + + /** @internal */ set initializer(value) { this.ast.data.initializer = value?.ast; } + /** @internal */ set condition(value) { this.ast.data.condition = value?.ast; } + /** @internal */ set incrementor(value) { this.ast.data.incrementor = value?.ast; } + /** @internal */ set statement(value) { this.ast.data.statement = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } export type ForInOrOfStatement = | ForInStatement | ForOfStatement; -export interface ForInStatement extends IterationStatement, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.ForInStatement; - readonly initializer: ForInitializer; - readonly expression: Expression; +// dprint-ignore +export class ForInStatement extends Node implements IterationStatement, LocalsContainer, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstForInStatement; + + get initializer(): ForInitializer { return this.ast.data.initializer.node; } + get expression(): Expression { return this.ast.data.expression.node; } + get statement(): Statement { return this.ast.data.statement.node; } + + /** @internal */ set initializer(value) { this.ast.data.initializer = value.ast; } + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set statement(value) { this.ast.data.statement = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface ForOfStatement extends IterationStatement, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.ForOfStatement; - readonly awaitModifier?: AwaitKeyword | undefined; - readonly initializer: ForInitializer; - readonly expression: Expression; +// dprint-ignore +export class ForOfStatement extends Node implements IterationStatement, LocalsContainer, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstForOfStatement; + + get awaitModifier(): AwaitKeyword | undefined { return this.ast.data.awaitModifier?.node; } + get initializer(): ForInitializer { return this.ast.data.initializer.node; } + get expression(): Expression { return this.ast.data.expression.node; } + get statement(): Statement { return this.ast.data.statement.node; } + + /** @internal */ set awaitModifier(value) { this.ast.data.awaitModifier = value?.ast; } + /** @internal */ set initializer(value) { this.ast.data.initializer = value.ast; } + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set statement(value) { this.ast.data.statement = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface BreakStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.BreakStatement; - readonly label?: Identifier | undefined; +// dprint-ignore +export class BreakStatement extends Node implements Statement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstBreakStatement; + + get label(): Identifier | undefined { return this.ast.data.label?.node; } + + /** @internal */ set label(value) { this.ast.data.label = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface ContinueStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.ContinueStatement; - readonly label?: Identifier | undefined; +// dprint-ignore +export class ContinueStatement extends Node implements Statement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstContinueStatement; + + get label(): Identifier | undefined { return this.ast.data.label?.node; } + + /** @internal */ set label(value) { this.ast.data.label = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } export type BreakOrContinueStatement = | BreakStatement | ContinueStatement; -export interface ReturnStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.ReturnStatement; - readonly expression?: Expression | undefined; +// dprint-ignore +export class ReturnStatement extends Node implements Statement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstReturnStatement; + + get expression(): Expression | undefined { return this.ast.data.expression?.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface WithStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.WithStatement; - readonly expression: Expression; - readonly statement: Statement; +// dprint-ignore +export class WithStatement extends Node implements Statement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstWithStatement; + + get expression(): Expression { return this.ast.data.expression.node; } + get statement(): Statement { return this.ast.data.statement.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set statement(value) { this.ast.data.statement = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface SwitchStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.SwitchStatement; - readonly expression: Expression; - readonly caseBlock: CaseBlock; - possiblyExhaustive?: boolean | undefined; // initialized by binding +// dprint-ignore +export class SwitchStatement extends Node implements Statement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstSwitchStatement; + + get expression(): Expression { return this.ast.data.expression.node; } + get caseBlock(): CaseBlock { return this.ast.data.caseBlock.node; } + get possiblyExhaustive(): boolean | undefined { return this.ast.data.possiblyExhaustive; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set caseBlock(value) { this.ast.data.caseBlock = value.ast; } + /** @internal */ set possiblyExhaustive(value) { this.ast.data.possiblyExhaustive = value; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface CaseBlock extends Node, LocalsContainer { - readonly kind: SyntaxKind.CaseBlock; - readonly parent: SwitchStatement; - readonly clauses: NodeArray; +// dprint-ignore +export class CaseBlock extends Node implements LocalsContainer { + declare _localsContainerBrand: any; + declare readonly ast: AstCaseBlock; + + override get parent() { return super.parent as SwitchStatement; } + + get clauses(): NodeArray { return this.ast.data.clauses.nodes; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set clauses(value) { this.ast.data.clauses = value.ast; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } -export interface CaseClause extends Node, JSDocContainer { - readonly kind: SyntaxKind.CaseClause; - readonly parent: CaseBlock; - readonly expression: Expression; - readonly statements: NodeArray; - /** @internal */ fallthroughFlowNode?: FlowNode | undefined; +// dprint-ignore +export class CaseClause extends Node implements JSDocContainer { + declare _jsdocContainerBrand: any; + declare readonly ast: AstCaseClause; + + override get parent() { return super.parent as CaseBlock; } + + get expression(): Expression { return this.ast.data.expression.node; } + get statements(): NodeArray { return this.ast.data.statements.nodes; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ set statements(value) { this.ast.data.statements = value.ast; } + /** @internal */ get fallthroughFlowNode(): FlowNode | undefined { return this.ast.data.fallthroughFlowNode; } + /** @internal */ set fallthroughFlowNode(value) { this.ast.data.fallthroughFlowNode = value; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } } -export interface DefaultClause extends Node { - readonly kind: SyntaxKind.DefaultClause; - readonly parent: CaseBlock; - readonly statements: NodeArray; - /** @internal */ fallthroughFlowNode?: FlowNode | undefined; +// dprint-ignore +export class DefaultClause extends Node { + declare readonly ast: AstDefaultClause; + + override get parent() { return super.parent as CaseBlock; } + + get statements(): NodeArray { return this.ast.data.statements.nodes; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set statements(value) { this.ast.data.statements = value.ast; } + /** @internal */ get fallthroughFlowNode(): FlowNode | undefined { return this.ast.data.fallthroughFlowNode; } + /** @internal */ set fallthroughFlowNode(value) { this.ast.data.fallthroughFlowNode = value; } } export type CaseOrDefaultClause = | CaseClause | DefaultClause; -export interface LabeledStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.LabeledStatement; - readonly label: Identifier; - readonly statement: Statement; +// dprint-ignore +export class LabeledStatement extends Node implements Statement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstLabeledStatement; + + get label(): Identifier { return this.ast.data.label.node; } + get statement(): Statement { return this.ast.data.statement.node; } + + /** @internal */ set label(value) { this.ast.data.label = value.ast; } + /** @internal */ set statement(value) { this.ast.data.statement = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface ThrowStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.ThrowStatement; - readonly expression: Expression; +// dprint-ignore +export class ThrowStatement extends Node implements Statement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstThrowStatement; + + get expression(): Expression { return this.ast.data.expression.node; } + + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface TryStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.TryStatement; - readonly tryBlock: Block; - readonly catchClause?: CatchClause | undefined; - readonly finallyBlock?: Block | undefined; +// dprint-ignore +export class TryStatement extends Node implements Statement, FlowContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; + declare readonly ast: AstTryStatement; + + get tryBlock(): Block { return this.ast.data.tryBlock.node; } + get catchClause(): CatchClause | undefined { return this.ast.data.catchClause?.node; } + get finallyBlock(): Block | undefined { return this.ast.data.finallyBlock?.node; } + + /** @internal */ set tryBlock(value) { this.ast.data.tryBlock = value.ast; } + /** @internal */ set catchClause(value) { this.ast.data.catchClause = value?.ast; } + /** @internal */ set finallyBlock(value) { this.ast.data.finallyBlock = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get flowNode(): FlowNode | undefined { return this.ast.data.flowNode; } + /** @internal */ set flowNode(value: FlowNode | undefined) { this.ast.data.flowNode = value; } } -export interface CatchClause extends Node, LocalsContainer { - readonly kind: SyntaxKind.CatchClause; - readonly parent: TryStatement; - readonly variableDeclaration?: VariableDeclaration | undefined; - readonly block: Block; +// dprint-ignore +export class CatchClause extends Node implements LocalsContainer { + declare _localsContainerBrand: any; + declare readonly ast: AstCatchClause; + + override get parent() { return super.parent as TryStatement; } + + get variableDeclaration(): VariableDeclaration | undefined { return this.ast.data.variableDeclaration?.node; } + get block(): Block { return this.ast.data.block.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set variableDeclaration(value) { this.ast.data.variableDeclaration = value?.ast; } + /** @internal */ set block(value) { this.ast.data.block = value.ast; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } export type ObjectTypeDeclaration = @@ -3528,6 +6325,7 @@ export type DeclarationWithTypeParameterChildren = | JSDocTemplateTag; export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { + readonly ast: AstNode; readonly kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; readonly name?: Identifier | undefined; readonly typeParameters?: NodeArray | undefined; @@ -3535,71 +6333,196 @@ export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContain readonly members: NodeArray; } -export interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatement { - readonly kind: SyntaxKind.ClassDeclaration; - readonly modifiers?: NodeArray | undefined; - /** May be undefined in `export default class { ... }`. */ - readonly name?: Identifier | undefined; +// dprint-ignore +export class ClassDeclaration extends Node implements ClassLikeDeclarationBase, DeclarationStatement { + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstClassDeclaration; + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): Identifier | undefined { return this.ast.data.name?.node; } + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get heritageClauses(): NodeArray | undefined { return this.ast.data.heritageClauses?.nodes; } + get members(): NodeArray { return this.ast.data.members.nodes; } + + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value?.ast; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set heritageClauses(value) { this.ast.data.heritageClauses = value?.ast; } + /** @internal */ set members(value: NodeArray) { this.ast.data.members = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpression { - readonly kind: SyntaxKind.ClassExpression; - readonly modifiers?: NodeArray | undefined; +// dprint-ignore +export class ClassExpression extends Node implements ClassLikeDeclarationBase, PrimaryExpression { + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare readonly ast: AstClassExpression; + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + /** May be undefined in `export default class { ... }`. */ + get name(): Identifier | undefined { return this.ast.data.name?.node; } + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get heritageClauses(): NodeArray | undefined { return this.ast.data.heritageClauses?.nodes; } + get members(): NodeArray { return this.ast.data.members.nodes; } + + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value?.ast; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set heritageClauses(value) { this.ast.data.heritageClauses = value?.ast; } + /** @internal */ set members(value) { this.ast.data.members = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export type ClassLikeDeclaration = | ClassDeclaration | ClassExpression; -export interface ClassElement extends NamedDeclaration { +export interface ClassElement extends Declaration { _classElementBrand: any; + readonly ast: AstClassElement; + + // TODO(rbuckton): remove this? readonly name?: PropertyName | undefined; } -export interface TypeElement extends NamedDeclaration { +export interface TypeElement extends Declaration { _typeElementBrand: any; + readonly ast: AstTypeElement; + + // TODO(rbuckton): remove these? readonly name?: PropertyName | undefined; readonly questionToken?: QuestionToken | undefined; } -export interface InterfaceDeclaration extends DeclarationStatement, JSDocContainer { - readonly kind: SyntaxKind.InterfaceDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: Identifier; - readonly typeParameters?: NodeArray | undefined; - readonly heritageClauses?: NodeArray | undefined; - readonly members: NodeArray; +// dprint-ignore +export class InterfaceDeclaration extends Node implements DeclarationStatement, JSDocContainer { + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstInterfaceDeclaration; + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): Identifier { return this.ast.data.name.node; } + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get heritageClauses(): NodeArray | undefined { return this.ast.data.heritageClauses?.nodes; } + get members(): NodeArray { return this.ast.data.members.nodes; } + + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set heritageClauses(value) { this.ast.data.heritageClauses = value?.ast; } + /** @internal */ set members(value) { this.ast.data.members = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface HeritageClause extends Node { - readonly kind: SyntaxKind.HeritageClause; - readonly parent: InterfaceDeclaration | ClassLikeDeclaration; - readonly token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; - readonly types: NodeArray; +// dprint-ignore +export class HeritageClause extends Node { + declare readonly ast: AstHeritageClause; + + override get parent() { return super.parent as InterfaceDeclaration | ClassLikeDeclaration; } + + get token(): SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword { return this.ast.data.token; } + get types(): NodeArray { return this.ast.data.types.nodes; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set token(value) { this.ast.data.token = value; } + /** @internal */ set types(value) { this.ast.data.types = value.ast; } } -export interface TypeAliasDeclaration extends DeclarationStatement, JSDocContainer, LocalsContainer { - readonly kind: SyntaxKind.TypeAliasDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: Identifier; - readonly typeParameters?: NodeArray | undefined; - readonly type: TypeNode; +// dprint-ignore +export class TypeAliasDeclaration extends Node implements DeclarationStatement, JSDocContainer, LocalsContainer { + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstTypeAliasDeclaration; + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): Identifier { return this.ast.data.name.node; } + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get type(): TypeNode { return this.ast.data.type.node; } + + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set type(value) { this.ast.data.type = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } -export interface EnumMember extends NamedDeclaration, JSDocContainer { - readonly kind: SyntaxKind.EnumMember; - readonly parent: EnumDeclaration; - // This does include ComputedPropertyName, but the parser will give an error - // if it parses a ComputedPropertyName in an EnumMember - readonly name: PropertyName; - readonly initializer?: Expression | undefined; +// dprint-ignore +export class EnumMember extends Node implements NamedDeclaration, JSDocContainer { + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstEnumMember; + + override get parent() { return super.parent as EnumDeclaration; } + + get name(): PropertyName { return this.ast.data.name.node; } + get initializer(): Expression | undefined { return this.ast.data.initializer?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set initializer(value) { this.ast.data.initializer = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface EnumDeclaration extends DeclarationStatement, JSDocContainer { - readonly kind: SyntaxKind.EnumDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: Identifier; - readonly members: NodeArray; +// dprint-ignore +export class EnumDeclaration extends Node implements DeclarationStatement, JSDocContainer { + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstEnumDeclaration; + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): Identifier { return this.ast.data.name.node; } + get members(): NodeArray { return this.ast.data.members.nodes; } + + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set members(value) { this.ast.data.members = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export type ModuleName = @@ -3610,17 +6533,40 @@ export type ModuleBody = | NamespaceBody | JSDocNamespaceBody; +// TODO(rbuckton): Move after ModuleDeclaration /** @internal */ export interface AmbientModuleDeclaration extends ModuleDeclaration { - readonly body?: ModuleBlock | undefined; + readonly body: ModuleBlock | undefined; } -export interface ModuleDeclaration extends DeclarationStatement, JSDocContainer, LocalsContainer { - readonly kind: SyntaxKind.ModuleDeclaration; - readonly parent: ModuleBody | SourceFile; - readonly modifiers?: NodeArray | undefined; - readonly name: ModuleName; - readonly body?: ModuleBody | JSDocNamespaceDeclaration | undefined; +// dprint-ignore +export class ModuleDeclaration extends Node implements DeclarationStatement, JSDocContainer, LocalsContainer { + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstModuleDeclaration; + + override get parent() { return super.parent as ModuleDeclaration | ModuleBlock | SourceFile; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): ModuleName { return this.ast.data.name.node; } + get body(): ModuleBody | JSDocNamespaceDeclaration | undefined { return this.ast.data.body?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set body(value) { this.ast.data.body = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } export type NamespaceBody = @@ -3628,6 +6574,8 @@ export type NamespaceBody = | NamespaceDeclaration; export interface NamespaceDeclaration extends ModuleDeclaration { + readonly ast: AstNamespaceDeclaration; + readonly data: AstNamespaceDeclarationData; readonly name: Identifier; readonly body: NamespaceBody; } @@ -3636,15 +6584,28 @@ export type JSDocNamespaceBody = | Identifier | JSDocNamespaceDeclaration; -export interface JSDocNamespaceDeclaration extends ModuleDeclaration { - readonly name: Identifier; - readonly body?: JSDocNamespaceBody | undefined; -} +export interface JSDocNamespaceDeclaration extends ModuleDeclaration { + readonly ast: AstJSDocNamespaceDeclaration; + readonly data: AstJSDocNamespaceDeclarationData; + readonly name: Identifier; + readonly body: JSDocNamespaceBody | undefined; +} + +// TODO(rbuckton): Is this actually a Statement? +// dprint-ignore +export class ModuleBlock extends Node implements Statement, JSDocContainer { + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstModuleBlock; + + override get parent() { return super.parent as ModuleDeclaration; } + + get statements(): NodeArray { return this.ast.data.statements.nodes; } -export interface ModuleBlock extends Node, Statement { - readonly kind: SyntaxKind.ModuleBlock; - readonly parent: ModuleDeclaration; - readonly statements: NodeArray; + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set statements(value) { this.ast.data.statements = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } } export type ModuleReference = @@ -3656,37 +6617,80 @@ export type ModuleReference = * - import x = require("mod"); * - import x = M.x; */ -export interface ImportEqualsDeclaration extends DeclarationStatement, JSDocContainer { - readonly kind: SyntaxKind.ImportEqualsDeclaration; - readonly parent: SourceFile | ModuleBlock; - readonly modifiers?: NodeArray | undefined; - readonly name: Identifier; - readonly isTypeOnly: boolean; +// dprint-ignore +export class ImportEqualsDeclaration extends Node implements DeclarationStatement, JSDocContainer { + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstImportEqualsDeclaration; + + override get parent() { return super.parent as ModuleBlock | SourceFile; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get name(): Identifier { return this.ast.data.name.node; } + get isTypeOnly(): boolean { return this.ast.data.isTypeOnly; } + /** + * 'EntityName' for an internal module reference, 'ExternalModuleReference' for an external module reference. + */ + get moduleReference(): ModuleReference { return this.ast.data.moduleReference.node; } - // 'EntityName' for an internal module reference, 'ExternalModuleReference' for an external - // module reference. - readonly moduleReference: ModuleReference; + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } + /** @internal */ set moduleReference(value) { this.ast.data.moduleReference = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface ExternalModuleReference extends Node { - readonly kind: SyntaxKind.ExternalModuleReference; - readonly parent: ImportEqualsDeclaration; - readonly expression: Expression; +// dprint-ignore +export class ExternalModuleReference extends Node { + declare readonly ast: AstExternalModuleReference; + + override get parent() { return super.parent as ImportEqualsDeclaration; } + + get expression(): Expression { return this.ast.data.expression.node; } + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } } // In case of: // import "mod" => importClause = undefined, moduleSpecifier = "mod" // In rest of the cases, module specifier is string literal corresponding to module // ImportClause information is shown at its declaration below. -export interface ImportDeclaration extends Statement { - readonly kind: SyntaxKind.ImportDeclaration; - readonly parent: SourceFile | ModuleBlock; - readonly modifiers?: NodeArray | undefined; - readonly importClause?: ImportClause | undefined; +// dprint-ignore +export class ImportDeclaration extends Node implements Declaration, JSDocContainer { + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstImportDeclaration; + + override get parent() { return super.parent as ModuleBlock | SourceFile; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get importClause(): ImportClause | undefined { return this.ast.data.importClause?.node; } /** If this is not a StringLiteral it will be a grammar error. */ - readonly moduleSpecifier: Expression; - /** @deprecated */ readonly assertClause?: AssertClause | undefined; - readonly attributes?: ImportAttributes | undefined; + get moduleSpecifier(): Expression { return this.ast.data.moduleSpecifier.node; } + /** @deprecated */ + get assertClause(): ImportAttributes | undefined { return this.ast.data.attributes?.node; } + get attributes(): ImportAttributes | undefined { return this.ast.data.attributes?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set importClause(value) { this.ast.data.importClause = value?.ast; } + /** @internal */ set moduleSpecifier(value) { this.ast.data.moduleSpecifier = value.ast; } + /** @internal */ set attributes(value) { this.ast.data.attributes = value?.ast; } + /** @internal */ set assertClause(value) { this.ast.data.attributes = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export type NamedImportBindings = @@ -3703,12 +6707,25 @@ export type NamedExportBindings = // import d, * as ns from "mod" => name = d, namedBinding: NamespaceImport = { name: ns } // import { a, b as x } from "mod" => name = undefined, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} // import d, { a, b as x } from "mod" => name = d, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} -export interface ImportClause extends NamedDeclaration { - readonly kind: SyntaxKind.ImportClause; - readonly parent: ImportDeclaration | JSDocImportTag; - readonly isTypeOnly: boolean; - readonly name?: Identifier | undefined; // Default binding - readonly namedBindings?: NamedImportBindings | undefined; +// dprint-ignore +export class ImportClause extends Node implements NamedDeclaration { + declare _declarationBrand: any; + declare readonly ast: AstImportClause; + + override get parent() { return super.parent as ImportDeclaration | JSDocImportTag; } + + get isTypeOnly(): boolean { return this.ast.data.isTypeOnly; } + get name(): Identifier | undefined { return this.ast.data.name?.node; } + get namedBindings(): NamedImportBindings | undefined { return this.ast.data.namedBindings?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } + /** @internal */ set name(value) { this.ast.data.name = value?.ast; } + /** @internal */ set namedBindings(value) { this.ast.data.namedBindings = value?.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } /** @deprecated */ @@ -3722,82 +6739,204 @@ export interface AssertClause extends ImportAttributes {} export type ImportAttributeName = Identifier | StringLiteral; -export interface ImportAttribute extends Node { - readonly kind: SyntaxKind.ImportAttribute; - readonly parent: ImportAttributes; - readonly name: ImportAttributeName; - readonly value: Expression; +// dprint-ignore +export class ImportAttribute extends Node { + declare readonly ast: AstImportAttribute; + + override get parent() { return super.parent as ImportAttributes; } + + get name(): ImportAttributeName { return this.ast.data.name.node; } + get value(): Expression { return this.ast.data.value.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set value(value) { this.ast.data.value = value.ast; } } -export interface ImportAttributes extends Node { - readonly kind: SyntaxKind.ImportAttributes; - readonly token: SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword; - readonly parent: ImportDeclaration | ExportDeclaration; - readonly elements: NodeArray; - readonly multiLine?: boolean | undefined; +// dprint-ignore +export class ImportAttributes extends Node { + declare readonly ast: AstImportAttributes; + + override get parent() { return super.parent as ImportDeclaration | ExportDeclaration; } + + get token(): SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword { return this.ast.data.token; } + get elements(): NodeArray { return this.ast.data.elements.nodes; } + // TODO(rbuckton): Should this be internal like Block, ObjectLiteralExpression, etc.? + get multiLine(): boolean | undefined { return this.ast.data.multiLine; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set token(value) { this.ast.data.token = value; } + /** @internal */ set elements(value) { this.ast.data.elements = value.ast; } + /** @internal */ set multiLine(value) { this.ast.data.multiLine = value; } } -export interface NamespaceImport extends NamedDeclaration { - readonly kind: SyntaxKind.NamespaceImport; - readonly parent: ImportClause; - readonly name: Identifier; +// dprint-ignore +export class NamespaceImport extends Node implements NamedDeclaration { + declare _declarationBrand: any; + declare readonly ast: AstNamespaceImport; + + override get parent() { return super.parent as ImportClause; } + + get name(): Identifier { return this.ast.data.name.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface NamespaceExport extends NamedDeclaration { - readonly kind: SyntaxKind.NamespaceExport; - readonly parent: ExportDeclaration; - readonly name: ModuleExportName; +// dprint-ignore +export class NamespaceExport extends Node implements NamedDeclaration { + declare _declarationBrand: any; + declare readonly ast: AstNamespaceExport; + + override get parent() { return super.parent as ExportDeclaration; } + + get name(): ModuleExportName { return this.ast.data.name.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface NamespaceExportDeclaration extends DeclarationStatement, JSDocContainer { - readonly kind: SyntaxKind.NamespaceExportDeclaration; - readonly name: Identifier; +// dprint-ignore +export class NamespaceExportDeclaration extends Node implements DeclarationStatement, JSDocContainer { + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstNamespaceExportDeclaration; + + get name(): Identifier { return this.ast.data.name.node; } - // The following properties are used only to report grammar errors (see `isGrammarError` in utilities.ts) - /** @internal */ readonly modifiers?: NodeArray | undefined; + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface ExportDeclaration extends DeclarationStatement, JSDocContainer { - readonly kind: SyntaxKind.ExportDeclaration; - readonly parent: SourceFile | ModuleBlock; - readonly modifiers?: NodeArray | undefined; - readonly isTypeOnly: boolean; - /** Will not be assigned in the case of `export * from "foo";` */ - readonly exportClause?: NamedExportBindings | undefined; - /** If this is not a StringLiteral it will be a grammar error. */ - readonly moduleSpecifier?: Expression | undefined; - /** @deprecated */ readonly assertClause?: AssertClause | undefined; - readonly attributes?: ImportAttributes | undefined; +// dprint-ignore +export class ExportDeclaration extends Node implements DeclarationStatement, JSDocContainer { + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstExportDeclaration; + + override get parent() { return super.parent as SourceFile | ModuleBlock; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get isTypeOnly(): boolean { return this.ast.data.isTypeOnly; } + get exportClause(): NamedExportBindings | undefined { return this.ast.data.exportClause?.node; } + get moduleSpecifier(): Expression | undefined { return this.ast.data.moduleSpecifier?.node; } + /** @deprecated */ + get assertClause(): ImportAttributes | undefined { return this.ast.data.attributes?.node; } + get attributes(): ImportAttributes | undefined { return this.ast.data.attributes?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } + /** @internal */ set exportClause(value) { this.ast.data.exportClause = value?.ast; } + /** @internal */ set moduleSpecifier(value) { this.ast.data.moduleSpecifier = value?.ast; } + /** @internal */ set attributes(value) { this.ast.data.attributes = value?.ast; } + /** @internal */ set assertClause(value) { this.ast.data.attributes = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface NamedImports extends Node { - readonly kind: SyntaxKind.NamedImports; - readonly parent: ImportClause; - readonly elements: NodeArray; +// dprint-ignore +export class NamedImports extends Node { + declare readonly ast: AstNamedImports; + + override get parent() { return super.parent as ImportClause; } + + get elements(): NodeArray { return this.ast.data.elements.nodes; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set elements(value) { this.ast.data.elements = value.ast; } } -export interface NamedExports extends Node { - readonly kind: SyntaxKind.NamedExports; - readonly parent: ExportDeclaration; - readonly elements: NodeArray; +// dprint-ignore +export class NamedExports extends Node { + declare readonly ast: AstNamedExports; + + override get parent() { return super.parent as ExportDeclaration; } + + get elements(): NodeArray { return this.ast.data.elements.nodes; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set elements(value) { this.ast.data.elements = value.ast; } } export type NamedImportsOrExports = NamedImports | NamedExports; -export interface ImportSpecifier extends NamedDeclaration { - readonly kind: SyntaxKind.ImportSpecifier; - readonly parent: NamedImports; - readonly propertyName?: ModuleExportName | undefined; // Name preceding "as" keyword (or undefined when "as" is absent) - readonly name: Identifier; // Declared name - readonly isTypeOnly: boolean; +// dprint-ignore +export class ImportSpecifier extends Node implements NamedDeclaration { + declare _declarationBrand: any; + declare readonly ast: AstImportSpecifier; + + override get parent() { return super.parent as NamedImports; } + + get isTypeOnly(): boolean { return this.ast.data.isTypeOnly; } + /** + * Name preceding "as" keyword (or undefined when "as" is absent) + */ + get propertyName(): ModuleExportName | undefined { return this.ast.data.propertyName?.node; } + /** + * Declared name + */ + get name(): Identifier { return this.ast.data.name.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set propertyName(value) { this.ast.data.propertyName = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface ExportSpecifier extends NamedDeclaration, JSDocContainer { - readonly kind: SyntaxKind.ExportSpecifier; - readonly parent: NamedExports; - readonly isTypeOnly: boolean; - readonly propertyName?: ModuleExportName | undefined; // Name preceding "as" keyword (or undefined when "as" is absent) - readonly name: ModuleExportName; // Declared name +// dprint-ignore +export class ExportSpecifier extends Node implements NamedDeclaration, JSDocContainer { + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstExportSpecifier; + + override get parent() { return super.parent as NamedExports; } + + get isTypeOnly(): boolean { return this.ast.data.isTypeOnly; } + /** + * Name preceding "as" keyword (or undefined when "as" is absent) + */ + get propertyName(): ModuleExportName | undefined { return this.ast.data.propertyName?.node; } + /** + * Declared name + */ + get name(): ModuleExportName { return this.ast.data.name.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } + /** @internal */ set propertyName(value) { this.ast.data.propertyName = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export type ModuleExportName = Identifier | StringLiteral; @@ -3832,12 +6971,29 @@ export type TypeOnlyAliasDeclaration = TypeOnlyImportDeclaration | TypeOnlyExpor * This is either an `export =` or an `export default` declaration. * Unless `isExportEquals` is set, this node was parsed as an `export default`. */ -export interface ExportAssignment extends DeclarationStatement, JSDocContainer { - readonly kind: SyntaxKind.ExportAssignment; - readonly parent: SourceFile; - readonly modifiers?: NodeArray | undefined; - readonly isExportEquals?: boolean | undefined; - readonly expression: Expression; +// dprint-ignore +export class ExportAssignment extends Node implements DeclarationStatement, JSDocContainer { + declare _declarationBrand: any; + declare _statementBrand: any; + declare _jsdocContainerBrand: any; + declare readonly ast: AstExportAssignment; + + override get parent() { return super.parent as SourceFile; } + + get modifiers(): NodeArray | undefined { return this.ast.data.modifiers?.nodes; } + get isExportEquals(): boolean | undefined { return this.ast.data.isExportEquals; } + get expression(): Expression { return this.ast.data.expression.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set modifiers(value) { this.ast.data.modifiers = value?.ast; } + /** @internal */ set isExportEquals(value) { this.ast.data.isExportEquals = value; } + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } export interface FileReference extends TextRange { @@ -3865,64 +7021,144 @@ export interface SynthesizedComment extends CommentRange { } // represents a top level: { type } expression in a JSDoc comment. -export interface JSDocTypeExpression extends TypeNode { - readonly kind: SyntaxKind.JSDocTypeExpression; - readonly type: TypeNode; +// dprint-ignore +export class JSDocTypeExpression extends Node implements TypeNode { + declare _typeNodeBrand: any; + declare readonly ast: AstJSDocTypeExpression; + + get type(): TypeNode { return this.ast.data.type.node; } + + /** @internal */ set type(value) { this.ast.data.type = value.ast; } } -export interface JSDocNameReference extends Node { - readonly kind: SyntaxKind.JSDocNameReference; - readonly name: EntityName | JSDocMemberName; +// dprint-ignore +export class JSDocNameReference extends Node { + declare readonly ast: AstJSDocNameReference; + + get name(): EntityName | JSDocMemberName { return this.ast.data.name.node; } + + /** @internal */ set name(value) { this.ast.data.name = value.ast; } } + /** Class#method reference in JSDoc */ -export interface JSDocMemberName extends Node { - readonly kind: SyntaxKind.JSDocMemberName; - readonly left: EntityName | JSDocMemberName; - readonly right: Identifier; +// dprint-ignore +export class JSDocMemberName extends Node { + declare readonly ast: AstJSDocMemberName; + + get left(): EntityName | JSDocMemberName { return this.ast.data.left.node; } + get right(): Identifier { return this.ast.data.right.node; } + + /** @internal */ set left(value) { this.ast.data.left = value.ast; } + /** @internal */ set right(value) { this.ast.data.right = value.ast; } } export interface JSDocType extends TypeNode { _jsDocTypeBrand: any; } -export interface JSDocAllType extends JSDocType { - readonly kind: SyntaxKind.JSDocAllType; +// dprint-ignore +export class JSDocAllType extends Node implements JSDocType { + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare readonly ast: AstJSDocAllType; } -export interface JSDocUnknownType extends JSDocType { - readonly kind: SyntaxKind.JSDocUnknownType; +// dprint-ignore +export class JSDocUnknownType extends Node implements JSDocType { + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare readonly ast: AstJSDocUnknownType; } -export interface JSDocNonNullableType extends JSDocType { - readonly kind: SyntaxKind.JSDocNonNullableType; - readonly type: TypeNode; - readonly postfix: boolean; +// dprint-ignore +export class JSDocNonNullableType extends Node implements JSDocType { + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare readonly ast: AstJSDocNonNullableType; + + get type(): TypeNode { return this.ast.data.type.node; } + get postfix(): boolean { return this.ast.data.postfix; } + + /** @internal */ set type(value) { this.ast.data.type = value.ast; } + /** @internal */ set postfix(value) { this.ast.data.postfix = value; } } -export interface JSDocNullableType extends JSDocType { - readonly kind: SyntaxKind.JSDocNullableType; - readonly type: TypeNode; - readonly postfix: boolean; +// dprint-ignore +export class JSDocNullableType extends Node implements JSDocType { + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare readonly ast: AstJSDocNullableType; + + get type(): TypeNode { return this.ast.data.type.node; } + get postfix(): boolean { return this.ast.data.postfix; } + + /** @internal */ set type(value) { this.ast.data.type = value.ast; } + /** @internal */ set postfix(value) { this.ast.data.postfix = value; } } -export interface JSDocOptionalType extends JSDocType { - readonly kind: SyntaxKind.JSDocOptionalType; - readonly type: TypeNode; +// dprint-ignore +export class JSDocOptionalType extends Node implements JSDocType { + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare readonly ast: AstJSDocOptionalType; + + get type(): TypeNode { return this.ast.data.type.node; } + + /** @internal */ set type(value) { this.ast.data.type = value.ast; } } -export interface JSDocFunctionType extends JSDocType, SignatureDeclarationBase, LocalsContainer { - readonly kind: SyntaxKind.JSDocFunctionType; +// dprint-ignore +export class JSDocFunctionType extends Node implements JSDocType, SignatureDeclarationBase, LocalsContainer { + declare _signatureDeclarationBrand: any; + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstJSDocFunctionType; + + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): TypeNode | undefined { return this.ast.data.type?.node; } + get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } + + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } -export interface JSDocVariadicType extends JSDocType { - readonly kind: SyntaxKind.JSDocVariadicType; - readonly type: TypeNode; +// dprint-ignore +export class JSDocVariadicType extends Node implements JSDocType { + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare readonly ast: AstJSDocVariadicType; + + get type(): TypeNode { return this.ast.data.type.node; } + + /** @internal */ set type(value) { this.ast.data.type = value.ast; } } -export interface JSDocNamepathType extends JSDocType { - readonly kind: SyntaxKind.JSDocNamepathType; - readonly type: TypeNode; +// dprint-ignore +export class JSDocNamepathType extends Node implements JSDocType { + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare readonly ast: AstJSDocNamepathType; + + get type(): TypeNode { return this.ast.data.type.node; } + + /** @internal */ set type(value) { this.ast.data.type = value.ast; } } export type JSDocTypeReferencingNode = @@ -3931,49 +7167,93 @@ export type JSDocTypeReferencingNode = | JSDocNullableType | JSDocNonNullableType; -export interface JSDoc extends Node { - readonly kind: SyntaxKind.JSDoc; - readonly parent: HasJSDoc; - readonly tags?: NodeArray | undefined; - readonly comment?: string | NodeArray | undefined; +// dprint-ignore +export class JSDoc extends Node { + declare readonly ast: AstJSDoc; + + override get parent() { return super.parent as HasJSDoc; } + + get tags(): NodeArray | undefined { return this.ast.data.tags?.nodes; } + get comment(): string | NodeArray | undefined { + const comment = this.ast.data.comment; + return typeof comment === "string" ? comment : comment?.nodes; + } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set tags(value) { this.ast.data.tags = value?.ast; } + /** @internal */ set comment(value) { this.ast.data.comment = typeof value === "string" ? value : value?.ast; } } -export interface JSDocTag extends Node { - readonly parent: JSDoc | JSDocTypeLiteral; - readonly tagName: Identifier; - readonly comment?: string | NodeArray | undefined; +// TODO(rbuckton): Move after JSDocText +// dprint-ignore +export class JSDocTag extends Node { + declare readonly ast: AstBaseJSDocTag; + + override get parent() { return super.parent as JSDoc | JSDocTypeLiteral; } + + get tagName(): Identifier { return this.ast.data.tagName.node; } + get comment(): string | NodeArray | undefined { + const comment = this.ast.data.comment; + return typeof comment === "string" ? comment : comment?.nodes; + } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set tagName(value) { this.ast.data.tagName = value.ast; } + /** @internal */ set comment(value) { this.ast.data.comment = typeof value === "string" ? value : value?.ast; } } -export interface JSDocLink extends Node { - readonly kind: SyntaxKind.JSDocLink; - readonly name?: EntityName | JSDocMemberName | undefined; - text: string; +// dprint-ignore +export class JSDocLink extends Node { + declare readonly ast: AstJSDocLink; + + get name(): EntityName | JSDocMemberName | undefined { return this.ast.data.name?.node; } + get text(): string { return this.ast.data.text; } + + /** @internal */ set name(value) { this.ast.data.name = value?.ast; } + /** @internal */ set text(value) { this.ast.data.text = value; } } -export interface JSDocLinkCode extends Node { - readonly kind: SyntaxKind.JSDocLinkCode; - readonly name?: EntityName | JSDocMemberName | undefined; - text: string; +// dprint-ignore +export class JSDocLinkCode extends Node { + declare readonly ast: AstJSDocLinkCode; + + get name(): EntityName | JSDocMemberName | undefined { return this.ast.data.name?.node; } + get text(): string { return this.ast.data.text; } + + /** @internal */ set name(value) { this.ast.data.name = value?.ast; } + /** @internal */ set text(value) { this.ast.data.text = value; } } -export interface JSDocLinkPlain extends Node { - readonly kind: SyntaxKind.JSDocLinkPlain; - readonly name?: EntityName | JSDocMemberName | undefined; - text: string; +// dprint-ignore +export class JSDocLinkPlain extends Node { + declare readonly ast: AstJSDocLinkPlain; + + get name(): EntityName | JSDocMemberName | undefined { return this.ast.data.name?.node; } + get text(): string { return this.ast.data.text; } + + /** @internal */ set name(value) { this.ast.data.name = value?.ast; } + /** @internal */ set text(value) { this.ast.data.text = value; } } export type JSDocComment = JSDocText | JSDocLink | JSDocLinkCode | JSDocLinkPlain; -export interface JSDocText extends Node { - readonly kind: SyntaxKind.JSDocText; - text: string; +// dprint-ignore +export class JSDocText extends Node { + declare readonly ast: AstJSDocText; + + get text(): string { return this.ast.data.text; } + + /** @internal */ set text(value) { this.ast.data.text = value; } } -export interface JSDocUnknownTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocTag; +// dprint-ignore +export class JSDocUnknownTag extends JSDocTag { + declare readonly ast: AstJSDocUnknownTag; } export interface JSDocClassReference extends ExpressionWithTypeArguments { + readonly ast: AstJSDocClassReference; + readonly data: AstJSDocClassReferenceData; readonly expression: Identifier | PropertyAccessEntityNameExpression; } @@ -3981,115 +7261,238 @@ export interface JSDocClassReference extends ExpressionWithTypeArguments { * Note that `@extends` is a synonym of `@augments`. * Both tags are represented by this interface. */ -export interface JSDocAugmentsTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocAugmentsTag; - readonly class: JSDocClassReference; +// dprint-ignore +export class JSDocAugmentsTag extends JSDocTag { + declare readonly ast: AstJSDocAugmentsTag; + + get class(): JSDocClassReference { return this.ast.data.class.node; } + + /** @internal */ set class(value) { this.ast.data.class = value.ast; } } -export interface JSDocImplementsTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocImplementsTag; - readonly class: JSDocClassReference; +// dprint-ignore +export class JSDocImplementsTag extends JSDocTag { + declare readonly ast: AstJSDocImplementsTag; + + get class(): JSDocClassReference { return this.ast.data.class.node; } + + /** @internal */ set class(value) { this.ast.data.class = value.ast; } } -export interface JSDocAuthorTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocAuthorTag; +// dprint-ignore +export class JSDocAuthorTag extends JSDocTag { + declare readonly ast: AstJSDocAuthorTag; } -export interface JSDocDeprecatedTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocDeprecatedTag; +// dprint-ignore +export class JSDocDeprecatedTag extends JSDocTag { + declare readonly ast: AstJSDocDeprecatedTag; } -export interface JSDocClassTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocClassTag; +// dprint-ignore +export class JSDocClassTag extends JSDocTag { + declare readonly ast: AstJSDocClassTag; } -export interface JSDocPublicTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocPublicTag; +// dprint-ignore +export class JSDocPublicTag extends JSDocTag { + declare readonly ast: AstJSDocPublicTag; } -export interface JSDocPrivateTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocPrivateTag; +// dprint-ignore +export class JSDocPrivateTag extends JSDocTag { + declare readonly ast: AstJSDocPrivateTag; } -export interface JSDocProtectedTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocProtectedTag; +// dprint-ignore +export class JSDocProtectedTag extends JSDocTag { + declare readonly ast: AstJSDocProtectedTag; } -export interface JSDocReadonlyTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocReadonlyTag; +// dprint-ignore +export class JSDocReadonlyTag extends JSDocTag { + declare readonly ast: AstJSDocReadonlyTag; } -export interface JSDocOverrideTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocOverrideTag; +// dprint-ignore +export class JSDocOverrideTag extends JSDocTag { + declare readonly ast: AstJSDocOverrideTag; } -export interface JSDocEnumTag extends JSDocTag, Declaration, LocalsContainer { - readonly kind: SyntaxKind.JSDocEnumTag; - readonly parent: JSDoc; - readonly typeExpression: JSDocTypeExpression; +// dprint-ignore +export class JSDocEnumTag extends JSDocTag implements Declaration, LocalsContainer { + declare _declarationBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstJSDocEnumTag; + + override get parent() { return super.parent as JSDoc; } + + get typeExpression(): JSDocTypeExpression { return this.ast.data.typeExpression.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set typeExpression(value) { this.ast.data.typeExpression = value.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } -export interface JSDocThisTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocThisTag; - readonly typeExpression: JSDocTypeExpression; +// dprint-ignore +export class JSDocThisTag extends JSDocTag { + declare readonly ast: AstJSDocThisTag; + + get typeExpression(): JSDocTypeExpression { return this.ast.data.typeExpression.node; } + + /** @internal */ set typeExpression(value) { this.ast.data.typeExpression = value.ast; } } -export interface JSDocTemplateTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocTemplateTag; - readonly constraint: JSDocTypeExpression | undefined; - readonly typeParameters: NodeArray; +// dprint-ignore +export class JSDocTemplateTag extends JSDocTag { + declare readonly ast: AstJSDocTemplateTag; + + get constraint(): JSDocTypeExpression | undefined { return this.ast.data.constraint?.node; } + get typeParameters(): NodeArray { return this.ast.data.typeParameters.nodes; } + + /** @internal */ set constraint(value) { this.ast.data.constraint = value?.ast; } + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value.ast; } } -export interface JSDocSeeTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocSeeTag; - readonly name?: JSDocNameReference | undefined; +// dprint-ignore +export class JSDocSeeTag extends JSDocTag { + declare readonly ast: AstJSDocSeeTag; + + get name(): JSDocNameReference | undefined { return this.ast.data.name?.node; } + + /** @internal */ set name(value) { this.ast.data.name = value?.ast; } } -export interface JSDocReturnTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocReturnTag; - readonly typeExpression?: JSDocTypeExpression | undefined; +// dprint-ignore +export class JSDocReturnTag extends JSDocTag { + declare readonly ast: AstJSDocReturnTag; + + get typeExpression(): JSDocTypeExpression | undefined { return this.ast.data.typeExpression?.node; } + + /** @internal */ set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } } -export interface JSDocTypeTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocTypeTag; - readonly typeExpression: JSDocTypeExpression; +// dprint-ignore +export class JSDocTypeTag extends JSDocTag { + declare readonly ast: AstJSDocTypeTag; + + get typeExpression(): JSDocTypeExpression { return this.ast.data.typeExpression.node; } + + /** @internal */ set typeExpression(value) { this.ast.data.typeExpression = value.ast; } } -export interface JSDocTypedefTag extends JSDocTag, NamedDeclaration, LocalsContainer { - readonly kind: SyntaxKind.JSDocTypedefTag; - readonly parent: JSDoc; - readonly fullName?: JSDocNamespaceDeclaration | Identifier | undefined; - readonly name?: Identifier | undefined; - readonly typeExpression?: JSDocTypeExpression | JSDocTypeLiteral | undefined; +// dprint-ignore +export class JSDocTypedefTag extends JSDocTag implements Declaration, LocalsContainer { + declare _declarationBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstJSDocTypedefTag; + + override get parent() { return super.parent as JSDoc; } + + get fullName(): Identifier | JSDocNamespaceDeclaration | undefined { return this.ast.data.fullName?.node; } + get name(): Identifier | undefined { return this.ast.data.name?.node; } + get typeExpression(): JSDocTypeLiteral | JSDocTypeExpression | undefined { return this.ast.data.typeExpression?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set fullName(value) { this.ast.data.fullName = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value?.ast; } + /** @internal */ set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } -export interface JSDocCallbackTag extends JSDocTag, NamedDeclaration, LocalsContainer { - readonly kind: SyntaxKind.JSDocCallbackTag; - readonly parent: JSDoc; - readonly fullName?: JSDocNamespaceDeclaration | Identifier | undefined; - readonly name?: Identifier | undefined; - readonly typeExpression: JSDocSignature; +// dprint-ignore +export class JSDocCallbackTag extends JSDocTag implements Declaration, LocalsContainer { + declare _declarationBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstJSDocCallbackTag; + + override get parent() { return super.parent as JSDoc; } + + get fullName(): Identifier | JSDocNamespaceDeclaration | undefined { return this.ast.data.fullName?.node; } + get name(): Identifier | undefined { return this.ast.data.name?.node; } + get typeExpression(): JSDocSignature { return this.ast.data.typeExpression.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set fullName(value) { this.ast.data.fullName = value?.ast; } + /** @internal */ set name(value) { this.ast.data.name = value?.ast; } + /** @internal */ set typeExpression(value) { this.ast.data.typeExpression = value.ast; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } -export interface JSDocOverloadTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocOverloadTag; - readonly parent: JSDoc; - readonly typeExpression: JSDocSignature; +// dprint-ignore +export class JSDocOverloadTag extends JSDocTag { + declare readonly ast: AstJSDocOverloadTag; + + override get parent() { return super.parent as JSDoc; } + + get typeExpression(): JSDocSignature { return this.ast.data.typeExpression.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set typeExpression(value) { this.ast.data.typeExpression = value.ast; } } -export interface JSDocThrowsTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocThrowsTag; - readonly typeExpression?: JSDocTypeExpression | undefined; +// dprint-ignore +export class JSDocThrowsTag extends JSDocTag { + declare readonly ast: AstJSDocThrowsTag; + + get typeExpression(): JSDocTypeExpression | undefined { return this.ast.data.typeExpression?.node; } + + /** @internal */ set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } } -export interface JSDocSignature extends JSDocType, Declaration, JSDocContainer, LocalsContainer { - readonly kind: SyntaxKind.JSDocSignature; - readonly typeParameters?: readonly JSDocTemplateTag[] | undefined; - readonly parameters: readonly JSDocParameterTag[]; - readonly type: JSDocReturnTag | undefined; +// dprint-ignore +export class JSDocSignature extends Node implements JSDocType, Declaration, JSDocContainer, LocalsContainer { + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare _signatureDeclarationBrand: any; + declare readonly ast: AstJSDocSignature; + + get typeParameters(): NodeArray | undefined { return this.ast.data.typeParameters?.nodes; } + get parameters(): NodeArray { return this.ast.data.parameters.nodes; } + get type(): JSDocReturnTag | undefined { return this.ast.data.type?.node; } + + /** @internal */ set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + /** @internal */ set parameters(value) { this.ast.data.parameters = value.ast; } + /** @internal */ set type(value) { this.ast.data.type = value?.ast; } + /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } + /** @internal */ set jsDoc(value) { this.ast.data.jsDoc = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } } export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { + readonly ast: AstJSDocPropertyLikeTag; + readonly data: AstJSDocTagData & AstDeclarationData; readonly parent: JSDoc; readonly name: EntityName; readonly typeExpression?: JSDocTypeExpression | undefined; @@ -4098,24 +7501,80 @@ export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { readonly isBracketed: boolean; } -export interface JSDocPropertyTag extends JSDocPropertyLikeTag { - readonly kind: SyntaxKind.JSDocPropertyTag; +// dprint-ignore +export class JSDocPropertyTag extends JSDocTag implements JSDocPropertyLikeTag, Declaration { + declare _declarationBrand: any; + declare readonly ast: AstJSDocPropertyTag; + + override get parent() { return super.parent as JSDoc; } + + get name(): Identifier | QualifiedName { return this.ast.data.name.node; } + get typeExpression(): JSDocTypeExpression | undefined { return this.ast.data.typeExpression?.node; } + /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ + get isNameFirst(): boolean { return this.ast.data.isNameFirst; } + get isBracketed(): boolean { return this.ast.data.isBracketed; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + /** @internal */ set isNameFirst(value) { this.ast.data.isNameFirst = value; } + /** @internal */ set isBracketed(value) { this.ast.data.isBracketed = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface JSDocParameterTag extends JSDocPropertyLikeTag { - readonly kind: SyntaxKind.JSDocParameterTag; +// dprint-ignore +export class JSDocParameterTag extends JSDocTag implements JSDocPropertyLikeTag { + declare _declarationBrand: any; + declare readonly ast: AstJSDocParameterTag; + + override get parent() { return super.parent as JSDoc; } + + get name(): Identifier | QualifiedName { return this.ast.data.name.node; } + get typeExpression(): JSDocTypeExpression | undefined { return this.ast.data.typeExpression?.node; } + /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ + get isNameFirst(): boolean { return this.ast.data.isNameFirst; } + get isBracketed(): boolean { return this.ast.data.isBracketed; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set name(value) { this.ast.data.name = value.ast; } + /** @internal */ set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + /** @internal */ set isNameFirst(value) { this.ast.data.isNameFirst = value; } + /** @internal */ set isBracketed(value) { this.ast.data.isBracketed = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface JSDocTypeLiteral extends JSDocType, Declaration { - readonly kind: SyntaxKind.JSDocTypeLiteral; - readonly jsDocPropertyTags?: readonly JSDocPropertyLikeTag[] | undefined; +// dprint-ignore +export class JSDocTypeLiteral extends Node implements JSDocType, Declaration { + declare _jsDocTypeBrand: any; + declare _typeNodeBrand: any; + declare _declarationBrand: any; + declare readonly ast: AstJSDocTypeLiteral; + + get jsDocPropertyTags(): NodeArray | undefined { return this.ast.data.jsDocPropertyTags?.nodes; } /** If true, then this type literal represents an *array* of its type. */ - readonly isArrayType: boolean; + get isArrayType(): boolean { return this.ast.data.isArrayType; } + + /** @internal */ set jsDocPropertyTags(value) { this.ast.data.jsDocPropertyTags = value?.ast; } + /** @internal */ set isArrayType(value) { this.ast.data.isArrayType = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } + /** @internal */ set symbol(value) { this.ast.data.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.localSymbol = value; } } -export interface JSDocSatisfiesTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocSatisfiesTag; - readonly typeExpression: JSDocTypeExpression; +// dprint-ignore +export class JSDocSatisfiesTag extends JSDocTag { + declare readonly ast: AstJSDocSatisfiesTag; + + get typeExpression(): JSDocTypeExpression { return this.ast.data.typeExpression.node; } + + /** @internal */ set typeExpression(value) { this.ast.data.typeExpression = value.ast; } } /** @internal */ @@ -4123,12 +7582,20 @@ export interface JSDocSatisfiesExpression extends ParenthesizedExpression { readonly _jsDocSatisfiesExpressionBrand: never; } -export interface JSDocImportTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocImportTag; - readonly parent: JSDoc; - readonly importClause?: ImportClause | undefined; - readonly moduleSpecifier: Expression; - readonly attributes?: ImportAttributes | undefined; +// dprint-ignore +export class JSDocImportTag extends JSDocTag { + declare readonly ast: AstJSDocImportTag; + + override get parent() { return super.parent as JSDoc; } + + get importClause(): ImportClause | undefined { return this.ast.data.importClause?.node; } + get moduleSpecifier(): Expression { return this.ast.data.moduleSpecifier.node; } + get attributes(): ImportAttributes | undefined { return this.ast.data.attributes?.node; } + + /** @internal */ override set parent(value) { super.parent = value; } + /** @internal */ set importClause(value) { this.ast.data.importClause = value?.ast; } + /** @internal */ set moduleSpecifier(value) { this.ast.data.moduleSpecifier = value.ast; } + /** @internal */ set attributes(value) { this.ast.data.attributes = value?.ast; } } // NOTE: Ensure this is up-to-date with src/debug/debug.ts @@ -4304,52 +7771,23 @@ export interface RedirectInfo { export type ResolutionMode = ModuleKind.ESNext | ModuleKind.CommonJS | undefined; // Source files are declarations when they are external modules. -export interface SourceFile extends Declaration, LocalsContainer { - readonly kind: SyntaxKind.SourceFile; - readonly statements: NodeArray; - readonly endOfFileToken: Token; - - fileName: string; - /** @internal */ path: Path; - text: string; - /** Resolved path can be different from path property, - * when file is included through project reference is mapped to its output instead of source - * in that case resolvedPath = path to output file - * path = input file's path - * - * @internal - */ - resolvedPath: Path; - /** Original file name that can be different from fileName, - * when file is included through project reference is mapped to its output instead of source - * in that case originalFileName = name of input file - * fileName = output file's name - * - * @internal - */ - originalFileName: string; - - /** - * If two source files are for the same version of the same package, one will redirect to the other. - * (See `createRedirectSourceFile` in program.ts.) - * The redirect will have this set. The redirected-to source file will be in `redirectTargetsMap`. - * - * @internal - */ - redirectInfo?: RedirectInfo | undefined; - - amdDependencies: readonly AmdDependency[]; - moduleName?: string | undefined; - referencedFiles: readonly FileReference[]; - typeReferenceDirectives: readonly FileReference[]; - libReferenceDirectives: readonly FileReference[]; - languageVariant: LanguageVariant; - isDeclarationFile: boolean; - - // this map is used by transpiler to supply alternative names for dependencies (i.e. in case of bundling) - /** @internal */ - renamedDependencies?: ReadonlyMap | undefined; - +// dprint-ignore +export class SourceFile extends Node implements Declaration, LocalsContainer, ReadonlyPragmaContext { + declare _declarationBrand: any; + declare _localsContainerBrand: any; + declare readonly ast: AstSourceFile; + + get statements(): NodeArray { return this.ast.data.statements.nodes; } + get endOfFileToken(): EndOfFileToken { return this.ast.data.endOfFileToken.node; } + get fileName(): string { return this.ast.data.fileName; } + get text(): string { return this.ast.data.text; } + get amdDependencies(): AmdDependency[] { return this.ast.data.amdDependencies; } + get moduleName(): string | undefined { return this.ast.data.moduleName; } + get referencedFiles(): readonly FileReference[] { return this.ast.data.referencedFiles; } + get typeReferenceDirectives(): readonly FileReference[] { return this.ast.data.typeReferenceDirectives; } + get libReferenceDirectives(): readonly FileReference[] { return this.ast.data.libReferenceDirectives; } + get languageVariant(): LanguageVariant { return this.ast.data.languageVariant; } + get isDeclarationFile(): boolean { return this.ast.data.isDeclarationFile; } /** * lib.d.ts should have a reference comment like * @@ -4358,10 +7796,8 @@ export interface SourceFile extends Declaration, LocalsContainer { * If any other file has this comment, it signals not to include lib.d.ts * because this containing file is intended to act as a default library. */ - hasNoDefaultLib: boolean; - - languageVersion: ScriptTarget; - + get hasNoDefaultLib(): boolean { return this.ast.data.hasNoDefaultLib; } + get languageVersion(): ScriptTarget { return this.ast.data.languageVersion; } /** * When `module` is `Node16` or `NodeNext`, this field controls whether the * source file in question is an ESNext-output-format file, or a CommonJS-output-format @@ -4379,101 +7815,374 @@ export interface SourceFile extends Declaration, LocalsContainer { * of `node`). If so, this field will be unset and source files will be considered to be * CommonJS-output-format by the node module transformer and type checker, regardless of extension or context. */ - impliedNodeFormat?: ResolutionMode | undefined; - /** @internal */ packageJsonLocations?: readonly string[] | undefined; - /** @internal */ packageJsonScope?: PackageJsonInfo | undefined; + get impliedNodeFormat(): ResolutionMode { return this.ast.data.impliedNodeFormat; } + + /** @internal */ set statements(value) { this.ast.data.statements = value.ast; } + /** @internal */ set endOfFileToken(value) { this.ast.data.endOfFileToken = value.ast; } + /** @internal */ set fileName(value) { this.ast.data.fileName = value; } + /** @internal */ get path(): Path { return this.ast.data.path; } + /** @internal */ set path(value) { this.ast.data.path = value; } + /** @internal */ set text(value) { this.ast.data.text = value; } + /** @internal */ get resolvedPath(): Path { return this.ast.data.resolvedPath; } + /** @internal */ set resolvedPath(value) { this.ast.data.resolvedPath = value; } + /** @internal */ get originalFileName(): string { return this.ast.data.originalFileName; } + /** @internal */ set originalFileName(value) { this.ast.data.originalFileName = value; } + /** @internal */ set amdDependencies(value) { this.ast.data.amdDependencies = value; } + /** @internal */ set moduleName(value) { this.ast.data.moduleName = value; } + /** @internal */ set referencedFiles(value) { this.ast.data.referencedFiles = value; } + /** @internal */ set typeReferenceDirectives(value) { this.ast.data.typeReferenceDirectives = value; } + /** @internal */ set libReferenceDirectives(value) { this.ast.data.libReferenceDirectives = value; } + /** @internal */ set languageVariant(value) { this.ast.data.languageVariant = value; } + /** @internal */ set isDeclarationFile(value) { this.ast.data.isDeclarationFile = value; } + /** @internal */ get renamedDependencies(): Map { return this.ast.data.renamedDependencies; } + /** @internal */ set renamedDependencies(value) { this.ast.data.renamedDependencies = value; } + /** @internal */ set hasNoDefaultLib(value) { this.ast.data.hasNoDefaultLib = value; } + /** @internal */ set languageVersion(value) { this.ast.data.languageVersion = value; } + /** @internal */ set impliedNodeFormat(value) { this.ast.data.impliedNodeFormat = value; } + /** @internal */ get scriptKind(): ScriptKind { return this.ast.data.scriptKind; } + /** @internal */ set scriptKind(value) { this.ast.data.scriptKind = value; } + /** @internal */ get pragmas(): ReadonlyPragmaMap { return this.ast.data.pragmas; } + /** @internal */ set pragmas(value) { this.ast.data.pragmas = value; } + /** @internal */ get externalModuleIndicator(): true | Node | undefined { return this.ast.data.externalModuleIndicator; } + /** @internal */ set externalModuleIndicator(value) { this.ast.data.externalModuleIndicator = value; } + /** @internal */ get commonJsModuleIndicator(): Node | undefined { return this.ast.data.commonJsModuleIndicator; } + /** @internal */ set commonJsModuleIndicator(value) { this.ast.data.commonJsModuleIndicator = value; } + /** @internal */ get identifiers(): Map { return this.ast.data.identifiers; } + /** @internal */ set identifiers(value) { this.ast.data.identifiers = value; } + /** @internal */ get parseDiagnostics(): DiagnosticWithLocation[] { return this.ast.data.parseDiagnostics; } + /** @internal */ set parseDiagnostics(value) { this.ast.data.parseDiagnostics = value; } + /** @internal */ get bindDiagnostics(): DiagnosticWithLocation[] { return this.ast.data.bindDiagnostics; } + /** @internal */ set bindDiagnostics(value) { this.ast.data.bindDiagnostics = value; } + /** @internal */ get bindSuggestionDiagnostics(): DiagnosticWithLocation[] | undefined { return this.ast.data.bindSuggestionDiagnostics; } + /** @internal */ set bindSuggestionDiagnostics(value) { this.ast.data.bindSuggestionDiagnostics = value; } + /** @internal */ get lineMap(): readonly number[] { return this.ast.data.lineMap; } + /** @internal */ set lineMap(value) { this.ast.data.lineMap = value; } + /** @internal */ get jsDocDiagnostics(): DiagnosticWithLocation[] | undefined { return this.ast.data.jsDocDiagnostics; } + /** @internal */ set jsDocDiagnostics(value) { this.ast.data.jsDocDiagnostics = value; } + /** @internal */ get commentDirectives(): CommentDirective[] | undefined { return this.ast.data.commentDirectives; } + /** @internal */ set commentDirectives(value) { this.ast.data.commentDirectives = value; } + /** @internal */ get checkJsDirective(): CheckJsDirective | undefined { return this.ast.data.checkJsDirective; } + /** @internal */ set checkJsDirective(value) { this.ast.data.checkJsDirective = value; } + /** @internal */ get version(): string { return this.ast.data.version; } + /** @internal */ set version(value) { this.ast.data.version = value; } + /** @internal */ get symbol(): Symbol { return this.ast.data.declaration.symbol; } + /** @internal */ set symbol(value) { this.ast.data.declaration.symbol = value; } + /** @internal */ get localSymbol(): Symbol | undefined { return this.ast.data.declaration.localSymbol; } + /** @internal */ set localSymbol(value) { this.ast.data.declaration.localSymbol = value; } + /** @internal */ get locals(): SymbolTable | undefined { return this.ast.data.locals; } + /** @internal */ set locals(value) { this.ast.data.locals = value; } + /** @internal */ get redirectInfo(): RedirectInfo | undefined { return this.ast.data.redirectInfo; } + /** @internal */ set redirectInfo(value) { this.ast.data.redirectInfo = value; } + /** @internal */ get packageJsonLocations(): readonly string[] | undefined { return this.ast.data.packageJsonLocations; } + /** @internal */ set packageJsonLocations(value) { this.ast.data.packageJsonLocations = value; } + /** @internal */ get packageJsonScope(): PackageJsonInfo | undefined { return this.ast.data.packageJsonScope; } + /** @internal */ set packageJsonScope(value) { this.ast.data.packageJsonScope = value; } + /** @internal */ get setExternalModuleIndicator(): ((file: SourceFile) => void) | undefined { return this.ast.data.setExternalModuleIndicator; } + /** @internal */ set setExternalModuleIndicator(value) { this.ast.data.setExternalModuleIndicator = value; } + /** @internal */ get jsGlobalAugmentations(): SymbolTable | undefined { return this.ast.data.jsGlobalAugmentations; } + /** @internal */ set jsGlobalAugmentations(value) { this.ast.data.jsGlobalAugmentations = value; } + /** @internal */ get nodeCount(): number { return this.ast.data.nodeCount; } + /** @internal */ set nodeCount(value) { this.ast.data.nodeCount = value; } + /** @internal */ get identifierCount(): number { return this.ast.data.identifierCount; } + /** @internal */ set identifierCount(value) { this.ast.data.identifierCount = value; } + /** @internal */ get symbolCount(): number { return this.ast.data.symbolCount; } + /** @internal */ set symbolCount(value) { this.ast.data.symbolCount = value; } + /** @internal */ get additionalSyntacticDiagnostics(): readonly DiagnosticWithLocation[] | undefined { return this.ast.data.additionalSyntacticDiagnostics; } + /** @internal */ set additionalSyntacticDiagnostics(value) { this.ast.data.additionalSyntacticDiagnostics = value; } + /** @internal */ get classifiableNames(): ReadonlySet<__String> | undefined { return this.ast.data.classifiableNames; } + /** @internal */ set classifiableNames(value) { this.ast.data.classifiableNames = value; } + /** @internal */ get imports(): readonly StringLiteralLike[] { return this.ast.data.imports; } + /** @internal */ set imports(value) { this.ast.data.imports = value; } + /** @internal */ get moduleAugmentations(): readonly (Identifier | StringLiteral)[] { return this.ast.data.moduleAugmentations; } + /** @internal */ set moduleAugmentations(value) { this.ast.data.moduleAugmentations = value; } + /** @internal */ get patternAmbientModules(): PatternAmbientModule[] | undefined { return this.ast.data.patternAmbientModules; } + /** @internal */ set patternAmbientModules(value) { this.ast.data.patternAmbientModules = value; } + /** @internal */ get ambientModuleNames(): readonly string[] { return this.ast.data.ambientModuleNames; } + /** @internal */ set ambientModuleNames(value) { this.ast.data.ambientModuleNames = value; } + /** @internal */ get localJsxNamespace(): __String | undefined { return this.ast.data.localJsxNamespace; } + /** @internal */ set localJsxNamespace(value) { this.ast.data.localJsxNamespace = value; } + /** @internal */ get localJsxFragmentNamespace(): __String | undefined { return this.ast.data.localJsxFragmentNamespace; } + /** @internal */ set localJsxFragmentNamespace(value) { this.ast.data.localJsxFragmentNamespace = value; } + /** @internal */ get localJsxFactory(): EntityName | undefined { return this.ast.data.localJsxFactory; } + /** @internal */ set localJsxFactory(value) { this.ast.data.localJsxFactory = value; } + /** @internal */ get localJsxFragmentFactory(): EntityName | undefined { return this.ast.data.localJsxFragmentFactory; } + /** @internal */ set localJsxFragmentFactory(value) { this.ast.data.localJsxFragmentFactory = value; } + /** @internal */ get endFlowNode(): FlowNode | undefined { return this.ast.data.endFlowNode; } + /** @internal */ set endFlowNode(value) { this.ast.data.endFlowNode = value; } + /** @internal */ get jsDocParsingMode(): JSDocParsingMode | undefined { return this.ast.data.jsDocParsingMode; } + /** @internal */ set jsDocParsingMode(value) { this.ast.data.jsDocParsingMode = value; } + /** @internal */ get scriptSnapshot(): IScriptSnapshot | undefined { return this.ast.data.scriptSnapshot; } + /** @internal */ set scriptSnapshot(value) { this.ast.data.scriptSnapshot = value; } + /** @internal */ get nameTable(): Map<__String, number> | undefined { return this.ast.data.nameTable; } + /** @internal */ set nameTable(value) { this.ast.data.nameTable = value; } + /** @internal */ get nextContainer(): HasLocals | undefined { return this.ast.data.nextContainer?.node; } + /** @internal */ set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + /** @internal */ get extendedSourceFiles(): string[] | undefined { return this.ast.data.extendedSourceFiles; } + /** @internal */ set extendedSourceFiles(value) { this.ast.data.extendedSourceFiles = value; } + /** @internal */ get configFileSpecs(): ConfigFileSpecs | undefined { return this.ast.data.configFileSpecs; } + /** @internal */ set configFileSpecs(value) { this.ast.data.configFileSpecs = value; } + + update(newText: string, textChangeRange: TextChangeRange): SourceFile { + return updateSourceFile(this, newText, textChangeRange); + } + + getLineAndCharacterOfPosition(position: number): LineAndCharacter { + return getLineAndCharacterOfPosition(this, position); + } + + getLineStarts(): readonly number[] { + return getLineStarts(this); + } + + getPositionOfLineAndCharacter(line: number, character: number): number; + /** @internal */ + getPositionOfLineAndCharacter(line: number, character: number, allowEdits?: true): number; // eslint-disable-line @typescript-eslint/unified-signatures + getPositionOfLineAndCharacter(line: number, character: number, allowEdits?: true): number { + return computePositionOfLineAndCharacter(getLineStarts(this), line, character, this.text, allowEdits); + } + + getLineEndOfPosition(pos: number): number { + const { line } = this.getLineAndCharacterOfPosition(pos); + const lineStarts = this.getLineStarts(); + + let lastCharPos: number | undefined; + if (line + 1 >= lineStarts.length) { + lastCharPos = this.getEnd(); + } + if (!lastCharPos) { + lastCharPos = lineStarts[line + 1] - 1; + } + + const fullText = this.getFullText(); + // if the new line is "\r\n", we should return the last non-new-line-character position + return fullText[lastCharPos] === "\n" && fullText[lastCharPos - 1] === "\r" ? lastCharPos - 1 : lastCharPos; + } + + /** @internal */ + getNamedDeclarations(): Map { + if (!this.ast.data.namedDeclarations) { + this.ast.data.namedDeclarations = this._computeNamedDeclarations(); + } + + return this.ast.data.namedDeclarations; + } + + /** @internal @private */ + _computeNamedDeclarations(): Map { + const result = createMultiMap(); + + this.forEachChild(visit); + + return result; + + function addDeclaration(declaration: Declaration) { + const name = getDeclarationName(declaration); + if (name) { + result.add(name, declaration); + } + } + + function getDeclarations(name: string) { + let declarations = result.get(name); + if (!declarations) { + result.set(name, declarations = []); + } + return declarations; + } + + function getDeclarationName(declaration: Declaration) { + const name = getNonAssignedNameOfDeclaration(declaration); + if (name) { + if (isComputedPropertyName(name) && isPropertyAccessExpression(name.expression)) { + return (name.expression.name as MemberName).text + } + if (isPropertyName(name)) { + return name.kind === SyntaxKind.ComputedPropertyName + // treat computed property names where expression is string/numeric literal as just string/numeric literal + ? isStringOrNumericLiteralLike(name.expression) ? name.expression.text : undefined + : isPrivateIdentifier(name) ? idText(name) : getTextOfIdentifierOrLiteral(name); + } + } + return undefined; + } + + function visit(node: Node): void { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + const functionDeclaration = node as FunctionLikeDeclaration; + const declarationName = getDeclarationName(functionDeclaration); + + if (declarationName) { + const declarations = getDeclarations(declarationName); + const lastDeclaration = lastOrUndefined(declarations); + + // Check whether this declaration belongs to an "overload group". + if (lastDeclaration && functionDeclaration.parent === lastDeclaration.parent && functionDeclaration.symbol === lastDeclaration.symbol) { + // Overwrite the last declaration if it was an overload + // and this one is an implementation. + if (functionDeclaration.body && !(lastDeclaration as FunctionLikeDeclaration).body) { + declarations[declarations.length - 1] = functionDeclaration; + } + } + else { + declarations.push(functionDeclaration); + } + } + forEachChild(node, visit); + break; + + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ExportSpecifier: + case SyntaxKind.ImportSpecifier: + case SyntaxKind.ImportClause: + case SyntaxKind.NamespaceImport: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.TypeLiteral: + addDeclaration(node as Declaration); + forEachChild(node, visit); + break; + + case SyntaxKind.Parameter: + // Only consider parameter properties + if (!hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) { + break; + } + // falls through + + case SyntaxKind.VariableDeclaration: + case SyntaxKind.BindingElement: { + const decl = node as VariableDeclaration; + if (isBindingPattern(decl.name)) { + forEachChild(decl.name, visit); + break; + } + if (decl.initializer) { + visit(decl.initializer); + } + } + // falls through + case SyntaxKind.EnumMember: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + addDeclaration(node as Declaration); + break; + + case SyntaxKind.ExportDeclaration: + // Handle named exports case e.g.: + // export {a, b as B} from "mod"; + const exportDeclaration = node as ExportDeclaration; + if (exportDeclaration.exportClause) { + if (isNamedExports(exportDeclaration.exportClause)) { + forEach(exportDeclaration.exportClause.elements, visit); + } + else { + visit(exportDeclaration.exportClause.name); + } + } + break; + + case SyntaxKind.ImportDeclaration: + const importClause = (node as ImportDeclaration).importClause; + if (importClause) { + // Handle default import case e.g.: + // import d from "mod"; + if (importClause.name) { + addDeclaration(importClause.name); + } + + // Handle named bindings in imports e.g.: + // import * as NS from "mod"; + // import {a, b as B} from "mod"; + if (importClause.namedBindings) { + if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + addDeclaration(importClause.namedBindings); + } + else { + forEach(importClause.namedBindings.elements, visit); + } + } + } + break; + + case SyntaxKind.BinaryExpression: + if (getAssignmentDeclarationKind(node as BinaryExpression) !== AssignmentDeclarationKind.None) { + addDeclaration(node as BinaryExpression); + } + // falls through + + default: + forEachChild(node, visit); + } + } + } +} + +/** @internal */ +export type PartialSourceFile = + & Pick + & Partial>; + +/** + * Represents an immutable snapshot of a script at a specified time.Once acquired, the + * snapshot is observably immutable. i.e. the same calls with the same parameters will return + * the same values. + */ +// eslint-disable-next-line @typescript-eslint/naming-convention +export interface IScriptSnapshot { + /** Gets a portion of the script snapshot specified by [start, end). */ + getText(start: number, end: number): string; - /** @internal */ scriptKind: ScriptKind; + /** Gets the length of this script snapshot. */ + getLength(): number; /** - * The first "most obvious" node that makes a file an external module. - * This is intended to be the first top-level import/export, - * but could be arbitrarily nested (e.g. `import.meta`). - * - * @internal - */ - externalModuleIndicator?: Node | true | undefined; - /** - * The callback used to set the external module indicator - this is saved to - * be later reused during incremental reparsing, which otherwise lacks the information - * to set this field - * - * @internal + * Gets the TextChangeRange that describe how the text changed between this text and + * an older version. This information is used by the incremental parser to determine + * what sections of the script need to be re-parsed. 'undefined' can be returned if the + * change range cannot be determined. However, in that case, incremental parsing will + * not happen and the entire document will be re - parsed. */ - setExternalModuleIndicator?: ((file: SourceFile) => void) | undefined; - // The first node that causes this file to be a CommonJS module - /** @internal */ commonJsModuleIndicator?: Node | undefined; - // JS identifier-declarations that are intended to merge with globals - /** @internal */ jsGlobalAugmentations?: SymbolTable | undefined; - - /** @internal */ identifiers: ReadonlyMap; // Map from a string to an interned string - /** @internal */ nodeCount: number; - /** @internal */ identifierCount: number; - /** @internal */ symbolCount: number; - - // File-level diagnostics reported by the parser (includes diagnostics about /// references - // as well as code diagnostics). - /** @internal */ parseDiagnostics: DiagnosticWithLocation[]; - - // File-level diagnostics reported by the binder. - /** @internal */ bindDiagnostics: DiagnosticWithLocation[]; - /** @internal */ bindSuggestionDiagnostics?: DiagnosticWithLocation[] | undefined; - - // File-level JSDoc diagnostics reported by the JSDoc parser - /** @internal */ jsDocDiagnostics?: DiagnosticWithLocation[] | undefined; - - // Stores additional file-level diagnostics reported by the program - /** @internal */ additionalSyntacticDiagnostics?: readonly DiagnosticWithLocation[] | undefined; - - // Stores a line map for the file. - // This field should never be used directly to obtain line map, use getLineMap function instead. - /** @internal */ lineMap: readonly number[]; - /** @internal */ classifiableNames?: ReadonlySet<__String> | undefined; - // Comments containing @ts-* directives, in order. - /** @internal */ commentDirectives?: CommentDirective[] | undefined; - /** @internal */ imports: readonly StringLiteralLike[]; - // Identifier only if `declare global` - /** @internal */ moduleAugmentations: readonly (StringLiteral | Identifier)[]; - /** @internal */ patternAmbientModules?: PatternAmbientModule[] | undefined; - /** @internal */ ambientModuleNames: readonly string[]; - /** @internal */ checkJsDirective?: CheckJsDirective | undefined; - /** @internal */ version: string; - /** @internal */ pragmas: ReadonlyPragmaMap; - /** @internal */ localJsxNamespace?: __String | undefined; - /** @internal */ localJsxFragmentNamespace?: __String | undefined; - /** @internal */ localJsxFactory?: EntityName | undefined; - /** @internal */ localJsxFragmentFactory?: EntityName | undefined; - - /** @internal */ endFlowNode?: FlowNode | undefined; + getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined; - /** @internal */ jsDocParsingMode?: JSDocParsingMode | undefined; + /** Releases all resources held by this script snapshot */ + dispose?(): void; } -/** @internal */ export interface ReadonlyPragmaContext { - languageVersion: ScriptTarget; - pragmas?: ReadonlyPragmaMap | undefined; - checkJsDirective?: CheckJsDirective | undefined; - referencedFiles: readonly FileReference[]; - typeReferenceDirectives: readonly FileReference[]; - libReferenceDirectives: readonly FileReference[]; - amdDependencies: readonly AmdDependency[]; - hasNoDefaultLib?: boolean | undefined; - moduleName?: string | undefined; + readonly languageVersion: ScriptTarget; + /** @internal */ readonly pragmas?: ReadonlyPragmaMap | undefined; + /** @internal */ readonly checkJsDirective?: CheckJsDirective | undefined; + readonly referencedFiles: readonly FileReference[]; + readonly typeReferenceDirectives: readonly FileReference[]; + readonly libReferenceDirectives: readonly FileReference[]; + readonly amdDependencies: readonly AmdDependency[]; + readonly hasNoDefaultLib?: boolean | undefined; + /** @internal */ readonly moduleName?: string | undefined; } /** @internal */ export interface PragmaContext extends ReadonlyPragmaContext { + languageVersion: ScriptTarget; pragmas?: PragmaMap; + checkJsDirective?: CheckJsDirective | undefined; referencedFiles: FileReference[]; typeReferenceDirectives: FileReference[]; libReferenceDirectives: FileReference[]; amdDependencies: AmdDependency[]; + hasNoDefaultLib?: boolean | undefined; + moduleName?: string | undefined; } -/** @internal */ -export interface SourceFile extends ReadonlyPragmaContext {} - /** @internal */ export interface CommentDirective { range: TextRange; @@ -4486,25 +8195,37 @@ export const enum CommentDirectiveType { Ignore, } -export interface Bundle extends Node { - readonly kind: SyntaxKind.Bundle; - readonly sourceFiles: readonly SourceFile[]; - /** @internal */ syntheticFileReferences?: readonly FileReference[] | undefined; - /** @internal */ syntheticTypeReferences?: readonly FileReference[] | undefined; - /** @internal */ syntheticLibReferences?: readonly FileReference[] | undefined; - /** @internal */ hasNoDefaultLib?: boolean | undefined; +// dprint-ignore +export class Bundle extends Node { + declare readonly ast: AstBundle; + + get sourceFiles(): readonly SourceFile[] { return this.ast.data.sourceFiles; } + + /** @internal */ set sourceFiles(value: readonly SourceFile[]) { this.ast.data.sourceFiles = value; } + /** @internal */ get syntheticFileReferences(): readonly FileReference[] | undefined { return this.ast.data.syntheticFileReferences; } + /** @internal */ set syntheticFileReferences(value: readonly FileReference[] | undefined) { this.ast.data.syntheticFileReferences = value; } + /** @internal */ get syntheticTypeReferences(): readonly FileReference[] | undefined { return this.ast.data.syntheticTypeReferences; } + /** @internal */ set syntheticTypeReferences(value: readonly FileReference[] | undefined) { this.ast.data.syntheticTypeReferences = value; } + /** @internal */ get syntheticLibReferences(): readonly FileReference[] | undefined { return this.ast.data.syntheticLibReferences; } + /** @internal */ set syntheticLibReferences(value: readonly FileReference[] | undefined) { this.ast.data.syntheticLibReferences = value; } + /** @internal */ get hasNoDefaultLib(): boolean | undefined { return this.ast.data.hasNoDefaultLib; } + /** @internal */ set hasNoDefaultLib(value: boolean | undefined) { this.ast.data.hasNoDefaultLib = value; } } export interface JsonSourceFile extends SourceFile { + readonly ast: AstJsonSourceFile; + readonly data: AstJsonSourceFileData; readonly statements: NodeArray; } export interface TsConfigSourceFile extends JsonSourceFile { - extendedSourceFiles?: string[]; - /** @internal */ configFileSpecs?: ConfigFileSpecs; + extendedSourceFiles: string[] | undefined; + /** @internal */ configFileSpecs: ConfigFileSpecs | undefined; } export interface JsonMinusNumericLiteral extends PrefixUnaryExpression { + readonly ast: AstJsonMinusNumericLiteral; + readonly data: AstJsonMinusNumericLiteralData; readonly operator: SyntaxKind.MinusToken; readonly operand: NumericLiteral; } @@ -4519,6 +8240,8 @@ export type JsonObjectExpression = | NullLiteral; export interface JsonObjectExpressionStatement extends ExpressionStatement { + readonly ast: AstJsonObjectExpressionStatement; + readonly data: AstJsonObjectExpressionStatementData; readonly expression: JsonObjectExpression; } @@ -8558,7 +12281,7 @@ export const enum OuterExpressionKinds { /** @internal */ export type OuterExpression = | ParenthesizedExpression - | TypeAssertion + | TypeAssertionExpression | SatisfiesExpression | AsExpression | NonNullExpression @@ -8643,7 +12366,7 @@ export interface NodeFactory { /** @internal */ readonly parenthesizer: ParenthesizerRules; /** @internal */ readonly converters: NodeConverters; /** @internal */ readonly flags: NodeFactoryFlags; - /** @internal */ readonly astFactory: ast.AstNodeFactory; + /** @internal */ readonly astFactory: AstNodeFactory; createNodeArray(elements?: readonly T[], hasTrailingComma?: boolean): NodeArray; @@ -8714,7 +12437,7 @@ export interface NodeFactory { createToken(token: TKind): KeywordTypeNode; createToken(token: TKind): ModifierToken; createToken(token: TKind): KeywordToken; - /** @internal */ createToken(token: TKind): Token; + /** @internal */ createToken(token: TKind): Token; // // Reserved words @@ -8869,8 +12592,8 @@ export interface NodeFactory { updateNewExpression(node: NewExpression, expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined): NewExpression; createTaggedTemplateExpression(tag: Expression, typeArguments: readonly TypeNode[] | undefined, template: TemplateLiteral): TaggedTemplateExpression; updateTaggedTemplateExpression(node: TaggedTemplateExpression, tag: Expression, typeArguments: readonly TypeNode[] | undefined, template: TemplateLiteral): TaggedTemplateExpression; - createTypeAssertion(type: TypeNode, expression: Expression): TypeAssertion; - updateTypeAssertion(node: TypeAssertion, type: TypeNode, expression: Expression): TypeAssertion; + createTypeAssertion(type: TypeNode, expression: Expression): TypeAssertionExpression; + updateTypeAssertion(node: TypeAssertionExpression, type: TypeNode, expression: Expression): TypeAssertionExpression; createParenthesizedExpression(expression: Expression): ParenthesizedExpression; updateParenthesizedExpression(node: ParenthesizedExpression, expression: Expression): ParenthesizedExpression; createFunctionExpression(modifiers: readonly Modifier[] | undefined, asteriskToken: AsteriskToken | undefined, name: string | Identifier | undefined, typeParameters: readonly TypeParameterDeclaration[] | undefined, parameters: readonly ParameterDeclaration[] | undefined, type: TypeNode | undefined, body: Block): FunctionExpression; @@ -9993,15 +13716,10 @@ export interface DiagnosticCollection { getDiagnostics(fileName: string): DiagnosticWithLocation[]; } -// SyntaxKind.SyntaxList -export interface SyntaxList extends Node { - kind: SyntaxKind.SyntaxList; - - // Unlike other nodes which may or may not have their child nodes calculated, - // the entire purpose of a SyntaxList is to hold child nodes. - // Instead of using the WeakMap machinery in `nodeChildren.ts`, - // we just store the children directly on the SyntaxList. - /** @internal */ _children: readonly Node[]; +// dprint-ignore +export class SyntaxList extends Node { + /** @internal */ get _children(): readonly Node[] { return this.ast.data._children; } + /** @internal */ set _children(value: readonly Node[]) { this.ast.data._children = value; } } // dprint-ignore diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 1ebfe3837a405..cccfe9b28c89b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -24,7 +24,14 @@ import { AssignmentDeclarationKind, AssignmentExpression, AssignmentOperatorToken, - ast, + AstBinaryExpression, + AstExpression, + AstHasJSDoc, + AstModifierLike, + AstNewExpression, + AstNode, + AstPostfixUnaryExpression, + AstPrefixUnaryExpression, BarBarEqualsToken, BinaryExpression, binarySearch, @@ -253,6 +260,7 @@ import { isArrayLiteralExpression, isArrowFunction, isAssertionExpression, + isAstJSDocTypeExpression, isAutoAccessorPropertyDeclaration, isBigIntLiteral, isBinaryExpression, @@ -488,6 +496,7 @@ import { QuestionQuestionEqualsToken, ReadonlyCollection, ReadonlyTextRange, + RegularExpressionLiteral, removeTrailingDirectorySeparator, RequireOrImportCall, RequireVariableStatement, @@ -508,6 +517,7 @@ import { shouldAllowImportingTsExtension, Signature, SignatureDeclaration, + SignatureDeclarationBase, SignatureFlags, singleElementArray, singleOrUndefined, @@ -525,6 +535,7 @@ import { Statement, StringLiteral, StringLiteralLike, + StringLiteralLikeNode, StringLiteralType, stringToToken, SuperCall, @@ -561,7 +572,7 @@ import { TupleTypeNode, Type, TypeAliasDeclaration, - TypeAssertion, + TypeAssertionExpression, TypeChecker, TypeCheckerHost, TypeElement, @@ -777,7 +788,7 @@ export function usingSingleLineStringWriter(action: (writer: EmitTextWriter) => } /** @internal */ -export function getFullWidth(node: Node | ast.AstNode): number { +export function getFullWidth(node: Node | AstNode): number { return node.end - node.pos; } @@ -933,8 +944,8 @@ export function hasChangesInResolutions( // Returns true if this node contains a parse error anywhere underneath it. /** @internal */ -export function containsParseError(node: Node | ast.AstNode): boolean { - aggregateChildData(node instanceof ast.AstNode ? node.node : node); // TODO(rbuckton): do not instantiate node +export function containsParseError(node: Node | AstNode): boolean { + aggregateChildData(node instanceof AstNode ? node.node : node); // TODO(rbuckton): do not instantiate node return (node.flags & NodeFlags.ThisNodeOrAnySubNodesHasError) !== 0; } @@ -1058,7 +1069,7 @@ export function isFileLevelUniqueName(sourceFile: SourceFile, name: string, hasG // However, this node will be 'missing' in the sense that no actual source-code/tokens are // contained within it. /** @internal */ -export function nodeIsMissing(node: Node | ast.AstNode | undefined): boolean { +export function nodeIsMissing(node: Node | AstNode | undefined): boolean { if (node === undefined) { return true; } @@ -1067,7 +1078,7 @@ export function nodeIsMissing(node: Node | ast.AstNode | undefined): boolean { } /** @internal */ -export function nodeIsPresent(node: Node | ast.AstNode | undefined): boolean { +export function nodeIsPresent(node: Node | AstNode | undefined): boolean { return !nodeIsMissing(node); } @@ -1279,9 +1290,9 @@ export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: return getTextOfNodeFromSourceText(sourceFile.text, node, includeTrivia); } -function isJSDocTypeExpressionOrChild(node: Node | ast.AstNode): boolean { - return node instanceof ast.AstNode ? - !!findAncestor(node, ast.isAstJSDocTypeExpression) : +function isJSDocTypeExpressionOrChild(node: Node | AstNode): boolean { + return node instanceof AstNode ? + !!findAncestor(node, isAstJSDocTypeExpression) : !!findAncestor(node, isJSDocTypeExpression); } @@ -1312,7 +1323,7 @@ export function moduleExportNameIsDefault(node: ModuleExportName): boolean { } /** @internal */ -export function getTextOfNodeFromSourceText(sourceText: string, node: Node | ast.AstNode, includeTrivia = false): string { +export function getTextOfNodeFromSourceText(sourceText: string, node: Node | AstNode, includeTrivia = false): string { if (nodeIsMissing(node)) { return ""; } @@ -1880,7 +1891,7 @@ export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile | u case SyntaxKind.BigIntLiteral: return node.text; case SyntaxKind.RegularExpressionLiteral: - if (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && node.isUnterminated) { + if (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && (node as RegularExpressionLiteral).isUnterminated) { return node.text + (node.text.charCodeAt(node.text.length - 1) === CharacterCodes.backslash ? " /" : "/"); } return node.text; @@ -1890,7 +1901,7 @@ export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile | u } function canUseOriginalText(node: LiteralLikeNode, flags: GetLiteralTextFlags): boolean { - if (nodeIsSynthesized(node) || !node.parent || (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && node.isUnterminated)) { + if (nodeIsSynthesized(node) || !node.parent || (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && (node as StringLiteralLikeNode).isUnterminated)) { return false; } @@ -2610,7 +2621,7 @@ export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: Sour } /** @internal */ -export function getJSDocCommentRanges(node: Node | ast.AstNode, text: string): CommentRange[] | undefined { +export function getJSDocCommentRanges(node: Node | AstNode, text: string): CommentRange[] | undefined { const commentRanges = (node.kind === SyntaxKind.Parameter || node.kind === SyntaxKind.TypeParameter || node.kind === SyntaxKind.FunctionExpression || @@ -2719,7 +2730,7 @@ export function isPartOfTypeNode(node: Node): boolean { case SyntaxKind.IndexSignature: return node === (parent as SignatureDeclaration).type; case SyntaxKind.TypeAssertionExpression: - return node === (parent as TypeAssertion).type; + return node === (parent as TypeAssertionExpression).type; case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: case SyntaxKind.TaggedTemplateExpression: @@ -2789,7 +2800,7 @@ export function forEachYieldExpression(body: Block, visitor: (expr: YieldExpress return; default: if (isFunctionLike(node)) { - if (node.name && node.name.kind === SyntaxKind.ComputedPropertyName) { + if (isNamedDeclaration(node) && node.name.kind === SyntaxKind.ComputedPropertyName) { // Note that we will not include methods/accessors of a class because they would require // first descending into the class. This is by design. traverse(node.name.expression); @@ -4394,8 +4405,8 @@ export function canHaveFlowNode(node: Node): node is HasFlowNode { /** @internal */ export function canHaveJSDoc(node: Node): node is HasJSDoc; /** @internal */ -export function canHaveJSDoc(node: ast.AstNode): node is ast.AstHasJSDoc; -export function canHaveJSDoc(node: Node | ast.AstNode) { +export function canHaveJSDoc(node: AstNode): node is AstHasJSDoc; +export function canHaveJSDoc(node: Node | AstNode) { switch (node.kind) { case SyntaxKind.ArrowFunction: case SyntaxKind.BinaryExpression: @@ -4672,6 +4683,7 @@ export function getTypeParameterFromJsDoc(node: TypeParameterDeclaration & { par /** @internal @knipignore */ export function hasTypeArguments(node: Node): node is HasTypeArguments { + // TODO: switch on kind return !!(node as HasTypeArguments).typeArguments; } @@ -5183,13 +5195,16 @@ export function getFunctionFlags(node: SignatureDeclaration | undefined): Functi /** @internal */ export function isAsyncFunction(node: Node): boolean { + Debug.type(node); switch (node.kind) { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: case SyntaxKind.MethodDeclaration: - return (node as FunctionLikeDeclaration).body !== undefined - && (node as FunctionLikeDeclaration).asteriskToken === undefined + return node.body !== undefined + && node.asteriskToken === undefined + && hasSyntacticModifier(node, ModifierFlags.Async); + case SyntaxKind.ArrowFunction: + return node.body !== undefined && hasSyntacticModifier(node, ModifierFlags.Async); } return false; @@ -5471,9 +5486,9 @@ export const enum Associativity { } /** @internal */ -export function getExpressionAssociativity(expression: Expression | ast.AstExpression): Associativity { +export function getExpressionAssociativity(expression: Expression | AstExpression): Associativity { const operator = getOperator(expression); - const hasArguments = expression.kind === SyntaxKind.NewExpression && (expression instanceof ast.AstNode ? (expression as ast.AstNewExpression).data.arguments !== undefined : (expression as NewExpression).arguments !== undefined); + const hasArguments = expression.kind === SyntaxKind.NewExpression && (expression instanceof AstNode ? (expression as AstNewExpression).data.arguments !== undefined : (expression as NewExpression).arguments !== undefined); return getOperatorAssociativity(expression.kind, operator, hasArguments); } @@ -5518,18 +5533,18 @@ export function getOperatorAssociativity(kind: SyntaxKind, operator: SyntaxKind, } /** @internal */ -export function getExpressionPrecedence(expression: Expression | ast.AstExpression): OperatorPrecedence { +export function getExpressionPrecedence(expression: Expression | AstExpression): OperatorPrecedence { const operator = getOperator(expression); - const hasArguments = expression.kind === SyntaxKind.NewExpression && (expression instanceof ast.AstNode ? (expression as ast.AstNewExpression).data.arguments !== undefined : (expression as NewExpression).arguments !== undefined); + const hasArguments = expression.kind === SyntaxKind.NewExpression && (expression instanceof AstNode ? (expression as AstNewExpression).data.arguments !== undefined : (expression as NewExpression).arguments !== undefined); return getOperatorPrecedence(expression.kind, operator, hasArguments); } -function getOperator(expression: Expression | ast.AstExpression): SyntaxKind { +function getOperator(expression: Expression | AstExpression): SyntaxKind { if (expression.kind === SyntaxKind.BinaryExpression) { - return expression instanceof ast.AstNode ? (expression as ast.AstBinaryExpression).data.operatorToken.kind : (expression as BinaryExpression).operatorToken.kind; + return expression instanceof AstNode ? (expression as AstBinaryExpression).data.operatorToken.kind : (expression as BinaryExpression).operatorToken.kind; } else if (expression.kind === SyntaxKind.PrefixUnaryExpression || expression.kind === SyntaxKind.PostfixUnaryExpression) { - return expression instanceof ast.AstNode ? (expression as ast.AstPrefixUnaryExpression | ast.AstPostfixUnaryExpression).data.operator : (expression as PrefixUnaryExpression | PostfixUnaryExpression).operator; + return expression instanceof AstNode ? (expression as AstPrefixUnaryExpression | AstPostfixUnaryExpression).data.operator : (expression as PrefixUnaryExpression | PostfixUnaryExpression).operator; } else { return expression.kind; @@ -7172,7 +7187,7 @@ export function getSyntacticModifierFlagsNoCache(node: Node): ModifierFlags { } /** @internal */ -export function modifiersToFlags(modifiers: readonly ModifierLike[] | readonly ast.AstModifierLike[] | undefined): ModifierFlags { +export function modifiersToFlags(modifiers: readonly ModifierLike[] | readonly AstModifierLike[] | undefined): ModifierFlags { let flags = ModifierFlags.None; if (modifiers) { for (const modifier of modifiers) { @@ -10424,11 +10439,11 @@ export function setNodeFlags(node: T | undefined, newFlags: Node * * @internal */ -export function setParent(child: T, parent: T["parent"] | undefined): T; +export function setParent(child: T, parent: T["parent"] | undefined): T; /** @internal */ -export function setParent(child: T | undefined, parent: T["parent"] | undefined): T | undefined; +export function setParent(child: T | undefined, parent: T["parent"] | undefined): T | undefined; /** @internal */ -export function setParent(child: T | undefined, parent: T["parent"] | undefined): T | undefined { +export function setParent(child: T | undefined, parent: T["parent"] | undefined): T | undefined { if (child && parent) { (child as Mutable).parent = parent; } @@ -11700,13 +11715,16 @@ export function createNameResolver({ return isTypeQueryNode(location) || (( isFunctionLikeDeclaration(location) || (location.kind === SyntaxKind.PropertyDeclaration && !isStatic(location)) - ) && (!lastLocation || lastLocation !== (location as SignatureDeclaration | PropertyDeclaration).name)); // A name is evaluated within the enclosing scope - so it shouldn't count as deferred + // TODO(rbuckton): unchecked cast can result in wrong map deopt for missing `name` property + ) && (!lastLocation || lastLocation !== (location as SignatureDeclarationBase | PropertyDeclaration).name)); // A name is evaluated within the enclosing scope - so it shouldn't count as deferred } - if (lastLocation && lastLocation === (location as FunctionExpression | ArrowFunction).name) { + // TODO(rbuckton): unchecked cast can result in wrong map deopt for missing `name` property + if (lastLocation && lastLocation === (location as FunctionExpression).name) { return false; } // generator functions and async functions are not inlined in control flow when immediately invoked - if ((location as FunctionExpression | ArrowFunction).asteriskToken || hasSyntacticModifier(location, ModifierFlags.Async)) { + // TODO(rbuckton): unchecked cast can result in wrong map deopt for missing `asteriskToken` property + if ((location as FunctionExpression).asteriskToken || hasSyntacticModifier(location, ModifierFlags.Async)) { return true; } return !getImmediatelyInvokedFunctionExpression(location); diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 3608fbada2251..ac237de709d0b 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -9,7 +9,6 @@ import { AssertionExpression, AssignmentDeclarationKind, AssignmentPattern, - ast, AutoAccessorPropertyDeclaration, BinaryExpression, BindableObjectDefinePropertyCall, @@ -227,6 +226,7 @@ import { ModuleDeclaration, ModuleReference, NamedDeclaration, + HasName, NamedExportBindings, NamedImportBindings, NamespaceBody, @@ -291,6 +291,10 @@ import { TypeReferenceType, UnaryExpression, VariableDeclaration, + HasQuestionToken, + HasAsteriskToken, + AsteriskToken, + AstNode, } from "./_namespaces/ts.js"; export function isExternalModuleNameRelative(moduleName: string): boolean { @@ -780,7 +784,7 @@ interface AncestorTraversable> { * At that point findAncestor returns undefined. * @internal */ -export function findAncestor(node: ast.AstNode | undefined, callback: (element: ast.AstNode) => element is T): T | undefined; +export function findAncestor(node: AstNode | undefined, callback: (element: AstNode) => element is T): T | undefined; /** * Iterates through the parent chain of a node and performs the callback on each parent until the callback * returns a truthy value, then returns that value. @@ -789,7 +793,7 @@ export function findAncestor(node: ast.AstNode | undefine */ export function findAncestor(node: Node | undefined, callback: (element: Node) => element is T): T | undefined; /** @internal */ -export function findAncestor(node: ast.AstNode | undefined, callback: (element: ast.AstNode) => boolean | "quit"): ast.AstNode | undefined; +export function findAncestor(node: AstNode | undefined, callback: (element: AstNode) => boolean | "quit"): AstNode | undefined; export function findAncestor(node: Node | undefined, callback: (element: Node) => boolean | "quit"): Node | undefined; export function findAncestor>(node: T | T | undefined, callback: (element: T) => boolean | "quit"): T | undefined { while (node) { @@ -812,8 +816,8 @@ export function findAncestor>(node: T | T | und */ export function isParseTreeNode(node: Node): boolean; /** @internal */ -export function isParseTreeNode(node: Node | ast.AstNode): boolean; // eslint-disable-line @typescript-eslint/unified-signatures -export function isParseTreeNode(node: Node | ast.AstNode): boolean { +export function isParseTreeNode(node: Node | AstNode): boolean; // eslint-disable-line @typescript-eslint/unified-signatures +export function isParseTreeNode(node: Node | AstNode): boolean { return (node.flags & NodeFlags.Synthesized) === 0; } @@ -956,6 +960,98 @@ export function isNamedDeclaration(node: Node): node is NamedDeclaration & { nam return !!(node as NamedDeclaration).name; // A 'name' property should always be a DeclarationName. } +/** @internal */ +export function canHaveName(node: Node): node is HasName { + switch (node.kind) { + case SyntaxKind.BindingElement: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.EnumMember: + case SyntaxKind.ExportSpecifier: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.GetAccessor: + case SyntaxKind.ImportAttribute: + case SyntaxKind.ImportClause: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ImportSpecifier: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.JSDocCallbackTag: + case SyntaxKind.JSDocLink: + case SyntaxKind.JSDocLinkCode: + case SyntaxKind.JSDocLinkPlain: + case SyntaxKind.JSDocNameReference: + case SyntaxKind.JSDocParameterTag: + case SyntaxKind.JSDocPropertyTag: + case SyntaxKind.JSDocSeeTag: + case SyntaxKind.JSDocTypedefTag: + case SyntaxKind.JsxAttribute: + case SyntaxKind.JsxNamespacedName: + case SyntaxKind.MetaProperty: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.MissingDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.NamedTupleMember: + case SyntaxKind.NamespaceExport: + case SyntaxKind.NamespaceExportDeclaration: + case SyntaxKind.NamespaceImport: + case SyntaxKind.Parameter: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.PropertyAssignment: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.SetAccessor: + case SyntaxKind.ShorthandPropertyAssignment: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.TypeParameter: + case SyntaxKind.VariableDeclaration: + return true; + } + return false; +} + +/** @internal */ +export function hasName(node: Node): node is HasName & { name: DeclarationName } { + return canHaveName(node) && !!node.name; +} + +/** @internal */ +export function canHaveQuestionToken(node: Node): node is HasQuestionToken { + switch (node.kind) { + case SyntaxKind.Parameter: + case SyntaxKind.PropertySignature: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.ShorthandPropertyAssignment: + case SyntaxKind.MappedType: + case SyntaxKind.NamedTupleMember: + case SyntaxKind.ConditionalExpression: + case SyntaxKind.PropertyAssignment: + return true; + } + return false; +} + +/** @internal */ +export function canHaveAsteriskToken(node: Node): node is HasAsteriskToken { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.YieldExpression: + return true; + } + return false; +} + +/** @internal */ +export function hasAsteriskToken(node: Node): node is HasAsteriskToken & { asteriskToken: AsteriskToken } { + return canHaveAsteriskToken(node) && !!node.asteriskToken; +} + /** @internal */ export function getNonAssignedNameOfDeclaration(declaration: Declaration | Expression): DeclarationName | undefined { switch (declaration.kind) { @@ -1494,7 +1590,7 @@ export function isToken(n: Node): boolean { /** @internal */ export function isNodeArray(array: readonly T[]): array is NodeArray { - return hasProperty(array, "pos") && hasProperty(array, "end") || array instanceof ast.NodeArray; + return hasProperty(array, "pos") && hasProperty(array, "end") || array instanceof NodeArray; } // Literals @@ -2558,6 +2654,7 @@ export function hasJSDocNodes(node: Node): node is HasJSDoc { * @internal */ export function hasType(node: Node): node is HasType { + // TODO: switch on kind return !!(node as HasType).type; } @@ -2567,6 +2664,7 @@ export function hasType(node: Node): node is HasType { * @internal */ export function hasInitializer(node: Node): node is HasInitializer { + // TODO: switch on kind return !!(node as HasInitializer).initializer; } diff --git a/src/harness/harnessUtils.ts b/src/harness/harnessUtils.ts index 63635adb82425..e00957ff814db 100644 --- a/src/harness/harnessUtils.ts +++ b/src/harness/harnessUtils.ts @@ -175,8 +175,8 @@ function convertDiagnostic(diagnostic: ts.Diagnostic) { export function sourceFileToJSON(file: ts.Node): string { const s = JSON.stringify(file, (_, v) => { - if (v instanceof ts.ast.AstNode) v = v.node; - if (v instanceof ts.ast.AstNodeArray) v = v.nodes; + if (v instanceof ts.AstNode) v = v.node; + if (v instanceof ts.AstNodeArray) v = v.nodes; return isNodeOrArray(v) ? serializeNode(v) : v; }, " "); return s; @@ -267,8 +267,8 @@ export function sourceFileToJSON(file: ts.Node): string { default: { let value = obj[propertyName]; - if (value instanceof ts.ast.AstNode) value = value.node; - if (value instanceof ts.ast.AstNodeArray) value = value.nodes; + if (value instanceof ts.AstNode) value = value.node; + if (value instanceof ts.AstNodeArray) value = value.nodes; o[propertyName] = value; } } @@ -282,7 +282,7 @@ export function sourceFileToJSON(file: ts.Node): string { if (ts.containsParseError(n)) { o.containsParseError = true; } - if (n instanceof ts.ast.Node) { + if (n instanceof ts.Node) { serializeProperties(o, n, n, ["pos", "end", "flags", "modifierFlagsCache", "transformFlags"]); serializeProperties(o, n, n.ast.data, Object.getOwnPropertyNames(n.ast.data)); } @@ -292,7 +292,7 @@ export function sourceFileToJSON(file: ts.Node): string { } else { serializeProperties(o, /*n*/ undefined, n, Object.getOwnPropertyNames(n)); - if (n instanceof ts.ast.NodeArray) { + if (n instanceof ts.NodeArray) { serializeProperties(o, /*n*/ undefined, n, ["pos", "end", "hasTrailingComma", "transformFlags"]); } } @@ -376,10 +376,10 @@ function assertArrayStructuralEquals(array1: ts.NodeArray, array2: ts.N } function findChildName(parent: any, child: any) { - if (parent instanceof ts.ast.Node) { + if (parent instanceof ts.Node) { parent = parent.ast.data; } - if (child instanceof ts.ast.Node || child instanceof ts.ast.NodeArray) { + if (child instanceof ts.Node || child instanceof ts.NodeArray) { child = child.ast; } for (const name in parent) { diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index b3e53fed929b5..ab957a5aa5a1c 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -64,7 +64,7 @@ import { TextSpan, ThrowStatement, TryStatement, - TypeAssertion, + TypeAssertionExpression, VariableDeclaration, VariableDeclarationList, VariableStatement, @@ -423,8 +423,8 @@ export function spanInSourceFileAtLocation(sourceFile: SourceFile, position: num break; case SyntaxKind.TypeAssertionExpression: // Breakpoint in type assertion goes to its operand - if ((node.parent as TypeAssertion).type === node) { - return spanInNextNode((node.parent as TypeAssertion).type); + if ((node.parent as TypeAssertionExpression).type === node) { + return spanInNextNode((node.parent as TypeAssertionExpression).type); } break; case SyntaxKind.VariableDeclaration: diff --git a/src/services/callHierarchy.ts b/src/services/callHierarchy.ts index 77a3b4698e2c0..e1bf30a2a02c0 100644 --- a/src/services/callHierarchy.ts +++ b/src/services/callHierarchy.ts @@ -101,7 +101,7 @@ import { TaggedTemplateExpression, TextRange, TextSpan, - TypeAssertion, + TypeAssertionExpression, TypeChecker, usingSingleLineStringWriter, VariableDeclaration, @@ -538,7 +538,7 @@ function createCallSiteCollector(program: Program, callSites: CallSite[]): (node case SyntaxKind.TypeAssertionExpression: case SyntaxKind.AsExpression: // do not descend into the type side of an assertion - collect((node as TypeAssertion | AsExpression).expression); + collect((node as TypeAssertionExpression | AsExpression).expression); return; case SyntaxKind.VariableDeclaration: case SyntaxKind.Parameter: diff --git a/src/services/codefixes/addConvertToUnknownForNonOverlappingTypes.ts b/src/services/codefixes/addConvertToUnknownForNonOverlappingTypes.ts index 942cb05ffb687..6936b90863a65 100644 --- a/src/services/codefixes/addConvertToUnknownForNonOverlappingTypes.ts +++ b/src/services/codefixes/addConvertToUnknownForNonOverlappingTypes.ts @@ -15,7 +15,7 @@ import { SourceFile, SyntaxKind, textChanges, - TypeAssertion, + TypeAssertionExpression, } from "../_namespaces/ts.js"; const fixId = "addConvertToUnknownForNonOverlappingTypes"; @@ -38,14 +38,14 @@ registerCodeFix({ }), }); -function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, assertion: AsExpression | TypeAssertion) { +function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, assertion: AsExpression | TypeAssertionExpression) { const replacement = isAsExpression(assertion) ? factory.createAsExpression(assertion.expression, factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword)) : factory.createTypeAssertion(factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword), assertion.expression); changeTracker.replaceNode(sourceFile, assertion.expression, replacement); } -function getAssertion(sourceFile: SourceFile, pos: number): AsExpression | TypeAssertion | undefined { +function getAssertion(sourceFile: SourceFile, pos: number): AsExpression | TypeAssertionExpression | undefined { if (isInJSFile(sourceFile)) return undefined; - return findAncestor(getTokenAtPosition(sourceFile, pos), (n): n is AsExpression | TypeAssertion => isAsExpression(n) || isTypeAssertionExpression(n)); + return findAncestor(getTokenAtPosition(sourceFile, pos), (n): n is AsExpression | TypeAssertionExpression => isAsExpression(n) || isTypeAssertionExpression(n)); } diff --git a/src/services/codefixes/convertFunctionToEs6Class.ts b/src/services/codefixes/convertFunctionToEs6Class.ts index 56fdaeec81da2..203ca2b7fce7e 100644 --- a/src/services/codefixes/convertFunctionToEs6Class.ts +++ b/src/services/codefixes/convertFunctionToEs6Class.ts @@ -28,6 +28,7 @@ import { getNameOfDeclaration, getQuotePreference, getTokenAtPosition, + hasName, idText, isAccessExpression, isArrowFunction, @@ -315,7 +316,7 @@ function getModifierKindFromSource(source: Node, kind: Modifier["kind"]): readon } function isConstructorAssignment(x: ObjectLiteralElementLike | PropertyAccessExpression) { - if (!x.name) return false; + if (!hasName(x)) return false; if (isIdentifier(x.name) && x.name.text === "constructor") return true; return false; } diff --git a/src/services/codefixes/convertToEsModule.ts b/src/services/codefixes/convertToEsModule.ts index 02d1a5f930114..7628adb536bcb 100644 --- a/src/services/codefixes/convertToEsModule.ts +++ b/src/services/codefixes/convertToEsModule.ts @@ -9,6 +9,7 @@ import { BinaryExpression, BindingElement, BindingName, + canHaveAsteriskToken, ClassDeclaration, ClassExpression, concatenate, @@ -35,6 +36,7 @@ import { getSynthesizedDeepClones, getSynthesizedDeepClonesWithReplacements, getSynthesizedDeepCloneWithReplacements, + hasName, Identifier, ImportDeclaration, importFromModuleSpecifier, @@ -77,6 +79,7 @@ import { SymbolFlags, SyntaxKind, textChanges, + tryCast, TypeChecker, VariableStatement, } from "../_namespaces/ts.js"; @@ -411,11 +414,11 @@ function reExportDefault(moduleSpecifier: string): ExportDeclaration { function convertExportsPropertyAssignment({ left, right, parent }: BinaryExpression & { left: PropertyAccessExpression; }, sourceFile: SourceFile, changes: textChanges.ChangeTracker): void { const name = left.name.text; - if ((isFunctionExpression(right) || isArrowFunction(right) || isClassExpression(right)) && (!right.name || right.name.text === name)) { + if ((isFunctionExpression(right) || isArrowFunction(right) || isClassExpression(right)) && (!hasName(right) || right.name.text === name)) { // `exports.f = function() {}` -> `export function f() {}` -- Replace `exports.f = ` with `export `, and insert the name after `function`. changes.replaceRange(sourceFile, { pos: left.getStart(sourceFile), end: right.getStart(sourceFile) }, factory.createToken(SyntaxKind.ExportKeyword), { suffix: " " }); - if (!right.name) changes.insertName(sourceFile, right, name); + if (!hasName(right)) changes.insertName(sourceFile, right, name); const semi = findChildOfKind(parent, SyntaxKind.SemicolonToken, sourceFile); if (semi) changes.delete(sourceFile, semi); @@ -631,7 +634,7 @@ function isFreeIdentifier(node: Identifier): boolean { function functionExpressionToDeclaration(name: string | undefined, additionalModifiers: readonly Modifier[], fn: FunctionExpression | ArrowFunction | MethodDeclaration, useSitesToUnqualify: Map | undefined): FunctionDeclaration { return factory.createFunctionDeclaration( concatenate(additionalModifiers, getSynthesizedDeepClones(fn.modifiers)), - getSynthesizedDeepClone(fn.asteriskToken), + getSynthesizedDeepClone(tryCast(fn, canHaveAsteriskToken)?.asteriskToken), name, getSynthesizedDeepClones(fn.typeParameters), getSynthesizedDeepClones(fn.parameters), diff --git a/src/services/codefixes/convertToMappedObjectType.ts b/src/services/codefixes/convertToMappedObjectType.ts index c4330112e8100..8d3223774af53 100644 --- a/src/services/codefixes/convertToMappedObjectType.ts +++ b/src/services/codefixes/convertToMappedObjectType.ts @@ -79,7 +79,7 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, { hasEffectiveReadonlyModifier(indexSignature) ? factory.createModifier(SyntaxKind.ReadonlyKeyword) : undefined, mappedTypeParameter, /*nameType*/ undefined, - indexSignature.questionToken, + /*questionToken*/ undefined, indexSignature.type, /*members*/ undefined, ); diff --git a/src/services/codefixes/fixJSDocTypes.ts b/src/services/codefixes/fixJSDocTypes.ts index 7d3983db3d48d..ecfe916d4648d 100644 --- a/src/services/codefixes/fixJSDocTypes.ts +++ b/src/services/codefixes/fixJSDocTypes.ts @@ -30,7 +30,7 @@ import { textChanges, Type, TypeAliasDeclaration, - TypeAssertion, + TypeAssertionExpression, TypeChecker, TypeFlags, TypeNode, @@ -92,7 +92,7 @@ function getInfo(sourceFile: SourceFile, pos: number, checker: TypeChecker): { r } // TODO: GH#19856 Node & { type: TypeNode } -type TypeContainer = AsExpression | CallSignatureDeclaration | ConstructSignatureDeclaration | FunctionDeclaration | GetAccessorDeclaration | IndexSignatureDeclaration | MappedTypeNode | MethodDeclaration | MethodSignature | ParameterDeclaration | PropertyDeclaration | PropertySignature | SetAccessorDeclaration | TypeAliasDeclaration | TypeAssertion | VariableDeclaration; +type TypeContainer = AsExpression | CallSignatureDeclaration | ConstructSignatureDeclaration | FunctionDeclaration | GetAccessorDeclaration | IndexSignatureDeclaration | MappedTypeNode | MethodDeclaration | MethodSignature | ParameterDeclaration | PropertyDeclaration | PropertySignature | SetAccessorDeclaration | TypeAliasDeclaration | TypeAssertionExpression | VariableDeclaration; function isTypeContainer(node: Node): node is TypeContainer { // NOTE: Some locations are not handled yet: // MappedTypeNode.typeParameters and SignatureDeclaration.typeParameters, as well as CallExpression.typeArguments diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 7957b28b110f5..0789108d9199d 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -6,6 +6,7 @@ import { ArrowFunction, Block, CallExpression, + canHaveAsteriskToken, CharacterCodes, CheckFlags, ClassLikeDeclaration, @@ -469,7 +470,7 @@ export function createSignatureDeclarationFromSignature( } const questionToken = optional ? factory.createToken(SyntaxKind.QuestionToken) : undefined; - const asteriskToken = signatureDeclaration.asteriskToken; + const asteriskToken = tryCast(signatureDeclaration, canHaveAsteriskToken)?.asteriskToken; if (isFunctionExpression(signatureDeclaration)) { return factory.updateFunctionExpression(signatureDeclaration, modifiers, signatureDeclaration.asteriskToken, tryCast(name, isIdentifier), typeParameters, parameters, type, body ?? signatureDeclaration.body); } diff --git a/src/services/codefixes/inferFromUsage.ts b/src/services/codefixes/inferFromUsage.ts index 620542686acab..78529cc5823e5 100644 --- a/src/services/codefixes/inferFromUsage.ts +++ b/src/services/codefixes/inferFromUsage.ts @@ -521,7 +521,7 @@ function getFunctionReferences(containingFunction: SignatureDeclaration, sourceF const parent = containingFunction.parent; searchToken = (isVariableDeclaration(parent) || isPropertyDeclaration(parent)) && isIdentifier(parent.name) ? parent.name : - containingFunction.name; + isFunctionExpression(containingFunction) ? containingFunction.name : undefined; break; case SyntaxKind.FunctionDeclaration: case SyntaxKind.MethodDeclaration: diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 74aeb9c5be05c..03cc77c9f79e5 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -96,6 +96,7 @@ import { GoToDefinition, hasEffectiveModifier, hasInitializer, + hasName, hasSyntacticModifier, hasType, HighlightSpan, @@ -389,9 +390,9 @@ function getContextNodeForNodeEntry(node: Node): ContextNode | undefined { } if ( - node.parent.name === node || // node is name of declaration, use parent - isConstructorDeclaration(node.parent) || isExportAssignment(node.parent) || + isConstructorDeclaration(node.parent) || + node.parent.name === node || // node is name of declaration, use parent // Property name of the import export specifier or binding pattern, use parent ((isImportOrExportSpecifier(node.parent) || isBindingElement(node.parent)) && node.parent.propertyName === node) || @@ -1752,7 +1753,7 @@ export namespace Core { checker: TypeChecker, cb: (name: Identifier, call?: CallExpression) => boolean, ): boolean { - if (!signature.name || !isIdentifier(signature.name)) return false; + if (!hasName(signature) || !isIdentifier(signature.name)) return false; const symbol = Debug.checkDefined(checker.getSymbolAtLocation(signature.name)); diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index 9a47d90ce1deb..52e35eda0b4a3 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -37,6 +37,7 @@ import { getTextOfPropertyName, getTouchingPropertyName, getTouchingToken, + hasAsteriskToken, hasEffectiveModifier, hasInitializer, hasStaticModifier, @@ -167,7 +168,7 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile if (node.kind === SyntaxKind.YieldKeyword) { const functionDeclaration = findAncestor(node, n => isFunctionLikeDeclaration(n)); - const isGeneratorFunction = functionDeclaration && functionDeclaration.asteriskToken; + const isGeneratorFunction = functionDeclaration && hasAsteriskToken(functionDeclaration); return isGeneratorFunction ? [createDefinitionFromSignatureDeclaration(typeChecker, functionDeclaration)] : undefined; } diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index 316d3874fb40e..5e35328032a40 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -138,7 +138,7 @@ export const enum ImportExport { } interface AmbientModuleDeclaration extends ModuleDeclaration { - body?: ModuleBlock; + body: ModuleBlock | undefined; } type SourceFileLike = SourceFile | AmbientModuleDeclaration; // Identifier for the case of `const x = require("y")`. diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 6ca2a1804a8ce..68b3e9283375a 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -48,6 +48,7 @@ import { getTextOfIdentifierOrLiteral, getTextOfNode, hasJSDocNodes, + hasName, Identifier, ImportClause, InterfaceDeclaration, @@ -407,12 +408,12 @@ function addChildrenRecursively(node: Node | undefined): void { break; } case SyntaxKind.FunctionDeclaration: - const nameNode = (node as FunctionLikeDeclaration).name; + const nameNode = (node as FunctionDeclaration).name; // If we see a function declaration track as a possible ES5 class if (nameNode && isIdentifier(nameNode)) { addTrackedEs5Class(nameNode.text); } - addNodeWithRecursiveChild(node, (node as FunctionLikeDeclaration).body); + addNodeWithRecursiveChild(node, (node as FunctionDeclaration).body); break; case SyntaxKind.ArrowFunction: case SyntaxKind.FunctionExpression: @@ -1027,7 +1028,7 @@ function getModifiers(node: Node): string { function getFunctionOrClassName(node: FunctionExpression | FunctionDeclaration | ArrowFunction | ClassLikeDeclaration): string { const { parent } = node; - if (node.name && getFullWidth(node.name) > 0) { + if (hasName(node) && getFullWidth(node.name) > 0) { return cleanText(declarationNameToString(node.name)); } // See if it is a var initializer. If so, use the var name. diff --git a/src/services/refactors/convertArrowFunctionOrFunctionExpression.ts b/src/services/refactors/convertArrowFunctionOrFunctionExpression.ts index ef0576e59f8bb..2874f801cd60e 100644 --- a/src/services/refactors/convertArrowFunctionOrFunctionExpression.ts +++ b/src/services/refactors/convertArrowFunctionOrFunctionExpression.ts @@ -2,6 +2,7 @@ import { ApplicableRefactorInfo, ArrowFunction, Block, + canHaveAsteriskToken, ConciseBody, copyComments, copyTrailingAsLeadingComments, @@ -48,6 +49,7 @@ import { suppressLeadingTrivia, SyntaxKind, textChanges, + tryCast, TypeChecker, VariableDeclaration, VariableDeclarationList, @@ -261,7 +263,7 @@ function getVariableInfo(func: FunctionExpression | ArrowFunction): VariableInfo function getEditInfoForConvertToAnonymousFunction(context: RefactorContext, func: FunctionExpression | ArrowFunction): FileTextChanges[] { const { file } = context; const body = convertToBlock(func.body); - const newNode = factory.createFunctionExpression(func.modifiers, func.asteriskToken, /*name*/ undefined, func.typeParameters, func.parameters, func.type, body); + const newNode = factory.createFunctionExpression(func.modifiers, tryCast(func, canHaveAsteriskToken)?.asteriskToken, /*name*/ undefined, func.typeParameters, func.parameters, func.type, body); return textChanges.ChangeTracker.with(context, t => t.replaceNode(file, func, newNode)); } @@ -274,7 +276,7 @@ function getEditInfoForConvertToNamedFunction(context: RefactorContext, func: Fu const modifiersFlags = (getCombinedModifierFlags(variableDeclaration) & ModifierFlags.Export) | getEffectiveModifierFlags(func); const modifiers = factory.createModifiersFromModifierFlags(modifiersFlags); - const newNode = factory.createFunctionDeclaration(length(modifiers) ? modifiers : undefined, func.asteriskToken, name, func.typeParameters, func.parameters, func.type, body); + const newNode = factory.createFunctionDeclaration(length(modifiers) ? modifiers : undefined, tryCast(func, canHaveAsteriskToken)?.asteriskToken, name, func.typeParameters, func.parameters, func.type, body); if (variableDeclarationList.declarations.length === 1) { return textChanges.ChangeTracker.with(context, t => t.replaceNode(file, statement, newNode)); diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 2d59e42c433d6..d419850fcc0e6 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -9,6 +9,7 @@ import { BreakStatement, CancellationToken, canHaveModifiers, + cast, CharacterCodes, ClassElement, ClassLikeDeclaration, @@ -59,6 +60,7 @@ import { getThisContainer, getUniqueName, hasEffectiveModifier, + hasName, hasSyntacticModifier, Identifier, InternalNodeBuilderFlags, @@ -1646,7 +1648,7 @@ function transformFunctionBody(body: Node, exposedVariableDeclarations: readonly assignments.unshift(factory.createPropertyAssignment(returnValueProperty, visitNode(node.expression, visitor, isExpression))); } if (assignments.length === 1) { - return factory.createReturnStatement(assignments[0].name as Expression); + return factory.createReturnStatement(cast(assignments[0], hasName).name as Expression); } else { return factory.createReturnStatement(factory.createObjectLiteralExpression(assignments)); diff --git a/src/services/suggestionDiagnostics.ts b/src/services/suggestionDiagnostics.ts index 3c4cf5c39b976..d36fc35809969 100644 --- a/src/services/suggestionDiagnostics.ts +++ b/src/services/suggestionDiagnostics.ts @@ -6,6 +6,7 @@ import { Block, CallExpression, CancellationToken, + canHaveName, codefix, compilerOptionsIndicateEsModules, createDiagnosticForNode, @@ -24,6 +25,7 @@ import { getAssignmentDeclarationKind, getFunctionFlags, hasInitializer, + hasName, hasPropertyAccessExpressionWithName, Identifier, importFromModuleSpecifier, @@ -55,6 +57,7 @@ import { some, SourceFile, SyntaxKind, + tryCast, TypeChecker, VariableStatement, } from "./_namespaces/ts.js"; @@ -125,7 +128,7 @@ export function computeSuggestionDiagnostics(sourceFile: SourceFile, program: Pr } if (codefix.parameterShouldGetTypeFromJSDoc(node)) { - diags.push(createDiagnosticForNode(node.name || node, Diagnostics.JSDoc_types_may_be_moved_to_TypeScript_types)); + diags.push(createDiagnosticForNode(tryCast(node, canHaveName)?.name ?? node, Diagnostics.JSDoc_types_may_be_moved_to_TypeScript_types)); } } @@ -176,7 +179,7 @@ function addConvertToAsyncFunctionDiagnostics(node: FunctionLikeDeclaration, che // need to check function before checking map so that deeper levels of nested callbacks are checked if (isConvertibleFunction(node, checker) && !visitedNestedConvertibleFunctions.has(getKeyFromNode(node))) { diags.push(createDiagnosticForNode( - !node.name && isVariableDeclaration(node.parent) && isIdentifier(node.parent.name) ? node.parent.name : node, + !hasName(node) && isVariableDeclaration(node.parent) && isIdentifier(node.parent.name) ? node.parent.name : node, Diagnostics.This_may_be_converted_to_an_async_function, )); } diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index 6c49848435e70..ca22f49d29705 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -29,6 +29,7 @@ import { getTextOfConstantValue, getTextOfIdentifierOrLiteral, getTextOfNode, + hasName, hasSyntacticModifier, idText, ImportEqualsDeclaration, @@ -509,7 +510,7 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker: Type displayParts.push(keywordPart(SyntaxKind.NewKeyword)); displayParts.push(spacePart()); } - else if (declaration.kind !== SyntaxKind.CallSignature && declaration.name) { + else if (declaration.kind !== SyntaxKind.CallSignature && hasName(declaration)) { addFullSymbolName(declaration.symbol); } addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature)); diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index b0a34cecde904..73683a9c0959b 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -1,7 +1,6 @@ import { addToSeen, ArrowFunction, - ast, BindingElement, CharacterCodes, ClassElement, @@ -67,6 +66,7 @@ import { group, HasJSDoc, hasJSDocNodes, + hasName, ImportClause, ImportSpecifier, indexOfNode, @@ -163,6 +163,7 @@ import { TextRange, textSpanEnd, Token, + TokenSyntaxKind, tokenToString, toSorted, TransformationContext, @@ -681,11 +682,11 @@ export class ChangeTracker { this.insertNodesAt(sourceFile, getAdjustedStartPosition(sourceFile, before, options), newNodes, this.getOptionsForInsertNodeBefore(before, first(newNodes), blankLineBetween)); } - public insertModifierAt(sourceFile: SourceFile, pos: number, modifier: SyntaxKind, options: InsertNodeOptions = {}): void { + public insertModifierAt(sourceFile: SourceFile, pos: number, modifier: TokenSyntaxKind, options: InsertNodeOptions = {}): void { this.insertNodeAt(sourceFile, pos, factory.createToken(modifier), options); } - public insertModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void { + public insertModifierBefore(sourceFile: SourceFile, modifier: TokenSyntaxKind, before: Node): void { return this.insertModifierAt(sourceFile, before.getStart(sourceFile), modifier, { suffix: " " }); } @@ -980,7 +981,7 @@ export class ChangeTracker { } public insertName(sourceFile: SourceFile, node: FunctionExpression | ClassExpression | ArrowFunction, name: string): void { - Debug.assert(!node.name); + Debug.assert(!hasName(node)); if (node.kind === SyntaxKind.ArrowFunction) { const arrow = findChildOfKind(node, SyntaxKind.EqualsGreaterThanToken, sourceFile)!; const lparen = findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile); @@ -1384,7 +1385,7 @@ const textChangesTransformationContext: TransformationContext = { export function assignPositionsToNode(node: Node): Node { const visited = visitEachChild(node, assignPositionsToNode, textChangesTransformationContext, assignPositionsToNodeArray, assignPositionsToNode); // create proxy node for non synthesized nodes - const newNode = nodeIsSynthesized(visited) ? visited : (visited as ast.Node).ast.shadow().node; + const newNode = nodeIsSynthesized(visited) ? visited : visited.ast.shadow().node; setTextRangePosEnd(newNode, getPos(node), getEnd(node)); return newNode; } diff --git a/src/services/types.ts b/src/services/types.ts index 30e4ee715d2af..a40ed9f838cbb 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -14,6 +14,7 @@ import { GetEffectiveTypeRootsHost, HasChangedAutomaticTypeDirectiveNames, HasInvalidatedResolutions, + IScriptSnapshot, JSDocParsingMode, LineAndCharacter, MinimalResolutionCacheHost, @@ -43,50 +44,6 @@ import { UserPreferences, } from "./_namespaces/ts.js"; -declare module "../compiler/types.js" { - // Module transform: converted from interface augmentation - export interface Node { - getSourceFile(): SourceFile; - getChildCount(sourceFile?: SourceFile): number; - getChildAt(index: number, sourceFile?: SourceFile): Node; - getChildren(sourceFile?: SourceFile): readonly Node[]; - /** @internal */ - getChildren(sourceFile?: SourceFileLike): readonly Node[]; // eslint-disable-line @typescript-eslint/unified-signatures - getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number; - /** @internal */ - getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number; // eslint-disable-line @typescript-eslint/unified-signatures - getFullStart(): number; - getEnd(): number; - getWidth(sourceFile?: SourceFileLike): number; - getFullWidth(): number; - getLeadingTriviaWidth(sourceFile?: SourceFile): number; - getFullText(sourceFile?: SourceFile): string; - getText(sourceFile?: SourceFile): string; - getFirstToken(sourceFile?: SourceFile): Node | undefined; - /** @internal */ - getFirstToken(sourceFile?: SourceFileLike): Node | undefined; // eslint-disable-line @typescript-eslint/unified-signatures - getLastToken(sourceFile?: SourceFile): Node | undefined; - /** @internal */ - getLastToken(sourceFile?: SourceFileLike): Node | undefined; // eslint-disable-line @typescript-eslint/unified-signatures - // See ts.forEachChild for documentation. - forEachChild(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined; - } -} - -declare module "../compiler/types.js" { - // Module transform: converted from interface augmentation - export interface Identifier { - readonly text: string; - } -} - -declare module "../compiler/types.js" { - // Module transform: converted from interface augmentation - export interface PrivateIdentifier { - readonly text: string; - } -} - declare module "../compiler/types.js" { // Module transform: converted from interface augmentation export interface Symbol { @@ -156,25 +113,6 @@ declare module "../compiler/types.js" { } } -declare module "../compiler/types.js" { - // Module transform: converted from interface augmentation - export interface SourceFile { - /** @internal */ version: string; - /** @internal */ scriptSnapshot: IScriptSnapshot | undefined; - /** @internal */ nameTable: Map<__String, number> | undefined; - - /** @internal */ getNamedDeclarations(): Map; - - getLineAndCharacterOfPosition(pos: number): LineAndCharacter; - getLineEndOfPosition(pos: number): number; - getLineStarts(): readonly number[]; - getPositionOfLineAndCharacter(line: number, character: number): number; - update(newText: string, textChangeRange: TextChangeRange): SourceFile; - - /** @internal */ sourceMapper?: DocumentPositionMapper; - } -} - declare module "../compiler/types.js" { // Module transform: converted from interface augmentation export interface SourceFileLike { @@ -189,32 +127,6 @@ declare module "../compiler/types.js" { } } -/** - * Represents an immutable snapshot of a script at a specified time.Once acquired, the - * snapshot is observably immutable. i.e. the same calls with the same parameters will return - * the same values. - */ -// eslint-disable-next-line @typescript-eslint/naming-convention -export interface IScriptSnapshot { - /** Gets a portion of the script snapshot specified by [start, end). */ - getText(start: number, end: number): string; - - /** Gets the length of this script snapshot. */ - getLength(): number; - - /** - * Gets the TextChangeRange that describe how the text changed between this text and - * an older version. This information is used by the incremental parser to determine - * what sections of the script need to be re-parsed. 'undefined' can be returned if the - * change range cannot be determined. However, in that case, incremental parsing will - * not happen and the entire document will be re - parsed. - */ - getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined; - - /** Releases all resources held by this script snapshot */ - dispose?(): void; -} - export namespace ScriptSnapshot { class StringScriptSnapshot implements IScriptSnapshot { constructor(private text: string) { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index fe06adeb8b217..dbbf3b2e4763c 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -13,6 +13,7 @@ import { BreakOrContinueStatement, CallExpression, canHaveModifiers, + canHaveName, CaseClause, cast, CatchClause, @@ -279,7 +280,6 @@ import { LanguageServiceHost, last, lastOrUndefined, - LiteralExpression, map, maybeBind, Modifier, @@ -347,6 +347,7 @@ import { startsWith, StringLiteral, StringLiteralLike, + StringLiteralLikeNode, stringToToken, stripQuotes, Symbol, @@ -715,7 +716,7 @@ export function isNameOfModuleDeclaration(node: Node): boolean { /** @internal */ export function isNameOfFunctionDeclaration(node: Node): boolean { - return isIdentifier(node) && tryCast(node.parent, isFunctionLike)?.name === node; + return isIdentifier(node) && tryCast(tryCast(node.parent, isFunctionLike), canHaveName)?.name === node; } /** @internal */ @@ -1863,7 +1864,7 @@ export function isInString(sourceFile: SourceFile, position: number, previousTok } if (position === end) { - return !!(previousToken as LiteralExpression).isUnterminated; + return !!(previousToken as StringLiteralLikeNode).isUnterminated; } } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index c6e0eda83f956..524d5225e4de2 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -14,7 +14,7 @@ and limitations under the License. ***************************************************************************** */ declare namespace ts { - namespace server { + export namespace server { namespace protocol { export import ApplicableRefactorInfo = ts.ApplicableRefactorInfo; export import ClassificationType = ts.ClassificationType; @@ -3585,7 +3585,7 @@ declare namespace ts { responseRequired?: boolean; } } - namespace JsTyping { + export namespace JsTyping { interface TypingResolutionHost { directoryExists(path: string): boolean; fileExists(fileName: string): boolean; @@ -3593,35 +3593,44 @@ declare namespace ts { readDirectory(rootDir: string, extensions: readonly string[], excludes: readonly string[] | undefined, includes: readonly string[] | undefined, depth?: number): string[]; } } - const versionMajorMinor = "5.7"; + const ReadonlyArray: new(...items: readonly T[]) => readonly T[]; + class AstNodeExtraFields { + } + /** + * Holds the id for a `Node`. The id is held by another object to support + * source file redirection. + */ + class AstNodeId { + } + export const versionMajorMinor = "5.7"; /** The version of the TypeScript compiler release */ - const version: string; + export const version: string; /** * Type of objects whose values are all of the same type. * The `in` and `for-in` operators can *not* be safely used, * since `Object.prototype` may be modified by outside code. */ - interface MapLike { + export interface MapLike { [index: string]: T; } - interface SortedReadonlyArray extends ReadonlyArray { + export interface SortedReadonlyArray extends ReadonlyArray { " __sortedArrayBrand": any; } - interface SortedArray extends Array { + export interface SortedArray extends Array { " __sortedArrayBrand": any; } - type Path = string & { + export type Path = string & { __pathBrand: any; }; - interface TextRange { + export interface TextRange { pos: number; end: number; } - interface ReadonlyTextRange { + export interface ReadonlyTextRange { readonly pos: number; readonly end: number; } - enum SyntaxKind { + export enum SyntaxKind { Unknown = 0, EndOfFileToken = 1, SingleLineCommentTrivia = 2, @@ -4018,10 +4027,10 @@ declare namespace ts { FirstJSDocTagNode = 327, LastJSDocTagNode = 351, } - type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; - type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; - type PseudoLiteralSyntaxKind = SyntaxKind.TemplateHead | SyntaxKind.TemplateMiddle | SyntaxKind.TemplateTail; - type PunctuationSyntaxKind = + export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; + export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; + export type PseudoLiteralSyntaxKind = SyntaxKind.TemplateHead | SyntaxKind.TemplateMiddle | SyntaxKind.TemplateTail; + export type PunctuationSyntaxKind = | SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.OpenParenToken @@ -4083,7 +4092,7 @@ declare namespace ts { | SyntaxKind.AmpersandEqualsToken | SyntaxKind.BarEqualsToken | SyntaxKind.CaretEqualsToken; - type KeywordSyntaxKind = + export type KeywordSyntaxKind = | SyntaxKind.AbstractKeyword | SyntaxKind.AccessorKeyword | SyntaxKind.AnyKeyword @@ -4167,12 +4176,50 @@ declare namespace ts { | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; - type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AccessorKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.InKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OutKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.StaticKeyword; - type KeywordTypeSyntaxKind = SyntaxKind.AnyKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VoidKeyword; - type TokenSyntaxKind = SyntaxKind.Unknown | SyntaxKind.EndOfFileToken | TriviaSyntaxKind | LiteralSyntaxKind | PseudoLiteralSyntaxKind | PunctuationSyntaxKind | SyntaxKind.Identifier | SyntaxKind.PrivateIdentifier | KeywordSyntaxKind; - type JsxTokenSyntaxKind = SyntaxKind.LessThanSlashToken | SyntaxKind.EndOfFileToken | SyntaxKind.ConflictMarkerTrivia | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.OpenBraceToken | SyntaxKind.LessThanToken; - type JSDocSyntaxKind = SyntaxKind.EndOfFileToken | SyntaxKind.WhitespaceTrivia | SyntaxKind.AtToken | SyntaxKind.NewLineTrivia | SyntaxKind.AsteriskToken | SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.LessThanToken | SyntaxKind.GreaterThanToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.OpenParenToken | SyntaxKind.CloseParenToken | SyntaxKind.EqualsToken | SyntaxKind.CommaToken | SyntaxKind.DotToken | SyntaxKind.Identifier | SyntaxKind.BacktickToken | SyntaxKind.HashToken | SyntaxKind.Unknown | KeywordSyntaxKind; - enum NodeFlags { + export type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AccessorKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.InKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OutKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.StaticKeyword; + export type KeywordTypeSyntaxKind = SyntaxKind.AnyKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VoidKeyword; + export type TypeNodeSyntaxKind = + | KeywordTypeSyntaxKind + | SyntaxKind.TypePredicate + | SyntaxKind.TypeReference + | SyntaxKind.FunctionType + | SyntaxKind.ConstructorType + | SyntaxKind.TypeQuery + | SyntaxKind.TypeLiteral + | SyntaxKind.ArrayType + | SyntaxKind.TupleType + | SyntaxKind.NamedTupleMember + | SyntaxKind.OptionalType + | SyntaxKind.RestType + | SyntaxKind.UnionType + | SyntaxKind.IntersectionType + | SyntaxKind.ConditionalType + | SyntaxKind.InferType + | SyntaxKind.ParenthesizedType + | SyntaxKind.ThisType + | SyntaxKind.TypeOperator + | SyntaxKind.IndexedAccessType + | SyntaxKind.MappedType + | SyntaxKind.LiteralType + | SyntaxKind.TemplateLiteralType + | SyntaxKind.TemplateLiteralTypeSpan + | SyntaxKind.ImportType + | SyntaxKind.ExpressionWithTypeArguments + | SyntaxKind.JSDocTypeExpression + | SyntaxKind.JSDocAllType + | SyntaxKind.JSDocUnknownType + | SyntaxKind.JSDocNonNullableType + | SyntaxKind.JSDocNullableType + | SyntaxKind.JSDocOptionalType + | SyntaxKind.JSDocFunctionType + | SyntaxKind.JSDocVariadicType + | SyntaxKind.JSDocNamepathType + | SyntaxKind.JSDocSignature + | SyntaxKind.JSDocTypeLiteral; + export type TokenSyntaxKind = SyntaxKind.Unknown | SyntaxKind.EndOfFileToken | TriviaSyntaxKind | LiteralSyntaxKind | PseudoLiteralSyntaxKind | PunctuationSyntaxKind | SyntaxKind.Identifier | SyntaxKind.PrivateIdentifier | KeywordSyntaxKind; + export type JsxTokenSyntaxKind = SyntaxKind.LessThanSlashToken | SyntaxKind.EndOfFileToken | SyntaxKind.ConflictMarkerTrivia | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.OpenBraceToken | SyntaxKind.LessThanToken; + export type JSDocSyntaxKind = SyntaxKind.EndOfFileToken | SyntaxKind.WhitespaceTrivia | SyntaxKind.AtToken | SyntaxKind.NewLineTrivia | SyntaxKind.AsteriskToken | SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.LessThanToken | SyntaxKind.GreaterThanToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.OpenParenToken | SyntaxKind.CloseParenToken | SyntaxKind.EqualsToken | SyntaxKind.CommaToken | SyntaxKind.DotToken | SyntaxKind.Identifier | SyntaxKind.BacktickToken | SyntaxKind.HashToken | SyntaxKind.Unknown | KeywordSyntaxKind; + export enum NodeFlags { None = 0, Let = 1, Const = 2, @@ -4206,7 +4253,7 @@ declare namespace ts { ContextFlags = 101441536, TypeExcludesFlags = 81920, } - enum ModifierFlags { + export enum ModifierFlags { None = 0, Public = 1, Private = 2, @@ -4235,7 +4282,7 @@ declare namespace ts { All = 131071, Modifier = 98303, } - enum JsxFlags { + export enum JsxFlags { None = 0, /** An element from a named property of the JSX.IntrinsicElements interface */ IntrinsicNamedElement = 1, @@ -4243,38 +4290,42 @@ declare namespace ts { IntrinsicIndexedElement = 2, IntrinsicElement = 3, } - interface Node extends ReadonlyTextRange { - readonly kind: SyntaxKind; - readonly flags: NodeFlags; - readonly parent: Node; - } - interface Node { + export type NodeConstructor = new(ast: AstNode>) => N; + export class Node implements ReadonlyTextRange { + readonly ast: AstNode>; + constructor(ast: AstNode>); + get kind(): K; + get data(): T; + get pos(): number; + get end(): number; + get flags(): NodeFlags; + get parent(): Node; getSourceFile(): SourceFile; - getChildCount(sourceFile?: SourceFile): number; - getChildAt(index: number, sourceFile?: SourceFile): Node; - getChildren(sourceFile?: SourceFile): readonly Node[]; - getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number; + getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number; getFullStart(): number; getEnd(): number; getWidth(sourceFile?: SourceFileLike): number; getFullWidth(): number; - getLeadingTriviaWidth(sourceFile?: SourceFile): number; - getFullText(sourceFile?: SourceFile): string; - getText(sourceFile?: SourceFile): string; - getFirstToken(sourceFile?: SourceFile): Node | undefined; - getLastToken(sourceFile?: SourceFile): Node | undefined; + getLeadingTriviaWidth(sourceFile?: SourceFileLike): number; + getFullText(sourceFile?: SourceFileLike): string; + getText(sourceFile?: SourceFileLike): string; + getChildCount(sourceFile?: SourceFileLike): number; + getChildAt(index: number, sourceFile?: SourceFileLike): Node; + getChildren(sourceFile?: SourceFileLike): readonly Node[]; + getFirstToken(sourceFile?: SourceFileLike): Node | undefined; + getLastToken(sourceFile?: SourceFileLike): Node | undefined; forEachChild(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined; } - interface JSDocContainer extends Node { + export interface JSDocContainer extends Node { _jsdocContainerBrand: any; } - interface LocalsContainer extends Node { + export interface LocalsContainer extends Node { _localsContainerBrand: any; } - interface FlowContainer extends Node { + export interface FlowContainer extends Node { _flowContainerBrand: any; } - type HasJSDoc = + export type HasJSDoc = | AccessorDeclaration | ArrowFunction | BinaryExpression @@ -4339,236 +4390,349 @@ declare namespace ts { | VariableStatement | WhileStatement | WithStatement; - type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType; - type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement; - type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute; - type HasExpressionInitializer = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | EnumMember; - type HasDecorators = ParameterDeclaration | PropertyDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ClassExpression | ClassDeclaration; - type HasModifiers = TypeParameterDeclaration | ParameterDeclaration | ConstructorTypeNode | PropertySignature | PropertyDeclaration | MethodSignature | MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | IndexSignatureDeclaration | FunctionExpression | ArrowFunction | ClassExpression | VariableStatement | FunctionDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | ExportAssignment | ExportDeclaration; - interface NodeArray extends ReadonlyArray, ReadonlyTextRange { - readonly hasTrailingComma: boolean; - } - interface Token extends Node { + export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType; + export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement; + export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute; + export type HasExpressionInitializer = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | EnumMember; + export type HasDecorators = ParameterDeclaration | PropertyDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ClassExpression | ClassDeclaration; + export type HasModifiers = TypeParameterDeclaration | ParameterDeclaration | ConstructorTypeNode | PropertySignature | PropertyDeclaration | MethodSignature | MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | IndexSignatureDeclaration | FunctionExpression | ArrowFunction | ClassExpression | VariableStatement | FunctionDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | ExportAssignment | ExportDeclaration; + export class NodeArray extends ReadonlyArray { + readonly ast: AstNodeArray; + constructor(ast: AstNodeArray); + static get [globalThis.Symbol.species](): ArrayConstructor; + get pos(): number; + get end(): number; + get hasTrailingComma(): boolean; + } + export class Token extends Node { + getChildCount(_sourceFile?: SourceFileLike): number; + getChildAt(index: number, _sourceFile?: SourceFileLike): Node; + getChildren(_sourceFile?: SourceFileLike): readonly Node[]; + getFirstToken(_sourceFile?: SourceFileLike): Node | undefined; + getLastToken(_sourceFile?: SourceFileLike): Node | undefined; + forEachChild(_cbNode: (node: Node) => T | undefined, _cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined; + } + export class EndOfFileToken extends Token implements JSDocContainer { + _jsdocContainerBrand: any; + readonly ast: AstEndOfFileToken; + } + export interface PunctuationToken extends Token { + } + export type DotToken = PunctuationToken; + export type DotDotDotToken = PunctuationToken; + export type QuestionToken = PunctuationToken; + export type ExclamationToken = PunctuationToken; + export type ColonToken = PunctuationToken; + export type EqualsToken = PunctuationToken; + export type AmpersandAmpersandEqualsToken = PunctuationToken; + export type BarBarEqualsToken = PunctuationToken; + export type QuestionQuestionEqualsToken = PunctuationToken; + export type AsteriskToken = PunctuationToken; + export type EqualsGreaterThanToken = PunctuationToken; + export type PlusToken = PunctuationToken; + export type MinusToken = PunctuationToken; + export type QuestionDotToken = PunctuationToken; + export interface KeywordToken extends Token { + } + export type AssertsKeyword = KeywordToken; + export type AssertKeyword = KeywordToken; + export type AwaitKeyword = KeywordToken; + export type CaseKeyword = KeywordToken; + export interface ModifierToken extends KeywordToken { + } + export type AbstractKeyword = ModifierToken; + export type AccessorKeyword = ModifierToken; + export type AsyncKeyword = ModifierToken; + export type ConstKeyword = ModifierToken; + export type DeclareKeyword = ModifierToken; + export type DefaultKeyword = ModifierToken; + export type ExportKeyword = ModifierToken; + export type InKeyword = ModifierToken; + export type PrivateKeyword = ModifierToken; + export type ProtectedKeyword = ModifierToken; + export type PublicKeyword = ModifierToken; + export type ReadonlyKeyword = ModifierToken; + export type OutKeyword = ModifierToken; + export type OverrideKeyword = ModifierToken; + export type StaticKeyword = ModifierToken; + export type Modifier = AbstractKeyword | AccessorKeyword | AsyncKeyword | ConstKeyword | DeclareKeyword | DefaultKeyword | ExportKeyword | InKeyword | PrivateKeyword | ProtectedKeyword | PublicKeyword | OutKeyword | OverrideKeyword | ReadonlyKeyword | StaticKeyword; + export type ModifierLike = Modifier | Decorator; + export type AccessibilityModifier = PublicKeyword | PrivateKeyword | ProtectedKeyword; + export type ParameterPropertyModifier = AccessibilityModifier | ReadonlyKeyword; + export type ClassMemberModifier = AccessibilityModifier | ReadonlyKeyword | StaticKeyword | AccessorKeyword; + export type ModifiersArray = NodeArray; + export interface KeywordExpression extends PrimaryExpression, KeywordToken { + readonly ast: AstKeywordExpression; readonly kind: TKind; } - interface EndOfFileToken extends Token, JSDocContainer { - readonly kind: SyntaxKind.EndOfFileToken; - } - interface PunctuationToken extends Token { - } - type DotToken = PunctuationToken; - type DotDotDotToken = PunctuationToken; - type QuestionToken = PunctuationToken; - type ExclamationToken = PunctuationToken; - type ColonToken = PunctuationToken; - type EqualsToken = PunctuationToken; - type AmpersandAmpersandEqualsToken = PunctuationToken; - type BarBarEqualsToken = PunctuationToken; - type QuestionQuestionEqualsToken = PunctuationToken; - type AsteriskToken = PunctuationToken; - type EqualsGreaterThanToken = PunctuationToken; - type PlusToken = PunctuationToken; - type MinusToken = PunctuationToken; - type QuestionDotToken = PunctuationToken; - interface KeywordToken extends Token { - } - type AssertsKeyword = KeywordToken; - type AssertKeyword = KeywordToken; - type AwaitKeyword = KeywordToken; - type CaseKeyword = KeywordToken; - interface ModifierToken extends KeywordToken { - } - type AbstractKeyword = ModifierToken; - type AccessorKeyword = ModifierToken; - type AsyncKeyword = ModifierToken; - type ConstKeyword = ModifierToken; - type DeclareKeyword = ModifierToken; - type DefaultKeyword = ModifierToken; - type ExportKeyword = ModifierToken; - type InKeyword = ModifierToken; - type PrivateKeyword = ModifierToken; - type ProtectedKeyword = ModifierToken; - type PublicKeyword = ModifierToken; - type ReadonlyKeyword = ModifierToken; - type OutKeyword = ModifierToken; - type OverrideKeyword = ModifierToken; - type StaticKeyword = ModifierToken; - type Modifier = AbstractKeyword | AccessorKeyword | AsyncKeyword | ConstKeyword | DeclareKeyword | DefaultKeyword | ExportKeyword | InKeyword | PrivateKeyword | ProtectedKeyword | PublicKeyword | OutKeyword | OverrideKeyword | ReadonlyKeyword | StaticKeyword; - type ModifierLike = Modifier | Decorator; - type AccessibilityModifier = PublicKeyword | PrivateKeyword | ProtectedKeyword; - type ParameterPropertyModifier = AccessibilityModifier | ReadonlyKeyword; - type ClassMemberModifier = AccessibilityModifier | ReadonlyKeyword | StaticKeyword | AccessorKeyword; - type ModifiersArray = NodeArray; - enum GeneratedIdentifierFlags { + export enum GeneratedIdentifierFlags { None = 0, ReservedInNestedScopes = 8, Optimistic = 16, FileLevel = 32, AllowNameSubstitution = 64, } - interface Identifier extends PrimaryExpression, Declaration, JSDocContainer, FlowContainer { - readonly kind: SyntaxKind.Identifier; + export class Identifier extends Token implements PrimaryExpression, Declaration, JSDocContainer, FlowContainer { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstIdentifier; /** - * Prefer to use `id.unescapedText`. (Note: This is available only in services, not internally to the TypeScript compiler.) + * Prefer to use {@link text}. * Text of identifier, but if the identifier begins with two underscores, this will begin with three. */ - readonly escapedText: __String; - } - interface Identifier { - readonly text: string; - } - interface TransientIdentifier extends Identifier { - resolvedSymbol: Symbol; + get escapedText(): __String; + get text(): string; } - interface QualifiedName extends Node, FlowContainer { - readonly kind: SyntaxKind.QualifiedName; - readonly left: EntityName; - readonly right: Identifier; - } - type EntityName = Identifier | QualifiedName; - type PropertyName = Identifier | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | ComputedPropertyName | PrivateIdentifier | BigIntLiteral; - type MemberName = Identifier | PrivateIdentifier; - type DeclarationName = PropertyName | JsxAttributeName | StringLiteralLike | ElementAccessExpression | BindingPattern | EntityNameExpression; - interface Declaration extends Node { + export class QualifiedName extends Node implements FlowContainer { + _flowContainerBrand: any; + readonly ast: AstQualifiedName; + get left(): EntityName; + get right(): Identifier; + } + export type EntityName = Identifier | QualifiedName; + export type PropertyName = Identifier | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | ComputedPropertyName | PrivateIdentifier | BigIntLiteral; + export type MemberName = Identifier | PrivateIdentifier; + export type DeclarationName = PropertyName | JsxAttributeName | StringLiteralLike | ElementAccessExpression | BindingPattern | EntityNameExpression; + export interface Declaration extends Node { _declarationBrand: any; + readonly ast: AstDeclaration; } - interface NamedDeclaration extends Declaration { + export interface NamedDeclaration extends Declaration { readonly name?: DeclarationName | undefined; } - interface DeclarationStatement extends NamedDeclaration, Statement { + export interface DeclarationStatement extends NamedDeclaration, Statement { + readonly ast: AstNode; readonly name?: Identifier | StringLiteral | NumericLiteral | undefined; } - interface ComputedPropertyName extends Node { - readonly kind: SyntaxKind.ComputedPropertyName; - readonly parent: Declaration; - readonly expression: Expression; + export class ComputedPropertyName extends Node { + readonly ast: AstComputedPropertyName; + get parent(): Declaration; + get expression(): Expression; } - interface PrivateIdentifier extends PrimaryExpression { - readonly kind: SyntaxKind.PrivateIdentifier; - readonly escapedText: __String; - } - interface PrivateIdentifier { - readonly text: string; + export class PrivateIdentifier extends Token { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstPrivateIdentifier; + get escapedText(): __String; + get text(): string; } - interface Decorator extends Node { - readonly kind: SyntaxKind.Decorator; - readonly parent: NamedDeclaration; - readonly expression: LeftHandSideExpression; + export class Decorator extends Node { + readonly ast: AstDecorator; + get parent(): Declaration; + get expression(): LeftHandSideExpression; } - interface TypeParameterDeclaration extends NamedDeclaration, JSDocContainer { - readonly kind: SyntaxKind.TypeParameter; - readonly parent: DeclarationWithTypeParameterChildren | InferTypeNode; - readonly modifiers?: NodeArray | undefined; - readonly name: Identifier; - /** Note: Consider calling `getEffectiveConstraintOfTypeParameter` */ - readonly constraint?: TypeNode | undefined; - readonly default?: TypeNode | undefined; - expression?: Expression | undefined; + export class TypeParameterDeclaration extends Node implements Declaration, JSDocContainer { + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstTypeParameterDeclaration; + get parent(): DeclarationWithTypeParameterChildren | InferTypeNode; + get modifiers(): NodeArray | undefined; + get name(): Identifier; + /** + * NOTE: Consider calling `getEffectiveConstraintOfTypeParameter` + */ + get constraint(): TypeNode | undefined; + get default(): TypeNode | undefined; } - interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { + export interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { + readonly ast: AstNode; readonly kind: SignatureDeclaration["kind"]; readonly name?: PropertyName | undefined; readonly typeParameters?: NodeArray | undefined; readonly parameters: NodeArray; readonly type?: TypeNode | undefined; } - type SignatureDeclaration = CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | AccessorDeclaration | FunctionExpression | ArrowFunction; - interface CallSignatureDeclaration extends SignatureDeclarationBase, TypeElement, LocalsContainer { - readonly kind: SyntaxKind.CallSignature; + export type SignatureDeclaration = CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | AccessorDeclaration | FunctionExpression | ArrowFunction; + export class CallSignatureDeclaration extends Node implements SignatureDeclarationBase, TypeElement, LocalsContainer { + _signatureDeclarationBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _typeElementBrand: any; + _localsContainerBrand: any; + readonly ast: AstCallSignatureDeclaration; + get typeParameters(): NodeArray | undefined; + get parameters(): NodeArray; + get type(): TypeNode | undefined; } - interface ConstructSignatureDeclaration extends SignatureDeclarationBase, TypeElement, LocalsContainer { - readonly kind: SyntaxKind.ConstructSignature; + export class ConstructSignatureDeclaration extends Node implements SignatureDeclarationBase, TypeElement, LocalsContainer { + _signatureDeclarationBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _typeElementBrand: any; + _localsContainerBrand: any; + readonly ast: AstConstructSignatureDeclaration; + get typeParameters(): NodeArray | undefined; + get parameters(): NodeArray; + get type(): TypeNode | undefined; } - type BindingName = Identifier | BindingPattern; - interface VariableDeclaration extends NamedDeclaration, JSDocContainer { - readonly kind: SyntaxKind.VariableDeclaration; - readonly parent: VariableDeclarationList | CatchClause; - readonly name: BindingName; - readonly exclamationToken?: ExclamationToken | undefined; - readonly type?: TypeNode | undefined; - readonly initializer?: Expression | undefined; - } - interface VariableDeclarationList extends Node { - readonly kind: SyntaxKind.VariableDeclarationList; - readonly parent: VariableStatement | ForStatement | ForOfStatement | ForInStatement; - readonly declarations: NodeArray; - } - interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { - readonly kind: SyntaxKind.Parameter; - readonly parent: SignatureDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly dotDotDotToken?: DotDotDotToken | undefined; - readonly name: BindingName; - readonly questionToken?: QuestionToken | undefined; - readonly type?: TypeNode | undefined; - readonly initializer?: Expression | undefined; - } - interface BindingElement extends NamedDeclaration, FlowContainer { - readonly kind: SyntaxKind.BindingElement; - readonly parent: BindingPattern; - readonly propertyName?: PropertyName | undefined; - readonly dotDotDotToken?: DotDotDotToken | undefined; - readonly name: BindingName; - readonly initializer?: Expression | undefined; - } - interface PropertySignature extends TypeElement, JSDocContainer { - readonly kind: SyntaxKind.PropertySignature; - readonly parent: TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: PropertyName; - readonly questionToken?: QuestionToken | undefined; - readonly type?: TypeNode | undefined; + export type BindingName = Identifier | BindingPattern; + export class VariableDeclaration extends Node implements Declaration, JSDocContainer { + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstVariableDeclaration; + get parent(): VariableDeclarationList | CatchClause; + /** + * Declared variable name + */ + get name(): BindingName; + /** + * Optional definite assignment assertion + */ + get exclamationToken(): ExclamationToken | undefined; + /** + * Optional type annotation + */ + get type(): TypeNode | undefined; + /** + * Optional initializer + */ + get initializer(): Expression | undefined; } - interface PropertyDeclaration extends ClassElement, JSDocContainer { - readonly kind: SyntaxKind.PropertyDeclaration; - readonly parent: ClassLikeDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: PropertyName; - readonly questionToken?: QuestionToken | undefined; - readonly exclamationToken?: ExclamationToken | undefined; - readonly type?: TypeNode | undefined; - readonly initializer?: Expression | undefined; + export class VariableDeclarationList extends Node { + readonly ast: AstVariableDeclarationList; + get parent(): VariableStatement | ForStatement | ForOfStatement | ForInStatement; + get declarations(): NodeArray; + } + export class ParameterDeclaration extends Node implements Declaration, JSDocContainer { + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstParameterDeclaration; + get parent(): SignatureDeclaration; + get modifiers(): NodeArray | undefined; + get dotDotDotToken(): DotDotDotToken | undefined; + get name(): BindingName; + get questionToken(): QuestionToken | undefined; + get type(): TypeNode | undefined; + get initializer(): Expression | undefined; + } + export class BindingElement extends Node implements Declaration, FlowContainer { + _declarationBrand: any; + _flowContainerBrand: any; + readonly ast: AstBindingElement; + get parent(): BindingPattern; + /** + * Binding property name (in object binding pattern) + */ + get propertyName(): PropertyName | undefined; + /** + * Present on rest element (in object binding pattern) + */ + get dotDotDotToken(): DotDotDotToken | undefined; + /** + * Declared binding element name + */ + get name(): BindingName; + /** + * Optional initializer + */ + get initializer(): Expression | undefined; + } + export class PropertySignature extends Node implements TypeElement, JSDocContainer { + _typeElementBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstPropertySignature; + get parent(): TypeLiteralNode | InterfaceDeclaration; + get modifiers(): NodeArray | undefined; + /** + * Declared property name + */ + get name(): PropertyName; + /** + * Present on optional property + */ + get questionToken(): QuestionToken | undefined; + /** + * Optional type annotation + */ + get type(): TypeNode | undefined; + } + export class PropertyDeclaration extends Node implements ClassElement, JSDocContainer { + _classElementBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstPropertyDeclaration; + get parent(): ClassLikeDeclaration; + get modifiers(): NodeArray | undefined; + get name(): PropertyName; + /** + * Optional field. Disallowed for auto-accessors and only used to report a grammar error (see `isGrammarError` in utilities.ts) + */ + get questionToken(): QuestionToken | undefined; + get exclamationToken(): ExclamationToken | undefined; + get type(): TypeNode | undefined; + /** + * Optional initializer + */ + get initializer(): Expression | undefined; } - interface AutoAccessorPropertyDeclaration extends PropertyDeclaration { + export interface AutoAccessorPropertyDeclaration extends PropertyDeclaration { _autoAccessorBrand: any; } - interface ObjectLiteralElement extends NamedDeclaration { + export interface ObjectLiteralElement extends NamedDeclaration { _objectLiteralBrand: any; + readonly ast: AstObjectLiteralElement; readonly name?: PropertyName | undefined; } /** Unlike ObjectLiteralElement, excludes JSXAttribute and JSXSpreadAttribute. */ - type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment | MethodDeclaration | AccessorDeclaration; - interface PropertyAssignment extends ObjectLiteralElement, JSDocContainer { - readonly kind: SyntaxKind.PropertyAssignment; - readonly parent: ObjectLiteralExpression; - readonly name: PropertyName; - readonly initializer: Expression; - } - interface ShorthandPropertyAssignment extends ObjectLiteralElement, JSDocContainer { - readonly kind: SyntaxKind.ShorthandPropertyAssignment; - readonly parent: ObjectLiteralExpression; - readonly name: Identifier; - readonly equalsToken?: EqualsToken | undefined; - readonly objectAssignmentInitializer?: Expression | undefined; - } - interface SpreadAssignment extends ObjectLiteralElement, JSDocContainer { - readonly kind: SyntaxKind.SpreadAssignment; - readonly parent: ObjectLiteralExpression; - readonly expression: Expression; - } - type VariableLikeDeclaration = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | PropertySignature | JsxAttribute | ShorthandPropertyAssignment | EnumMember | JSDocPropertyTag | JSDocParameterTag; - interface ObjectBindingPattern extends Node { - readonly kind: SyntaxKind.ObjectBindingPattern; - readonly parent: VariableDeclaration | ParameterDeclaration | BindingElement; - readonly elements: NodeArray; - } - interface ArrayBindingPattern extends Node { - readonly kind: SyntaxKind.ArrayBindingPattern; - readonly parent: VariableDeclaration | ParameterDeclaration | BindingElement; - readonly elements: NodeArray; - } - type BindingPattern = ObjectBindingPattern | ArrayBindingPattern; - type ArrayBindingElement = BindingElement | OmittedExpression; + export type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment | MethodDeclaration | AccessorDeclaration; + export class PropertyAssignment extends Node implements ObjectLiteralElement, Declaration, JSDocContainer { + _objectLiteralBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstPropertyAssignment; + get parent(): ObjectLiteralExpression; + get modifiers(): NodeArray | undefined; + get name(): PropertyName; + get questionToken(): QuestionToken | undefined; + get exclamationToken(): ExclamationToken | undefined; + get initializer(): Expression; + } + export class ShorthandPropertyAssignment extends Node implements ObjectLiteralElement, Declaration, JSDocContainer { + _objectLiteralBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstShorthandPropertyAssignment; + get parent(): ObjectLiteralExpression; + get modifiers(): NodeArray | undefined; + get name(): Identifier; + get questionToken(): QuestionToken | undefined; + get exclamationToken(): ExclamationToken | undefined; + get equalsToken(): EqualsToken | undefined; + get objectAssignmentInitializer(): Expression | undefined; + } + export class SpreadAssignment extends Node implements ObjectLiteralElement, JSDocContainer { + _objectLiteralBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstSpreadAssignment; + get parent(): ObjectLiteralExpression; + get expression(): Expression; + } + export type VariableLikeDeclaration = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | PropertySignature | JsxAttribute | ShorthandPropertyAssignment | EnumMember | JSDocPropertyTag | JSDocParameterTag; + export class ObjectBindingPattern extends Node { + readonly ast: AstObjectBindingPattern; + get parent(): VariableDeclaration | ParameterDeclaration | BindingElement; + get elements(): NodeArray; + } + export class ArrayBindingPattern extends Node { + readonly ast: AstArrayBindingPattern; + get parent(): VariableDeclaration | ParameterDeclaration | BindingElement; + get elements(): NodeArray; + } + export type BindingPattern = ObjectBindingPattern | ArrayBindingPattern; + export type ArrayBindingElement = BindingElement | OmittedExpression; /** * Several node kinds share function-like features such as a signature, * a name, and a body. These nodes should extend FunctionLikeDeclarationBase. @@ -4577,392 +4741,658 @@ declare namespace ts { * - MethodDeclaration * - AccessorDeclaration */ - interface FunctionLikeDeclarationBase extends SignatureDeclarationBase { + export interface FunctionLikeDeclarationBase extends SignatureDeclarationBase { _functionLikeDeclarationBrand: any; readonly asteriskToken?: AsteriskToken | undefined; readonly questionToken?: QuestionToken | undefined; readonly exclamationToken?: ExclamationToken | undefined; readonly body?: Block | Expression | undefined; } - type FunctionLikeDeclaration = FunctionDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ConstructorDeclaration | FunctionExpression | ArrowFunction; + export type FunctionLikeDeclaration = FunctionDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ConstructorDeclaration | FunctionExpression | ArrowFunction; /** @deprecated Use SignatureDeclaration */ - type FunctionLike = SignatureDeclaration; - interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement, LocalsContainer { - readonly kind: SyntaxKind.FunctionDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name?: Identifier | undefined; - readonly body?: FunctionBody | undefined; - } - interface MethodSignature extends SignatureDeclarationBase, TypeElement, LocalsContainer { - readonly kind: SyntaxKind.MethodSignature; - readonly parent: TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: PropertyName; - } - interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.MethodDeclaration; - readonly parent: ClassLikeDeclaration | ObjectLiteralExpression; - readonly modifiers?: NodeArray | undefined; - readonly name: PropertyName; - readonly body?: FunctionBody | undefined; - } - interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElement, JSDocContainer, LocalsContainer { - readonly kind: SyntaxKind.Constructor; - readonly parent: ClassLikeDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly body?: FunctionBody | undefined; + export type FunctionLike = SignatureDeclaration; + export class FunctionDeclaration extends Node implements FunctionLikeDeclarationBase, DeclarationStatement, LocalsContainer { + _functionLikeDeclarationBrand: any; + _signatureDeclarationBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _statementBrand: any; + _localsContainerBrand: any; + readonly ast: AstFunctionDeclaration; + get modifiers(): NodeArray | undefined; + get asteriskToken(): AsteriskToken | undefined; + get name(): Identifier | undefined; + get typeParameters(): NodeArray | undefined; + get parameters(): NodeArray; + get type(): TypeNode | undefined; + get body(): Block | undefined; + } + export class MethodSignature extends Node implements SignatureDeclarationBase, TypeElement, LocalsContainer { + _signatureDeclarationBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _typeElementBrand: any; + _localsContainerBrand: any; + readonly ast: AstMethodSignature; + get parent(): TypeLiteralNode | InterfaceDeclaration; + get modifiers(): NodeArray | undefined; + get name(): PropertyName; + get questionToken(): QuestionToken | undefined; + get typeParameters(): NodeArray | undefined; + get parameters(): NodeArray; + get type(): TypeNode | undefined; + } + export class MethodDeclaration extends Node implements FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, LocalsContainer, FlowContainer { + _functionLikeDeclarationBrand: any; + _signatureDeclarationBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _classElementBrand: any; + _objectLiteralBrand: any; + _localsContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstMethodDeclaration; + get parent(): ClassLikeDeclaration | ObjectLiteralExpression; + get modifiers(): NodeArray | undefined; + get asteriskToken(): AsteriskToken | undefined; + get name(): PropertyName; + get questionToken(): QuestionToken | undefined; + get typeParameters(): NodeArray | undefined; + get parameters(): NodeArray; + get type(): TypeNode | undefined; + get body(): Block | undefined; + } + export class ConstructorDeclaration extends Node implements FunctionLikeDeclarationBase, ClassElement, JSDocContainer, LocalsContainer { + _functionLikeDeclarationBrand: any; + _signatureDeclarationBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _classElementBrand: any; + _localsContainerBrand: any; + readonly ast: AstConstructorDeclaration; + get parent(): ClassLikeDeclaration; + get modifiers(): NodeArray | undefined; + get body(): Block | undefined; + get parameters(): NodeArray; } /** For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. */ - interface SemicolonClassElement extends ClassElement, JSDocContainer { - readonly kind: SyntaxKind.SemicolonClassElement; - readonly parent: ClassLikeDeclaration; - } - interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.GetAccessor; - readonly parent: ClassLikeDeclaration | ObjectLiteralExpression | TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: PropertyName; - readonly body?: FunctionBody | undefined; - } - interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.SetAccessor; - readonly parent: ClassLikeDeclaration | ObjectLiteralExpression | TypeLiteralNode | InterfaceDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: PropertyName; - readonly body?: FunctionBody | undefined; - } - type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; - interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement, LocalsContainer { - readonly kind: SyntaxKind.IndexSignature; - readonly parent: ObjectTypeDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly type: TypeNode; + export class SemicolonClassElement extends Node implements ClassElement, JSDocContainer { + _classElementBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + symbol: never; + localSymbol: never; + readonly ast: AstSemicolonClassElement; + get parent(): ClassLikeDeclaration; } - interface ClassStaticBlockDeclaration extends ClassElement, JSDocContainer, LocalsContainer { - readonly kind: SyntaxKind.ClassStaticBlockDeclaration; - readonly parent: ClassDeclaration | ClassExpression; - readonly body: Block; + export class GetAccessorDeclaration extends Node implements FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { + _functionLikeDeclarationBrand: any; + _signatureDeclarationBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _classElementBrand: any; + _typeElementBrand: any; + _objectLiteralBrand: any; + _localsContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstGetAccessorDeclaration; + get parent(): ClassLikeDeclaration | ObjectLiteralExpression | InterfaceDeclaration | TypeLiteralNode; + get modifiers(): NodeArray | undefined; + get name(): PropertyName; + get body(): Block | undefined; + get parameters(): NodeArray; + get type(): TypeNode | undefined; + } + export class SetAccessorDeclaration extends Node implements FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { + _functionLikeDeclarationBrand: any; + _signatureDeclarationBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _classElementBrand: any; + _typeElementBrand: any; + _objectLiteralBrand: any; + _localsContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstSetAccessorDeclaration; + get parent(): ClassLikeDeclaration | ObjectLiteralExpression | InterfaceDeclaration | TypeLiteralNode; + get modifiers(): NodeArray | undefined; + get name(): PropertyName; + get body(): Block | undefined; + get parameters(): NodeArray; + } + export type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; + export class IndexSignatureDeclaration extends Node implements SignatureDeclarationBase, ClassElement, TypeElement, LocalsContainer { + _declarationBrand: any; + _jsdocContainerBrand: any; + _classElementBrand: any; + _typeElementBrand: any; + _localsContainerBrand: any; + readonly ast: AstIndexSignatureDeclaration; + get parent(): ObjectTypeDeclaration; + get modifiers(): NodeArray | undefined; + get parameters(): NodeArray; + get type(): TypeNode; + } + export class ClassStaticBlockDeclaration extends Node implements ClassElement, JSDocContainer, LocalsContainer { + _signatureDeclarationBrand: any; + _classElementBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + readonly ast: AstClassStaticBlockDeclaration; + get parent(): ClassLikeDeclaration; + get body(): Block; } - interface TypeNode extends Node { + export interface TypeNode extends Node { _typeNodeBrand: any; + readonly ast: AstTypeNode; } - interface KeywordTypeNode extends KeywordToken, TypeNode { + export interface KeywordTypeNode extends KeywordToken, TypeNode { + readonly ast: AstKeywordTypeNode; readonly kind: TKind; } /** @deprecated */ - interface ImportTypeAssertionContainer extends Node { - readonly kind: SyntaxKind.ImportTypeAssertionContainer; - readonly parent: ImportTypeNode; - /** @deprecated */ readonly assertClause: AssertClause; - readonly multiLine?: boolean | undefined; - } - interface ImportTypeNode extends NodeWithTypeArguments { - readonly kind: SyntaxKind.ImportType; - readonly isTypeOf: boolean; - readonly argument: TypeNode; - /** @deprecated */ readonly assertions?: ImportTypeAssertionContainer | undefined; - readonly attributes?: ImportAttributes | undefined; - readonly qualifier?: EntityName | undefined; - } - interface ThisTypeNode extends TypeNode { - readonly kind: SyntaxKind.ThisType; - } - type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; - interface FunctionOrConstructorTypeNodeBase extends TypeNode, SignatureDeclarationBase { + export class ImportTypeAssertionContainer extends Node { + readonly ast: AstImportTypeAssertionContainer; + get parent(): ImportTypeNode; + /** @deprecated */ + get assertClause(): ImportAttributes; + } + export class ImportTypeNode extends Node implements TypeNode, NodeWithTypeArguments { + _typeNodeBrand: any; + readonly ast: AstImportTypeNode; + get isTypeOf(): boolean; + get argument(): TypeNode; + get attributes(): ImportAttributes | undefined; + /** @deprecated */ + get assertions(): ImportTypeAssertionContainer | undefined; + get qualifier(): EntityName | undefined; + get typeArguments(): NodeArray | undefined; + } + export class ThisTypeNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstThisTypeNode; + } + export type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; + export interface FunctionOrConstructorTypeNodeBase extends TypeNode, SignatureDeclarationBase { + readonly ast: AstNode; readonly kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType; readonly type: TypeNode; } - interface FunctionTypeNode extends FunctionOrConstructorTypeNodeBase, LocalsContainer { - readonly kind: SyntaxKind.FunctionType; - } - interface ConstructorTypeNode extends FunctionOrConstructorTypeNodeBase, LocalsContainer { - readonly kind: SyntaxKind.ConstructorType; - readonly modifiers?: NodeArray | undefined; + export class FunctionTypeNode extends Node implements FunctionOrConstructorTypeNodeBase, LocalsContainer { + _signatureDeclarationBrand: any; + _typeNodeBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + readonly ast: AstFunctionTypeNode; + get typeParameters(): NodeArray | undefined; + get parameters(): NodeArray; + get type(): TypeNode; + } + export class ConstructorTypeNode extends Node implements FunctionOrConstructorTypeNodeBase, LocalsContainer { + readonly ast: AstConstructorTypeNode; + _signatureDeclarationBrand: any; + _typeNodeBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + get modifiers(): NodeArray | undefined; + get typeParameters(): NodeArray | undefined; + get parameters(): NodeArray; + get type(): TypeNode; } - interface NodeWithTypeArguments extends TypeNode { + export interface NodeWithTypeArguments extends TypeNode { readonly typeArguments?: NodeArray | undefined; } - type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; - interface TypeReferenceNode extends NodeWithTypeArguments { - readonly kind: SyntaxKind.TypeReference; - readonly typeName: EntityName; + export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; + export class TypeReferenceNode extends Node implements NodeWithTypeArguments { + _typeNodeBrand: any; + readonly ast: AstTypeReferenceNode; + get typeName(): Identifier | QualifiedName; + get typeArguments(): NodeArray | undefined; } - interface TypePredicateNode extends TypeNode { - readonly kind: SyntaxKind.TypePredicate; - readonly parent: SignatureDeclaration | JSDocTypeExpression; - readonly assertsModifier?: AssertsKeyword | undefined; - readonly parameterName: Identifier | ThisTypeNode; - readonly type?: TypeNode | undefined; + export class TypePredicateNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstTypePredicateNode; + get parent(): SignatureDeclaration | JSDocTypeExpression; + get assertsModifier(): AssertsKeyword | undefined; + get parameterName(): Identifier | ThisTypeNode; + get type(): TypeNode | undefined; } - interface TypeQueryNode extends NodeWithTypeArguments { - readonly kind: SyntaxKind.TypeQuery; - readonly exprName: EntityName; + export class TypeQueryNode extends Node implements NodeWithTypeArguments { + _typeNodeBrand: any; + readonly ast: AstTypeQueryNode; + get exprName(): Identifier | QualifiedName; + get typeArguments(): NodeArray | undefined; } - interface TypeLiteralNode extends TypeNode, Declaration { - readonly kind: SyntaxKind.TypeLiteral; - readonly members: NodeArray; + export class TypeLiteralNode extends Node implements TypeNode, Declaration { + _typeNodeBrand: any; + _declarationBrand: any; + readonly ast: AstTypeLiteralNode; + get members(): NodeArray; } - interface ArrayTypeNode extends TypeNode { - readonly kind: SyntaxKind.ArrayType; - readonly elementType: TypeNode; + export class ArrayTypeNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstArrayTypeNode; + get elementType(): TypeNode; } - interface TupleTypeNode extends TypeNode { - readonly kind: SyntaxKind.TupleType; - readonly elements: NodeArray; + export class TupleTypeNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstTupleTypeNode; + get elements(): NodeArray; } - interface NamedTupleMember extends TypeNode, Declaration, JSDocContainer { - readonly kind: SyntaxKind.NamedTupleMember; - readonly dotDotDotToken?: DotDotDotToken | undefined; - readonly name: Identifier; - readonly questionToken?: QuestionToken | undefined; - readonly type: TypeNode; + export class NamedTupleMember extends Node implements TypeNode, Declaration, JSDocContainer { + _typeNodeBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstNamedTupleMember; + get dotDotDotToken(): DotDotDotToken | undefined; + get name(): Identifier; + get questionToken(): QuestionToken | undefined; + get type(): TypeNode; } - interface OptionalTypeNode extends TypeNode { - readonly kind: SyntaxKind.OptionalType; - readonly type: TypeNode; + export class OptionalTypeNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstOptionalTypeNode; + get type(): TypeNode; } - interface RestTypeNode extends TypeNode { - readonly kind: SyntaxKind.RestType; - readonly type: TypeNode; + export class RestTypeNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstRestTypeNode; + get type(): TypeNode; } - type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; - interface UnionTypeNode extends TypeNode { - readonly kind: SyntaxKind.UnionType; - readonly types: NodeArray; + export type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; + export class UnionTypeNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstUnionTypeNode; + get types(): NodeArray; } - interface IntersectionTypeNode extends TypeNode { - readonly kind: SyntaxKind.IntersectionType; - readonly types: NodeArray; + export class IntersectionTypeNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstIntersectionTypeNode; + get types(): NodeArray; } - interface ConditionalTypeNode extends TypeNode, LocalsContainer { - readonly kind: SyntaxKind.ConditionalType; - readonly checkType: TypeNode; - readonly extendsType: TypeNode; - readonly trueType: TypeNode; - readonly falseType: TypeNode; + export class ConditionalTypeNode extends Node implements TypeNode, LocalsContainer { + _typeNodeBrand: any; + _localsContainerBrand: any; + readonly ast: AstConditionalTypeNode; + get checkType(): TypeNode; + get extendsType(): TypeNode; + get trueType(): TypeNode; + get falseType(): TypeNode; } - interface InferTypeNode extends TypeNode { - readonly kind: SyntaxKind.InferType; - readonly typeParameter: TypeParameterDeclaration; + export class InferTypeNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstInferTypeNode; + get typeParameter(): TypeParameterDeclaration; } - interface ParenthesizedTypeNode extends TypeNode { - readonly kind: SyntaxKind.ParenthesizedType; - readonly type: TypeNode; + export class ParenthesizedTypeNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstParenthesizedTypeNode; + get type(): TypeNode; } - interface TypeOperatorNode extends TypeNode { - readonly kind: SyntaxKind.TypeOperator; - readonly operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; - readonly type: TypeNode; + export class TypeOperatorNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstTypeOperatorNode; + get operator(): SyntaxKind.KeyOfKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.UniqueKeyword; + get type(): TypeNode; } - interface IndexedAccessTypeNode extends TypeNode { - readonly kind: SyntaxKind.IndexedAccessType; - readonly objectType: TypeNode; - readonly indexType: TypeNode; - } - interface MappedTypeNode extends TypeNode, Declaration, LocalsContainer { - readonly kind: SyntaxKind.MappedType; - readonly readonlyToken?: ReadonlyKeyword | PlusToken | MinusToken | undefined; - readonly typeParameter: TypeParameterDeclaration; - readonly nameType?: TypeNode | undefined; - readonly questionToken?: QuestionToken | PlusToken | MinusToken | undefined; - readonly type?: TypeNode | undefined; - /** Used only to produce grammar errors */ - readonly members?: NodeArray | undefined; - } - interface LiteralTypeNode extends TypeNode { - readonly kind: SyntaxKind.LiteralType; - readonly literal: NullLiteral | BooleanLiteral | LiteralExpression | PrefixUnaryExpression; - } - interface StringLiteral extends LiteralExpression, Declaration { - readonly kind: SyntaxKind.StringLiteral; - } - type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral; - type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral | JsxNamespacedName | BigIntLiteral; - interface TemplateLiteralTypeNode extends TypeNode { - readonly kind: SyntaxKind.TemplateLiteralType; - readonly head: TemplateHead; - readonly templateSpans: NodeArray; - } - interface TemplateLiteralTypeSpan extends TypeNode { - readonly kind: SyntaxKind.TemplateLiteralTypeSpan; - readonly parent: TemplateLiteralTypeNode; - readonly type: TypeNode; - readonly literal: TemplateMiddle | TemplateTail; + export class IndexedAccessTypeNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstIndexedAccessTypeNode; + get objectType(): TypeNode; + get indexType(): TypeNode; + } + export class MappedTypeNode extends Node implements TypeNode, Declaration, LocalsContainer { + _typeNodeBrand: any; + _declarationBrand: any; + _localsContainerBrand: any; + readonly ast: AstMappedTypeNode; + get readonlyToken(): PlusToken | MinusToken | ReadonlyKeyword | undefined; + get typeParameter(): TypeParameterDeclaration; + get nameType(): TypeNode | undefined; + get questionToken(): QuestionToken | PlusToken | MinusToken | undefined; + get type(): TypeNode | undefined; + get members(): NodeArray | undefined; + } + export class LiteralTypeNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstLiteralTypeNode; + get literal(): NullLiteral | TrueLiteral | FalseLiteral | PrefixUnaryExpression | LiteralExpression; + } + export class StringLiteral extends Token implements LiteralExpression, StringLiteralLikeNode, Declaration { + _literalExpressionBrand: any; + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _declarationBrand: any; + readonly ast: AstStringLiteral; + get text(): string; + get isUnterminated(): boolean; + get hasExtendedUnicodeEscape(): boolean; + } + export type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral; + export type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral | JsxNamespacedName | BigIntLiteral; + export class TemplateLiteralTypeNode extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstTemplateLiteralTypeNode; + get head(): TemplateHead; + get templateSpans(): NodeArray; + } + export class TemplateLiteralTypeSpan extends Node { + _typeNodeBrand: any; + readonly ast: AstTemplateLiteralTypeSpan; + get parent(): TemplateLiteralTypeNode; + get type(): TypeNode; + get literal(): TemplateMiddle | TemplateTail; } - interface Expression extends Node { + export interface Expression extends Node { _expressionBrand: any; + readonly ast: AstExpression; } - interface OmittedExpression extends Expression { - readonly kind: SyntaxKind.OmittedExpression; + export class OmittedExpression extends Node implements Expression { + _expressionBrand: any; + readonly ast: AstOmittedExpression; } - interface PartiallyEmittedExpression extends LeftHandSideExpression { - readonly kind: SyntaxKind.PartiallyEmittedExpression; - readonly expression: Expression; + export class PartiallyEmittedExpression extends Node implements LeftHandSideExpression { + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstPartiallyEmittedExpression; + get expression(): Expression; } - interface UnaryExpression extends Expression { + export interface UnaryExpression extends Expression { _unaryExpressionBrand: any; + readonly ast: AstUnaryExpression; } - /** Deprecated, please use UpdateExpression */ - type IncrementExpression = UpdateExpression; - interface UpdateExpression extends UnaryExpression { + /** @deprecated use UpdateExpression instead */ + export type IncrementExpression = UpdateExpression; + export interface UpdateExpression extends UnaryExpression { _updateExpressionBrand: any; + readonly ast: AstUpdateExpression; } - type PrefixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.TildeToken | SyntaxKind.ExclamationToken; - interface PrefixUnaryExpression extends UpdateExpression { - readonly kind: SyntaxKind.PrefixUnaryExpression; - readonly operator: PrefixUnaryOperator; - readonly operand: UnaryExpression; + export type PrefixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.TildeToken | SyntaxKind.ExclamationToken; + export class PrefixUnaryExpression extends Node implements UpdateExpression { + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstPrefixUnaryExpression; + get operator(): PrefixUnaryOperator; + get operand(): UnaryExpression; } - type PostfixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken; - interface PostfixUnaryExpression extends UpdateExpression { - readonly kind: SyntaxKind.PostfixUnaryExpression; - readonly operand: LeftHandSideExpression; - readonly operator: PostfixUnaryOperator; + export type PostfixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken; + export class PostfixUnaryExpression extends Node implements UpdateExpression { + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstPostfixUnaryExpression; + get operand(): LeftHandSideExpression; + get operator(): PostfixUnaryOperator; } - interface LeftHandSideExpression extends UpdateExpression { + export interface LeftHandSideExpression extends UpdateExpression { _leftHandSideExpressionBrand: any; + readonly ast: AstLeftHandSideExpression; } - interface MemberExpression extends LeftHandSideExpression { + export interface MemberExpression extends LeftHandSideExpression { _memberExpressionBrand: any; + readonly ast: AstMemberExpression; } - interface PrimaryExpression extends MemberExpression { + export interface PrimaryExpression extends MemberExpression { _primaryExpressionBrand: any; + readonly ast: AstPrimaryExpression; } - interface NullLiteral extends PrimaryExpression { - readonly kind: SyntaxKind.NullKeyword; - } - interface TrueLiteral extends PrimaryExpression { - readonly kind: SyntaxKind.TrueKeyword; - } - interface FalseLiteral extends PrimaryExpression { - readonly kind: SyntaxKind.FalseKeyword; - } - type BooleanLiteral = TrueLiteral | FalseLiteral; - interface ThisExpression extends PrimaryExpression, FlowContainer { - readonly kind: SyntaxKind.ThisKeyword; - } - interface SuperExpression extends PrimaryExpression, FlowContainer { - readonly kind: SyntaxKind.SuperKeyword; - } - interface ImportExpression extends PrimaryExpression { - readonly kind: SyntaxKind.ImportKeyword; + export class NullLiteral extends Token implements KeywordExpression { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstNullLiteral; } - interface DeleteExpression extends UnaryExpression { - readonly kind: SyntaxKind.DeleteExpression; - readonly expression: UnaryExpression; + export class TrueLiteral extends Token implements KeywordExpression { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstTrueLiteral; } - interface TypeOfExpression extends UnaryExpression { - readonly kind: SyntaxKind.TypeOfExpression; - readonly expression: UnaryExpression; + export class FalseLiteral extends Token implements KeywordExpression { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstFalseLiteral; } - interface VoidExpression extends UnaryExpression { - readonly kind: SyntaxKind.VoidExpression; - readonly expression: UnaryExpression; + export type BooleanLiteral = TrueLiteral | FalseLiteral; + export class ThisExpression extends Token implements KeywordExpression, FlowContainer { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _flowContainerBrand: any; + readonly ast: AstThisExpression; } - interface AwaitExpression extends UnaryExpression { - readonly kind: SyntaxKind.AwaitExpression; - readonly expression: UnaryExpression; + export class SuperExpression extends Token implements KeywordExpression, FlowContainer { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _flowContainerBrand: any; + readonly ast: AstSuperExpression; } - interface YieldExpression extends Expression { - readonly kind: SyntaxKind.YieldExpression; - readonly asteriskToken?: AsteriskToken | undefined; - readonly expression?: Expression | undefined; - } - interface SyntheticExpression extends Expression { - readonly kind: SyntaxKind.SyntheticExpression; - readonly isSpread: boolean; - readonly type: Type; - readonly tupleNameSource?: ParameterDeclaration | NamedTupleMember | undefined; - } - type ExponentiationOperator = SyntaxKind.AsteriskAsteriskToken; - type MultiplicativeOperator = SyntaxKind.AsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken; - type MultiplicativeOperatorOrHigher = ExponentiationOperator | MultiplicativeOperator; - type AdditiveOperator = SyntaxKind.PlusToken | SyntaxKind.MinusToken; - type AdditiveOperatorOrHigher = MultiplicativeOperatorOrHigher | AdditiveOperator; - type ShiftOperator = SyntaxKind.LessThanLessThanToken | SyntaxKind.GreaterThanGreaterThanToken | SyntaxKind.GreaterThanGreaterThanGreaterThanToken; - type ShiftOperatorOrHigher = AdditiveOperatorOrHigher | ShiftOperator; - type RelationalOperator = SyntaxKind.LessThanToken | SyntaxKind.LessThanEqualsToken | SyntaxKind.GreaterThanToken | SyntaxKind.GreaterThanEqualsToken | SyntaxKind.InstanceOfKeyword | SyntaxKind.InKeyword; - type RelationalOperatorOrHigher = ShiftOperatorOrHigher | RelationalOperator; - type EqualityOperator = SyntaxKind.EqualsEqualsToken | SyntaxKind.EqualsEqualsEqualsToken | SyntaxKind.ExclamationEqualsEqualsToken | SyntaxKind.ExclamationEqualsToken; - type EqualityOperatorOrHigher = RelationalOperatorOrHigher | EqualityOperator; - type BitwiseOperator = SyntaxKind.AmpersandToken | SyntaxKind.BarToken | SyntaxKind.CaretToken; - type BitwiseOperatorOrHigher = EqualityOperatorOrHigher | BitwiseOperator; - type LogicalOperator = SyntaxKind.AmpersandAmpersandToken | SyntaxKind.BarBarToken; - type LogicalOperatorOrHigher = BitwiseOperatorOrHigher | LogicalOperator; - type CompoundAssignmentOperator = SyntaxKind.PlusEqualsToken | SyntaxKind.MinusEqualsToken | SyntaxKind.AsteriskAsteriskEqualsToken | SyntaxKind.AsteriskEqualsToken | SyntaxKind.SlashEqualsToken | SyntaxKind.PercentEqualsToken | SyntaxKind.AmpersandEqualsToken | SyntaxKind.BarEqualsToken | SyntaxKind.CaretEqualsToken | SyntaxKind.LessThanLessThanEqualsToken | SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken | SyntaxKind.GreaterThanGreaterThanEqualsToken | SyntaxKind.BarBarEqualsToken | SyntaxKind.AmpersandAmpersandEqualsToken | SyntaxKind.QuestionQuestionEqualsToken; - type AssignmentOperator = SyntaxKind.EqualsToken | CompoundAssignmentOperator; - type AssignmentOperatorOrHigher = SyntaxKind.QuestionQuestionToken | LogicalOperatorOrHigher | AssignmentOperator; - type BinaryOperator = AssignmentOperatorOrHigher | SyntaxKind.CommaToken; - type LogicalOrCoalescingAssignmentOperator = SyntaxKind.AmpersandAmpersandEqualsToken | SyntaxKind.BarBarEqualsToken | SyntaxKind.QuestionQuestionEqualsToken; - type BinaryOperatorToken = Token; - interface BinaryExpression extends Expression, Declaration, JSDocContainer { - readonly kind: SyntaxKind.BinaryExpression; - readonly left: Expression; - readonly operatorToken: BinaryOperatorToken; - readonly right: Expression; - } - type AssignmentOperatorToken = Token; - interface AssignmentExpression extends BinaryExpression { + export class ImportExpression extends Token implements KeywordExpression { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstImportExpression; + } + export class DeleteExpression extends Node implements UnaryExpression { + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstDeleteExpression; + get expression(): UnaryExpression; + } + export class TypeOfExpression extends Node implements UnaryExpression { + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstTypeOfExpression; + get expression(): UnaryExpression; + } + export class VoidExpression extends Node implements UnaryExpression { + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstVoidExpression; + get expression(): UnaryExpression; + } + export class AwaitExpression extends Node implements UnaryExpression { + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstAwaitExpression; + get expression(): UnaryExpression; + } + export class YieldExpression extends Node implements Expression { + _expressionBrand: any; + readonly ast: AstYieldExpression; + get asteriskToken(): AsteriskToken | undefined; + get expression(): Expression | undefined; + } + export class SyntheticExpression extends Node implements Expression { + _expressionBrand: any; + readonly ast: AstSyntheticExpression; + get isSpread(): boolean; + get type(): Type; + get tupleNameSource(): ParameterDeclaration | NamedTupleMember | undefined; + } + export type ExponentiationOperator = SyntaxKind.AsteriskAsteriskToken; + export type MultiplicativeOperator = SyntaxKind.AsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken; + export type MultiplicativeOperatorOrHigher = ExponentiationOperator | MultiplicativeOperator; + export type AdditiveOperator = SyntaxKind.PlusToken | SyntaxKind.MinusToken; + export type AdditiveOperatorOrHigher = MultiplicativeOperatorOrHigher | AdditiveOperator; + export type ShiftOperator = SyntaxKind.LessThanLessThanToken | SyntaxKind.GreaterThanGreaterThanToken | SyntaxKind.GreaterThanGreaterThanGreaterThanToken; + export type ShiftOperatorOrHigher = AdditiveOperatorOrHigher | ShiftOperator; + export type RelationalOperator = SyntaxKind.LessThanToken | SyntaxKind.LessThanEqualsToken | SyntaxKind.GreaterThanToken | SyntaxKind.GreaterThanEqualsToken | SyntaxKind.InstanceOfKeyword | SyntaxKind.InKeyword; + export type RelationalOperatorOrHigher = ShiftOperatorOrHigher | RelationalOperator; + export type EqualityOperator = SyntaxKind.EqualsEqualsToken | SyntaxKind.EqualsEqualsEqualsToken | SyntaxKind.ExclamationEqualsEqualsToken | SyntaxKind.ExclamationEqualsToken; + export type EqualityOperatorOrHigher = RelationalOperatorOrHigher | EqualityOperator; + export type BitwiseOperator = SyntaxKind.AmpersandToken | SyntaxKind.BarToken | SyntaxKind.CaretToken; + export type BitwiseOperatorOrHigher = EqualityOperatorOrHigher | BitwiseOperator; + export type LogicalOperator = SyntaxKind.AmpersandAmpersandToken | SyntaxKind.BarBarToken; + export type LogicalOperatorOrHigher = BitwiseOperatorOrHigher | LogicalOperator; + export type CompoundAssignmentOperator = SyntaxKind.PlusEqualsToken | SyntaxKind.MinusEqualsToken | SyntaxKind.AsteriskAsteriskEqualsToken | SyntaxKind.AsteriskEqualsToken | SyntaxKind.SlashEqualsToken | SyntaxKind.PercentEqualsToken | SyntaxKind.AmpersandEqualsToken | SyntaxKind.BarEqualsToken | SyntaxKind.CaretEqualsToken | SyntaxKind.LessThanLessThanEqualsToken | SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken | SyntaxKind.GreaterThanGreaterThanEqualsToken | SyntaxKind.BarBarEqualsToken | SyntaxKind.AmpersandAmpersandEqualsToken | SyntaxKind.QuestionQuestionEqualsToken; + export type AssignmentOperator = SyntaxKind.EqualsToken | CompoundAssignmentOperator; + export type AssignmentOperatorOrHigher = SyntaxKind.QuestionQuestionToken | LogicalOperatorOrHigher | AssignmentOperator; + export type BinaryOperator = AssignmentOperatorOrHigher | SyntaxKind.CommaToken; + export type LogicalOrCoalescingAssignmentOperator = SyntaxKind.AmpersandAmpersandEqualsToken | SyntaxKind.BarBarEqualsToken | SyntaxKind.QuestionQuestionEqualsToken; + export type BinaryOperatorToken = Token; + export class BinaryExpression extends Node implements Expression, Declaration, JSDocContainer { + _expressionBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstBinaryExpression; + get left(): Expression; + get operatorToken(): BinaryOperatorToken; + get right(): Expression; + } + export type AssignmentOperatorToken = Token; + export interface AssignmentExpression extends BinaryExpression { readonly left: LeftHandSideExpression; readonly operatorToken: TOperator; } - interface ObjectDestructuringAssignment extends AssignmentExpression { + export interface ObjectDestructuringAssignment extends AssignmentExpression { readonly left: ObjectLiteralExpression; } - interface ArrayDestructuringAssignment extends AssignmentExpression { + export interface ArrayDestructuringAssignment extends AssignmentExpression { readonly left: ArrayLiteralExpression; } - type DestructuringAssignment = ObjectDestructuringAssignment | ArrayDestructuringAssignment; - type BindingOrAssignmentElement = VariableDeclaration | ParameterDeclaration | ObjectBindingOrAssignmentElement | ArrayBindingOrAssignmentElement; - type ObjectBindingOrAssignmentElement = BindingElement | PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment; - type ArrayBindingOrAssignmentElement = BindingElement | OmittedExpression | SpreadElement | ArrayLiteralExpression | ObjectLiteralExpression | AssignmentExpression | Identifier | PropertyAccessExpression | ElementAccessExpression; - type BindingOrAssignmentElementRestIndicator = DotDotDotToken | SpreadElement | SpreadAssignment; - type BindingOrAssignmentElementTarget = BindingOrAssignmentPattern | Identifier | PropertyAccessExpression | ElementAccessExpression | OmittedExpression; - type ObjectBindingOrAssignmentPattern = ObjectBindingPattern | ObjectLiteralExpression; - type ArrayBindingOrAssignmentPattern = ArrayBindingPattern | ArrayLiteralExpression; - type AssignmentPattern = ObjectLiteralExpression | ArrayLiteralExpression; - type BindingOrAssignmentPattern = ObjectBindingOrAssignmentPattern | ArrayBindingOrAssignmentPattern; - interface ConditionalExpression extends Expression { - readonly kind: SyntaxKind.ConditionalExpression; - readonly condition: Expression; - readonly questionToken: QuestionToken; - readonly whenTrue: Expression; - readonly colonToken: ColonToken; - readonly whenFalse: Expression; - } - type FunctionBody = Block; - type ConciseBody = FunctionBody | Expression; - interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.FunctionExpression; - readonly modifiers?: NodeArray | undefined; - readonly name?: Identifier | undefined; - readonly body: FunctionBody; - } - interface ArrowFunction extends Expression, FunctionLikeDeclarationBase, JSDocContainer, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.ArrowFunction; - readonly modifiers?: NodeArray | undefined; - readonly equalsGreaterThanToken: EqualsGreaterThanToken; - readonly body: ConciseBody; - readonly name: never; - } - interface LiteralLikeNode extends Node { - text: string; - isUnterminated?: boolean | undefined; - hasExtendedUnicodeEscape?: boolean | undefined; - } - interface TemplateLiteralLikeNode extends LiteralLikeNode { - rawText?: string | undefined; + export type DestructuringAssignment = ObjectDestructuringAssignment | ArrayDestructuringAssignment; + export type BindingOrAssignmentElement = VariableDeclaration | ParameterDeclaration | ObjectBindingOrAssignmentElement | ArrayBindingOrAssignmentElement; + export type ObjectBindingOrAssignmentElement = BindingElement | PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment; + export type ArrayBindingOrAssignmentElement = BindingElement | OmittedExpression | SpreadElement | ArrayLiteralExpression | ObjectLiteralExpression | AssignmentExpression | Identifier | PropertyAccessExpression | ElementAccessExpression; + export type BindingOrAssignmentElementRestIndicator = DotDotDotToken | SpreadElement | SpreadAssignment; + export type BindingOrAssignmentElementTarget = BindingOrAssignmentPattern | Identifier | PropertyAccessExpression | ElementAccessExpression | OmittedExpression; + export type ObjectBindingOrAssignmentPattern = ObjectBindingPattern | ObjectLiteralExpression; + export type ArrayBindingOrAssignmentPattern = ArrayBindingPattern | ArrayLiteralExpression; + export type AssignmentPattern = ObjectLiteralExpression | ArrayLiteralExpression; + export type BindingOrAssignmentPattern = ObjectBindingOrAssignmentPattern | ArrayBindingOrAssignmentPattern; + export interface InstanceofExpression extends BinaryExpression { + readonly operatorToken: Token; } - interface LiteralExpression extends LiteralLikeNode, PrimaryExpression { + export class ConditionalExpression extends Node implements Expression { + _expressionBrand: any; + readonly ast: AstConditionalExpression; + get condition(): Expression; + get questionToken(): QuestionToken; + get whenTrue(): Expression; + get colonToken(): ColonToken; + get whenFalse(): Expression; + } + export type FunctionBody = Block; + export type ConciseBody = FunctionBody | Expression; + export class FunctionExpression extends Node implements PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer, LocalsContainer, FlowContainer { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _functionLikeDeclarationBrand: any; + _signatureDeclarationBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstFunctionExpression; + get modifiers(): NodeArray | undefined; + get asteriskToken(): AsteriskToken | undefined; + get name(): Identifier | undefined; + get typeParameters(): NodeArray | undefined; + get parameters(): NodeArray; + get type(): TypeNode | undefined; + get body(): Block; + } + export class ArrowFunction extends Node implements Expression, FunctionLikeDeclarationBase, JSDocContainer, LocalsContainer, FlowContainer { + _expressionBrand: any; + _functionLikeDeclarationBrand: any; + _signatureDeclarationBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstArrowFunction; + get modifiers(): NodeArray | undefined; + get equalsGreaterThanToken(): EqualsGreaterThanToken; + get typeParameters(): NodeArray | undefined; + get parameters(): NodeArray; + get type(): TypeNode | undefined; + get body(): Block | Expression; + } + export interface LiteralLikeNode extends Node { + readonly ast: AstLiteralLikeNode; + readonly data: AstLiteralLikeNodeData; + get text(): string; + } + export interface StringLiteralLikeNode extends LiteralLikeNode { + readonly ast: AstStringLiteralLikeNode; + readonly data: AstStringLiteralLikeNodeData; + get isUnterminated(): boolean | undefined; + get hasExtendedUnicodeEscape(): boolean | undefined; + } + export interface TemplateLiteralLikeNode extends StringLiteralLikeNode { + readonly ast: AstTemplateLiteralLikeNode; + readonly data: AstTemplateLiteralLikeNodeData; + get rawText(): string | undefined; + } + export interface LiteralExpression extends LiteralLikeNode, PrimaryExpression { _literalExpressionBrand: any; + readonly ast: AstLiteralExpression; + readonly data: AstLiteralExpressionData; } - interface RegularExpressionLiteral extends LiteralExpression { - readonly kind: SyntaxKind.RegularExpressionLiteral; + export class RegularExpressionLiteral extends Token implements StringLiteralLikeNode { + _literalExpressionBrand: any; + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstRegularExpressionLiteral; + get text(): string; + get isUnterminated(): boolean | undefined; + get hasExtendedUnicodeEscape(): boolean | undefined; } - interface NoSubstitutionTemplateLiteral extends LiteralExpression, TemplateLiteralLikeNode, Declaration { - readonly kind: SyntaxKind.NoSubstitutionTemplateLiteral; + export class NoSubstitutionTemplateLiteral extends Token implements LiteralExpression, TemplateLiteralLikeNode, Declaration { + _literalExpressionBrand: any; + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _declarationBrand: any; + readonly ast: AstNoSubstitutionTemplateLiteral; + get text(): string; + get rawText(): string | undefined; + get isUnterminated(): boolean | undefined; + get hasExtendedUnicodeEscape(): boolean | undefined; } - enum TokenFlags { + export enum TokenFlags { None = 0, Scientific = 16, Octal = 32, @@ -4970,51 +5400,100 @@ declare namespace ts { BinarySpecifier = 128, OctalSpecifier = 256, } - interface NumericLiteral extends LiteralExpression, Declaration { - readonly kind: SyntaxKind.NumericLiteral; - } - interface BigIntLiteral extends LiteralExpression { - readonly kind: SyntaxKind.BigIntLiteral; - } - type LiteralToken = NumericLiteral | BigIntLiteral | StringLiteral | JsxText | RegularExpressionLiteral | NoSubstitutionTemplateLiteral; - interface TemplateHead extends TemplateLiteralLikeNode { - readonly kind: SyntaxKind.TemplateHead; - readonly parent: TemplateExpression | TemplateLiteralTypeNode; - } - interface TemplateMiddle extends TemplateLiteralLikeNode { - readonly kind: SyntaxKind.TemplateMiddle; - readonly parent: TemplateSpan | TemplateLiteralTypeSpan; - } - interface TemplateTail extends TemplateLiteralLikeNode { - readonly kind: SyntaxKind.TemplateTail; - readonly parent: TemplateSpan | TemplateLiteralTypeSpan; - } - type PseudoLiteralToken = TemplateHead | TemplateMiddle | TemplateTail; - type TemplateLiteralToken = NoSubstitutionTemplateLiteral | PseudoLiteralToken; - interface TemplateExpression extends PrimaryExpression { - readonly kind: SyntaxKind.TemplateExpression; - readonly head: TemplateHead; - readonly templateSpans: NodeArray; - } - type TemplateLiteral = TemplateExpression | NoSubstitutionTemplateLiteral; - interface TemplateSpan extends Node { - readonly kind: SyntaxKind.TemplateSpan; - readonly parent: TemplateExpression; - readonly expression: Expression; - readonly literal: TemplateMiddle | TemplateTail; + export class NumericLiteral extends Token implements LiteralExpression, LiteralLikeNode, Declaration { + _literalExpressionBrand: any; + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _declarationBrand: any; + readonly ast: AstNumericLiteral; + get text(): string; } - interface ParenthesizedExpression extends PrimaryExpression, JSDocContainer { - readonly kind: SyntaxKind.ParenthesizedExpression; - readonly expression: Expression; + export class BigIntLiteral extends Token implements LiteralExpression, LiteralLikeNode { + _literalExpressionBrand: any; + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstBigIntLiteral; + get text(): string; + } + export type LiteralToken = NumericLiteral | BigIntLiteral | StringLiteral | JsxText | RegularExpressionLiteral | NoSubstitutionTemplateLiteral; + export class TemplateHead extends Token implements TemplateLiteralLikeNode { + readonly ast: AstTemplateHead; + get parent(): TemplateExpression | TemplateLiteralTypeNode; + get text(): string; + get isUnterminated(): boolean | undefined; + get hasExtendedUnicodeEscape(): boolean | undefined; + get rawText(): string | undefined; + } + export class TemplateMiddle extends Token implements TemplateLiteralLikeNode { + readonly ast: AstTemplateMiddle; + get parent(): TemplateSpan | TemplateLiteralTypeSpan; + get text(): string; + get isUnterminated(): boolean | undefined; + get hasExtendedUnicodeEscape(): boolean | undefined; + get rawText(): string | undefined; + } + export class TemplateTail extends Token implements TemplateLiteralLikeNode { + readonly ast: AstTemplateTail; + get parent(): TemplateSpan | TemplateLiteralTypeSpan; + get text(): string; + get isUnterminated(): boolean | undefined; + get hasExtendedUnicodeEscape(): boolean | undefined; + get rawText(): string | undefined; + } + export type PseudoLiteralToken = TemplateHead | TemplateMiddle | TemplateTail; + export type TemplateLiteralToken = NoSubstitutionTemplateLiteral | PseudoLiteralToken; + export class TemplateExpression extends Node implements PrimaryExpression { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstTemplateExpression; + get head(): TemplateHead; + get templateSpans(): NodeArray; + } + export type TemplateLiteral = TemplateExpression | NoSubstitutionTemplateLiteral; + export class TemplateSpan extends Node { + readonly ast: AstTemplateSpan; + get parent(): TemplateExpression; + get expression(): Expression; + get literal(): TemplateMiddle | TemplateTail; + } + export class ParenthesizedExpression extends Node implements PrimaryExpression, JSDocContainer { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstParenthesizedExpression; + get expression(): Expression; } - interface ArrayLiteralExpression extends PrimaryExpression { - readonly kind: SyntaxKind.ArrayLiteralExpression; - readonly elements: NodeArray; + export class ArrayLiteralExpression extends Node implements PrimaryExpression { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstArrayLiteralExpression; + get elements(): NodeArray; } - interface SpreadElement extends Expression { - readonly kind: SyntaxKind.SpreadElement; - readonly parent: ArrayLiteralExpression | CallExpression | NewExpression; - readonly expression: Expression; + export class SpreadElement extends Node implements Expression { + _expressionBrand: any; + readonly ast: AstSpreadElement; + get parent(): ArrayLiteralExpression | CallExpression | NewExpression; + get expression(): Expression; } /** * This interface is a base interface for ObjectLiteralExpression and JSXAttributes to extend from. JSXAttributes is similar to @@ -5022,531 +5501,795 @@ declare namespace ts { * JSXAttribute or JSXSpreadAttribute. ObjectLiteralExpression, on the other hand, can only have properties of type * ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.) */ - interface ObjectLiteralExpressionBase extends PrimaryExpression, Declaration { + export interface ObjectLiteralExpressionBase extends PrimaryExpression, Declaration { + readonly ast: AstNode; readonly properties: NodeArray; } - interface ObjectLiteralExpression extends ObjectLiteralExpressionBase, JSDocContainer { - readonly kind: SyntaxKind.ObjectLiteralExpression; + export class ObjectLiteralExpression extends Node implements ObjectLiteralExpressionBase, JSDocContainer { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstObjectLiteralExpression; + get properties(): NodeArray; } - type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression; - type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression; - type AccessExpression = PropertyAccessExpression | ElementAccessExpression; - interface PropertyAccessExpression extends MemberExpression, NamedDeclaration, JSDocContainer, FlowContainer { - readonly kind: SyntaxKind.PropertyAccessExpression; - readonly expression: LeftHandSideExpression; - readonly questionDotToken?: QuestionDotToken | undefined; - readonly name: MemberName; + export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression; + export type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression; + export type AccessExpression = PropertyAccessExpression | ElementAccessExpression; + export class PropertyAccessExpression extends Node implements MemberExpression, NamedDeclaration, JSDocContainer, FlowContainer { + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstPropertyAccessExpression; + get expression(): LeftHandSideExpression; + get questionDotToken(): QuestionDotToken | undefined; + get name(): Identifier | PrivateIdentifier; + } + export interface JsxTagNamePropertyAccess extends PropertyAccessExpression { + readonly ast: AstJsxTagNamePropertyAccess; + readonly data: AstJsxTagNamePropertyAccessData; + readonly expression: Identifier | ThisExpression | JsxTagNamePropertyAccess; } - interface PropertyAccessChain extends PropertyAccessExpression { + export interface PropertyAccessChain extends PropertyAccessExpression { _optionalChainBrand: any; + readonly ast: AstPropertyAccessChain; readonly name: MemberName; } - interface SuperPropertyAccessExpression extends PropertyAccessExpression { + export interface SuperPropertyAccessExpression extends PropertyAccessExpression { readonly expression: SuperExpression; } /** Brand for a PropertyAccessExpression which, like a QualifiedName, consists of a sequence of identifiers separated by dots. */ - interface PropertyAccessEntityNameExpression extends PropertyAccessExpression { + export interface PropertyAccessEntityNameExpression extends PropertyAccessExpression { _propertyAccessExpressionLikeQualifiedNameBrand?: any; readonly expression: EntityNameExpression; readonly name: Identifier; } - interface ElementAccessExpression extends MemberExpression, Declaration, JSDocContainer, FlowContainer { - readonly kind: SyntaxKind.ElementAccessExpression; - readonly expression: LeftHandSideExpression; - readonly questionDotToken?: QuestionDotToken | undefined; - readonly argumentExpression: Expression; + export class ElementAccessExpression extends Node implements MemberExpression, Declaration, JSDocContainer, FlowContainer { + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstElementAccessExpression; + get expression(): LeftHandSideExpression; + get questionDotToken(): QuestionDotToken | undefined; + get argumentExpression(): Expression; } - interface ElementAccessChain extends ElementAccessExpression { + export interface ElementAccessChain extends ElementAccessExpression { _optionalChainBrand: any; + readonly ast: AstElementAccessChain; } - interface SuperElementAccessExpression extends ElementAccessExpression { + export interface SuperElementAccessExpression extends ElementAccessExpression { readonly expression: SuperExpression; } - type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; - interface CallExpression extends LeftHandSideExpression, Declaration { - readonly kind: SyntaxKind.CallExpression; - readonly expression: LeftHandSideExpression; - readonly questionDotToken?: QuestionDotToken | undefined; - readonly typeArguments?: NodeArray | undefined; - readonly arguments: NodeArray; + export type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; + export class CallExpression extends Node implements LeftHandSideExpression, Declaration { + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _declarationBrand: any; + readonly ast: AstCallExpression; + get expression(): LeftHandSideExpression; + get questionDotToken(): QuestionDotToken | undefined; + get typeArguments(): NodeArray | undefined; + get arguments(): NodeArray; } - interface CallChain extends CallExpression { + export interface CallChain extends CallExpression { _optionalChainBrand: any; + readonly ast: AstCallChain; } - type OptionalChain = PropertyAccessChain | ElementAccessChain | CallChain | NonNullChain; - interface SuperCall extends CallExpression { + export type OptionalChain = PropertyAccessChain | ElementAccessChain | CallChain | NonNullChain; + export interface SuperCall extends CallExpression { readonly expression: SuperExpression; } - interface ImportCall extends CallExpression { + export interface ImportCall extends CallExpression { readonly expression: ImportExpression; } - interface ExpressionWithTypeArguments extends MemberExpression, NodeWithTypeArguments { - readonly kind: SyntaxKind.ExpressionWithTypeArguments; - readonly expression: LeftHandSideExpression; + export class ExpressionWithTypeArguments extends Node implements MemberExpression, NodeWithTypeArguments { + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _typeNodeBrand: any; + readonly ast: AstExpressionWithTypeArguments; + get expression(): LeftHandSideExpression; + get typeArguments(): NodeArray | undefined; } - interface NewExpression extends PrimaryExpression, Declaration { - readonly kind: SyntaxKind.NewExpression; - readonly expression: LeftHandSideExpression; - readonly typeArguments?: NodeArray | undefined; - readonly arguments?: NodeArray | undefined; + export class NewExpression extends Node implements PrimaryExpression, Declaration { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _declarationBrand: any; + readonly ast: AstNewExpression; + get expression(): LeftHandSideExpression; + get typeArguments(): NodeArray | undefined; + get arguments(): NodeArray | undefined; } - interface TaggedTemplateExpression extends MemberExpression { - readonly kind: SyntaxKind.TaggedTemplateExpression; - readonly tag: LeftHandSideExpression; - readonly typeArguments?: NodeArray | undefined; - readonly template: TemplateLiteral; + export class TaggedTemplateExpression extends Node implements MemberExpression { + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstTaggedTemplateExpression; + get tag(): LeftHandSideExpression; + get typeArguments(): NodeArray | undefined; + get template(): NoSubstitutionTemplateLiteral | TemplateExpression; } - interface InstanceofExpression extends BinaryExpression { - readonly operatorToken: Token; + export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator | JsxOpeningLikeElement | InstanceofExpression; + export class AsExpression extends Node implements Expression { + _expressionBrand: any; + readonly ast: AstAsExpression; + get expression(): Expression; + get type(): TypeNode; } - type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator | JsxOpeningLikeElement | InstanceofExpression; - interface AsExpression extends Expression { - readonly kind: SyntaxKind.AsExpression; - readonly expression: Expression; - readonly type: TypeNode; + export class TypeAssertionExpression extends Node implements UnaryExpression { + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstTypeAssertion; + get type(): TypeNode; + get expression(): UnaryExpression; + } + /** @deprecated Use `TypeAssertionExpression` instead */ + export type TypeAssertion = TypeAssertionExpression; + export type AssertionExpression = TypeAssertionExpression | AsExpression; + export class SatisfiesExpression extends Node implements Expression { + _expressionBrand: any; + readonly ast: AstSatisfiesExpression; + get expression(): Expression; + get type(): TypeNode; } - interface TypeAssertion extends UnaryExpression { - readonly kind: SyntaxKind.TypeAssertionExpression; - readonly type: TypeNode; - readonly expression: UnaryExpression; + export class NonNullExpression extends Node implements LeftHandSideExpression { + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstNonNullExpression; + get expression(): Expression; } - interface SatisfiesExpression extends Expression { - readonly kind: SyntaxKind.SatisfiesExpression; - readonly expression: Expression; - readonly type: TypeNode; + export interface NonNullChain extends NonNullExpression { + _optionalChainBrand: any; + readonly ast: AstNonNullChain; } - type AssertionExpression = TypeAssertion | AsExpression; - interface NonNullExpression extends LeftHandSideExpression { - readonly kind: SyntaxKind.NonNullExpression; - readonly expression: Expression; + export class MetaProperty extends Node implements PrimaryExpression, FlowContainer { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _flowContainerBrand: any; + readonly ast: AstMetaProperty; + get keywordToken(): SyntaxKind.ImportKeyword | SyntaxKind.NewKeyword; + get name(): Identifier; } - interface NonNullChain extends NonNullExpression { - _optionalChainBrand: any; + export class JsxElement extends Node implements PrimaryExpression { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstJsxElement; + get openingElement(): JsxOpeningElement; + get children(): NodeArray; + get closingElement(): JsxClosingElement; + } + export type JsxOpeningLikeElement = JsxSelfClosingElement | JsxOpeningElement; + export type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute; + export type JsxAttributeName = Identifier | JsxNamespacedName; + export type JsxTagNameExpression = Identifier | ThisExpression | JsxTagNamePropertyAccess | JsxNamespacedName; + export class JsxAttributes extends Node implements PrimaryExpression, Declaration { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + _declarationBrand: any; + readonly ast: AstJsxAttributes; + get parent(): JsxOpeningLikeElement; + get properties(): NodeArray; } - interface MetaProperty extends PrimaryExpression, FlowContainer { - readonly kind: SyntaxKind.MetaProperty; - readonly keywordToken: SyntaxKind.NewKeyword | SyntaxKind.ImportKeyword; - readonly name: Identifier; + export class JsxNamespacedName extends Node { + readonly ast: AstJsxNamespacedName; + get name(): Identifier; + get namespace(): Identifier; } - interface JsxElement extends PrimaryExpression { - readonly kind: SyntaxKind.JsxElement; - readonly openingElement: JsxOpeningElement; - readonly children: NodeArray; - readonly closingElement: JsxClosingElement; - } - type JsxOpeningLikeElement = JsxSelfClosingElement | JsxOpeningElement; - type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute; - type JsxAttributeName = Identifier | JsxNamespacedName; - type JsxTagNameExpression = Identifier | ThisExpression | JsxTagNamePropertyAccess | JsxNamespacedName; - interface JsxTagNamePropertyAccess extends PropertyAccessExpression { - readonly expression: Identifier | ThisExpression | JsxTagNamePropertyAccess; + export class JsxOpeningElement extends Node implements Expression { + _expressionBrand: any; + readonly ast: AstJsxOpeningElement; + get parent(): JsxElement; + get tagName(): JsxTagNameExpression; + get typeArguments(): NodeArray | undefined; + get attributes(): JsxAttributes; } - interface JsxAttributes extends PrimaryExpression, Declaration { - readonly kind: SyntaxKind.JsxAttributes; - readonly properties: NodeArray; - readonly parent: JsxOpeningLikeElement; + export class JsxSelfClosingElement extends Node implements PrimaryExpression { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstJsxSelfClosingElement; + get tagName(): JsxTagNameExpression; + get typeArguments(): NodeArray | undefined; + get attributes(): JsxAttributes; } - interface JsxNamespacedName extends Node { - readonly kind: SyntaxKind.JsxNamespacedName; - readonly name: Identifier; - readonly namespace: Identifier; + export class JsxFragment extends Node implements PrimaryExpression { + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstJsxFragment; + get openingFragment(): JsxOpeningFragment; + get children(): NodeArray; + get closingFragment(): JsxClosingFragment; } - interface JsxOpeningElement extends Expression { - readonly kind: SyntaxKind.JsxOpeningElement; - readonly parent: JsxElement; - readonly tagName: JsxTagNameExpression; - readonly typeArguments?: NodeArray | undefined; - readonly attributes: JsxAttributes; + export class JsxOpeningFragment extends Node implements Expression { + _expressionBrand: any; + readonly ast: AstJsxOpeningFragment; + get parent(): JsxFragment; } - interface JsxSelfClosingElement extends PrimaryExpression { - readonly kind: SyntaxKind.JsxSelfClosingElement; - readonly tagName: JsxTagNameExpression; - readonly typeArguments?: NodeArray | undefined; - readonly attributes: JsxAttributes; - } - interface JsxFragment extends PrimaryExpression { - readonly kind: SyntaxKind.JsxFragment; - readonly openingFragment: JsxOpeningFragment; - readonly children: NodeArray; - readonly closingFragment: JsxClosingFragment; - } - interface JsxOpeningFragment extends Expression { - readonly kind: SyntaxKind.JsxOpeningFragment; - readonly parent: JsxFragment; - } - interface JsxClosingFragment extends Expression { - readonly kind: SyntaxKind.JsxClosingFragment; - readonly parent: JsxFragment; - } - interface JsxAttribute extends Declaration { - readonly kind: SyntaxKind.JsxAttribute; - readonly parent: JsxAttributes; - readonly name: JsxAttributeName; - readonly initializer?: JsxAttributeValue | undefined; - } - type JsxAttributeValue = StringLiteral | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment; - interface JsxSpreadAttribute extends ObjectLiteralElement { - readonly kind: SyntaxKind.JsxSpreadAttribute; - readonly parent: JsxAttributes; - readonly expression: Expression; - } - interface JsxClosingElement extends Node { - readonly kind: SyntaxKind.JsxClosingElement; - readonly parent: JsxElement; - readonly tagName: JsxTagNameExpression; - } - interface JsxExpression extends Expression { - readonly kind: SyntaxKind.JsxExpression; - readonly parent: JsxElement | JsxFragment | JsxAttributeLike; - readonly dotDotDotToken?: Token | undefined; - readonly expression?: Expression | undefined; - } - interface JsxText extends LiteralLikeNode { - readonly kind: SyntaxKind.JsxText; - readonly parent: JsxElement | JsxFragment; - readonly containsOnlyTriviaWhiteSpaces: boolean; - } - type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment; - interface Statement extends Node, JSDocContainer { + export class JsxClosingFragment extends Node implements Expression { + _expressionBrand: any; + readonly ast: AstJsxClosingFragment; + get parent(): JsxFragment; + } + export class JsxAttribute extends Node implements Declaration { + readonly ast: AstJsxAttribute; + _declarationBrand: any; + get parent(): JsxAttributes; + get name(): JsxAttributeName; + get initializer(): JsxAttributeValue | undefined; + } + export type JsxAttributeValue = StringLiteral | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment; + export class JsxSpreadAttribute extends Node implements ObjectLiteralElement { + _objectLiteralBrand: any; + _declarationBrand: any; + readonly ast: AstJsxSpreadAttribute; + get parent(): JsxAttributes; + get expression(): Expression; + } + export class JsxClosingElement extends Node { + readonly ast: AstJsxClosingElement; + get parent(): JsxElement; + get tagName(): JsxTagNameExpression; + } + export class JsxExpression extends Node implements Expression { + _expressionBrand: any; + readonly ast: AstJsxExpression; + get parent(): JsxElement | JsxFragment | JsxAttributeLike; + get dotDotDotToken(): DotDotDotToken | undefined; + get expression(): Expression | undefined; + } + export class JsxText extends Token implements LiteralLikeNode { + readonly ast: AstJsxText; + get parent(): JsxElement | JsxFragment; + get text(): string; + get isUnterminated(): boolean | undefined; + get hasExtendedUnicodeEscape(): boolean | undefined; + get containsOnlyTriviaWhiteSpaces(): boolean; + } + export type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment; + export interface Statement extends JSDocContainer { _statementBrand: any; + readonly ast: AstStatement; } - interface NotEmittedStatement extends Statement { - readonly kind: SyntaxKind.NotEmittedStatement; + export class NotEmittedStatement extends Node implements Statement { + _statementBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstNotEmittedStatement; } - interface NotEmittedTypeElement extends TypeElement { - readonly kind: SyntaxKind.NotEmittedTypeElement; + export class NotEmittedTypeElement extends Node implements TypeElement { + _typeElementBrand: any; + _declarationBrand: any; + readonly ast: AstNotEmittedTypeElement; } /** * A list of comma-separated expressions. This node is only created by transformations. */ - interface CommaListExpression extends Expression { - readonly kind: SyntaxKind.CommaListExpression; - readonly elements: NodeArray; + export class CommaListExpression extends Node implements Expression { + _expressionBrand: any; + readonly ast: AstCommaListExpression; + get elements(): NodeArray; } - interface EmptyStatement extends Statement { - readonly kind: SyntaxKind.EmptyStatement; + export class EmptyStatement extends Node implements Statement, JSDocContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstEmptyStatement; } - interface DebuggerStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.DebuggerStatement; + export class DebuggerStatement extends Node implements Statement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstDebuggerStatement; } - interface MissingDeclaration extends DeclarationStatement, PrimaryExpression { - readonly kind: SyntaxKind.MissingDeclaration; - readonly name?: Identifier | undefined; + export class MissingDeclaration extends Node implements DeclarationStatement { + _declarationBrand: any; + _statementBrand: any; + _jsdocContainerBrand: any; + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstMissingDeclaration; + get name(): Identifier | undefined; + get modifiers(): NodeArray | undefined; } - type BlockLike = SourceFile | Block | ModuleBlock | CaseOrDefaultClause; - interface Block extends Statement, LocalsContainer { - readonly kind: SyntaxKind.Block; - readonly statements: NodeArray; + export type BlockLike = SourceFile | Block | ModuleBlock | CaseOrDefaultClause; + export class Block extends Node implements Statement, LocalsContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + readonly ast: AstBlock; + get statements(): NodeArray; } - interface VariableStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.VariableStatement; - readonly modifiers?: NodeArray | undefined; - readonly declarationList: VariableDeclarationList; + export class VariableStatement extends Node implements Statement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstVariableStatement; + get modifiers(): NodeArray | undefined; + get declarationList(): VariableDeclarationList; } - interface ExpressionStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.ExpressionStatement; - readonly expression: Expression; + export class ExpressionStatement extends Node implements Statement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstExpressionStatement; + get expression(): Expression; } - interface IfStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.IfStatement; - readonly expression: Expression; - readonly thenStatement: Statement; - readonly elseStatement?: Statement | undefined; + export class IfStatement extends Node implements Statement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstIfStatement; + get expression(): Expression; + get thenStatement(): Statement; + get elseStatement(): Statement | undefined; } - interface IterationStatement extends Statement { + export interface IterationStatement extends Statement { readonly statement: Statement; } - interface DoStatement extends IterationStatement, FlowContainer { - readonly kind: SyntaxKind.DoStatement; - readonly expression: Expression; - } - interface WhileStatement extends IterationStatement, FlowContainer { - readonly kind: SyntaxKind.WhileStatement; - readonly expression: Expression; - } - type ForInitializer = VariableDeclarationList | Expression; - interface ForStatement extends IterationStatement, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.ForStatement; - readonly initializer?: ForInitializer | undefined; - readonly condition?: Expression | undefined; - readonly incrementor?: Expression | undefined; - } - type ForInOrOfStatement = ForInStatement | ForOfStatement; - interface ForInStatement extends IterationStatement, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.ForInStatement; - readonly initializer: ForInitializer; - readonly expression: Expression; - } - interface ForOfStatement extends IterationStatement, LocalsContainer, FlowContainer { - readonly kind: SyntaxKind.ForOfStatement; - readonly awaitModifier?: AwaitKeyword | undefined; - readonly initializer: ForInitializer; - readonly expression: Expression; - } - interface BreakStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.BreakStatement; - readonly label?: Identifier | undefined; - } - interface ContinueStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.ContinueStatement; - readonly label?: Identifier | undefined; - } - type BreakOrContinueStatement = BreakStatement | ContinueStatement; - interface ReturnStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.ReturnStatement; - readonly expression?: Expression | undefined; - } - interface WithStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.WithStatement; - readonly expression: Expression; - readonly statement: Statement; + export class DoStatement extends Node implements IterationStatement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstDoStatement; + get statement(): Statement; + get expression(): Expression; } - interface SwitchStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.SwitchStatement; - readonly expression: Expression; - readonly caseBlock: CaseBlock; - possiblyExhaustive?: boolean | undefined; - } - interface CaseBlock extends Node, LocalsContainer { - readonly kind: SyntaxKind.CaseBlock; - readonly parent: SwitchStatement; - readonly clauses: NodeArray; - } - interface CaseClause extends Node, JSDocContainer { - readonly kind: SyntaxKind.CaseClause; - readonly parent: CaseBlock; - readonly expression: Expression; - readonly statements: NodeArray; - } - interface DefaultClause extends Node { - readonly kind: SyntaxKind.DefaultClause; - readonly parent: CaseBlock; - readonly statements: NodeArray; - } - type CaseOrDefaultClause = CaseClause | DefaultClause; - interface LabeledStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.LabeledStatement; - readonly label: Identifier; - readonly statement: Statement; + export class WhileStatement extends Node implements IterationStatement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstWhileStatement; + get expression(): Expression; + get statement(): Statement; + } + export type ForInitializer = VariableDeclarationList | Expression; + export class ForStatement extends Node implements IterationStatement, LocalsContainer, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstForStatement; + get initializer(): ForInitializer | undefined; + get condition(): Expression | undefined; + get incrementor(): Expression | undefined; + get statement(): Statement; + } + export type ForInOrOfStatement = ForInStatement | ForOfStatement; + export class ForInStatement extends Node implements IterationStatement, LocalsContainer, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstForInStatement; + get initializer(): ForInitializer; + get expression(): Expression; + get statement(): Statement; } - interface ThrowStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.ThrowStatement; - readonly expression: Expression; - } - interface TryStatement extends Statement, FlowContainer { - readonly kind: SyntaxKind.TryStatement; - readonly tryBlock: Block; - readonly catchClause?: CatchClause | undefined; - readonly finallyBlock?: Block | undefined; - } - interface CatchClause extends Node, LocalsContainer { - readonly kind: SyntaxKind.CatchClause; - readonly parent: TryStatement; - readonly variableDeclaration?: VariableDeclaration | undefined; - readonly block: Block; - } - type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode; - type DeclarationWithTypeParameters = DeclarationWithTypeParameterChildren | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; - type DeclarationWithTypeParameterChildren = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; - interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { + export class ForOfStatement extends Node implements IterationStatement, LocalsContainer, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstForOfStatement; + get awaitModifier(): AwaitKeyword | undefined; + get initializer(): ForInitializer; + get expression(): Expression; + get statement(): Statement; + } + export class BreakStatement extends Node implements Statement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstBreakStatement; + get label(): Identifier | undefined; + } + export class ContinueStatement extends Node implements Statement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstContinueStatement; + get label(): Identifier | undefined; + } + export type BreakOrContinueStatement = BreakStatement | ContinueStatement; + export class ReturnStatement extends Node implements Statement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstReturnStatement; + get expression(): Expression | undefined; + } + export class WithStatement extends Node implements Statement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstWithStatement; + get expression(): Expression; + get statement(): Statement; + } + export class SwitchStatement extends Node implements Statement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstSwitchStatement; + get expression(): Expression; + get caseBlock(): CaseBlock; + get possiblyExhaustive(): boolean | undefined; + } + export class CaseBlock extends Node implements LocalsContainer { + _localsContainerBrand: any; + readonly ast: AstCaseBlock; + get parent(): SwitchStatement; + get clauses(): NodeArray; + } + export class CaseClause extends Node implements JSDocContainer { + _jsdocContainerBrand: any; + readonly ast: AstCaseClause; + get parent(): CaseBlock; + get expression(): Expression; + get statements(): NodeArray; + } + export class DefaultClause extends Node { + readonly ast: AstDefaultClause; + get parent(): CaseBlock; + get statements(): NodeArray; + } + export type CaseOrDefaultClause = CaseClause | DefaultClause; + export class LabeledStatement extends Node implements Statement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstLabeledStatement; + get label(): Identifier; + get statement(): Statement; + } + export class ThrowStatement extends Node implements Statement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstThrowStatement; + get expression(): Expression; + } + export class TryStatement extends Node implements Statement, FlowContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + _flowContainerBrand: any; + readonly ast: AstTryStatement; + get tryBlock(): Block; + get catchClause(): CatchClause | undefined; + get finallyBlock(): Block | undefined; + } + export class CatchClause extends Node implements LocalsContainer { + _localsContainerBrand: any; + readonly ast: AstCatchClause; + get parent(): TryStatement; + get variableDeclaration(): VariableDeclaration | undefined; + get block(): Block; + } + export type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode; + export type DeclarationWithTypeParameters = DeclarationWithTypeParameterChildren | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; + export type DeclarationWithTypeParameterChildren = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; + export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { + readonly ast: AstNode; readonly kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; readonly name?: Identifier | undefined; readonly typeParameters?: NodeArray | undefined; readonly heritageClauses?: NodeArray | undefined; readonly members: NodeArray; } - interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatement { - readonly kind: SyntaxKind.ClassDeclaration; - readonly modifiers?: NodeArray | undefined; + export class ClassDeclaration extends Node implements ClassLikeDeclarationBase, DeclarationStatement { + _declarationBrand: any; + _statementBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstClassDeclaration; + get modifiers(): NodeArray | undefined; + get name(): Identifier | undefined; + get typeParameters(): NodeArray | undefined; + get heritageClauses(): NodeArray | undefined; + get members(): NodeArray; + } + export class ClassExpression extends Node implements ClassLikeDeclarationBase, PrimaryExpression { + _declarationBrand: any; + _jsdocContainerBrand: any; + _primaryExpressionBrand: any; + _memberExpressionBrand: any; + _leftHandSideExpressionBrand: any; + _updateExpressionBrand: any; + _unaryExpressionBrand: any; + _expressionBrand: any; + readonly ast: AstClassExpression; + get modifiers(): NodeArray | undefined; /** May be undefined in `export default class { ... }`. */ - readonly name?: Identifier | undefined; + get name(): Identifier | undefined; + get typeParameters(): NodeArray | undefined; + get heritageClauses(): NodeArray | undefined; + get members(): NodeArray; } - interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpression { - readonly kind: SyntaxKind.ClassExpression; - readonly modifiers?: NodeArray | undefined; - } - type ClassLikeDeclaration = ClassDeclaration | ClassExpression; - interface ClassElement extends NamedDeclaration { + export type ClassLikeDeclaration = ClassDeclaration | ClassExpression; + export interface ClassElement extends Declaration { _classElementBrand: any; + readonly ast: AstClassElement; readonly name?: PropertyName | undefined; } - interface TypeElement extends NamedDeclaration { + export interface TypeElement extends Declaration { _typeElementBrand: any; + readonly ast: AstTypeElement; readonly name?: PropertyName | undefined; readonly questionToken?: QuestionToken | undefined; } - interface InterfaceDeclaration extends DeclarationStatement, JSDocContainer { - readonly kind: SyntaxKind.InterfaceDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: Identifier; - readonly typeParameters?: NodeArray | undefined; - readonly heritageClauses?: NodeArray | undefined; - readonly members: NodeArray; - } - interface HeritageClause extends Node { - readonly kind: SyntaxKind.HeritageClause; - readonly parent: InterfaceDeclaration | ClassLikeDeclaration; - readonly token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; - readonly types: NodeArray; - } - interface TypeAliasDeclaration extends DeclarationStatement, JSDocContainer, LocalsContainer { - readonly kind: SyntaxKind.TypeAliasDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: Identifier; - readonly typeParameters?: NodeArray | undefined; - readonly type: TypeNode; + export class InterfaceDeclaration extends Node implements DeclarationStatement, JSDocContainer { + _declarationBrand: any; + _statementBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstInterfaceDeclaration; + get modifiers(): NodeArray | undefined; + get name(): Identifier; + get typeParameters(): NodeArray | undefined; + get heritageClauses(): NodeArray | undefined; + get members(): NodeArray; + } + export class HeritageClause extends Node { + readonly ast: AstHeritageClause; + get parent(): InterfaceDeclaration | ClassLikeDeclaration; + get token(): SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; + get types(): NodeArray; + } + export class TypeAliasDeclaration extends Node implements DeclarationStatement, JSDocContainer, LocalsContainer { + _declarationBrand: any; + _statementBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + readonly ast: AstTypeAliasDeclaration; + get modifiers(): NodeArray | undefined; + get name(): Identifier; + get typeParameters(): NodeArray | undefined; + get type(): TypeNode; } - interface EnumMember extends NamedDeclaration, JSDocContainer { - readonly kind: SyntaxKind.EnumMember; - readonly parent: EnumDeclaration; - readonly name: PropertyName; - readonly initializer?: Expression | undefined; + export class EnumMember extends Node implements NamedDeclaration, JSDocContainer { + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstEnumMember; + get parent(): EnumDeclaration; + get name(): PropertyName; + get initializer(): Expression | undefined; } - interface EnumDeclaration extends DeclarationStatement, JSDocContainer { - readonly kind: SyntaxKind.EnumDeclaration; - readonly modifiers?: NodeArray | undefined; - readonly name: Identifier; - readonly members: NodeArray; - } - type ModuleName = Identifier | StringLiteral; - type ModuleBody = NamespaceBody | JSDocNamespaceBody; - interface ModuleDeclaration extends DeclarationStatement, JSDocContainer, LocalsContainer { - readonly kind: SyntaxKind.ModuleDeclaration; - readonly parent: ModuleBody | SourceFile; - readonly modifiers?: NodeArray | undefined; - readonly name: ModuleName; - readonly body?: ModuleBody | JSDocNamespaceDeclaration | undefined; - } - type NamespaceBody = ModuleBlock | NamespaceDeclaration; - interface NamespaceDeclaration extends ModuleDeclaration { + export class EnumDeclaration extends Node implements DeclarationStatement, JSDocContainer { + _declarationBrand: any; + _statementBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstEnumDeclaration; + get modifiers(): NodeArray | undefined; + get name(): Identifier; + get members(): NodeArray; + } + export type ModuleName = Identifier | StringLiteral; + export type ModuleBody = NamespaceBody | JSDocNamespaceBody; + export class ModuleDeclaration extends Node implements DeclarationStatement, JSDocContainer, LocalsContainer { + _declarationBrand: any; + _statementBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + readonly ast: AstModuleDeclaration; + get parent(): ModuleDeclaration | ModuleBlock | SourceFile; + get modifiers(): NodeArray | undefined; + get name(): ModuleName; + get body(): ModuleBody | JSDocNamespaceDeclaration | undefined; + } + export type NamespaceBody = ModuleBlock | NamespaceDeclaration; + export interface NamespaceDeclaration extends ModuleDeclaration { + readonly ast: AstNamespaceDeclaration; + readonly data: AstNamespaceDeclarationData; readonly name: Identifier; readonly body: NamespaceBody; } - type JSDocNamespaceBody = Identifier | JSDocNamespaceDeclaration; - interface JSDocNamespaceDeclaration extends ModuleDeclaration { + export type JSDocNamespaceBody = Identifier | JSDocNamespaceDeclaration; + export interface JSDocNamespaceDeclaration extends ModuleDeclaration { + readonly ast: AstJSDocNamespaceDeclaration; + readonly data: AstJSDocNamespaceDeclarationData; readonly name: Identifier; - readonly body?: JSDocNamespaceBody | undefined; + readonly body: JSDocNamespaceBody | undefined; } - interface ModuleBlock extends Node, Statement { - readonly kind: SyntaxKind.ModuleBlock; - readonly parent: ModuleDeclaration; - readonly statements: NodeArray; + export class ModuleBlock extends Node implements Statement, JSDocContainer { + _statementBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstModuleBlock; + get parent(): ModuleDeclaration; + get statements(): NodeArray; } - type ModuleReference = EntityName | ExternalModuleReference; + export type ModuleReference = EntityName | ExternalModuleReference; /** * One of: * - import x = require("mod"); * - import x = M.x; */ - interface ImportEqualsDeclaration extends DeclarationStatement, JSDocContainer { - readonly kind: SyntaxKind.ImportEqualsDeclaration; - readonly parent: SourceFile | ModuleBlock; - readonly modifiers?: NodeArray | undefined; - readonly name: Identifier; - readonly isTypeOnly: boolean; - readonly moduleReference: ModuleReference; - } - interface ExternalModuleReference extends Node { - readonly kind: SyntaxKind.ExternalModuleReference; - readonly parent: ImportEqualsDeclaration; - readonly expression: Expression; - } - interface ImportDeclaration extends Statement { - readonly kind: SyntaxKind.ImportDeclaration; - readonly parent: SourceFile | ModuleBlock; - readonly modifiers?: NodeArray | undefined; - readonly importClause?: ImportClause | undefined; + export class ImportEqualsDeclaration extends Node implements DeclarationStatement, JSDocContainer { + _declarationBrand: any; + _statementBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstImportEqualsDeclaration; + get parent(): ModuleBlock | SourceFile; + get modifiers(): NodeArray | undefined; + get name(): Identifier; + get isTypeOnly(): boolean; + /** + * 'EntityName' for an internal module reference, 'ExternalModuleReference' for an external module reference. + */ + get moduleReference(): ModuleReference; + } + export class ExternalModuleReference extends Node { + readonly ast: AstExternalModuleReference; + get parent(): ImportEqualsDeclaration; + get expression(): Expression; + } + export class ImportDeclaration extends Node implements Declaration, JSDocContainer { + _declarationBrand: any; + _statementBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstImportDeclaration; + get parent(): ModuleBlock | SourceFile; + get modifiers(): NodeArray | undefined; + get importClause(): ImportClause | undefined; /** If this is not a StringLiteral it will be a grammar error. */ - readonly moduleSpecifier: Expression; - /** @deprecated */ readonly assertClause?: AssertClause | undefined; - readonly attributes?: ImportAttributes | undefined; - } - type NamedImportBindings = NamespaceImport | NamedImports; - type NamedExportBindings = NamespaceExport | NamedExports; - interface ImportClause extends NamedDeclaration { - readonly kind: SyntaxKind.ImportClause; - readonly parent: ImportDeclaration | JSDocImportTag; - readonly isTypeOnly: boolean; - readonly name?: Identifier | undefined; - readonly namedBindings?: NamedImportBindings | undefined; + get moduleSpecifier(): Expression; + /** @deprecated */ + get assertClause(): ImportAttributes | undefined; + get attributes(): ImportAttributes | undefined; + } + export type NamedImportBindings = NamespaceImport | NamedImports; + export type NamedExportBindings = NamespaceExport | NamedExports; + export class ImportClause extends Node implements NamedDeclaration { + _declarationBrand: any; + readonly ast: AstImportClause; + get parent(): ImportDeclaration | JSDocImportTag; + get isTypeOnly(): boolean; + get name(): Identifier | undefined; + get namedBindings(): NamedImportBindings | undefined; } /** @deprecated */ - type AssertionKey = ImportAttributeName; + export type AssertionKey = ImportAttributeName; /** @deprecated */ - interface AssertEntry extends ImportAttribute { + export interface AssertEntry extends ImportAttribute { } /** @deprecated */ - interface AssertClause extends ImportAttributes { - } - type ImportAttributeName = Identifier | StringLiteral; - interface ImportAttribute extends Node { - readonly kind: SyntaxKind.ImportAttribute; - readonly parent: ImportAttributes; - readonly name: ImportAttributeName; - readonly value: Expression; - } - interface ImportAttributes extends Node { - readonly kind: SyntaxKind.ImportAttributes; - readonly token: SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword; - readonly parent: ImportDeclaration | ExportDeclaration; - readonly elements: NodeArray; - readonly multiLine?: boolean | undefined; - } - interface NamespaceImport extends NamedDeclaration { - readonly kind: SyntaxKind.NamespaceImport; - readonly parent: ImportClause; - readonly name: Identifier; + export interface AssertClause extends ImportAttributes { + } + export type ImportAttributeName = Identifier | StringLiteral; + export class ImportAttribute extends Node { + readonly ast: AstImportAttribute; + get parent(): ImportAttributes; + get name(): ImportAttributeName; + get value(): Expression; + } + export class ImportAttributes extends Node { + readonly ast: AstImportAttributes; + get parent(): ImportDeclaration | ExportDeclaration; + get token(): SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword; + get elements(): NodeArray; + get multiLine(): boolean | undefined; + } + export class NamespaceImport extends Node implements NamedDeclaration { + _declarationBrand: any; + readonly ast: AstNamespaceImport; + get parent(): ImportClause; + get name(): Identifier; } - interface NamespaceExport extends NamedDeclaration { - readonly kind: SyntaxKind.NamespaceExport; - readonly parent: ExportDeclaration; - readonly name: ModuleExportName; + export class NamespaceExport extends Node implements NamedDeclaration { + _declarationBrand: any; + readonly ast: AstNamespaceExport; + get parent(): ExportDeclaration; + get name(): ModuleExportName; } - interface NamespaceExportDeclaration extends DeclarationStatement, JSDocContainer { - readonly kind: SyntaxKind.NamespaceExportDeclaration; - readonly name: Identifier; + export class NamespaceExportDeclaration extends Node implements DeclarationStatement, JSDocContainer { + _declarationBrand: any; + _statementBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstNamespaceExportDeclaration; + get name(): Identifier; } - interface ExportDeclaration extends DeclarationStatement, JSDocContainer { - readonly kind: SyntaxKind.ExportDeclaration; - readonly parent: SourceFile | ModuleBlock; - readonly modifiers?: NodeArray | undefined; - readonly isTypeOnly: boolean; - /** Will not be assigned in the case of `export * from "foo";` */ - readonly exportClause?: NamedExportBindings | undefined; - /** If this is not a StringLiteral it will be a grammar error. */ - readonly moduleSpecifier?: Expression | undefined; - /** @deprecated */ readonly assertClause?: AssertClause | undefined; - readonly attributes?: ImportAttributes | undefined; - } - interface NamedImports extends Node { - readonly kind: SyntaxKind.NamedImports; - readonly parent: ImportClause; - readonly elements: NodeArray; - } - interface NamedExports extends Node { - readonly kind: SyntaxKind.NamedExports; - readonly parent: ExportDeclaration; - readonly elements: NodeArray; - } - type NamedImportsOrExports = NamedImports | NamedExports; - interface ImportSpecifier extends NamedDeclaration { - readonly kind: SyntaxKind.ImportSpecifier; - readonly parent: NamedImports; - readonly propertyName?: ModuleExportName | undefined; - readonly name: Identifier; - readonly isTypeOnly: boolean; - } - interface ExportSpecifier extends NamedDeclaration, JSDocContainer { - readonly kind: SyntaxKind.ExportSpecifier; - readonly parent: NamedExports; - readonly isTypeOnly: boolean; - readonly propertyName?: ModuleExportName | undefined; - readonly name: ModuleExportName; - } - type ModuleExportName = Identifier | StringLiteral; - type ImportOrExportSpecifier = ImportSpecifier | ExportSpecifier; - type TypeOnlyCompatibleAliasDeclaration = ImportClause | ImportEqualsDeclaration | NamespaceImport | ImportOrExportSpecifier | ExportDeclaration | NamespaceExport; - type TypeOnlyImportDeclaration = + export class ExportDeclaration extends Node implements DeclarationStatement, JSDocContainer { + _declarationBrand: any; + _statementBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstExportDeclaration; + get parent(): SourceFile | ModuleBlock; + get modifiers(): NodeArray | undefined; + get isTypeOnly(): boolean; + get exportClause(): NamedExportBindings | undefined; + get moduleSpecifier(): Expression | undefined; + /** @deprecated */ + get assertClause(): ImportAttributes | undefined; + get attributes(): ImportAttributes | undefined; + } + export class NamedImports extends Node { + readonly ast: AstNamedImports; + get parent(): ImportClause; + get elements(): NodeArray; + } + export class NamedExports extends Node { + readonly ast: AstNamedExports; + get parent(): ExportDeclaration; + get elements(): NodeArray; + } + export type NamedImportsOrExports = NamedImports | NamedExports; + export class ImportSpecifier extends Node implements NamedDeclaration { + _declarationBrand: any; + readonly ast: AstImportSpecifier; + get parent(): NamedImports; + get isTypeOnly(): boolean; + /** + * Name preceding "as" keyword (or undefined when "as" is absent) + */ + get propertyName(): ModuleExportName | undefined; + /** + * Declared name + */ + get name(): Identifier; + } + export class ExportSpecifier extends Node implements NamedDeclaration, JSDocContainer { + _declarationBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstExportSpecifier; + get parent(): NamedExports; + get isTypeOnly(): boolean; + /** + * Name preceding "as" keyword (or undefined when "as" is absent) + */ + get propertyName(): ModuleExportName | undefined; + /** + * Declared name + */ + get name(): ModuleExportName; + } + export type ModuleExportName = Identifier | StringLiteral; + export type ImportOrExportSpecifier = ImportSpecifier | ExportSpecifier; + export type TypeOnlyCompatibleAliasDeclaration = ImportClause | ImportEqualsDeclaration | NamespaceImport | ImportOrExportSpecifier | ExportDeclaration | NamespaceExport; + export type TypeOnlyImportDeclaration = | ImportClause & { readonly isTypeOnly: true; readonly name: Identifier; @@ -5569,7 +6312,7 @@ declare namespace ts { }; }; }); - type TypeOnlyExportDeclaration = + export type TypeOnlyExportDeclaration = | ExportSpecifier & ({ readonly isTypeOnly: true; @@ -5590,215 +6333,260 @@ declare namespace ts { readonly moduleSpecifier: Expression; }; }; - type TypeOnlyAliasDeclaration = TypeOnlyImportDeclaration | TypeOnlyExportDeclaration; + export type TypeOnlyAliasDeclaration = TypeOnlyImportDeclaration | TypeOnlyExportDeclaration; /** * This is either an `export =` or an `export default` declaration. * Unless `isExportEquals` is set, this node was parsed as an `export default`. */ - interface ExportAssignment extends DeclarationStatement, JSDocContainer { - readonly kind: SyntaxKind.ExportAssignment; - readonly parent: SourceFile; - readonly modifiers?: NodeArray | undefined; - readonly isExportEquals?: boolean | undefined; - readonly expression: Expression; - } - interface FileReference extends TextRange { + export class ExportAssignment extends Node implements DeclarationStatement, JSDocContainer { + _declarationBrand: any; + _statementBrand: any; + _jsdocContainerBrand: any; + readonly ast: AstExportAssignment; + get parent(): SourceFile; + get modifiers(): NodeArray | undefined; + get isExportEquals(): boolean | undefined; + get expression(): Expression; + } + export interface FileReference extends TextRange { fileName: string; resolutionMode?: ResolutionMode; preserve?: boolean; } - interface CheckJsDirective extends TextRange { + export interface CheckJsDirective extends TextRange { enabled: boolean; } - type CommentKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia; - interface CommentRange extends TextRange { + export type CommentKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia; + export interface CommentRange extends TextRange { hasTrailingNewLine?: boolean; kind: CommentKind; } - interface SynthesizedComment extends CommentRange { + export interface SynthesizedComment extends CommentRange { text: string; pos: -1; end: -1; hasLeadingNewline?: boolean; } - interface JSDocTypeExpression extends TypeNode { - readonly kind: SyntaxKind.JSDocTypeExpression; - readonly type: TypeNode; + export class JSDocTypeExpression extends Node implements TypeNode { + _typeNodeBrand: any; + readonly ast: AstJSDocTypeExpression; + get type(): TypeNode; } - interface JSDocNameReference extends Node { - readonly kind: SyntaxKind.JSDocNameReference; - readonly name: EntityName | JSDocMemberName; + export class JSDocNameReference extends Node { + readonly ast: AstJSDocNameReference; + get name(): EntityName | JSDocMemberName; } /** Class#method reference in JSDoc */ - interface JSDocMemberName extends Node { - readonly kind: SyntaxKind.JSDocMemberName; - readonly left: EntityName | JSDocMemberName; - readonly right: Identifier; + export class JSDocMemberName extends Node { + readonly ast: AstJSDocMemberName; + get left(): EntityName | JSDocMemberName; + get right(): Identifier; } - interface JSDocType extends TypeNode { + export interface JSDocType extends TypeNode { _jsDocTypeBrand: any; } - interface JSDocAllType extends JSDocType { - readonly kind: SyntaxKind.JSDocAllType; - } - interface JSDocUnknownType extends JSDocType { - readonly kind: SyntaxKind.JSDocUnknownType; - } - interface JSDocNonNullableType extends JSDocType { - readonly kind: SyntaxKind.JSDocNonNullableType; - readonly type: TypeNode; - readonly postfix: boolean; - } - interface JSDocNullableType extends JSDocType { - readonly kind: SyntaxKind.JSDocNullableType; - readonly type: TypeNode; - readonly postfix: boolean; - } - interface JSDocOptionalType extends JSDocType { - readonly kind: SyntaxKind.JSDocOptionalType; - readonly type: TypeNode; - } - interface JSDocFunctionType extends JSDocType, SignatureDeclarationBase, LocalsContainer { - readonly kind: SyntaxKind.JSDocFunctionType; - } - interface JSDocVariadicType extends JSDocType { - readonly kind: SyntaxKind.JSDocVariadicType; - readonly type: TypeNode; + export class JSDocAllType extends Node implements JSDocType { + _jsDocTypeBrand: any; + _typeNodeBrand: any; + readonly ast: AstJSDocAllType; } - interface JSDocNamepathType extends JSDocType { - readonly kind: SyntaxKind.JSDocNamepathType; - readonly type: TypeNode; + export class JSDocUnknownType extends Node implements JSDocType { + _jsDocTypeBrand: any; + _typeNodeBrand: any; + readonly ast: AstJSDocUnknownType; } - type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; - interface JSDoc extends Node { - readonly kind: SyntaxKind.JSDoc; - readonly parent: HasJSDoc; - readonly tags?: NodeArray | undefined; - readonly comment?: string | NodeArray | undefined; - } - interface JSDocTag extends Node { - readonly parent: JSDoc | JSDocTypeLiteral; - readonly tagName: Identifier; - readonly comment?: string | NodeArray | undefined; - } - interface JSDocLink extends Node { - readonly kind: SyntaxKind.JSDocLink; - readonly name?: EntityName | JSDocMemberName | undefined; - text: string; + export class JSDocNonNullableType extends Node implements JSDocType { + _jsDocTypeBrand: any; + _typeNodeBrand: any; + readonly ast: AstJSDocNonNullableType; + get type(): TypeNode; + get postfix(): boolean; } - interface JSDocLinkCode extends Node { - readonly kind: SyntaxKind.JSDocLinkCode; - readonly name?: EntityName | JSDocMemberName | undefined; - text: string; + export class JSDocNullableType extends Node implements JSDocType { + _jsDocTypeBrand: any; + _typeNodeBrand: any; + readonly ast: AstJSDocNullableType; + get type(): TypeNode; + get postfix(): boolean; } - interface JSDocLinkPlain extends Node { - readonly kind: SyntaxKind.JSDocLinkPlain; - readonly name?: EntityName | JSDocMemberName | undefined; - text: string; + export class JSDocOptionalType extends Node implements JSDocType { + _jsDocTypeBrand: any; + _typeNodeBrand: any; + readonly ast: AstJSDocOptionalType; + get type(): TypeNode; } - type JSDocComment = JSDocText | JSDocLink | JSDocLinkCode | JSDocLinkPlain; - interface JSDocText extends Node { - readonly kind: SyntaxKind.JSDocText; - text: string; + export class JSDocFunctionType extends Node implements JSDocType, SignatureDeclarationBase, LocalsContainer { + _signatureDeclarationBrand: any; + _jsDocTypeBrand: any; + _typeNodeBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + readonly ast: AstJSDocFunctionType; + get typeParameters(): NodeArray | undefined; + get parameters(): NodeArray; + get type(): TypeNode | undefined; + get typeArguments(): NodeArray | undefined; } - interface JSDocUnknownTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocTag; + export class JSDocVariadicType extends Node implements JSDocType { + _jsDocTypeBrand: any; + _typeNodeBrand: any; + readonly ast: AstJSDocVariadicType; + get type(): TypeNode; } - interface JSDocClassReference extends ExpressionWithTypeArguments { + export class JSDocNamepathType extends Node implements JSDocType { + _jsDocTypeBrand: any; + _typeNodeBrand: any; + readonly ast: AstJSDocNamepathType; + get type(): TypeNode; + } + export type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; + export class JSDoc extends Node { + readonly ast: AstJSDoc; + get parent(): HasJSDoc; + get tags(): NodeArray | undefined; + get comment(): string | NodeArray | undefined; + } + export class JSDocTag extends Node { + readonly ast: AstBaseJSDocTag; + get parent(): JSDoc | JSDocTypeLiteral; + get tagName(): Identifier; + get comment(): string | NodeArray | undefined; + } + export class JSDocLink extends Node { + readonly ast: AstJSDocLink; + get name(): EntityName | JSDocMemberName | undefined; + get text(): string; + } + export class JSDocLinkCode extends Node { + readonly ast: AstJSDocLinkCode; + get name(): EntityName | JSDocMemberName | undefined; + get text(): string; + } + export class JSDocLinkPlain extends Node { + readonly ast: AstJSDocLinkPlain; + get name(): EntityName | JSDocMemberName | undefined; + get text(): string; + } + export type JSDocComment = JSDocText | JSDocLink | JSDocLinkCode | JSDocLinkPlain; + export class JSDocText extends Node { + readonly ast: AstJSDocText; + get text(): string; + } + export class JSDocUnknownTag extends JSDocTag { + readonly ast: AstJSDocUnknownTag; + } + export interface JSDocClassReference extends ExpressionWithTypeArguments { + readonly ast: AstJSDocClassReference; + readonly data: AstJSDocClassReferenceData; readonly expression: Identifier | PropertyAccessEntityNameExpression; } /** * Note that `@extends` is a synonym of `@augments`. * Both tags are represented by this interface. */ - interface JSDocAugmentsTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocAugmentsTag; - readonly class: JSDocClassReference; - } - interface JSDocImplementsTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocImplementsTag; - readonly class: JSDocClassReference; - } - interface JSDocAuthorTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocAuthorTag; - } - interface JSDocDeprecatedTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocDeprecatedTag; - } - interface JSDocClassTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocClassTag; + export class JSDocAugmentsTag extends JSDocTag { + readonly ast: AstJSDocAugmentsTag; + get class(): JSDocClassReference; } - interface JSDocPublicTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocPublicTag; + export class JSDocImplementsTag extends JSDocTag { + readonly ast: AstJSDocImplementsTag; + get class(): JSDocClassReference; } - interface JSDocPrivateTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocPrivateTag; + export class JSDocAuthorTag extends JSDocTag { + readonly ast: AstJSDocAuthorTag; } - interface JSDocProtectedTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocProtectedTag; + export class JSDocDeprecatedTag extends JSDocTag { + readonly ast: AstJSDocDeprecatedTag; } - interface JSDocReadonlyTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocReadonlyTag; + export class JSDocClassTag extends JSDocTag { + readonly ast: AstJSDocClassTag; } - interface JSDocOverrideTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocOverrideTag; + export class JSDocPublicTag extends JSDocTag { + readonly ast: AstJSDocPublicTag; } - interface JSDocEnumTag extends JSDocTag, Declaration, LocalsContainer { - readonly kind: SyntaxKind.JSDocEnumTag; - readonly parent: JSDoc; - readonly typeExpression: JSDocTypeExpression; - } - interface JSDocThisTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocThisTag; - readonly typeExpression: JSDocTypeExpression; + export class JSDocPrivateTag extends JSDocTag { + readonly ast: AstJSDocPrivateTag; } - interface JSDocTemplateTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocTemplateTag; - readonly constraint: JSDocTypeExpression | undefined; - readonly typeParameters: NodeArray; + export class JSDocProtectedTag extends JSDocTag { + readonly ast: AstJSDocProtectedTag; } - interface JSDocSeeTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocSeeTag; - readonly name?: JSDocNameReference | undefined; + export class JSDocReadonlyTag extends JSDocTag { + readonly ast: AstJSDocReadonlyTag; } - interface JSDocReturnTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocReturnTag; - readonly typeExpression?: JSDocTypeExpression | undefined; + export class JSDocOverrideTag extends JSDocTag { + readonly ast: AstJSDocOverrideTag; } - interface JSDocTypeTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocTypeTag; - readonly typeExpression: JSDocTypeExpression; + export class JSDocEnumTag extends JSDocTag implements Declaration, LocalsContainer { + _declarationBrand: any; + _localsContainerBrand: any; + readonly ast: AstJSDocEnumTag; + get parent(): JSDoc; + get typeExpression(): JSDocTypeExpression; } - interface JSDocTypedefTag extends JSDocTag, NamedDeclaration, LocalsContainer { - readonly kind: SyntaxKind.JSDocTypedefTag; - readonly parent: JSDoc; - readonly fullName?: JSDocNamespaceDeclaration | Identifier | undefined; - readonly name?: Identifier | undefined; - readonly typeExpression?: JSDocTypeExpression | JSDocTypeLiteral | undefined; + export class JSDocThisTag extends JSDocTag { + readonly ast: AstJSDocThisTag; + get typeExpression(): JSDocTypeExpression; } - interface JSDocCallbackTag extends JSDocTag, NamedDeclaration, LocalsContainer { - readonly kind: SyntaxKind.JSDocCallbackTag; - readonly parent: JSDoc; - readonly fullName?: JSDocNamespaceDeclaration | Identifier | undefined; - readonly name?: Identifier | undefined; - readonly typeExpression: JSDocSignature; + export class JSDocTemplateTag extends JSDocTag { + readonly ast: AstJSDocTemplateTag; + get constraint(): JSDocTypeExpression | undefined; + get typeParameters(): NodeArray; } - interface JSDocOverloadTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocOverloadTag; - readonly parent: JSDoc; - readonly typeExpression: JSDocSignature; + export class JSDocSeeTag extends JSDocTag { + readonly ast: AstJSDocSeeTag; + get name(): JSDocNameReference | undefined; } - interface JSDocThrowsTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocThrowsTag; - readonly typeExpression?: JSDocTypeExpression | undefined; + export class JSDocReturnTag extends JSDocTag { + readonly ast: AstJSDocReturnTag; + get typeExpression(): JSDocTypeExpression | undefined; } - interface JSDocSignature extends JSDocType, Declaration, JSDocContainer, LocalsContainer { - readonly kind: SyntaxKind.JSDocSignature; - readonly typeParameters?: readonly JSDocTemplateTag[] | undefined; - readonly parameters: readonly JSDocParameterTag[]; - readonly type: JSDocReturnTag | undefined; + export class JSDocTypeTag extends JSDocTag { + readonly ast: AstJSDocTypeTag; + get typeExpression(): JSDocTypeExpression; } - interface JSDocPropertyLikeTag extends JSDocTag, Declaration { + export class JSDocTypedefTag extends JSDocTag implements Declaration, LocalsContainer { + _declarationBrand: any; + _localsContainerBrand: any; + readonly ast: AstJSDocTypedefTag; + get parent(): JSDoc; + get fullName(): Identifier | JSDocNamespaceDeclaration | undefined; + get name(): Identifier | undefined; + get typeExpression(): JSDocTypeLiteral | JSDocTypeExpression | undefined; + } + export class JSDocCallbackTag extends JSDocTag implements Declaration, LocalsContainer { + _declarationBrand: any; + _localsContainerBrand: any; + readonly ast: AstJSDocCallbackTag; + get parent(): JSDoc; + get fullName(): Identifier | JSDocNamespaceDeclaration | undefined; + get name(): Identifier | undefined; + get typeExpression(): JSDocSignature; + } + export class JSDocOverloadTag extends JSDocTag { + readonly ast: AstJSDocOverloadTag; + get parent(): JSDoc; + get typeExpression(): JSDocSignature; + } + export class JSDocThrowsTag extends JSDocTag { + readonly ast: AstJSDocThrowsTag; + get typeExpression(): JSDocTypeExpression | undefined; + } + export class JSDocSignature extends Node implements JSDocType, Declaration, JSDocContainer, LocalsContainer { + _jsDocTypeBrand: any; + _typeNodeBrand: any; + _declarationBrand: any; + _jsdocContainerBrand: any; + _localsContainerBrand: any; + _signatureDeclarationBrand: any; + readonly ast: AstJSDocSignature; + get typeParameters(): NodeArray | undefined; + get parameters(): NodeArray; + get type(): JSDocReturnTag | undefined; + } + export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { + readonly ast: AstJSDocPropertyLikeTag; + readonly data: AstJSDocTagData & AstDeclarationData; readonly parent: JSDoc; readonly name: EntityName; readonly typeExpression?: JSDocTypeExpression | undefined; @@ -5806,61 +6594,80 @@ declare namespace ts { readonly isNameFirst: boolean; readonly isBracketed: boolean; } - interface JSDocPropertyTag extends JSDocPropertyLikeTag { - readonly kind: SyntaxKind.JSDocPropertyTag; + export class JSDocPropertyTag extends JSDocTag implements JSDocPropertyLikeTag, Declaration { + _declarationBrand: any; + readonly ast: AstJSDocPropertyTag; + get parent(): JSDoc; + get name(): Identifier | QualifiedName; + get typeExpression(): JSDocTypeExpression | undefined; + /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ + get isNameFirst(): boolean; + get isBracketed(): boolean; } - interface JSDocParameterTag extends JSDocPropertyLikeTag { - readonly kind: SyntaxKind.JSDocParameterTag; + export class JSDocParameterTag extends JSDocTag implements JSDocPropertyLikeTag { + _declarationBrand: any; + readonly ast: AstJSDocParameterTag; + get parent(): JSDoc; + get name(): Identifier | QualifiedName; + get typeExpression(): JSDocTypeExpression | undefined; + /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ + get isNameFirst(): boolean; + get isBracketed(): boolean; } - interface JSDocTypeLiteral extends JSDocType, Declaration { - readonly kind: SyntaxKind.JSDocTypeLiteral; - readonly jsDocPropertyTags?: readonly JSDocPropertyLikeTag[] | undefined; + export class JSDocTypeLiteral extends Node implements JSDocType, Declaration { + _jsDocTypeBrand: any; + _typeNodeBrand: any; + _declarationBrand: any; + readonly ast: AstJSDocTypeLiteral; + get jsDocPropertyTags(): NodeArray | undefined; /** If true, then this type literal represents an *array* of its type. */ - readonly isArrayType: boolean; + get isArrayType(): boolean; } - interface JSDocSatisfiesTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocSatisfiesTag; - readonly typeExpression: JSDocTypeExpression; + export class JSDocSatisfiesTag extends JSDocTag { + readonly ast: AstJSDocSatisfiesTag; + get typeExpression(): JSDocTypeExpression; } - interface JSDocImportTag extends JSDocTag { - readonly kind: SyntaxKind.JSDocImportTag; - readonly parent: JSDoc; - readonly importClause?: ImportClause | undefined; - readonly moduleSpecifier: Expression; - readonly attributes?: ImportAttributes | undefined; + export class JSDocImportTag extends JSDocTag { + readonly ast: AstJSDocImportTag; + get parent(): JSDoc; + get importClause(): ImportClause | undefined; + get moduleSpecifier(): Expression; + get attributes(): ImportAttributes | undefined; } - type FlowType = Type | IncompleteType; - interface IncompleteType { + export type FlowType = Type | IncompleteType; + export interface IncompleteType { flags: TypeFlags | 0; type: Type; } - interface AmdDependency { + export interface AmdDependency { path: string; name?: string; } /** * Subset of properties from SourceFile that are used in multiple utility functions */ - interface SourceFileLike { + export interface SourceFileLike { readonly text: string; } - interface SourceFileLike { + export interface SourceFileLike { getLineAndCharacterOfPosition(pos: number): LineAndCharacter; } - type ResolutionMode = ModuleKind.ESNext | ModuleKind.CommonJS | undefined; - interface SourceFile extends Declaration, LocalsContainer { - readonly kind: SyntaxKind.SourceFile; - readonly statements: NodeArray; - readonly endOfFileToken: Token; - fileName: string; - text: string; - amdDependencies: readonly AmdDependency[]; - moduleName?: string | undefined; - referencedFiles: readonly FileReference[]; - typeReferenceDirectives: readonly FileReference[]; - libReferenceDirectives: readonly FileReference[]; - languageVariant: LanguageVariant; - isDeclarationFile: boolean; + export type ResolutionMode = ModuleKind.ESNext | ModuleKind.CommonJS | undefined; + export class SourceFile extends Node implements Declaration, LocalsContainer, ReadonlyPragmaContext { + _declarationBrand: any; + _localsContainerBrand: any; + readonly ast: AstSourceFile; + get statements(): NodeArray; + get endOfFileToken(): EndOfFileToken; + get fileName(): string; + get text(): string; + get amdDependencies(): AmdDependency[]; + get moduleName(): string | undefined; + get referencedFiles(): readonly FileReference[]; + get typeReferenceDirectives(): readonly FileReference[]; + get libReferenceDirectives(): readonly FileReference[]; + get languageVariant(): LanguageVariant; + get isDeclarationFile(): boolean; /** * lib.d.ts should have a reference comment like * @@ -5869,8 +6676,8 @@ declare namespace ts { * If any other file has this comment, it signals not to include lib.d.ts * because this containing file is intended to act as a default library. */ - hasNoDefaultLib: boolean; - languageVersion: ScriptTarget; + get hasNoDefaultLib(): boolean; + get languageVersion(): ScriptTarget; /** * When `module` is `Node16` or `NodeNext`, this field controls whether the * source file in question is an ESNext-output-format file, or a CommonJS-output-format @@ -5888,40 +6695,73 @@ declare namespace ts { * of `node`). If so, this field will be unset and source files will be considered to be * CommonJS-output-format by the node module transformer and type checker, regardless of extension or context. */ - impliedNodeFormat?: ResolutionMode | undefined; - } - interface SourceFile { - getLineAndCharacterOfPosition(pos: number): LineAndCharacter; - getLineEndOfPosition(pos: number): number; + get impliedNodeFormat(): ResolutionMode; + update(newText: string, textChangeRange: TextChangeRange): SourceFile; + getLineAndCharacterOfPosition(position: number): LineAndCharacter; getLineStarts(): readonly number[]; getPositionOfLineAndCharacter(line: number, character: number): number; - update(newText: string, textChangeRange: TextChangeRange): SourceFile; + getLineEndOfPosition(pos: number): number; } - interface Bundle extends Node { - readonly kind: SyntaxKind.Bundle; - readonly sourceFiles: readonly SourceFile[]; + /** + * Represents an immutable snapshot of a script at a specified time.Once acquired, the + * snapshot is observably immutable. i.e. the same calls with the same parameters will return + * the same values. + */ + export interface IScriptSnapshot { + /** Gets a portion of the script snapshot specified by [start, end). */ + getText(start: number, end: number): string; + /** Gets the length of this script snapshot. */ + getLength(): number; + /** + * Gets the TextChangeRange that describe how the text changed between this text and + * an older version. This information is used by the incremental parser to determine + * what sections of the script need to be re-parsed. 'undefined' can be returned if the + * change range cannot be determined. However, in that case, incremental parsing will + * not happen and the entire document will be re - parsed. + */ + getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined; + /** Releases all resources held by this script snapshot */ + dispose?(): void; } - interface JsonSourceFile extends SourceFile { + export interface ReadonlyPragmaContext { + readonly languageVersion: ScriptTarget; + readonly referencedFiles: readonly FileReference[]; + readonly typeReferenceDirectives: readonly FileReference[]; + readonly libReferenceDirectives: readonly FileReference[]; + readonly amdDependencies: readonly AmdDependency[]; + readonly hasNoDefaultLib?: boolean | undefined; + } + export class Bundle extends Node { + readonly ast: AstBundle; + get sourceFiles(): readonly SourceFile[]; + } + export interface JsonSourceFile extends SourceFile { + readonly ast: AstJsonSourceFile; + readonly data: AstJsonSourceFileData; readonly statements: NodeArray; } - interface TsConfigSourceFile extends JsonSourceFile { - extendedSourceFiles?: string[]; + export interface TsConfigSourceFile extends JsonSourceFile { + extendedSourceFiles: string[] | undefined; } - interface JsonMinusNumericLiteral extends PrefixUnaryExpression { + export interface JsonMinusNumericLiteral extends PrefixUnaryExpression { + readonly ast: AstJsonMinusNumericLiteral; + readonly data: AstJsonMinusNumericLiteralData; readonly operator: SyntaxKind.MinusToken; readonly operand: NumericLiteral; } - type JsonObjectExpression = ObjectLiteralExpression | ArrayLiteralExpression | JsonMinusNumericLiteral | NumericLiteral | StringLiteral | BooleanLiteral | NullLiteral; - interface JsonObjectExpressionStatement extends ExpressionStatement { + export type JsonObjectExpression = ObjectLiteralExpression | ArrayLiteralExpression | JsonMinusNumericLiteral | NumericLiteral | StringLiteral | BooleanLiteral | NullLiteral; + export interface JsonObjectExpressionStatement extends ExpressionStatement { + readonly ast: AstJsonObjectExpressionStatement; + readonly data: AstJsonObjectExpressionStatementData; readonly expression: JsonObjectExpression; } - interface ScriptReferenceHost { + export interface ScriptReferenceHost { getCompilerOptions(): CompilerOptions; getSourceFile(fileName: string): SourceFile | undefined; getSourceFileByPath(path: Path): SourceFile | undefined; getCurrentDirectory(): string; } - interface ParseConfigHost extends ModuleResolutionHost { + export interface ParseConfigHost extends ModuleResolutionHost { useCaseSensitiveFileNames: boolean; readDirectory(rootDir: string, extensions: readonly string[], excludes: readonly string[] | undefined, includes: readonly string[], depth?: number): readonly string[]; /** @@ -5937,20 +6777,20 @@ declare namespace ts { * specified like "./blah" to an absolute path to an actual * tsconfig file, e.g. "/root/blah/tsconfig.json" */ - type ResolvedConfigFileName = string & { + export type ResolvedConfigFileName = string & { _isResolvedConfigFileName: never; }; - interface WriteFileCallbackData { + export interface WriteFileCallbackData { } - type WriteFileCallback = (fileName: string, text: string, writeByteOrderMark: boolean, onError?: (message: string) => void, sourceFiles?: readonly SourceFile[], data?: WriteFileCallbackData) => void; - class OperationCanceledException { + export type WriteFileCallback = (fileName: string, text: string, writeByteOrderMark: boolean, onError?: (message: string) => void, sourceFiles?: readonly SourceFile[], data?: WriteFileCallbackData) => void; + export class OperationCanceledException { } - interface CancellationToken { + export interface CancellationToken { isCancellationRequested(): boolean; /** @throws OperationCanceledException if isCancellationRequested is true */ throwIfCancellationRequested(): void; } - interface Program extends ScriptReferenceHost { + export interface Program extends ScriptReferenceHost { getCurrentDirectory(): string; /** * Get a list of root file names that were passed to a 'createProgram' @@ -6062,17 +6902,17 @@ declare namespace ts { getProjectReferences(): readonly ProjectReference[] | undefined; getResolvedProjectReferences(): readonly (ResolvedProjectReference | undefined)[] | undefined; } - interface ResolvedProjectReference { + export interface ResolvedProjectReference { commandLine: ParsedCommandLine; sourceFile: SourceFile; references?: readonly (ResolvedProjectReference | undefined)[]; } - type CustomTransformerFactory = (context: TransformationContext) => CustomTransformer; - interface CustomTransformer { + export type CustomTransformerFactory = (context: TransformationContext) => CustomTransformer; + export interface CustomTransformer { transformSourceFile(node: SourceFile): SourceFile; transformBundle(node: Bundle): Bundle; } - interface CustomTransformers { + export interface CustomTransformers { /** Custom transformers to evaluate before built-in .js transformations. */ before?: (TransformerFactory | CustomTransformerFactory)[]; /** Custom transformers to evaluate after built-in .js transformations. */ @@ -6080,7 +6920,7 @@ declare namespace ts { /** Custom transformers to evaluate after built-in .d.ts transformations. */ afterDeclarations?: (TransformerFactory | CustomTransformerFactory)[]; } - interface SourceMapSpan { + export interface SourceMapSpan { /** Line number in the .js file. */ emittedLine: number; /** Column number in the .js file. */ @@ -6095,20 +6935,20 @@ declare namespace ts { sourceIndex: number; } /** Return code used by getEmitOutput function to indicate status of the function */ - enum ExitStatus { + export enum ExitStatus { Success = 0, DiagnosticsPresent_OutputsSkipped = 1, DiagnosticsPresent_OutputsGenerated = 2, InvalidProject_OutputsSkipped = 3, ProjectReferenceCycle_OutputsSkipped = 4, } - interface EmitResult { + export interface EmitResult { emitSkipped: boolean; /** Contains declaration emit diagnostics */ diagnostics: readonly Diagnostic[]; emittedFiles?: string[]; } - interface TypeChecker { + export interface TypeChecker { getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getTypeOfSymbol(symbol: Symbol): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; @@ -6298,7 +7138,7 @@ declare namespace ts { */ runWithCancellationToken(token: CancellationToken, cb: (checker: TypeChecker) => T): T; } - enum NodeBuilderFlags { + export enum NodeBuilderFlags { None = 0, NoTruncation = 1, WriteArrayAsGenericType = 2, @@ -6331,7 +7171,7 @@ declare namespace ts { InTypeAlias = 8388608, InInitialEntityName = 16777216, } - enum TypeFormatFlags { + export enum TypeFormatFlags { None = 0, NoTruncation = 1, WriteArrayAsGenericType = 2, @@ -6357,49 +7197,49 @@ declare namespace ts { InTypeAlias = 8388608, NodeBuilderFlagsMask = 848330095, } - enum SymbolFormatFlags { + export enum SymbolFormatFlags { None = 0, WriteTypeParametersOrArguments = 1, UseOnlyExternalAliasing = 2, AllowAnyNodeKind = 4, UseAliasDefinedOutsideCurrentScope = 8, } - enum TypePredicateKind { + export enum TypePredicateKind { This = 0, Identifier = 1, AssertsThis = 2, AssertsIdentifier = 3, } - interface TypePredicateBase { + export interface TypePredicateBase { kind: TypePredicateKind; type: Type | undefined; } - interface ThisTypePredicate extends TypePredicateBase { + export interface ThisTypePredicate extends TypePredicateBase { kind: TypePredicateKind.This; parameterName: undefined; parameterIndex: undefined; type: Type; } - interface IdentifierTypePredicate extends TypePredicateBase { + export interface IdentifierTypePredicate extends TypePredicateBase { kind: TypePredicateKind.Identifier; parameterName: string; parameterIndex: number; type: Type; } - interface AssertsThisTypePredicate extends TypePredicateBase { + export interface AssertsThisTypePredicate extends TypePredicateBase { kind: TypePredicateKind.AssertsThis; parameterName: undefined; parameterIndex: undefined; type: Type | undefined; } - interface AssertsIdentifierTypePredicate extends TypePredicateBase { + export interface AssertsIdentifierTypePredicate extends TypePredicateBase { kind: TypePredicateKind.AssertsIdentifier; parameterName: string; parameterIndex: number; type: Type | undefined; } - type TypePredicate = ThisTypePredicate | IdentifierTypePredicate | AssertsThisTypePredicate | AssertsIdentifierTypePredicate; - enum SymbolFlags { + export type TypePredicate = ThisTypePredicate | IdentifierTypePredicate | AssertsThisTypePredicate | AssertsIdentifierTypePredicate; + export enum SymbolFlags { None = 0, FunctionScopedVariable = 1, BlockScopedVariable = 2, @@ -6462,7 +7302,7 @@ declare namespace ts { PropertyOrAccessor = 98308, ClassMember = 106500, } - interface Symbol { + export interface Symbol { flags: SymbolFlags; escapedName: __String; declarations?: Declaration[]; @@ -6471,7 +7311,7 @@ declare namespace ts { exports?: SymbolTable; globalExports?: SymbolTable; } - interface Symbol { + export interface Symbol { readonly name: string; getFlags(): SymbolFlags; getEscapedName(): __String; @@ -6480,7 +7320,7 @@ declare namespace ts { getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[]; getJsDocTags(checker?: TypeChecker): JSDocTagInfo[]; } - enum InternalSymbolName { + export enum InternalSymbolName { Call = "__call", Constructor = "__constructor", New = "__new", @@ -6509,7 +7349,7 @@ declare namespace ts { * with a normal string (which is good, it cannot be misused on assignment or on usage), * while still being comparable with a normal string via === (also good) and castable from a string. */ - type __String = + export type __String = | (string & { __escapedIdentifier: void; }) @@ -6518,12 +7358,12 @@ declare namespace ts { }) | InternalSymbolName; /** @deprecated Use ReadonlyMap<__String, T> instead. */ - type ReadonlyUnderscoreEscapedMap = ReadonlyMap<__String, T>; + export type ReadonlyUnderscoreEscapedMap = ReadonlyMap<__String, T>; /** @deprecated Use Map<__String, T> instead. */ - type UnderscoreEscapedMap = Map<__String, T>; + export type UnderscoreEscapedMap = Map<__String, T>; /** SymbolTable based on ES6 Map interface. */ - type SymbolTable = Map<__String, Symbol>; - enum TypeFlags { + export type SymbolTable = Map<__String, Symbol>; + export enum TypeFlags { Any = 1, Unknown = 2, String = 4, @@ -6574,15 +7414,15 @@ declare namespace ts { StructuredOrInstantiable = 469499904, Narrowable = 536624127, } - type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression; - interface Type { + export type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression; + export interface Type { flags: TypeFlags; symbol: Symbol; pattern?: DestructuringPattern; aliasSymbol?: Symbol; aliasTypeArguments?: readonly Type[]; } - interface Type { + export interface Type { getFlags(): TypeFlags; getSymbol(): Symbol | undefined; getProperties(): Symbol[]; @@ -6607,29 +7447,29 @@ declare namespace ts { isClass(): this is InterfaceType; isIndexType(): this is IndexType; } - interface FreshableType extends Type { + export interface FreshableType extends Type { freshType: FreshableType; regularType: FreshableType; } - interface LiteralType extends FreshableType { + export interface LiteralType extends FreshableType { value: string | number | PseudoBigInt; } - interface UniqueESSymbolType extends Type { + export interface UniqueESSymbolType extends Type { symbol: Symbol; escapedName: __String; } - interface StringLiteralType extends LiteralType { + export interface StringLiteralType extends LiteralType { value: string; } - interface NumberLiteralType extends LiteralType { + export interface NumberLiteralType extends LiteralType { value: number; } - interface BigIntLiteralType extends LiteralType { + export interface BigIntLiteralType extends LiteralType { value: PseudoBigInt; } - interface EnumType extends FreshableType { + export interface EnumType extends FreshableType { } - enum ObjectFlags { + export enum ObjectFlags { None = 0, Class = 1, Interface = 2, @@ -6652,18 +7492,18 @@ declare namespace ts { InstantiationExpressionType = 8388608, SingleSignatureType = 134217728, } - interface ObjectType extends Type { + export interface ObjectType extends Type { objectFlags: ObjectFlags; } /** Class and interface types (ObjectFlags.Class and ObjectFlags.Interface). */ - interface InterfaceType extends ObjectType { + export interface InterfaceType extends ObjectType { typeParameters: TypeParameter[] | undefined; outerTypeParameters: TypeParameter[] | undefined; localTypeParameters: TypeParameter[] | undefined; thisType: TypeParameter | undefined; } - type BaseType = ObjectType | IntersectionType | TypeVariable; - interface InterfaceTypeWithDeclaredMembers extends InterfaceType { + export type BaseType = ObjectType | IntersectionType | TypeVariable; + export interface InterfaceTypeWithDeclaredMembers extends InterfaceType { declaredProperties: Symbol[]; declaredCallSignatures: Signature[]; declaredConstructSignatures: Signature[]; @@ -6679,18 +7519,18 @@ declare namespace ts { * if the class or interface has no type parameters and the reference isn't specifying an * explicit "this" argument. */ - interface TypeReference extends ObjectType { + export interface TypeReference extends ObjectType { target: GenericType; node?: TypeReferenceNode | ArrayTypeNode | TupleTypeNode; } - interface TypeReference { + export interface TypeReference { typeArguments?: readonly Type[]; } - interface DeferredTypeReference extends TypeReference { + export interface DeferredTypeReference extends TypeReference { } - interface GenericType extends InterfaceType, TypeReference { + export interface GenericType extends InterfaceType, TypeReference { } - enum ElementFlags { + export enum ElementFlags { Required = 1, Optional = 2, Rest = 4, @@ -6700,7 +7540,7 @@ declare namespace ts { NonRequired = 14, NonRest = 11, } - interface TupleType extends GenericType { + export interface TupleType extends GenericType { elementFlags: readonly ElementFlags[]; /** Number of required or variadic elements */ minLength: number; @@ -6716,37 +7556,37 @@ declare namespace ts { readonly: boolean; labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration | undefined)[]; } - interface TupleTypeReference extends TypeReference { + export interface TupleTypeReference extends TypeReference { target: TupleType; } - interface UnionOrIntersectionType extends Type { + export interface UnionOrIntersectionType extends Type { types: Type[]; } - interface UnionType extends UnionOrIntersectionType { + export interface UnionType extends UnionOrIntersectionType { } - interface IntersectionType extends UnionOrIntersectionType { + export interface IntersectionType extends UnionOrIntersectionType { } - type StructuredType = ObjectType | UnionType | IntersectionType; - interface EvolvingArrayType extends ObjectType { + export type StructuredType = ObjectType | UnionType | IntersectionType; + export interface EvolvingArrayType extends ObjectType { elementType: Type; finalArrayType?: Type; } - interface InstantiableType extends Type { + export interface InstantiableType extends Type { } - interface TypeParameter extends InstantiableType { + export interface TypeParameter extends InstantiableType { } - interface IndexedAccessType extends InstantiableType { + export interface IndexedAccessType extends InstantiableType { objectType: Type; indexType: Type; constraint?: Type; simplifiedForReading?: Type; simplifiedForWriting?: Type; } - type TypeVariable = TypeParameter | IndexedAccessType; - interface IndexType extends InstantiableType { + export type TypeVariable = TypeParameter | IndexedAccessType; + export interface IndexType extends InstantiableType { type: InstantiableType | UnionOrIntersectionType; } - interface ConditionalRoot { + export interface ConditionalRoot { node: ConditionalTypeNode; checkType: Type; extendsType: Type; @@ -6757,37 +7597,37 @@ declare namespace ts { aliasSymbol?: Symbol; aliasTypeArguments?: Type[]; } - interface ConditionalType extends InstantiableType { + export interface ConditionalType extends InstantiableType { root: ConditionalRoot; checkType: Type; extendsType: Type; resolvedTrueType?: Type; resolvedFalseType?: Type; } - interface TemplateLiteralType extends InstantiableType { + export interface TemplateLiteralType extends InstantiableType { texts: readonly string[]; types: readonly Type[]; } - interface StringMappingType extends InstantiableType { + export interface StringMappingType extends InstantiableType { symbol: Symbol; type: Type; } - interface SubstitutionType extends InstantiableType { + export interface SubstitutionType extends InstantiableType { objectFlags: ObjectFlags; baseType: Type; constraint: Type; } - enum SignatureKind { + export enum SignatureKind { Call = 0, Construct = 1, } - interface Signature { + export interface Signature { declaration?: SignatureDeclaration | JSDocSignature; typeParameters?: readonly TypeParameter[]; parameters: readonly Symbol[]; thisParameter?: Symbol; } - interface Signature { + export interface Signature { getDeclaration(): SignatureDeclaration; getTypeParameters(): TypeParameter[] | undefined; getParameters(): Symbol[]; @@ -6796,17 +7636,17 @@ declare namespace ts { getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[]; getJsDocTags(): JSDocTagInfo[]; } - enum IndexKind { + export enum IndexKind { String = 0, Number = 1, } - interface IndexInfo { + export interface IndexInfo { keyType: Type; type: Type; isReadonly: boolean; declaration?: IndexSignatureDeclaration; } - enum InferencePriority { + export enum InferencePriority { None = 0, NakedTypeVariable = 1, SpeculativeTuple = 2, @@ -6823,12 +7663,12 @@ declare namespace ts { PriorityImpliesCombination = 416, Circularity = -1, } - interface FileExtensionInfo { + export interface FileExtensionInfo { extension: string; isMixedContent: boolean; scriptKind?: ScriptKind; } - interface DiagnosticMessage { + export interface DiagnosticMessage { key: string; category: DiagnosticCategory; code: number; @@ -6842,20 +7682,20 @@ declare namespace ts { * While it seems that DiagnosticMessageChain is structurally similar to DiagnosticMessage, * the difference is that messages are all preformatted in DMC. */ - interface DiagnosticMessageChain { + export interface DiagnosticMessageChain { messageText: string; category: DiagnosticCategory; code: number; next?: DiagnosticMessageChain[]; } - interface Diagnostic extends DiagnosticRelatedInformation { + export interface Diagnostic extends DiagnosticRelatedInformation { /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ reportsUnnecessary?: {}; reportsDeprecated?: {}; source?: string; relatedInformation?: DiagnosticRelatedInformation[]; } - interface DiagnosticRelatedInformation { + export interface DiagnosticRelatedInformation { category: DiagnosticCategory; code: number; file: SourceFile | undefined; @@ -6863,18 +7703,18 @@ declare namespace ts { length: number | undefined; messageText: string | DiagnosticMessageChain; } - interface DiagnosticWithLocation extends Diagnostic { + export interface DiagnosticWithLocation extends Diagnostic { file: SourceFile; start: number; length: number; } - enum DiagnosticCategory { + export enum DiagnosticCategory { Warning = 0, Error = 1, Suggestion = 2, Message = 3, } - enum ModuleResolutionKind { + export enum ModuleResolutionKind { Classic = 1, /** * @deprecated @@ -6887,7 +7727,7 @@ declare namespace ts { NodeNext = 99, Bundler = 100, } - enum ModuleDetectionKind { + export enum ModuleDetectionKind { /** * Files with imports, exports and/or import.meta are considered modules */ @@ -6901,10 +7741,10 @@ declare namespace ts { */ Force = 3, } - interface PluginImport { + export interface PluginImport { name: string; } - interface ProjectReference { + export interface ProjectReference { /** A normalized path on disk */ path: string; /** The path as the user originally wrote it */ @@ -6914,7 +7754,7 @@ declare namespace ts { /** True if it is intended that this reference form a circularity */ circular?: boolean; } - enum WatchFileKind { + export enum WatchFileKind { FixedPollingInterval = 0, PriorityPollingInterval = 1, DynamicPriorityPolling = 2, @@ -6922,20 +7762,20 @@ declare namespace ts { UseFsEvents = 4, UseFsEventsOnParentDirectory = 5, } - enum WatchDirectoryKind { + export enum WatchDirectoryKind { UseFsEvents = 0, FixedPollingInterval = 1, DynamicPriorityPolling = 2, FixedChunkSizePolling = 3, } - enum PollingWatchKind { + export enum PollingWatchKind { FixedInterval = 0, PriorityInterval = 1, DynamicPriority = 2, FixedChunkSize = 3, } - type CompilerOptionsValue = string | number | boolean | (string | number)[] | string[] | MapLike | PluginImport[] | ProjectReference[] | null | undefined; - interface CompilerOptions { + export type CompilerOptionsValue = string | number | boolean | (string | number)[] | string[] | MapLike | PluginImport[] | ProjectReference[] | null | undefined; + export interface CompilerOptions { allowImportingTsExtensions?: boolean; allowJs?: boolean; allowArbitraryExtensions?: boolean; @@ -7053,7 +7893,7 @@ declare namespace ts { useDefineForClassFields?: boolean; [option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined; } - interface WatchOptions { + export interface WatchOptions { watchFile?: WatchFileKind; watchDirectory?: WatchDirectoryKind; fallbackPolling?: PollingWatchKind; @@ -7062,14 +7902,14 @@ declare namespace ts { excludeFiles?: string[]; [option: string]: CompilerOptionsValue | undefined; } - interface TypeAcquisition { + export interface TypeAcquisition { enable?: boolean; include?: string[]; exclude?: string[]; disableFilenameBasedTypeAcquisition?: boolean; [option: string]: CompilerOptionsValue | undefined; } - enum ModuleKind { + export enum ModuleKind { None = 0, CommonJS = 1, AMD = 2, @@ -7083,7 +7923,7 @@ declare namespace ts { NodeNext = 199, Preserve = 200, } - enum JsxEmit { + export enum JsxEmit { None = 0, Preserve = 1, React = 2, @@ -7092,21 +7932,21 @@ declare namespace ts { ReactJSXDev = 5, } /** @deprecated */ - enum ImportsNotUsedAsValues { + export enum ImportsNotUsedAsValues { Remove = 0, Preserve = 1, Error = 2, } - enum NewLineKind { + export enum NewLineKind { CarriageReturnLineFeed = 0, LineFeed = 1, } - interface LineAndCharacter { + export interface LineAndCharacter { /** 0-based. */ line: number; character: number; } - enum ScriptKind { + export enum ScriptKind { Unknown = 0, JS = 1, JSX = 2, @@ -7120,7 +7960,7 @@ declare namespace ts { */ Deferred = 7, } - enum ScriptTarget { + export enum ScriptTarget { /** @deprecated */ ES3 = 0, ES5 = 1, @@ -7137,12 +7977,12 @@ declare namespace ts { JSON = 100, Latest = 99, } - enum LanguageVariant { + export enum LanguageVariant { Standard = 0, JSX = 1, } /** Either a parsed command line or a parsed tsconfig.json */ - interface ParsedCommandLine { + export interface ParsedCommandLine { options: CompilerOptions; typeAcquisition?: TypeAcquisition; fileNames: string[]; @@ -7153,11 +7993,11 @@ declare namespace ts { wildcardDirectories?: MapLike; compileOnSave?: boolean; } - enum WatchDirectoryFlags { + export enum WatchDirectoryFlags { None = 0, Recursive = 1, } - interface CreateProgramOptions { + export interface CreateProgramOptions { rootNames: readonly string[]; options: CompilerOptions; projectReferences?: readonly ProjectReference[]; @@ -7165,7 +8005,7 @@ declare namespace ts { oldProgram?: Program; configFileParsingDiagnostics?: readonly Diagnostic[]; } - interface ModuleResolutionHost { + export interface ModuleResolutionHost { fileExists(fileName: string): boolean; readFile(fileName: string): string | undefined; trace?(s: string): void; @@ -7182,7 +8022,7 @@ declare namespace ts { /** * Used by services to specify the minimum host area required to set up source files under any compilation settings */ - interface MinimalResolutionCacheHost extends ModuleResolutionHost { + export interface MinimalResolutionCacheHost extends ModuleResolutionHost { getCompilationSettings(): CompilerOptions; getCompilerHost?(): CompilerHost | undefined; } @@ -7193,7 +8033,7 @@ declare namespace ts { * * Prefer to return a `ResolvedModuleFull` so that the file type does not have to be inferred. */ - interface ResolvedModule { + export interface ResolvedModule { /** Path of the file the module was resolved to. */ resolvedFileName: string; /** True if `resolvedFileName` comes from `node_modules`. */ @@ -7209,7 +8049,7 @@ declare namespace ts { * Prefer this over `ResolvedModule`. * If changing this, remember to change `moduleResolutionIsEqualTo`. */ - interface ResolvedModuleFull extends ResolvedModule { + export interface ResolvedModuleFull extends ResolvedModule { /** * Extension of resolvedFileName. This must match what's at the end of resolvedFileName. * This is optional for backwards-compatibility, but will be added if not provided. @@ -7221,7 +8061,7 @@ declare namespace ts { * Unique identifier with a package name and version. * If changing this, remember to change `packageIdIsEqual`. */ - interface PackageId { + export interface PackageId { /** * Name of the package. * Should not include `@types`. @@ -7236,7 +8076,7 @@ declare namespace ts { /** Version of the package, e.g. "1.2.3" */ version: string; } - enum Extension { + export enum Extension { Ts = ".ts", Tsx = ".tsx", Dts = ".d.ts", @@ -7251,20 +8091,20 @@ declare namespace ts { Cts = ".cts", Dcts = ".d.cts", } - interface ResolvedModuleWithFailedLookupLocations { + export interface ResolvedModuleWithFailedLookupLocations { readonly resolvedModule: ResolvedModuleFull | undefined; } - interface ResolvedTypeReferenceDirective { + export interface ResolvedTypeReferenceDirective { primary: boolean; resolvedFileName: string | undefined; packageId?: PackageId; /** True if `resolvedFileName` comes from `node_modules`. */ isExternalLibraryImport?: boolean; } - interface ResolvedTypeReferenceDirectiveWithFailedLookupLocations { + export interface ResolvedTypeReferenceDirectiveWithFailedLookupLocations { readonly resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective | undefined; } - interface CompilerHost extends ModuleResolutionHost { + export interface CompilerHost extends ModuleResolutionHost { getSourceFile(fileName: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; getSourceFileByPath?(fileName: string, path: Path, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined; getCancellationToken?(): CancellationToken; @@ -7297,18 +8137,18 @@ declare namespace ts { getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined; jsDocParsingMode?: JSDocParsingMode; } - interface SourceMapRange extends TextRange { + export interface SourceMapRange extends TextRange { source?: SourceMapSource; } - interface SourceMapSource { + export interface SourceMapSource { fileName: string; text: string; skipTrivia?: (pos: number) => number; } - interface SourceMapSource { + export interface SourceMapSource { getLineAndCharacterOfPosition(pos: number): LineAndCharacter; } - enum EmitFlags { + export enum EmitFlags { None = 0, SingleLine = 1, MultiLine = 2, @@ -7339,23 +8179,23 @@ declare namespace ts { Iterator = 8388608, NoAsciiEscaping = 16777216, } - interface EmitHelperBase { + export interface EmitHelperBase { readonly name: string; readonly scoped: boolean; readonly text: string | ((node: EmitHelperUniqueNameCallback) => string); readonly priority?: number; readonly dependencies?: EmitHelper[]; } - interface ScopedEmitHelper extends EmitHelperBase { + export interface ScopedEmitHelper extends EmitHelperBase { readonly scoped: true; } - interface UnscopedEmitHelper extends EmitHelperBase { + export interface UnscopedEmitHelper extends EmitHelperBase { readonly scoped: false; readonly text: string; } - type EmitHelper = ScopedEmitHelper | UnscopedEmitHelper; - type EmitHelperUniqueNameCallback = (name: string) => string; - enum EmitHint { + export type EmitHelper = ScopedEmitHelper | UnscopedEmitHelper; + export type EmitHelperUniqueNameCallback = (name: string) => string; + export enum EmitHint { SourceFile = 0, Expression = 1, IdentifierName = 2, @@ -7365,7 +8205,7 @@ declare namespace ts { JsxAttributeValue = 6, ImportTypeNodeAttributes = 7, } - enum OuterExpressionKinds { + export enum OuterExpressionKinds { Parentheses = 1, TypeAssertions = 2, NonNullAssertions = 4, @@ -7375,15 +8215,15 @@ declare namespace ts { All = 31, ExcludeJSDocTypeAssertion = -2147483648, } - type ImmediatelyInvokedFunctionExpression = CallExpression & { + export type ImmediatelyInvokedFunctionExpression = CallExpression & { readonly expression: FunctionExpression; }; - type ImmediatelyInvokedArrowFunction = CallExpression & { + export type ImmediatelyInvokedArrowFunction = CallExpression & { readonly expression: ParenthesizedExpression & { readonly expression: ArrowFunction; }; }; - interface NodeFactory { + export interface NodeFactory { createNodeArray(elements?: readonly T[], hasTrailingComma?: boolean): NodeArray; createNumericLiteral(value: string | number, numericLiteralFlags?: TokenFlags): NumericLiteral; createBigIntLiteral(value: string | PseudoBigInt): BigIntLiteral; @@ -7539,8 +8379,8 @@ declare namespace ts { updateNewExpression(node: NewExpression, expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined): NewExpression; createTaggedTemplateExpression(tag: Expression, typeArguments: readonly TypeNode[] | undefined, template: TemplateLiteral): TaggedTemplateExpression; updateTaggedTemplateExpression(node: TaggedTemplateExpression, tag: Expression, typeArguments: readonly TypeNode[] | undefined, template: TemplateLiteral): TaggedTemplateExpression; - createTypeAssertion(type: TypeNode, expression: Expression): TypeAssertion; - updateTypeAssertion(node: TypeAssertion, type: TypeNode, expression: Expression): TypeAssertion; + createTypeAssertion(type: TypeNode, expression: Expression): TypeAssertionExpression; + updateTypeAssertion(node: TypeAssertionExpression, type: TypeNode, expression: Expression): TypeAssertionExpression; createParenthesizedExpression(expression: Expression): ParenthesizedExpression; updateParenthesizedExpression(node: ParenthesizedExpression, expression: Expression): ParenthesizedExpression; createFunctionExpression(modifiers: readonly Modifier[] | undefined, asteriskToken: AsteriskToken | undefined, name: string | Identifier | undefined, typeParameters: readonly TypeParameterDeclaration[] | undefined, parameters: readonly ParameterDeclaration[] | undefined, type: TypeNode | undefined, body: Block): FunctionExpression; @@ -7877,7 +8717,7 @@ declare namespace ts { */ replacePropertyName(node: T, name: T["name"]): T; } - interface CoreTransformationContext { + export interface CoreTransformationContext { readonly factory: NodeFactory; /** Gets the compiler options supplied to the transformer. */ getCompilerOptions(): CompilerOptions; @@ -7894,7 +8734,7 @@ declare namespace ts { /** Hoists a variable declaration to the containing scope. */ hoistVariableDeclaration(node: Identifier): void; } - interface TransformationContext extends CoreTransformationContext { + export interface TransformationContext extends CoreTransformationContext { /** Records a request for a non-scoped emit helper in the current context. */ requestEmitHelper(helper: EmitHelper): void; /** Gets and resets the requested non-scoped emit helpers. */ @@ -7930,7 +8770,7 @@ declare namespace ts { */ onEmitNode: (hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) => void; } - interface TransformationResult { + export interface TransformationResult { /** Gets the transformed source files. */ transformed: T[]; /** Gets diagnostics for the transformation. */ @@ -7965,15 +8805,15 @@ declare namespace ts { * A function that is used to initialize and return a `Transformer` callback, which in turn * will be used to transform one or more nodes. */ - type TransformerFactory = (context: TransformationContext) => Transformer; + export type TransformerFactory = (context: TransformationContext) => Transformer; /** * A function that transforms a node. */ - type Transformer = (node: T) => T; + export type Transformer = (node: T) => T; /** * A function that accepts and possibly transforms a node. */ - type Visitor = (node: TIn) => VisitResult; + export type Visitor = (node: TIn) => VisitResult; /** * A function that walks a node using the given visitor, lifting node arrays into single nodes, * returning an node which satisfies the test. @@ -7986,7 +8826,7 @@ declare namespace ts { * * For the canonical implementation of this type, @see {visitNode}. */ - interface NodeVisitor { + export interface NodeVisitor { (node: TIn, visitor: Visitor, TVisited>, test: (node: Node) => node is TOut, lift?: (node: readonly Node[]) => Node): TOut | (TIn & undefined) | (TVisited & undefined); (node: TIn, visitor: Visitor, TVisited>, test?: (node: Node) => boolean, lift?: (node: readonly Node[]) => Node): Node | (TIn & undefined) | (TVisited & undefined); } @@ -8001,12 +8841,12 @@ declare namespace ts { * * For the canonical implementation of this type, @see {visitNodes}. */ - interface NodesVisitor { + export interface NodesVisitor { | undefined, TOut extends Node>(nodes: TInArray, visitor: Visitor, test: (node: Node) => node is TOut, start?: number, count?: number): NodeArray | (TInArray & undefined); | undefined>(nodes: TInArray, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | (TInArray & undefined); } - type VisitResult = T | readonly Node[]; - interface Printer { + export type VisitResult = T | readonly Node[]; + export interface Printer { /** * Print a node and its subtree as-is, without any emit transformations. * @param hint A value indicating the purpose of a node. This is primarily used to @@ -8034,7 +8874,7 @@ declare namespace ts { */ printBundle(bundle: Bundle): string; } - interface PrintHandlers { + export interface PrintHandlers { /** * A hook used by the Printer when generating unique names to avoid collisions with * globally defined names that exist outside of the current source file. @@ -8082,27 +8922,26 @@ declare namespace ts { */ substituteNode?(hint: EmitHint, node: Node): Node; } - interface PrinterOptions { + export interface PrinterOptions { removeComments?: boolean; newLine?: NewLineKind; omitTrailingSemicolon?: boolean; noEmitHelpers?: boolean; } - interface GetEffectiveTypeRootsHost { + export interface GetEffectiveTypeRootsHost { getCurrentDirectory?(): string; } - interface TextSpan { + export interface TextSpan { start: number; length: number; } - interface TextChangeRange { + export interface TextChangeRange { span: TextSpan; newLength: number; } - interface SyntaxList extends Node { - kind: SyntaxKind.SyntaxList; + export class SyntaxList extends Node { } - enum ListFormat { + export enum ListFormat { None = 0, SingleLine = 0, MultiLine = 1, @@ -8173,7 +9012,7 @@ declare namespace ts { IndexSignatureParameters = 8848, JSDocComment = 33, } - enum JSDocParsingMode { + export enum JSDocParsingMode { /** * Always parse JSDoc comments and include them in the AST. * @@ -8200,7 +9039,7 @@ declare namespace ts { */ ParseForTypeInfo = 3, } - interface UserPreferences { + export interface UserPreferences { readonly disableSuggestions?: boolean; readonly quotePreference?: "auto" | "double" | "single"; /** @@ -8338,21 +9177,1564 @@ declare namespace ts { readonly generateReturnInDocTemplate?: boolean; readonly disableLineTextInReferences?: boolean; } - type OrganizeImportsTypeOrder = "last" | "inline" | "first"; + export type OrganizeImportsTypeOrder = "last" | "inline" | "first"; /** Represents a bigint literal value without requiring bigint support */ - interface PseudoBigInt { + export interface PseudoBigInt { negative: boolean; base10Value: string; } - enum FileWatcherEventKind { + export class AstNodeArray { + readonly items: readonly N[]; + pos: number; + end: number; + private _extra; + constructor(items: readonly N[], hasTrailingComma?: boolean); + private get extra(); + get nodes(): NodeArray; + get hasTrailingComma(): boolean; + set hasTrailingComma(value: boolean); + } + export class AstNode = Node> { + private _node; + private _nodeConstructor; + private _extra; + readonly kind: N["kind"]; + readonly data: N["data"]; + parent: AstNode> | undefined; + flags: NodeFlags; + pos: number; + end: number; + constructor(kind: N["kind"], data: N["data"], nodeConstructor: NodeConstructor, flags?: NodeFlags); + get node(): N; + static Token(kind: K): AstToken; + private static _tokenFactoryMap; + static EndOfFileToken(): AstEndOfFileToken; + static ThisExpression(): AstThisExpression; + static SuperExpression(): AstSuperExpression; + static ImportExpression(): AstImportExpression; + static NullLiteral(): AstNullLiteral; + static TrueLiteral(): AstTrueLiteral; + static FalseLiteral(): AstFalseLiteral; + static Identifier(): AstIdentifier; + static PrivateIdentifier(): AstPrivateIdentifier; + static QualifiedName(): AstQualifiedName; + static ComputedPropertyName(): AstComputedPropertyName; + static TypeParameterDeclaration(): AstTypeParameterDeclaration; + static ParameterDeclaration(): AstParameterDeclaration; + static Decorator(): AstDecorator; + static PropertySignature(): AstPropertySignature; + static CallSignatureDeclaration(): AstCallSignatureDeclaration; + static ConstructSignatureDeclaration(): AstConstructSignatureDeclaration; + static VariableDeclaration(): AstVariableDeclaration; + static VariableDeclarationList(): AstVariableDeclarationList; + static BindingElement(): AstBindingElement; + static PropertyDeclaration(): AstPropertyDeclaration; + static PropertyAssignment(): AstPropertyAssignment; + static ShorthandPropertyAssignment(): AstShorthandPropertyAssignment; + static SpreadAssignment(): AstSpreadAssignment; + static ObjectBindingPattern(): AstObjectBindingPattern; + static ArrayBindingPattern(): AstArrayBindingPattern; + static FunctionDeclaration(): AstFunctionDeclaration; + static MethodSignature(): AstMethodSignature; + static MethodDeclaration(): AstMethodDeclaration; + static ConstructorDeclaration(): AstConstructorDeclaration; + static SemicolonClassElement(): AstSemicolonClassElement; + static GetAccessorDeclaration(): AstGetAccessorDeclaration; + static SetAccessorDeclaration(): AstSetAccessorDeclaration; + static IndexSignatureDeclaration(): AstIndexSignatureDeclaration; + static ClassStaticBlockDeclaration(): AstClassStaticBlockDeclaration; + /** @deprecated */ + static ImportTypeAssertionContainer(): AstImportTypeAssertionContainer; + static ImportTypeNode(): AstImportTypeNode; + static ThisTypeNode(): AstThisTypeNode; + static FunctionTypeNode(): AstFunctionTypeNode; + static ConstructorTypeNode(): AstConstructorTypeNode; + static TypeReferenceNode(): AstTypeReferenceNode; + static TypePredicateNode(): AstTypePredicateNode; + static TypeQueryNode(): AstTypeQueryNode; + static TypeLiteralNode(): AstTypeLiteralNode; + static ArrayTypeNode(): AstArrayTypeNode; + static TupleTypeNode(): AstTupleTypeNode; + static NamedTupleMember(): AstNamedTupleMember; + static OptionalTypeNode(): AstOptionalTypeNode; + static RestTypeNode(): AstRestTypeNode; + static UnionTypeNode(): AstUnionTypeNode; + static IntersectionTypeNode(): AstIntersectionTypeNode; + static ConditionalTypeNode(): AstConditionalTypeNode; + static InferTypeNode(): AstInferTypeNode; + static ParenthesizedTypeNode(): AstParenthesizedTypeNode; + static TypeOperatorNode(): AstTypeOperatorNode; + static IndexedAccessTypeNode(): AstIndexedAccessTypeNode; + static MappedTypeNode(): AstMappedTypeNode; + static LiteralTypeNode(): AstLiteralTypeNode; + static StringLiteral(): AstStringLiteral; + static TemplateLiteralTypeNode(): AstTemplateLiteralTypeNode; + static TemplateLiteralTypeSpan(): AstTemplateLiteralTypeSpan; + static OmittedExpression(): AstOmittedExpression; + static PrefixUnaryExpression(): AstPrefixUnaryExpression; + static PostfixUnaryExpression(): AstPostfixUnaryExpression; + static DeleteExpression(): AstDeleteExpression; + static TypeOfExpression(): AstTypeOfExpression; + static VoidExpression(): AstVoidExpression; + static AwaitExpression(): AstAwaitExpression; + static YieldExpression(): AstYieldExpression; + static BinaryExpression(): AstBinaryExpression; + static ConditionalExpression(): AstConditionalExpression; + static FunctionExpression(): AstFunctionExpression; + static ArrowFunction(): AstArrowFunction; + static RegularExpressionLiteral(): AstRegularExpressionLiteral; + static NoSubstitutionTemplateLiteral(): AstNoSubstitutionTemplateLiteral; + static NumericLiteral(): AstNumericLiteral; + static BigIntLiteral(): AstBigIntLiteral; + static TemplateHead(): AstTemplateHead; + static TemplateMiddle(): AstTemplateMiddle; + static TemplateTail(): AstTemplateTail; + static TemplateExpression(): AstTemplateExpression; + static TemplateSpan(): AstTemplateSpan; + static ParenthesizedExpression(): AstParenthesizedExpression; + static ArrayLiteralExpression(): AstArrayLiteralExpression; + static SpreadElement(): AstSpreadElement; + static ObjectLiteralExpression(): AstObjectLiteralExpression; + static PropertyAccessExpression(): AstPropertyAccessExpression; + static PropertyAccessChain(): AstPropertyAccessChain; + static ElementAccessExpression(): AstElementAccessExpression; + static ElementAccessChain(): AstElementAccessChain; + static CallExpression(): AstCallExpression; + static CallChain(): AstCallChain; + static ExpressionWithTypeArguments(): AstExpressionWithTypeArguments; + static NewExpression(): AstNewExpression; + static TaggedTemplateExpression(): AstTaggedTemplateExpression; + static AsExpression(): AstAsExpression; + static TypeAssertion(): AstTypeAssertion; + static SatisfiesExpression(): AstSatisfiesExpression; + static NonNullExpression(): AstNonNullExpression; + static NonNullChain(): AstNonNullChain; + static MetaProperty(): AstMetaProperty; + static JsxElement(): AstJsxElement; + static JsxAttributes(): AstJsxAttributes; + static JsxNamespacedName(): AstJsxNamespacedName; + static JsxOpeningElement(): AstJsxOpeningElement; + static JsxSelfClosingElement(): AstJsxSelfClosingElement; + static JsxFragment(): AstJsxFragment; + static JsxOpeningFragment(): AstJsxOpeningFragment; + static JsxClosingFragment(): AstJsxClosingFragment; + static JsxAttribute(): AstJsxAttribute; + static JsxSpreadAttribute(): AstJsxSpreadAttribute; + static JsxClosingElement(): AstJsxClosingElement; + static JsxExpression(): AstJsxExpression; + static JsxText(): AstJsxText; + static EmptyStatement(): AstEmptyStatement; + static DebuggerStatement(): AstDebuggerStatement; + static MissingDeclaration(): AstMissingDeclaration; + static Block(): AstBlock; + static VariableStatement(): AstVariableStatement; + static ExpressionStatement(): AstExpressionStatement; + static IfStatement(): AstIfStatement; + static DoStatement(): AstDoStatement; + static WhileStatement(): AstWhileStatement; + static ForStatement(): AstForStatement; + static ForInStatement(): AstForInStatement; + static ForOfStatement(): AstForOfStatement; + static BreakStatement(): AstBreakStatement; + static ContinueStatement(): AstContinueStatement; + static ReturnStatement(): AstReturnStatement; + static WithStatement(): AstWithStatement; + static SwitchStatement(): AstSwitchStatement; + static CaseBlock(): AstCaseBlock; + static CaseClause(): AstCaseClause; + static DefaultClause(): AstDefaultClause; + static LabeledStatement(): AstLabeledStatement; + static ThrowStatement(): AstThrowStatement; + static TryStatement(): AstTryStatement; + static CatchClause(): AstCatchClause; + static ClassDeclaration(): AstClassDeclaration; + static ClassExpression(): AstClassExpression; + static InterfaceDeclaration(): AstInterfaceDeclaration; + static HeritageClause(): AstHeritageClause; + static TypeAliasDeclaration(): AstTypeAliasDeclaration; + static EnumMember(): AstEnumMember; + static EnumDeclaration(): AstEnumDeclaration; + static ModuleDeclaration(): AstModuleDeclaration; + static ModuleBlock(): AstModuleBlock; + static ImportEqualsDeclaration(): AstImportEqualsDeclaration; + static ExternalModuleReference(): AstExternalModuleReference; + static ImportDeclaration(): AstImportDeclaration; + static ImportClause(): AstImportClause; + static ImportAttribute(): AstImportAttribute; + static ImportAttributes(): AstImportAttributes; + static NamespaceImport(): AstNamespaceImport; + static NamespaceExport(): AstNamespaceExport; + static NamespaceExportDeclaration(): AstNamespaceExportDeclaration; + static ExportDeclaration(): AstExportDeclaration; + static NamedImports(): AstNamedImports; + static NamedExports(): AstNamedExports; + static ImportSpecifier(): AstImportSpecifier; + static ExportSpecifier(): AstExportSpecifier; + static ExportAssignment(): AstExportAssignment; + static JSDocTypeExpression(): AstJSDocTypeExpression; + static JSDocNameReference(): AstJSDocNameReference; + static JSDocMemberName(): AstJSDocMemberName; + static JSDocAllType(): AstJSDocAllType; + static JSDocUnknownType(): AstJSDocUnknownType; + static JSDocNonNullableType(): AstJSDocNonNullableType; + static JSDocNullableType(): AstJSDocNullableType; + static JSDocOptionalType(): AstJSDocOptionalType; + static JSDocFunctionType(): AstJSDocFunctionType; + static JSDocVariadicType(): AstJSDocVariadicType; + static JSDocNamepathType(): AstJSDocNamepathType; + static JSDocNode(): AstJSDoc; + static JSDocLink(): AstJSDocLink; + static JSDocLinkCode(): AstJSDocLinkCode; + static JSDocLinkPlain(): AstJSDocLinkPlain; + static JSDocText(): AstJSDocText; + static JSDocUnknownTag(): AstJSDocUnknownTag; + static JSDocAugmentsTag(): AstJSDocAugmentsTag; + static JSDocImplementsTag(): AstJSDocImplementsTag; + static JSDocAuthorTag(): AstJSDocAuthorTag; + static JSDocDeprecatedTag(): AstJSDocDeprecatedTag; + static JSDocClassTag(): AstJSDocClassTag; + static JSDocPublicTag(): AstJSDocPublicTag; + static JSDocPrivateTag(): AstJSDocPrivateTag; + static JSDocProtectedTag(): AstJSDocProtectedTag; + static JSDocReadonlyTag(): AstJSDocReadonlyTag; + static JSDocOverrideTag(): AstJSDocOverrideTag; + static JSDocEnumTag(): AstJSDocEnumTag; + static JSDocThisTag(): AstJSDocThisTag; + static JSDocTemplateTag(): AstJSDocTemplateTag; + static JSDocSeeTag(): AstJSDocSeeTag; + static JSDocReturnTag(): AstJSDocReturnTag; + static JSDocTypeTag(): AstJSDocTypeTag; + static JSDocTypedefTag(): AstJSDocTypedefTag; + static JSDocCallbackTag(): AstJSDocCallbackTag; + static JSDocOverloadTag(): AstJSDocOverloadTag; + static JSDocThrowsTag(): AstJSDocThrowsTag; + static JSDocSignature(): AstJSDocSignature; + static JSDocPropertyTag(): AstJSDocPropertyTag; + static JSDocParameterTag(): AstJSDocParameterTag; + static JSDocTypeLiteral(): AstJSDocTypeLiteral; + static JSDocSatisfiesTag(): AstJSDocSatisfiesTag; + static JSDocImportTag(): AstJSDocImportTag; + static SourceFile(): AstSourceFile; + static SyntheticExpression(): AstSyntheticExpression; + static Bundle(): AstBundle; + static SyntaxList(): AstSyntaxList; + static NotEmittedStatement(): AstNotEmittedStatement; + static NotEmittedTypeElement(): AstNotEmittedTypeElement; + static PartiallyEmittedExpression(): AstPartiallyEmittedExpression; + static CommaListExpression(): AstCommaListExpression; + } + export type AstNodeOneOf = N extends unknown ? AstNode : never; + export class AstData { + } + export class AstTypeScriptNodeData extends AstData { + } + export type AstHasDecorators = AstNodeOneOf; + export type AstHasModifiers = AstNodeOneOf; + export type AstDeclaration = AstNode; + export type AstTypeNode = AstNode>; + export type AstStatement = AstNode; + export type AstExpression = AstNode; + export type AstUnaryExpression = AstNode; + export type AstUpdateExpression = AstNode; + export type AstLeftHandSideExpression = AstNode; + export type AstMemberExpression = AstNode; + export type AstPrimaryExpression = AstNode; + export type AstKeywordExpression = AstNode>; + export type AstLiteralLikeNode = AstNode; + export interface AstLiteralLikeNodeData extends AstData { + text: string; + } + export type AstStringLiteralLikeNode = AstNode; + export interface AstStringLiteralLikeNodeData extends AstLiteralLikeNodeData { + isUnterminated: boolean | undefined; + hasExtendedUnicodeEscape: boolean | undefined; + } + export interface AstTemplateLiteralLikeNodeData extends AstStringLiteralLikeNodeData { + rawText: string | undefined; + } + export type AstTemplateLiteralLikeNode = AstNode; + export type AstLiteralExpression = AstNode; + export interface AstLiteralExpressionData extends AstLiteralLikeNodeData { + } + export class AstTokenData extends AstData { + } + export class AstEndOfFileTokenData extends AstTokenData { + } + export class AstThisExpressionData extends AstTokenData { + } + export class AstSuperExpressionData extends AstTokenData { + } + export type AstBooleanLiteral = AstNodeOneOf; + export type AstPunctuationToken = AstNode>; + export type AstDotToken = AstNode; + export type AstDotDotDotToken = AstNode; + export type AstQuestionToken = AstNode; + export type AstExclamationToken = AstNode; + export type AstColonToken = AstNode; + export type AstEqualsToken = AstNode; + export type AstAmpersandAmpersandEqualsToken = AstNode; + export type AstBarBarEqualsToken = AstNode; + export type AstQuestionQuestionEqualsToken = AstNode; + export type AstAsteriskToken = AstNode; + export type AstEqualsGreaterThanToken = AstNode; + export type AstPlusToken = AstNode; + export type AstMinusToken = AstNode; + export type AstQuestionDotToken = AstNode; + export type AstKeywordToken = AstNode>; + export type AstAssertsKeyword = AstNode; + export type AstAssertKeyword = AstNode; + export type AstAwaitKeyword = AstNode; + export type AstCaseKeyword = AstNode; + export type AstModifierToken = AstNode>; + export type AstAbstractKeyword = AstNode; + export type AstAccessorKeyword = AstNode; + export type AstAsyncKeyword = AstNode; + export type AstConstKeyword = AstNode; + export type AstDeclareKeyword = AstNode; + export type AstDefaultKeyword = AstNode; + export type AstExportKeyword = AstNode; + export type AstInKeyword = AstNode; + export type AstPrivateKeyword = AstNode; + export type AstProtectedKeyword = AstNode; + export type AstPublicKeyword = AstNode; + export type AstReadonlyKeyword = AstNode; + export type AstOutKeyword = AstNode; + export type AstOverrideKeyword = AstNode; + export type AstStaticKeyword = AstNode; + export type AstModifier = AstNodeOneOf; + export type AstModifierLike = AstNodeOneOf; + export class AstIdentifierData extends AstTokenData { + escapedText: __String; + } + export class AstQualifiedNameData extends AstData { + left: AstEntityName; + right: AstIdentifier; + } + export type AstEntityName = AstNodeOneOf; + export type AstBindingName = AstNodeOneOf; + export type AstPropertyName = AstNodeOneOf; + export type AstMemberName = AstNodeOneOf; + export type AstDeclarationName = AstNodeOneOf; + export class AstComputedPropertyNameData extends AstData { + expression: AstExpression; + } + export class AstPrivateIdentifierData extends AstTokenData { + escapedText: __String; + } + export class AstTypeParameterDeclarationData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined; + name: AstIdentifier; + constraint: AstTypeNode | undefined; + default: AstTypeNode | undefined; + expression: AstExpression | undefined; + } + export class AstParameterDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + dotDotDotToken: AstDotDotDotToken | undefined; + name: AstBindingName; + questionToken: AstQuestionToken | undefined; + type: AstTypeNode | undefined; + initializer: AstExpression | undefined; + } + export class AstDecoratorData extends AstData { + expression: AstLeftHandSideExpression; + } + export class AstPropertySignatureData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined; + name: AstPropertyName; + questionToken: AstQuestionToken | undefined; + type: AstTypeNode | undefined; + } + export type AstSignatureDeclaration = AstNodeOneOf; + export class AstCallSignatureDeclarationData extends AstTypeScriptNodeData { + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode | undefined; + } + export class AstConstructSignatureDeclarationData extends AstTypeScriptNodeData { + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode | undefined; + } + export class AstVariableDeclarationData extends AstData { + name: AstBindingName; + exclamationToken: AstExclamationToken | undefined; + type: AstTypeNode | undefined; + initializer: AstExpression | undefined; + } + export class AstVariableDeclarationListData extends AstData { + declarations: AstNodeArray; + } + export class AstBindingElementData extends AstData { + propertyName: AstPropertyName | undefined; + dotDotDotToken: AstDotDotDotToken | undefined; + name: AstBindingName; + initializer: AstExpression | undefined; + } + export class AstPropertyDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + name: AstPropertyName; + questionToken: AstQuestionToken | undefined; + exclamationToken: AstExclamationToken | undefined; + type: AstTypeNode | undefined; + initializer: AstExpression | undefined; + } + export class AstPropertyAssignmentData extends AstData { + modifiers: AstNodeArray | undefined; + name: AstPropertyName; + questionToken: AstQuestionToken | undefined; + exclamationToken: AstExclamationToken | undefined; + initializer: AstExpression; + } + export class AstShorthandPropertyAssignmentData extends AstData { + name: AstIdentifier; + equalsToken: AstEqualsToken | undefined; + objectAssignmentInitializer: AstExpression | undefined; + modifiers: AstNodeArray | undefined; + questionToken: AstQuestionToken | undefined; + exclamationToken: AstExclamationToken | undefined; + } + export class AstSpreadAssignmentData extends AstData { + expression: AstExpression; + } + export type AstBindingPattern = AstNodeOneOf; + export type AstArrayBindingElement = AstNodeOneOf; + export class AstObjectBindingPatternData extends AstData { + elements: AstNodeArray; + } + export class AstArrayBindingPatternData extends AstData { + elements: AstNodeArray; + } + export class AstFunctionDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + asteriskToken: AstAsteriskToken | undefined; + name: AstIdentifier | undefined; + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode | undefined; + body: AstFunctionBody | undefined; + } + export class AstMethodSignatureData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined; + name: AstPropertyName; + questionToken: AstQuestionToken | undefined; + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode | undefined; + } + export class AstMethodDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + asteriskToken: AstAsteriskToken | undefined; + name: AstPropertyName; + questionToken: AstQuestionToken | undefined; + exclamationToken: AstExclamationToken | undefined; + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode | undefined; + body: AstFunctionBody | undefined; + } + export class AstConstructorDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + body: AstFunctionBody | undefined; + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode | undefined; + } + export class AstSemicolonClassElementData extends AstData { + } + export class AstGetAccessorDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + name: AstPropertyName; + body: AstFunctionBody | undefined; + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode | undefined; + } + export class AstSetAccessorDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + name: AstPropertyName; + body: AstFunctionBody | undefined; + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode | undefined; + } + export type AstAccessorDeclaration = AstNodeOneOf; + export class AstIndexSignatureDeclarationData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined; + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode | undefined; + } + export class AstClassStaticBlockDeclarationData extends AstData { + body: AstBlock; + modifiers: AstNodeArray | undefined; + } + /** + * @deprecated + */ + export type AstImportTypeAssertionContainer = AstNode; + /** + * @deprecated + */ + export class AstImportTypeAssertionContainerData extends AstTypeScriptNodeData { + assertClause: AstImportAttributes; + multiLine: boolean; + } + export class AstImportTypeNodeData extends AstTypeScriptNodeData { + isTypeOf: boolean; + argument: AstTypeNode; + assertions: AstImportTypeAssertionContainer | undefined; + attributes: AstImportAttributes | undefined; + qualifier: AstEntityName | undefined; + typeArguments: AstNodeArray | undefined; + } + export type AstKeywordTypeNode = AstNode>; + export class AstThisTypeNodeData extends AstTypeScriptNodeData { + } + export type AstFunctionOrConstructorTypeNode = AstNodeOneOf; + export class AstFunctionTypeNodeData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined; + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode; + } + export class AstConstructorTypeNodeData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined; + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode; + } + export class AstTypeReferenceNodeData extends AstTypeScriptNodeData { + typeName: AstEntityName; + typeArguments: AstNodeArray | undefined; + } + export class AstTypePredicateNodeData extends AstTypeScriptNodeData { + assertsModifier: AstAssertsKeyword | undefined; + parameterName: AstIdentifier | AstThisTypeNode; + type: AstTypeNode | undefined; + } + export class AstTypeQueryNodeData extends AstTypeScriptNodeData { + exprName: AstEntityName; + typeArguments: AstNodeArray | undefined; + } + export class AstTypeLiteralNodeData extends AstTypeScriptNodeData { + members: AstNodeArray; + } + export class AstArrayTypeNodeData extends AstTypeScriptNodeData { + elementType: AstTypeNode; + } + export class AstTupleTypeNodeData extends AstTypeScriptNodeData { + elements: AstNodeArray; + } + export class AstNamedTupleMemberData extends AstTypeScriptNodeData { + dotDotDotToken: AstDotDotDotToken | undefined; + name: AstIdentifier; + questionToken: AstQuestionToken | undefined; + type: AstTypeNode; + } + export class AstOptionalTypeNodeData extends AstTypeScriptNodeData { + type: AstTypeNode; + } + export class AstRestTypeNodeData extends AstTypeScriptNodeData { + type: AstTypeNode; + } + export type AstUnionOrIntersectionTypeNode = AstNodeOneOf; + export class AstUnionTypeNodeData extends AstTypeScriptNodeData { + types: AstNodeArray; + } + export class AstIntersectionTypeNodeData extends AstTypeScriptNodeData { + types: AstNodeArray; + } + export class AstConditionalTypeNodeData extends AstTypeScriptNodeData { + checkType: AstTypeNode; + extendsType: AstTypeNode; + trueType: AstTypeNode; + falseType: AstTypeNode; + } + export class AstInferTypeNodeData extends AstTypeScriptNodeData { + typeParameter: AstTypeParameterDeclaration; + } + export class AstParenthesizedTypeNodeData extends AstTypeScriptNodeData { + type: AstTypeNode; + } + export class AstTypeOperatorNodeData extends AstTypeScriptNodeData { + operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; + type: AstTypeNode; + } + export class AstIndexedAccessTypeNodeData extends AstTypeScriptNodeData { + objectType: AstTypeNode; + indexType: AstTypeNode; + } + export class AstMappedTypeNodeData extends AstTypeScriptNodeData { + readonlyToken: AstReadonlyKeyword | AstPlusToken | AstMinusToken | undefined; + typeParameter: AstTypeParameterDeclaration; + nameType: AstTypeNode | undefined; + questionToken: AstQuestionToken | AstPlusToken | AstMinusToken | undefined; + type: AstTypeNode | undefined; + members: AstNodeArray | undefined; + } + export class AstLiteralTypeNodeData extends AstTypeScriptNodeData { + literal: AstNullLiteral | AstBooleanLiteral | AstLiteralExpression | AstPrefixUnaryExpression; + } + export type AstPropertyNameLiteral = AstNodeOneOf; + export class AstTemplateLiteralTypeNodeData extends AstTypeScriptNodeData { + head: AstTemplateHead; + templateSpans: AstNodeArray; + } + export class AstTemplateLiteralTypeSpanData extends AstTypeScriptNodeData { + type: AstTypeNode; + literal: AstTemplateMiddle | AstTemplateTail; + } + export class AstOmittedExpressionData extends AstData { + } + export class AstPrefixUnaryExpressionData extends AstData { + operator: PrefixUnaryOperator; + operand: AstUnaryExpression; + } + export class AstPostfixUnaryExpressionData extends AstData { + operand: AstLeftHandSideExpression; + operator: PostfixUnaryOperator; + } + export class AstDeleteExpressionData extends AstData { + expression: AstUnaryExpression; + } + export class AstTypeOfExpressionData extends AstData { + expression: AstUnaryExpression; + } + export class AstVoidExpressionData extends AstData { + expression: AstUnaryExpression; + } + export class AstAwaitExpressionData extends AstData { + expression: AstUnaryExpression; + } + export class AstYieldExpressionData extends AstData { + asteriskToken: AstAsteriskToken | undefined; + expression: AstExpression | undefined; + } + export type AstBinaryOperatorToken = AstNode; + export class AstBinaryExpressionData extends AstData { + left: AstExpression; + operatorToken: AstBinaryOperatorToken; + right: AstExpression; + } + export type AstDestructuringAssignment = AstNodeOneOf; + export class AstConditionalExpressionData extends AstData { + condition: AstExpression; + questionToken: AstQuestionToken; + whenTrue: AstExpression; + colonToken: AstColonToken; + whenFalse: AstExpression; + } + export type AstFunctionBody = AstNodeOneOf; + export type AstConciseBody = AstNodeOneOf; + export class AstFunctionExpressionData extends AstData { + modifiers: AstNodeArray | undefined; + asteriskToken: AstAsteriskToken | undefined; + name: AstIdentifier | undefined; + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode | undefined; + body: AstFunctionBody; + } + export class AstArrowFunctionData extends AstData { + modifiers: AstNodeArray | undefined; + equalsGreaterThanToken: AstEqualsGreaterThanToken; + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode | undefined; + body: AstConciseBody; + typeArguments: AstNodeArray | undefined; + } + export class AstRegularExpressionLiteralData extends AstTokenData { + text: string; + isUnterminated: boolean | undefined; + hasExtendedUnicodeEscape: boolean | undefined; + } + export class AstStringLiteralData extends AstTokenData { + text: string; + singleQuote: boolean | undefined; + isUnterminated: boolean; + hasExtendedUnicodeEscape: boolean; + } + export class AstNoSubstitutionTemplateLiteralData extends AstTokenData { + text: string; + rawText: string | undefined; + isUnterminated: boolean | undefined; + hasExtendedUnicodeEscape: boolean | undefined; + } + export type AstPseudoLiteralToken = AstNodeOneOf; + export type AstTemplateLiteralToken = AstNodeOneOf; + export type AstStringLiteralLike = AstNodeOneOf; + export class AstNumericLiteralData extends AstTokenData { + text: string; + } + export class AstBigIntLiteralData extends AstTokenData { + text: string; + } + export type AstLiteralToken = AstNodeOneOf; + export class AstTemplateHeadData extends AstTokenData { + text: string; + isUnterminated: boolean | undefined; + hasExtendedUnicodeEscape: boolean | undefined; + rawText: string | undefined; + } + export class AstTemplateMiddleData extends AstTokenData { + text: string; + isUnterminated: boolean | undefined; + hasExtendedUnicodeEscape: boolean | undefined; + rawText: string | undefined; + } + export class AstTemplateTailData extends AstTokenData { + text: string; + isUnterminated: boolean | undefined; + hasExtendedUnicodeEscape: boolean | undefined; + rawText: string | undefined; + } + export class AstTemplateExpressionData extends AstData { + head: AstTemplateHead; + templateSpans: AstNodeArray; + } + export class AstTemplateSpanData extends AstData { + expression: AstExpression; + literal: AstTemplateMiddle | AstTemplateTail; + } + export class AstParenthesizedExpressionData extends AstData { + expression: AstExpression; + } + export class AstArrayLiteralExpressionData extends AstData { + elements: AstNodeArray; + } + export class AstSpreadElementData extends AstData { + expression: AstExpression; + } + export type AstObjectLiteralElement = AstNode; + export type AstObjectLiteralElementLike = AstNodeOneOf; + export class AstObjectLiteralExpressionData extends AstData { + properties: AstNodeArray; + } + export class AstPropertyAccessExpressionData extends AstData { + expression: AstLeftHandSideExpression; + questionDotToken: AstQuestionDotToken | undefined; + name: AstMemberName; + } + export type AstPropertyAccessEntityNameExpression = AstNode; + export interface AstPropertyAccessEntityNameExpressionData extends AstPropertyAccessExpressionData { + expression: AstEntityNameExpression; + name: AstIdentifier; + } + export type AstEntityNameExpression = AstNodeOneOf; + export type AstPropertyAccessChain = AstNode; + export class AstElementAccessExpressionData extends AstData { + expression: AstLeftHandSideExpression; + questionDotToken: AstQuestionDotToken | undefined; + argumentExpression: AstExpression; + } + export type AstElementAccessChain = AstNode; + export class AstCallExpressionData extends AstData { + expression: AstLeftHandSideExpression; + questionDotToken: AstQuestionDotToken | undefined; + typeArguments: AstNodeArray | undefined; + arguments: AstNodeArray; + } + export type AstCallChain = AstNode; + export class AstExpressionWithTypeArgumentsData extends AstData { + expression: AstLeftHandSideExpression; + typeArguments: AstNodeArray | undefined; + } + export class AstNewExpressionData extends AstData { + expression: AstLeftHandSideExpression; + typeArguments: AstNodeArray | undefined; + arguments: AstNodeArray | undefined; + } + export type AstTemplateLiteral = AstNodeOneOf; + export class AstTaggedTemplateExpressionData extends AstData { + tag: AstLeftHandSideExpression; + typeArguments: AstNodeArray | undefined; + template: AstTemplateLiteral; + questionDotToken: AstQuestionDotToken | undefined; + } + export class AstAsExpressionData extends AstData { + expression: AstExpression; + type: AstTypeNode; + } + export class AstTypeAssertionData extends AstData { + type: AstTypeNode; + expression: AstUnaryExpression; + } + export class AstSatisfiesExpressionData extends AstData { + expression: AstExpression; + type: AstTypeNode; + } + export class AstNonNullExpressionData extends AstData { + expression: AstExpression; + } + export type AstNonNullChain = AstNode; + export class AstMetaPropertyData extends AstData { + keywordToken: SyntaxKind.NewKeyword | SyntaxKind.ImportKeyword; + name: AstIdentifier; + } + export class AstJsxElementData extends AstData { + openingElement: AstJsxOpeningElement; + children: AstNodeArray; + closingElement: AstJsxClosingElement; + } + export type AstJsxOpeningLikeElement = AstNodeOneOf; + export type AstJsxAttributeLike = AstNodeOneOf; + export type AstJsxAttributeName = AstNodeOneOf; + export type AstJsxTagNameExpression = AstNodeOneOf; + export type AstJsxTagNamePropertyAccess = AstNode; + export interface AstJsxTagNamePropertyAccessData extends AstPropertyAccessExpressionData { + expression: AstIdentifier | AstThisExpression | AstJsxTagNamePropertyAccess; + } + export class AstJsxAttributesData extends AstData { + properties: AstNodeArray; + } + export class AstJsxNamespacedNameData extends AstData { + name: AstIdentifier; + namespace: AstIdentifier; + } + export class AstJsxOpeningElementData extends AstData { + tagName: AstJsxTagNameExpression; + typeArguments: AstNodeArray | undefined; + attributes: AstJsxAttributes; + } + export class AstJsxClosingElementData extends AstData { + tagName: AstJsxTagNameExpression; + } + export class AstJsxSelfClosingElementData extends AstData { + tagName: AstJsxTagNameExpression; + typeArguments: AstNodeArray | undefined; + attributes: AstJsxAttributes; + } + export class AstJsxFragmentData extends AstData { + openingFragment: AstJsxOpeningFragment; + children: AstNodeArray; + closingFragment: AstJsxClosingFragment; + } + export class AstJsxOpeningFragmentData extends AstData { + } + export class AstJsxClosingFragmentData extends AstData { + } + export class AstJsxAttributeData extends AstData { + name: AstJsxAttributeName; + initializer: AstJsxAttributeValue | undefined; + } + export type AstJsxAttributeValue = AstNodeOneOf; + export class AstJsxSpreadAttributeData extends AstData { + expression: AstExpression; + } + export class AstJsxExpressionData extends AstData { + dotDotDotToken: AstDotDotDotToken | undefined; + expression: AstExpression | undefined; + } + export class AstJsxTextData extends AstData { + text: string; + isUnterminated: boolean | undefined; + hasExtendedUnicodeEscape: boolean | undefined; + containsOnlyTriviaWhiteSpaces: boolean; + } + export type AstJsxChild = AstNodeOneOf; + export type AstIterationStatement = AstNodeOneOf; + export class AstEmptyStatementData extends AstData { + } + export class AstDebuggerStatementData extends AstData { + } + export class AstMissingDeclarationData extends AstData { + name: AstIdentifier | undefined; + modifiers: AstNodeArray | undefined; + } + export class AstBlockData extends AstData { + statements: AstNodeArray; + } + export class AstVariableStatementData extends AstData { + modifiers: AstNodeArray | undefined; + declarationList: AstVariableDeclarationList; + } + export class AstExpressionStatementData extends AstData { + expression: AstExpression; + } + export class AstIfStatementData extends AstData { + expression: AstExpression; + thenStatement: AstStatement; + elseStatement: AstStatement | undefined; + } + export class AstDoStatementData extends AstData { + statement: AstStatement; + expression: AstExpression; + } + export class AstWhileStatementData extends AstData { + expression: AstExpression; + statement: AstStatement; + } + export type AstForInitializer = AstNodeOneOf; + export class AstForStatementData extends AstData { + initializer: AstForInitializer | undefined; + condition: AstExpression | undefined; + incrementor: AstExpression | undefined; + statement: AstStatement; + } + export type AstForInOrOfStatement = AstNodeOneOf; + export class AstForInStatementData extends AstData { + initializer: AstForInitializer; + expression: AstExpression; + statement: AstStatement; + } + export class AstForOfStatementData extends AstData { + awaitModifier: AstAwaitKeyword | undefined; + initializer: AstForInitializer; + expression: AstExpression; + statement: AstStatement; + } + export class AstBreakStatementData extends AstData { + label: AstIdentifier | undefined; + } + export type AstBreakOrContinueStatement = AstNodeOneOf; + export class AstContinueStatementData extends AstData { + label: AstIdentifier | undefined; + } + export class AstReturnStatementData extends AstData { + expression: AstExpression | undefined; + } + export class AstWithStatementData extends AstData { + expression: AstExpression; + statement: AstStatement; + } + export class AstSwitchStatementData extends AstData { + expression: AstExpression; + caseBlock: AstCaseBlock; + possiblyExhaustive: boolean | undefined; + } + export class AstCaseBlockData extends AstData { + clauses: AstNodeArray; + } + export class AstCaseClauseData extends AstData { + expression: AstExpression; + statements: AstNodeArray; + } + export class AstDefaultClauseData extends AstData { + statements: AstNodeArray; + } + export type AstCaseOrDefaultClause = AstNodeOneOf; + export class AstLabeledStatementData extends AstData { + label: AstIdentifier; + statement: AstStatement; + } + export class AstThrowStatementData extends AstData { + expression: AstExpression; + } + export class AstTryStatementData extends AstData { + tryBlock: AstBlock; + catchClause: AstCatchClause | undefined; + finallyBlock: AstBlock | undefined; + } + export class AstCatchClauseData extends AstData { + variableDeclaration: AstVariableDeclaration | undefined; + block: AstBlock; + } + export type AstObjectTypeDeclaration = AstNodeOneOf; + export type AstDeclarationWithTypeParameterChildren = AstNodeOneOf; + export type AstClassElement = AstNodeOneOf; + export type AstClassLikeDeclaration = AstNodeOneOf; + export class AstClassDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + /** May be undefined in `export default class { ... }`. */ + name: AstIdentifier | undefined; + typeParameters: AstNodeArray | undefined; + heritageClauses: AstNodeArray | undefined; + members: AstNodeArray; + } + export class AstClassExpressionData extends AstData { + modifiers: AstNodeArray | undefined; + name: AstIdentifier | undefined; + typeParameters: AstNodeArray | undefined; + heritageClauses: AstNodeArray | undefined; + members: AstNodeArray; + } + export type AstTypeElement = AstNode; + export class AstInterfaceDeclarationData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined; + name: AstIdentifier; + typeParameters: AstNodeArray | undefined; + heritageClauses: AstNodeArray | undefined; + members: AstNodeArray; + } + export class AstHeritageClauseData extends AstData { + token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; + types: AstNodeArray; + } + export class AstTypeAliasDeclarationData extends AstTypeScriptNodeData { + modifiers: AstNodeArray | undefined; + name: AstIdentifier; + typeParameters: AstNodeArray | undefined; + type: AstTypeNode; + } + export class AstEnumDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + name: AstIdentifier; + members: AstNodeArray; + } + export class AstEnumMemberData extends AstData { + name: AstPropertyName; + initializer: AstExpression | undefined; + } + export type AstModuleName = AstNodeOneOf; + export type AstModuleBody = AstNodeOneOf; + export class AstModuleDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + name: AstModuleName; + body: AstModuleBody | AstJSDocNamespaceDeclaration | undefined; + } + export type AstNamespaceBody = AstNodeOneOf; + export type AstNamespaceDeclaration = AstNode; + export interface AstNamespaceDeclarationData extends AstModuleDeclarationData { + name: AstIdentifier; + body: AstNamespaceBody; + } + export type AstJSDocNamespaceBody = AstNodeOneOf; + export type AstJSDocNamespaceDeclaration = AstNode; + export interface AstJSDocNamespaceDeclarationData extends AstModuleDeclarationData { + name: AstIdentifier; + body: AstJSDocNamespaceBody | undefined; + } + export class AstModuleBlockData extends AstData { + statements: AstNodeArray; + } + export type AstModuleReference = AstNodeOneOf; + export class AstImportEqualsDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + name: AstIdentifier; + isTypeOnly: boolean; + moduleReference: AstModuleReference; + } + export class AstExternalModuleReferenceData extends AstData { + expression: AstExpression; + } + export class AstImportDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + importClause: AstImportClause | undefined; + /** If this is not a StringLiteral it will be a grammar error. */ + moduleSpecifier: AstExpression; + attributes: AstImportAttributes | undefined; + } + export type AstNamedImportBindings = AstNodeOneOf; + export type AstNamedExportBindings = AstNodeOneOf; + export class AstImportClauseData extends AstData { + isTypeOnly: boolean; + name: AstIdentifier | undefined; + namedBindings: AstNamedImportBindings | undefined; + } + export type AstAssertionKey = AstNodeOneOf; + /** @deprecated */ + export type AstAssertEntry = AstImportAttribute; + export type AstImportAttributeName = AstNodeOneOf; + export class AstImportAttributeData extends AstData { + name: AstImportAttributeName; + value: AstExpression; + } + /** @deprecated */ + export type AstAssertClause = AstNode; + export class AstImportAttributesData extends AstData { + token: SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword; + elements: AstNodeArray; + multiLine: boolean | undefined; + } + export class AstNamespaceImportData extends AstData { + name: AstIdentifier; + } + export class AstNamespaceExportData extends AstData { + name: AstModuleExportName; + } + export class AstNamespaceExportDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + name: AstIdentifier; + } + export class AstExportDeclarationData extends AstData { + modifiers: AstNodeArray | undefined; + isTypeOnly: boolean; + exportClause: AstNamedExportBindings | undefined; + moduleSpecifier: AstExpression | undefined; + attributes: AstImportAttributes | undefined; + } + export class AstNamedImportsData extends AstData { + elements: AstNodeArray; + } + export class AstNamedExportsData extends AstData { + elements: AstNodeArray; + } + export class AstImportSpecifierData extends AstData { + propertyName: AstModuleExportName | undefined; + name: AstIdentifier; + isTypeOnly: boolean; + } + export class AstExportSpecifierData extends AstData { + isTypeOnly: boolean; + propertyName: AstModuleExportName | undefined; + name: AstModuleExportName; + } + export type AstModuleExportName = AstNodeOneOf; + export class AstExportAssignmentData extends AstData { + modifiers: AstNodeArray | undefined; + isExportEquals: boolean | undefined; + expression: AstExpression; + } + export class AstJSDocTypeExpressionData extends AstData { + type: AstTypeNode; + } + export class AstJSDocNameReferenceData extends AstData { + name: AstEntityName | AstJSDocMemberName; + } + export class AstJSDocMemberNameData extends AstData { + left: AstEntityName | AstJSDocMemberName; + right: AstIdentifier; + } + export type AstJSDocType = AstNodeOneOf; + export class AstJSDocAllTypeData extends AstData { + } + export class AstJSDocUnknownTypeData extends AstData { + } + export class AstJSDocNonNullableTypeData extends AstData { + type: AstTypeNode; + postfix: boolean; + } + export class AstJSDocNullableTypeData extends AstData { + type: AstTypeNode; + postfix: boolean; + } + export class AstJSDocOptionalTypeData extends AstData { + type: AstTypeNode; + } + export class AstJSDocFunctionTypeData extends AstData { + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstTypeNode | undefined; + } + export class AstJSDocVariadicTypeData extends AstData { + type: AstTypeNode; + } + export class AstJSDocNamepathTypeData extends AstData { + type: AstTypeNode; + } + export class AstJSDocData extends AstData { + comment: string | AstNodeArray | undefined; + tags: AstNodeArray | undefined; + } + export type AstHasJSDoc = AstNodeOneOf; + export type AstJSDocTag = AstNodeOneOf; + export class AstJSDocLinkData extends AstData { + name: AstEntityName | AstJSDocMemberName | undefined; + text: string; + } + export class AstJSDocLinkCodeData extends AstData { + name: AstEntityName | AstJSDocMemberName | undefined; + text: string; + } + export class AstJSDocLinkPlainData extends AstData { + name: AstEntityName | AstJSDocMemberName | undefined; + text: string; + } + export type AstJSDocComment = AstNodeOneOf; + export class AstJSDocTextData extends AstData { + text: string; + } + export type AstBaseJSDocTag = AstNode>; + export class AstJSDocTagData extends AstData { + tagName: AstIdentifier; + comment: string | AstNodeArray | undefined; + } + export class AstJSDocUnknownTagData extends AstJSDocTagData { + } + export type AstJSDocClassReference = AstNode; + export interface AstJSDocClassReferenceData extends AstExpressionWithTypeArgumentsData { + expression: AstIdentifier | AstPropertyAccessEntityNameExpression; + } + export class AstJSDocAugmentsTagData extends AstJSDocTagData { + class: AstJSDocClassReference; + } + export class AstJSDocImplementsTagData extends AstJSDocTagData { + class: AstJSDocClassReference; + } + export class AstJSDocAuthorTagData extends AstJSDocTagData { + } + export class AstJSDocDeprecatedTagData extends AstJSDocTagData { + } + export class AstJSDocClassTagData extends AstJSDocTagData { + } + export class AstJSDocPublicTagData extends AstJSDocTagData { + } + export class AstJSDocPrivateTagData extends AstJSDocTagData { + } + export class AstJSDocProtectedTagData extends AstJSDocTagData { + } + export class AstJSDocReadonlyTagData extends AstJSDocTagData { + } + export class AstJSDocOverrideTagData extends AstJSDocTagData { + } + export class AstJSDocEnumTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression; + } + export class AstJSDocThisTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression; + } + export class AstJSDocTemplateTagData extends AstJSDocTagData { + constraint: AstJSDocTypeExpression | undefined; + typeParameters: AstNodeArray; + } + export class AstJSDocSeeTagData extends AstJSDocTagData { + name: AstJSDocNameReference | undefined; + } + export class AstJSDocReturnTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression | undefined; + } + export class AstJSDocTypeTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression; + } + export class AstJSDocTypedefTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression | AstJSDocTypeLiteral | undefined; + fullName: AstJSDocNamespaceDeclaration | AstIdentifier | undefined; + name: AstIdentifier | undefined; + } + export class AstJSDocCallbackTagData extends AstJSDocTagData { + fullName: AstJSDocNamespaceDeclaration | AstIdentifier | undefined; + name: AstIdentifier | undefined; + typeExpression: AstJSDocSignature; + } + export class AstJSDocOverloadTagData extends AstJSDocTagData { + typeExpression: AstJSDocSignature; + } + export class AstJSDocThrowsTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression | undefined; + } + export class AstJSDocSignatureData extends AstData { + typeParameters: AstNodeArray | undefined; + parameters: AstNodeArray; + type: AstJSDocReturnTag | undefined; + } + export class AstJSDocPropertyTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression | undefined; + name: AstEntityName; + /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ + isNameFirst: boolean; + isBracketed: boolean; + } + export class AstJSDocParameterTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression | undefined; + name: AstEntityName; + /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ + isNameFirst: boolean; + isBracketed: boolean; + } + export type AstJSDocPropertyLikeTag = AstNodeOneOf; + export class AstJSDocTypeLiteralData extends AstData { + jsDocPropertyTags: AstNodeArray | undefined; + /** If true, then this type literal represents an *array* of its type. */ + isArrayType: boolean; + } + export class AstJSDocSatisfiesTagData extends AstJSDocTagData { + typeExpression: AstJSDocTypeExpression; + } + export class AstJSDocImportTagData extends AstJSDocTagData { + importClause: AstImportClause | undefined; + moduleSpecifier: AstExpression; + attributes: AstImportAttributes | undefined; + } + export class AstSyntheticExpressionData extends AstData { + isSpread: boolean; + type: Type; + tupleNameSource: AstParameterDeclaration | AstNamedTupleMember | undefined; + } + export class AstBundleData extends AstData { + sourceFiles: readonly SourceFile[]; + } + export class AstSyntaxListData extends AstData { + } + export class AstNotEmittedStatementData extends AstData { + } + export class AstNotEmittedTypeElementData extends AstData { + } + export class AstPartiallyEmittedExpressionData extends AstData { + expression: AstExpression; + } + export class AstCommaListExpressionData extends AstData { + elements: AstNodeArray; + } + export class AstDeclarationData { + } + export class AstSourceFileData extends AstData { + declaration: AstDeclarationData; + statements: AstNodeArray; + endOfFileToken: AstEndOfFileToken; + text: string; + fileName: string; + languageVersion: ScriptTarget; + languageVariant: LanguageVariant; + isDeclarationFile: boolean; + /** + * lib.d.ts should have a reference comment like + * + * /// + * + * If any other file has this comment, it signals not to include lib.d.ts + * because this containing file is intended to act as a default library. + */ + hasNoDefaultLib: boolean; + referencedFiles: readonly FileReference[]; + typeReferenceDirectives: readonly FileReference[]; + libReferenceDirectives: readonly FileReference[]; + amdDependencies: AmdDependency[]; + /** + * When `module` is `Node16` or `NodeNext`, this field controls whether the + * source file in question is an ESNext-output-format file, or a CommonJS-output-format + * module. This is derived by the module resolver as it looks up the file, since + * it is derived from either the file extension of the module, or the containing + * `package.json` context, and affects both checking and emit. + * + * It is _public_ so that (pre)transformers can set this field, + * since it switches the builtin `node` module transform. Generally speaking, if unset, + * the field is treated as though it is `ModuleKind.CommonJS`. + * + * Note that this field is only set by the module resolution process when + * `moduleResolution` is `Node16` or `NodeNext`, which is implied by the `module` setting + * of `Node16` or `NodeNext`, respectively, but may be overriden (eg, by a `moduleResolution` + * of `node`). If so, this field will be unset and source files will be considered to be + * CommonJS-output-format by the node module transformer and type checker, regardless of extension or context. + */ + impliedNodeFormat: ResolutionMode | undefined; + moduleName: string | undefined; + namedDeclarations: Map | undefined; + cloneNode(node: AstNode): AstNode; + } + export type AstToken = AstNode>; + export type AstEndOfFileToken = AstNode; + export type AstThisExpression = AstNode; + export type AstSuperExpression = AstNode; + export type AstImportExpression = AstNode; + export type AstNullLiteral = AstNode; + export type AstTrueLiteral = AstNode; + export type AstFalseLiteral = AstNode; + export type AstIdentifier = AstNode; + export type AstQualifiedName = AstNode; + export type AstComputedPropertyName = AstNode; + export type AstPrivateIdentifier = AstNode; + export type AstTypeParameterDeclaration = AstNode; + export type AstParameterDeclaration = AstNode; + export type AstDecorator = AstNode; + export type AstPropertySignature = AstNode; + export type AstCallSignatureDeclaration = AstNode; + export type AstConstructSignatureDeclaration = AstNode; + export type AstVariableDeclaration = AstNode; + export type AstVariableDeclarationList = AstNode; + export type AstBindingElement = AstNode; + export type AstPropertyDeclaration = AstNode; + export type AstPropertyAssignment = AstNode; + export type AstShorthandPropertyAssignment = AstNode; + export type AstSpreadAssignment = AstNode; + export type AstObjectBindingPattern = AstNode; + export type AstArrayBindingPattern = AstNode; + export type AstFunctionDeclaration = AstNode; + export type AstMethodSignature = AstNode; + export type AstMethodDeclaration = AstNode; + export type AstConstructorDeclaration = AstNode; + export type AstSemicolonClassElement = AstNode; + export type AstGetAccessorDeclaration = AstNode; + export type AstSetAccessorDeclaration = AstNode; + export type AstIndexSignatureDeclaration = AstNode; + export type AstClassStaticBlockDeclaration = AstNode; + export type AstImportTypeNode = AstNode; + export type AstThisTypeNode = AstNode; + export type AstFunctionTypeNode = AstNode; + export type AstConstructorTypeNode = AstNode; + export type AstTypeReferenceNode = AstNode; + export type AstTypePredicateNode = AstNode; + export type AstTypeQueryNode = AstNode; + export type AstTypeLiteralNode = AstNode; + export type AstArrayTypeNode = AstNode; + export type AstTupleTypeNode = AstNode; + export type AstNamedTupleMember = AstNode; + export type AstOptionalTypeNode = AstNode; + export type AstRestTypeNode = AstNode; + export type AstUnionTypeNode = AstNode; + export type AstIntersectionTypeNode = AstNode; + export type AstConditionalTypeNode = AstNode; + export type AstInferTypeNode = AstNode; + export type AstParenthesizedTypeNode = AstNode; + export type AstTypeOperatorNode = AstNode; + export type AstIndexedAccessTypeNode = AstNode; + export type AstMappedTypeNode = AstNode; + export type AstLiteralTypeNode = AstNode; + export type AstStringLiteral = AstNode; + export type AstTemplateLiteralTypeNode = AstNode; + export type AstTemplateLiteralTypeSpan = AstNode; + export type AstOmittedExpression = AstNode; + export type AstPrefixUnaryExpression = AstNode; + export type AstPostfixUnaryExpression = AstNode; + export type AstDeleteExpression = AstNode; + export type AstTypeOfExpression = AstNode; + export type AstVoidExpression = AstNode; + export type AstAwaitExpression = AstNode; + export type AstYieldExpression = AstNode; + export type AstBinaryExpression = AstNode; + export type AstConditionalExpression = AstNode; + export type AstFunctionExpression = AstNode; + export type AstArrowFunction = AstNode; + export type AstRegularExpressionLiteral = AstNode; + export type AstNoSubstitutionTemplateLiteral = AstNode; + export type AstNumericLiteral = AstNode; + export type AstBigIntLiteral = AstNode; + export type AstTemplateHead = AstNode; + export type AstTemplateMiddle = AstNode; + export type AstTemplateTail = AstNode; + export type AstTemplateExpression = AstNode; + export type AstTemplateSpan = AstNode; + export type AstParenthesizedExpression = AstNode; + export type AstArrayLiteralExpression = AstNode; + export type AstSpreadElement = AstNode; + export type AstObjectLiteralExpression = AstNode; + export type AstPropertyAccessExpression = AstNode; + export type AstElementAccessExpression = AstNode; + export type AstCallExpression = AstNode; + export type AstExpressionWithTypeArguments = AstNode; + export type AstNewExpression = AstNode; + export type AstTaggedTemplateExpression = AstNode; + export type AstAsExpression = AstNode; + export type AstTypeAssertion = AstNode; + export type AstSatisfiesExpression = AstNode; + export type AstNonNullExpression = AstNode; + export type AstMetaProperty = AstNode; + export type AstJsxElement = AstNode; + export type AstJsxAttributes = AstNode; + export type AstJsxNamespacedName = AstNode; + export type AstJsxOpeningElement = AstNode; + export type AstJsxSelfClosingElement = AstNode; + export type AstJsxFragment = AstNode; + export type AstJsxOpeningFragment = AstNode; + export type AstJsxClosingFragment = AstNode; + export type AstJsxAttribute = AstNode; + export type AstJsxSpreadAttribute = AstNode; + export type AstJsxClosingElement = AstNode; + export type AstJsxExpression = AstNode; + export type AstJsxText = AstNode; + export type AstEmptyStatement = AstNode; + export type AstDebuggerStatement = AstNode; + export type AstMissingDeclaration = AstNode; + export type AstBlock = AstNode; + export type AstVariableStatement = AstNode; + export type AstExpressionStatement = AstNode; + export type AstIfStatement = AstNode; + export type AstDoStatement = AstNode; + export type AstWhileStatement = AstNode; + export type AstForStatement = AstNode; + export type AstForInStatement = AstNode; + export type AstForOfStatement = AstNode; + export type AstBreakStatement = AstNode; + export type AstContinueStatement = AstNode; + export type AstReturnStatement = AstNode; + export type AstWithStatement = AstNode; + export type AstSwitchStatement = AstNode; + export type AstCaseBlock = AstNode; + export type AstCaseClause = AstNode; + export type AstDefaultClause = AstNode; + export type AstLabeledStatement = AstNode; + export type AstThrowStatement = AstNode; + export type AstTryStatement = AstNode; + export type AstCatchClause = AstNode; + export type AstClassDeclaration = AstNode; + export type AstClassExpression = AstNode; + export type AstInterfaceDeclaration = AstNode; + export type AstHeritageClause = AstNode; + export type AstTypeAliasDeclaration = AstNode; + export type AstEnumMember = AstNode; + export type AstEnumDeclaration = AstNode; + export type AstModuleDeclaration = AstNode; + export type AstModuleBlock = AstNode; + export type AstImportEqualsDeclaration = AstNode; + export type AstExternalModuleReference = AstNode; + export type AstImportDeclaration = AstNode; + export type AstImportClause = AstNode; + export type AstImportAttribute = AstNode; + export type AstImportAttributes = AstNode; + export type AstNamespaceImport = AstNode; + export type AstNamespaceExport = AstNode; + export type AstNamespaceExportDeclaration = AstNode; + export type AstExportDeclaration = AstNode; + export type AstNamedImports = AstNode; + export type AstNamedExports = AstNode; + export type AstImportSpecifier = AstNode; + export type AstExportSpecifier = AstNode; + export type AstExportAssignment = AstNode; + export type AstJSDocTypeExpression = AstNode; + export type AstJSDocNameReference = AstNode; + export type AstJSDocMemberName = AstNode; + export type AstJSDocAllType = AstNode; + export type AstJSDocUnknownType = AstNode; + export type AstJSDocNonNullableType = AstNode; + export type AstJSDocNullableType = AstNode; + export type AstJSDocOptionalType = AstNode; + export type AstJSDocFunctionType = AstNode; + export type AstJSDocVariadicType = AstNode; + export type AstJSDocNamepathType = AstNode; + export type AstJSDoc = AstNode; + export type AstJSDocLink = AstNode; + export type AstJSDocLinkCode = AstNode; + export type AstJSDocLinkPlain = AstNode; + export type AstJSDocText = AstNode; + export type AstJSDocUnknownTag = AstNode; + export type AstJSDocAugmentsTag = AstNode; + export type AstJSDocImplementsTag = AstNode; + export type AstJSDocAuthorTag = AstNode; + export type AstJSDocDeprecatedTag = AstNode; + export type AstJSDocClassTag = AstNode; + export type AstJSDocPublicTag = AstNode; + export type AstJSDocPrivateTag = AstNode; + export type AstJSDocProtectedTag = AstNode; + export type AstJSDocReadonlyTag = AstNode; + export type AstJSDocOverrideTag = AstNode; + export type AstJSDocEnumTag = AstNode; + export type AstJSDocThisTag = AstNode; + export type AstJSDocTemplateTag = AstNode; + export type AstJSDocSeeTag = AstNode; + export type AstJSDocReturnTag = AstNode; + export type AstJSDocTypeTag = AstNode; + export type AstJSDocTypedefTag = AstNode; + export type AstJSDocCallbackTag = AstNode; + export type AstJSDocOverloadTag = AstNode; + export type AstJSDocThrowsTag = AstNode; + export type AstJSDocSignature = AstNode; + export type AstJSDocPropertyTag = AstNode; + export type AstJSDocParameterTag = AstNode; + export type AstJSDocTypeLiteral = AstNode; + export type AstJSDocSatisfiesTag = AstNode; + export type AstJSDocImportTag = AstNode; + export type AstSourceFile = AstNode; + export type AstSyntheticExpression = AstNode; + export type AstBundle = AstNode; + export type AstSyntaxList = AstNode; + export type AstNotEmittedStatement = AstNode; + export type AstNotEmittedTypeElement = AstNode; + export type AstPartiallyEmittedExpression = AstNode; + export type AstCommaListExpression = AstNode; + export interface AstJsonMinusNumericLiteralData extends AstPrefixUnaryExpressionData { + operator: SyntaxKind.MinusToken; + operand: AstNumericLiteral; + } + export type AstJsonMinusNumericLiteral = AstNode; + export type AstJsonObjectExpression = AstNodeOneOf; + export type AstJsonObjectExpressionStatement = AstNode; + export interface AstJsonObjectExpressionStatementData extends AstExpressionStatementData { + expression: AstJsonObjectExpression; + } + export type AstJsonSourceFile = AstNode; + export interface AstJsonSourceFileData extends AstSourceFileData { + statements: AstNodeArray; + } + export enum FileWatcherEventKind { Created = 0, Changed = 1, Deleted = 2, } - type FileWatcherCallback = (fileName: string, eventKind: FileWatcherEventKind, modifiedTime?: Date) => void; - type DirectoryWatcherCallback = (fileName: string) => void; - type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"; - interface System { + export type FileWatcherCallback = (fileName: string, eventKind: FileWatcherEventKind, modifiedTime?: Date) => void; + export type DirectoryWatcherCallback = (fileName: string) => void; + export type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"; + export interface System { args: string[]; newLine: string; useCaseSensitiveFileNames: boolean; @@ -8394,33 +10776,33 @@ declare namespace ts { base64decode?(input: string): string; base64encode?(input: string): string; } - interface FileWatcher { + export interface FileWatcher { close(): void; } - let sys: System; - function tokenToString(t: SyntaxKind): string | undefined; - function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number): number; - function getLineAndCharacterOfPosition(sourceFile: SourceFileLike, position: number): LineAndCharacter; - function isWhiteSpaceLike(ch: number): boolean; + export let sys: System; + export function tokenToString(t: SyntaxKind): string | undefined; + export function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number): number; + export function getLineAndCharacterOfPosition(sourceFile: SourceFileLike, position: number): LineAndCharacter; + export function isWhiteSpaceLike(ch: number): boolean; /** Does not include line breaks. For that, see isWhiteSpaceLike. */ - function isWhiteSpaceSingleLine(ch: number): boolean; - function isLineBreak(ch: number): boolean; - function couldStartTrivia(text: string, pos: number): boolean; - function forEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined; - function forEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; - function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined; - function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; - function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T, initial: U): U | undefined; - function reduceEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T, initial: U): U | undefined; - function getLeadingCommentRanges(text: string, pos: number): CommentRange[] | undefined; - function getTrailingCommentRanges(text: string, pos: number): CommentRange[] | undefined; + export function isWhiteSpaceSingleLine(ch: number): boolean; + export function isLineBreak(ch: number): boolean; + export function couldStartTrivia(text: string, pos: number): boolean; + export function forEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined; + export function forEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; + export function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined; + export function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; + export function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T, initial: U): U | undefined; + export function reduceEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T, initial: U): U | undefined; + export function getLeadingCommentRanges(text: string, pos: number): CommentRange[] | undefined; + export function getTrailingCommentRanges(text: string, pos: number): CommentRange[] | undefined; /** Optionally, get the shebang */ - function getShebang(text: string): string | undefined; - function isIdentifierStart(ch: number, languageVersion: ScriptTarget | undefined): boolean; - function isIdentifierPart(ch: number, languageVersion: ScriptTarget | undefined, identifierVariant?: LanguageVariant): boolean; - function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, languageVariant?: LanguageVariant, textInitial?: string, onError?: ErrorCallback, start?: number, length?: number): Scanner; - type ErrorCallback = (message: DiagnosticMessage, length: number, arg0?: any) => void; - interface Scanner { + export function getShebang(text: string): string | undefined; + export function isIdentifierStart(ch: number, languageVersion: ScriptTarget | undefined): boolean; + export function isIdentifierPart(ch: number, languageVersion: ScriptTarget | undefined, identifierVariant?: LanguageVariant): boolean; + export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, languageVariant?: LanguageVariant, textInitial?: string, onError?: ErrorCallback, start?: number, length?: number): Scanner; + export type ErrorCallback = (message: DiagnosticMessage, length: number, arg0?: any) => void; + export interface Scanner { /** @deprecated use {@link getTokenFullStart} */ getStartPos(): number; getToken(): SyntaxKind; @@ -8470,25 +10852,25 @@ declare namespace ts { scanRange(start: number, length: number, callback: () => T): T; tryScan(callback: () => T): T; } - function isExternalModuleNameRelative(moduleName: string): boolean; - function sortAndDeduplicateDiagnostics(diagnostics: readonly T[]): SortedReadonlyArray; - function getDefaultLibFileName(options: CompilerOptions): string; - function textSpanEnd(span: TextSpan): number; - function textSpanIsEmpty(span: TextSpan): boolean; - function textSpanContainsPosition(span: TextSpan, position: number): boolean; - function textSpanContainsTextSpan(span: TextSpan, other: TextSpan): boolean; - function textSpanOverlapsWith(span: TextSpan, other: TextSpan): boolean; - function textSpanOverlap(span1: TextSpan, span2: TextSpan): TextSpan | undefined; - function textSpanIntersectsWithTextSpan(span: TextSpan, other: TextSpan): boolean; - function textSpanIntersectsWith(span: TextSpan, start: number, length: number): boolean; - function decodedTextSpanIntersectsWith(start1: number, length1: number, start2: number, length2: number): boolean; - function textSpanIntersectsWithPosition(span: TextSpan, position: number): boolean; - function textSpanIntersection(span1: TextSpan, span2: TextSpan): TextSpan | undefined; - function createTextSpan(start: number, length: number): TextSpan; - function createTextSpanFromBounds(start: number, end: number): TextSpan; - function textChangeRangeNewSpan(range: TextChangeRange): TextSpan; - function textChangeRangeIsUnchanged(range: TextChangeRange): boolean; - function createTextChangeRange(span: TextSpan, newLength: number): TextChangeRange; + export function isExternalModuleNameRelative(moduleName: string): boolean; + export function sortAndDeduplicateDiagnostics(diagnostics: readonly T[]): SortedReadonlyArray; + export function getDefaultLibFileName(options: CompilerOptions): string; + export function textSpanEnd(span: TextSpan): number; + export function textSpanIsEmpty(span: TextSpan): boolean; + export function textSpanContainsPosition(span: TextSpan, position: number): boolean; + export function textSpanContainsTextSpan(span: TextSpan, other: TextSpan): boolean; + export function textSpanOverlapsWith(span: TextSpan, other: TextSpan): boolean; + export function textSpanOverlap(span1: TextSpan, span2: TextSpan): TextSpan | undefined; + export function textSpanIntersectsWithTextSpan(span: TextSpan, other: TextSpan): boolean; + export function textSpanIntersectsWith(span: TextSpan, start: number, length: number): boolean; + export function decodedTextSpanIntersectsWith(start1: number, length1: number, start2: number, length2: number): boolean; + export function textSpanIntersectsWithPosition(span: TextSpan, position: number): boolean; + export function textSpanIntersection(span1: TextSpan, span2: TextSpan): TextSpan | undefined; + export function createTextSpan(start: number, length: number): TextSpan; + export function createTextSpanFromBounds(start: number, end: number): TextSpan; + export function textChangeRangeNewSpan(range: TextChangeRange): TextSpan; + export function textChangeRangeIsUnchanged(range: TextChangeRange): boolean; + export function createTextChangeRange(span: TextSpan, newLength: number): TextChangeRange; /** * Called to merge all the changes that occurred across several versions of a script snapshot * into a single change. i.e. if a user keeps making successive edits to a script we will @@ -8497,49 +10879,49 @@ declare namespace ts { * This function will then merge those changes into a single change range valid between V1 and * Vn. */ - function collapseTextChangeRangesAcrossMultipleVersions(changes: readonly TextChangeRange[]): TextChangeRange; - function getTypeParameterOwner(d: Declaration): Declaration | undefined; - function isParameterPropertyDeclaration(node: Node, parent: Node): node is ParameterPropertyDeclaration; - function isEmptyBindingPattern(node: BindingName): node is BindingPattern; - function isEmptyBindingElement(node: BindingElement | ArrayBindingElement): boolean; - function walkUpBindingElementsAndPatterns(binding: BindingElement): VariableDeclaration | ParameterDeclaration; - function getCombinedModifierFlags(node: Declaration): ModifierFlags; - function getCombinedNodeFlags(node: Node): NodeFlags; + export function collapseTextChangeRangesAcrossMultipleVersions(changes: readonly TextChangeRange[]): TextChangeRange; + export function getTypeParameterOwner(d: Declaration): Declaration | undefined; + export function isParameterPropertyDeclaration(node: Node, parent: Node): node is ParameterPropertyDeclaration; + export function isEmptyBindingPattern(node: BindingName): node is BindingPattern; + export function isEmptyBindingElement(node: BindingElement | ArrayBindingElement): boolean; + export function walkUpBindingElementsAndPatterns(binding: BindingElement): VariableDeclaration | ParameterDeclaration; + export function getCombinedModifierFlags(node: Declaration): ModifierFlags; + export function getCombinedNodeFlags(node: Node): NodeFlags; /** * Checks to see if the locale is in the appropriate format, * and if it is, attempts to set the appropriate language. */ - function validateLocaleAndSetLanguage(locale: string, sys: { + export function validateLocaleAndSetLanguage(locale: string, sys: { getExecutingFilePath(): string; resolvePath(path: string): string; fileExists(fileName: string): boolean; readFile(fileName: string): string | undefined; }, errors?: Diagnostic[]): void; - function getOriginalNode(node: Node): Node; - function getOriginalNode(node: Node, nodeTest: (node: Node) => node is T): T; - function getOriginalNode(node: Node | undefined): Node | undefined; - function getOriginalNode(node: Node | undefined, nodeTest: (node: Node) => node is T): T | undefined; + export function getOriginalNode(node: Node): Node; + export function getOriginalNode(node: Node, nodeTest: (node: Node) => node is T): T; + export function getOriginalNode(node: Node | undefined): Node | undefined; + export function getOriginalNode(node: Node | undefined, nodeTest: (node: Node) => node is T): T | undefined; /** * Iterates through the parent chain of a node and performs the callback on each parent until the callback * returns a truthy value, then returns that value. * If no such value is found, it applies the callback until the parent pointer is undefined or the callback returns "quit" * At that point findAncestor returns undefined. */ - function findAncestor(node: Node | undefined, callback: (element: Node) => element is T): T | undefined; - function findAncestor(node: Node | undefined, callback: (element: Node) => boolean | "quit"): Node | undefined; + export function findAncestor(node: Node | undefined, callback: (element: Node) => element is T): T | undefined; + export function findAncestor(node: Node | undefined, callback: (element: Node) => boolean | "quit"): Node | undefined; /** * Gets a value indicating whether a node originated in the parse tree. * * @param node The node to test. */ - function isParseTreeNode(node: Node): boolean; + export function isParseTreeNode(node: Node): boolean; /** * Gets the original parse tree node for a node. * * @param node The original node. * @returns The original parse tree node if found; otherwise, undefined. */ - function getParseTreeNode(node: Node | undefined): Node | undefined; + export function getParseTreeNode(node: Node | undefined): Node | undefined; /** * Gets the original parse tree node for a node. * @@ -8547,27 +10929,27 @@ declare namespace ts { * @param nodeTest A callback used to ensure the correct type of parse tree node is returned. * @returns The original parse tree node if found; otherwise, undefined. */ - function getParseTreeNode(node: T | undefined, nodeTest?: (node: Node) => node is T): T | undefined; + export function getParseTreeNode(node: T | undefined, nodeTest?: (node: Node) => node is T): T | undefined; /** Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' */ - function escapeLeadingUnderscores(identifier: string): __String; + export function escapeLeadingUnderscores(identifier: string): __String; /** * Remove extra underscore from escaped identifier text content. * * @param identifier The escaped identifier text. * @returns The unescaped identifier text. */ - function unescapeLeadingUnderscores(identifier: __String): string; - function idText(identifierOrPrivateName: Identifier | PrivateIdentifier): string; + export function unescapeLeadingUnderscores(identifier: __String): string; + export function idText(identifierOrPrivateName: Identifier | PrivateIdentifier): string; /** * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the * SyntaxKind for the matching keyword. */ - function identifierToKeywordKind(node: Identifier): KeywordSyntaxKind | undefined; - function symbolName(symbol: Symbol): string; - function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | PrivateIdentifier | undefined; - function getNameOfDeclaration(declaration: Declaration | Expression | undefined): DeclarationName | undefined; - function getDecorators(node: HasDecorators): readonly Decorator[] | undefined; - function getModifiers(node: HasModifiers): readonly Modifier[] | undefined; + export function identifierToKeywordKind(node: Identifier): KeywordSyntaxKind | undefined; + export function symbolName(symbol: Symbol): string; + export function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | PrivateIdentifier | undefined; + export function getNameOfDeclaration(declaration: Declaration | Expression | undefined): DeclarationName | undefined; + export function getDecorators(node: HasDecorators): readonly Decorator[] | undefined; + export function getModifiers(node: HasModifiers): readonly Modifier[] | undefined; /** * Gets the JSDoc parameter tags for the node if present. * @@ -8580,7 +10962,7 @@ declare namespace ts { * * For binding patterns, parameter tags are matched by position. */ - function getJSDocParameterTags(param: ParameterDeclaration): readonly JSDocParameterTag[]; + export function getJSDocParameterTags(param: ParameterDeclaration): readonly JSDocParameterTag[]; /** * Gets the JSDoc type parameter tags for the node if present. * @@ -8591,42 +10973,42 @@ declare namespace ts { * node are returned first, so in the previous example, the template * tag on the containing function expression would be first. */ - function getJSDocTypeParameterTags(param: TypeParameterDeclaration): readonly JSDocTemplateTag[]; + export function getJSDocTypeParameterTags(param: TypeParameterDeclaration): readonly JSDocTemplateTag[]; /** * Return true if the node has JSDoc parameter tags. * * @remarks Includes parameter tags that are not directly on the node, * for example on a variable declaration whose initializer is a function expression. */ - function hasJSDocParameterTags(node: FunctionLikeDeclaration | SignatureDeclaration): boolean; + export function hasJSDocParameterTags(node: FunctionLikeDeclaration | SignatureDeclaration): boolean; /** Gets the JSDoc augments tag for the node if present */ - function getJSDocAugmentsTag(node: Node): JSDocAugmentsTag | undefined; + export function getJSDocAugmentsTag(node: Node): JSDocAugmentsTag | undefined; /** Gets the JSDoc implements tags for the node if present */ - function getJSDocImplementsTags(node: Node): readonly JSDocImplementsTag[]; + export function getJSDocImplementsTags(node: Node): readonly JSDocImplementsTag[]; /** Gets the JSDoc class tag for the node if present */ - function getJSDocClassTag(node: Node): JSDocClassTag | undefined; + export function getJSDocClassTag(node: Node): JSDocClassTag | undefined; /** Gets the JSDoc public tag for the node if present */ - function getJSDocPublicTag(node: Node): JSDocPublicTag | undefined; + export function getJSDocPublicTag(node: Node): JSDocPublicTag | undefined; /** Gets the JSDoc private tag for the node if present */ - function getJSDocPrivateTag(node: Node): JSDocPrivateTag | undefined; + export function getJSDocPrivateTag(node: Node): JSDocPrivateTag | undefined; /** Gets the JSDoc protected tag for the node if present */ - function getJSDocProtectedTag(node: Node): JSDocProtectedTag | undefined; + export function getJSDocProtectedTag(node: Node): JSDocProtectedTag | undefined; /** Gets the JSDoc protected tag for the node if present */ - function getJSDocReadonlyTag(node: Node): JSDocReadonlyTag | undefined; - function getJSDocOverrideTagNoCache(node: Node): JSDocOverrideTag | undefined; + export function getJSDocReadonlyTag(node: Node): JSDocReadonlyTag | undefined; + export function getJSDocOverrideTagNoCache(node: Node): JSDocOverrideTag | undefined; /** Gets the JSDoc deprecated tag for the node if present */ - function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; + export function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc enum tag for the node if present */ - function getJSDocEnumTag(node: Node): JSDocEnumTag | undefined; + export function getJSDocEnumTag(node: Node): JSDocEnumTag | undefined; /** Gets the JSDoc this tag for the node if present */ - function getJSDocThisTag(node: Node): JSDocThisTag | undefined; + export function getJSDocThisTag(node: Node): JSDocThisTag | undefined; /** Gets the JSDoc return tag for the node if present */ - function getJSDocReturnTag(node: Node): JSDocReturnTag | undefined; + export function getJSDocReturnTag(node: Node): JSDocReturnTag | undefined; /** Gets the JSDoc template tag for the node if present */ - function getJSDocTemplateTag(node: Node): JSDocTemplateTag | undefined; - function getJSDocSatisfiesTag(node: Node): JSDocSatisfiesTag | undefined; + export function getJSDocTemplateTag(node: Node): JSDocTemplateTag | undefined; + export function getJSDocSatisfiesTag(node: Node): JSDocSatisfiesTag | undefined; /** Gets the JSDoc type tag for the node if present and valid */ - function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined; + export function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined; /** * Gets the type node for the node if provided via JSDoc. * @@ -8638,22 +11020,22 @@ declare namespace ts { * node are examined first, so in the previous example, the type * tag directly on the node would be returned. */ - function getJSDocType(node: Node): TypeNode | undefined; + export function getJSDocType(node: Node): TypeNode | undefined; /** * Gets the return type node for the node if provided via JSDoc return tag or type tag. * * @remarks `getJSDocReturnTag` just gets the whole JSDoc tag. This function * gets the type from inside the braces, after the fat arrow, etc. */ - function getJSDocReturnType(node: Node): TypeNode | undefined; + export function getJSDocReturnType(node: Node): TypeNode | undefined; /** Get all JSDoc tags related to a node, including those on parent nodes. */ - function getJSDocTags(node: Node): readonly JSDocTag[]; + export function getJSDocTags(node: Node): readonly JSDocTag[]; /** Gets all JSDoc tags that match a specified predicate */ - function getAllJSDocTags(node: Node, predicate: (tag: JSDocTag) => tag is T): readonly T[]; + export function getAllJSDocTags(node: Node, predicate: (tag: JSDocTag) => tag is T): readonly T[]; /** Gets all JSDoc tags of a specified kind */ - function getAllJSDocTagsOfKind(node: Node, kind: SyntaxKind): readonly JSDocTag[]; + export function getAllJSDocTagsOfKind(node: Node, kind: SyntaxKind): readonly JSDocTag[]; /** Gets the text of a jsdoc comment, flattening links to their text. */ - function getTextOfJSDocComment(comment?: string | NodeArray): string | undefined; + export function getTextOfJSDocComment(comment?: string | NodeArray): string | undefined; /** * Gets the effective type parameters. If the node was parsed in a * JavaScript file, gets the type parameters from the `@template` tag from JSDoc. @@ -8664,107 +11046,107 @@ declare namespace ts { * /** @type {Id} / * function id(x) { return x } */ - function getEffectiveTypeParameterDeclarations(node: DeclarationWithTypeParameters): readonly TypeParameterDeclaration[]; - function getEffectiveConstraintOfTypeParameter(node: TypeParameterDeclaration): TypeNode | undefined; - function isMemberName(node: Node): node is MemberName; - function isPropertyAccessChain(node: Node): node is PropertyAccessChain; - function isElementAccessChain(node: Node): node is ElementAccessChain; - function isCallChain(node: Node): node is CallChain; - function isOptionalChain(node: Node): node is PropertyAccessChain | ElementAccessChain | CallChain | NonNullChain; - function isNullishCoalesce(node: Node): boolean; - function isConstTypeReference(node: Node): boolean; - function skipPartiallyEmittedExpressions(node: Expression): Expression; - function skipPartiallyEmittedExpressions(node: Node): Node; - function isNonNullChain(node: Node): node is NonNullChain; - function isBreakOrContinueStatement(node: Node): node is BreakOrContinueStatement; - function isNamedExportBindings(node: Node): node is NamedExportBindings; - function isJSDocPropertyLikeTag(node: Node): node is JSDocPropertyLikeTag; + export function getEffectiveTypeParameterDeclarations(node: DeclarationWithTypeParameters): readonly TypeParameterDeclaration[]; + export function getEffectiveConstraintOfTypeParameter(node: TypeParameterDeclaration): TypeNode | undefined; + export function isMemberName(node: Node): node is MemberName; + export function isPropertyAccessChain(node: Node): node is PropertyAccessChain; + export function isElementAccessChain(node: Node): node is ElementAccessChain; + export function isCallChain(node: Node): node is CallChain; + export function isOptionalChain(node: Node): node is PropertyAccessChain | ElementAccessChain | CallChain | NonNullChain; + export function isNullishCoalesce(node: Node): boolean; + export function isConstTypeReference(node: Node): boolean; + export function skipPartiallyEmittedExpressions(node: Expression): Expression; + export function skipPartiallyEmittedExpressions(node: Node): Node; + export function isNonNullChain(node: Node): node is NonNullChain; + export function isBreakOrContinueStatement(node: Node): node is BreakOrContinueStatement; + export function isNamedExportBindings(node: Node): node is NamedExportBindings; + export function isJSDocPropertyLikeTag(node: Node): node is JSDocPropertyLikeTag; /** * True if kind is of some token syntax kind. * For example, this is true for an IfKeyword but not for an IfStatement. * Literals are considered tokens, except TemplateLiteral, but does include TemplateHead/Middle/Tail. */ - function isTokenKind(kind: SyntaxKind): boolean; + export function isTokenKind(kind: SyntaxKind): boolean; /** * True if node is of some token syntax kind. * For example, this is true for an IfKeyword but not for an IfStatement. * Literals are considered tokens, except TemplateLiteral, but does include TemplateHead/Middle/Tail. */ - function isToken(n: Node): boolean; - function isLiteralExpression(node: Node): node is LiteralExpression; - function isTemplateLiteralToken(node: Node): node is TemplateLiteralToken; - function isTemplateMiddleOrTemplateTail(node: Node): node is TemplateMiddle | TemplateTail; - function isImportOrExportSpecifier(node: Node): node is ImportSpecifier | ExportSpecifier; - function isTypeOnlyImportDeclaration(node: Node): node is TypeOnlyImportDeclaration; - function isTypeOnlyExportDeclaration(node: Node): node is TypeOnlyExportDeclaration; - function isTypeOnlyImportOrExportDeclaration(node: Node): node is TypeOnlyAliasDeclaration; - function isStringTextContainingNode(node: Node): node is StringLiteral | TemplateLiteralToken; - function isImportAttributeName(node: Node): node is ImportAttributeName; - function isModifier(node: Node): node is Modifier; - function isEntityName(node: Node): node is EntityName; - function isPropertyName(node: Node): node is PropertyName; - function isBindingName(node: Node): node is BindingName; - function isFunctionLike(node: Node | undefined): node is SignatureDeclaration; - function isClassElement(node: Node): node is ClassElement; - function isClassLike(node: Node): node is ClassLikeDeclaration; - function isAccessor(node: Node): node is AccessorDeclaration; - function isAutoAccessorPropertyDeclaration(node: Node): node is AutoAccessorPropertyDeclaration; - function isModifierLike(node: Node): node is ModifierLike; - function isTypeElement(node: Node): node is TypeElement; - function isClassOrTypeElement(node: Node): node is ClassElement | TypeElement; - function isObjectLiteralElementLike(node: Node): node is ObjectLiteralElementLike; + export function isToken(n: Node): boolean; + export function isLiteralExpression(node: Node): node is LiteralExpression; + export function isTemplateLiteralToken(node: Node): node is TemplateLiteralToken; + export function isTemplateMiddleOrTemplateTail(node: Node): node is TemplateMiddle | TemplateTail; + export function isImportOrExportSpecifier(node: Node): node is ImportSpecifier | ExportSpecifier; + export function isTypeOnlyImportDeclaration(node: Node): node is TypeOnlyImportDeclaration; + export function isTypeOnlyExportDeclaration(node: Node): node is TypeOnlyExportDeclaration; + export function isTypeOnlyImportOrExportDeclaration(node: Node): node is TypeOnlyAliasDeclaration; + export function isStringTextContainingNode(node: Node): node is StringLiteral | TemplateLiteralToken; + export function isImportAttributeName(node: Node): node is ImportAttributeName; + export function isModifier(node: Node): node is Modifier; + export function isEntityName(node: Node): node is EntityName; + export function isPropertyName(node: Node): node is PropertyName; + export function isBindingName(node: Node): node is BindingName; + export function isFunctionLike(node: Node | undefined): node is SignatureDeclaration; + export function isClassElement(node: Node): node is ClassElement; + export function isClassLike(node: Node): node is ClassLikeDeclaration; + export function isAccessor(node: Node): node is AccessorDeclaration; + export function isAutoAccessorPropertyDeclaration(node: Node): node is AutoAccessorPropertyDeclaration; + export function isModifierLike(node: Node): node is ModifierLike; + export function isTypeElement(node: Node): node is TypeElement; + export function isClassOrTypeElement(node: Node): node is ClassElement | TypeElement; + export function isObjectLiteralElementLike(node: Node): node is ObjectLiteralElementLike; /** * Node test that determines whether a node is a valid type node. * This differs from the `isPartOfTypeNode` function which determines whether a node is *part* * of a TypeNode. */ - function isTypeNode(node: Node): node is TypeNode; - function isFunctionOrConstructorTypeNode(node: Node): node is FunctionTypeNode | ConstructorTypeNode; - function isArrayBindingElement(node: Node): node is ArrayBindingElement; - function isPropertyAccessOrQualifiedName(node: Node): node is PropertyAccessExpression | QualifiedName; - function isCallLikeExpression(node: Node): node is CallLikeExpression; - function isCallOrNewExpression(node: Node): node is CallExpression | NewExpression; - function isTemplateLiteral(node: Node): node is TemplateLiteral; - function isLeftHandSideExpression(node: Node): node is LeftHandSideExpression; - function isLiteralTypeLiteral(node: Node): node is NullLiteral | BooleanLiteral | LiteralExpression | PrefixUnaryExpression; + export function isTypeNode(node: Node): node is TypeNode; + export function isFunctionOrConstructorTypeNode(node: Node): node is FunctionTypeNode | ConstructorTypeNode; + export function isArrayBindingElement(node: Node): node is ArrayBindingElement; + export function isPropertyAccessOrQualifiedName(node: Node): node is PropertyAccessExpression | QualifiedName; + export function isCallLikeExpression(node: Node): node is CallLikeExpression; + export function isCallOrNewExpression(node: Node): node is CallExpression | NewExpression; + export function isTemplateLiteral(node: Node): node is TemplateLiteral; + export function isLeftHandSideExpression(node: Node): node is LeftHandSideExpression; + export function isLiteralTypeLiteral(node: Node): node is NullLiteral | BooleanLiteral | LiteralExpression | PrefixUnaryExpression; /** * Determines whether a node is an expression based only on its kind. */ - function isExpression(node: Node): node is Expression; - function isAssertionExpression(node: Node): node is AssertionExpression; - function isIterationStatement(node: Node, lookInLabeledStatements: false): node is IterationStatement; - function isIterationStatement(node: Node, lookInLabeledStatements: boolean): node is IterationStatement | LabeledStatement; - function isConciseBody(node: Node): node is ConciseBody; - function isForInitializer(node: Node): node is ForInitializer; - function isModuleBody(node: Node): node is ModuleBody; - function isNamedImportBindings(node: Node): node is NamedImportBindings; - function isDeclarationStatement(node: Node): node is DeclarationStatement; - function isStatement(node: Node): node is Statement; - function isModuleReference(node: Node): node is ModuleReference; - function isJsxTagNameExpression(node: Node): node is JsxTagNameExpression; - function isJsxChild(node: Node): node is JsxChild; - function isJsxAttributeLike(node: Node): node is JsxAttributeLike; - function isStringLiteralOrJsxExpression(node: Node): node is StringLiteral | JsxExpression; - function isJsxOpeningLikeElement(node: Node): node is JsxOpeningLikeElement; - function isCaseOrDefaultClause(node: Node): node is CaseOrDefaultClause; + export function isExpression(node: Node): node is Expression; + export function isAssertionExpression(node: Node): node is AssertionExpression; + export function isIterationStatement(node: Node, lookInLabeledStatements: false): node is IterationStatement; + export function isIterationStatement(node: Node, lookInLabeledStatements: boolean): node is IterationStatement | LabeledStatement; + export function isConciseBody(node: Node): node is ConciseBody; + export function isForInitializer(node: Node): node is ForInitializer; + export function isModuleBody(node: Node): node is ModuleBody; + export function isNamedImportBindings(node: Node): node is NamedImportBindings; + export function isDeclarationStatement(node: Node): node is DeclarationStatement; + export function isStatement(node: Node): node is Statement; + export function isModuleReference(node: Node): node is ModuleReference; + export function isJsxTagNameExpression(node: Node): node is JsxTagNameExpression; + export function isJsxChild(node: Node): node is JsxChild; + export function isJsxAttributeLike(node: Node): node is JsxAttributeLike; + export function isStringLiteralOrJsxExpression(node: Node): node is StringLiteral | JsxExpression; + export function isJsxOpeningLikeElement(node: Node): node is JsxOpeningLikeElement; + export function isCaseOrDefaultClause(node: Node): node is CaseOrDefaultClause; /** True if node is of a kind that may contain comment text. */ - function isJSDocCommentContainingNode(node: Node): boolean; - function isSetAccessor(node: Node): node is SetAccessorDeclaration; - function isGetAccessor(node: Node): node is GetAccessorDeclaration; + export function isJSDocCommentContainingNode(node: Node): boolean; + export function isSetAccessor(node: Node): node is SetAccessorDeclaration; + export function isGetAccessor(node: Node): node is GetAccessorDeclaration; /** True if has initializer node attached to it. */ - function hasOnlyExpressionInitializer(node: Node): node is HasExpressionInitializer; - function isObjectLiteralElement(node: Node): node is ObjectLiteralElement; - function isStringLiteralLike(node: Node | FileReference): node is StringLiteralLike; - function isJSDocLinkLike(node: Node): node is JSDocLink | JSDocLinkCode | JSDocLinkPlain; - function hasRestParameter(s: SignatureDeclaration | JSDocSignature): boolean; - function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean; - function isInternalDeclaration(node: Node, sourceFile?: SourceFile): boolean; - const unchangedTextChangeRange: TextChangeRange; - type ParameterPropertyDeclaration = ParameterDeclaration & { + export function hasOnlyExpressionInitializer(node: Node): node is HasExpressionInitializer; + export function isObjectLiteralElement(node: Node): node is ObjectLiteralElement; + export function isStringLiteralLike(node: Node | FileReference): node is StringLiteralLike; + export function isJSDocLinkLike(node: Node): node is JSDocLink | JSDocLinkCode | JSDocLinkPlain; + export function hasRestParameter(s: SignatureDeclaration | JSDocSignature): boolean; + export function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean; + export function isInternalDeclaration(node: Node, sourceFile?: SourceFile): boolean; + export const unchangedTextChangeRange: TextChangeRange; + export type ParameterPropertyDeclaration = ParameterDeclaration & { parent: ConstructorDeclaration; name: Identifier; }; - function isPartOfTypeNode(node: Node): boolean; + export function isPartOfTypeNode(node: Node): boolean; /** * This function checks multiple locations for JSDoc comments that apply to a host node. * At each location, the whole comment may apply to the node, or only a specific tag in @@ -8784,330 +11166,316 @@ declare namespace ts { * function b(/** JSDoc will be returned for `c` *\/ c) {} * ``` */ - function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDocTag)[]; + export function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDocTag)[]; /** * Create an external source map source file reference */ - function createSourceMapSource(fileName: string, text: string, skipTrivia?: (pos: number) => number): SourceMapSource; - function setOriginalNode(node: T, original: Node | undefined): T; - const factory: NodeFactory; + export function createSourceMapSource(fileName: string, text: string, skipTrivia?: (pos: number) => number): SourceMapSource; + export function setOriginalNode(node: T, original: Node | undefined): T; + export const factory: NodeFactory; /** * Clears any `EmitNode` entries from parse-tree nodes. * @param sourceFile A source file. */ - function disposeEmitNodes(sourceFile: SourceFile | undefined): void; + export function disposeEmitNodes(sourceFile: SourceFile | undefined): void; /** * Sets flags that control emit behavior of a node. */ - function setEmitFlags(node: T, emitFlags: EmitFlags): T; + export function setEmitFlags(node: T, emitFlags: EmitFlags): T; /** * Gets a custom text range to use when emitting source maps. */ - function getSourceMapRange(node: Node): SourceMapRange; + export function getSourceMapRange(node: Node): SourceMapRange; /** * Sets a custom text range to use when emitting source maps. */ - function setSourceMapRange(node: T, range: SourceMapRange | undefined): T; + export function setSourceMapRange(node: T, range: SourceMapRange | undefined): T; /** * Gets the TextRange to use for source maps for a token of a node. */ - function getTokenSourceMapRange(node: Node, token: SyntaxKind): SourceMapRange | undefined; + export function getTokenSourceMapRange(node: Node, token: SyntaxKind): SourceMapRange | undefined; /** * Sets the TextRange to use for source maps for a token of a node. */ - function setTokenSourceMapRange(node: T, token: SyntaxKind, range: SourceMapRange | undefined): T; + export function setTokenSourceMapRange(node: T, token: SyntaxKind, range: SourceMapRange | undefined): T; /** * Gets a custom text range to use when emitting comments. */ - function getCommentRange(node: Node): TextRange; + export function getCommentRange(node: Node): TextRange; /** * Sets a custom text range to use when emitting comments. */ - function setCommentRange(node: T, range: TextRange): T; - function getSyntheticLeadingComments(node: Node): SynthesizedComment[] | undefined; - function setSyntheticLeadingComments(node: T, comments: SynthesizedComment[] | undefined): T; - function addSyntheticLeadingComment(node: T, kind: SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia, text: string, hasTrailingNewLine?: boolean): T; - function getSyntheticTrailingComments(node: Node): SynthesizedComment[] | undefined; - function setSyntheticTrailingComments(node: T, comments: SynthesizedComment[] | undefined): T; - function addSyntheticTrailingComment(node: T, kind: SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia, text: string, hasTrailingNewLine?: boolean): T; - function moveSyntheticComments(node: T, original: Node): T; + export function setCommentRange(node: T, range: TextRange): T; + export function getSyntheticLeadingComments(node: Node): SynthesizedComment[] | undefined; + export function setSyntheticLeadingComments(node: T, comments: SynthesizedComment[] | undefined): T; + export function addSyntheticLeadingComment(node: T, kind: SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia, text: string, hasTrailingNewLine?: boolean): T; + export function getSyntheticTrailingComments(node: Node): SynthesizedComment[] | undefined; + export function setSyntheticTrailingComments(node: T, comments: SynthesizedComment[] | undefined): T; + export function addSyntheticTrailingComment(node: T, kind: SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia, text: string, hasTrailingNewLine?: boolean): T; + export function moveSyntheticComments(node: T, original: Node): T; /** * Gets the constant value to emit for an expression representing an enum. */ - function getConstantValue(node: AccessExpression): string | number | undefined; + export function getConstantValue(node: AccessExpression): string | number | undefined; /** * Sets the constant value to emit for an expression. */ - function setConstantValue(node: AccessExpression, value: string | number): AccessExpression; + export function setConstantValue(node: AccessExpression, value: string | number): AccessExpression; /** * Adds an EmitHelper to a node. */ - function addEmitHelper(node: T, helper: EmitHelper): T; + export function addEmitHelper(node: T, helper: EmitHelper): T; /** * Add EmitHelpers to a node. */ - function addEmitHelpers(node: T, helpers: EmitHelper[] | undefined): T; + export function addEmitHelpers(node: T, helpers: EmitHelper[] | undefined): T; /** * Removes an EmitHelper from a node. */ - function removeEmitHelper(node: Node, helper: EmitHelper): boolean; + export function removeEmitHelper(node: Node, helper: EmitHelper): boolean; /** * Gets the EmitHelpers of a node. */ - function getEmitHelpers(node: Node): EmitHelper[] | undefined; + export function getEmitHelpers(node: Node): EmitHelper[] | undefined; /** * Moves matching emit helpers from a source node to a target node. */ - function moveEmitHelpers(source: Node, target: Node, predicate: (helper: EmitHelper) => boolean): void; - function isNumericLiteral(node: Node): node is NumericLiteral; - function isBigIntLiteral(node: Node): node is BigIntLiteral; - function isStringLiteral(node: Node): node is StringLiteral; - function isJsxText(node: Node): node is JsxText; - function isRegularExpressionLiteral(node: Node): node is RegularExpressionLiteral; - function isNoSubstitutionTemplateLiteral(node: Node): node is NoSubstitutionTemplateLiteral; - function isTemplateHead(node: Node): node is TemplateHead; - function isTemplateMiddle(node: Node): node is TemplateMiddle; - function isTemplateTail(node: Node): node is TemplateTail; - function isDotDotDotToken(node: Node): node is DotDotDotToken; - function isPlusToken(node: Node): node is PlusToken; - function isMinusToken(node: Node): node is MinusToken; - function isAsteriskToken(node: Node): node is AsteriskToken; - function isExclamationToken(node: Node): node is ExclamationToken; - function isQuestionToken(node: Node): node is QuestionToken; - function isColonToken(node: Node): node is ColonToken; - function isQuestionDotToken(node: Node): node is QuestionDotToken; - function isEqualsGreaterThanToken(node: Node): node is EqualsGreaterThanToken; - function isIdentifier(node: Node): node is Identifier; - function isPrivateIdentifier(node: Node): node is PrivateIdentifier; - function isAssertsKeyword(node: Node): node is AssertsKeyword; - function isAwaitKeyword(node: Node): node is AwaitKeyword; - function isQualifiedName(node: Node): node is QualifiedName; - function isComputedPropertyName(node: Node): node is ComputedPropertyName; - function isTypeParameterDeclaration(node: Node): node is TypeParameterDeclaration; - function isParameter(node: Node): node is ParameterDeclaration; - function isDecorator(node: Node): node is Decorator; - function isPropertySignature(node: Node): node is PropertySignature; - function isPropertyDeclaration(node: Node): node is PropertyDeclaration; - function isMethodSignature(node: Node): node is MethodSignature; - function isMethodDeclaration(node: Node): node is MethodDeclaration; - function isClassStaticBlockDeclaration(node: Node): node is ClassStaticBlockDeclaration; - function isConstructorDeclaration(node: Node): node is ConstructorDeclaration; - function isGetAccessorDeclaration(node: Node): node is GetAccessorDeclaration; - function isSetAccessorDeclaration(node: Node): node is SetAccessorDeclaration; - function isCallSignatureDeclaration(node: Node): node is CallSignatureDeclaration; - function isConstructSignatureDeclaration(node: Node): node is ConstructSignatureDeclaration; - function isIndexSignatureDeclaration(node: Node): node is IndexSignatureDeclaration; - function isTypePredicateNode(node: Node): node is TypePredicateNode; - function isTypeReferenceNode(node: Node): node is TypeReferenceNode; - function isFunctionTypeNode(node: Node): node is FunctionTypeNode; - function isConstructorTypeNode(node: Node): node is ConstructorTypeNode; - function isTypeQueryNode(node: Node): node is TypeQueryNode; - function isTypeLiteralNode(node: Node): node is TypeLiteralNode; - function isArrayTypeNode(node: Node): node is ArrayTypeNode; - function isTupleTypeNode(node: Node): node is TupleTypeNode; - function isNamedTupleMember(node: Node): node is NamedTupleMember; - function isOptionalTypeNode(node: Node): node is OptionalTypeNode; - function isRestTypeNode(node: Node): node is RestTypeNode; - function isUnionTypeNode(node: Node): node is UnionTypeNode; - function isIntersectionTypeNode(node: Node): node is IntersectionTypeNode; - function isConditionalTypeNode(node: Node): node is ConditionalTypeNode; - function isInferTypeNode(node: Node): node is InferTypeNode; - function isParenthesizedTypeNode(node: Node): node is ParenthesizedTypeNode; - function isThisTypeNode(node: Node): node is ThisTypeNode; - function isTypeOperatorNode(node: Node): node is TypeOperatorNode; - function isIndexedAccessTypeNode(node: Node): node is IndexedAccessTypeNode; - function isMappedTypeNode(node: Node): node is MappedTypeNode; - function isLiteralTypeNode(node: Node): node is LiteralTypeNode; - function isImportTypeNode(node: Node): node is ImportTypeNode; - function isTemplateLiteralTypeSpan(node: Node): node is TemplateLiteralTypeSpan; - function isTemplateLiteralTypeNode(node: Node): node is TemplateLiteralTypeNode; - function isObjectBindingPattern(node: Node): node is ObjectBindingPattern; - function isArrayBindingPattern(node: Node): node is ArrayBindingPattern; - function isBindingElement(node: Node): node is BindingElement; - function isArrayLiteralExpression(node: Node): node is ArrayLiteralExpression; - function isObjectLiteralExpression(node: Node): node is ObjectLiteralExpression; - function isPropertyAccessExpression(node: Node): node is PropertyAccessExpression; - function isElementAccessExpression(node: Node): node is ElementAccessExpression; - function isCallExpression(node: Node): node is CallExpression; - function isNewExpression(node: Node): node is NewExpression; - function isTaggedTemplateExpression(node: Node): node is TaggedTemplateExpression; - function isTypeAssertionExpression(node: Node): node is TypeAssertion; - function isParenthesizedExpression(node: Node): node is ParenthesizedExpression; - function isFunctionExpression(node: Node): node is FunctionExpression; - function isArrowFunction(node: Node): node is ArrowFunction; - function isDeleteExpression(node: Node): node is DeleteExpression; - function isTypeOfExpression(node: Node): node is TypeOfExpression; - function isVoidExpression(node: Node): node is VoidExpression; - function isAwaitExpression(node: Node): node is AwaitExpression; - function isPrefixUnaryExpression(node: Node): node is PrefixUnaryExpression; - function isPostfixUnaryExpression(node: Node): node is PostfixUnaryExpression; - function isBinaryExpression(node: Node): node is BinaryExpression; - function isConditionalExpression(node: Node): node is ConditionalExpression; - function isTemplateExpression(node: Node): node is TemplateExpression; - function isYieldExpression(node: Node): node is YieldExpression; - function isSpreadElement(node: Node): node is SpreadElement; - function isClassExpression(node: Node): node is ClassExpression; - function isOmittedExpression(node: Node): node is OmittedExpression; - function isExpressionWithTypeArguments(node: Node): node is ExpressionWithTypeArguments; - function isAsExpression(node: Node): node is AsExpression; - function isSatisfiesExpression(node: Node): node is SatisfiesExpression; - function isNonNullExpression(node: Node): node is NonNullExpression; - function isMetaProperty(node: Node): node is MetaProperty; - function isSyntheticExpression(node: Node): node is SyntheticExpression; - function isPartiallyEmittedExpression(node: Node): node is PartiallyEmittedExpression; - function isCommaListExpression(node: Node): node is CommaListExpression; - function isTemplateSpan(node: Node): node is TemplateSpan; - function isSemicolonClassElement(node: Node): node is SemicolonClassElement; - function isBlock(node: Node): node is Block; - function isVariableStatement(node: Node): node is VariableStatement; - function isEmptyStatement(node: Node): node is EmptyStatement; - function isExpressionStatement(node: Node): node is ExpressionStatement; - function isIfStatement(node: Node): node is IfStatement; - function isDoStatement(node: Node): node is DoStatement; - function isWhileStatement(node: Node): node is WhileStatement; - function isForStatement(node: Node): node is ForStatement; - function isForInStatement(node: Node): node is ForInStatement; - function isForOfStatement(node: Node): node is ForOfStatement; - function isContinueStatement(node: Node): node is ContinueStatement; - function isBreakStatement(node: Node): node is BreakStatement; - function isReturnStatement(node: Node): node is ReturnStatement; - function isWithStatement(node: Node): node is WithStatement; - function isSwitchStatement(node: Node): node is SwitchStatement; - function isLabeledStatement(node: Node): node is LabeledStatement; - function isThrowStatement(node: Node): node is ThrowStatement; - function isTryStatement(node: Node): node is TryStatement; - function isDebuggerStatement(node: Node): node is DebuggerStatement; - function isVariableDeclaration(node: Node): node is VariableDeclaration; - function isVariableDeclarationList(node: Node): node is VariableDeclarationList; - function isFunctionDeclaration(node: Node): node is FunctionDeclaration; - function isClassDeclaration(node: Node): node is ClassDeclaration; - function isInterfaceDeclaration(node: Node): node is InterfaceDeclaration; - function isTypeAliasDeclaration(node: Node): node is TypeAliasDeclaration; - function isEnumDeclaration(node: Node): node is EnumDeclaration; - function isModuleDeclaration(node: Node): node is ModuleDeclaration; - function isModuleBlock(node: Node): node is ModuleBlock; - function isCaseBlock(node: Node): node is CaseBlock; - function isNamespaceExportDeclaration(node: Node): node is NamespaceExportDeclaration; - function isImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration; - function isImportDeclaration(node: Node): node is ImportDeclaration; - function isImportClause(node: Node): node is ImportClause; - function isImportTypeAssertionContainer(node: Node): node is ImportTypeAssertionContainer; + export function moveEmitHelpers(source: Node, target: Node, predicate: (helper: EmitHelper) => boolean): void; + export function isNumericLiteral(node: Node): node is NumericLiteral; + export function isBigIntLiteral(node: Node): node is BigIntLiteral; + export function isStringLiteral(node: Node): node is StringLiteral; + export function isJsxText(node: Node): node is JsxText; + export function isRegularExpressionLiteral(node: Node): node is RegularExpressionLiteral; + export function isNoSubstitutionTemplateLiteral(node: Node): node is NoSubstitutionTemplateLiteral; + export function isTemplateHead(node: Node): node is TemplateHead; + export function isTemplateMiddle(node: Node): node is TemplateMiddle; + export function isTemplateTail(node: Node): node is TemplateTail; + export function isDotDotDotToken(node: Node): node is DotDotDotToken; + export function isPlusToken(node: Node): node is PlusToken; + export function isMinusToken(node: Node): node is MinusToken; + export function isAsteriskToken(node: Node): node is AsteriskToken; + export function isExclamationToken(node: Node): node is ExclamationToken; + export function isQuestionToken(node: Node): node is QuestionToken; + export function isColonToken(node: Node): node is ColonToken; + export function isQuestionDotToken(node: Node): node is QuestionDotToken; + export function isEqualsGreaterThanToken(node: Node): node is EqualsGreaterThanToken; + export function isIdentifier(node: Node): node is Identifier; + export function isPrivateIdentifier(node: Node): node is PrivateIdentifier; + export function isAssertsKeyword(node: Node): node is AssertsKeyword; + export function isAwaitKeyword(node: Node): node is AwaitKeyword; + export function isQualifiedName(node: Node): node is QualifiedName; + export function isComputedPropertyName(node: Node): node is ComputedPropertyName; + export function isTypeParameterDeclaration(node: Node): node is TypeParameterDeclaration; + export function isParameter(node: Node): node is ParameterDeclaration; + export function isDecorator(node: Node): node is Decorator; + export function isPropertySignature(node: Node): node is PropertySignature; + export function isPropertyDeclaration(node: Node): node is PropertyDeclaration; + export function isMethodSignature(node: Node): node is MethodSignature; + export function isMethodDeclaration(node: Node): node is MethodDeclaration; + export function isClassStaticBlockDeclaration(node: Node): node is ClassStaticBlockDeclaration; + export function isConstructorDeclaration(node: Node): node is ConstructorDeclaration; + export function isGetAccessorDeclaration(node: Node): node is GetAccessorDeclaration; + export function isSetAccessorDeclaration(node: Node): node is SetAccessorDeclaration; + export function isCallSignatureDeclaration(node: Node): node is CallSignatureDeclaration; + export function isConstructSignatureDeclaration(node: Node): node is ConstructSignatureDeclaration; + export function isIndexSignatureDeclaration(node: Node): node is IndexSignatureDeclaration; + export function isTypePredicateNode(node: Node): node is TypePredicateNode; + export function isTypeReferenceNode(node: Node): node is TypeReferenceNode; + export function isFunctionTypeNode(node: Node): node is FunctionTypeNode; + export function isConstructorTypeNode(node: Node): node is ConstructorTypeNode; + export function isTypeQueryNode(node: Node): node is TypeQueryNode; + export function isTypeLiteralNode(node: Node): node is TypeLiteralNode; + export function isArrayTypeNode(node: Node): node is ArrayTypeNode; + export function isTupleTypeNode(node: Node): node is TupleTypeNode; + export function isNamedTupleMember(node: Node): node is NamedTupleMember; + export function isOptionalTypeNode(node: Node): node is OptionalTypeNode; + export function isRestTypeNode(node: Node): node is RestTypeNode; + export function isUnionTypeNode(node: Node): node is UnionTypeNode; + export function isIntersectionTypeNode(node: Node): node is IntersectionTypeNode; + export function isConditionalTypeNode(node: Node): node is ConditionalTypeNode; + export function isInferTypeNode(node: Node): node is InferTypeNode; + export function isParenthesizedTypeNode(node: Node): node is ParenthesizedTypeNode; + export function isThisTypeNode(node: Node): node is ThisTypeNode; + export function isTypeOperatorNode(node: Node): node is TypeOperatorNode; + export function isIndexedAccessTypeNode(node: Node): node is IndexedAccessTypeNode; + export function isMappedTypeNode(node: Node): node is MappedTypeNode; + export function isLiteralTypeNode(node: Node): node is LiteralTypeNode; + export function isImportTypeNode(node: Node): node is ImportTypeNode; + export function isTemplateLiteralTypeSpan(node: Node): node is TemplateLiteralTypeSpan; + export function isTemplateLiteralTypeNode(node: Node): node is TemplateLiteralTypeNode; + export function isObjectBindingPattern(node: Node): node is ObjectBindingPattern; + export function isArrayBindingPattern(node: Node): node is ArrayBindingPattern; + export function isBindingElement(node: Node): node is BindingElement; + export function isArrayLiteralExpression(node: Node): node is ArrayLiteralExpression; + export function isObjectLiteralExpression(node: Node): node is ObjectLiteralExpression; + export function isPropertyAccessExpression(node: Node): node is PropertyAccessExpression; + export function isElementAccessExpression(node: Node): node is ElementAccessExpression; + export function isCallExpression(node: Node): node is CallExpression; + export function isNewExpression(node: Node): node is NewExpression; + export function isTaggedTemplateExpression(node: Node): node is TaggedTemplateExpression; + export function isTypeAssertionExpression(node: Node): node is TypeAssertionExpression; + export function isParenthesizedExpression(node: Node): node is ParenthesizedExpression; + export function isFunctionExpression(node: Node): node is FunctionExpression; + export function isArrowFunction(node: Node): node is ArrowFunction; + export function isDeleteExpression(node: Node): node is DeleteExpression; + export function isTypeOfExpression(node: Node): node is TypeOfExpression; + export function isVoidExpression(node: Node): node is VoidExpression; + export function isAwaitExpression(node: Node): node is AwaitExpression; + export function isPrefixUnaryExpression(node: Node): node is PrefixUnaryExpression; + export function isPostfixUnaryExpression(node: Node): node is PostfixUnaryExpression; + export function isBinaryExpression(node: Node): node is BinaryExpression; + export function isConditionalExpression(node: Node): node is ConditionalExpression; + export function isTemplateExpression(node: Node): node is TemplateExpression; + export function isYieldExpression(node: Node): node is YieldExpression; + export function isSpreadElement(node: Node): node is SpreadElement; + export function isClassExpression(node: Node): node is ClassExpression; + export function isOmittedExpression(node: Node): node is OmittedExpression; + export function isExpressionWithTypeArguments(node: Node): node is ExpressionWithTypeArguments; + export function isAsExpression(node: Node): node is AsExpression; + export function isSatisfiesExpression(node: Node): node is SatisfiesExpression; + export function isNonNullExpression(node: Node): node is NonNullExpression; + export function isMetaProperty(node: Node): node is MetaProperty; + export function isSyntheticExpression(node: Node): node is SyntheticExpression; + export function isPartiallyEmittedExpression(node: Node): node is PartiallyEmittedExpression; + export function isCommaListExpression(node: Node): node is CommaListExpression; + export function isTemplateSpan(node: Node): node is TemplateSpan; + export function isSemicolonClassElement(node: Node): node is SemicolonClassElement; + export function isBlock(node: Node): node is Block; + export function isVariableStatement(node: Node): node is VariableStatement; + export function isEmptyStatement(node: Node): node is EmptyStatement; + export function isExpressionStatement(node: Node): node is ExpressionStatement; + export function isIfStatement(node: Node): node is IfStatement; + export function isDoStatement(node: Node): node is DoStatement; + export function isWhileStatement(node: Node): node is WhileStatement; + export function isForStatement(node: Node): node is ForStatement; + export function isForInStatement(node: Node): node is ForInStatement; + export function isForOfStatement(node: Node): node is ForOfStatement; + export function isContinueStatement(node: Node): node is ContinueStatement; + export function isBreakStatement(node: Node): node is BreakStatement; + export function isReturnStatement(node: Node): node is ReturnStatement; + export function isWithStatement(node: Node): node is WithStatement; + export function isSwitchStatement(node: Node): node is SwitchStatement; + export function isLabeledStatement(node: Node): node is LabeledStatement; + export function isThrowStatement(node: Node): node is ThrowStatement; + export function isTryStatement(node: Node): node is TryStatement; + export function isDebuggerStatement(node: Node): node is DebuggerStatement; + export function isVariableDeclaration(node: Node): node is VariableDeclaration; + export function isVariableDeclarationList(node: Node): node is VariableDeclarationList; + export function isFunctionDeclaration(node: Node): node is FunctionDeclaration; + export function isClassDeclaration(node: Node): node is ClassDeclaration; + export function isInterfaceDeclaration(node: Node): node is InterfaceDeclaration; + export function isTypeAliasDeclaration(node: Node): node is TypeAliasDeclaration; + export function isEnumDeclaration(node: Node): node is EnumDeclaration; + export function isModuleDeclaration(node: Node): node is ModuleDeclaration; + export function isModuleBlock(node: Node): node is ModuleBlock; + export function isCaseBlock(node: Node): node is CaseBlock; + export function isNamespaceExportDeclaration(node: Node): node is NamespaceExportDeclaration; + export function isImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration; + export function isImportDeclaration(node: Node): node is ImportDeclaration; + export function isImportClause(node: Node): node is ImportClause; + export function isImportTypeAssertionContainer(node: Node): node is ImportTypeAssertionContainer; /** @deprecated */ - function isAssertClause(node: Node): node is AssertClause; + export function isAssertClause(node: Node): node is AssertClause; /** @deprecated */ - function isAssertEntry(node: Node): node is AssertEntry; - function isImportAttributes(node: Node): node is ImportAttributes; - function isImportAttribute(node: Node): node is ImportAttribute; - function isNamespaceImport(node: Node): node is NamespaceImport; - function isNamespaceExport(node: Node): node is NamespaceExport; - function isNamedImports(node: Node): node is NamedImports; - function isImportSpecifier(node: Node): node is ImportSpecifier; - function isExportAssignment(node: Node): node is ExportAssignment; - function isExportDeclaration(node: Node): node is ExportDeclaration; - function isNamedExports(node: Node): node is NamedExports; - function isExportSpecifier(node: Node): node is ExportSpecifier; - function isModuleExportName(node: Node): node is ModuleExportName; - function isMissingDeclaration(node: Node): node is MissingDeclaration; - function isNotEmittedStatement(node: Node): node is NotEmittedStatement; - function isExternalModuleReference(node: Node): node is ExternalModuleReference; - function isJsxElement(node: Node): node is JsxElement; - function isJsxSelfClosingElement(node: Node): node is JsxSelfClosingElement; - function isJsxOpeningElement(node: Node): node is JsxOpeningElement; - function isJsxClosingElement(node: Node): node is JsxClosingElement; - function isJsxFragment(node: Node): node is JsxFragment; - function isJsxOpeningFragment(node: Node): node is JsxOpeningFragment; - function isJsxClosingFragment(node: Node): node is JsxClosingFragment; - function isJsxAttribute(node: Node): node is JsxAttribute; - function isJsxAttributes(node: Node): node is JsxAttributes; - function isJsxSpreadAttribute(node: Node): node is JsxSpreadAttribute; - function isJsxExpression(node: Node): node is JsxExpression; - function isJsxNamespacedName(node: Node): node is JsxNamespacedName; - function isCaseClause(node: Node): node is CaseClause; - function isDefaultClause(node: Node): node is DefaultClause; - function isHeritageClause(node: Node): node is HeritageClause; - function isCatchClause(node: Node): node is CatchClause; - function isPropertyAssignment(node: Node): node is PropertyAssignment; - function isShorthandPropertyAssignment(node: Node): node is ShorthandPropertyAssignment; - function isSpreadAssignment(node: Node): node is SpreadAssignment; - function isEnumMember(node: Node): node is EnumMember; - function isSourceFile(node: Node): node is SourceFile; - function isBundle(node: Node): node is Bundle; - function isJSDocTypeExpression(node: Node): node is JSDocTypeExpression; - function isJSDocNameReference(node: Node): node is JSDocNameReference; - function isJSDocMemberName(node: Node): node is JSDocMemberName; - function isJSDocLink(node: Node): node is JSDocLink; - function isJSDocLinkCode(node: Node): node is JSDocLinkCode; - function isJSDocLinkPlain(node: Node): node is JSDocLinkPlain; - function isJSDocAllType(node: Node): node is JSDocAllType; - function isJSDocUnknownType(node: Node): node is JSDocUnknownType; - function isJSDocNullableType(node: Node): node is JSDocNullableType; - function isJSDocNonNullableType(node: Node): node is JSDocNonNullableType; - function isJSDocOptionalType(node: Node): node is JSDocOptionalType; - function isJSDocFunctionType(node: Node): node is JSDocFunctionType; - function isJSDocVariadicType(node: Node): node is JSDocVariadicType; - function isJSDocNamepathType(node: Node): node is JSDocNamepathType; - function isJSDoc(node: Node): node is JSDoc; - function isJSDocTypeLiteral(node: Node): node is JSDocTypeLiteral; - function isJSDocSignature(node: Node): node is JSDocSignature; - function isJSDocAugmentsTag(node: Node): node is JSDocAugmentsTag; - function isJSDocAuthorTag(node: Node): node is JSDocAuthorTag; - function isJSDocClassTag(node: Node): node is JSDocClassTag; - function isJSDocCallbackTag(node: Node): node is JSDocCallbackTag; - function isJSDocPublicTag(node: Node): node is JSDocPublicTag; - function isJSDocPrivateTag(node: Node): node is JSDocPrivateTag; - function isJSDocProtectedTag(node: Node): node is JSDocProtectedTag; - function isJSDocReadonlyTag(node: Node): node is JSDocReadonlyTag; - function isJSDocOverrideTag(node: Node): node is JSDocOverrideTag; - function isJSDocOverloadTag(node: Node): node is JSDocOverloadTag; - function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag; - function isJSDocSeeTag(node: Node): node is JSDocSeeTag; - function isJSDocEnumTag(node: Node): node is JSDocEnumTag; - function isJSDocParameterTag(node: Node): node is JSDocParameterTag; - function isJSDocReturnTag(node: Node): node is JSDocReturnTag; - function isJSDocThisTag(node: Node): node is JSDocThisTag; - function isJSDocTypeTag(node: Node): node is JSDocTypeTag; - function isJSDocTemplateTag(node: Node): node is JSDocTemplateTag; - function isJSDocTypedefTag(node: Node): node is JSDocTypedefTag; - function isJSDocUnknownTag(node: Node): node is JSDocUnknownTag; - function isJSDocPropertyTag(node: Node): node is JSDocPropertyTag; - function isJSDocImplementsTag(node: Node): node is JSDocImplementsTag; - function isJSDocSatisfiesTag(node: Node): node is JSDocSatisfiesTag; - function isJSDocThrowsTag(node: Node): node is JSDocThrowsTag; - function isJSDocImportTag(node: Node): node is JSDocImportTag; - function isQuestionOrExclamationToken(node: Node): node is QuestionToken | ExclamationToken; - function isIdentifierOrThisTypeNode(node: Node): node is Identifier | ThisTypeNode; - function isReadonlyKeywordOrPlusOrMinusToken(node: Node): node is ReadonlyKeyword | PlusToken | MinusToken; - function isQuestionOrPlusOrMinusToken(node: Node): node is QuestionToken | PlusToken | MinusToken; - function isModuleName(node: Node): node is ModuleName; - function isBinaryOperatorToken(node: Node): node is BinaryOperatorToken; - function setTextRange(range: T, location: TextRange | undefined): T; - function canHaveModifiers(node: Node): node is HasModifiers; - function canHaveDecorators(node: Node): node is HasDecorators; - /** - * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes - * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, - * embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns - * a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. - * - * @param node a given node to visit its children - * @param cbNode a callback to be invoked for all child nodes - * @param cbNodes a callback to be invoked for embedded array - * - * @remarks `forEachChild` must visit the children of a node in the order - * that they appear in the source code. The language service depends on this property to locate nodes by position. - */ - function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined; - function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile; - function parseIsolatedEntityName(text: string, languageVersion: ScriptTarget): EntityName | undefined; + export function isAssertEntry(node: Node): node is AssertEntry; + export function isImportAttributes(node: Node): node is ImportAttributes; + export function isImportAttribute(node: Node): node is ImportAttribute; + export function isNamespaceImport(node: Node): node is NamespaceImport; + export function isNamespaceExport(node: Node): node is NamespaceExport; + export function isNamedImports(node: Node): node is NamedImports; + export function isImportSpecifier(node: Node): node is ImportSpecifier; + export function isExportAssignment(node: Node): node is ExportAssignment; + export function isExportDeclaration(node: Node): node is ExportDeclaration; + export function isNamedExports(node: Node): node is NamedExports; + export function isExportSpecifier(node: Node): node is ExportSpecifier; + export function isModuleExportName(node: Node): node is ModuleExportName; + export function isMissingDeclaration(node: Node): node is MissingDeclaration; + export function isNotEmittedStatement(node: Node): node is NotEmittedStatement; + export function isExternalModuleReference(node: Node): node is ExternalModuleReference; + export function isJsxElement(node: Node): node is JsxElement; + export function isJsxSelfClosingElement(node: Node): node is JsxSelfClosingElement; + export function isJsxOpeningElement(node: Node): node is JsxOpeningElement; + export function isJsxClosingElement(node: Node): node is JsxClosingElement; + export function isJsxFragment(node: Node): node is JsxFragment; + export function isJsxOpeningFragment(node: Node): node is JsxOpeningFragment; + export function isJsxClosingFragment(node: Node): node is JsxClosingFragment; + export function isJsxAttribute(node: Node): node is JsxAttribute; + export function isJsxAttributes(node: Node): node is JsxAttributes; + export function isJsxSpreadAttribute(node: Node): node is JsxSpreadAttribute; + export function isJsxExpression(node: Node): node is JsxExpression; + export function isJsxNamespacedName(node: Node): node is JsxNamespacedName; + export function isCaseClause(node: Node): node is CaseClause; + export function isDefaultClause(node: Node): node is DefaultClause; + export function isHeritageClause(node: Node): node is HeritageClause; + export function isCatchClause(node: Node): node is CatchClause; + export function isPropertyAssignment(node: Node): node is PropertyAssignment; + export function isShorthandPropertyAssignment(node: Node): node is ShorthandPropertyAssignment; + export function isSpreadAssignment(node: Node): node is SpreadAssignment; + export function isEnumMember(node: Node): node is EnumMember; + export function isSourceFile(node: Node): node is SourceFile; + export function isBundle(node: Node): node is Bundle; + export function isJSDocTypeExpression(node: Node): node is JSDocTypeExpression; + export function isJSDocNameReference(node: Node): node is JSDocNameReference; + export function isJSDocMemberName(node: Node): node is JSDocMemberName; + export function isJSDocLink(node: Node): node is JSDocLink; + export function isJSDocLinkCode(node: Node): node is JSDocLinkCode; + export function isJSDocLinkPlain(node: Node): node is JSDocLinkPlain; + export function isJSDocAllType(node: Node): node is JSDocAllType; + export function isJSDocUnknownType(node: Node): node is JSDocUnknownType; + export function isJSDocNullableType(node: Node): node is JSDocNullableType; + export function isJSDocNonNullableType(node: Node): node is JSDocNonNullableType; + export function isJSDocOptionalType(node: Node): node is JSDocOptionalType; + export function isJSDocFunctionType(node: Node): node is JSDocFunctionType; + export function isJSDocVariadicType(node: Node): node is JSDocVariadicType; + export function isJSDocNamepathType(node: Node): node is JSDocNamepathType; + export function isJSDoc(node: Node): node is JSDoc; + export function isJSDocTypeLiteral(node: Node): node is JSDocTypeLiteral; + export function isJSDocSignature(node: Node): node is JSDocSignature; + export function isJSDocAugmentsTag(node: Node): node is JSDocAugmentsTag; + export function isJSDocAuthorTag(node: Node): node is JSDocAuthorTag; + export function isJSDocClassTag(node: Node): node is JSDocClassTag; + export function isJSDocCallbackTag(node: Node): node is JSDocCallbackTag; + export function isJSDocPublicTag(node: Node): node is JSDocPublicTag; + export function isJSDocPrivateTag(node: Node): node is JSDocPrivateTag; + export function isJSDocProtectedTag(node: Node): node is JSDocProtectedTag; + export function isJSDocReadonlyTag(node: Node): node is JSDocReadonlyTag; + export function isJSDocOverrideTag(node: Node): node is JSDocOverrideTag; + export function isJSDocOverloadTag(node: Node): node is JSDocOverloadTag; + export function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag; + export function isJSDocSeeTag(node: Node): node is JSDocSeeTag; + export function isJSDocEnumTag(node: Node): node is JSDocEnumTag; + export function isJSDocParameterTag(node: Node): node is JSDocParameterTag; + export function isJSDocReturnTag(node: Node): node is JSDocReturnTag; + export function isJSDocThisTag(node: Node): node is JSDocThisTag; + export function isJSDocTypeTag(node: Node): node is JSDocTypeTag; + export function isJSDocTemplateTag(node: Node): node is JSDocTemplateTag; + export function isJSDocTypedefTag(node: Node): node is JSDocTypedefTag; + export function isJSDocUnknownTag(node: Node): node is JSDocUnknownTag; + export function isJSDocPropertyTag(node: Node): node is JSDocPropertyTag; + export function isJSDocImplementsTag(node: Node): node is JSDocImplementsTag; + export function isJSDocSatisfiesTag(node: Node): node is JSDocSatisfiesTag; + export function isJSDocThrowsTag(node: Node): node is JSDocThrowsTag; + export function isJSDocImportTag(node: Node): node is JSDocImportTag; + export function isQuestionOrExclamationToken(node: Node): node is QuestionToken | ExclamationToken; + export function isIdentifierOrThisTypeNode(node: Node): node is Identifier | ThisTypeNode; + export function isReadonlyKeywordOrPlusOrMinusToken(node: Node): node is ReadonlyKeyword | PlusToken | MinusToken; + export function isQuestionOrPlusOrMinusToken(node: Node): node is QuestionToken | PlusToken | MinusToken; + export function isModuleName(node: Node): node is ModuleName; + export function isBinaryOperatorToken(node: Node): node is BinaryOperatorToken; + export function setTextRange(range: T, location: TextRange | undefined): T; + export function canHaveModifiers(node: Node): node is HasModifiers; + export function canHaveDecorators(node: Node): node is HasDecorators; + export function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile; + export function parseIsolatedEntityName(text: string, languageVersion: ScriptTarget): EntityName | undefined; /** * Parse json text into SyntaxTree and return node and parse errors if any * @param fileName * @param sourceText */ - function parseJsonText(fileName: string, sourceText: string): JsonSourceFile; - function isExternalModule(file: SourceFile): boolean; - function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; - interface CreateSourceFileOptions { + export function parseJsonText(fileName: string, sourceText: string): JsonSourceFile; + export function isExternalModule(file: SourceFile): boolean; + export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; + export interface CreateSourceFileOptions { languageVersion: ScriptTarget; /** * Controls the format the file is detected as - this can be derived from only the path @@ -9123,17 +11491,45 @@ declare namespace ts { setExternalModuleIndicator?: (file: SourceFile) => void; jsDocParsingMode?: JSDocParsingMode; } - function parseCommandLine(commandLine: readonly string[], readFile?: (path: string) => string | undefined): ParsedCommandLine; - function parseBuildCommand(commandLine: readonly string[]): ParsedBuildCommand; + /** + * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes + * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, + * embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns + * a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. + * + * @param node a given node to visit its children + * @param cbNode a callback to be invoked for all child nodes + * @param cbNodes a callback to be invoked for embedded array + * + * @remarks `forEachChild` must visit the children of a node in the order + * that they appear in the source code. The language service depends on this property to locate nodes by position. + */ + export function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined): T | undefined; + /** + * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes + * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, + * embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns + * a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. + * + * @param node a given node to visit its children + * @param cbNode a callback to be invoked for all child nodes + * @param cbNodes a callback to be invoked for embedded array + * + * @remarks `forEachChild` must visit the children of a node in the order + * that they appear in the source code. The language service depends on this property to locate nodes by position. + */ + export function astForEachChild(node: AstNode, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined; + export function parseCommandLine(commandLine: readonly string[], readFile?: (path: string) => string | undefined): ParsedCommandLine; + export function parseBuildCommand(commandLine: readonly string[]): ParsedBuildCommand; /** * Reads the config file, reports errors if any and exits if the config file cannot be found */ - function getParsedCommandLineOfConfigFile(configFileName: string, optionsToExtend: CompilerOptions | undefined, host: ParseConfigFileHost, extendedConfigCache?: Map, watchOptionsToExtend?: WatchOptions, extraFileExtensions?: readonly FileExtensionInfo[]): ParsedCommandLine | undefined; + export function getParsedCommandLineOfConfigFile(configFileName: string, optionsToExtend: CompilerOptions | undefined, host: ParseConfigFileHost, extendedConfigCache?: Map, watchOptionsToExtend?: WatchOptions, extraFileExtensions?: readonly FileExtensionInfo[]): ParsedCommandLine | undefined; /** * Read tsconfig.json file * @param fileName The path to the config file */ - function readConfigFile(fileName: string, readFile: (path: string) => string | undefined): { + export function readConfigFile(fileName: string, readFile: (path: string) => string | undefined): { config?: any; error?: Diagnostic; }; @@ -9142,7 +11538,7 @@ declare namespace ts { * @param fileName The path to the config file * @param jsonText The text of the config file */ - function parseConfigFileTextToJson(fileName: string, jsonText: string): { + export function parseConfigFileTextToJson(fileName: string, jsonText: string): { config?: any; error?: Diagnostic; }; @@ -9150,11 +11546,11 @@ declare namespace ts { * Read tsconfig.json file * @param fileName The path to the config file */ - function readJsonConfigFile(fileName: string, readFile: (path: string) => string | undefined): TsConfigSourceFile; + export function readJsonConfigFile(fileName: string, readFile: (path: string) => string | undefined): TsConfigSourceFile; /** * Convert the json syntax tree into the json value */ - function convertToObject(sourceFile: JsonSourceFile, errors: Diagnostic[]): any; + export function convertToObject(sourceFile: JsonSourceFile, errors: Diagnostic[]): any; /** * Parse the contents of a config file (tsconfig.json). * @param json The contents of the config file to parse @@ -9162,7 +11558,7 @@ declare namespace ts { * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ - function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: readonly FileExtensionInfo[], extendedConfigCache?: Map, existingWatchOptions?: WatchOptions): ParsedCommandLine; + export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: readonly FileExtensionInfo[], extendedConfigCache?: Map, existingWatchOptions?: WatchOptions): ParsedCommandLine; /** * Parse the contents of a config file (tsconfig.json). * @param jsonNode The contents of the config file to parse @@ -9170,27 +11566,27 @@ declare namespace ts { * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ - function parseJsonSourceFileConfigFileContent(sourceFile: TsConfigSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: readonly FileExtensionInfo[], extendedConfigCache?: Map, existingWatchOptions?: WatchOptions): ParsedCommandLine; - function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string, configFileName?: string): { + export function parseJsonSourceFileConfigFileContent(sourceFile: TsConfigSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: readonly FileExtensionInfo[], extendedConfigCache?: Map, existingWatchOptions?: WatchOptions): ParsedCommandLine; + export function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string, configFileName?: string): { options: CompilerOptions; errors: Diagnostic[]; }; - function convertTypeAcquisitionFromJson(jsonOptions: any, basePath: string, configFileName?: string): { + export function convertTypeAcquisitionFromJson(jsonOptions: any, basePath: string, configFileName?: string): { options: TypeAcquisition; errors: Diagnostic[]; }; /** Parsed command line for build */ - interface ParsedBuildCommand { + export interface ParsedBuildCommand { buildOptions: BuildOptions; watchOptions: WatchOptions | undefined; projects: string[]; errors: Diagnostic[]; } - type DiagnosticReporter = (diagnostic: Diagnostic) => void; + export type DiagnosticReporter = (diagnostic: Diagnostic) => void; /** * Reports config file diagnostics */ - interface ConfigFileDiagnosticsReporter { + export interface ConfigFileDiagnosticsReporter { /** * Reports unrecoverable error when parsing config file */ @@ -9199,10 +11595,10 @@ declare namespace ts { /** * Interface extending ParseConfigHost to support ParseConfigFile that reads config file and reports errors */ - interface ParseConfigFileHost extends ParseConfigHost, ConfigFileDiagnosticsReporter { + export interface ParseConfigFileHost extends ParseConfigHost, ConfigFileDiagnosticsReporter { getCurrentDirectory(): string; } - interface ParsedTsconfig { + export interface ParsedTsconfig { raw: any; options?: CompilerOptions; watchOptions?: WatchOptions; @@ -9212,17 +11608,17 @@ declare namespace ts { */ extendedConfigPath?: string | string[]; } - interface ExtendedConfigCacheEntry { + export interface ExtendedConfigCacheEntry { extendedResult: TsConfigSourceFile; extendedConfig: ParsedTsconfig | undefined; } - function getEffectiveTypeRoots(options: CompilerOptions, host: GetEffectiveTypeRootsHost): string[] | undefined; + export function getEffectiveTypeRoots(options: CompilerOptions, host: GetEffectiveTypeRootsHost): string[] | undefined; /** * @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown. * This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups * is assumed to be the same as root directory of the project. */ - function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, cache?: TypeReferenceDirectiveResolutionCache, resolutionMode?: ResolutionMode): ResolvedTypeReferenceDirectiveWithFailedLookupLocations; + export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, cache?: TypeReferenceDirectiveResolutionCache, resolutionMode?: ResolutionMode): ResolvedTypeReferenceDirectiveWithFailedLookupLocations; /** * Given a set of options, returns the set of type directive names * that should be included for this program automatically. @@ -9231,17 +11627,17 @@ declare namespace ts { * More type directives might appear in the program later as a result of loading actual source files; * this list is only the set of defaults that are implicitly included. */ - function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[]; - function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache): ModuleResolutionCache; - function createTypeReferenceDirectiveResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache): TypeReferenceDirectiveResolutionCache; - function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined; - function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations; - function bundlerModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; - function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; - function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; - interface TypeReferenceDirectiveResolutionCache extends PerDirectoryResolutionCache, NonRelativeNameResolutionCache, PackageJsonInfoCache { - } - interface ModeAwareCache { + export function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[]; + export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache): ModuleResolutionCache; + export function createTypeReferenceDirectiveResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache): TypeReferenceDirectiveResolutionCache; + export function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined; + export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations; + export function bundlerModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; + export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; + export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; + export interface TypeReferenceDirectiveResolutionCache extends PerDirectoryResolutionCache, NonRelativeNameResolutionCache, PackageJsonInfoCache { + } + export interface ModeAwareCache { get(key: string, mode: ResolutionMode): T | undefined; set(key: string, mode: ResolutionMode, value: T): this; delete(key: string, mode: ResolutionMode): this; @@ -9253,7 +11649,7 @@ declare namespace ts { * Cached resolutions per containing directory. * This assumes that any module id will have the same resolution for sibling files located in the same folder. */ - interface PerDirectoryResolutionCache { + export interface PerDirectoryResolutionCache { getFromDirectoryCache(name: string, mode: ResolutionMode, directoryName: string, redirectedReference: ResolvedProjectReference | undefined): T | undefined; getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference): ModeAwareCache; clear(): void; @@ -9263,7 +11659,7 @@ declare namespace ts { */ update(options: CompilerOptions): void; } - interface NonRelativeNameResolutionCache { + export interface NonRelativeNameResolutionCache { getFromNonRelativeNameCache(nonRelativeName: string, mode: ResolutionMode, directoryName: string, redirectedReference: ResolvedProjectReference | undefined): T | undefined; getOrCreateCacheForNonRelativeName(nonRelativeName: string, mode: ResolutionMode, redirectedReference?: ResolvedProjectReference): PerNonRelativeNameCache; clear(): void; @@ -9273,25 +11669,25 @@ declare namespace ts { */ update(options: CompilerOptions): void; } - interface PerNonRelativeNameCache { + export interface PerNonRelativeNameCache { get(directory: string): T | undefined; set(directory: string, result: T): void; } - interface ModuleResolutionCache extends PerDirectoryResolutionCache, NonRelativeModuleNameResolutionCache, PackageJsonInfoCache { + export interface ModuleResolutionCache extends PerDirectoryResolutionCache, NonRelativeModuleNameResolutionCache, PackageJsonInfoCache { getPackageJsonInfoCache(): PackageJsonInfoCache; } /** * Stored map from non-relative module name to a table: directory -> result of module lookup in this directory * We support only non-relative module names because resolution of relative module names is usually more deterministic and thus less expensive. */ - interface NonRelativeModuleNameResolutionCache extends NonRelativeNameResolutionCache, PackageJsonInfoCache { + export interface NonRelativeModuleNameResolutionCache extends NonRelativeNameResolutionCache, PackageJsonInfoCache { /** @deprecated Use getOrCreateCacheForNonRelativeName */ getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ResolutionMode, redirectedReference?: ResolvedProjectReference): PerModuleNameCache; } - interface PackageJsonInfoCache { + export interface PackageJsonInfoCache { clear(): void; } - type PerModuleNameCache = PerNonRelativeNameCache; + export type PerModuleNameCache = PerNonRelativeNameCache; /** * Visits a Node using the supplied visitor, possibly returning a new Node in its place. * @@ -9306,7 +11702,7 @@ declare namespace ts { * @param test A callback to execute to verify the Node is valid. * @param lift An optional callback to execute to lift a NodeArray into a valid Node. */ - function visitNode(node: TIn, visitor: Visitor, TVisited>, test: (node: Node) => node is TOut, lift?: (node: readonly Node[]) => Node): TOut | (TIn & undefined) | (TVisited & undefined); + export function visitNode(node: TIn, visitor: Visitor, TVisited>, test: (node: Node) => node is TOut, lift?: (node: readonly Node[]) => Node): TOut | (TIn & undefined) | (TVisited & undefined); /** * Visits a Node using the supplied visitor, possibly returning a new Node in its place. * @@ -9321,7 +11717,7 @@ declare namespace ts { * @param test A callback to execute to verify the Node is valid. * @param lift An optional callback to execute to lift a NodeArray into a valid Node. */ - function visitNode(node: TIn, visitor: Visitor, TVisited>, test?: (node: Node) => boolean, lift?: (node: readonly Node[]) => Node): Node | (TIn & undefined) | (TVisited & undefined); + export function visitNode(node: TIn, visitor: Visitor, TVisited>, test?: (node: Node) => boolean, lift?: (node: readonly Node[]) => Node): Node | (TIn & undefined) | (TVisited & undefined); /** * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. * @@ -9337,7 +11733,7 @@ declare namespace ts { * @param start An optional value indicating the starting offset at which to start visiting. * @param count An optional value indicating the maximum number of nodes to visit. */ - function visitNodes | undefined, TOut extends Node>(nodes: TInArray, visitor: Visitor, test: (node: Node) => node is TOut, start?: number, count?: number): NodeArray | (TInArray & undefined); + export function visitNodes | undefined, TOut extends Node>(nodes: TInArray, visitor: Visitor, test: (node: Node) => node is TOut, start?: number, count?: number): NodeArray | (TInArray & undefined); /** * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. * @@ -9353,43 +11749,43 @@ declare namespace ts { * @param start An optional value indicating the starting offset at which to start visiting. * @param count An optional value indicating the maximum number of nodes to visit. */ - function visitNodes | undefined>(nodes: TInArray, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | (TInArray & undefined); + export function visitNodes | undefined>(nodes: TInArray, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | (TInArray & undefined); /** * Starts a new lexical environment and visits a statement list, ending the lexical environment * and merging hoisted declarations upon completion. */ - function visitLexicalEnvironment(statements: NodeArray, visitor: Visitor, context: TransformationContext, start?: number, ensureUseStrict?: boolean, nodesVisitor?: NodesVisitor): NodeArray; + export function visitLexicalEnvironment(statements: NodeArray, visitor: Visitor, context: TransformationContext, start?: number, ensureUseStrict?: boolean, nodesVisitor?: NodesVisitor): NodeArray; /** * Starts a new lexical environment and visits a parameter list, suspending the lexical * environment upon completion. */ - function visitParameterList(nodes: NodeArray, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray; - function visitParameterList(nodes: NodeArray | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray | undefined; + export function visitParameterList(nodes: NodeArray, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray; + export function visitParameterList(nodes: NodeArray | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray | undefined; /** * Resumes a suspended lexical environment and visits a function body, ending the lexical * environment and merging hoisted declarations upon completion. */ - function visitFunctionBody(node: FunctionBody, visitor: Visitor, context: TransformationContext): FunctionBody; + export function visitFunctionBody(node: FunctionBody, visitor: Visitor, context: TransformationContext): FunctionBody; /** * Resumes a suspended lexical environment and visits a function body, ending the lexical * environment and merging hoisted declarations upon completion. */ - function visitFunctionBody(node: FunctionBody | undefined, visitor: Visitor, context: TransformationContext): FunctionBody | undefined; + export function visitFunctionBody(node: FunctionBody | undefined, visitor: Visitor, context: TransformationContext): FunctionBody | undefined; /** * Resumes a suspended lexical environment and visits a concise body, ending the lexical * environment and merging hoisted declarations upon completion. */ - function visitFunctionBody(node: ConciseBody, visitor: Visitor, context: TransformationContext): ConciseBody; + export function visitFunctionBody(node: ConciseBody, visitor: Visitor, context: TransformationContext): ConciseBody; /** * Visits an iteration body, adding any block-scoped variables required by the transformation. */ - function visitIterationBody(body: Statement, visitor: Visitor, context: TransformationContext): Statement; + export function visitIterationBody(body: Statement, visitor: Visitor, context: TransformationContext): Statement; /** * Visits the elements of a {@link CommaListExpression}. * @param visitor The visitor to use when visiting expressions whose result will not be discarded at runtime. * @param discardVisitor The visitor to use when visiting expressions whose result will be discarded at runtime. Defaults to {@link visitor}. */ - function visitCommaListElements(elements: NodeArray, visitor: Visitor, discardVisitor?: Visitor): NodeArray; + export function visitCommaListElements(elements: NodeArray, visitor: Visitor, discardVisitor?: Visitor): NodeArray; /** * Visits each child of a Node using the supplied visitor, possibly returning a new Node of the same kind in its place. * @@ -9397,7 +11793,7 @@ declare namespace ts { * @param visitor The callback used to visit each child. * @param context A lexical environment context for the visitor. */ - function visitEachChild(node: T, visitor: Visitor, context: TransformationContext | undefined): T; + export function visitEachChild(node: T, visitor: Visitor, context: TransformationContext | undefined): T; /** * Visits each child of a Node using the supplied visitor, possibly returning a new Node of the same kind in its place. * @@ -9405,11 +11801,11 @@ declare namespace ts { * @param visitor The callback used to visit each child. * @param context A lexical environment context for the visitor. */ - function visitEachChild(node: T | undefined, visitor: Visitor, context: TransformationContext | undefined, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined; - function getTsBuildInfoEmitOutputFilePath(options: CompilerOptions): string | undefined; - function getOutputFileNames(commandLine: ParsedCommandLine, inputFileName: string, ignoreCase: boolean): readonly string[]; - function createPrinter(printerOptions?: PrinterOptions, handlers?: PrintHandlers): Printer; - enum ProgramUpdateLevel { + export function visitEachChild(node: T | undefined, visitor: Visitor, context: TransformationContext | undefined, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined; + export function getTsBuildInfoEmitOutputFilePath(options: CompilerOptions): string | undefined; + export function getOutputFileNames(commandLine: ParsedCommandLine, inputFileName: string, ignoreCase: boolean): readonly string[]; + export function createPrinter(printerOptions?: PrinterOptions, handlers?: PrintHandlers): Printer; + export enum ProgramUpdateLevel { /** Program is updated with same root file names and options */ Update = 0, /** Loads program after updating root file names from the disk */ @@ -9422,19 +11818,19 @@ declare namespace ts { */ Full = 2, } - function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName?: string): string | undefined; - function resolveTripleslashReference(moduleName: string, containingFile: string): string; - function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; - function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): readonly Diagnostic[]; - function formatDiagnostics(diagnostics: readonly Diagnostic[], host: FormatDiagnosticsHost): string; - function formatDiagnostic(diagnostic: Diagnostic, host: FormatDiagnosticsHost): string; - function formatDiagnosticsWithColorAndContext(diagnostics: readonly Diagnostic[], host: FormatDiagnosticsHost): string; - function flattenDiagnosticMessageText(diag: string | DiagnosticMessageChain | undefined, newLine: string, indent?: number): string; + export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName?: string): string | undefined; + export function resolveTripleslashReference(moduleName: string, containingFile: string): string; + export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; + export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): readonly Diagnostic[]; + export function formatDiagnostics(diagnostics: readonly Diagnostic[], host: FormatDiagnosticsHost): string; + export function formatDiagnostic(diagnostic: Diagnostic, host: FormatDiagnosticsHost): string; + export function formatDiagnosticsWithColorAndContext(diagnostics: readonly Diagnostic[], host: FormatDiagnosticsHost): string; + export function flattenDiagnosticMessageText(diag: string | DiagnosticMessageChain | undefined, newLine: string, indent?: number): string; /** * Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly * provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file. */ - function getModeForFileReference(ref: FileReference | string, containingFileMode: ResolutionMode): ResolutionMode; + export function getModeForFileReference(ref: FileReference | string, containingFileMode: ResolutionMode): ResolutionMode; /** * Use `program.getModeForResolutionAtIndex`, which retrieves the correct `compilerOptions`, instead of this function whenever possible. * Calculates the final resolution mode for an import at some index within a file's `imports` list. This is the resolution mode @@ -9447,7 +11843,7 @@ declare namespace ts { * @param compilerOptions The compiler options for the program that owns the file. If the file belongs to a referenced project, the compiler options * should be the options of the referenced project, not the referencing project. */ - function getModeForResolutionAtIndex(file: SourceFile, index: number, compilerOptions: CompilerOptions): ResolutionMode; + export function getModeForResolutionAtIndex(file: SourceFile, index: number, compilerOptions: CompilerOptions): ResolutionMode; /** * Use `program.getModeForUsageLocation`, which retrieves the correct `compilerOptions`, instead of this function whenever possible. * Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution @@ -9486,8 +11882,8 @@ declare namespace ts { * should be the options of the referenced project, not the referencing project. * @returns The final resolution mode of the import */ - function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike, compilerOptions: CompilerOptions): ResolutionMode; - function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[]; + export function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike, compilerOptions: CompilerOptions): ResolutionMode; + export function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[]; /** * A function for determining if a given file is esm or cjs format, assuming modern node module resolution rules, as configured by the * `options` parameter. @@ -9498,7 +11894,7 @@ declare namespace ts { * @param options The compiler options to perform the analysis under - relevant options are `moduleResolution` and `traceResolution` * @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format */ - function getImpliedNodeFormatForFile(fileName: string, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions): ResolutionMode; + export function getImpliedNodeFormatForFile(fileName: string, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions): ResolutionMode; /** * Create a new 'Program' instance. A Program is an immutable collection of 'SourceFile's and a 'CompilerOptions' * that represent a compilation unit. @@ -9509,7 +11905,7 @@ declare namespace ts { * @param createProgramOptions - The options for creating a program. * @returns A 'Program' object. */ - function createProgram(createProgramOptions: CreateProgramOptions): Program; + export function createProgram(createProgramOptions: CreateProgramOptions): Program; /** * Create a new 'Program' instance. A Program is an immutable collection of 'SourceFile's and a 'CompilerOptions' * that represent a compilation unit. @@ -9524,23 +11920,23 @@ declare namespace ts { * @param configFileParsingDiagnostics - error during config file parsing * @returns A 'Program' object. */ - function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[]): Program; + export function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[]): Program; /** * Returns the target config filename of a project reference. * Note: The file might not exist. */ - function resolveProjectReferencePath(ref: ProjectReference): ResolvedConfigFileName; - interface FormatDiagnosticsHost { + export function resolveProjectReferencePath(ref: ProjectReference): ResolvedConfigFileName; + export interface FormatDiagnosticsHost { getCurrentDirectory(): string; getCanonicalFileName(fileName: string): string; getNewLine(): string; } - interface EmitOutput { + export interface EmitOutput { outputFiles: OutputFile[]; emitSkipped: boolean; diagnostics: readonly Diagnostic[]; } - interface OutputFile { + export interface OutputFile { name: string; writeByteOrderMark: boolean; text: string; @@ -9548,24 +11944,24 @@ declare namespace ts { /** * Create the builder to manage semantic diagnostics and cache them */ - function createSemanticDiagnosticsBuilderProgram(newProgram: Program, host: BuilderProgramHost, oldProgram?: SemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[]): SemanticDiagnosticsBuilderProgram; - function createSemanticDiagnosticsBuilderProgram(rootNames: readonly string[] | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: SemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[], projectReferences?: readonly ProjectReference[]): SemanticDiagnosticsBuilderProgram; + export function createSemanticDiagnosticsBuilderProgram(newProgram: Program, host: BuilderProgramHost, oldProgram?: SemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[]): SemanticDiagnosticsBuilderProgram; + export function createSemanticDiagnosticsBuilderProgram(rootNames: readonly string[] | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: SemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[], projectReferences?: readonly ProjectReference[]): SemanticDiagnosticsBuilderProgram; /** * Create the builder that can handle the changes in program and iterate through changed files * to emit the those files and manage semantic diagnostics cache as well */ - function createEmitAndSemanticDiagnosticsBuilderProgram(newProgram: Program, host: BuilderProgramHost, oldProgram?: EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[]): EmitAndSemanticDiagnosticsBuilderProgram; - function createEmitAndSemanticDiagnosticsBuilderProgram(rootNames: readonly string[] | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[], projectReferences?: readonly ProjectReference[]): EmitAndSemanticDiagnosticsBuilderProgram; + export function createEmitAndSemanticDiagnosticsBuilderProgram(newProgram: Program, host: BuilderProgramHost, oldProgram?: EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[]): EmitAndSemanticDiagnosticsBuilderProgram; + export function createEmitAndSemanticDiagnosticsBuilderProgram(rootNames: readonly string[] | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[], projectReferences?: readonly ProjectReference[]): EmitAndSemanticDiagnosticsBuilderProgram; /** * Creates a builder thats just abstraction over program and can be used with watch */ - function createAbstractBuilder(newProgram: Program, host: BuilderProgramHost, oldProgram?: BuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[]): BuilderProgram; - function createAbstractBuilder(rootNames: readonly string[] | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: BuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[], projectReferences?: readonly ProjectReference[]): BuilderProgram; - type AffectedFileResult = { + export function createAbstractBuilder(newProgram: Program, host: BuilderProgramHost, oldProgram?: BuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[]): BuilderProgram; + export function createAbstractBuilder(rootNames: readonly string[] | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: BuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[], projectReferences?: readonly ProjectReference[]): BuilderProgram; + export type AffectedFileResult = { result: T; affected: SourceFile | Program; } | undefined; - interface BuilderProgramHost { + export interface BuilderProgramHost { /** * If provided this would be used this hash instead of actual file shape text for detecting changes */ @@ -9579,7 +11975,7 @@ declare namespace ts { /** * Builder to manage the program state changes */ - interface BuilderProgram { + export interface BuilderProgram { /** * Returns current program */ @@ -9649,7 +12045,7 @@ declare namespace ts { /** * The builder that caches the semantic diagnostics for the program and handles the changed files and affected files */ - interface SemanticDiagnosticsBuilderProgram extends BuilderProgram { + export interface SemanticDiagnosticsBuilderProgram extends BuilderProgram { /** * Gets the semantic diagnostics from the program for the next affected file and caches it * Returns undefined if the iteration is complete @@ -9660,7 +12056,7 @@ declare namespace ts { * The builder that can handle the changes in program and iterate through changed file to emit the files * The semantic diagnostics are cached per file and managed by clearing for the changed/affected files */ - interface EmitAndSemanticDiagnosticsBuilderProgram extends SemanticDiagnosticsBuilderProgram { + export interface EmitAndSemanticDiagnosticsBuilderProgram extends SemanticDiagnosticsBuilderProgram { /** * Emits the next affected file's emit result (EmitResult and sourceFiles emitted) or returns undefined if iteration is complete * The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host @@ -9668,28 +12064,28 @@ declare namespace ts { */ emitNextAffectedFile(writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): AffectedFileResult; } - function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost): EmitAndSemanticDiagnosticsBuilderProgram | undefined; - function createIncrementalCompilerHost(options: CompilerOptions, system?: System): CompilerHost; - function createIncrementalProgram({ rootNames, options, configFileParsingDiagnostics, projectReferences, host, createProgram }: IncrementalProgramOptions): T; + export function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost): EmitAndSemanticDiagnosticsBuilderProgram | undefined; + export function createIncrementalCompilerHost(options: CompilerOptions, system?: System): CompilerHost; + export function createIncrementalProgram({ rootNames, options, configFileParsingDiagnostics, projectReferences, host, createProgram }: IncrementalProgramOptions): T; /** * Create the watch compiler host for either configFile or fileNames and its options */ - function createWatchCompilerHost(configFileName: string, optionsToExtend: CompilerOptions | undefined, system: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter, watchOptionsToExtend?: WatchOptions, extraFileExtensions?: readonly FileExtensionInfo[]): WatchCompilerHostOfConfigFile; - function createWatchCompilerHost(rootFiles: string[], options: CompilerOptions, system: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter, projectReferences?: readonly ProjectReference[], watchOptions?: WatchOptions): WatchCompilerHostOfFilesAndCompilerOptions; + export function createWatchCompilerHost(configFileName: string, optionsToExtend: CompilerOptions | undefined, system: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter, watchOptionsToExtend?: WatchOptions, extraFileExtensions?: readonly FileExtensionInfo[]): WatchCompilerHostOfConfigFile; + export function createWatchCompilerHost(rootFiles: string[], options: CompilerOptions, system: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter, projectReferences?: readonly ProjectReference[], watchOptions?: WatchOptions): WatchCompilerHostOfFilesAndCompilerOptions; /** * Creates the watch from the host for root files and compiler options */ - function createWatchProgram(host: WatchCompilerHostOfFilesAndCompilerOptions): WatchOfFilesAndCompilerOptions; + export function createWatchProgram(host: WatchCompilerHostOfFilesAndCompilerOptions): WatchOfFilesAndCompilerOptions; /** * Creates the watch from the host for config file */ - function createWatchProgram(host: WatchCompilerHostOfConfigFile): WatchOfConfigFile; - interface ReadBuildProgramHost { + export function createWatchProgram(host: WatchCompilerHostOfConfigFile): WatchOfConfigFile; + export interface ReadBuildProgramHost { useCaseSensitiveFileNames(): boolean; getCurrentDirectory(): string; readFile(fileName: string): string | undefined; } - interface IncrementalProgramOptions { + export interface IncrementalProgramOptions { rootNames: readonly string[]; options: CompilerOptions; configFileParsingDiagnostics?: readonly Diagnostic[]; @@ -9697,11 +12093,11 @@ declare namespace ts { host?: CompilerHost; createProgram?: CreateProgram; } - type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number) => void; + export type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number) => void; /** Create the program with rootNames and options, if they are undefined, oldProgram and new configFile diagnostics create new program */ - type CreateProgram = (rootNames: readonly string[] | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: T, configFileParsingDiagnostics?: readonly Diagnostic[], projectReferences?: readonly ProjectReference[] | undefined) => T; + export type CreateProgram = (rootNames: readonly string[] | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: T, configFileParsingDiagnostics?: readonly Diagnostic[], projectReferences?: readonly ProjectReference[] | undefined) => T; /** Host that has watch functionality used in --watch mode */ - interface WatchHost { + export interface WatchHost { /** If provided, called with Diagnostic message that informs about change in watch status */ onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions, errorCount?: number): void; /** Used to watch changes in source files, missing files needed to update the program or config file */ @@ -9714,7 +12110,7 @@ declare namespace ts { clearTimeout?(timeoutId: any): void; preferNonRecursiveWatch?: boolean; } - interface ProgramHost { + export interface ProgramHost { /** * Used to create the program when need for program creation or recreation detected */ @@ -9769,7 +12165,7 @@ declare namespace ts { getModuleResolutionCache?(): ModuleResolutionCache | undefined; jsDocParsingMode?: JSDocParsingMode; } - interface WatchCompilerHost extends ProgramHost, WatchHost { + export interface WatchCompilerHost extends ProgramHost, WatchHost { /** Instead of using output d.ts file from project reference, use its source file */ useSourceOfProjectReferenceRedirect?(): boolean; /** If provided, use this method to get parsed command lines for referenced projects */ @@ -9780,7 +12176,7 @@ declare namespace ts { /** * Host to create watch with root files and options */ - interface WatchCompilerHostOfFilesAndCompilerOptions extends WatchCompilerHost { + export interface WatchCompilerHostOfFilesAndCompilerOptions extends WatchCompilerHost { /** root files to use to generate program */ rootFiles: string[]; /** Compiler options */ @@ -9792,7 +12188,7 @@ declare namespace ts { /** * Host to create watch with config file */ - interface WatchCompilerHostOfConfigFile extends WatchCompilerHost, ConfigFileDiagnosticsReporter { + export interface WatchCompilerHostOfConfigFile extends WatchCompilerHost, ConfigFileDiagnosticsReporter { /** Name of the config file to compile */ configFileName: string; /** Options to extend */ @@ -9805,7 +12201,7 @@ declare namespace ts { */ readDirectory(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[]; } - interface Watch { + export interface Watch { /** Synchronize with host and get updated program */ getProgram(): T; /** Closes the watch */ @@ -9814,24 +12210,24 @@ declare namespace ts { /** * Creates the watch what generates program using the config file */ - interface WatchOfConfigFile extends Watch { + export interface WatchOfConfigFile extends Watch { } /** * Creates the watch that generates program using the root files and compiler options */ - interface WatchOfFilesAndCompilerOptions extends Watch { + export interface WatchOfFilesAndCompilerOptions extends Watch { /** Updates the root files in the program, only if this is not config file compilation */ updateRootFileNames(fileNames: string[]): void; } /** * Create a function that reports watch status by writing to the system and handles the formating of the diagnostic */ - function createBuilderStatusReporter(system: System, pretty?: boolean): DiagnosticReporter; - function createSolutionBuilderHost(system?: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): SolutionBuilderHost; - function createSolutionBuilderWithWatchHost(system?: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): SolutionBuilderWithWatchHost; - function createSolutionBuilder(host: SolutionBuilderHost, rootNames: readonly string[], defaultOptions: BuildOptions): SolutionBuilder; - function createSolutionBuilderWithWatch(host: SolutionBuilderWithWatchHost, rootNames: readonly string[], defaultOptions: BuildOptions, baseWatchOptions?: WatchOptions): SolutionBuilder; - interface BuildOptions { + export function createBuilderStatusReporter(system: System, pretty?: boolean): DiagnosticReporter; + export function createSolutionBuilderHost(system?: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): SolutionBuilderHost; + export function createSolutionBuilderWithWatchHost(system?: System, createProgram?: CreateProgram, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): SolutionBuilderWithWatchHost; + export function createSolutionBuilder(host: SolutionBuilderHost, rootNames: readonly string[], defaultOptions: BuildOptions): SolutionBuilder; + export function createSolutionBuilderWithWatch(host: SolutionBuilderWithWatchHost, rootNames: readonly string[], defaultOptions: BuildOptions, baseWatchOptions?: WatchOptions): SolutionBuilder; + export interface BuildOptions { dry?: boolean; force?: boolean; verbose?: boolean; @@ -9846,12 +12242,12 @@ declare namespace ts { traceResolution?: boolean; [option: string]: CompilerOptionsValue | undefined; } - type ReportEmitErrorSummary = (errorCount: number, filesInError: (ReportFileInError | undefined)[]) => void; - interface ReportFileInError { + export type ReportEmitErrorSummary = (errorCount: number, filesInError: (ReportFileInError | undefined)[]) => void; + export interface ReportFileInError { fileName: string; line: number; } - interface SolutionBuilderHostBase extends ProgramHost { + export interface SolutionBuilderHostBase extends ProgramHost { createDirectory?(path: string): void; /** * Should provide create directory and writeFile if done of invalidatedProjects is not invoked with @@ -9867,23 +12263,23 @@ declare namespace ts { reportSolutionBuilderStatus: DiagnosticReporter; afterProgramEmitAndDiagnostics?(program: T): void; } - interface SolutionBuilderHost extends SolutionBuilderHostBase { + export interface SolutionBuilderHost extends SolutionBuilderHostBase { reportErrorSummary?: ReportEmitErrorSummary; } - interface SolutionBuilderWithWatchHost extends SolutionBuilderHostBase, WatchHost { + export interface SolutionBuilderWithWatchHost extends SolutionBuilderHostBase, WatchHost { } - interface SolutionBuilder { + export interface SolutionBuilder { build(project?: string, cancellationToken?: CancellationToken, writeFile?: WriteFileCallback, getCustomTransformers?: (project: string) => CustomTransformers): ExitStatus; clean(project?: string): ExitStatus; buildReferences(project: string, cancellationToken?: CancellationToken, writeFile?: WriteFileCallback, getCustomTransformers?: (project: string) => CustomTransformers): ExitStatus; cleanReferences(project?: string): ExitStatus; getNextInvalidatedProject(cancellationToken?: CancellationToken): InvalidatedProject | undefined; } - enum InvalidatedProjectKind { + export enum InvalidatedProjectKind { Build = 0, UpdateOutputFileStamps = 1, } - interface InvalidatedProjectBase { + export interface InvalidatedProjectBase { readonly kind: InvalidatedProjectKind; readonly project: ResolvedConfigFileName; /** @@ -9893,11 +12289,11 @@ declare namespace ts { getCompilerOptions(): CompilerOptions; getCurrentDirectory(): string; } - interface UpdateOutputFileStampsProject extends InvalidatedProjectBase { + export interface UpdateOutputFileStampsProject extends InvalidatedProjectBase { readonly kind: InvalidatedProjectKind.UpdateOutputFileStamps; updateOutputFileStatmps(): void; } - interface BuildInvalidedProject extends InvalidatedProjectBase { + export interface BuildInvalidedProject extends InvalidatedProjectBase { readonly kind: InvalidatedProjectKind.Build; getBuilderProgram(): T | undefined; getProgram(): Program | undefined; @@ -9912,35 +12308,14 @@ declare namespace ts { getSemanticDiagnosticsOfNextAffectedFile(cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): AffectedFileResult; emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): EmitResult | undefined; } - type InvalidatedProject = UpdateOutputFileStampsProject | BuildInvalidedProject; + export type InvalidatedProject = UpdateOutputFileStampsProject | BuildInvalidedProject; /** Returns true if commandline is --build and needs to be parsed useing parseBuildCommand */ - function isBuildCommand(commandLineArgs: readonly string[]): boolean; - function getDefaultFormatCodeSettings(newLineCharacter?: string): FormatCodeSettings; - /** - * Represents an immutable snapshot of a script at a specified time.Once acquired, the - * snapshot is observably immutable. i.e. the same calls with the same parameters will return - * the same values. - */ - interface IScriptSnapshot { - /** Gets a portion of the script snapshot specified by [start, end). */ - getText(start: number, end: number): string; - /** Gets the length of this script snapshot. */ - getLength(): number; - /** - * Gets the TextChangeRange that describe how the text changed between this text and - * an older version. This information is used by the incremental parser to determine - * what sections of the script need to be re-parsed. 'undefined' can be returned if the - * change range cannot be determined. However, in that case, incremental parsing will - * not happen and the entire document will be re - parsed. - */ - getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined; - /** Releases all resources held by this script snapshot */ - dispose?(): void; - } - namespace ScriptSnapshot { + export function isBuildCommand(commandLineArgs: readonly string[]): boolean; + export function getDefaultFormatCodeSettings(newLineCharacter?: string): FormatCodeSettings; + export namespace ScriptSnapshot { function fromString(text: string): IScriptSnapshot; } - interface PreProcessedFileInfo { + export interface PreProcessedFileInfo { referencedFiles: FileReference[]; typeReferenceDirectives: FileReference[]; libReferenceDirectives: FileReference[]; @@ -9948,28 +12323,28 @@ declare namespace ts { ambientExternalModules?: string[]; isLibFile: boolean; } - interface HostCancellationToken { + export interface HostCancellationToken { isCancellationRequested(): boolean; } - interface InstallPackageOptions { + export interface InstallPackageOptions { fileName: Path; packageName: string; } - interface PerformanceEvent { + export interface PerformanceEvent { kind: "UpdateGraph" | "CreatePackageJsonAutoImportProvider"; durationMs: number; } - enum LanguageServiceMode { + export enum LanguageServiceMode { Semantic = 0, PartialSemantic = 1, Syntactic = 2, } - interface IncompleteCompletionsCache { + export interface IncompleteCompletionsCache { get(): CompletionInfo | undefined; set(response: CompletionInfo): void; clear(): void; } - interface LanguageServiceHost extends GetEffectiveTypeRootsHost, MinimalResolutionCacheHost { + export interface LanguageServiceHost extends GetEffectiveTypeRootsHost, MinimalResolutionCacheHost { getCompilationSettings(): CompilerOptions; getNewLine?(): string; getProjectVersion?(): string; @@ -10009,14 +12384,14 @@ declare namespace ts { getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined; jsDocParsingMode?: JSDocParsingMode | undefined; } - type WithMetadata = T & { + export type WithMetadata = T & { metadata?: unknown; }; - enum SemanticClassificationFormat { + export enum SemanticClassificationFormat { Original = "original", TwentyTwenty = "2020", } - interface LanguageService { + export interface LanguageService { /** This is used as a part of restarting the language service. */ cleanupSemanticCache(): void; /** @@ -10191,27 +12566,27 @@ declare namespace ts { dispose(): void; getPasteEdits(args: PasteEditsArgs, formatOptions: FormatCodeSettings): PasteEdits; } - interface JsxClosingTagInfo { + export interface JsxClosingTagInfo { readonly newText: string; } - interface LinkedEditingInfo { + export interface LinkedEditingInfo { readonly ranges: TextSpan[]; wordPattern?: string; } - interface CombinedCodeFixScope { + export interface CombinedCodeFixScope { type: "file"; fileName: string; } - enum OrganizeImportsMode { + export enum OrganizeImportsMode { All = "All", SortAndCombine = "SortAndCombine", RemoveUnused = "RemoveUnused", } - interface PasteEdits { + export interface PasteEdits { edits: readonly FileTextChanges[]; fixId?: {}; } - interface PasteEditsArgs { + export interface PasteEditsArgs { targetFile: string; pastedText: string[]; pasteLocations: TextRange[]; @@ -10221,13 +12596,13 @@ declare namespace ts { } | undefined; preferences: UserPreferences; } - interface OrganizeImportsArgs extends CombinedCodeFixScope { + export interface OrganizeImportsArgs extends CombinedCodeFixScope { /** @deprecated Use `mode` instead */ skipDestructiveCodeActions?: boolean; mode?: OrganizeImportsMode; } - type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#" | " "; - enum CompletionTriggerKind { + export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#" | " "; + export enum CompletionTriggerKind { /** Completion was triggered by typing an identifier, manual invocation (e.g Ctrl+Space) or via API. */ Invoked = 1, /** Completion was triggered by a trigger character. */ @@ -10235,7 +12610,7 @@ declare namespace ts { /** Completion was re-triggered as the current completion list is incomplete. */ TriggerForIncompleteCompletions = 3, } - interface GetCompletionsAtPositionOptions extends UserPreferences { + export interface GetCompletionsAtPositionOptions extends UserPreferences { /** * If the editor is asking for completions because a certain character was typed * (as opposed to when the user explicitly requested them) this should be set. @@ -10254,17 +12629,17 @@ declare namespace ts { /** @deprecated Use includeCompletionsWithInsertText */ includeInsertTextCompletions?: boolean; } - type SignatureHelpTriggerCharacter = "," | "(" | "<"; - type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; - interface SignatureHelpItemsOptions { + export type SignatureHelpTriggerCharacter = "," | "(" | "<"; + export type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")"; + export interface SignatureHelpItemsOptions { triggerReason?: SignatureHelpTriggerReason; } - type SignatureHelpTriggerReason = SignatureHelpInvokedReason | SignatureHelpCharacterTypedReason | SignatureHelpRetriggeredReason; + export type SignatureHelpTriggerReason = SignatureHelpInvokedReason | SignatureHelpCharacterTypedReason | SignatureHelpRetriggeredReason; /** * Signals that the user manually requested signature help. * The language service will unconditionally attempt to provide a result. */ - interface SignatureHelpInvokedReason { + export interface SignatureHelpInvokedReason { kind: "invoked"; triggerCharacter?: undefined; } @@ -10272,7 +12647,7 @@ declare namespace ts { * Signals that the signature help request came from a user typing a character. * Depending on the character and the syntactic context, the request may or may not be served a result. */ - interface SignatureHelpCharacterTypedReason { + export interface SignatureHelpCharacterTypedReason { kind: "characterTyped"; /** * Character that was responsible for triggering signature help. @@ -10285,25 +12660,25 @@ declare namespace ts { * The language service will unconditionally attempt to provide a result. * `triggerCharacter` can be `undefined` for a retrigger caused by a cursor move. */ - interface SignatureHelpRetriggeredReason { + export interface SignatureHelpRetriggeredReason { kind: "retrigger"; /** * Character that was responsible for triggering signature help. */ triggerCharacter?: SignatureHelpRetriggerCharacter; } - interface ApplyCodeActionCommandResult { + export interface ApplyCodeActionCommandResult { successMessage: string; } - interface Classifications { + export interface Classifications { spans: number[]; endOfLineState: EndOfLineState; } - interface ClassifiedSpan { + export interface ClassifiedSpan { textSpan: TextSpan; classificationType: ClassificationTypeNames; } - interface ClassifiedSpan2020 { + export interface ClassifiedSpan2020 { textSpan: TextSpan; classificationType: number; } @@ -10313,7 +12688,7 @@ declare namespace ts { * The navbar is returned as a list of top-level items, each of which has a list of child items. * Child items always have an empty array for their `childItems`. */ - interface NavigationBarItem { + export interface NavigationBarItem { text: string; kind: ScriptElementKind; kindModifiers: string; @@ -10327,7 +12702,7 @@ declare namespace ts { * Node in a tree of nested declarations in a file. * The top node is always a script or module node. */ - interface NavigationTree { + export interface NavigationTree { /** Name of the declaration, or a short description, e.g. "". */ text: string; kind: ScriptElementKind; @@ -10342,7 +12717,7 @@ declare namespace ts { /** Present if non-empty */ childItems?: NavigationTree[]; } - interface CallHierarchyItem { + export interface CallHierarchyItem { name: string; kind: ScriptElementKind; kindModifiers?: string; @@ -10351,20 +12726,20 @@ declare namespace ts { selectionSpan: TextSpan; containerName?: string; } - interface CallHierarchyIncomingCall { + export interface CallHierarchyIncomingCall { from: CallHierarchyItem; fromSpans: TextSpan[]; } - interface CallHierarchyOutgoingCall { + export interface CallHierarchyOutgoingCall { to: CallHierarchyItem; fromSpans: TextSpan[]; } - enum InlayHintKind { + export enum InlayHintKind { Type = "Type", Parameter = "Parameter", Enum = "Enum", } - interface InlayHint { + export interface InlayHint { /** This property will be the empty string when displayParts is set. */ text: string; position: number; @@ -10373,30 +12748,30 @@ declare namespace ts { whitespaceAfter?: boolean; displayParts?: InlayHintDisplayPart[]; } - interface InlayHintDisplayPart { + export interface InlayHintDisplayPart { text: string; span?: TextSpan; file?: string; } - interface TodoCommentDescriptor { + export interface TodoCommentDescriptor { text: string; priority: number; } - interface TodoComment { + export interface TodoComment { descriptor: TodoCommentDescriptor; message: string; position: number; } - interface TextChange { + export interface TextChange { span: TextSpan; newText: string; } - interface FileTextChanges { + export interface FileTextChanges { fileName: string; textChanges: readonly TextChange[]; isNewFile?: boolean; } - interface CodeAction { + export interface CodeAction { /** Description of the code action to display in the UI of the editor */ description: string; /** Text changes to apply to each file as part of the code action */ @@ -10407,7 +12782,7 @@ declare namespace ts { */ commands?: CodeActionCommand[]; } - interface CodeFixAction extends CodeAction { + export interface CodeFixAction extends CodeAction { /** Short name to identify the fix, for use by telemetry. */ fixName: string; /** @@ -10417,17 +12792,17 @@ declare namespace ts { fixId?: {}; fixAllDescription?: string; } - interface CombinedCodeActions { + export interface CombinedCodeActions { changes: readonly FileTextChanges[]; commands?: readonly CodeActionCommand[]; } - type CodeActionCommand = InstallPackageAction; - interface InstallPackageAction { + export type CodeActionCommand = InstallPackageAction; + export interface InstallPackageAction { } /** * A set of one or more available refactoring actions, grouped under a parent refactoring. */ - interface ApplicableRefactorInfo { + export interface ApplicableRefactorInfo { /** * The programmatic name of the refactoring */ @@ -10451,7 +12826,7 @@ declare namespace ts { * Represents a single refactoring action - for example, the "Extract Method..." refactor might * offer several actions, each corresponding to a surround class or closure to extract into. */ - interface RefactorActionInfo { + export interface RefactorActionInfo { /** * The programmatic name of the refactoring action */ @@ -10494,20 +12869,20 @@ declare namespace ts { * A set of edits to make in response to a refactor action, plus an optional * location where renaming should be invoked from */ - interface RefactorEditInfo { + export interface RefactorEditInfo { edits: FileTextChanges[]; renameFilename?: string; renameLocation?: number; commands?: CodeActionCommand[]; notApplicableReason?: string; } - type RefactorTriggerReason = "implicit" | "invoked"; - interface TextInsertion { + export type RefactorTriggerReason = "implicit" | "invoked"; + export interface TextInsertion { newText: string; /** The position in newText the caret should point to after the insertion. */ caretOffset: number; } - interface DocumentSpan { + export interface DocumentSpan { textSpan: TextSpan; fileName: string; /** @@ -10523,32 +12898,32 @@ declare namespace ts { contextSpan?: TextSpan; originalContextSpan?: TextSpan; } - interface RenameLocation extends DocumentSpan { + export interface RenameLocation extends DocumentSpan { readonly prefixText?: string; readonly suffixText?: string; } - interface ReferenceEntry extends DocumentSpan { + export interface ReferenceEntry extends DocumentSpan { isWriteAccess: boolean; isInString?: true; } - interface ImplementationLocation extends DocumentSpan { + export interface ImplementationLocation extends DocumentSpan { kind: ScriptElementKind; displayParts: SymbolDisplayPart[]; } - enum HighlightSpanKind { + export enum HighlightSpanKind { none = "none", definition = "definition", reference = "reference", writtenReference = "writtenReference", } - interface HighlightSpan { + export interface HighlightSpan { fileName?: string; isInString?: true; textSpan: TextSpan; contextSpan?: TextSpan; kind: HighlightSpanKind; } - interface NavigateToItem { + export interface NavigateToItem { name: string; kind: ScriptElementKind; kindModifiers: string; @@ -10559,18 +12934,18 @@ declare namespace ts { containerName: string; containerKind: ScriptElementKind; } - enum IndentStyle { + export enum IndentStyle { None = 0, Block = 1, Smart = 2, } - enum SemicolonPreference { + export enum SemicolonPreference { Ignore = "ignore", Insert = "insert", Remove = "remove", } /** @deprecated - consider using EditorSettings instead */ - interface EditorOptions { + export interface EditorOptions { BaseIndentSize?: number; IndentSize: number; TabSize: number; @@ -10578,7 +12953,7 @@ declare namespace ts { ConvertTabsToSpaces: boolean; IndentStyle: IndentStyle; } - interface EditorSettings { + export interface EditorSettings { baseIndentSize?: number; indentSize?: number; tabSize?: number; @@ -10588,7 +12963,7 @@ declare namespace ts { trimTrailingWhitespace?: boolean; } /** @deprecated - consider using FormatCodeSettings instead */ - interface FormatCodeOptions extends EditorOptions { + export interface FormatCodeOptions extends EditorOptions { InsertSpaceAfterCommaDelimiter: boolean; InsertSpaceAfterSemicolonInForStatements: boolean; InsertSpaceBeforeAndAfterBinaryOperators: boolean; @@ -10606,7 +12981,7 @@ declare namespace ts { PlaceOpenBraceOnNewLineForControlBlocks: boolean; insertSpaceBeforeTypeAnnotation?: boolean; } - interface FormatCodeSettings extends EditorSettings { + export interface FormatCodeSettings extends EditorSettings { readonly insertSpaceAfterCommaDelimiter?: boolean; readonly insertSpaceAfterSemicolonInForStatements?: boolean; readonly insertSpaceBeforeAndAfterBinaryOperators?: boolean; @@ -10628,28 +13003,28 @@ declare namespace ts { readonly semicolons?: SemicolonPreference; readonly indentSwitchCase?: boolean; } - interface DefinitionInfo extends DocumentSpan { + export interface DefinitionInfo extends DocumentSpan { kind: ScriptElementKind; name: string; containerKind: ScriptElementKind; containerName: string; unverified?: boolean; } - interface DefinitionInfoAndBoundSpan { + export interface DefinitionInfoAndBoundSpan { definitions?: readonly DefinitionInfo[]; textSpan: TextSpan; } - interface ReferencedSymbolDefinitionInfo extends DefinitionInfo { + export interface ReferencedSymbolDefinitionInfo extends DefinitionInfo { displayParts: SymbolDisplayPart[]; } - interface ReferencedSymbol { + export interface ReferencedSymbol { definition: ReferencedSymbolDefinitionInfo; references: ReferencedSymbolEntry[]; } - interface ReferencedSymbolEntry extends ReferenceEntry { + export interface ReferencedSymbolEntry extends ReferenceEntry { isDefinition?: boolean; } - enum SymbolDisplayPartKind { + export enum SymbolDisplayPartKind { aliasName = 0, className = 1, enumName = 2, @@ -10676,7 +13051,7 @@ declare namespace ts { linkName = 23, linkText = 24, } - interface SymbolDisplayPart { + export interface SymbolDisplayPart { /** * Text of an item describing the symbol. */ @@ -10686,14 +13061,14 @@ declare namespace ts { */ kind: string; } - interface JSDocLinkDisplayPart extends SymbolDisplayPart { + export interface JSDocLinkDisplayPart extends SymbolDisplayPart { target: DocumentSpan; } - interface JSDocTagInfo { + export interface JSDocTagInfo { name: string; text?: SymbolDisplayPart[]; } - interface QuickInfo { + export interface QuickInfo { kind: ScriptElementKind; kindModifiers: string; textSpan: TextSpan; @@ -10701,8 +13076,8 @@ declare namespace ts { documentation?: SymbolDisplayPart[]; tags?: JSDocTagInfo[]; } - type RenameInfo = RenameInfoSuccess | RenameInfoFailure; - interface RenameInfoSuccess { + export type RenameInfo = RenameInfoSuccess | RenameInfoFailure; + export interface RenameInfoSuccess { canRename: true; /** * File or directory to rename. @@ -10719,33 +13094,33 @@ declare namespace ts { kindModifiers: string; triggerSpan: TextSpan; } - interface RenameInfoFailure { + export interface RenameInfoFailure { canRename: false; localizedErrorMessage: string; } /** * @deprecated Use `UserPreferences` instead. */ - interface RenameInfoOptions { + export interface RenameInfoOptions { readonly allowRenameOfImportPath?: boolean; } - interface DocCommentTemplateOptions { + export interface DocCommentTemplateOptions { readonly generateReturnInDocTemplate?: boolean; } - interface InteractiveRefactorArguments { + export interface InteractiveRefactorArguments { targetFile: string; } /** * Signature help information for a single parameter */ - interface SignatureHelpParameter { + export interface SignatureHelpParameter { name: string; documentation: SymbolDisplayPart[]; displayParts: SymbolDisplayPart[]; isOptional: boolean; isRest?: boolean; } - interface SelectionRange { + export interface SelectionRange { textSpan: TextSpan; parent?: SelectionRange; } @@ -10756,7 +13131,7 @@ declare namespace ts { * an edit has happened, while signature help is still active, the host can ask important * questions like 'what parameter is the user currently contained within?'. */ - interface SignatureHelpItem { + export interface SignatureHelpItem { isVariadic: boolean; prefixDisplayParts: SymbolDisplayPart[]; suffixDisplayParts: SymbolDisplayPart[]; @@ -10768,14 +13143,14 @@ declare namespace ts { /** * Represents a set of signature help items, and the preferred item that should be selected. */ - interface SignatureHelpItems { + export interface SignatureHelpItems { items: SignatureHelpItem[]; applicableSpan: TextSpan; selectedItemIndex: number; argumentIndex: number; argumentCount: number; } - enum CompletionInfoFlags { + export enum CompletionInfoFlags { None = 0, MayIncludeAutoImports = 1, IsImportStatementCompletion = 2, @@ -10784,7 +13159,7 @@ declare namespace ts { ResolvedModuleSpecifiersBeyondLimit = 16, MayIncludeMethodSnippets = 32, } - interface CompletionInfo { + export interface CompletionInfo { /** For performance telemetry. */ flags?: CompletionInfoFlags; /** Not true for all global completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */ @@ -10810,7 +13185,7 @@ declare namespace ts { */ defaultCommitCharacters?: string[]; } - interface CompletionEntryDataAutoImport { + export interface CompletionEntryDataAutoImport { /** * The name of the property or export in the module's symbol table. Differs from the completion name * in the case of InternalSymbolName.ExportEquals and InternalSymbolName.Default. @@ -10825,14 +13200,14 @@ declare namespace ts { /** True if the export was found in the package.json AutoImportProvider */ isPackageJsonImport?: true; } - interface CompletionEntryDataUnresolved extends CompletionEntryDataAutoImport { + export interface CompletionEntryDataUnresolved extends CompletionEntryDataAutoImport { exportMapKey: ExportMapInfoKey; } - interface CompletionEntryDataResolved extends CompletionEntryDataAutoImport { + export interface CompletionEntryDataResolved extends CompletionEntryDataAutoImport { moduleSpecifier: string; } - type CompletionEntryData = CompletionEntryDataUnresolved | CompletionEntryDataResolved; - interface CompletionEntry { + export type CompletionEntryData = CompletionEntryDataUnresolved | CompletionEntryDataResolved; + export interface CompletionEntry { name: string; kind: ScriptElementKind; kindModifiers?: string; @@ -10920,7 +13295,7 @@ declare namespace ts { */ commitCharacters?: string[]; } - interface CompletionEntryLabelDetails { + export interface CompletionEntryLabelDetails { /** * An optional string which is rendered less prominently directly after * {@link CompletionEntry.name name}, without any spacing. Should be @@ -10934,7 +13309,7 @@ declare namespace ts { */ description?: string; } - interface CompletionEntryDetails { + export interface CompletionEntryDetails { name: string; kind: ScriptElementKind; kindModifiers: string; @@ -10946,7 +13321,7 @@ declare namespace ts { source?: SymbolDisplayPart[]; sourceDisplay?: SymbolDisplayPart[]; } - interface OutliningSpan { + export interface OutliningSpan { /** The span of the document to actually collapse. */ textSpan: TextSpan; /** The span of the document to display when the user hovers over the collapsed span. */ @@ -10963,7 +13338,7 @@ declare namespace ts { */ kind: OutliningSpanKind; } - enum OutliningSpanKind { + export enum OutliningSpanKind { /** Single or multi-line comments */ Comment = "comment", /** Sections marked by '// #region' and '// #endregion' comments */ @@ -10973,12 +13348,12 @@ declare namespace ts { /** Contiguous blocks of import declarations */ Imports = "imports", } - enum OutputFileType { + export enum OutputFileType { JavaScript = 0, SourceMap = 1, Declaration = 2, } - enum EndOfLineState { + export enum EndOfLineState { None = 0, InMultiLineCommentTrivia = 1, InSingleQuoteStringLiteral = 2, @@ -10987,7 +13362,7 @@ declare namespace ts { InTemplateMiddleOrTail = 5, InTemplateSubstitutionPosition = 6, } - enum TokenClass { + export enum TokenClass { Punctuation = 0, Keyword = 1, Operator = 2, @@ -10999,15 +13374,15 @@ declare namespace ts { StringLiteral = 8, RegExpLiteral = 9, } - interface ClassificationResult { + export interface ClassificationResult { finalLexState: EndOfLineState; entries: ClassificationInfo[]; } - interface ClassificationInfo { + export interface ClassificationInfo { length: number; classification: TokenClass; } - interface Classifier { + export interface Classifier { /** * Gives lexical classifications of tokens on a line without any syntactic context. * For instance, a token consisting of the text 'string' can be either an identifier @@ -11031,7 +13406,7 @@ declare namespace ts { getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult; getEncodedLexicalClassifications(text: string, endOfLineState: EndOfLineState, syntacticClassifierAbsent: boolean): Classifications; } - enum ScriptElementKind { + export enum ScriptElementKind { unknown = "", warning = "warning", /** predefined type (void) or keyword (class) */ @@ -11116,7 +13491,7 @@ declare namespace ts { /** Jsdoc @link: in `{@link C link text}`, the link text "link text" */ linkText = "link text", } - enum ScriptElementKindModifier { + export enum ScriptElementKindModifier { none = "", publicMemberModifier = "public", privateMemberModifier = "private", @@ -11140,7 +13515,7 @@ declare namespace ts { ctsModifier = ".cts", cjsModifier = ".cjs", } - enum ClassificationTypeNames { + export enum ClassificationTypeNames { comment = "comment", identifier = "identifier", keyword = "keyword", @@ -11166,7 +13541,7 @@ declare namespace ts { jsxText = "jsx text", jsxAttributeStringLiteralValue = "jsx attribute string literal value", } - enum ClassificationType { + export enum ClassificationType { comment = 1, identifier = 2, keyword = 3, @@ -11193,7 +13568,7 @@ declare namespace ts { jsxAttributeStringLiteralValue = 24, bigintLiteral = 25, } - interface InlayHintsContext { + export interface InlayHintsContext { file: SourceFile; program: Program; cancellationToken: CancellationToken; @@ -11201,16 +13576,16 @@ declare namespace ts { span: TextSpan; preferences: UserPreferences; } - type ExportMapInfoKey = string & { + export type ExportMapInfoKey = string & { __exportInfoKey: void; }; /** The classifier is used for syntactic highlighting in editors via the TSServer */ - function createClassifier(): Classifier; - interface DocumentHighlights { + export function createClassifier(): Classifier; + export interface DocumentHighlights { fileName: string; highlightSpans: HighlightSpan[]; } - function createDocumentRegistry(useCaseSensitiveFileNames?: boolean, currentDirectory?: string, jsDocParsingMode?: JSDocParsingMode): DocumentRegistry; + export function createDocumentRegistry(useCaseSensitiveFileNames?: boolean, currentDirectory?: string, jsDocParsingMode?: JSDocParsingMode): DocumentRegistry; /** * The document registry represents a store of SourceFile objects that can be shared between * multiple LanguageService instances. A LanguageService instance holds on the SourceFile (AST) @@ -11226,7 +13601,7 @@ declare namespace ts { * To create a default DocumentRegistry, use createDocumentRegistry to create one, and pass it * to all subsequent createLanguageService calls. */ - interface DocumentRegistry { + export interface DocumentRegistry { /** * Request a stored SourceFile with a given fileName and compilationSettings. * The first call to acquire will call createLanguageServiceSourceFile to generate @@ -11295,14 +13670,14 @@ declare namespace ts { releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind: ScriptKind, impliedNodeFormat: ResolutionMode): void; reportStats(): string; } - type DocumentRegistryBucketKey = string & { + export type DocumentRegistryBucketKey = string & { __bucketKey: any; }; - function preProcessFile(sourceText: string, readImportFiles?: boolean, detectJavaScriptImports?: boolean): PreProcessedFileInfo; - function transpileModule(input: string, transpileOptions: TranspileOptions): TranspileOutput; - function transpileDeclaration(input: string, transpileOptions: TranspileOptions): TranspileOutput; - function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string; - interface TranspileOptions { + export function preProcessFile(sourceText: string, readImportFiles?: boolean, detectJavaScriptImports?: boolean): PreProcessedFileInfo; + export function transpileModule(input: string, transpileOptions: TranspileOptions): TranspileOutput; + export function transpileDeclaration(input: string, transpileOptions: TranspileOptions): TranspileOutput; + export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string; + export interface TranspileOptions { compilerOptions?: CompilerOptions; fileName?: string; reportDiagnostics?: boolean; @@ -11311,32 +13686,32 @@ declare namespace ts { transformers?: CustomTransformers; jsDocParsingMode?: JSDocParsingMode; } - interface TranspileOutput { + export interface TranspileOutput { outputText: string; diagnostics?: Diagnostic[]; sourceMapText?: string; } - function toEditorSettings(options: EditorOptions | EditorSettings): EditorSettings; - function displayPartsToString(displayParts: SymbolDisplayPart[] | undefined): string; - function getDefaultCompilerOptions(): CompilerOptions; - function getSupportedCodeFixes(): readonly string[]; - function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTargetOrOptions: ScriptTarget | CreateSourceFileOptions, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile; - function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange | undefined, aggressiveChecks?: boolean): SourceFile; - function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry, syntaxOnlyOrLanguageServiceMode?: boolean | LanguageServiceMode): LanguageService; + export function toEditorSettings(options: EditorOptions | EditorSettings): EditorSettings; + export function displayPartsToString(displayParts: SymbolDisplayPart[] | undefined): string; + export function getDefaultCompilerOptions(): CompilerOptions; + export function getSupportedCodeFixes(): readonly string[]; + export function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTargetOrOptions: ScriptTarget | CreateSourceFileOptions, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile; + export function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange | undefined, aggressiveChecks?: boolean): SourceFile; + export function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry, syntaxOnlyOrLanguageServiceMode?: boolean | LanguageServiceMode): LanguageService; /** * Get the path of the default library files (lib.d.ts) as distributed with the typescript * node package. * The functionality is not supported if the ts module is consumed outside of a node module. */ - function getDefaultLibFilePath(options: CompilerOptions): string; + export function getDefaultLibFilePath(options: CompilerOptions): string; /** The version of the language service API */ - const servicesVersion = "0.8"; + export const servicesVersion = "0.8"; /** * Transform one or more nodes using the supplied transformers. * @param source A single `Node` or an array of `Node` objects. * @param transformers An array of `TransformerFactory` callbacks used to process the transformation. * @param compilerOptions Optional compiler options. */ - function transform(source: T | T[], transformers: TransformerFactory[], compilerOptions?: CompilerOptions): TransformationResult; + export function transform(source: T | T[], transformers: TransformerFactory[], compilerOptions?: CompilerOptions): TransformationResult; } export = ts; diff --git a/tests/baselines/reference/objectRestPropertyMustBeLast.js b/tests/baselines/reference/objectRestPropertyMustBeLast.js index aa644259f6e92..9cd3a26a3ad8a 100644 --- a/tests/baselines/reference/objectRestPropertyMustBeLast.js +++ b/tests/baselines/reference/objectRestPropertyMustBeLast.js @@ -24,4 +24,4 @@ var _a, _b; var _c = { x: 1 }, x = _c.x; // Error, rest must be last property (_a = { x: 1 }, x = _a.x); // Error, rest must be last property var _d = { x: 1 }, x = _d.x, b = __rest(_d, ["a", "x"]); // Error, rest must be last property -(_b = { x: 1 }, x = _b.x, b = __rest(_b, ["x"])); // Error, rest must be last property +(_b = { x: 1 }, x = _b.x, b = __rest(_b, ["a", "x"])); // Error, rest must be last property From aaf7906ce303dbede73457f1e7d962cb07263a5b Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 20 Sep 2024 15:54:06 -0400 Subject: [PATCH 07/10] Monomorphic flag calculation and property access for name/jsDoc --- src/compiler/ast.ts | 809 +++++++++++++++++- src/compiler/nodes.ts | 9 + src/compiler/parser.ts | 8 +- src/compiler/program.ts | 18 +- src/compiler/types.ts | 770 ++++++----------- tests/baselines/reference/api/typescript.d.ts | 378 ++------ 6 files changed, 1165 insertions(+), 827 deletions(-) diff --git a/src/compiler/ast.ts b/src/compiler/ast.ts index 2352b5169685e..2e92a5b474c09 100644 --- a/src/compiler/ast.ts +++ b/src/compiler/ast.ts @@ -17,6 +17,7 @@ import { AssertKeyword, AssertsKeyword, AsteriskToken, + astHasJSDocNodes, AsyncKeyword, AwaitExpression, AwaitKeyword, @@ -236,6 +237,7 @@ import { LiteralToken, LiteralTypeNode, MappedTypeNode, + MatchingKeys, MemberExpression, MemberName, MetaProperty, @@ -554,7 +556,7 @@ export class AstNode = Node; export interface AstLiteralExpressionData extends AstLiteralLikeNodeData { } +export type AstToken = AstNode>; + // dprint-ignore export class AstTokenData extends AstData { /** @internal */ override computeTransformFlags(node: AstNode): TransformFlags { @@ -1479,21 +1483,31 @@ export class AstTokenData extends AstData { } } +export type AstEndOfFileToken = AstNode; + // dprint-ignore export class AstEndOfFileTokenData extends AstTokenData { /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) } +export type AstThisExpression = AstNode; + // dprint-ignore export class AstThisExpressionData extends AstTokenData { /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) } +export type AstSuperExpression = AstNode; + // dprint-ignore export class AstSuperExpressionData extends AstTokenData { /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) } +export type AstImportExpression = AstNode; +export type AstNullLiteral = AstNode; +export type AstTrueLiteral = AstNode; +export type AstFalseLiteral = AstNode; export type AstBooleanLiteral = AstNodeOneOf; // Punctuation @@ -1543,6 +1557,8 @@ export type AstStaticKeyword = AstNode; export type AstModifier = AstNodeOneOf; export type AstModifierLike = AstNodeOneOf; +export type AstIdentifier = AstNode; + // dprint-ignore export class AstIdentifierData extends AstTokenData { escapedText: __String = undefined!; @@ -1565,6 +1581,8 @@ export class AstIdentifierData extends AstTokenData { } } +export type AstQualifiedName = AstNode; + // dprint-ignore export class AstQualifiedNameData extends AstData { left: AstEntityName = undefined!; @@ -1583,6 +1601,7 @@ export type AstBindingName = AstNodeOneOf; export type AstPropertyName = AstNodeOneOf; export type AstMemberName = AstNodeOneOf; export type AstDeclarationName = AstNodeOneOf; +export type AstComputedPropertyName = AstNode; // dprint-ignore export class AstComputedPropertyNameData extends AstData { @@ -1595,6 +1614,8 @@ export class AstComputedPropertyNameData extends AstData { } } +export type AstPrivateIdentifier = AstNode; + // dprint-ignore export class AstPrivateIdentifierData extends AstTokenData { escapedText: __String = undefined!; @@ -1604,6 +1625,8 @@ export class AstPrivateIdentifierData extends AstTokenData { } } +export type AstTypeParameterDeclaration = AstNode; + // dprint-ignore export class AstTypeParameterDeclarationData extends AstTypeScriptNodeData { modifiers: AstNodeArray | undefined = undefined; @@ -1617,6 +1640,7 @@ export class AstTypeParameterDeclarationData extends AstTypeScriptNodeData { /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) } +export type AstParameterDeclaration = AstNode; // dprint-ignore export class AstParameterDeclarationData extends AstData { @@ -1648,6 +1672,8 @@ export class AstParameterDeclarationData extends AstData { } } +export type AstDecorator = AstNode; + // dprint-ignore export class AstDecoratorData extends AstData { expression: AstLeftHandSideExpression = undefined!; @@ -1660,6 +1686,8 @@ export class AstDecoratorData extends AstData { } } +export type AstPropertySignature = AstNode; + // dprint-ignore export class AstPropertySignatureData extends AstTypeScriptNodeData { modifiers: AstNodeArray | undefined = undefined; @@ -1674,6 +1702,7 @@ export class AstPropertySignatureData extends AstTypeScriptNodeData { } export type AstSignatureDeclaration = AstNodeOneOf; +export type AstCallSignatureDeclaration = AstNode; // dprint-ignore export class AstCallSignatureDeclarationData extends AstTypeScriptNodeData { @@ -1689,6 +1718,8 @@ export class AstCallSignatureDeclarationData extends AstTypeScriptNodeData { /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) } +export type AstConstructSignatureDeclaration = AstNode; + // dprint-ignore export class AstConstructSignatureDeclarationData extends AstTypeScriptNodeData { typeParameters: AstNodeArray | undefined = undefined; @@ -1703,6 +1734,8 @@ export class AstConstructSignatureDeclarationData extends AstTypeScriptNodeData /** @internal */ nextContainer: AstHasLocals | undefined = undefined; } +export type AstVariableDeclaration = AstNode; + // dprint-ignore export class AstVariableDeclarationData extends AstData { name: AstBindingName = undefined!; // Declared variable name @@ -1721,6 +1754,8 @@ export class AstVariableDeclarationData extends AstData { } } +export type AstVariableDeclarationList = AstNode; + // dprint-ignore export class AstVariableDeclarationListData extends AstData { declarations: AstNodeArray = undefined!; @@ -1739,6 +1774,8 @@ export class AstVariableDeclarationListData extends AstData { } } +export type AstBindingElement = AstNode; + // dprint-ignore export class AstBindingElementData extends AstData { propertyName: AstPropertyName | undefined = undefined; // Binding property name (in object binding pattern) @@ -1760,6 +1797,8 @@ export class AstBindingElementData extends AstData { } } +export type AstPropertyDeclaration = AstNode; + // dprint-ignore export class AstPropertyDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; @@ -1786,6 +1825,8 @@ export class AstPropertyDeclarationData extends AstData { } } +export type AstPropertyAssignment = AstNode; + // dprint-ignore export class AstPropertyAssignmentData extends AstData { modifiers: AstNodeArray | undefined = undefined; // initialized by parser (grammar error) @@ -1804,6 +1845,8 @@ export class AstPropertyAssignmentData extends AstData { } } +export type AstShorthandPropertyAssignment = AstNode; + // dprint-ignore export class AstShorthandPropertyAssignmentData extends AstData { name: AstIdentifier = undefined!; @@ -1826,6 +1869,8 @@ export class AstShorthandPropertyAssignmentData extends AstData { } } +export type AstSpreadAssignment = AstNode; + // dprint-ignore export class AstSpreadAssignmentData extends AstData { expression: AstExpression = undefined!; @@ -1842,7 +1887,7 @@ export class AstSpreadAssignmentData extends AstData { } export type AstBindingPattern = AstNodeOneOf; -export type AstArrayBindingElement = AstNodeOneOf; +export type AstObjectBindingPattern = AstNode; // dprint-ignore export class AstObjectBindingPatternData extends AstData { @@ -1859,6 +1904,9 @@ export class AstObjectBindingPatternData extends AstData { } } +export type AstArrayBindingElement = AstNodeOneOf; +export type AstArrayBindingPattern = AstNode; + // dprint-ignore export class AstArrayBindingPatternData extends AstData { elements: AstNodeArray = undefined!; @@ -1870,6 +1918,8 @@ export class AstArrayBindingPatternData extends AstData { } } +export type AstFunctionDeclaration = AstNode; + // dprint-ignore export class AstFunctionDeclarationData extends AstData { modifiers: AstNodeArray | undefined = undefined; @@ -2755,6 +2805,8 @@ export class AstObjectLiteralExpressionData extends AstData { } } +export type AstPropertyAccessExpression = AstNode; + // dprint-ignore export class AstPropertyAccessExpressionData extends AstData { expression: AstLeftHandSideExpression = undefined!; @@ -2786,13 +2838,6 @@ export class AstPropertyAccessExpressionData extends AstData { } export type AstPropertyAccessEntityNameExpression = AstNode; - -export interface AstPropertyAccessEntityNameExpressionData extends AstPropertyAccessExpressionData { - expression: AstEntityNameExpression; - name: AstIdentifier; -} - - export type AstEntityNameExpression = AstNodeOneOf; export type AstPropertyAccessChain = AstNode; /** @internal */ @@ -4524,34 +4569,7 @@ export class AstSourceFileData extends AstData { } } -export type AstToken = AstNode>; -export type AstEndOfFileToken = AstNode; -export type AstThisExpression = AstNode; -export type AstSuperExpression = AstNode; -export type AstImportExpression = AstNode; -export type AstNullLiteral = AstNode; -export type AstTrueLiteral = AstNode; -export type AstFalseLiteral = AstNode; -export type AstIdentifier = AstNode; -export type AstQualifiedName = AstNode; -export type AstComputedPropertyName = AstNode; -export type AstPrivateIdentifier = AstNode; -export type AstTypeParameterDeclaration = AstNode; -export type AstParameterDeclaration = AstNode; -export type AstDecorator = AstNode; -export type AstPropertySignature = AstNode; -export type AstCallSignatureDeclaration = AstNode; -export type AstConstructSignatureDeclaration = AstNode; -export type AstVariableDeclaration = AstNode; -export type AstVariableDeclarationList = AstNode; -export type AstBindingElement = AstNode; -export type AstPropertyDeclaration = AstNode; -export type AstPropertyAssignment = AstNode; -export type AstShorthandPropertyAssignment = AstNode; -export type AstSpreadAssignment = AstNode; -export type AstObjectBindingPattern = AstNode; -export type AstArrayBindingPattern = AstNode; -export type AstFunctionDeclaration = AstNode; +// TODO(rbuckton): Move these closer to their associated data properties export type AstMethodSignature = AstNode; export type AstMethodDeclaration = AstNode; export type AstConstructorDeclaration = AstNode; @@ -4610,7 +4628,6 @@ export type AstParenthesizedExpression = AstNode; export type AstArrayLiteralExpression = AstNode; export type AstSpreadElement = AstNode; export type AstObjectLiteralExpression = AstNode; -export type AstPropertyAccessExpression = AstNode; export type AstElementAccessExpression = AstNode; export type AstCallExpression = AstNode; export type AstExpressionWithTypeArguments = AstNode; @@ -4759,6 +4776,110 @@ export interface AstJsonSourceFileData extends AstSourceFileData { statements: AstNodeArray; } +// /** +// * Constraint used to pick out keys of an `AstData` subtype that match the constraint. +// */ +// type AstDataValue = AstNode | { readonly items: readonly AstNode[] } | JSDocArray | FlowNode | string | number | boolean | null | undefined; + +// /** +// * Constraint limiting what props can be applied to an AstNode refinement. +// * For ease of use, tuples can be used to constrain `AstNodeArray` without needing to also specify `{ items: [] }`. +// */ +// type AstDataProps = { +// [K in keyof A["data"] & keyof A["node"] as A["data"][K] extends AstDataValue ? K : never]?: +// A["data"][K] extends AstNodeArray ? { readonly items: readonly C[] } | readonly C[] : +// A["data"][K]; +// }; + +// /** +// * Converts `AstDataProps` into an actual `AstData` refinement. +// */ +// type RefinedDataProps> = { +// [K in keyof D & keyof A["data"] & keyof A["node"]]: +// D[K] extends infer C extends readonly AstNode[] ? { readonly items: C } : +// D[K]; +// }; + +// /** +// * Converts `AstDataProps` into an actual `Node` refinement. +// */ +// type RefinedNodeProps> = { +// [K in keyof D & keyof A["data"] & keyof A["node"]]: +// D[K] extends AstNode ? N : // Convert AstNode to Node +// D[K] extends infer C extends readonly AstNode[] ? RefinedNodeArray : // Convert AstNode[] to Node[] +// D[K] extends { readonly items: infer C extends readonly AstNode[] } ? RefinedNodeArray : // Convert AstNodeArray to Node[] +// D[K]; // primitive value +// }; + +// /** +// * Converts `AstNode[]` to `Node[]` +// */ +// type RefinedNodeArray = { [P in keyof A]: A[P]["node"] }; + +// /** +// * Subset of `Node` into which to inject refinements for `ast` and `data`. +// */ +// interface RefinedNode> { +// readonly ast: AstNode; +// readonly data: A["data"] & RefinedDataProps; +// } + +// /** +// * Refines an `AstNode` based on a set of specific data properties. +// */ +// export type RefineAstNode, Brand extends string = never> = Branded< +// & A["node"] +// & RefinedNode +// & RefinedNodeProps, +// Brand>; + +/** + * Constraint limiting what props can be applied to a Node refinement. + */ +export type NodeProps = { + [K in keyof N["data"] & keyof N as Exclude]?: + N["data"][K] extends infer P ? + P extends AstNodeArray ? readonly C["node"][] : + P extends AstNode ? C : + P : + never; +}; + +/** + * Converts `Node[]` to `AstNodeArray` + */ +export type RefineAstNodeArray = + & AstNodeArray + // only intersect with elements if `A` is a tuple (i.e., has a more specific `length` than `number`) + & (number extends A["length"] ? unknown : { readonly items: { +readonly [P in keyof A]-?: A[P]["ast"] } }); + +/** + * Converts the supplied node properties to AST form. + */ +export type RefineNodeData> = { + [K in keyof D]: + // Convert arrays/tuples to AstNodeArray + D[K] extends infer C extends readonly Node[] ? RefineAstNodeArray : + // Convert nodes to their ast form + D[K] extends Node ? D[K]["ast"] : + // Use primitives as-is + D[K]; +}; + +/** + * Refines a `Node` based on a set of specific node properties. + */ +export type RefineNode> = + N & D & { readonly data: RefineNodeData; }; + +/** + * Refines a `Node` with specific required properties. + */ +export type RequiredNodeProp = + N extends Node ? + RefineNode]-?: NonNullable[P]> }, NodeProps>> : + never; + function propagateNameFlags(node: AstPropertyName | AstBindingPattern | AstNoSubstitutionTemplateLiteral | undefined) { return node?.kind === SyntaxKind.Identifier ? propagateIdentifierNameFlags(node) : propagateChildFlags(node); } @@ -4775,7 +4896,8 @@ function propagatePropertyNameFlagsOfChild(node: AstPropertyName, transformFlags function propagateChildFlags(child: AstNode | undefined): TransformFlags { if (!child) return TransformFlags.None; const childFlags = child.transformFlags & ~getTransformFlagsSubtreeExclusions(child.kind); - return astCanHaveName(child) && child.data.name && isAstPropertyName(child.data.name) ? propagatePropertyNameFlagsOfChild(child.data.name, childFlags) : childFlags; + const name = astGetName(child); + return name && isAstPropertyName(name) ? propagatePropertyNameFlagsOfChild(name, childFlags) : childFlags; } function propagateChildrenFlags(children: AstNodeArray | undefined): TransformFlags { @@ -4801,7 +4923,8 @@ export type AstNamedDeclaration = AstNodeOneOf; /** @internal */ export type AstHasName = AstNodeOneOf; -function astCanHaveName(node: AstNode): node is AstHasName { +/** @internal */ +export function astCanHaveName(node: AstNode): node is AstHasName { switch (node.kind) { case SyntaxKind.BindingElement: case SyntaxKind.ClassDeclaration: @@ -4852,6 +4975,612 @@ function astCanHaveName(node: AstNode): node is AstHasName { return false; } +/** @internal */ +export function astHasName(node: AstNode): node is AstNodeOneOf> { + return !!astGetName(node); +} + +/** @internal */ +export function astGetName(node: T): T extends AstHasName ? T["data"]["name"] : undefined; +export function astGetName(node: AstNode) { + Debug.type(node); + // NOTE: each branch is monomorphic + switch (node.kind) { + case SyntaxKind.BindingElement: return node.data.name; + case SyntaxKind.ClassDeclaration: return node.data.name; + case SyntaxKind.ClassExpression: return node.data.name; + case SyntaxKind.EnumDeclaration: return node.data.name; + case SyntaxKind.EnumMember: return node.data.name; + case SyntaxKind.ExportSpecifier: return node.data.name; + case SyntaxKind.FunctionDeclaration: return node.data.name; + case SyntaxKind.FunctionExpression: return node.data.name; + case SyntaxKind.GetAccessor: return node.data.name; + case SyntaxKind.ImportAttribute: return node.data.name; + case SyntaxKind.ImportClause: return node.data.name; + case SyntaxKind.ImportEqualsDeclaration: return node.data.name; + case SyntaxKind.ImportSpecifier: return node.data.name; + case SyntaxKind.InterfaceDeclaration: return node.data.name; + case SyntaxKind.JSDocCallbackTag: return node.data.name; + case SyntaxKind.JSDocLink: return node.data.name; + case SyntaxKind.JSDocLinkCode: return node.data.name; + case SyntaxKind.JSDocLinkPlain: return node.data.name; + case SyntaxKind.JSDocNameReference: return node.data.name; + case SyntaxKind.JSDocParameterTag: return node.data.name; + case SyntaxKind.JSDocPropertyTag: return node.data.name; + case SyntaxKind.JSDocSeeTag: return node.data.name; + case SyntaxKind.JSDocTypedefTag: return node.data.name; + case SyntaxKind.JsxAttribute: return node.data.name; + case SyntaxKind.JsxNamespacedName: return node.data.name; + case SyntaxKind.MetaProperty: return node.data.name; + case SyntaxKind.MethodDeclaration: return node.data.name; + case SyntaxKind.MethodSignature: return node.data.name; + case SyntaxKind.MissingDeclaration: return node.data.name; + case SyntaxKind.ModuleDeclaration: return node.data.name; + case SyntaxKind.NamedTupleMember: return node.data.name; + case SyntaxKind.NamespaceExport: return node.data.name; + case SyntaxKind.NamespaceExportDeclaration: return node.data.name; + case SyntaxKind.NamespaceImport: return node.data.name; + case SyntaxKind.Parameter: return node.data.name; + case SyntaxKind.PropertyAccessExpression: return node.data.name; + case SyntaxKind.PropertyAssignment: return node.data.name; + case SyntaxKind.PropertyDeclaration: return node.data.name; + case SyntaxKind.PropertySignature: return node.data.name; + case SyntaxKind.SetAccessor: return node.data.name; + case SyntaxKind.ShorthandPropertyAssignment: return node.data.name; + case SyntaxKind.TypeAliasDeclaration: return node.data.name; + case SyntaxKind.TypeParameter: return node.data.name; + case SyntaxKind.VariableDeclaration: return node.data.name; + default: return undefined; + } +} + +/** @internal */ +export function astCanHaveJSDoc(node: AstNode): node is AstHasJSDoc { + switch (node.kind) { + case SyntaxKind.ArrowFunction: + case SyntaxKind.BinaryExpression: + case SyntaxKind.Block: + case SyntaxKind.BreakStatement: + case SyntaxKind.CallSignature: + case SyntaxKind.CaseClause: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + case SyntaxKind.ClassStaticBlockDeclaration: + case SyntaxKind.Constructor: + case SyntaxKind.ConstructorType: + case SyntaxKind.ConstructSignature: + case SyntaxKind.ContinueStatement: + case SyntaxKind.DebuggerStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.EmptyStatement: + case SyntaxKind.EndOfFileToken: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.EnumMember: + case SyntaxKind.ExportAssignment: + case SyntaxKind.ExportDeclaration: + case SyntaxKind.ExportSpecifier: + case SyntaxKind.ExpressionStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + case SyntaxKind.ForStatement: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.FunctionType: + case SyntaxKind.GetAccessor: + case SyntaxKind.Identifier: + case SyntaxKind.IfStatement: + case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.IndexSignature: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.JSDocFunctionType: + case SyntaxKind.JSDocSignature: + case SyntaxKind.LabeledStatement: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.NamedTupleMember: + case SyntaxKind.NamespaceExportDeclaration: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.Parameter: + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.PropertyAssignment: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.ReturnStatement: + case SyntaxKind.SemicolonClassElement: + case SyntaxKind.SetAccessor: + case SyntaxKind.ShorthandPropertyAssignment: + case SyntaxKind.SpreadAssignment: + case SyntaxKind.SwitchStatement: + case SyntaxKind.ThrowStatement: + case SyntaxKind.TryStatement: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.TypeParameter: + case SyntaxKind.VariableDeclaration: + case SyntaxKind.VariableStatement: + case SyntaxKind.WhileStatement: + case SyntaxKind.WithStatement: + case SyntaxKind.ModuleBlock: + case SyntaxKind.MissingDeclaration: + case SyntaxKind.NotEmittedStatement: + return true; + default: + return false; + } +} + +/** @internal */ +export function astHasJSDoc(node: AstNode): node is AstNodeOneOf> { + return !!astGetJSDoc(node); +} + +/** @internal */ +export function astGetJSDoc(node: AstNode): JSDocArray | undefined { + // each branch is monomorphic + Debug.type(node); + switch (node.kind) { + case SyntaxKind.ArrowFunction: return node.data.jsDoc; + case SyntaxKind.BinaryExpression: return node.data.jsDoc; + case SyntaxKind.Block: return node.data.jsDoc; + case SyntaxKind.BreakStatement: return node.data.jsDoc; + case SyntaxKind.CallSignature: return node.data.jsDoc; + case SyntaxKind.CaseClause: return node.data.jsDoc; + case SyntaxKind.ClassDeclaration: return node.data.jsDoc; + case SyntaxKind.ClassExpression: return node.data.jsDoc; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.jsDoc; + case SyntaxKind.Constructor: return node.data.jsDoc; + case SyntaxKind.ConstructorType: return node.data.jsDoc; + case SyntaxKind.ConstructSignature: return node.data.jsDoc; + case SyntaxKind.ContinueStatement: return node.data.jsDoc; + case SyntaxKind.DebuggerStatement: return node.data.jsDoc; + case SyntaxKind.DoStatement: return node.data.jsDoc; + case SyntaxKind.ElementAccessExpression: return node.data.jsDoc; + case SyntaxKind.EmptyStatement: return node.data.jsDoc; + case SyntaxKind.EndOfFileToken: return node.data.jsDoc; + case SyntaxKind.EnumDeclaration: return node.data.jsDoc; + case SyntaxKind.EnumMember: return node.data.jsDoc; + case SyntaxKind.ExportAssignment: return node.data.jsDoc; + case SyntaxKind.ExportDeclaration: return node.data.jsDoc; + case SyntaxKind.ExportSpecifier: return node.data.jsDoc; + case SyntaxKind.ExpressionStatement: return node.data.jsDoc; + case SyntaxKind.ForInStatement: return node.data.jsDoc; + case SyntaxKind.ForOfStatement: return node.data.jsDoc; + case SyntaxKind.ForStatement: return node.data.jsDoc; + case SyntaxKind.FunctionDeclaration: return node.data.jsDoc; + case SyntaxKind.FunctionExpression: return node.data.jsDoc; + case SyntaxKind.FunctionType: return node.data.jsDoc; + case SyntaxKind.GetAccessor: return node.data.jsDoc; + case SyntaxKind.Identifier: return node.data.jsDoc; + case SyntaxKind.IfStatement: return node.data.jsDoc; + case SyntaxKind.ImportDeclaration: return node.data.jsDoc; + case SyntaxKind.ImportEqualsDeclaration: return node.data.jsDoc; + case SyntaxKind.IndexSignature: return node.data.jsDoc; + case SyntaxKind.InterfaceDeclaration: return node.data.jsDoc; + case SyntaxKind.JSDocFunctionType: return node.data.jsDoc; + case SyntaxKind.JSDocSignature: return node.data.jsDoc; + case SyntaxKind.LabeledStatement: return node.data.jsDoc; + case SyntaxKind.MethodDeclaration: return node.data.jsDoc; + case SyntaxKind.MethodSignature: return node.data.jsDoc; + case SyntaxKind.ModuleDeclaration: return node.data.jsDoc; + case SyntaxKind.NamedTupleMember: return node.data.jsDoc; + case SyntaxKind.NamespaceExportDeclaration: return node.data.jsDoc; + case SyntaxKind.ObjectLiteralExpression: return node.data.jsDoc; + case SyntaxKind.Parameter: return node.data.jsDoc; + case SyntaxKind.ParenthesizedExpression: return node.data.jsDoc; + case SyntaxKind.PropertyAccessExpression: return node.data.jsDoc; + case SyntaxKind.PropertyAssignment: return node.data.jsDoc; + case SyntaxKind.PropertyDeclaration: return node.data.jsDoc; + case SyntaxKind.PropertySignature: return node.data.jsDoc; + case SyntaxKind.ReturnStatement: return node.data.jsDoc; + case SyntaxKind.SemicolonClassElement: return node.data.jsDoc; + case SyntaxKind.SetAccessor: return node.data.jsDoc; + case SyntaxKind.ShorthandPropertyAssignment: return node.data.jsDoc; + case SyntaxKind.SpreadAssignment: return node.data.jsDoc; + case SyntaxKind.SwitchStatement: return node.data.jsDoc; + case SyntaxKind.ThrowStatement: return node.data.jsDoc; + case SyntaxKind.TryStatement: return node.data.jsDoc; + case SyntaxKind.TypeAliasDeclaration: return node.data.jsDoc; + case SyntaxKind.TypeParameter: return node.data.jsDoc; + case SyntaxKind.VariableDeclaration: return node.data.jsDoc; + case SyntaxKind.VariableStatement: return node.data.jsDoc; + case SyntaxKind.WhileStatement: return node.data.jsDoc; + case SyntaxKind.WithStatement: return node.data.jsDoc; + case SyntaxKind.ModuleBlock: return node.data.jsDoc; + case SyntaxKind.MissingDeclaration: return node.data.jsDoc; + case SyntaxKind.NotEmittedStatement: return node.data.jsDoc; + default: Debug.assertNever(node); + } +} + +/** @internal */ +export function astSetJSDoc(node: AstHasJSDoc, value: JSDocArray | undefined): void { + // each branch is monomorphic + switch (node.kind) { + case SyntaxKind.ArrowFunction: + node.data.jsDoc = value; + break; + case SyntaxKind.BinaryExpression: + node.data.jsDoc = value; + break; + case SyntaxKind.Block: + node.data.jsDoc = value; + break; + case SyntaxKind.BreakStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.CallSignature: + node.data.jsDoc = value; + break; + case SyntaxKind.CaseClause: + node.data.jsDoc = value; + break; + case SyntaxKind.ClassDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.ClassExpression: + node.data.jsDoc = value; + break; + case SyntaxKind.ClassStaticBlockDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.Constructor: + node.data.jsDoc = value; + break; + case SyntaxKind.ConstructorType: + node.data.jsDoc = value; + break; + case SyntaxKind.ConstructSignature: + node.data.jsDoc = value; + break; + case SyntaxKind.ContinueStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.DebuggerStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.DoStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.ElementAccessExpression: + node.data.jsDoc = value; + break; + case SyntaxKind.EmptyStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.EndOfFileToken: + node.data.jsDoc = value; + break; + case SyntaxKind.EnumDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.EnumMember: + node.data.jsDoc = value; + break; + case SyntaxKind.ExportAssignment: + node.data.jsDoc = value; + break; + case SyntaxKind.ExportDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.ExportSpecifier: + node.data.jsDoc = value; + break; + case SyntaxKind.ExpressionStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.ForInStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.ForOfStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.ForStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.FunctionDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.FunctionExpression: + node.data.jsDoc = value; + break; + case SyntaxKind.FunctionType: + node.data.jsDoc = value; + break; + case SyntaxKind.GetAccessor: + node.data.jsDoc = value; + break; + case SyntaxKind.Identifier: + node.data.jsDoc = value; + break; + case SyntaxKind.IfStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.ImportDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.ImportEqualsDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.IndexSignature: + node.data.jsDoc = value; + break; + case SyntaxKind.InterfaceDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.JSDocFunctionType: + node.data.jsDoc = value; + break; + case SyntaxKind.JSDocSignature: + node.data.jsDoc = value; + break; + case SyntaxKind.LabeledStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.MethodDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.MethodSignature: + node.data.jsDoc = value; + break; + case SyntaxKind.ModuleDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.NamedTupleMember: + node.data.jsDoc = value; + break; + case SyntaxKind.NamespaceExportDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.ObjectLiteralExpression: + node.data.jsDoc = value; + break; + case SyntaxKind.Parameter: + node.data.jsDoc = value; + break; + case SyntaxKind.ParenthesizedExpression: + node.data.jsDoc = value; + break; + case SyntaxKind.PropertyAccessExpression: + node.data.jsDoc = value; + break; + case SyntaxKind.PropertyAssignment: + node.data.jsDoc = value; + break; + case SyntaxKind.PropertyDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.PropertySignature: + node.data.jsDoc = value; + break; + case SyntaxKind.ReturnStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.SemicolonClassElement: + node.data.jsDoc = value; + break; + case SyntaxKind.SetAccessor: + node.data.jsDoc = value; + break; + case SyntaxKind.ShorthandPropertyAssignment: + node.data.jsDoc = value; + break; + case SyntaxKind.SpreadAssignment: + node.data.jsDoc = value; + break; + case SyntaxKind.SwitchStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.ThrowStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.TryStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.TypeAliasDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.TypeParameter: + node.data.jsDoc = value; + break; + case SyntaxKind.VariableDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.VariableStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.WhileStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.WithStatement: + node.data.jsDoc = value; + break; + case SyntaxKind.ModuleBlock: + node.data.jsDoc = value; + break; + case SyntaxKind.MissingDeclaration: + node.data.jsDoc = value; + break; + case SyntaxKind.NotEmittedStatement: + node.data.jsDoc = value; + break; + default: Debug.assertNever(node); + } +} + +// NOTE: each branch is monomorphic +const computeTransformFlagsMap: Partial TransformFlags>> = { + [SyntaxKind.EndOfFileToken]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ThisKeyword]: node => node.data.computeTransformFlags(node), + [SyntaxKind.SuperKeyword]: node => node.data.computeTransformFlags(node), + [SyntaxKind.Identifier]: node => node.data.computeTransformFlags(node), + [SyntaxKind.PrivateIdentifier]: node => node.data.computeTransformFlags(node), + [SyntaxKind.QualifiedName]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ComputedPropertyName]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TypeParameter]: node => node.data.computeTransformFlags(node), + [SyntaxKind.Parameter]: node => node.data.computeTransformFlags(node), + [SyntaxKind.Decorator]: node => node.data.computeTransformFlags(node), + [SyntaxKind.PropertySignature]: node => node.data.computeTransformFlags(node), + [SyntaxKind.CallSignature]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ConstructSignature]: node => node.data.computeTransformFlags(node), + [SyntaxKind.VariableDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.VariableDeclarationList]: node => node.data.computeTransformFlags(node), + [SyntaxKind.BindingElement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.PropertyDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.PropertyAssignment]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ShorthandPropertyAssignment]: node => node.data.computeTransformFlags(node), + [SyntaxKind.SpreadAssignment]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ObjectBindingPattern]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ArrayBindingPattern]: node => node.data.computeTransformFlags(node), + [SyntaxKind.FunctionDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.MethodSignature]: node => node.data.computeTransformFlags(node), + [SyntaxKind.MethodDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.Constructor]: node => node.data.computeTransformFlags(node), + [SyntaxKind.SemicolonClassElement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.GetAccessor]: node => node.data.computeTransformFlags(node), + [SyntaxKind.SetAccessor]: node => node.data.computeTransformFlags(node), + [SyntaxKind.IndexSignature]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ClassStaticBlockDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ImportTypeAssertionContainer]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ImportType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ThisType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.FunctionType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ConstructorType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TypeReference]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TypePredicate]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TypeQuery]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TypeLiteral]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ArrayType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TupleType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.NamedTupleMember]: node => node.data.computeTransformFlags(node), + [SyntaxKind.OptionalType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.RestType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.UnionType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.IntersectionType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ConditionalType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.InferType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ParenthesizedType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TypeOperator]: node => node.data.computeTransformFlags(node), + [SyntaxKind.IndexedAccessType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.MappedType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.LiteralType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.StringLiteral]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TemplateLiteralType]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TemplateLiteralTypeSpan]: node => node.data.computeTransformFlags(node), + [SyntaxKind.OmittedExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.PrefixUnaryExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.PostfixUnaryExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.DeleteExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TypeOfExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.VoidExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.AwaitExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.YieldExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.BinaryExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ConditionalExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.FunctionExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ArrowFunction]: node => node.data.computeTransformFlags(node), + [SyntaxKind.RegularExpressionLiteral]: node => node.data.computeTransformFlags(node), + [SyntaxKind.NoSubstitutionTemplateLiteral]: node => node.data.computeTransformFlags(node), + [SyntaxKind.NumericLiteral]: node => node.data.computeTransformFlags(node), + [SyntaxKind.BigIntLiteral]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TemplateHead]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TemplateMiddle]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TemplateTail]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TemplateExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TemplateSpan]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ParenthesizedExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ArrayLiteralExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.SpreadElement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ObjectLiteralExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.PropertyAccessExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ElementAccessExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.CallExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ExpressionWithTypeArguments]: node => node.data.computeTransformFlags(node), + [SyntaxKind.NewExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TaggedTemplateExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.AsExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TypeAssertionExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.SatisfiesExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.NonNullExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.MetaProperty]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxElement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxAttributes]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxNamespacedName]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxOpeningElement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxSelfClosingElement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxFragment]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxOpeningFragment]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxClosingFragment]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxAttribute]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxSpreadAttribute]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxClosingElement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.JsxText]: node => node.data.computeTransformFlags(node), + [SyntaxKind.EmptyStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.DebuggerStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.MissingDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.Block]: node => node.data.computeTransformFlags(node), + [SyntaxKind.VariableStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ExpressionStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.IfStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.DoStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.WhileStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ForStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ForInStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ForOfStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.BreakStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ContinueStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ReturnStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.WithStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.SwitchStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.CaseBlock]: node => node.data.computeTransformFlags(node), + [SyntaxKind.CaseClause]: node => node.data.computeTransformFlags(node), + [SyntaxKind.DefaultClause]: node => node.data.computeTransformFlags(node), + [SyntaxKind.LabeledStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ThrowStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TryStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.CatchClause]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ClassDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ClassExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.InterfaceDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.HeritageClause]: node => node.data.computeTransformFlags(node), + [SyntaxKind.TypeAliasDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.EnumMember]: node => node.data.computeTransformFlags(node), + [SyntaxKind.EnumDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ModuleDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ModuleBlock]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ImportEqualsDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ExternalModuleReference]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ImportDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ImportClause]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ImportAttribute]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ImportAttributes]: node => node.data.computeTransformFlags(node), + [SyntaxKind.NamespaceImport]: node => node.data.computeTransformFlags(node), + [SyntaxKind.NamespaceExport]: node => node.data.computeTransformFlags(node), + [SyntaxKind.NamespaceExportDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ExportDeclaration]: node => node.data.computeTransformFlags(node), + [SyntaxKind.NamedImports]: node => node.data.computeTransformFlags(node), + [SyntaxKind.NamedExports]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ImportSpecifier]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ExportSpecifier]: node => node.data.computeTransformFlags(node), + [SyntaxKind.ExportAssignment]: node => node.data.computeTransformFlags(node), + [SyntaxKind.SourceFile]: node => node.data.computeTransformFlags(node), + [SyntaxKind.SyntheticExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.Bundle]: node => node.data.computeTransformFlags(node), + [SyntaxKind.SyntaxList]: node => node.data.computeTransformFlags(node), + [SyntaxKind.NotEmittedStatement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.NotEmittedTypeElement]: node => node.data.computeTransformFlags(node), + [SyntaxKind.PartiallyEmittedExpression]: node => node.data.computeTransformFlags(node), + [SyntaxKind.CommaListExpression]: node => node.data.computeTransformFlags(node), +}; + +function computeTransformFlags(node: AstNode) { + const fn = computeTransformFlagsMap[node.kind]; + return fn !== undefined ? fn(node) : node.data.computeTransformFlags(node); +} + function isAstPropertyName(node: AstNode): node is AstPropertyName { const kind = node.kind; return kind === SyntaxKind.Identifier diff --git a/src/compiler/nodes.ts b/src/compiler/nodes.ts index b09cc1f4d3af1..9e2a506f06b31 100644 --- a/src/compiler/nodes.ts +++ b/src/compiler/nodes.ts @@ -52,6 +52,7 @@ import { FunctionExpression, FunctionTypeNode, GetAccessorDeclaration, + HasJSDoc, HasLocals, HasName, HeritageClause, @@ -235,6 +236,14 @@ import { ]; } +{ + // eslint-disable-next-line @typescript-eslint/naming-convention + type _ = [ + __Expect>, + __Expect, HasJSDoc>, + ]; +} + // Registry /** diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 24ac27de383a5..c0d0c87801b2c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -59,6 +59,7 @@ import { AstFunctionExpression, AstFunctionOrConstructorTypeNode, AstHasJSDoc, + astHasJSDoc, astHasJSDocNodes, AstHasModifiers, AstHeritageClause, @@ -183,6 +184,7 @@ import { AstReadonlyKeyword, AstReturnStatement, AstSatisfiesExpression, + astSetJSDoc, AstShorthandPropertyAssignment, AstSourceFile, AstStatement, @@ -938,12 +940,12 @@ namespace Parser { return node; } - Debug.assert(!node.data.jsDoc); // Should only be called once per node + Debug.assert(!astHasJSDoc(node)); // Should only be called once per node const jsDoc = mapDefined(getJSDocCommentRanges(node, sourceText), comment => JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos)?.node); // TODO(rbuckton): do not instantiate .node - if (jsDoc.length) node.data.jsDoc = jsDoc; + if (jsDoc.length) astSetJSDoc(node, jsDoc); if (hasDeprecatedTag) { hasDeprecatedTag = false; - (node as Mutable).flags |= NodeFlags.Deprecated; + node.flags |= NodeFlags.Deprecated; } return node; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index d007322d7144a..867b9baf91440 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -334,6 +334,8 @@ import { WriteFileCallbackData, writeFileEnsuringDirectories, PartialSourceFile, + PackageJsonInfo, + JSDocParsingMode, } from "./_namespaces/ts.js"; import * as performance from "./_namespaces/ts.performance.js"; @@ -3724,9 +3726,19 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg const result = getImpliedNodeFormatForFileWorker(getNormalizedAbsolutePath(fileName, currentDirectory), moduleResolutionCache?.getPackageJsonInfoCache(), host, options); const languageVersion = getEmitScriptTarget(options); const setExternalModuleIndicator = getSetExternalModuleIndicator(options); - return typeof result === "object" ? - { ...result, languageVersion, setExternalModuleIndicator, jsDocParsingMode: host.jsDocParsingMode } : - { languageVersion, impliedNodeFormat: result, setExternalModuleIndicator, jsDocParsingMode: host.jsDocParsingMode }; + const jsDocParsingMode = host.jsDocParsingMode; + let impliedNodeFormat: ResolutionMode | undefined; + let packageJsonLocations: readonly string[] | undefined; + let packageJsonScope: PackageJsonInfo | undefined; + if (typeof result === "object") { + impliedNodeFormat = result.impliedNodeFormat; + packageJsonLocations = result.packageJsonLocations; + packageJsonScope = result.packageJsonScope; + } + else { + impliedNodeFormat = result; + } + return { languageVersion, impliedNodeFormat, setExternalModuleIndicator, packageJsonLocations, packageJsonScope, jsDocParsingMode }; } function findSourceFileWorker(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, reason: FileIncludeReason, packageId: PackageId | undefined): SourceFile | undefined { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b258399e5f344..6e4161fb4ac6f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1,467 +1,229 @@ /* eslint-disable @typescript-eslint/adjacent-overload-signatures */ import { - AstArrayBindingPattern, AstArrayBindingPatternData, - AstArrayLiteralExpression, AstArrayLiteralExpressionData, - AstArrayTypeNode, AstArrayTypeNodeData, - AstArrowFunction, AstArrowFunctionData, - AstAsExpression, AstAsExpressionData, - AstAwaitExpression, AstAwaitExpressionData, - AstBaseJSDocTag, - AstBigIntLiteral, AstBigIntLiteralData, - AstBinaryExpression, AstBinaryExpressionData, - AstBindingElement, AstBindingElementData, - AstBlock, AstBlockData, - AstBreakStatement, AstBreakStatementData, - AstBundle, AstBundleData, - AstCallChain, - AstCallExpression, AstCallExpressionData, - AstCallSignatureDeclaration, AstCallSignatureDeclarationData, - AstCaseBlock, AstCaseBlockData, - AstCaseClause, AstCaseClauseData, - AstCatchClause, AstCatchClauseData, - AstClassDeclaration, AstClassDeclarationData, - AstClassElement, - AstClassExpression, AstClassExpressionData, - AstClassStaticBlockDeclaration, AstClassStaticBlockDeclarationData, - AstCommaListExpression, AstCommaListExpressionData, - AstComputedPropertyName, AstComputedPropertyNameData, - AstConditionalExpression, AstConditionalExpressionData, - AstConditionalTypeNode, AstConditionalTypeNodeData, - AstConstructorDeclaration, AstConstructorDeclarationData, - AstConstructorTypeNode, AstConstructorTypeNodeData, - AstConstructSignatureDeclaration, AstConstructSignatureDeclarationData, - AstContinueStatement, AstContinueStatementData, AstData, - AstDebuggerStatement, AstDebuggerStatementData, - AstDeclaration, AstDeclarationData, - AstDecorator, AstDecoratorData, - AstDefaultClause, AstDefaultClauseData, - AstDeleteExpression, AstDeleteExpressionData, - AstDoStatement, AstDoStatementData, - AstElementAccessChain, - AstElementAccessExpression, AstElementAccessExpressionData, - AstEmptyStatement, AstEmptyStatementData, - AstEndOfFileToken, AstEndOfFileTokenData, - AstEnumDeclaration, AstEnumDeclarationData, - AstEnumMember, AstEnumMemberData, - AstExportAssignment, AstExportAssignmentData, - AstExportDeclaration, AstExportDeclarationData, - AstExportSpecifier, AstExportSpecifierData, - AstExpression, - AstExpressionStatement, AstExpressionStatementData, - AstExpressionWithTypeArguments, AstExpressionWithTypeArgumentsData, - AstExternalModuleReference, AstExternalModuleReferenceData, - AstFalseLiteral, - AstForInStatement, AstForInStatementData, - AstForOfStatement, AstForOfStatementData, - AstForStatement, AstForStatementData, - AstFunctionDeclaration, AstFunctionDeclarationData, - AstFunctionExpression, AstFunctionExpressionData, - AstFunctionTypeNode, AstFunctionTypeNodeData, - AstGetAccessorDeclaration, AstGetAccessorDeclarationData, - AstHeritageClause, AstHeritageClauseData, AstIdentifier, AstIdentifierData, - AstIfStatement, AstIfStatementData, - AstImportAttribute, AstImportAttributeData, - AstImportAttributes, AstImportAttributesData, - AstImportClause, AstImportClauseData, - AstImportDeclaration, AstImportDeclarationData, - AstImportEqualsDeclaration, AstImportEqualsDeclarationData, - AstImportExpression, - AstImportSpecifier, AstImportSpecifierData, - AstImportTypeAssertionContainer, AstImportTypeAssertionContainerData, - AstImportTypeNode, AstImportTypeNodeData, - AstIndexedAccessTypeNode, AstIndexedAccessTypeNodeData, - AstIndexSignatureDeclaration, AstIndexSignatureDeclarationData, - AstInferTypeNode, AstInferTypeNodeData, - AstInterfaceDeclaration, AstInterfaceDeclarationData, - AstIntersectionTypeNode, AstIntersectionTypeNodeData, - AstJSDoc, - AstJSDocAllType, AstJSDocAllTypeData, - AstJSDocAugmentsTag, AstJSDocAugmentsTagData, - AstJSDocAuthorTag, AstJSDocAuthorTagData, - AstJSDocCallbackTag, AstJSDocCallbackTagData, - AstJSDocClassReference, AstJSDocClassReferenceData, - AstJSDocClassTag, AstJSDocClassTagData, AstJSDocData, - AstJSDocDeprecatedTag, AstJSDocDeprecatedTagData, - AstJSDocEnumTag, AstJSDocEnumTagData, - AstJSDocFunctionType, AstJSDocFunctionTypeData, - AstJSDocImplementsTag, AstJSDocImplementsTagData, - AstJSDocImportTag, AstJSDocImportTagData, - AstJSDocLink, - AstJSDocLinkCode, AstJSDocLinkCodeData, AstJSDocLinkData, - AstJSDocLinkPlain, AstJSDocLinkPlainData, - AstJSDocMemberName, AstJSDocMemberNameData, - AstJSDocNamepathType, AstJSDocNamepathTypeData, - AstJSDocNameReference, AstJSDocNameReferenceData, - AstJSDocNamespaceDeclaration, AstJSDocNamespaceDeclarationData, - AstJSDocNonNullableType, AstJSDocNonNullableTypeData, - AstJSDocNullableType, AstJSDocNullableTypeData, - AstJSDocOptionalType, AstJSDocOptionalTypeData, - AstJSDocOverloadTag, AstJSDocOverloadTagData, - AstJSDocOverrideTag, AstJSDocOverrideTagData, - AstJSDocParameterTag, AstJSDocParameterTagData, - AstJSDocPrivateTag, AstJSDocPrivateTagData, - AstJSDocPropertyLikeTag, - AstJSDocPropertyTag, AstJSDocPropertyTagData, - AstJSDocProtectedTag, AstJSDocProtectedTagData, - AstJSDocPublicTag, AstJSDocPublicTagData, - AstJSDocReadonlyTag, AstJSDocReadonlyTagData, - AstJSDocReturnTag, AstJSDocReturnTagData, - AstJSDocSatisfiesTag, AstJSDocSatisfiesTagData, - AstJSDocSeeTag, AstJSDocSeeTagData, - AstJSDocSignature, AstJSDocSignatureData, AstJSDocTagData, - AstJSDocTemplateTag, AstJSDocTemplateTagData, - AstJSDocText, AstJSDocTextData, - AstJSDocThisTag, AstJSDocThisTagData, - AstJSDocThrowsTag, AstJSDocThrowsTagData, - AstJSDocTypedefTag, AstJSDocTypedefTagData, - AstJSDocTypeExpression, AstJSDocTypeExpressionData, - AstJSDocTypeLiteral, AstJSDocTypeLiteralData, - AstJSDocTypeTag, AstJSDocTypeTagData, - AstJSDocUnknownTag, AstJSDocUnknownTagData, - AstJSDocUnknownType, AstJSDocUnknownTypeData, - AstJSDocVariadicType, AstJSDocVariadicTypeData, - AstJsonMinusNumericLiteral, AstJsonMinusNumericLiteralData, - AstJsonObjectExpressionStatement, AstJsonObjectExpressionStatementData, - AstJsonSourceFile, AstJsonSourceFileData, - AstJsxAttribute, AstJsxAttributeData, - AstJsxAttributes, AstJsxAttributesData, - AstJsxClosingElement, AstJsxClosingElementData, - AstJsxClosingFragment, AstJsxClosingFragmentData, - AstJsxElement, AstJsxElementData, - AstJsxExpression, AstJsxExpressionData, - AstJsxFragment, AstJsxFragmentData, - AstJsxNamespacedName, AstJsxNamespacedNameData, - AstJsxOpeningElement, AstJsxOpeningElementData, - AstJsxOpeningFragment, AstJsxOpeningFragmentData, - AstJsxSelfClosingElement, AstJsxSelfClosingElementData, - AstJsxSpreadAttribute, AstJsxSpreadAttributeData, - AstJsxTagNamePropertyAccess, AstJsxTagNamePropertyAccessData, - AstJsxText, AstJsxTextData, - AstKeywordExpression, - AstKeywordTypeNode, - AstLabeledStatement, AstLabeledStatementData, - AstLeftHandSideExpression, - AstLiteralExpression, AstLiteralExpressionData, - AstLiteralLikeNode, AstLiteralLikeNodeData, - AstLiteralTypeNode, AstLiteralTypeNodeData, - AstMappedTypeNode, AstMappedTypeNodeData, - AstMemberExpression, - AstMetaProperty, AstMetaPropertyData, - AstMethodDeclaration, AstMethodDeclarationData, - AstMethodSignature, AstMethodSignatureData, - AstMissingDeclaration, AstMissingDeclarationData, - AstModuleBlock, AstModuleBlockData, - AstModuleDeclaration, AstModuleDeclarationData, - AstNamedExports, AstNamedExportsData, - AstNamedImports, AstNamedImportsData, - AstNamedTupleMember, AstNamedTupleMemberData, - AstNamespaceDeclaration, AstNamespaceDeclarationData, - AstNamespaceExport, AstNamespaceExportData, - AstNamespaceExportDeclaration, AstNamespaceExportDeclarationData, - AstNamespaceImport, AstNamespaceImportData, - AstNewExpression, AstNewExpressionData, AstNode, AstNodeArray, - AstNonNullChain, - AstNonNullExpression, AstNonNullExpressionData, - AstNoSubstitutionTemplateLiteral, AstNoSubstitutionTemplateLiteralData, - AstNotEmittedStatement, AstNotEmittedStatementData, - AstNotEmittedTypeElement, AstNotEmittedTypeElementData, - AstNullLiteral, - AstNumericLiteral, AstNumericLiteralData, - AstObjectBindingPattern, AstObjectBindingPatternData, - AstObjectLiteralElement, - AstObjectLiteralExpression, AstObjectLiteralExpressionData, - AstOmittedExpression, AstOmittedExpressionData, - AstOptionalTypeNode, AstOptionalTypeNodeData, - AstParameterDeclaration, AstParameterDeclarationData, - AstParenthesizedExpression, AstParenthesizedExpressionData, - AstParenthesizedTypeNode, AstParenthesizedTypeNodeData, - AstPartiallyEmittedExpression, AstPartiallyEmittedExpressionData, - AstPostfixUnaryExpression, AstPostfixUnaryExpressionData, - AstPrefixUnaryExpression, AstPrefixUnaryExpressionData, - AstPrimaryExpression, - AstPrivateIdentifier, AstPrivateIdentifierData, - AstPropertyAccessChain, - AstPropertyAccessExpression, AstPropertyAccessExpressionData, - AstPropertyAssignment, AstPropertyAssignmentData, - AstPropertyDeclaration, AstPropertyDeclarationData, - AstPropertySignature, AstPropertySignatureData, - AstQualifiedName, AstQualifiedNameData, - AstRegularExpressionLiteral, AstRegularExpressionLiteralData, - AstRestTypeNode, AstRestTypeNodeData, - AstReturnStatement, AstReturnStatementData, - AstSatisfiesExpression, AstSatisfiesExpressionData, - AstSemicolonClassElement, AstSemicolonClassElementData, - AstSetAccessorDeclaration, AstSetAccessorDeclarationData, - AstShorthandPropertyAssignment, AstShorthandPropertyAssignmentData, - AstSourceFile, AstSourceFileData, - AstSpreadAssignment, AstSpreadAssignmentData, - AstSpreadElement, AstSpreadElementData, - AstStatement, - AstStringLiteral, AstStringLiteralData, - AstStringLiteralLikeNode, AstStringLiteralLikeNodeData, AstSuperExpression, AstSuperExpressionData, - AstSwitchStatement, AstSwitchStatementData, AstSyntaxListData, - AstSyntheticExpression, AstSyntheticExpressionData, - AstSyntheticReferenceExpression, AstSyntheticReferenceExpressionData, - AstTaggedTemplateExpression, AstTaggedTemplateExpressionData, - AstTemplateExpression, AstTemplateExpressionData, - AstTemplateHead, AstTemplateHeadData, - AstTemplateLiteralLikeNode, AstTemplateLiteralLikeNodeData, - AstTemplateLiteralTypeNode, AstTemplateLiteralTypeNodeData, - AstTemplateLiteralTypeSpan, AstTemplateLiteralTypeSpanData, - AstTemplateMiddle, AstTemplateMiddleData, - AstTemplateSpan, AstTemplateSpanData, - AstTemplateTail, AstTemplateTailData, - AstThisExpression, AstThisExpressionData, - AstThisTypeNode, AstThisTypeNodeData, - AstThrowStatement, AstThrowStatementData, AstTokenData, - AstTrueLiteral, - AstTryStatement, AstTryStatementData, - AstTupleTypeNode, AstTupleTypeNodeData, - AstTypeAliasDeclaration, AstTypeAliasDeclarationData, - AstTypeAssertion, AstTypeAssertionData, - AstTypeElement, - AstTypeLiteralNode, AstTypeLiteralNodeData, - AstTypeNode, - AstTypeOfExpression, AstTypeOfExpressionData, - AstTypeOperatorNode, AstTypeOperatorNodeData, - AstTypeParameterDeclaration, AstTypeParameterDeclarationData, - AstTypePredicateNode, AstTypePredicateNodeData, - AstTypeQueryNode, AstTypeQueryNodeData, - AstTypeReferenceNode, AstTypeReferenceNodeData, - AstUnaryExpression, - AstUnionTypeNode, AstUnionTypeNodeData, - AstUpdateExpression, - AstVariableDeclaration, AstVariableDeclarationData, - AstVariableDeclarationList, AstVariableDeclarationListData, - AstVariableStatement, AstVariableStatementData, - AstVoidExpression, AstVoidExpressionData, - AstWhileStatement, AstWhileStatementData, - AstWithStatement, AstWithStatementData, - AstYieldExpression, AstYieldExpressionData, AstNodeFactory, computePositionOfLineAndCharacter, @@ -550,6 +312,9 @@ import { SymlinkCache, ThisContainer, updateSourceFile, + AstEntityNameExpression, + AstQuestionDotToken, + AstMemberName, } from "./_namespaces/ts.js"; // branded string type used to store absolute, normalized and canonicalized paths @@ -1470,17 +1235,17 @@ export const enum PredicateSemantics { /** @internal */ export type NodeId = number; -export type NodeConstructor = new (ast: AstNode>) => N; // TODO: don't use indexed access type +export type NodeConstructor = new (ast: AstNode>) => N; // TODO: avoid indexed access type // dprint-ignore export class Node< K extends SyntaxKind = SyntaxKind, T extends AstData = AstData > implements ReadonlyTextRange { - readonly ast: AstNode> = undefined!; + readonly ast: AstNode = undefined!; constructor(ast: AstNode>) { - this.ast = ast; + this.ast = ast as AstNode; Object.preventExtensions(this); } @@ -2008,7 +1773,10 @@ export type HasJSDoc = | VariableDeclaration | VariableStatement | WhileStatement - | WithStatement; + | WithStatement + | ModuleBlock + | MissingDeclaration + | NotEmittedStatement; export type HasType = | SignatureDeclaration @@ -2411,7 +2179,7 @@ export class Token implements JSDocContainer { declare _jsdocContainerBrand: any; - declare readonly ast: AstEndOfFileToken; + // declare readonly ast: AstEndOfFileToken; /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } @@ -2501,7 +2269,7 @@ export type ClassMemberModifier = export type ModifiersArray = NodeArray; export interface KeywordExpression extends PrimaryExpression, KeywordToken { - readonly ast: AstKeywordExpression; + // readonly ast: AstKeywordExpression; readonly kind: TKind; } @@ -2533,7 +2301,7 @@ export class Identifier extends Token declare _declarationBrand: any; declare _jsdocContainerBrand: any; declare _flowContainerBrand: any; - declare readonly ast: AstIdentifier; + // declare readonly ast: AstIdentifier; /** * Prefer to use {@link text}. @@ -2572,7 +2340,7 @@ export interface GeneratedIdentifier extends Identifier { // dprint-ignore export class QualifiedName extends Node implements FlowContainer { declare _flowContainerBrand: any; - declare readonly ast: AstQualifiedName; + // declare readonly ast: AstQualifiedName; get left(): EntityName { return this.ast.data.left?.node; } get right(): Identifier { return this.ast.data.right?.node; } @@ -2606,7 +2374,7 @@ export type DeclarationName = export interface Declaration extends Node { _declarationBrand: any; - readonly ast: AstDeclaration; + // readonly ast: AstDeclaration; /** @internal */ symbol: Symbol; // Symbol declared by node (initialized by binding) /** @internal */ localSymbol: Symbol | undefined; // Local symbol declared by node (initialized by binding only for exported nodes) } @@ -2691,13 +2459,13 @@ export interface LateBoundElementAccessExpression extends ElementAccessExpressio } export interface DeclarationStatement extends NamedDeclaration, Statement { - readonly ast: AstNode; + // readonly ast: AstNode; readonly name?: Identifier | StringLiteral | NumericLiteral | undefined; } // dprint-ignore export class ComputedPropertyName extends Node { - declare readonly ast: AstComputedPropertyName; + // declare readonly ast: AstComputedPropertyName; override get parent(): Declaration { return super.parent as Declaration; } @@ -2716,7 +2484,7 @@ export class PrivateIdentifier extends Token { - declare readonly ast: AstDecorator; + // declare readonly ast: AstDecorator; override get parent(): Declaration { return super.parent as Declaration; } @@ -2751,7 +2519,7 @@ export class Decorator extends Node { export class TypeParameterDeclaration extends Node implements Declaration, JSDocContainer { declare _declarationBrand: any; declare _jsdocContainerBrand: any; - declare readonly ast: AstTypeParameterDeclaration; + // declare readonly ast: AstTypeParameterDeclaration; override get parent(): DeclarationWithTypeParameterChildren | InferTypeNode { return super.parent as DeclarationWithTypeParameterChildren | InferTypeNode; } @@ -2779,7 +2547,7 @@ export class TypeParameterDeclaration extends Node; + // readonly ast: AstNode; readonly kind: SignatureDeclaration["kind"]; readonly name?: PropertyName | undefined; readonly typeParameters?: NodeArray | undefined; @@ -2810,7 +2578,7 @@ export class CallSignatureDeclaration extends Node | undefined { return this.ast.data.typeParameters?.nodes; } get parameters(): NodeArray { return this.ast.data.parameters.nodes; } @@ -2840,7 +2608,7 @@ export class ConstructSignatureDeclaration extends Node | undefined { return this.ast.data.typeParameters?.nodes; } get parameters(): NodeArray { return this.ast.data.parameters.nodes; } @@ -2869,7 +2637,7 @@ export type BindingName = Identifier | BindingPattern; export class VariableDeclaration extends Node implements Declaration, JSDocContainer { declare _declarationBrand: any; declare _jsdocContainerBrand: any; - declare readonly ast: AstVariableDeclaration; + // declare readonly ast: AstVariableDeclaration; override get parent() { return super.parent as VariableDeclarationList | CatchClause; } @@ -2909,7 +2677,7 @@ export type InitializedVariableDeclaration = VariableDeclaration & { readonly in // dprint-ignore export class VariableDeclarationList extends Node { - declare readonly ast: AstVariableDeclarationList; + // declare readonly ast: AstVariableDeclarationList; override get parent() { return super.parent as VariableStatement | ForStatement | ForOfStatement | ForInStatement; } @@ -2923,7 +2691,7 @@ export class VariableDeclarationList extends Node implements Declaration, JSDocContainer { declare _declarationBrand: any; declare _jsdocContainerBrand: any; - declare readonly ast: AstParameterDeclaration; + // declare readonly ast: AstParameterDeclaration; override get parent(): SignatureDeclaration { return super.parent as SignatureDeclaration; } @@ -2955,7 +2723,7 @@ export class ParameterDeclaration extends Node implements Declaration, FlowContainer { declare _declarationBrand: any; declare _flowContainerBrand: any; - declare readonly ast: AstBindingElement; + // declare readonly ast: AstBindingElement; override get parent() { return super.parent as BindingPattern; } @@ -2997,7 +2765,7 @@ export class PropertySignature extends Node { - declare readonly ast: AstObjectBindingPattern; + // declare readonly ast: AstObjectBindingPattern; override get parent() { return super.parent as VariableDeclaration | ParameterDeclaration | BindingElement; } @@ -3228,7 +2996,7 @@ export class ObjectBindingPattern extends Node { - declare readonly ast: AstArrayBindingPattern; + // declare readonly ast: AstArrayBindingPattern; override get parent() { return super.parent as VariableDeclaration | ParameterDeclaration | BindingElement; } @@ -3305,7 +3073,7 @@ export class FunctionDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } get asteriskToken(): AsteriskToken | undefined { return this.ast.data.asteriskToken?.node; } @@ -3348,7 +3116,7 @@ export class MethodSignature extends Node extends Node { _typeNodeBrand: any; - readonly ast: AstTypeNode; + // readonly ast: AstTypeNode; } export interface KeywordTypeNode extends KeywordToken, TypeNode { - readonly ast: AstKeywordTypeNode; + // readonly ast: AstKeywordTypeNode; readonly kind: TKind; } /** @deprecated */ // dprint-ignore export class ImportTypeAssertionContainer extends Node { - declare readonly ast: AstImportTypeAssertionContainer; + // declare readonly ast: AstImportTypeAssertionContainer; override get parent() { return super.parent as ImportTypeNode; } @@ -3707,7 +3475,7 @@ export class ImportTypeAssertionContainer extends Node implements TypeNode, NodeWithTypeArguments { declare _typeNodeBrand: any; - declare readonly ast: AstImportTypeNode; + // declare readonly ast: AstImportTypeNode; get isTypeOf(): boolean { return this.ast.data.isTypeOf; } get argument(): TypeNode { return this.ast.data.argument.node; } @@ -3731,13 +3499,13 @@ export type LiteralImportTypeNode = ImportTypeNode & { readonly argument: Litera // dprint-ignore export class ThisTypeNode extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstThisTypeNode; + // declare readonly ast: AstThisTypeNode; } export type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; export interface FunctionOrConstructorTypeNodeBase extends TypeNode, SignatureDeclarationBase { - readonly ast: AstNode; + // readonly ast: AstNode; readonly kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType; readonly type: TypeNode; } @@ -3749,7 +3517,7 @@ export class FunctionTypeNode extends Node | undefined { return this.ast.data.typeParameters?.nodes; } get parameters(): NodeArray { return this.ast.data.parameters.nodes; } @@ -3776,7 +3544,7 @@ export class FunctionTypeNode extends Node implements FunctionOrConstructorTypeNodeBase, LocalsContainer { - declare readonly ast: AstConstructorTypeNode; + // declare readonly ast: AstConstructorTypeNode; declare _signatureDeclarationBrand: any; declare _typeNodeBrand: any; @@ -3816,7 +3584,7 @@ export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; // dprint-ignore export class TypeReferenceNode extends Node implements NodeWithTypeArguments { declare _typeNodeBrand: any; - declare readonly ast: AstTypeReferenceNode; + // declare readonly ast: AstTypeReferenceNode; get typeName(): Identifier | QualifiedName { return this.ast.data.typeName.node; } get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } @@ -3828,7 +3596,7 @@ export class TypeReferenceNode extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstTypePredicateNode; + // declare readonly ast: AstTypePredicateNode; override get parent() { return super.parent as SignatureDeclaration | JSDocTypeExpression; } @@ -3845,7 +3613,7 @@ export class TypePredicateNode extends Node implements NodeWithTypeArguments { declare _typeNodeBrand: any; - declare readonly ast: AstTypeQueryNode; + // declare readonly ast: AstTypeQueryNode; get exprName(): Identifier | QualifiedName { return this.ast.data.exprName.node; } get typeArguments(): NodeArray | undefined { return this.ast.data.typeArguments?.nodes; } @@ -3859,7 +3627,7 @@ export class TypeQueryNode extends Node implements TypeNode, Declaration { declare _typeNodeBrand: any; declare _declarationBrand: any; - declare readonly ast: AstTypeLiteralNode; + // declare readonly ast: AstTypeLiteralNode; get members(): NodeArray { return this.ast.data.members.nodes; } @@ -3873,7 +3641,7 @@ export class TypeLiteralNode extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstArrayTypeNode; + // declare readonly ast: AstArrayTypeNode; get elementType(): TypeNode { return this.ast.data.elementType.node; } @@ -3883,7 +3651,7 @@ export class ArrayTypeNode extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstTupleTypeNode; + // declare readonly ast: AstTupleTypeNode; get elements(): NodeArray { return this.ast.data.elements.nodes; } @@ -3895,7 +3663,7 @@ export class NamedTupleMember extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstOptionalTypeNode; + // declare readonly ast: AstOptionalTypeNode; get type(): TypeNode { return this.ast.data.type.node; } @@ -3927,7 +3695,7 @@ export class OptionalTypeNode extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstRestTypeNode; + // declare readonly ast: AstRestTypeNode; get type(): TypeNode { return this.ast.data.type.node; } @@ -3939,7 +3707,7 @@ export type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; // dprint-ignore export class UnionTypeNode extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstUnionTypeNode; + // declare readonly ast: AstUnionTypeNode; get types(): NodeArray { return this.ast.data.types.nodes; } @@ -3949,7 +3717,7 @@ export class UnionTypeNode extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstIntersectionTypeNode; + // declare readonly ast: AstIntersectionTypeNode; get types(): NodeArray { return this.ast.data.types.nodes; } @@ -3960,7 +3728,7 @@ export class IntersectionTypeNode extends Node implements TypeNode, LocalsContainer { declare _typeNodeBrand: any; declare _localsContainerBrand: any; - declare readonly ast: AstConditionalTypeNode; + // declare readonly ast: AstConditionalTypeNode; get checkType(): TypeNode { return this.ast.data.checkType.node; } get extendsType(): TypeNode { return this.ast.data.extendsType.node; } @@ -3980,7 +3748,7 @@ export class ConditionalTypeNode extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstInferTypeNode; + // declare readonly ast: AstInferTypeNode; get typeParameter(): TypeParameterDeclaration { return this.ast.data.typeParameter.node; } @@ -3990,7 +3758,7 @@ export class InferTypeNode extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstParenthesizedTypeNode; + // declare readonly ast: AstParenthesizedTypeNode; get type(): TypeNode { return this.ast.data.type.node; } @@ -4000,7 +3768,7 @@ export class ParenthesizedTypeNode extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstTypeOperatorNode; + // declare readonly ast: AstTypeOperatorNode; get operator(): SyntaxKind.KeyOfKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.UniqueKeyword { return this.ast.data.operator; } get type(): TypeNode { return this.ast.data.type.node; } @@ -4017,7 +3785,7 @@ export interface UniqueTypeOperatorNode extends TypeOperatorNode { // dprint-ignore export class IndexedAccessTypeNode extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstIndexedAccessTypeNode; + // declare readonly ast: AstIndexedAccessTypeNode; get objectType(): TypeNode { return this.ast.data.objectType.node; } get indexType(): TypeNode { return this.ast.data.indexType.node; } @@ -4031,7 +3799,7 @@ export class MappedTypeNode extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstLiteralTypeNode; + // declare readonly ast: AstLiteralTypeNode; get literal(): NullLiteral | TrueLiteral | FalseLiteral | PrefixUnaryExpression | LiteralExpression { return this.ast.data.literal.node; } @@ -4077,7 +3845,7 @@ export class StringLiteral extends Token implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstTemplateLiteralTypeNode; + // declare readonly ast: AstTemplateLiteralTypeNode; get head(): TemplateHead { return this.ast.data.head.node; } get templateSpans(): NodeArray { return this.ast.data.templateSpans.nodes; } @@ -4118,7 +3886,7 @@ export class TemplateLiteralTypeNode extends Node { declare _typeNodeBrand: any; - declare readonly ast: AstTemplateLiteralTypeSpan; + // declare readonly ast: AstTemplateLiteralTypeSpan; override get parent() { return super.parent as TemplateLiteralTypeNode; } @@ -4139,13 +3907,13 @@ export class TemplateLiteralTypeSpan extends Node implements Expression { declare _expressionBrand: any; - declare readonly ast: AstOmittedExpression; + // declare readonly ast: AstOmittedExpression; } // Represents an expression that is elided as part of a transformation to emit comments on a @@ -4156,7 +3924,7 @@ export class PartiallyEmittedExpression extends Node implements Keywor declare _updateExpressionBrand: any; declare _unaryExpressionBrand: any; declare _expressionBrand: any; - declare readonly ast: AstNullLiteral; + // declare readonly ast: AstNullLiteral; } // TODO(rbuckton): Move literal token nodes adjacent to other tokens and literals. @@ -4255,7 +4023,7 @@ export class TrueLiteral extends Token implements Keywor declare _updateExpressionBrand: any; declare _unaryExpressionBrand: any; declare _expressionBrand: any; - declare readonly ast: AstTrueLiteral; + // declare readonly ast: AstTrueLiteral; } // TODO(rbuckton): Move literal token nodes adjacent to other tokens and literals. @@ -4267,7 +4035,7 @@ export class FalseLiteral extends Token implements Keyw declare _updateExpressionBrand: any; declare _unaryExpressionBrand: any; declare _expressionBrand: any; - declare readonly ast: AstFalseLiteral; + // declare readonly ast: AstFalseLiteral; } export type BooleanLiteral = TrueLiteral | FalseLiteral; @@ -4281,7 +4049,7 @@ export class ThisExpression extends Token implements declare _updateExpressionBrand: any; declare _unaryExpressionBrand: any; declare _expressionBrand: any; - declare readonly ast: AstImportExpression; + // declare readonly ast: AstImportExpression; } // dprint-ignore export class DeleteExpression extends Node implements UnaryExpression { declare _unaryExpressionBrand: any; declare _expressionBrand: any; - declare readonly ast: AstDeleteExpression; + // declare readonly ast: AstDeleteExpression; get expression(): UnaryExpression { return this.ast.data.expression.node; } @@ -4328,7 +4096,7 @@ export class DeleteExpression extends Node implements UnaryExpression { declare _unaryExpressionBrand: any; declare _expressionBrand: any; - declare readonly ast: AstTypeOfExpression; + // declare readonly ast: AstTypeOfExpression; get expression(): UnaryExpression { return this.ast.data.expression.node; } @@ -4339,7 +4107,7 @@ export class TypeOfExpression extends Node implements UnaryExpression { declare _unaryExpressionBrand: any; declare _expressionBrand: any; - declare readonly ast: AstVoidExpression; + // declare readonly ast: AstVoidExpression; get expression(): UnaryExpression { return this.ast.data.expression.node; } @@ -4350,7 +4118,7 @@ export class VoidExpression extends Node implements UnaryExpression { declare _unaryExpressionBrand: any; declare _expressionBrand: any; - declare readonly ast: AstAwaitExpression; + // declare readonly ast: AstAwaitExpression; get expression(): UnaryExpression { return this.ast.data.expression.node; } @@ -4360,7 +4128,7 @@ export class AwaitExpression extends Node implements Expression { declare _expressionBrand: any; - declare readonly ast: AstYieldExpression; + // declare readonly ast: AstYieldExpression; get asteriskToken(): AsteriskToken | undefined { return this.ast.data.asteriskToken?.node; } get expression(): Expression | undefined { return this.ast.data.expression?.node; } @@ -4372,7 +4140,7 @@ export class YieldExpression extends Node implements Expression { declare _expressionBrand: any; - declare readonly ast: AstSyntheticExpression; + // declare readonly ast: AstSyntheticExpression; get isSpread(): boolean { return this.ast.data.isSpread; } get type(): Type { return this.ast.data.type; } @@ -4517,7 +4285,7 @@ export class BinaryExpression extends Node implements Expression { declare _expressionBrand: any; - declare readonly ast: AstConditionalExpression; + // declare readonly ast: AstConditionalExpression; get condition(): Expression { return this.ast.data.condition.node; } get questionToken(): QuestionToken { return this.ast.data.questionToken.node; } @@ -4653,7 +4421,7 @@ export class FunctionExpression extends Node | undefined { return this.ast.data.modifiers?.nodes; } get asteriskToken(): AsteriskToken | undefined { return this.ast.data.asteriskToken?.node; } @@ -4699,7 +4467,7 @@ export class ArrowFunction extends Node | undefined { return this.ast.data.modifiers?.nodes; } get equalsGreaterThanToken(): EqualsGreaterThanToken { return this.ast.data.equalsGreaterThanToken.node; } @@ -4739,7 +4507,7 @@ export class ArrowFunction extends Node implements TemplateLiteralLikeNode { - declare readonly ast: AstTemplateHead; + // declare readonly ast: AstTemplateHead; override get parent() { return super.parent as TemplateExpression | TemplateLiteralTypeNode; } @@ -4967,7 +4735,7 @@ export class TemplateHead extends Token implements TemplateLiteralLikeNode { - declare readonly ast: AstTemplateMiddle; + // declare readonly ast: AstTemplateMiddle; override get parent() { return super.parent as TemplateSpan | TemplateLiteralTypeSpan; } @@ -4988,7 +4756,7 @@ export class TemplateMiddle extends Token implements TemplateLiteralLikeNode { - declare readonly ast: AstTemplateTail; + // declare readonly ast: AstTemplateTail; override get parent() { return super.parent as TemplateSpan | TemplateLiteralTypeSpan; } @@ -5025,7 +4793,7 @@ export class TemplateExpression extends Node { return this.ast.data.templateSpans.nodes; } @@ -5042,7 +4810,7 @@ export type TemplateLiteral = // The template literal must have kind TemplateMiddleLiteral or TemplateTailLiteral. // dprint-ignore export class TemplateSpan extends Node { - declare readonly ast: AstTemplateSpan; + // declare readonly ast: AstTemplateSpan; override get parent() { return super.parent as TemplateExpression; } @@ -5063,7 +4831,7 @@ export class ParenthesizedExpression extends Node { return this.ast.data.elements.nodes; } @@ -5097,7 +4865,7 @@ export class ArrayLiteralExpression extends Node implements Expression { declare _expressionBrand: any; - declare readonly ast: AstSpreadElement; + // declare readonly ast: AstSpreadElement; override get parent() { return super.parent as ArrayLiteralExpression | CallExpression | NewExpression; } @@ -5115,7 +4883,7 @@ export class SpreadElement extends Node extends PrimaryExpression, Declaration { - readonly ast: AstNode; + // readonly ast: AstNode; readonly properties: NodeArray; } @@ -5130,7 +4898,7 @@ export class ObjectLiteralExpression extends Node { return this.ast.data.properties.nodes; } @@ -5159,7 +4927,7 @@ export class PropertyAccessExpression extends Node implements MemberExpression, Declaration, JSDocContainer, FlowContainer { @@ -5221,7 +5001,7 @@ export class ElementAccessExpression extends Node | undefined { return this.ast.data.typeArguments?.nodes; } @@ -5383,7 +5163,7 @@ export class NewExpression extends Node | undefined { return this.ast.data.typeArguments?.nodes; } @@ -5405,7 +5185,7 @@ export class TaggedTemplateExpression extends Node | undefined { return this.ast.data.typeArguments?.nodes; } @@ -5429,7 +5209,7 @@ export type CallLikeExpression = // dprint-ignore export class AsExpression extends Node implements Expression { declare _expressionBrand: any; - declare readonly ast: AstAsExpression; + // declare readonly ast: AstAsExpression; get expression(): Expression { return this.ast.data.expression.node; } get type(): TypeNode { return this.ast.data.type.node; } @@ -5442,7 +5222,7 @@ export class AsExpression extends Node implements UnaryExpression { declare _unaryExpressionBrand: any; declare _expressionBrand: any; - declare readonly ast: AstTypeAssertion; + // declare readonly ast: AstTypeAssertion; get type(): TypeNode { return this.ast.data.type.node; } get expression(): UnaryExpression { return this.ast.data.expression.node; } @@ -5461,7 +5241,7 @@ export type AssertionExpression = // dprint-ignore export class SatisfiesExpression extends Node implements Expression { declare _expressionBrand: any; - declare readonly ast: AstSatisfiesExpression; + // declare readonly ast: AstSatisfiesExpression; get expression(): Expression { return this.ast.data.expression.node; } get type(): TypeNode { return this.ast.data.type.node; } @@ -5476,7 +5256,7 @@ export class NonNullExpression extends Node i declare _updateExpressionBrand: any; declare _unaryExpressionBrand: any; declare _expressionBrand: any; - declare readonly ast: AstJsxElement; + // declare readonly ast: AstJsxElement; get openingElement(): JsxOpeningElement { return this.ast.data.openingElement.node; } get children(): NodeArray { return this.ast.data.children.nodes; } @@ -5562,7 +5342,7 @@ export class JsxAttributes extends Node { - declare readonly ast: AstJsxNamespacedName; + // declare readonly ast: AstJsxNamespacedName; get name(): Identifier { return this.ast.data.name.node; } get namespace(): Identifier { return this.ast.data.namespace.node; } @@ -5592,7 +5372,7 @@ export class JsxNamespacedName extends Node implements Expression { declare _expressionBrand: any; - declare readonly ast: AstJsxOpeningElement; + // declare readonly ast: AstJsxOpeningElement; override get parent() { return super.parent as JsxElement; } @@ -5615,7 +5395,7 @@ export class JsxSelfClosingElement extends Node | undefined { return this.ast.data.typeArguments?.nodes; } @@ -5635,7 +5415,7 @@ export class JsxFragment extends Node { return this.ast.data.children.nodes; } @@ -5651,7 +5431,7 @@ export class JsxFragment extends Node implements Expression { declare _expressionBrand: any; - declare readonly ast: AstJsxOpeningFragment; + // declare readonly ast: AstJsxOpeningFragment; override get parent() { return super.parent as JsxFragment; } @@ -5663,7 +5443,7 @@ export class JsxOpeningFragment extends Node implements Expression { declare _expressionBrand: any; - declare readonly ast: AstJsxClosingFragment; + // declare readonly ast: AstJsxClosingFragment; override get parent() { return super.parent as JsxFragment; } @@ -5672,7 +5452,7 @@ export class JsxClosingFragment extends Node implements Declaration { - declare readonly ast: AstJsxAttribute; + // declare readonly ast: AstJsxAttribute; declare _declarationBrand: any; @@ -5703,7 +5483,7 @@ export type JsxAttributeValue = export class JsxSpreadAttribute extends Node implements ObjectLiteralElement { declare _objectLiteralBrand: any; declare _declarationBrand: any; - declare readonly ast: AstJsxSpreadAttribute; + // declare readonly ast: AstJsxSpreadAttribute; /** @internal*/ declare symbol: never; // not actually a declaration /** @internal*/ declare localSymbol: never; // not actually a declaration @@ -5719,7 +5499,7 @@ export class JsxSpreadAttribute extends Node { - declare readonly ast: AstJsxClosingElement; + // declare readonly ast: AstJsxClosingElement; override get parent() { return super.parent as JsxElement; } @@ -5733,7 +5513,7 @@ export class JsxClosingElement extends Node implements Expression { declare _expressionBrand: any; - declare readonly ast: AstJsxExpression; + // declare readonly ast: AstJsxExpression; override get parent() { return super.parent as JsxElement | JsxFragment | JsxAttributeLike; } @@ -5747,7 +5527,7 @@ export class JsxExpression extends Node implements LiteralLikeNode { - declare readonly ast: AstJsxText; + // declare readonly ast: AstJsxText; override get parent() { return super.parent as JsxElement | JsxFragment; } @@ -5772,7 +5552,7 @@ export type JsxChild = export interface Statement extends JSDocContainer { _statementBrand: any; - readonly ast: AstStatement; + // readonly ast: AstStatement; } // Represents a statement that is elided as part of a transformation to emit comments on a @@ -5781,7 +5561,7 @@ export interface Statement extends JSDocContainer { export class NotEmittedStatement extends Node implements Statement { declare _statementBrand: any; declare _jsdocContainerBrand: any; - declare readonly ast: AstNotEmittedStatement; + // declare readonly ast: AstNotEmittedStatement; /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } @@ -5792,7 +5572,7 @@ export class NotEmittedStatement extends Node implements TypeElement { declare _typeElementBrand: any; declare _declarationBrand: any; - declare readonly ast: AstNotEmittedTypeElement; + // declare readonly ast: AstNotEmittedTypeElement; /** @internal */ get symbol(): Symbol { return this.ast.data.symbol; } /** @internal */ set symbol(value: Symbol) { this.ast.data.symbol = value; } @@ -5806,7 +5586,7 @@ export class NotEmittedTypeElement extends Node implements Expression { declare _expressionBrand: any; - declare readonly ast: AstCommaListExpression; + // declare readonly ast: AstCommaListExpression; get elements(): NodeArray { return this.ast.data.elements.nodes; } @@ -5820,7 +5600,7 @@ export class SyntheticReferenceExpression extends Node implements Statement, JSDocContainer { declare _statementBrand: any; declare _jsdocContainerBrand: any; - declare readonly ast: AstEmptyStatement; + // declare readonly ast: AstEmptyStatement; /** @internal */ get jsDoc(): JSDocArray | undefined { return this.ast.data.jsDoc; } /** @internal */ set jsDoc(value: JSDocArray | undefined) { this.ast.data.jsDoc = value; } @@ -5843,7 +5623,7 @@ export class DebuggerStatement extends Node | undefined { return this.ast.data.modifiers?.nodes; } @@ -5888,7 +5668,7 @@ export class Block extends Node implements State declare _statementBrand: any; declare _jsdocContainerBrand: any; declare _localsContainerBrand: any; - declare readonly ast: AstBlock; + // declare readonly ast: AstBlock; get statements(): NodeArray { return this.ast.data.statements.nodes; } @@ -5908,7 +5688,7 @@ export class VariableStatement extends Node | undefined { return this.ast.data.modifiers?.nodes; } get declarationList(): VariableDeclarationList { return this.ast.data.declarationList.node; } @@ -5926,7 +5706,7 @@ export class ExpressionStatement extends Node implements LocalsContainer { declare _localsContainerBrand: any; - declare readonly ast: AstCaseBlock; + // declare readonly ast: AstCaseBlock; override get parent() { return super.parent as SwitchStatement; } @@ -6199,7 +5979,7 @@ export class CaseBlock extends Node impl // dprint-ignore export class CaseClause extends Node implements JSDocContainer { declare _jsdocContainerBrand: any; - declare readonly ast: AstCaseClause; + // declare readonly ast: AstCaseClause; override get parent() { return super.parent as CaseBlock; } @@ -6217,7 +5997,7 @@ export class CaseClause extends Node i // dprint-ignore export class DefaultClause extends Node { - declare readonly ast: AstDefaultClause; + // declare readonly ast: AstDefaultClause; override get parent() { return super.parent as CaseBlock; } @@ -6238,7 +6018,7 @@ export class LabeledStatement extends Node implements LocalsContainer { declare _localsContainerBrand: any; - declare readonly ast: AstCatchClause; + // declare readonly ast: AstCatchClause; override get parent() { return super.parent as TryStatement; } @@ -6325,7 +6105,7 @@ export type DeclarationWithTypeParameterChildren = | JSDocTemplateTag; export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { - readonly ast: AstNode; + // readonly ast: AstNode; readonly kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; readonly name?: Identifier | undefined; readonly typeParameters?: NodeArray | undefined; @@ -6338,7 +6118,7 @@ export class ClassDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } get name(): Identifier | undefined { return this.ast.data.name?.node; } @@ -6369,7 +6149,7 @@ export class ClassExpression extends Node | undefined { return this.ast.data.modifiers?.nodes; } /** May be undefined in `export default class { ... }`. */ @@ -6397,7 +6177,7 @@ export type ClassLikeDeclaration = export interface ClassElement extends Declaration { _classElementBrand: any; - readonly ast: AstClassElement; + // readonly ast: AstClassElement; // TODO(rbuckton): remove this? readonly name?: PropertyName | undefined; @@ -6405,7 +6185,7 @@ export interface ClassElement extends Declaration { export interface TypeElement extends Declaration { _typeElementBrand: any; - readonly ast: AstTypeElement; + // readonly ast: AstTypeElement; // TODO(rbuckton): remove these? readonly name?: PropertyName | undefined; @@ -6417,7 +6197,7 @@ export class InterfaceDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } get name(): Identifier { return this.ast.data.name.node; } @@ -6440,7 +6220,7 @@ export class InterfaceDeclaration extends Node { - declare readonly ast: AstHeritageClause; + // declare readonly ast: AstHeritageClause; override get parent() { return super.parent as InterfaceDeclaration | ClassLikeDeclaration; } @@ -6458,7 +6238,7 @@ export class TypeAliasDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } get name(): Identifier { return this.ast.data.name.node; } @@ -6485,7 +6265,7 @@ export class TypeAliasDeclaration extends Node implements NamedDeclaration, JSDocContainer { declare _declarationBrand: any; declare _jsdocContainerBrand: any; - declare readonly ast: AstEnumMember; + // declare readonly ast: AstEnumMember; override get parent() { return super.parent as EnumDeclaration; } @@ -6508,7 +6288,7 @@ export class EnumDeclaration extends Node | undefined { return this.ast.data.modifiers?.nodes; } get name(): Identifier { return this.ast.data.name.node; } @@ -6545,7 +6325,7 @@ export class ModuleDeclaration extends Node implements Statement, JSDocContainer { declare _statementBrand: any; declare _jsdocContainerBrand: any; - declare readonly ast: AstModuleBlock; + // declare readonly ast: AstModuleBlock; override get parent() { return super.parent as ModuleDeclaration; } @@ -6622,7 +6402,7 @@ export class ImportEqualsDeclaration extends Node { - declare readonly ast: AstExternalModuleReference; + // declare readonly ast: AstExternalModuleReference; override get parent() { return super.parent as ImportEqualsDeclaration; } @@ -6667,7 +6447,7 @@ export class ImportDeclaration extends Node implements NamedDeclaration { declare _declarationBrand: any; - declare readonly ast: AstImportClause; + // declare readonly ast: AstImportClause; override get parent() { return super.parent as ImportDeclaration | JSDocImportTag; } @@ -6741,7 +6521,7 @@ export type ImportAttributeName = Identifier | StringLiteral; // dprint-ignore export class ImportAttribute extends Node { - declare readonly ast: AstImportAttribute; + // declare readonly ast: AstImportAttribute; override get parent() { return super.parent as ImportAttributes; } @@ -6755,7 +6535,7 @@ export class ImportAttribute extends Node { - declare readonly ast: AstImportAttributes; + // declare readonly ast: AstImportAttributes; override get parent() { return super.parent as ImportDeclaration | ExportDeclaration; } @@ -6773,7 +6553,7 @@ export class ImportAttributes extends Node implements NamedDeclaration { declare _declarationBrand: any; - declare readonly ast: AstNamespaceImport; + // declare readonly ast: AstNamespaceImport; override get parent() { return super.parent as ImportClause; } @@ -6790,7 +6570,7 @@ export class NamespaceImport extends Node implements NamedDeclaration { declare _declarationBrand: any; - declare readonly ast: AstNamespaceExport; + // declare readonly ast: AstNamespaceExport; override get parent() { return super.parent as ExportDeclaration; } @@ -6809,7 +6589,7 @@ export class NamespaceExportDeclaration extends Node { - declare readonly ast: AstNamedImports; + // declare readonly ast: AstNamedImports; override get parent() { return super.parent as ImportClause; } @@ -6870,7 +6650,7 @@ export class NamedImports extends Node { - declare readonly ast: AstNamedExports; + // declare readonly ast: AstNamedExports; override get parent() { return super.parent as ExportDeclaration; } @@ -6885,7 +6665,7 @@ export type NamedImportsOrExports = NamedImports | NamedExports; // dprint-ignore export class ImportSpecifier extends Node implements NamedDeclaration { declare _declarationBrand: any; - declare readonly ast: AstImportSpecifier; + // declare readonly ast: AstImportSpecifier; override get parent() { return super.parent as NamedImports; } @@ -6913,7 +6693,7 @@ export class ImportSpecifier extends Node implements NamedDeclaration, JSDocContainer { declare _declarationBrand: any; declare _jsdocContainerBrand: any; - declare readonly ast: AstExportSpecifier; + // declare readonly ast: AstExportSpecifier; override get parent() { return super.parent as NamedExports; } @@ -6976,7 +6756,7 @@ export class ExportAssignment extends Node implements TypeNode { declare _typeNodeBrand: any; - declare readonly ast: AstJSDocTypeExpression; + // declare readonly ast: AstJSDocTypeExpression; get type(): TypeNode { return this.ast.data.type.node; } @@ -7033,7 +6813,7 @@ export class JSDocTypeExpression extends Node { - declare readonly ast: AstJSDocNameReference; + // declare readonly ast: AstJSDocNameReference; get name(): EntityName | JSDocMemberName { return this.ast.data.name.node; } @@ -7044,7 +6824,7 @@ export class JSDocNameReference extends Node { - declare readonly ast: AstJSDocMemberName; + // declare readonly ast: AstJSDocMemberName; get left(): EntityName | JSDocMemberName { return this.ast.data.left.node; } get right(): Identifier { return this.ast.data.right.node; } @@ -7061,21 +6841,21 @@ export interface JSDocType extends TypeNode { export class JSDocAllType extends Node implements JSDocType { declare _jsDocTypeBrand: any; declare _typeNodeBrand: any; - declare readonly ast: AstJSDocAllType; + // declare readonly ast: AstJSDocAllType; } // dprint-ignore export class JSDocUnknownType extends Node implements JSDocType { declare _jsDocTypeBrand: any; declare _typeNodeBrand: any; - declare readonly ast: AstJSDocUnknownType; + // declare readonly ast: AstJSDocUnknownType; } // dprint-ignore export class JSDocNonNullableType extends Node implements JSDocType { declare _jsDocTypeBrand: any; declare _typeNodeBrand: any; - declare readonly ast: AstJSDocNonNullableType; + // declare readonly ast: AstJSDocNonNullableType; get type(): TypeNode { return this.ast.data.type.node; } get postfix(): boolean { return this.ast.data.postfix; } @@ -7088,7 +6868,7 @@ export class JSDocNonNullableType extends Node implements JSDocType { declare _jsDocTypeBrand: any; declare _typeNodeBrand: any; - declare readonly ast: AstJSDocNullableType; + // declare readonly ast: AstJSDocNullableType; get type(): TypeNode { return this.ast.data.type.node; } get postfix(): boolean { return this.ast.data.postfix; } @@ -7101,7 +6881,7 @@ export class JSDocNullableType extends Node implements JSDocType { declare _jsDocTypeBrand: any; declare _typeNodeBrand: any; - declare readonly ast: AstJSDocOptionalType; + // declare readonly ast: AstJSDocOptionalType; get type(): TypeNode { return this.ast.data.type.node; } @@ -7116,7 +6896,7 @@ export class JSDocFunctionType extends Node | undefined { return this.ast.data.typeParameters?.nodes; } get parameters(): NodeArray { return this.ast.data.parameters.nodes; } @@ -7143,7 +6923,7 @@ export class JSDocFunctionType extends Node implements JSDocType { declare _jsDocTypeBrand: any; declare _typeNodeBrand: any; - declare readonly ast: AstJSDocVariadicType; + // declare readonly ast: AstJSDocVariadicType; get type(): TypeNode { return this.ast.data.type.node; } @@ -7154,7 +6934,7 @@ export class JSDocVariadicType extends Node implements JSDocType { declare _jsDocTypeBrand: any; declare _typeNodeBrand: any; - declare readonly ast: AstJSDocNamepathType; + // declare readonly ast: AstJSDocNamepathType; get type(): TypeNode { return this.ast.data.type.node; } @@ -7169,7 +6949,7 @@ export type JSDocTypeReferencingNode = // dprint-ignore export class JSDoc extends Node { - declare readonly ast: AstJSDoc; + // declare readonly ast: AstJSDoc; override get parent() { return super.parent as HasJSDoc; } @@ -7187,7 +6967,7 @@ export class JSDoc extends Node { // TODO(rbuckton): Move after JSDocText // dprint-ignore export class JSDocTag extends Node { - declare readonly ast: AstBaseJSDocTag; + // declare readonly ast: AstBaseJSDocTag; override get parent() { return super.parent as JSDoc | JSDocTypeLiteral; } @@ -7204,7 +6984,7 @@ export class JSDocTag { - declare readonly ast: AstJSDocLink; + // declare readonly ast: AstJSDocLink; get name(): EntityName | JSDocMemberName | undefined { return this.ast.data.name?.node; } get text(): string { return this.ast.data.text; } @@ -7215,7 +6995,7 @@ export class JSDocLink extends Node { // dprint-ignore export class JSDocLinkCode extends Node { - declare readonly ast: AstJSDocLinkCode; + // declare readonly ast: AstJSDocLinkCode; get name(): EntityName | JSDocMemberName | undefined { return this.ast.data.name?.node; } get text(): string { return this.ast.data.text; } @@ -7226,7 +7006,7 @@ export class JSDocLinkCode extends Node { - declare readonly ast: AstJSDocLinkPlain; + // declare readonly ast: AstJSDocLinkPlain; get name(): EntityName | JSDocMemberName | undefined { return this.ast.data.name?.node; } get text(): string { return this.ast.data.text; } @@ -7239,7 +7019,7 @@ export type JSDocComment = JSDocText | JSDocLink | JSDocLinkCode | JSDocLinkPlai // dprint-ignore export class JSDocText extends Node { - declare readonly ast: AstJSDocText; + // declare readonly ast: AstJSDocText; get text(): string { return this.ast.data.text; } @@ -7248,11 +7028,11 @@ export class JSDocText extends Node { // dprint-ignore export class JSDocUnknownTag extends JSDocTag { - declare readonly ast: AstJSDocUnknownTag; + // declare readonly ast: AstJSDocUnknownTag; } export interface JSDocClassReference extends ExpressionWithTypeArguments { - readonly ast: AstJSDocClassReference; + // readonly ast: AstJSDocClassReference; readonly data: AstJSDocClassReferenceData; readonly expression: Identifier | PropertyAccessEntityNameExpression; } @@ -7263,7 +7043,7 @@ export interface JSDocClassReference extends ExpressionWithTypeArguments { */ // dprint-ignore export class JSDocAugmentsTag extends JSDocTag { - declare readonly ast: AstJSDocAugmentsTag; + // declare readonly ast: AstJSDocAugmentsTag; get class(): JSDocClassReference { return this.ast.data.class.node; } @@ -7272,7 +7052,7 @@ export class JSDocAugmentsTag extends JSDocTag { - declare readonly ast: AstJSDocImplementsTag; + // declare readonly ast: AstJSDocImplementsTag; get class(): JSDocClassReference { return this.ast.data.class.node; } @@ -7281,49 +7061,49 @@ export class JSDocImplementsTag extends JSDocTag { - declare readonly ast: AstJSDocAuthorTag; + // declare readonly ast: AstJSDocAuthorTag; } // dprint-ignore export class JSDocDeprecatedTag extends JSDocTag { - declare readonly ast: AstJSDocDeprecatedTag; + // declare readonly ast: AstJSDocDeprecatedTag; } // dprint-ignore export class JSDocClassTag extends JSDocTag { - declare readonly ast: AstJSDocClassTag; + // declare readonly ast: AstJSDocClassTag; } // dprint-ignore export class JSDocPublicTag extends JSDocTag { - declare readonly ast: AstJSDocPublicTag; + // declare readonly ast: AstJSDocPublicTag; } // dprint-ignore export class JSDocPrivateTag extends JSDocTag { - declare readonly ast: AstJSDocPrivateTag; + // declare readonly ast: AstJSDocPrivateTag; } // dprint-ignore export class JSDocProtectedTag extends JSDocTag { - declare readonly ast: AstJSDocProtectedTag; + // declare readonly ast: AstJSDocProtectedTag; } // dprint-ignore export class JSDocReadonlyTag extends JSDocTag { - declare readonly ast: AstJSDocReadonlyTag; + // declare readonly ast: AstJSDocReadonlyTag; } // dprint-ignore export class JSDocOverrideTag extends JSDocTag { - declare readonly ast: AstJSDocOverrideTag; + // declare readonly ast: AstJSDocOverrideTag; } // dprint-ignore export class JSDocEnumTag extends JSDocTag implements Declaration, LocalsContainer { declare _declarationBrand: any; declare _localsContainerBrand: any; - declare readonly ast: AstJSDocEnumTag; + // declare readonly ast: AstJSDocEnumTag; override get parent() { return super.parent as JSDoc; } @@ -7343,7 +7123,7 @@ export class JSDocEnumTag extends JSDocTag { - declare readonly ast: AstJSDocThisTag; + // declare readonly ast: AstJSDocThisTag; get typeExpression(): JSDocTypeExpression { return this.ast.data.typeExpression.node; } @@ -7352,7 +7132,7 @@ export class JSDocThisTag extends JSDocTag { - declare readonly ast: AstJSDocTemplateTag; + // declare readonly ast: AstJSDocTemplateTag; get constraint(): JSDocTypeExpression | undefined { return this.ast.data.constraint?.node; } get typeParameters(): NodeArray { return this.ast.data.typeParameters.nodes; } @@ -7363,7 +7143,7 @@ export class JSDocTemplateTag extends JSDocTag { - declare readonly ast: AstJSDocSeeTag; + // declare readonly ast: AstJSDocSeeTag; get name(): JSDocNameReference | undefined { return this.ast.data.name?.node; } @@ -7372,7 +7152,7 @@ export class JSDocSeeTag extends JSDocTag { - declare readonly ast: AstJSDocReturnTag; + // declare readonly ast: AstJSDocReturnTag; get typeExpression(): JSDocTypeExpression | undefined { return this.ast.data.typeExpression?.node; } @@ -7381,7 +7161,7 @@ export class JSDocReturnTag extends JSDocTag { - declare readonly ast: AstJSDocTypeTag; + // declare readonly ast: AstJSDocTypeTag; get typeExpression(): JSDocTypeExpression { return this.ast.data.typeExpression.node; } @@ -7392,7 +7172,7 @@ export class JSDocTypeTag extends JSDocTag implements Declaration, LocalsContainer { declare _declarationBrand: any; declare _localsContainerBrand: any; - declare readonly ast: AstJSDocTypedefTag; + // declare readonly ast: AstJSDocTypedefTag; override get parent() { return super.parent as JSDoc; } @@ -7418,7 +7198,7 @@ export class JSDocTypedefTag extends JSDocTag implements Declaration, LocalsContainer { declare _declarationBrand: any; declare _localsContainerBrand: any; - declare readonly ast: AstJSDocCallbackTag; + // declare readonly ast: AstJSDocCallbackTag; override get parent() { return super.parent as JSDoc; } @@ -7442,7 +7222,7 @@ export class JSDocCallbackTag extends JSDocTag { - declare readonly ast: AstJSDocOverloadTag; + // declare readonly ast: AstJSDocOverloadTag; override get parent() { return super.parent as JSDoc; } @@ -7454,7 +7234,7 @@ export class JSDocOverloadTag extends JSDocTag { - declare readonly ast: AstJSDocThrowsTag; + // declare readonly ast: AstJSDocThrowsTag; get typeExpression(): JSDocTypeExpression | undefined { return this.ast.data.typeExpression?.node; } @@ -7469,7 +7249,7 @@ export class JSDocSignature extends Node | undefined { return this.ast.data.typeParameters?.nodes; } get parameters(): NodeArray { return this.ast.data.parameters.nodes; } @@ -7491,7 +7271,7 @@ export class JSDocSignature extends Node implements JSDocPropertyLikeTag, Declaration { declare _declarationBrand: any; - declare readonly ast: AstJSDocPropertyTag; + // declare readonly ast: AstJSDocPropertyTag; override get parent() { return super.parent as JSDoc; } @@ -7528,7 +7308,7 @@ export class JSDocPropertyTag extends JSDocTag implements JSDocPropertyLikeTag { declare _declarationBrand: any; - declare readonly ast: AstJSDocParameterTag; + // declare readonly ast: AstJSDocParameterTag; override get parent() { return super.parent as JSDoc; } @@ -7554,7 +7334,7 @@ export class JSDocTypeLiteral extends Node | undefined { return this.ast.data.jsDocPropertyTags?.nodes; } /** If true, then this type literal represents an *array* of its type. */ @@ -7570,7 +7350,7 @@ export class JSDocTypeLiteral extends Node { - declare readonly ast: AstJSDocSatisfiesTag; + // declare readonly ast: AstJSDocSatisfiesTag; get typeExpression(): JSDocTypeExpression { return this.ast.data.typeExpression.node; } @@ -7584,7 +7364,7 @@ export interface JSDocSatisfiesExpression extends ParenthesizedExpression { // dprint-ignore export class JSDocImportTag extends JSDocTag { - declare readonly ast: AstJSDocImportTag; + // declare readonly ast: AstJSDocImportTag; override get parent() { return super.parent as JSDoc; } @@ -7775,7 +7555,7 @@ export type ResolutionMode = ModuleKind.ESNext | ModuleKind.CommonJS | undefined export class SourceFile extends Node implements Declaration, LocalsContainer, ReadonlyPragmaContext { declare _declarationBrand: any; declare _localsContainerBrand: any; - declare readonly ast: AstSourceFile; + // declare readonly ast: AstSourceFile; get statements(): NodeArray { return this.ast.data.statements.nodes; } get endOfFileToken(): EndOfFileToken { return this.ast.data.endOfFileToken.node; } @@ -8197,7 +7977,7 @@ export const enum CommentDirectiveType { // dprint-ignore export class Bundle extends Node { - declare readonly ast: AstBundle; + // declare readonly ast: AstBundle; get sourceFiles(): readonly SourceFile[] { return this.ast.data.sourceFiles; } @@ -8213,7 +7993,7 @@ export class Bundle extends Node { } export interface JsonSourceFile extends SourceFile { - readonly ast: AstJsonSourceFile; + // readonly ast: AstJsonSourceFile; readonly data: AstJsonSourceFileData; readonly statements: NodeArray; } @@ -8224,7 +8004,7 @@ export interface TsConfigSourceFile extends JsonSourceFile { } export interface JsonMinusNumericLiteral extends PrefixUnaryExpression { - readonly ast: AstJsonMinusNumericLiteral; + // readonly ast: AstJsonMinusNumericLiteral; readonly data: AstJsonMinusNumericLiteralData; readonly operator: SyntaxKind.MinusToken; readonly operand: NumericLiteral; @@ -8240,7 +8020,7 @@ export type JsonObjectExpression = | NullLiteral; export interface JsonObjectExpressionStatement extends ExpressionStatement { - readonly ast: AstJsonObjectExpressionStatement; + // readonly ast: AstJsonObjectExpressionStatement; readonly data: AstJsonObjectExpressionStatementData; readonly expression: JsonObjectExpression; } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 524d5225e4de2..6a59d56734b60 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4292,7 +4292,7 @@ declare namespace ts { } export type NodeConstructor = new(ast: AstNode>) => N; export class Node implements ReadonlyTextRange { - readonly ast: AstNode>; + readonly ast: AstNode; constructor(ast: AstNode>); get kind(): K; get data(): T; @@ -4389,7 +4389,10 @@ declare namespace ts { | VariableDeclaration | VariableStatement | WhileStatement - | WithStatement; + | WithStatement + | ModuleBlock + | MissingDeclaration + | NotEmittedStatement; export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType; export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement; export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute; @@ -4414,7 +4417,6 @@ declare namespace ts { } export class EndOfFileToken extends Token implements JSDocContainer { _jsdocContainerBrand: any; - readonly ast: AstEndOfFileToken; } export interface PunctuationToken extends Token { } @@ -4462,7 +4464,6 @@ declare namespace ts { export type ClassMemberModifier = AccessibilityModifier | ReadonlyKeyword | StaticKeyword | AccessorKeyword; export type ModifiersArray = NodeArray; export interface KeywordExpression extends PrimaryExpression, KeywordToken { - readonly ast: AstKeywordExpression; readonly kind: TKind; } export enum GeneratedIdentifierFlags { @@ -4482,7 +4483,6 @@ declare namespace ts { _declarationBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstIdentifier; /** * Prefer to use {@link text}. * Text of identifier, but if the identifier begins with two underscores, this will begin with three. @@ -4492,7 +4492,6 @@ declare namespace ts { } export class QualifiedName extends Node implements FlowContainer { _flowContainerBrand: any; - readonly ast: AstQualifiedName; get left(): EntityName; get right(): Identifier; } @@ -4502,17 +4501,14 @@ declare namespace ts { export type DeclarationName = PropertyName | JsxAttributeName | StringLiteralLike | ElementAccessExpression | BindingPattern | EntityNameExpression; export interface Declaration extends Node { _declarationBrand: any; - readonly ast: AstDeclaration; } export interface NamedDeclaration extends Declaration { readonly name?: DeclarationName | undefined; } export interface DeclarationStatement extends NamedDeclaration, Statement { - readonly ast: AstNode; readonly name?: Identifier | StringLiteral | NumericLiteral | undefined; } export class ComputedPropertyName extends Node { - readonly ast: AstComputedPropertyName; get parent(): Declaration; get expression(): Expression; } @@ -4523,19 +4519,16 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstPrivateIdentifier; get escapedText(): __String; get text(): string; } export class Decorator extends Node { - readonly ast: AstDecorator; get parent(): Declaration; get expression(): LeftHandSideExpression; } export class TypeParameterDeclaration extends Node implements Declaration, JSDocContainer { _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstTypeParameterDeclaration; get parent(): DeclarationWithTypeParameterChildren | InferTypeNode; get modifiers(): NodeArray | undefined; get name(): Identifier; @@ -4546,7 +4539,6 @@ declare namespace ts { get default(): TypeNode | undefined; } export interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { - readonly ast: AstNode; readonly kind: SignatureDeclaration["kind"]; readonly name?: PropertyName | undefined; readonly typeParameters?: NodeArray | undefined; @@ -4560,7 +4552,6 @@ declare namespace ts { _jsdocContainerBrand: any; _typeElementBrand: any; _localsContainerBrand: any; - readonly ast: AstCallSignatureDeclaration; get typeParameters(): NodeArray | undefined; get parameters(): NodeArray; get type(): TypeNode | undefined; @@ -4571,7 +4562,6 @@ declare namespace ts { _jsdocContainerBrand: any; _typeElementBrand: any; _localsContainerBrand: any; - readonly ast: AstConstructSignatureDeclaration; get typeParameters(): NodeArray | undefined; get parameters(): NodeArray; get type(): TypeNode | undefined; @@ -4580,7 +4570,6 @@ declare namespace ts { export class VariableDeclaration extends Node implements Declaration, JSDocContainer { _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstVariableDeclaration; get parent(): VariableDeclarationList | CatchClause; /** * Declared variable name @@ -4600,14 +4589,12 @@ declare namespace ts { get initializer(): Expression | undefined; } export class VariableDeclarationList extends Node { - readonly ast: AstVariableDeclarationList; get parent(): VariableStatement | ForStatement | ForOfStatement | ForInStatement; get declarations(): NodeArray; } export class ParameterDeclaration extends Node implements Declaration, JSDocContainer { _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstParameterDeclaration; get parent(): SignatureDeclaration; get modifiers(): NodeArray | undefined; get dotDotDotToken(): DotDotDotToken | undefined; @@ -4619,7 +4606,6 @@ declare namespace ts { export class BindingElement extends Node implements Declaration, FlowContainer { _declarationBrand: any; _flowContainerBrand: any; - readonly ast: AstBindingElement; get parent(): BindingPattern; /** * Binding property name (in object binding pattern) @@ -4642,7 +4628,6 @@ declare namespace ts { _typeElementBrand: any; _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstPropertySignature; get parent(): TypeLiteralNode | InterfaceDeclaration; get modifiers(): NodeArray | undefined; /** @@ -4662,7 +4647,6 @@ declare namespace ts { _classElementBrand: any; _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstPropertyDeclaration; get parent(): ClassLikeDeclaration; get modifiers(): NodeArray | undefined; get name(): PropertyName; @@ -4682,7 +4666,6 @@ declare namespace ts { } export interface ObjectLiteralElement extends NamedDeclaration { _objectLiteralBrand: any; - readonly ast: AstObjectLiteralElement; readonly name?: PropertyName | undefined; } /** Unlike ObjectLiteralElement, excludes JSXAttribute and JSXSpreadAttribute. */ @@ -4691,7 +4674,6 @@ declare namespace ts { _objectLiteralBrand: any; _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstPropertyAssignment; get parent(): ObjectLiteralExpression; get modifiers(): NodeArray | undefined; get name(): PropertyName; @@ -4703,7 +4685,6 @@ declare namespace ts { _objectLiteralBrand: any; _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstShorthandPropertyAssignment; get parent(): ObjectLiteralExpression; get modifiers(): NodeArray | undefined; get name(): Identifier; @@ -4716,18 +4697,15 @@ declare namespace ts { _objectLiteralBrand: any; _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstSpreadAssignment; get parent(): ObjectLiteralExpression; get expression(): Expression; } export type VariableLikeDeclaration = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | PropertySignature | JsxAttribute | ShorthandPropertyAssignment | EnumMember | JSDocPropertyTag | JSDocParameterTag; export class ObjectBindingPattern extends Node { - readonly ast: AstObjectBindingPattern; get parent(): VariableDeclaration | ParameterDeclaration | BindingElement; get elements(): NodeArray; } export class ArrayBindingPattern extends Node { - readonly ast: AstArrayBindingPattern; get parent(): VariableDeclaration | ParameterDeclaration | BindingElement; get elements(): NodeArray; } @@ -4758,7 +4736,6 @@ declare namespace ts { _jsdocContainerBrand: any; _statementBrand: any; _localsContainerBrand: any; - readonly ast: AstFunctionDeclaration; get modifiers(): NodeArray | undefined; get asteriskToken(): AsteriskToken | undefined; get name(): Identifier | undefined; @@ -4773,7 +4750,6 @@ declare namespace ts { _jsdocContainerBrand: any; _typeElementBrand: any; _localsContainerBrand: any; - readonly ast: AstMethodSignature; get parent(): TypeLiteralNode | InterfaceDeclaration; get modifiers(): NodeArray | undefined; get name(): PropertyName; @@ -4791,7 +4767,6 @@ declare namespace ts { _objectLiteralBrand: any; _localsContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstMethodDeclaration; get parent(): ClassLikeDeclaration | ObjectLiteralExpression; get modifiers(): NodeArray | undefined; get asteriskToken(): AsteriskToken | undefined; @@ -4809,7 +4784,6 @@ declare namespace ts { _jsdocContainerBrand: any; _classElementBrand: any; _localsContainerBrand: any; - readonly ast: AstConstructorDeclaration; get parent(): ClassLikeDeclaration; get modifiers(): NodeArray | undefined; get body(): Block | undefined; @@ -4822,7 +4796,6 @@ declare namespace ts { _jsdocContainerBrand: any; symbol: never; localSymbol: never; - readonly ast: AstSemicolonClassElement; get parent(): ClassLikeDeclaration; } export class GetAccessorDeclaration extends Node implements FunctionLikeDeclarationBase, ClassElement, TypeElement, ObjectLiteralElement, JSDocContainer, LocalsContainer, FlowContainer { @@ -4835,7 +4808,6 @@ declare namespace ts { _objectLiteralBrand: any; _localsContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstGetAccessorDeclaration; get parent(): ClassLikeDeclaration | ObjectLiteralExpression | InterfaceDeclaration | TypeLiteralNode; get modifiers(): NodeArray | undefined; get name(): PropertyName; @@ -4853,7 +4825,6 @@ declare namespace ts { _objectLiteralBrand: any; _localsContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstSetAccessorDeclaration; get parent(): ClassLikeDeclaration | ObjectLiteralExpression | InterfaceDeclaration | TypeLiteralNode; get modifiers(): NodeArray | undefined; get name(): PropertyName; @@ -4867,7 +4838,6 @@ declare namespace ts { _classElementBrand: any; _typeElementBrand: any; _localsContainerBrand: any; - readonly ast: AstIndexSignatureDeclaration; get parent(): ObjectTypeDeclaration; get modifiers(): NodeArray | undefined; get parameters(): NodeArray; @@ -4879,28 +4849,23 @@ declare namespace ts { _declarationBrand: any; _jsdocContainerBrand: any; _localsContainerBrand: any; - readonly ast: AstClassStaticBlockDeclaration; get parent(): ClassLikeDeclaration; get body(): Block; } export interface TypeNode extends Node { _typeNodeBrand: any; - readonly ast: AstTypeNode; } export interface KeywordTypeNode extends KeywordToken, TypeNode { - readonly ast: AstKeywordTypeNode; readonly kind: TKind; } /** @deprecated */ export class ImportTypeAssertionContainer extends Node { - readonly ast: AstImportTypeAssertionContainer; get parent(): ImportTypeNode; /** @deprecated */ get assertClause(): ImportAttributes; } export class ImportTypeNode extends Node implements TypeNode, NodeWithTypeArguments { _typeNodeBrand: any; - readonly ast: AstImportTypeNode; get isTypeOf(): boolean; get argument(): TypeNode; get attributes(): ImportAttributes | undefined; @@ -4911,11 +4876,9 @@ declare namespace ts { } export class ThisTypeNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstThisTypeNode; } export type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; export interface FunctionOrConstructorTypeNodeBase extends TypeNode, SignatureDeclarationBase { - readonly ast: AstNode; readonly kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType; readonly type: TypeNode; } @@ -4925,13 +4888,11 @@ declare namespace ts { _declarationBrand: any; _jsdocContainerBrand: any; _localsContainerBrand: any; - readonly ast: AstFunctionTypeNode; get typeParameters(): NodeArray | undefined; get parameters(): NodeArray; get type(): TypeNode; } export class ConstructorTypeNode extends Node implements FunctionOrConstructorTypeNodeBase, LocalsContainer { - readonly ast: AstConstructorTypeNode; _signatureDeclarationBrand: any; _typeNodeBrand: any; _declarationBrand: any; @@ -4948,13 +4909,11 @@ declare namespace ts { export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; export class TypeReferenceNode extends Node implements NodeWithTypeArguments { _typeNodeBrand: any; - readonly ast: AstTypeReferenceNode; get typeName(): Identifier | QualifiedName; get typeArguments(): NodeArray | undefined; } export class TypePredicateNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstTypePredicateNode; get parent(): SignatureDeclaration | JSDocTypeExpression; get assertsModifier(): AssertsKeyword | undefined; get parameterName(): Identifier | ThisTypeNode; @@ -4962,31 +4921,26 @@ declare namespace ts { } export class TypeQueryNode extends Node implements NodeWithTypeArguments { _typeNodeBrand: any; - readonly ast: AstTypeQueryNode; get exprName(): Identifier | QualifiedName; get typeArguments(): NodeArray | undefined; } export class TypeLiteralNode extends Node implements TypeNode, Declaration { _typeNodeBrand: any; _declarationBrand: any; - readonly ast: AstTypeLiteralNode; get members(): NodeArray; } export class ArrayTypeNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstArrayTypeNode; get elementType(): TypeNode; } export class TupleTypeNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstTupleTypeNode; get elements(): NodeArray; } export class NamedTupleMember extends Node implements TypeNode, Declaration, JSDocContainer { _typeNodeBrand: any; _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstNamedTupleMember; get dotDotDotToken(): DotDotDotToken | undefined; get name(): Identifier; get questionToken(): QuestionToken | undefined; @@ -4994,29 +4948,24 @@ declare namespace ts { } export class OptionalTypeNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstOptionalTypeNode; get type(): TypeNode; } export class RestTypeNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstRestTypeNode; get type(): TypeNode; } export type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; export class UnionTypeNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstUnionTypeNode; get types(): NodeArray; } export class IntersectionTypeNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstIntersectionTypeNode; get types(): NodeArray; } export class ConditionalTypeNode extends Node implements TypeNode, LocalsContainer { _typeNodeBrand: any; _localsContainerBrand: any; - readonly ast: AstConditionalTypeNode; get checkType(): TypeNode; get extendsType(): TypeNode; get trueType(): TypeNode; @@ -5024,23 +4973,19 @@ declare namespace ts { } export class InferTypeNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstInferTypeNode; get typeParameter(): TypeParameterDeclaration; } export class ParenthesizedTypeNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstParenthesizedTypeNode; get type(): TypeNode; } export class TypeOperatorNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstTypeOperatorNode; get operator(): SyntaxKind.KeyOfKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.UniqueKeyword; get type(): TypeNode; } export class IndexedAccessTypeNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstIndexedAccessTypeNode; get objectType(): TypeNode; get indexType(): TypeNode; } @@ -5048,7 +4993,6 @@ declare namespace ts { _typeNodeBrand: any; _declarationBrand: any; _localsContainerBrand: any; - readonly ast: AstMappedTypeNode; get readonlyToken(): PlusToken | MinusToken | ReadonlyKeyword | undefined; get typeParameter(): TypeParameterDeclaration; get nameType(): TypeNode | undefined; @@ -5058,7 +5002,6 @@ declare namespace ts { } export class LiteralTypeNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstLiteralTypeNode; get literal(): NullLiteral | TrueLiteral | FalseLiteral | PrefixUnaryExpression | LiteralExpression; } export class StringLiteral extends Token implements LiteralExpression, StringLiteralLikeNode, Declaration { @@ -5070,7 +5013,6 @@ declare namespace ts { _unaryExpressionBrand: any; _expressionBrand: any; _declarationBrand: any; - readonly ast: AstStringLiteral; get text(): string; get isUnterminated(): boolean; get hasExtendedUnicodeEscape(): boolean; @@ -5079,49 +5021,41 @@ declare namespace ts { export type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral | JsxNamespacedName | BigIntLiteral; export class TemplateLiteralTypeNode extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstTemplateLiteralTypeNode; get head(): TemplateHead; get templateSpans(): NodeArray; } export class TemplateLiteralTypeSpan extends Node { _typeNodeBrand: any; - readonly ast: AstTemplateLiteralTypeSpan; get parent(): TemplateLiteralTypeNode; get type(): TypeNode; get literal(): TemplateMiddle | TemplateTail; } export interface Expression extends Node { _expressionBrand: any; - readonly ast: AstExpression; } export class OmittedExpression extends Node implements Expression { _expressionBrand: any; - readonly ast: AstOmittedExpression; } export class PartiallyEmittedExpression extends Node implements LeftHandSideExpression { _leftHandSideExpressionBrand: any; _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstPartiallyEmittedExpression; get expression(): Expression; } export interface UnaryExpression extends Expression { _unaryExpressionBrand: any; - readonly ast: AstUnaryExpression; } /** @deprecated use UpdateExpression instead */ export type IncrementExpression = UpdateExpression; export interface UpdateExpression extends UnaryExpression { _updateExpressionBrand: any; - readonly ast: AstUpdateExpression; } export type PrefixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.TildeToken | SyntaxKind.ExclamationToken; export class PrefixUnaryExpression extends Node implements UpdateExpression { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstPrefixUnaryExpression; get operator(): PrefixUnaryOperator; get operand(): UnaryExpression; } @@ -5130,21 +5064,17 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstPostfixUnaryExpression; get operand(): LeftHandSideExpression; get operator(): PostfixUnaryOperator; } export interface LeftHandSideExpression extends UpdateExpression { _leftHandSideExpressionBrand: any; - readonly ast: AstLeftHandSideExpression; } export interface MemberExpression extends LeftHandSideExpression { _memberExpressionBrand: any; - readonly ast: AstMemberExpression; } export interface PrimaryExpression extends MemberExpression { _primaryExpressionBrand: any; - readonly ast: AstPrimaryExpression; } export class NullLiteral extends Token implements KeywordExpression { _primaryExpressionBrand: any; @@ -5153,7 +5083,6 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstNullLiteral; } export class TrueLiteral extends Token implements KeywordExpression { _primaryExpressionBrand: any; @@ -5162,7 +5091,6 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstTrueLiteral; } export class FalseLiteral extends Token implements KeywordExpression { _primaryExpressionBrand: any; @@ -5171,7 +5099,6 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstFalseLiteral; } export type BooleanLiteral = TrueLiteral | FalseLiteral; export class ThisExpression extends Token implements KeywordExpression, FlowContainer { @@ -5182,7 +5109,6 @@ declare namespace ts { _unaryExpressionBrand: any; _expressionBrand: any; _flowContainerBrand: any; - readonly ast: AstThisExpression; } export class SuperExpression extends Token implements KeywordExpression, FlowContainer { _primaryExpressionBrand: any; @@ -5192,7 +5118,6 @@ declare namespace ts { _unaryExpressionBrand: any; _expressionBrand: any; _flowContainerBrand: any; - readonly ast: AstSuperExpression; } export class ImportExpression extends Token implements KeywordExpression { _primaryExpressionBrand: any; @@ -5201,41 +5126,34 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstImportExpression; } export class DeleteExpression extends Node implements UnaryExpression { _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstDeleteExpression; get expression(): UnaryExpression; } export class TypeOfExpression extends Node implements UnaryExpression { _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstTypeOfExpression; get expression(): UnaryExpression; } export class VoidExpression extends Node implements UnaryExpression { _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstVoidExpression; get expression(): UnaryExpression; } export class AwaitExpression extends Node implements UnaryExpression { _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstAwaitExpression; get expression(): UnaryExpression; } export class YieldExpression extends Node implements Expression { _expressionBrand: any; - readonly ast: AstYieldExpression; get asteriskToken(): AsteriskToken | undefined; get expression(): Expression | undefined; } export class SyntheticExpression extends Node implements Expression { _expressionBrand: any; - readonly ast: AstSyntheticExpression; get isSpread(): boolean; get type(): Type; get tupleNameSource(): ParameterDeclaration | NamedTupleMember | undefined; @@ -5265,7 +5183,6 @@ declare namespace ts { _expressionBrand: any; _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstBinaryExpression; get left(): Expression; get operatorToken(): BinaryOperatorToken; get right(): Expression; @@ -5296,7 +5213,6 @@ declare namespace ts { } export class ConditionalExpression extends Node implements Expression { _expressionBrand: any; - readonly ast: AstConditionalExpression; get condition(): Expression; get questionToken(): QuestionToken; get whenTrue(): Expression; @@ -5318,7 +5234,6 @@ declare namespace ts { _jsdocContainerBrand: any; _localsContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstFunctionExpression; get modifiers(): NodeArray | undefined; get asteriskToken(): AsteriskToken | undefined; get name(): Identifier | undefined; @@ -5335,7 +5250,6 @@ declare namespace ts { _jsdocContainerBrand: any; _localsContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstArrowFunction; get modifiers(): NodeArray | undefined; get equalsGreaterThanToken(): EqualsGreaterThanToken; get typeParameters(): NodeArray | undefined; @@ -5344,24 +5258,20 @@ declare namespace ts { get body(): Block | Expression; } export interface LiteralLikeNode extends Node { - readonly ast: AstLiteralLikeNode; readonly data: AstLiteralLikeNodeData; get text(): string; } export interface StringLiteralLikeNode extends LiteralLikeNode { - readonly ast: AstStringLiteralLikeNode; readonly data: AstStringLiteralLikeNodeData; get isUnterminated(): boolean | undefined; get hasExtendedUnicodeEscape(): boolean | undefined; } export interface TemplateLiteralLikeNode extends StringLiteralLikeNode { - readonly ast: AstTemplateLiteralLikeNode; readonly data: AstTemplateLiteralLikeNodeData; get rawText(): string | undefined; } export interface LiteralExpression extends LiteralLikeNode, PrimaryExpression { _literalExpressionBrand: any; - readonly ast: AstLiteralExpression; readonly data: AstLiteralExpressionData; } export class RegularExpressionLiteral extends Token implements StringLiteralLikeNode { @@ -5372,7 +5282,6 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstRegularExpressionLiteral; get text(): string; get isUnterminated(): boolean | undefined; get hasExtendedUnicodeEscape(): boolean | undefined; @@ -5386,7 +5295,6 @@ declare namespace ts { _unaryExpressionBrand: any; _expressionBrand: any; _declarationBrand: any; - readonly ast: AstNoSubstitutionTemplateLiteral; get text(): string; get rawText(): string | undefined; get isUnterminated(): boolean | undefined; @@ -5409,7 +5317,6 @@ declare namespace ts { _unaryExpressionBrand: any; _expressionBrand: any; _declarationBrand: any; - readonly ast: AstNumericLiteral; get text(): string; } export class BigIntLiteral extends Token implements LiteralExpression, LiteralLikeNode { @@ -5420,12 +5327,10 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstBigIntLiteral; get text(): string; } export type LiteralToken = NumericLiteral | BigIntLiteral | StringLiteral | JsxText | RegularExpressionLiteral | NoSubstitutionTemplateLiteral; export class TemplateHead extends Token implements TemplateLiteralLikeNode { - readonly ast: AstTemplateHead; get parent(): TemplateExpression | TemplateLiteralTypeNode; get text(): string; get isUnterminated(): boolean | undefined; @@ -5433,7 +5338,6 @@ declare namespace ts { get rawText(): string | undefined; } export class TemplateMiddle extends Token implements TemplateLiteralLikeNode { - readonly ast: AstTemplateMiddle; get parent(): TemplateSpan | TemplateLiteralTypeSpan; get text(): string; get isUnterminated(): boolean | undefined; @@ -5441,7 +5345,6 @@ declare namespace ts { get rawText(): string | undefined; } export class TemplateTail extends Token implements TemplateLiteralLikeNode { - readonly ast: AstTemplateTail; get parent(): TemplateSpan | TemplateLiteralTypeSpan; get text(): string; get isUnterminated(): boolean | undefined; @@ -5457,13 +5360,11 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstTemplateExpression; get head(): TemplateHead; get templateSpans(): NodeArray; } export type TemplateLiteral = TemplateExpression | NoSubstitutionTemplateLiteral; export class TemplateSpan extends Node { - readonly ast: AstTemplateSpan; get parent(): TemplateExpression; get expression(): Expression; get literal(): TemplateMiddle | TemplateTail; @@ -5476,7 +5377,6 @@ declare namespace ts { _unaryExpressionBrand: any; _expressionBrand: any; _jsdocContainerBrand: any; - readonly ast: AstParenthesizedExpression; get expression(): Expression; } export class ArrayLiteralExpression extends Node implements PrimaryExpression { @@ -5486,12 +5386,10 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstArrayLiteralExpression; get elements(): NodeArray; } export class SpreadElement extends Node implements Expression { _expressionBrand: any; - readonly ast: AstSpreadElement; get parent(): ArrayLiteralExpression | CallExpression | NewExpression; get expression(): Expression; } @@ -5502,7 +5400,6 @@ declare namespace ts { * ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.) */ export interface ObjectLiteralExpressionBase extends PrimaryExpression, Declaration { - readonly ast: AstNode; readonly properties: NodeArray; } export class ObjectLiteralExpression extends Node implements ObjectLiteralExpressionBase, JSDocContainer { @@ -5514,7 +5411,6 @@ declare namespace ts { _expressionBrand: any; _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstObjectLiteralExpression; get properties(): NodeArray; } export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression; @@ -5529,30 +5425,37 @@ declare namespace ts { _declarationBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstPropertyAccessExpression; get expression(): LeftHandSideExpression; get questionDotToken(): QuestionDotToken | undefined; get name(): Identifier | PrivateIdentifier; } export interface JsxTagNamePropertyAccess extends PropertyAccessExpression { - readonly ast: AstJsxTagNamePropertyAccess; readonly data: AstJsxTagNamePropertyAccessData; readonly expression: Identifier | ThisExpression | JsxTagNamePropertyAccess; } - export interface PropertyAccessChain extends PropertyAccessExpression { + export type PropertyAccessChain = PropertyAccessExpression & { _optionalChainBrand: any; - readonly ast: AstPropertyAccessChain; readonly name: MemberName; - } - export interface SuperPropertyAccessExpression extends PropertyAccessExpression { + readonly data: { + readonly name: AstMemberName; + }; + }; + export type SuperPropertyAccessExpression = PropertyAccessExpression & { readonly expression: SuperExpression; - } + readonly data: { + readonly expression: AstSuperExpression; + }; + }; /** Brand for a PropertyAccessExpression which, like a QualifiedName, consists of a sequence of identifiers separated by dots. */ - export interface PropertyAccessEntityNameExpression extends PropertyAccessExpression { + export type PropertyAccessEntityNameExpression = PropertyAccessExpression & { _propertyAccessExpressionLikeQualifiedNameBrand?: any; readonly expression: EntityNameExpression; readonly name: Identifier; - } + readonly data: { + readonly expression: AstEntityNameExpression; + readonly name: AstIdentifier; + }; + }; export class ElementAccessExpression extends Node implements MemberExpression, Declaration, JSDocContainer, FlowContainer { _memberExpressionBrand: any; _leftHandSideExpressionBrand: any; @@ -5562,14 +5465,12 @@ declare namespace ts { _declarationBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstElementAccessExpression; get expression(): LeftHandSideExpression; get questionDotToken(): QuestionDotToken | undefined; get argumentExpression(): Expression; } export interface ElementAccessChain extends ElementAccessExpression { _optionalChainBrand: any; - readonly ast: AstElementAccessChain; } export interface SuperElementAccessExpression extends ElementAccessExpression { readonly expression: SuperExpression; @@ -5581,7 +5482,6 @@ declare namespace ts { _unaryExpressionBrand: any; _expressionBrand: any; _declarationBrand: any; - readonly ast: AstCallExpression; get expression(): LeftHandSideExpression; get questionDotToken(): QuestionDotToken | undefined; get typeArguments(): NodeArray | undefined; @@ -5589,7 +5489,6 @@ declare namespace ts { } export interface CallChain extends CallExpression { _optionalChainBrand: any; - readonly ast: AstCallChain; } export type OptionalChain = PropertyAccessChain | ElementAccessChain | CallChain | NonNullChain; export interface SuperCall extends CallExpression { @@ -5605,7 +5504,6 @@ declare namespace ts { _unaryExpressionBrand: any; _expressionBrand: any; _typeNodeBrand: any; - readonly ast: AstExpressionWithTypeArguments; get expression(): LeftHandSideExpression; get typeArguments(): NodeArray | undefined; } @@ -5617,7 +5515,6 @@ declare namespace ts { _unaryExpressionBrand: any; _expressionBrand: any; _declarationBrand: any; - readonly ast: AstNewExpression; get expression(): LeftHandSideExpression; get typeArguments(): NodeArray | undefined; get arguments(): NodeArray | undefined; @@ -5628,7 +5525,6 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstTaggedTemplateExpression; get tag(): LeftHandSideExpression; get typeArguments(): NodeArray | undefined; get template(): NoSubstitutionTemplateLiteral | TemplateExpression; @@ -5636,14 +5532,12 @@ declare namespace ts { export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator | JsxOpeningLikeElement | InstanceofExpression; export class AsExpression extends Node implements Expression { _expressionBrand: any; - readonly ast: AstAsExpression; get expression(): Expression; get type(): TypeNode; } export class TypeAssertionExpression extends Node implements UnaryExpression { _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstTypeAssertion; get type(): TypeNode; get expression(): UnaryExpression; } @@ -5652,7 +5546,6 @@ declare namespace ts { export type AssertionExpression = TypeAssertionExpression | AsExpression; export class SatisfiesExpression extends Node implements Expression { _expressionBrand: any; - readonly ast: AstSatisfiesExpression; get expression(): Expression; get type(): TypeNode; } @@ -5661,12 +5554,10 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstNonNullExpression; get expression(): Expression; } export interface NonNullChain extends NonNullExpression { _optionalChainBrand: any; - readonly ast: AstNonNullChain; } export class MetaProperty extends Node implements PrimaryExpression, FlowContainer { _primaryExpressionBrand: any; @@ -5676,7 +5567,6 @@ declare namespace ts { _unaryExpressionBrand: any; _expressionBrand: any; _flowContainerBrand: any; - readonly ast: AstMetaProperty; get keywordToken(): SyntaxKind.ImportKeyword | SyntaxKind.NewKeyword; get name(): Identifier; } @@ -5687,7 +5577,6 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstJsxElement; get openingElement(): JsxOpeningElement; get children(): NodeArray; get closingElement(): JsxClosingElement; @@ -5704,18 +5593,15 @@ declare namespace ts { _unaryExpressionBrand: any; _expressionBrand: any; _declarationBrand: any; - readonly ast: AstJsxAttributes; get parent(): JsxOpeningLikeElement; get properties(): NodeArray; } export class JsxNamespacedName extends Node { - readonly ast: AstJsxNamespacedName; get name(): Identifier; get namespace(): Identifier; } export class JsxOpeningElement extends Node implements Expression { _expressionBrand: any; - readonly ast: AstJsxOpeningElement; get parent(): JsxElement; get tagName(): JsxTagNameExpression; get typeArguments(): NodeArray | undefined; @@ -5728,7 +5614,6 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstJsxSelfClosingElement; get tagName(): JsxTagNameExpression; get typeArguments(): NodeArray | undefined; get attributes(): JsxAttributes; @@ -5740,23 +5625,19 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstJsxFragment; get openingFragment(): JsxOpeningFragment; get children(): NodeArray; get closingFragment(): JsxClosingFragment; } export class JsxOpeningFragment extends Node implements Expression { _expressionBrand: any; - readonly ast: AstJsxOpeningFragment; get parent(): JsxFragment; } export class JsxClosingFragment extends Node implements Expression { _expressionBrand: any; - readonly ast: AstJsxClosingFragment; get parent(): JsxFragment; } export class JsxAttribute extends Node implements Declaration { - readonly ast: AstJsxAttribute; _declarationBrand: any; get parent(): JsxAttributes; get name(): JsxAttributeName; @@ -5766,24 +5647,20 @@ declare namespace ts { export class JsxSpreadAttribute extends Node implements ObjectLiteralElement { _objectLiteralBrand: any; _declarationBrand: any; - readonly ast: AstJsxSpreadAttribute; get parent(): JsxAttributes; get expression(): Expression; } export class JsxClosingElement extends Node { - readonly ast: AstJsxClosingElement; get parent(): JsxElement; get tagName(): JsxTagNameExpression; } export class JsxExpression extends Node implements Expression { _expressionBrand: any; - readonly ast: AstJsxExpression; get parent(): JsxElement | JsxFragment | JsxAttributeLike; get dotDotDotToken(): DotDotDotToken | undefined; get expression(): Expression | undefined; } export class JsxText extends Token implements LiteralLikeNode { - readonly ast: AstJsxText; get parent(): JsxElement | JsxFragment; get text(): string; get isUnterminated(): boolean | undefined; @@ -5793,36 +5670,30 @@ declare namespace ts { export type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment; export interface Statement extends JSDocContainer { _statementBrand: any; - readonly ast: AstStatement; } export class NotEmittedStatement extends Node implements Statement { _statementBrand: any; _jsdocContainerBrand: any; - readonly ast: AstNotEmittedStatement; } export class NotEmittedTypeElement extends Node implements TypeElement { _typeElementBrand: any; _declarationBrand: any; - readonly ast: AstNotEmittedTypeElement; } /** * A list of comma-separated expressions. This node is only created by transformations. */ export class CommaListExpression extends Node implements Expression { _expressionBrand: any; - readonly ast: AstCommaListExpression; get elements(): NodeArray; } export class EmptyStatement extends Node implements Statement, JSDocContainer { _statementBrand: any; _jsdocContainerBrand: any; - readonly ast: AstEmptyStatement; } export class DebuggerStatement extends Node implements Statement, FlowContainer { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstDebuggerStatement; } export class MissingDeclaration extends Node implements DeclarationStatement { _declarationBrand: any; @@ -5834,7 +5705,6 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstMissingDeclaration; get name(): Identifier | undefined; get modifiers(): NodeArray | undefined; } @@ -5843,14 +5713,12 @@ declare namespace ts { _statementBrand: any; _jsdocContainerBrand: any; _localsContainerBrand: any; - readonly ast: AstBlock; get statements(): NodeArray; } export class VariableStatement extends Node implements Statement, FlowContainer { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstVariableStatement; get modifiers(): NodeArray | undefined; get declarationList(): VariableDeclarationList; } @@ -5858,14 +5726,12 @@ declare namespace ts { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstExpressionStatement; get expression(): Expression; } export class IfStatement extends Node implements Statement, FlowContainer { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstIfStatement; get expression(): Expression; get thenStatement(): Statement; get elseStatement(): Statement | undefined; @@ -5877,7 +5743,6 @@ declare namespace ts { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstDoStatement; get statement(): Statement; get expression(): Expression; } @@ -5885,7 +5750,6 @@ declare namespace ts { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstWhileStatement; get expression(): Expression; get statement(): Statement; } @@ -5895,7 +5759,6 @@ declare namespace ts { _jsdocContainerBrand: any; _localsContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstForStatement; get initializer(): ForInitializer | undefined; get condition(): Expression | undefined; get incrementor(): Expression | undefined; @@ -5907,7 +5770,6 @@ declare namespace ts { _jsdocContainerBrand: any; _localsContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstForInStatement; get initializer(): ForInitializer; get expression(): Expression; get statement(): Statement; @@ -5917,7 +5779,6 @@ declare namespace ts { _jsdocContainerBrand: any; _localsContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstForOfStatement; get awaitModifier(): AwaitKeyword | undefined; get initializer(): ForInitializer; get expression(): Expression; @@ -5927,14 +5788,12 @@ declare namespace ts { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstBreakStatement; get label(): Identifier | undefined; } export class ContinueStatement extends Node implements Statement, FlowContainer { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstContinueStatement; get label(): Identifier | undefined; } export type BreakOrContinueStatement = BreakStatement | ContinueStatement; @@ -5942,14 +5801,12 @@ declare namespace ts { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstReturnStatement; get expression(): Expression | undefined; } export class WithStatement extends Node implements Statement, FlowContainer { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstWithStatement; get expression(): Expression; get statement(): Statement; } @@ -5957,26 +5814,22 @@ declare namespace ts { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstSwitchStatement; get expression(): Expression; get caseBlock(): CaseBlock; get possiblyExhaustive(): boolean | undefined; } export class CaseBlock extends Node implements LocalsContainer { _localsContainerBrand: any; - readonly ast: AstCaseBlock; get parent(): SwitchStatement; get clauses(): NodeArray; } export class CaseClause extends Node implements JSDocContainer { _jsdocContainerBrand: any; - readonly ast: AstCaseClause; get parent(): CaseBlock; get expression(): Expression; get statements(): NodeArray; } export class DefaultClause extends Node { - readonly ast: AstDefaultClause; get parent(): CaseBlock; get statements(): NodeArray; } @@ -5985,7 +5838,6 @@ declare namespace ts { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstLabeledStatement; get label(): Identifier; get statement(): Statement; } @@ -5993,21 +5845,18 @@ declare namespace ts { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstThrowStatement; get expression(): Expression; } export class TryStatement extends Node implements Statement, FlowContainer { _statementBrand: any; _jsdocContainerBrand: any; _flowContainerBrand: any; - readonly ast: AstTryStatement; get tryBlock(): Block; get catchClause(): CatchClause | undefined; get finallyBlock(): Block | undefined; } export class CatchClause extends Node implements LocalsContainer { _localsContainerBrand: any; - readonly ast: AstCatchClause; get parent(): TryStatement; get variableDeclaration(): VariableDeclaration | undefined; get block(): Block; @@ -6016,7 +5865,6 @@ declare namespace ts { export type DeclarationWithTypeParameters = DeclarationWithTypeParameterChildren | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; export type DeclarationWithTypeParameterChildren = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { - readonly ast: AstNode; readonly kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; readonly name?: Identifier | undefined; readonly typeParameters?: NodeArray | undefined; @@ -6027,7 +5875,6 @@ declare namespace ts { _declarationBrand: any; _statementBrand: any; _jsdocContainerBrand: any; - readonly ast: AstClassDeclaration; get modifiers(): NodeArray | undefined; get name(): Identifier | undefined; get typeParameters(): NodeArray | undefined; @@ -6043,7 +5890,6 @@ declare namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; - readonly ast: AstClassExpression; get modifiers(): NodeArray | undefined; /** May be undefined in `export default class { ... }`. */ get name(): Identifier | undefined; @@ -6054,12 +5900,10 @@ declare namespace ts { export type ClassLikeDeclaration = ClassDeclaration | ClassExpression; export interface ClassElement extends Declaration { _classElementBrand: any; - readonly ast: AstClassElement; readonly name?: PropertyName | undefined; } export interface TypeElement extends Declaration { _typeElementBrand: any; - readonly ast: AstTypeElement; readonly name?: PropertyName | undefined; readonly questionToken?: QuestionToken | undefined; } @@ -6067,7 +5911,6 @@ declare namespace ts { _declarationBrand: any; _statementBrand: any; _jsdocContainerBrand: any; - readonly ast: AstInterfaceDeclaration; get modifiers(): NodeArray | undefined; get name(): Identifier; get typeParameters(): NodeArray | undefined; @@ -6075,7 +5918,6 @@ declare namespace ts { get members(): NodeArray; } export class HeritageClause extends Node { - readonly ast: AstHeritageClause; get parent(): InterfaceDeclaration | ClassLikeDeclaration; get token(): SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; get types(): NodeArray; @@ -6085,7 +5927,6 @@ declare namespace ts { _statementBrand: any; _jsdocContainerBrand: any; _localsContainerBrand: any; - readonly ast: AstTypeAliasDeclaration; get modifiers(): NodeArray | undefined; get name(): Identifier; get typeParameters(): NodeArray | undefined; @@ -6094,7 +5935,6 @@ declare namespace ts { export class EnumMember extends Node implements NamedDeclaration, JSDocContainer { _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstEnumMember; get parent(): EnumDeclaration; get name(): PropertyName; get initializer(): Expression | undefined; @@ -6103,7 +5943,6 @@ declare namespace ts { _declarationBrand: any; _statementBrand: any; _jsdocContainerBrand: any; - readonly ast: AstEnumDeclaration; get modifiers(): NodeArray | undefined; get name(): Identifier; get members(): NodeArray; @@ -6115,7 +5954,6 @@ declare namespace ts { _statementBrand: any; _jsdocContainerBrand: any; _localsContainerBrand: any; - readonly ast: AstModuleDeclaration; get parent(): ModuleDeclaration | ModuleBlock | SourceFile; get modifiers(): NodeArray | undefined; get name(): ModuleName; @@ -6123,14 +5961,12 @@ declare namespace ts { } export type NamespaceBody = ModuleBlock | NamespaceDeclaration; export interface NamespaceDeclaration extends ModuleDeclaration { - readonly ast: AstNamespaceDeclaration; readonly data: AstNamespaceDeclarationData; readonly name: Identifier; readonly body: NamespaceBody; } export type JSDocNamespaceBody = Identifier | JSDocNamespaceDeclaration; export interface JSDocNamespaceDeclaration extends ModuleDeclaration { - readonly ast: AstJSDocNamespaceDeclaration; readonly data: AstJSDocNamespaceDeclarationData; readonly name: Identifier; readonly body: JSDocNamespaceBody | undefined; @@ -6138,7 +5974,6 @@ declare namespace ts { export class ModuleBlock extends Node implements Statement, JSDocContainer { _statementBrand: any; _jsdocContainerBrand: any; - readonly ast: AstModuleBlock; get parent(): ModuleDeclaration; get statements(): NodeArray; } @@ -6152,7 +5987,6 @@ declare namespace ts { _declarationBrand: any; _statementBrand: any; _jsdocContainerBrand: any; - readonly ast: AstImportEqualsDeclaration; get parent(): ModuleBlock | SourceFile; get modifiers(): NodeArray | undefined; get name(): Identifier; @@ -6163,7 +5997,6 @@ declare namespace ts { get moduleReference(): ModuleReference; } export class ExternalModuleReference extends Node { - readonly ast: AstExternalModuleReference; get parent(): ImportEqualsDeclaration; get expression(): Expression; } @@ -6171,7 +6004,6 @@ declare namespace ts { _declarationBrand: any; _statementBrand: any; _jsdocContainerBrand: any; - readonly ast: AstImportDeclaration; get parent(): ModuleBlock | SourceFile; get modifiers(): NodeArray | undefined; get importClause(): ImportClause | undefined; @@ -6185,7 +6017,6 @@ declare namespace ts { export type NamedExportBindings = NamespaceExport | NamedExports; export class ImportClause extends Node implements NamedDeclaration { _declarationBrand: any; - readonly ast: AstImportClause; get parent(): ImportDeclaration | JSDocImportTag; get isTypeOnly(): boolean; get name(): Identifier | undefined; @@ -6201,13 +6032,11 @@ declare namespace ts { } export type ImportAttributeName = Identifier | StringLiteral; export class ImportAttribute extends Node { - readonly ast: AstImportAttribute; get parent(): ImportAttributes; get name(): ImportAttributeName; get value(): Expression; } export class ImportAttributes extends Node { - readonly ast: AstImportAttributes; get parent(): ImportDeclaration | ExportDeclaration; get token(): SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword; get elements(): NodeArray; @@ -6215,13 +6044,11 @@ declare namespace ts { } export class NamespaceImport extends Node implements NamedDeclaration { _declarationBrand: any; - readonly ast: AstNamespaceImport; get parent(): ImportClause; get name(): Identifier; } export class NamespaceExport extends Node implements NamedDeclaration { _declarationBrand: any; - readonly ast: AstNamespaceExport; get parent(): ExportDeclaration; get name(): ModuleExportName; } @@ -6229,14 +6056,12 @@ declare namespace ts { _declarationBrand: any; _statementBrand: any; _jsdocContainerBrand: any; - readonly ast: AstNamespaceExportDeclaration; get name(): Identifier; } export class ExportDeclaration extends Node implements DeclarationStatement, JSDocContainer { _declarationBrand: any; _statementBrand: any; _jsdocContainerBrand: any; - readonly ast: AstExportDeclaration; get parent(): SourceFile | ModuleBlock; get modifiers(): NodeArray | undefined; get isTypeOnly(): boolean; @@ -6247,19 +6072,16 @@ declare namespace ts { get attributes(): ImportAttributes | undefined; } export class NamedImports extends Node { - readonly ast: AstNamedImports; get parent(): ImportClause; get elements(): NodeArray; } export class NamedExports extends Node { - readonly ast: AstNamedExports; get parent(): ExportDeclaration; get elements(): NodeArray; } export type NamedImportsOrExports = NamedImports | NamedExports; export class ImportSpecifier extends Node implements NamedDeclaration { _declarationBrand: any; - readonly ast: AstImportSpecifier; get parent(): NamedImports; get isTypeOnly(): boolean; /** @@ -6274,7 +6096,6 @@ declare namespace ts { export class ExportSpecifier extends Node implements NamedDeclaration, JSDocContainer { _declarationBrand: any; _jsdocContainerBrand: any; - readonly ast: AstExportSpecifier; get parent(): NamedExports; get isTypeOnly(): boolean; /** @@ -6342,7 +6163,6 @@ declare namespace ts { _declarationBrand: any; _statementBrand: any; _jsdocContainerBrand: any; - readonly ast: AstExportAssignment; get parent(): SourceFile; get modifiers(): NodeArray | undefined; get isExportEquals(): boolean | undefined; @@ -6369,16 +6189,13 @@ declare namespace ts { } export class JSDocTypeExpression extends Node implements TypeNode { _typeNodeBrand: any; - readonly ast: AstJSDocTypeExpression; get type(): TypeNode; } export class JSDocNameReference extends Node { - readonly ast: AstJSDocNameReference; get name(): EntityName | JSDocMemberName; } /** Class#method reference in JSDoc */ export class JSDocMemberName extends Node { - readonly ast: AstJSDocMemberName; get left(): EntityName | JSDocMemberName; get right(): Identifier; } @@ -6388,31 +6205,26 @@ declare namespace ts { export class JSDocAllType extends Node implements JSDocType { _jsDocTypeBrand: any; _typeNodeBrand: any; - readonly ast: AstJSDocAllType; } export class JSDocUnknownType extends Node implements JSDocType { _jsDocTypeBrand: any; _typeNodeBrand: any; - readonly ast: AstJSDocUnknownType; } export class JSDocNonNullableType extends Node implements JSDocType { _jsDocTypeBrand: any; _typeNodeBrand: any; - readonly ast: AstJSDocNonNullableType; get type(): TypeNode; get postfix(): boolean; } export class JSDocNullableType extends Node implements JSDocType { _jsDocTypeBrand: any; _typeNodeBrand: any; - readonly ast: AstJSDocNullableType; get type(): TypeNode; get postfix(): boolean; } export class JSDocOptionalType extends Node implements JSDocType { _jsDocTypeBrand: any; _typeNodeBrand: any; - readonly ast: AstJSDocOptionalType; get type(): TypeNode; } export class JSDocFunctionType extends Node implements JSDocType, SignatureDeclarationBase, LocalsContainer { @@ -6422,7 +6234,6 @@ declare namespace ts { _declarationBrand: any; _jsdocContainerBrand: any; _localsContainerBrand: any; - readonly ast: AstJSDocFunctionType; get typeParameters(): NodeArray | undefined; get parameters(): NodeArray; get type(): TypeNode | undefined; @@ -6431,53 +6242,43 @@ declare namespace ts { export class JSDocVariadicType extends Node implements JSDocType { _jsDocTypeBrand: any; _typeNodeBrand: any; - readonly ast: AstJSDocVariadicType; get type(): TypeNode; } export class JSDocNamepathType extends Node implements JSDocType { _jsDocTypeBrand: any; _typeNodeBrand: any; - readonly ast: AstJSDocNamepathType; get type(): TypeNode; } export type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; export class JSDoc extends Node { - readonly ast: AstJSDoc; get parent(): HasJSDoc; get tags(): NodeArray | undefined; get comment(): string | NodeArray | undefined; } export class JSDocTag extends Node { - readonly ast: AstBaseJSDocTag; get parent(): JSDoc | JSDocTypeLiteral; get tagName(): Identifier; get comment(): string | NodeArray | undefined; } export class JSDocLink extends Node { - readonly ast: AstJSDocLink; get name(): EntityName | JSDocMemberName | undefined; get text(): string; } export class JSDocLinkCode extends Node { - readonly ast: AstJSDocLinkCode; get name(): EntityName | JSDocMemberName | undefined; get text(): string; } export class JSDocLinkPlain extends Node { - readonly ast: AstJSDocLinkPlain; get name(): EntityName | JSDocMemberName | undefined; get text(): string; } export type JSDocComment = JSDocText | JSDocLink | JSDocLinkCode | JSDocLinkPlain; export class JSDocText extends Node { - readonly ast: AstJSDocText; get text(): string; } export class JSDocUnknownTag extends JSDocTag { - readonly ast: AstJSDocUnknownTag; } export interface JSDocClassReference extends ExpressionWithTypeArguments { - readonly ast: AstJSDocClassReference; readonly data: AstJSDocClassReferenceData; readonly expression: Identifier | PropertyAccessEntityNameExpression; } @@ -6486,69 +6287,52 @@ declare namespace ts { * Both tags are represented by this interface. */ export class JSDocAugmentsTag extends JSDocTag { - readonly ast: AstJSDocAugmentsTag; get class(): JSDocClassReference; } export class JSDocImplementsTag extends JSDocTag { - readonly ast: AstJSDocImplementsTag; get class(): JSDocClassReference; } export class JSDocAuthorTag extends JSDocTag { - readonly ast: AstJSDocAuthorTag; } export class JSDocDeprecatedTag extends JSDocTag { - readonly ast: AstJSDocDeprecatedTag; } export class JSDocClassTag extends JSDocTag { - readonly ast: AstJSDocClassTag; } export class JSDocPublicTag extends JSDocTag { - readonly ast: AstJSDocPublicTag; } export class JSDocPrivateTag extends JSDocTag { - readonly ast: AstJSDocPrivateTag; } export class JSDocProtectedTag extends JSDocTag { - readonly ast: AstJSDocProtectedTag; } export class JSDocReadonlyTag extends JSDocTag { - readonly ast: AstJSDocReadonlyTag; } export class JSDocOverrideTag extends JSDocTag { - readonly ast: AstJSDocOverrideTag; } export class JSDocEnumTag extends JSDocTag implements Declaration, LocalsContainer { _declarationBrand: any; _localsContainerBrand: any; - readonly ast: AstJSDocEnumTag; get parent(): JSDoc; get typeExpression(): JSDocTypeExpression; } export class JSDocThisTag extends JSDocTag { - readonly ast: AstJSDocThisTag; get typeExpression(): JSDocTypeExpression; } export class JSDocTemplateTag extends JSDocTag { - readonly ast: AstJSDocTemplateTag; get constraint(): JSDocTypeExpression | undefined; get typeParameters(): NodeArray; } export class JSDocSeeTag extends JSDocTag { - readonly ast: AstJSDocSeeTag; get name(): JSDocNameReference | undefined; } export class JSDocReturnTag extends JSDocTag { - readonly ast: AstJSDocReturnTag; get typeExpression(): JSDocTypeExpression | undefined; } export class JSDocTypeTag extends JSDocTag { - readonly ast: AstJSDocTypeTag; get typeExpression(): JSDocTypeExpression; } export class JSDocTypedefTag extends JSDocTag implements Declaration, LocalsContainer { _declarationBrand: any; _localsContainerBrand: any; - readonly ast: AstJSDocTypedefTag; get parent(): JSDoc; get fullName(): Identifier | JSDocNamespaceDeclaration | undefined; get name(): Identifier | undefined; @@ -6557,19 +6341,16 @@ declare namespace ts { export class JSDocCallbackTag extends JSDocTag implements Declaration, LocalsContainer { _declarationBrand: any; _localsContainerBrand: any; - readonly ast: AstJSDocCallbackTag; get parent(): JSDoc; get fullName(): Identifier | JSDocNamespaceDeclaration | undefined; get name(): Identifier | undefined; get typeExpression(): JSDocSignature; } export class JSDocOverloadTag extends JSDocTag { - readonly ast: AstJSDocOverloadTag; get parent(): JSDoc; get typeExpression(): JSDocSignature; } export class JSDocThrowsTag extends JSDocTag { - readonly ast: AstJSDocThrowsTag; get typeExpression(): JSDocTypeExpression | undefined; } export class JSDocSignature extends Node implements JSDocType, Declaration, JSDocContainer, LocalsContainer { @@ -6579,13 +6360,11 @@ declare namespace ts { _jsdocContainerBrand: any; _localsContainerBrand: any; _signatureDeclarationBrand: any; - readonly ast: AstJSDocSignature; get typeParameters(): NodeArray | undefined; get parameters(): NodeArray; get type(): JSDocReturnTag | undefined; } export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { - readonly ast: AstJSDocPropertyLikeTag; readonly data: AstJSDocTagData & AstDeclarationData; readonly parent: JSDoc; readonly name: EntityName; @@ -6596,7 +6375,6 @@ declare namespace ts { } export class JSDocPropertyTag extends JSDocTag implements JSDocPropertyLikeTag, Declaration { _declarationBrand: any; - readonly ast: AstJSDocPropertyTag; get parent(): JSDoc; get name(): Identifier | QualifiedName; get typeExpression(): JSDocTypeExpression | undefined; @@ -6606,7 +6384,6 @@ declare namespace ts { } export class JSDocParameterTag extends JSDocTag implements JSDocPropertyLikeTag { _declarationBrand: any; - readonly ast: AstJSDocParameterTag; get parent(): JSDoc; get name(): Identifier | QualifiedName; get typeExpression(): JSDocTypeExpression | undefined; @@ -6618,17 +6395,14 @@ declare namespace ts { _jsDocTypeBrand: any; _typeNodeBrand: any; _declarationBrand: any; - readonly ast: AstJSDocTypeLiteral; get jsDocPropertyTags(): NodeArray | undefined; /** If true, then this type literal represents an *array* of its type. */ get isArrayType(): boolean; } export class JSDocSatisfiesTag extends JSDocTag { - readonly ast: AstJSDocSatisfiesTag; get typeExpression(): JSDocTypeExpression; } export class JSDocImportTag extends JSDocTag { - readonly ast: AstJSDocImportTag; get parent(): JSDoc; get importClause(): ImportClause | undefined; get moduleSpecifier(): Expression; @@ -6656,7 +6430,6 @@ declare namespace ts { export class SourceFile extends Node implements Declaration, LocalsContainer, ReadonlyPragmaContext { _declarationBrand: any; _localsContainerBrand: any; - readonly ast: AstSourceFile; get statements(): NodeArray; get endOfFileToken(): EndOfFileToken; get fileName(): string; @@ -6732,11 +6505,9 @@ declare namespace ts { readonly hasNoDefaultLib?: boolean | undefined; } export class Bundle extends Node { - readonly ast: AstBundle; get sourceFiles(): readonly SourceFile[]; } export interface JsonSourceFile extends SourceFile { - readonly ast: AstJsonSourceFile; readonly data: AstJsonSourceFileData; readonly statements: NodeArray; } @@ -6744,14 +6515,12 @@ declare namespace ts { extendedSourceFiles: string[] | undefined; } export interface JsonMinusNumericLiteral extends PrefixUnaryExpression { - readonly ast: AstJsonMinusNumericLiteral; readonly data: AstJsonMinusNumericLiteralData; readonly operator: SyntaxKind.MinusToken; readonly operand: NumericLiteral; } export type JsonObjectExpression = ObjectLiteralExpression | ArrayLiteralExpression | JsonMinusNumericLiteral | NumericLiteral | StringLiteral | BooleanLiteral | NullLiteral; export interface JsonObjectExpressionStatement extends ExpressionStatement { - readonly ast: AstJsonObjectExpressionStatement; readonly data: AstJsonObjectExpressionStatementData; readonly expression: JsonObjectExpression; } @@ -9456,14 +9225,22 @@ declare namespace ts { export type AstLiteralExpression = AstNode; export interface AstLiteralExpressionData extends AstLiteralLikeNodeData { } + export type AstToken = AstNode>; export class AstTokenData extends AstData { } + export type AstEndOfFileToken = AstNode; export class AstEndOfFileTokenData extends AstTokenData { } + export type AstThisExpression = AstNode; export class AstThisExpressionData extends AstTokenData { } + export type AstSuperExpression = AstNode; export class AstSuperExpressionData extends AstTokenData { } + export type AstImportExpression = AstNode; + export type AstNullLiteral = AstNode; + export type AstTrueLiteral = AstNode; + export type AstFalseLiteral = AstNode; export type AstBooleanLiteral = AstNodeOneOf; export type AstPunctuationToken = AstNode>; export type AstDotToken = AstNode; @@ -9503,9 +9280,11 @@ declare namespace ts { export type AstStaticKeyword = AstNode; export type AstModifier = AstNodeOneOf; export type AstModifierLike = AstNodeOneOf; + export type AstIdentifier = AstNode; export class AstIdentifierData extends AstTokenData { escapedText: __String; } + export type AstQualifiedName = AstNode; export class AstQualifiedNameData extends AstData { left: AstEntityName; right: AstIdentifier; @@ -9515,12 +9294,15 @@ declare namespace ts { export type AstPropertyName = AstNodeOneOf; export type AstMemberName = AstNodeOneOf; export type AstDeclarationName = AstNodeOneOf; + export type AstComputedPropertyName = AstNode; export class AstComputedPropertyNameData extends AstData { expression: AstExpression; } + export type AstPrivateIdentifier = AstNode; export class AstPrivateIdentifierData extends AstTokenData { escapedText: __String; } + export type AstTypeParameterDeclaration = AstNode; export class AstTypeParameterDeclarationData extends AstTypeScriptNodeData { modifiers: AstNodeArray | undefined; name: AstIdentifier; @@ -9528,6 +9310,7 @@ declare namespace ts { default: AstTypeNode | undefined; expression: AstExpression | undefined; } + export type AstParameterDeclaration = AstNode; export class AstParameterDeclarationData extends AstData { modifiers: AstNodeArray | undefined; dotDotDotToken: AstDotDotDotToken | undefined; @@ -9536,9 +9319,11 @@ declare namespace ts { type: AstTypeNode | undefined; initializer: AstExpression | undefined; } + export type AstDecorator = AstNode; export class AstDecoratorData extends AstData { expression: AstLeftHandSideExpression; } + export type AstPropertySignature = AstNode; export class AstPropertySignatureData extends AstTypeScriptNodeData { modifiers: AstNodeArray | undefined; name: AstPropertyName; @@ -9546,31 +9331,37 @@ declare namespace ts { type: AstTypeNode | undefined; } export type AstSignatureDeclaration = AstNodeOneOf; + export type AstCallSignatureDeclaration = AstNode; export class AstCallSignatureDeclarationData extends AstTypeScriptNodeData { typeParameters: AstNodeArray | undefined; parameters: AstNodeArray; type: AstTypeNode | undefined; } + export type AstConstructSignatureDeclaration = AstNode; export class AstConstructSignatureDeclarationData extends AstTypeScriptNodeData { typeParameters: AstNodeArray | undefined; parameters: AstNodeArray; type: AstTypeNode | undefined; } + export type AstVariableDeclaration = AstNode; export class AstVariableDeclarationData extends AstData { name: AstBindingName; exclamationToken: AstExclamationToken | undefined; type: AstTypeNode | undefined; initializer: AstExpression | undefined; } + export type AstVariableDeclarationList = AstNode; export class AstVariableDeclarationListData extends AstData { declarations: AstNodeArray; } + export type AstBindingElement = AstNode; export class AstBindingElementData extends AstData { propertyName: AstPropertyName | undefined; dotDotDotToken: AstDotDotDotToken | undefined; name: AstBindingName; initializer: AstExpression | undefined; } + export type AstPropertyDeclaration = AstNode; export class AstPropertyDeclarationData extends AstData { modifiers: AstNodeArray | undefined; name: AstPropertyName; @@ -9579,6 +9370,7 @@ declare namespace ts { type: AstTypeNode | undefined; initializer: AstExpression | undefined; } + export type AstPropertyAssignment = AstNode; export class AstPropertyAssignmentData extends AstData { modifiers: AstNodeArray | undefined; name: AstPropertyName; @@ -9586,6 +9378,7 @@ declare namespace ts { exclamationToken: AstExclamationToken | undefined; initializer: AstExpression; } + export type AstShorthandPropertyAssignment = AstNode; export class AstShorthandPropertyAssignmentData extends AstData { name: AstIdentifier; equalsToken: AstEqualsToken | undefined; @@ -9594,17 +9387,21 @@ declare namespace ts { questionToken: AstQuestionToken | undefined; exclamationToken: AstExclamationToken | undefined; } + export type AstSpreadAssignment = AstNode; export class AstSpreadAssignmentData extends AstData { expression: AstExpression; } export type AstBindingPattern = AstNodeOneOf; - export type AstArrayBindingElement = AstNodeOneOf; + export type AstObjectBindingPattern = AstNode; export class AstObjectBindingPatternData extends AstData { elements: AstNodeArray; } + export type AstArrayBindingElement = AstNodeOneOf; + export type AstArrayBindingPattern = AstNode; export class AstArrayBindingPatternData extends AstData { elements: AstNodeArray; } + export type AstFunctionDeclaration = AstNode; export class AstFunctionDeclarationData extends AstData { modifiers: AstNodeArray | undefined; asteriskToken: AstAsteriskToken | undefined; @@ -9912,16 +9709,13 @@ declare namespace ts { export class AstObjectLiteralExpressionData extends AstData { properties: AstNodeArray; } + export type AstPropertyAccessExpression = AstNode; export class AstPropertyAccessExpressionData extends AstData { expression: AstLeftHandSideExpression; questionDotToken: AstQuestionDotToken | undefined; name: AstMemberName; } export type AstPropertyAccessEntityNameExpression = AstNode; - export interface AstPropertyAccessEntityNameExpressionData extends AstPropertyAccessExpressionData { - expression: AstEntityNameExpression; - name: AstIdentifier; - } export type AstEntityNameExpression = AstNodeOneOf; export type AstPropertyAccessChain = AstNode; export class AstElementAccessExpressionData extends AstData { @@ -10503,34 +10297,6 @@ declare namespace ts { namedDeclarations: Map | undefined; cloneNode(node: AstNode): AstNode; } - export type AstToken = AstNode>; - export type AstEndOfFileToken = AstNode; - export type AstThisExpression = AstNode; - export type AstSuperExpression = AstNode; - export type AstImportExpression = AstNode; - export type AstNullLiteral = AstNode; - export type AstTrueLiteral = AstNode; - export type AstFalseLiteral = AstNode; - export type AstIdentifier = AstNode; - export type AstQualifiedName = AstNode; - export type AstComputedPropertyName = AstNode; - export type AstPrivateIdentifier = AstNode; - export type AstTypeParameterDeclaration = AstNode; - export type AstParameterDeclaration = AstNode; - export type AstDecorator = AstNode; - export type AstPropertySignature = AstNode; - export type AstCallSignatureDeclaration = AstNode; - export type AstConstructSignatureDeclaration = AstNode; - export type AstVariableDeclaration = AstNode; - export type AstVariableDeclarationList = AstNode; - export type AstBindingElement = AstNode; - export type AstPropertyDeclaration = AstNode; - export type AstPropertyAssignment = AstNode; - export type AstShorthandPropertyAssignment = AstNode; - export type AstSpreadAssignment = AstNode; - export type AstObjectBindingPattern = AstNode; - export type AstArrayBindingPattern = AstNode; - export type AstFunctionDeclaration = AstNode; export type AstMethodSignature = AstNode; export type AstMethodDeclaration = AstNode; export type AstConstructorDeclaration = AstNode; @@ -10589,7 +10355,6 @@ declare namespace ts { export type AstArrayLiteralExpression = AstNode; export type AstSpreadElement = AstNode; export type AstObjectLiteralExpression = AstNode; - export type AstPropertyAccessExpression = AstNode; export type AstElementAccessExpression = AstNode; export type AstCallExpression = AstNode; export type AstExpressionWithTypeArguments = AstNode; @@ -10726,6 +10491,47 @@ declare namespace ts { export interface AstJsonSourceFileData extends AstSourceFileData { statements: AstNodeArray; } + /** + * Constraint limiting what props can be applied to a Node refinement. + */ + export type NodeProps = { + [K in keyof N["data"] & keyof N as Exclude]?: N["data"][K] extends infer P ? P extends AstNodeArray ? readonly C["node"][] : P extends AstNode ? C : P : never; + }; + /** + * Converts `Node[]` to `AstNodeArray` + */ + export type RefineAstNodeArray = + & AstNodeArray + & (number extends A["length"] ? unknown : { + readonly items: { + +readonly [P in keyof A]-?: A[P]["ast"]; + }; + }); + /** + * Converts the supplied node properties to AST form. + */ + export type RefineNodeData> = { + [K in keyof D]: D[K] extends infer C extends readonly Node[] ? RefineAstNodeArray : D[K] extends Node ? D[K]["ast"] : D[K]; + }; + /** + * Refines a `Node` based on a set of specific node properties. + */ + export type RefineNode> = N & D & { + readonly data: RefineNodeData; + }; + /** + * Refines a `Node` with specific required properties. + */ + export type RequiredNodeProp = N extends Node ? RefineNode< + N, + Extract< + { + readonly [P in K & keyof NodeProps]-?: NonNullable[P]>; + }, + NodeProps + > + > + : never; export enum FileWatcherEventKind { Created = 0, Changed = 1, From 2598c94babd982be30fcdd3f3a2cb6af592cc097 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 1 Oct 2024 15:10:58 -0400 Subject: [PATCH 08/10] Temporary monomorphic Node projection --- src/compiler/ast.ts | 811 ++++++++++++++++++++++++++++------------ src/compiler/program.ts | 1 - src/compiler/types.ts | 3 +- 3 files changed, 584 insertions(+), 231 deletions(-) diff --git a/src/compiler/ast.ts b/src/compiler/ast.ts index 2e92a5b474c09..11d3b356eb487 100644 --- a/src/compiler/ast.ts +++ b/src/compiler/ast.ts @@ -17,7 +17,6 @@ import { AssertKeyword, AssertsKeyword, AsteriskToken, - astHasJSDocNodes, AsyncKeyword, AwaitExpression, AwaitKeyword, @@ -82,6 +81,7 @@ import { ElementAccessExpression, EmitFlags, EmitNode, + emptyArray, EmptyStatement, EndOfFileToken, EntityName, @@ -125,6 +125,7 @@ import { hasProperty, HeritageClause, Identifier, + idText, IfStatement, ImportAttribute, ImportAttributeName, @@ -146,6 +147,7 @@ import { IScriptSnapshot, isLogicalOrCoalescingAssignmentOperator, isParseTreeNode, + isTokenKind, IterationStatement, JSDoc, JSDocAllType, @@ -237,7 +239,6 @@ import { LiteralToken, LiteralTypeNode, MappedTypeNode, - MatchingKeys, MemberExpression, MemberName, MetaProperty, @@ -341,6 +342,7 @@ import { ShorthandPropertyAssignment, SignatureDeclaration, SourceFile, + SourceFileLike, SpreadAssignment, SpreadElement, Statement, @@ -649,653 +651,653 @@ export class AstNode = Node(kind: K) { + static Token(kind: K): AstToken { const makeToken = AstNode._tokenFactoryMap.get(kind); - return (makeToken ? makeToken() : new AstNode(kind, new AstTokenData(), Token)) as AstToken; + return (makeToken ? makeToken() : new AstNode(kind, new AstTokenData(), AnyNode /*Token*/)) as AstToken; } private static _tokenFactoryMap = new Map AstToken>([ - [SyntaxKind.NumericLiteral, this.NumericLiteral], - [SyntaxKind.BigIntLiteral, this.BigIntLiteral], - [SyntaxKind.StringLiteral, this.StringLiteral], - [SyntaxKind.JsxText, this.JsxText], - [SyntaxKind.RegularExpressionLiteral, this.RegularExpressionLiteral], - [SyntaxKind.NoSubstitutionTemplateLiteral, this.NoSubstitutionTemplateLiteral], - [SyntaxKind.TemplateHead, this.TemplateHead], - [SyntaxKind.TemplateMiddle, this.TemplateMiddle], - [SyntaxKind.TemplateTail, this.TemplateTail], - [SyntaxKind.Identifier, this.Identifier], - [SyntaxKind.PrivateIdentifier, this.PrivateIdentifier], - [SyntaxKind.EndOfFileToken, this.EndOfFileToken], - [SyntaxKind.ThisKeyword, this.ThisExpression], - [SyntaxKind.SuperKeyword, this.SuperExpression], - [SyntaxKind.ImportKeyword, this.ImportExpression], - [SyntaxKind.NullKeyword, this.NullLiteral], - [SyntaxKind.TrueKeyword, this.TrueLiteral], - [SyntaxKind.FalseKeyword, this.FalseLiteral], + // [SyntaxKind.NumericLiteral, this.NumericLiteral], + // [SyntaxKind.BigIntLiteral, this.BigIntLiteral], + // [SyntaxKind.StringLiteral, this.StringLiteral], + // [SyntaxKind.JsxText, this.JsxText], + // [SyntaxKind.RegularExpressionLiteral, this.RegularExpressionLiteral], + // [SyntaxKind.NoSubstitutionTemplateLiteral, this.NoSubstitutionTemplateLiteral], + // [SyntaxKind.TemplateHead, this.TemplateHead], + // [SyntaxKind.TemplateMiddle, this.TemplateMiddle], + // [SyntaxKind.TemplateTail, this.TemplateTail], + // [SyntaxKind.Identifier, this.Identifier], + // [SyntaxKind.PrivateIdentifier, this.PrivateIdentifier], + // [SyntaxKind.EndOfFileToken, this.EndOfFileToken], + // [SyntaxKind.ThisKeyword, this.ThisExpression], + // [SyntaxKind.SuperKeyword, this.SuperExpression], + // [SyntaxKind.ImportKeyword, this.ImportExpression], + // [SyntaxKind.NullKeyword, this.NullLiteral], + // [SyntaxKind.TrueKeyword, this.TrueLiteral], + // [SyntaxKind.FalseKeyword, this.FalseLiteral], ]); static EndOfFileToken(): AstEndOfFileToken { - return new AstNode(SyntaxKind.EndOfFileToken, new AstEndOfFileTokenData(), EndOfFileToken); + return new AstNode(SyntaxKind.EndOfFileToken, new AstEndOfFileTokenData(), AnyNode /* EndOfFileToken */); } static ThisExpression(): AstThisExpression { - return new AstNode(SyntaxKind.ThisKeyword, new AstThisExpressionData(), ThisExpression); + return new AstNode(SyntaxKind.ThisKeyword, new AstThisExpressionData(), AnyNode /* ThisExpression */); } static SuperExpression(): AstSuperExpression { - return new AstNode(SyntaxKind.SuperKeyword, new AstSuperExpressionData(), SuperExpression); + return new AstNode(SyntaxKind.SuperKeyword, new AstSuperExpressionData(), AnyNode /* SuperExpression */); } static ImportExpression(): AstImportExpression { - return new AstNode(SyntaxKind.ImportKeyword, new AstTokenData(), ImportExpression); + return new AstNode(SyntaxKind.ImportKeyword, new AstTokenData(), AnyNode /* ImportExpression */); } static NullLiteral(): AstNullLiteral { - return new AstNode(SyntaxKind.NullKeyword, new AstTokenData(), NullLiteral); + return new AstNode(SyntaxKind.NullKeyword, new AstTokenData(), AnyNode /* NullLiteral */); } static TrueLiteral(): AstTrueLiteral { - return new AstNode(SyntaxKind.TrueKeyword, new AstTokenData(), TrueLiteral); + return new AstNode(SyntaxKind.TrueKeyword, new AstTokenData(), AnyNode /* TrueLiteral */); } static FalseLiteral(): AstFalseLiteral { - return new AstNode(SyntaxKind.FalseKeyword, new AstTokenData(), FalseLiteral); + return new AstNode(SyntaxKind.FalseKeyword, new AstTokenData(), AnyNode /* FalseLiteral */); } static Identifier(): AstIdentifier { - return new AstNode(SyntaxKind.Identifier, new AstIdentifierData(), Identifier); + return new AstNode(SyntaxKind.Identifier, new AstIdentifierData(), AnyNode /* Identifier */); } static PrivateIdentifier(): AstPrivateIdentifier { - return new AstNode(SyntaxKind.PrivateIdentifier, new AstPrivateIdentifierData(), PrivateIdentifier); + return new AstNode(SyntaxKind.PrivateIdentifier, new AstPrivateIdentifierData(), AnyNode /* PrivateIdentifier */); } static QualifiedName(): AstQualifiedName { - return new AstNode(SyntaxKind.QualifiedName, new AstQualifiedNameData(), QualifiedName); + return new AstNode(SyntaxKind.QualifiedName, new AstQualifiedNameData(), AnyNode /* QualifiedName */); } static ComputedPropertyName(): AstComputedPropertyName { - return new AstNode(SyntaxKind.ComputedPropertyName, new AstComputedPropertyNameData(), ComputedPropertyName); + return new AstNode(SyntaxKind.ComputedPropertyName, new AstComputedPropertyNameData(), AnyNode /* ComputedPropertyName */); } static TypeParameterDeclaration(): AstTypeParameterDeclaration { - return new AstNode(SyntaxKind.TypeParameter, new AstTypeParameterDeclarationData(), TypeParameterDeclaration); + return new AstNode(SyntaxKind.TypeParameter, new AstTypeParameterDeclarationData(), AnyNode /* TypeParameterDeclaration */); } static ParameterDeclaration(): AstParameterDeclaration { - return new AstNode(SyntaxKind.Parameter, new AstParameterDeclarationData(), ParameterDeclaration); + return new AstNode(SyntaxKind.Parameter, new AstParameterDeclarationData(), AnyNode /* ParameterDeclaration */); } static Decorator(): AstDecorator { - return new AstNode(SyntaxKind.Decorator, new AstDecoratorData(), Decorator); + return new AstNode(SyntaxKind.Decorator, new AstDecoratorData(), AnyNode /* Decorator */); } static PropertySignature(): AstPropertySignature { - return new AstNode(SyntaxKind.PropertySignature, new AstPropertySignatureData(), PropertySignature); + return new AstNode(SyntaxKind.PropertySignature, new AstPropertySignatureData(), AnyNode /* PropertySignature */); } static CallSignatureDeclaration(): AstCallSignatureDeclaration { - return new AstNode(SyntaxKind.CallSignature, new AstCallSignatureDeclarationData(), CallSignatureDeclaration); + return new AstNode(SyntaxKind.CallSignature, new AstCallSignatureDeclarationData(), AnyNode /* CallSignatureDeclaration */); } static ConstructSignatureDeclaration(): AstConstructSignatureDeclaration { - return new AstNode(SyntaxKind.ConstructSignature, new AstConstructSignatureDeclarationData(), ConstructSignatureDeclaration); + return new AstNode(SyntaxKind.ConstructSignature, new AstConstructSignatureDeclarationData(), AnyNode /* ConstructSignatureDeclaration */); } static VariableDeclaration(): AstVariableDeclaration { - return new AstNode(SyntaxKind.VariableDeclaration, new AstVariableDeclarationData(), VariableDeclaration); + return new AstNode(SyntaxKind.VariableDeclaration, new AstVariableDeclarationData(), AnyNode /* VariableDeclaration */); } static VariableDeclarationList(): AstVariableDeclarationList { - return new AstNode(SyntaxKind.VariableDeclarationList, new AstVariableDeclarationListData(), VariableDeclarationList); + return new AstNode(SyntaxKind.VariableDeclarationList, new AstVariableDeclarationListData(), AnyNode /* VariableDeclarationList */); } static BindingElement(): AstBindingElement { - return new AstNode(SyntaxKind.BindingElement, new AstBindingElementData(), BindingElement); + return new AstNode(SyntaxKind.BindingElement, new AstBindingElementData(), AnyNode /* BindingElement */); } static PropertyDeclaration(): AstPropertyDeclaration { - return new AstNode(SyntaxKind.PropertyDeclaration, new AstPropertyDeclarationData(), PropertyDeclaration); + return new AstNode(SyntaxKind.PropertyDeclaration, new AstPropertyDeclarationData(), AnyNode /* PropertyDeclaration */); } static PropertyAssignment(): AstPropertyAssignment { - return new AstNode(SyntaxKind.PropertyAssignment, new AstPropertyAssignmentData(), PropertyAssignment); + return new AstNode(SyntaxKind.PropertyAssignment, new AstPropertyAssignmentData(), AnyNode /* PropertyAssignment */); } static ShorthandPropertyAssignment(): AstShorthandPropertyAssignment { - return new AstNode(SyntaxKind.ShorthandPropertyAssignment, new AstShorthandPropertyAssignmentData(), ShorthandPropertyAssignment); + return new AstNode(SyntaxKind.ShorthandPropertyAssignment, new AstShorthandPropertyAssignmentData(), AnyNode /* ShorthandPropertyAssignment */); } static SpreadAssignment(): AstSpreadAssignment { - return new AstNode(SyntaxKind.SpreadAssignment, new AstSpreadAssignmentData(), SpreadAssignment); + return new AstNode(SyntaxKind.SpreadAssignment, new AstSpreadAssignmentData(), AnyNode /* SpreadAssignment */); } static ObjectBindingPattern(): AstObjectBindingPattern { - return new AstNode(SyntaxKind.ObjectBindingPattern, new AstObjectBindingPatternData(), ObjectBindingPattern); + return new AstNode(SyntaxKind.ObjectBindingPattern, new AstObjectBindingPatternData(), AnyNode /* ObjectBindingPattern */); } static ArrayBindingPattern(): AstArrayBindingPattern { - return new AstNode(SyntaxKind.ArrayBindingPattern, new AstArrayBindingPatternData(), ArrayBindingPattern); + return new AstNode(SyntaxKind.ArrayBindingPattern, new AstArrayBindingPatternData(), AnyNode /* ArrayBindingPattern */); } static FunctionDeclaration(): AstFunctionDeclaration { - return new AstNode(SyntaxKind.FunctionDeclaration, new AstFunctionDeclarationData(), FunctionDeclaration); + return new AstNode(SyntaxKind.FunctionDeclaration, new AstFunctionDeclarationData(), AnyNode /* FunctionDeclaration */); } static MethodSignature(): AstMethodSignature { - return new AstNode(SyntaxKind.MethodSignature, new AstMethodSignatureData(), MethodSignature); + return new AstNode(SyntaxKind.MethodSignature, new AstMethodSignatureData(), AnyNode /* MethodSignature */); } static MethodDeclaration(): AstMethodDeclaration { - return new AstNode(SyntaxKind.MethodDeclaration, new AstMethodDeclarationData(), MethodDeclaration); + return new AstNode(SyntaxKind.MethodDeclaration, new AstMethodDeclarationData(), AnyNode /* MethodDeclaration */); } static ConstructorDeclaration(): AstConstructorDeclaration { - return new AstNode(SyntaxKind.Constructor, new AstConstructorDeclarationData(), ConstructorDeclaration); + return new AstNode(SyntaxKind.Constructor, new AstConstructorDeclarationData(), AnyNode /* ConstructorDeclaration */); } static SemicolonClassElement(): AstSemicolonClassElement { - return new AstNode(SyntaxKind.SemicolonClassElement, new AstSemicolonClassElementData(), SemicolonClassElement); + return new AstNode(SyntaxKind.SemicolonClassElement, new AstSemicolonClassElementData(), AnyNode as any /* SemicolonClassElement */); } static GetAccessorDeclaration(): AstGetAccessorDeclaration { - return new AstNode(SyntaxKind.GetAccessor, new AstGetAccessorDeclarationData(), GetAccessorDeclaration); + return new AstNode(SyntaxKind.GetAccessor, new AstGetAccessorDeclarationData(), AnyNode /* GetAccessorDeclaration */); } static SetAccessorDeclaration(): AstSetAccessorDeclaration { - return new AstNode(SyntaxKind.SetAccessor, new AstSetAccessorDeclarationData(), SetAccessorDeclaration); + return new AstNode(SyntaxKind.SetAccessor, new AstSetAccessorDeclarationData(), AnyNode /* SetAccessorDeclaration */); } static IndexSignatureDeclaration(): AstIndexSignatureDeclaration { - return new AstNode(SyntaxKind.IndexSignature, new AstIndexSignatureDeclarationData(), IndexSignatureDeclaration); + return new AstNode(SyntaxKind.IndexSignature, new AstIndexSignatureDeclarationData(), AnyNode /* IndexSignatureDeclaration */); } static ClassStaticBlockDeclaration(): AstClassStaticBlockDeclaration { - return new AstNode(SyntaxKind.ClassStaticBlockDeclaration, new AstClassStaticBlockDeclarationData(), ClassStaticBlockDeclaration); + return new AstNode(SyntaxKind.ClassStaticBlockDeclaration, new AstClassStaticBlockDeclarationData(), AnyNode /* ClassStaticBlockDeclaration */); } /** @deprecated */ static ImportTypeAssertionContainer(): AstImportTypeAssertionContainer { - return new AstNode(SyntaxKind.ImportTypeAssertionContainer, new AstImportTypeAssertionContainerData(), ImportTypeAssertionContainer); + return new AstNode(SyntaxKind.ImportTypeAssertionContainer, new AstImportTypeAssertionContainerData(), AnyNode /* ImportTypeAssertionContainer */); } static ImportTypeNode(): AstImportTypeNode { - return new AstNode(SyntaxKind.ImportType, new AstImportTypeNodeData(), ImportTypeNode); + return new AstNode(SyntaxKind.ImportType, new AstImportTypeNodeData(), AnyNode /* ImportTypeNode */); } static ThisTypeNode(): AstThisTypeNode { - return new AstNode(SyntaxKind.ThisType, new AstThisTypeNodeData(), ThisTypeNode); + return new AstNode(SyntaxKind.ThisType, new AstThisTypeNodeData(), AnyNode /* ThisTypeNode */); } static FunctionTypeNode(): AstFunctionTypeNode { - return new AstNode(SyntaxKind.FunctionType, new AstFunctionTypeNodeData(), FunctionTypeNode); + return new AstNode(SyntaxKind.FunctionType, new AstFunctionTypeNodeData(), AnyNode /* FunctionTypeNode */); } static ConstructorTypeNode(): AstConstructorTypeNode { - return new AstNode(SyntaxKind.ConstructorType, new AstConstructorTypeNodeData(), ConstructorTypeNode); + return new AstNode(SyntaxKind.ConstructorType, new AstConstructorTypeNodeData(), AnyNode /* ConstructorTypeNode */); } static TypeReferenceNode(): AstTypeReferenceNode { - return new AstNode(SyntaxKind.TypeReference, new AstTypeReferenceNodeData(), TypeReferenceNode); + return new AstNode(SyntaxKind.TypeReference, new AstTypeReferenceNodeData(), AnyNode /* TypeReferenceNode */); } static TypePredicateNode(): AstTypePredicateNode { - return new AstNode(SyntaxKind.TypePredicate, new AstTypePredicateNodeData(), TypePredicateNode); + return new AstNode(SyntaxKind.TypePredicate, new AstTypePredicateNodeData(), AnyNode /* TypePredicateNode */); } static TypeQueryNode(): AstTypeQueryNode { - return new AstNode(SyntaxKind.TypeQuery, new AstTypeQueryNodeData(), TypeQueryNode); + return new AstNode(SyntaxKind.TypeQuery, new AstTypeQueryNodeData(), AnyNode /* TypeQueryNode */); } static TypeLiteralNode(): AstTypeLiteralNode { - return new AstNode(SyntaxKind.TypeLiteral, new AstTypeLiteralNodeData(), TypeLiteralNode); + return new AstNode(SyntaxKind.TypeLiteral, new AstTypeLiteralNodeData(), AnyNode /* TypeLiteralNode */); } static ArrayTypeNode(): AstArrayTypeNode { - return new AstNode(SyntaxKind.ArrayType, new AstArrayTypeNodeData(), ArrayTypeNode); + return new AstNode(SyntaxKind.ArrayType, new AstArrayTypeNodeData(), AnyNode /* ArrayTypeNode */); } static TupleTypeNode(): AstTupleTypeNode { - return new AstNode(SyntaxKind.TupleType, new AstTupleTypeNodeData(), TupleTypeNode); + return new AstNode(SyntaxKind.TupleType, new AstTupleTypeNodeData(), AnyNode /* TupleTypeNode */); } static NamedTupleMember(): AstNamedTupleMember { - return new AstNode(SyntaxKind.NamedTupleMember, new AstNamedTupleMemberData(), NamedTupleMember); + return new AstNode(SyntaxKind.NamedTupleMember, new AstNamedTupleMemberData(), AnyNode /* NamedTupleMember */); } static OptionalTypeNode(): AstOptionalTypeNode { - return new AstNode(SyntaxKind.OptionalType, new AstOptionalTypeNodeData(), OptionalTypeNode); + return new AstNode(SyntaxKind.OptionalType, new AstOptionalTypeNodeData(), AnyNode /* OptionalTypeNode */); } static RestTypeNode(): AstRestTypeNode { - return new AstNode(SyntaxKind.RestType, new AstRestTypeNodeData(), RestTypeNode); + return new AstNode(SyntaxKind.RestType, new AstRestTypeNodeData(), AnyNode /* RestTypeNode */); } static UnionTypeNode(): AstUnionTypeNode { - return new AstNode(SyntaxKind.UnionType, new AstUnionTypeNodeData(), UnionTypeNode); + return new AstNode(SyntaxKind.UnionType, new AstUnionTypeNodeData(), AnyNode /* UnionTypeNode */); } static IntersectionTypeNode(): AstIntersectionTypeNode { - return new AstNode(SyntaxKind.IntersectionType, new AstIntersectionTypeNodeData(), IntersectionTypeNode); + return new AstNode(SyntaxKind.IntersectionType, new AstIntersectionTypeNodeData(), AnyNode /* IntersectionTypeNode */); } static ConditionalTypeNode(): AstConditionalTypeNode { - return new AstNode(SyntaxKind.ConditionalType, new AstConditionalTypeNodeData(), ConditionalTypeNode); + return new AstNode(SyntaxKind.ConditionalType, new AstConditionalTypeNodeData(), AnyNode /* ConditionalTypeNode */); } static InferTypeNode(): AstInferTypeNode { - return new AstNode(SyntaxKind.InferType, new AstInferTypeNodeData(), InferTypeNode); + return new AstNode(SyntaxKind.InferType, new AstInferTypeNodeData(), AnyNode /* InferTypeNode */); } static ParenthesizedTypeNode(): AstParenthesizedTypeNode { - return new AstNode(SyntaxKind.ParenthesizedType, new AstParenthesizedTypeNodeData(), ParenthesizedTypeNode); + return new AstNode(SyntaxKind.ParenthesizedType, new AstParenthesizedTypeNodeData(), AnyNode /* ParenthesizedTypeNode */); } static TypeOperatorNode(): AstTypeOperatorNode { - return new AstNode(SyntaxKind.TypeOperator, new AstTypeOperatorNodeData(), TypeOperatorNode); + return new AstNode(SyntaxKind.TypeOperator, new AstTypeOperatorNodeData(), AnyNode /* TypeOperatorNode */); } static IndexedAccessTypeNode(): AstIndexedAccessTypeNode { - return new AstNode(SyntaxKind.IndexedAccessType, new AstIndexedAccessTypeNodeData(), IndexedAccessTypeNode); + return new AstNode(SyntaxKind.IndexedAccessType, new AstIndexedAccessTypeNodeData(), AnyNode /* IndexedAccessTypeNode */); } static MappedTypeNode(): AstMappedTypeNode { - return new AstNode(SyntaxKind.MappedType, new AstMappedTypeNodeData(), MappedTypeNode); + return new AstNode(SyntaxKind.MappedType, new AstMappedTypeNodeData(), AnyNode /* MappedTypeNode */); } static LiteralTypeNode(): AstLiteralTypeNode { - return new AstNode(SyntaxKind.LiteralType, new AstLiteralTypeNodeData(), LiteralTypeNode); + return new AstNode(SyntaxKind.LiteralType, new AstLiteralTypeNodeData(), AnyNode /* LiteralTypeNode */); } static StringLiteral(): AstStringLiteral { - return new AstNode(SyntaxKind.StringLiteral, new AstStringLiteralData(), StringLiteral); + return new AstNode(SyntaxKind.StringLiteral, new AstStringLiteralData(), AnyNode /* StringLiteral */); } static TemplateLiteralTypeNode(): AstTemplateLiteralTypeNode { - return new AstNode(SyntaxKind.TemplateLiteralType, new AstTemplateLiteralTypeNodeData(), TemplateLiteralTypeNode); + return new AstNode(SyntaxKind.TemplateLiteralType, new AstTemplateLiteralTypeNodeData(), AnyNode /* TemplateLiteralTypeNode */); } static TemplateLiteralTypeSpan(): AstTemplateLiteralTypeSpan { - return new AstNode(SyntaxKind.TemplateLiteralTypeSpan, new AstTemplateLiteralTypeSpanData(), TemplateLiteralTypeSpan); + return new AstNode(SyntaxKind.TemplateLiteralTypeSpan, new AstTemplateLiteralTypeSpanData(), AnyNode /* TemplateLiteralTypeSpan */); } static OmittedExpression(): AstOmittedExpression { - return new AstNode(SyntaxKind.OmittedExpression, new AstOmittedExpressionData(), OmittedExpression); + return new AstNode(SyntaxKind.OmittedExpression, new AstOmittedExpressionData(), AnyNode /* OmittedExpression */); } static PrefixUnaryExpression(): AstPrefixUnaryExpression { - return new AstNode(SyntaxKind.PrefixUnaryExpression, new AstPrefixUnaryExpressionData(), PrefixUnaryExpression); + return new AstNode(SyntaxKind.PrefixUnaryExpression, new AstPrefixUnaryExpressionData(), AnyNode /* PrefixUnaryExpression */); } static PostfixUnaryExpression(): AstPostfixUnaryExpression { - return new AstNode(SyntaxKind.PostfixUnaryExpression, new AstPostfixUnaryExpressionData(), PostfixUnaryExpression); + return new AstNode(SyntaxKind.PostfixUnaryExpression, new AstPostfixUnaryExpressionData(), AnyNode /* PostfixUnaryExpression */); } static DeleteExpression(): AstDeleteExpression { - return new AstNode(SyntaxKind.DeleteExpression, new AstDeleteExpressionData(), DeleteExpression); + return new AstNode(SyntaxKind.DeleteExpression, new AstDeleteExpressionData(), AnyNode /* DeleteExpression */); } static TypeOfExpression(): AstTypeOfExpression { - return new AstNode(SyntaxKind.TypeOfExpression, new AstTypeOfExpressionData(), TypeOfExpression); + return new AstNode(SyntaxKind.TypeOfExpression, new AstTypeOfExpressionData(), AnyNode /* TypeOfExpression */); } static VoidExpression(): AstVoidExpression { - return new AstNode(SyntaxKind.VoidExpression, new AstVoidExpressionData(), VoidExpression); + return new AstNode(SyntaxKind.VoidExpression, new AstVoidExpressionData(), AnyNode /* VoidExpression */); } static AwaitExpression(): AstAwaitExpression { - return new AstNode(SyntaxKind.AwaitExpression, new AstAwaitExpressionData(), AwaitExpression); + return new AstNode(SyntaxKind.AwaitExpression, new AstAwaitExpressionData(), AnyNode /* AwaitExpression */); } static YieldExpression(): AstYieldExpression { - return new AstNode(SyntaxKind.YieldExpression, new AstYieldExpressionData(), YieldExpression); + return new AstNode(SyntaxKind.YieldExpression, new AstYieldExpressionData(), AnyNode /* YieldExpression */); } static BinaryExpression(): AstBinaryExpression { - return new AstNode(SyntaxKind.BinaryExpression, new AstBinaryExpressionData(), BinaryExpression); + return new AstNode(SyntaxKind.BinaryExpression, new AstBinaryExpressionData(), AnyNode /* BinaryExpression */); } static ConditionalExpression(): AstConditionalExpression { - return new AstNode(SyntaxKind.ConditionalExpression, new AstConditionalExpressionData(), ConditionalExpression); + return new AstNode(SyntaxKind.ConditionalExpression, new AstConditionalExpressionData(), AnyNode /* ConditionalExpression */); } static FunctionExpression(): AstFunctionExpression { - return new AstNode(SyntaxKind.FunctionExpression, new AstFunctionExpressionData(), FunctionExpression); + return new AstNode(SyntaxKind.FunctionExpression, new AstFunctionExpressionData(), AnyNode /* FunctionExpression */); } static ArrowFunction(): AstArrowFunction { - return new AstNode(SyntaxKind.ArrowFunction, new AstArrowFunctionData(), ArrowFunction); + return new AstNode(SyntaxKind.ArrowFunction, new AstArrowFunctionData(), AnyNode /* ArrowFunction */); } static RegularExpressionLiteral(): AstRegularExpressionLiteral { - return new AstNode(SyntaxKind.RegularExpressionLiteral, new AstRegularExpressionLiteralData(), RegularExpressionLiteral); + return new AstNode(SyntaxKind.RegularExpressionLiteral, new AstRegularExpressionLiteralData(), AnyNode /* RegularExpressionLiteral */); } static NoSubstitutionTemplateLiteral(): AstNoSubstitutionTemplateLiteral { - return new AstNode(SyntaxKind.NoSubstitutionTemplateLiteral, new AstNoSubstitutionTemplateLiteralData(), NoSubstitutionTemplateLiteral); + return new AstNode(SyntaxKind.NoSubstitutionTemplateLiteral, new AstNoSubstitutionTemplateLiteralData(), AnyNode /* NoSubstitutionTemplateLiteral */); } static NumericLiteral(): AstNumericLiteral { - return new AstNode(SyntaxKind.NumericLiteral, new AstNumericLiteralData(), NumericLiteral); + return new AstNode(SyntaxKind.NumericLiteral, new AstNumericLiteralData(), AnyNode /* NumericLiteral */); } static BigIntLiteral(): AstBigIntLiteral { - return new AstNode(SyntaxKind.BigIntLiteral, new AstBigIntLiteralData(), BigIntLiteral); + return new AstNode(SyntaxKind.BigIntLiteral, new AstBigIntLiteralData(), AnyNode /* BigIntLiteral */); } static TemplateHead(): AstTemplateHead { - return new AstNode(SyntaxKind.TemplateHead, new AstTemplateHeadData(), TemplateHead); + return new AstNode(SyntaxKind.TemplateHead, new AstTemplateHeadData(), AnyNode /* TemplateHead */); } static TemplateMiddle(): AstTemplateMiddle { - return new AstNode(SyntaxKind.TemplateMiddle, new AstTemplateMiddleData(), TemplateMiddle); + return new AstNode(SyntaxKind.TemplateMiddle, new AstTemplateMiddleData(), AnyNode /* TemplateMiddle */); } static TemplateTail(): AstTemplateTail { - return new AstNode(SyntaxKind.TemplateTail, new AstTemplateTailData(), TemplateTail); + return new AstNode(SyntaxKind.TemplateTail, new AstTemplateTailData(), AnyNode /* TemplateTail */); } static TemplateExpression(): AstTemplateExpression { - return new AstNode(SyntaxKind.TemplateExpression, new AstTemplateExpressionData(), TemplateExpression); + return new AstNode(SyntaxKind.TemplateExpression, new AstTemplateExpressionData(), AnyNode /* TemplateExpression */); } static TemplateSpan(): AstTemplateSpan { - return new AstNode(SyntaxKind.TemplateSpan, new AstTemplateSpanData(), TemplateSpan); + return new AstNode(SyntaxKind.TemplateSpan, new AstTemplateSpanData(), AnyNode /* TemplateSpan */); } static ParenthesizedExpression(): AstParenthesizedExpression { - return new AstNode(SyntaxKind.ParenthesizedExpression, new AstParenthesizedExpressionData(), ParenthesizedExpression); + return new AstNode(SyntaxKind.ParenthesizedExpression, new AstParenthesizedExpressionData(), AnyNode /* ParenthesizedExpression */); } static ArrayLiteralExpression(): AstArrayLiteralExpression { - return new AstNode(SyntaxKind.ArrayLiteralExpression, new AstArrayLiteralExpressionData(), ArrayLiteralExpression); + return new AstNode(SyntaxKind.ArrayLiteralExpression, new AstArrayLiteralExpressionData(), AnyNode /* ArrayLiteralExpression */); } static SpreadElement(): AstSpreadElement { - return new AstNode(SyntaxKind.SpreadElement, new AstSpreadElementData(), SpreadElement); + return new AstNode(SyntaxKind.SpreadElement, new AstSpreadElementData(), AnyNode /* SpreadElement */); } static ObjectLiteralExpression(): AstObjectLiteralExpression { - return new AstNode(SyntaxKind.ObjectLiteralExpression, new AstObjectLiteralExpressionData(), ObjectLiteralExpression); + return new AstNode(SyntaxKind.ObjectLiteralExpression, new AstObjectLiteralExpressionData(), AnyNode /* ObjectLiteralExpression */); } static PropertyAccessExpression(): AstPropertyAccessExpression { - return new AstNode(SyntaxKind.PropertyAccessExpression, new AstPropertyAccessExpressionData(), PropertyAccessExpression); + return new AstNode(SyntaxKind.PropertyAccessExpression, new AstPropertyAccessExpressionData(), AnyNode /* PropertyAccessExpression */); } static PropertyAccessChain(): AstPropertyAccessChain { return new AstNode(SyntaxKind.PropertyAccessExpression, new AstPropertyAccessExpressionData(), PropertyAccessExpression, NodeFlags.OptionalChain) as AstPropertyAccessChain; } static ElementAccessExpression(): AstElementAccessExpression { - return new AstNode(SyntaxKind.ElementAccessExpression, new AstElementAccessExpressionData(), ElementAccessExpression); + return new AstNode(SyntaxKind.ElementAccessExpression, new AstElementAccessExpressionData(), AnyNode /* ElementAccessExpression */); } static ElementAccessChain(): AstElementAccessChain { return new AstNode(SyntaxKind.ElementAccessExpression, new AstElementAccessExpressionData(), ElementAccessExpression, NodeFlags.OptionalChain) as AstElementAccessChain; } static CallExpression(): AstCallExpression { - return new AstNode(SyntaxKind.CallExpression, new AstCallExpressionData(), CallExpression); + return new AstNode(SyntaxKind.CallExpression, new AstCallExpressionData(), AnyNode /* CallExpression */); } static CallChain(): AstCallChain { return new AstNode(SyntaxKind.CallExpression, new AstCallExpressionData(), CallExpression, NodeFlags.OptionalChain) as AstCallChain; } static ExpressionWithTypeArguments(): AstExpressionWithTypeArguments { - return new AstNode(SyntaxKind.ExpressionWithTypeArguments, new AstExpressionWithTypeArgumentsData(), ExpressionWithTypeArguments); + return new AstNode(SyntaxKind.ExpressionWithTypeArguments, new AstExpressionWithTypeArgumentsData(), AnyNode /* ExpressionWithTypeArguments */); } static NewExpression(): AstNewExpression { - return new AstNode(SyntaxKind.NewExpression, new AstNewExpressionData(), NewExpression); + return new AstNode(SyntaxKind.NewExpression, new AstNewExpressionData(), AnyNode /* NewExpression */); } static TaggedTemplateExpression(): AstTaggedTemplateExpression { - return new AstNode(SyntaxKind.TaggedTemplateExpression, new AstTaggedTemplateExpressionData(), TaggedTemplateExpression); + return new AstNode(SyntaxKind.TaggedTemplateExpression, new AstTaggedTemplateExpressionData(), AnyNode /* TaggedTemplateExpression */); } static AsExpression(): AstAsExpression { - return new AstNode(SyntaxKind.AsExpression, new AstAsExpressionData(), AsExpression); + return new AstNode(SyntaxKind.AsExpression, new AstAsExpressionData(), AnyNode /* AsExpression */); } static TypeAssertion(): AstTypeAssertion { - return new AstNode(SyntaxKind.TypeAssertionExpression, new AstTypeAssertionData(), TypeAssertionExpression); + return new AstNode(SyntaxKind.TypeAssertionExpression, new AstTypeAssertionData(), AnyNode /* TypeAssertionExpression */); } static SatisfiesExpression(): AstSatisfiesExpression { - return new AstNode(SyntaxKind.SatisfiesExpression, new AstSatisfiesExpressionData(), SatisfiesExpression); + return new AstNode(SyntaxKind.SatisfiesExpression, new AstSatisfiesExpressionData(), AnyNode /* SatisfiesExpression */); } static NonNullExpression(): AstNonNullExpression { - return new AstNode(SyntaxKind.NonNullExpression, new AstNonNullExpressionData(), NonNullExpression); + return new AstNode(SyntaxKind.NonNullExpression, new AstNonNullExpressionData(), AnyNode /* NonNullExpression */); } static NonNullChain(): AstNonNullChain { return new AstNode(SyntaxKind.NonNullExpression, new AstNonNullExpressionData(), NonNullExpression, NodeFlags.OptionalChain) as AstNonNullChain; } static MetaProperty(): AstMetaProperty { - return new AstNode(SyntaxKind.MetaProperty, new AstMetaPropertyData(), MetaProperty); + return new AstNode(SyntaxKind.MetaProperty, new AstMetaPropertyData(), AnyNode /* MetaProperty */); } static JsxElement(): AstJsxElement { - return new AstNode(SyntaxKind.JsxElement, new AstJsxElementData(), JsxElement); + return new AstNode(SyntaxKind.JsxElement, new AstJsxElementData(), AnyNode /* JsxElement */); } static JsxAttributes(): AstJsxAttributes { - return new AstNode(SyntaxKind.JsxAttributes, new AstJsxAttributesData(), JsxAttributes); + return new AstNode(SyntaxKind.JsxAttributes, new AstJsxAttributesData(), AnyNode /* JsxAttributes */); } static JsxNamespacedName(): AstJsxNamespacedName { - return new AstNode(SyntaxKind.JsxNamespacedName, new AstJsxNamespacedNameData(), JsxNamespacedName); + return new AstNode(SyntaxKind.JsxNamespacedName, new AstJsxNamespacedNameData(), AnyNode /* JsxNamespacedName */); } static JsxOpeningElement(): AstJsxOpeningElement { - return new AstNode(SyntaxKind.JsxOpeningElement, new AstJsxOpeningElementData(), JsxOpeningElement); + return new AstNode(SyntaxKind.JsxOpeningElement, new AstJsxOpeningElementData(), AnyNode /* JsxOpeningElement */); } static JsxSelfClosingElement(): AstJsxSelfClosingElement { - return new AstNode(SyntaxKind.JsxSelfClosingElement, new AstJsxSelfClosingElementData(), JsxSelfClosingElement); + return new AstNode(SyntaxKind.JsxSelfClosingElement, new AstJsxSelfClosingElementData(), AnyNode /* JsxSelfClosingElement */); } static JsxFragment(): AstJsxFragment { - return new AstNode(SyntaxKind.JsxFragment, new AstJsxFragmentData(), JsxFragment); + return new AstNode(SyntaxKind.JsxFragment, new AstJsxFragmentData(), AnyNode /* JsxFragment */); } static JsxOpeningFragment(): AstJsxOpeningFragment { - return new AstNode(SyntaxKind.JsxOpeningFragment, new AstJsxOpeningFragmentData(), JsxOpeningFragment); + return new AstNode(SyntaxKind.JsxOpeningFragment, new AstJsxOpeningFragmentData(), AnyNode /* JsxOpeningFragment */); } static JsxClosingFragment(): AstJsxClosingFragment { - return new AstNode(SyntaxKind.JsxClosingFragment, new AstJsxClosingFragmentData(), JsxClosingFragment); + return new AstNode(SyntaxKind.JsxClosingFragment, new AstJsxClosingFragmentData(), AnyNode /* JsxClosingFragment */); } static JsxAttribute(): AstJsxAttribute { - return new AstNode(SyntaxKind.JsxAttribute, new AstJsxAttributeData(), JsxAttribute); + return new AstNode(SyntaxKind.JsxAttribute, new AstJsxAttributeData(), AnyNode /* JsxAttribute */); } static JsxSpreadAttribute(): AstJsxSpreadAttribute { - return new AstNode(SyntaxKind.JsxSpreadAttribute, new AstJsxSpreadAttributeData(), JsxSpreadAttribute); + return new AstNode(SyntaxKind.JsxSpreadAttribute, new AstJsxSpreadAttributeData(), AnyNode as any /* JsxSpreadAttribute */); } static JsxClosingElement(): AstJsxClosingElement { - return new AstNode(SyntaxKind.JsxClosingElement, new AstJsxClosingElementData(), JsxClosingElement); + return new AstNode(SyntaxKind.JsxClosingElement, new AstJsxClosingElementData(), AnyNode /* JsxClosingElement */); } static JsxExpression(): AstJsxExpression { - return new AstNode(SyntaxKind.JsxExpression, new AstJsxExpressionData(), JsxExpression); + return new AstNode(SyntaxKind.JsxExpression, new AstJsxExpressionData(), AnyNode /* JsxExpression */); } static JsxText(): AstJsxText { - return new AstNode(SyntaxKind.JsxText, new AstJsxTextData(), JsxText); + return new AstNode(SyntaxKind.JsxText, new AstJsxTextData(), AnyNode /* JsxText */); } static EmptyStatement(): AstEmptyStatement { - return new AstNode(SyntaxKind.EmptyStatement, new AstEmptyStatementData(), EmptyStatement); + return new AstNode(SyntaxKind.EmptyStatement, new AstEmptyStatementData(), AnyNode /* EmptyStatement */); } static DebuggerStatement(): AstDebuggerStatement { - return new AstNode(SyntaxKind.DebuggerStatement, new AstDebuggerStatementData(), DebuggerStatement); + return new AstNode(SyntaxKind.DebuggerStatement, new AstDebuggerStatementData(), AnyNode /* DebuggerStatement */); } static MissingDeclaration(): AstMissingDeclaration { - return new AstNode(SyntaxKind.MissingDeclaration, new AstMissingDeclarationData(), MissingDeclaration); + return new AstNode(SyntaxKind.MissingDeclaration, new AstMissingDeclarationData(), AnyNode /* MissingDeclaration */); } static Block(): AstBlock { - return new AstNode(SyntaxKind.Block, new AstBlockData(), Block); + return new AstNode(SyntaxKind.Block, new AstBlockData(), AnyNode /* Block */); } static VariableStatement(): AstVariableStatement { - return new AstNode(SyntaxKind.VariableStatement, new AstVariableStatementData(), VariableStatement); + return new AstNode(SyntaxKind.VariableStatement, new AstVariableStatementData(), AnyNode /* VariableStatement */); } static ExpressionStatement(): AstExpressionStatement { - return new AstNode(SyntaxKind.ExpressionStatement, new AstExpressionStatementData(), ExpressionStatement); + return new AstNode(SyntaxKind.ExpressionStatement, new AstExpressionStatementData(), AnyNode /* ExpressionStatement */); } static IfStatement(): AstIfStatement { - return new AstNode(SyntaxKind.IfStatement, new AstIfStatementData(), IfStatement); + return new AstNode(SyntaxKind.IfStatement, new AstIfStatementData(), AnyNode /* IfStatement */); } static DoStatement(): AstDoStatement { - return new AstNode(SyntaxKind.DoStatement, new AstDoStatementData(), DoStatement); + return new AstNode(SyntaxKind.DoStatement, new AstDoStatementData(), AnyNode /* DoStatement */); } static WhileStatement(): AstWhileStatement { - return new AstNode(SyntaxKind.WhileStatement, new AstWhileStatementData(), WhileStatement); + return new AstNode(SyntaxKind.WhileStatement, new AstWhileStatementData(), AnyNode /* WhileStatement */); } static ForStatement(): AstForStatement { - return new AstNode(SyntaxKind.ForStatement, new AstForStatementData(), ForStatement); + return new AstNode(SyntaxKind.ForStatement, new AstForStatementData(), AnyNode /* ForStatement */); } static ForInStatement(): AstForInStatement { - return new AstNode(SyntaxKind.ForInStatement, new AstForInStatementData(), ForInStatement); + return new AstNode(SyntaxKind.ForInStatement, new AstForInStatementData(), AnyNode /* ForInStatement */); } static ForOfStatement(): AstForOfStatement { - return new AstNode(SyntaxKind.ForOfStatement, new AstForOfStatementData(), ForOfStatement); + return new AstNode(SyntaxKind.ForOfStatement, new AstForOfStatementData(), AnyNode /* ForOfStatement */); } static BreakStatement(): AstBreakStatement { - return new AstNode(SyntaxKind.BreakStatement, new AstBreakStatementData(), BreakStatement); + return new AstNode(SyntaxKind.BreakStatement, new AstBreakStatementData(), AnyNode /* BreakStatement */); } static ContinueStatement(): AstContinueStatement { - return new AstNode(SyntaxKind.ContinueStatement, new AstContinueStatementData(), ContinueStatement); + return new AstNode(SyntaxKind.ContinueStatement, new AstContinueStatementData(), AnyNode /* ContinueStatement */); } static ReturnStatement(): AstReturnStatement { - return new AstNode(SyntaxKind.ReturnStatement, new AstReturnStatementData(), ReturnStatement); + return new AstNode(SyntaxKind.ReturnStatement, new AstReturnStatementData(), AnyNode /* ReturnStatement */); } static WithStatement(): AstWithStatement { - return new AstNode(SyntaxKind.WithStatement, new AstWithStatementData(), WithStatement); + return new AstNode(SyntaxKind.WithStatement, new AstWithStatementData(), AnyNode /* WithStatement */); } static SwitchStatement(): AstSwitchStatement { - return new AstNode(SyntaxKind.SwitchStatement, new AstSwitchStatementData(), SwitchStatement); + return new AstNode(SyntaxKind.SwitchStatement, new AstSwitchStatementData(), AnyNode /* SwitchStatement */); } static CaseBlock(): AstCaseBlock { - return new AstNode(SyntaxKind.CaseBlock, new AstCaseBlockData(), CaseBlock); + return new AstNode(SyntaxKind.CaseBlock, new AstCaseBlockData(), AnyNode /* CaseBlock */); } static CaseClause(): AstCaseClause { - return new AstNode(SyntaxKind.CaseClause, new AstCaseClauseData(), CaseClause); + return new AstNode(SyntaxKind.CaseClause, new AstCaseClauseData(), AnyNode /* CaseClause */); } static DefaultClause(): AstDefaultClause { - return new AstNode(SyntaxKind.DefaultClause, new AstDefaultClauseData(), DefaultClause); + return new AstNode(SyntaxKind.DefaultClause, new AstDefaultClauseData(), AnyNode /* DefaultClause */); } static LabeledStatement(): AstLabeledStatement { - return new AstNode(SyntaxKind.LabeledStatement, new AstLabeledStatementData(), LabeledStatement); + return new AstNode(SyntaxKind.LabeledStatement, new AstLabeledStatementData(), AnyNode /* LabeledStatement */); } static ThrowStatement(): AstThrowStatement { - return new AstNode(SyntaxKind.ThrowStatement, new AstThrowStatementData(), ThrowStatement); + return new AstNode(SyntaxKind.ThrowStatement, new AstThrowStatementData(), AnyNode /* ThrowStatement */); } static TryStatement(): AstTryStatement { - return new AstNode(SyntaxKind.TryStatement, new AstTryStatementData(), TryStatement); + return new AstNode(SyntaxKind.TryStatement, new AstTryStatementData(), AnyNode /* TryStatement */); } static CatchClause(): AstCatchClause { - return new AstNode(SyntaxKind.CatchClause, new AstCatchClauseData(), CatchClause); + return new AstNode(SyntaxKind.CatchClause, new AstCatchClauseData(), AnyNode /* CatchClause */); } static ClassDeclaration(): AstClassDeclaration { - return new AstNode(SyntaxKind.ClassDeclaration, new AstClassDeclarationData(), ClassDeclaration); + return new AstNode(SyntaxKind.ClassDeclaration, new AstClassDeclarationData(), AnyNode /* ClassDeclaration */); } static ClassExpression(): AstClassExpression { - return new AstNode(SyntaxKind.ClassExpression, new AstClassExpressionData(), ClassExpression); + return new AstNode(SyntaxKind.ClassExpression, new AstClassExpressionData(), AnyNode /* ClassExpression */); } static InterfaceDeclaration(): AstInterfaceDeclaration { - return new AstNode(SyntaxKind.InterfaceDeclaration, new AstInterfaceDeclarationData(), InterfaceDeclaration); + return new AstNode(SyntaxKind.InterfaceDeclaration, new AstInterfaceDeclarationData(), AnyNode /* InterfaceDeclaration */); } static HeritageClause(): AstHeritageClause { - return new AstNode(SyntaxKind.HeritageClause, new AstHeritageClauseData(), HeritageClause); + return new AstNode(SyntaxKind.HeritageClause, new AstHeritageClauseData(), AnyNode /* HeritageClause */); } static TypeAliasDeclaration(): AstTypeAliasDeclaration { - return new AstNode(SyntaxKind.TypeAliasDeclaration, new AstTypeAliasDeclarationData(), TypeAliasDeclaration); + return new AstNode(SyntaxKind.TypeAliasDeclaration, new AstTypeAliasDeclarationData(), AnyNode /* TypeAliasDeclaration */); } static EnumMember(): AstEnumMember { - return new AstNode(SyntaxKind.EnumMember, new AstEnumMemberData(), EnumMember); + return new AstNode(SyntaxKind.EnumMember, new AstEnumMemberData(), AnyNode /* EnumMember */); } static EnumDeclaration(): AstEnumDeclaration { - return new AstNode(SyntaxKind.EnumDeclaration, new AstEnumDeclarationData(), EnumDeclaration); + return new AstNode(SyntaxKind.EnumDeclaration, new AstEnumDeclarationData(), AnyNode /* EnumDeclaration */); } static ModuleDeclaration(): AstModuleDeclaration { - return new AstNode(SyntaxKind.ModuleDeclaration, new AstModuleDeclarationData(), ModuleDeclaration); + return new AstNode(SyntaxKind.ModuleDeclaration, new AstModuleDeclarationData(), AnyNode /* ModuleDeclaration */); } static ModuleBlock(): AstModuleBlock { - return new AstNode(SyntaxKind.ModuleBlock, new AstModuleBlockData(), ModuleBlock); + return new AstNode(SyntaxKind.ModuleBlock, new AstModuleBlockData(), AnyNode /* ModuleBlock */); } static ImportEqualsDeclaration(): AstImportEqualsDeclaration { - return new AstNode(SyntaxKind.ImportEqualsDeclaration, new AstImportEqualsDeclarationData(), ImportEqualsDeclaration); + return new AstNode(SyntaxKind.ImportEqualsDeclaration, new AstImportEqualsDeclarationData(), AnyNode /* ImportEqualsDeclaration */); } static ExternalModuleReference(): AstExternalModuleReference { - return new AstNode(SyntaxKind.ExternalModuleReference, new AstExternalModuleReferenceData(), ExternalModuleReference); + return new AstNode(SyntaxKind.ExternalModuleReference, new AstExternalModuleReferenceData(), AnyNode /* ExternalModuleReference */); } static ImportDeclaration(): AstImportDeclaration { - return new AstNode(SyntaxKind.ImportDeclaration, new AstImportDeclarationData(), ImportDeclaration); + return new AstNode(SyntaxKind.ImportDeclaration, new AstImportDeclarationData(), AnyNode /* ImportDeclaration */); } static ImportClause(): AstImportClause { - return new AstNode(SyntaxKind.ImportClause, new AstImportClauseData(), ImportClause); + return new AstNode(SyntaxKind.ImportClause, new AstImportClauseData(), AnyNode /* ImportClause */); } static ImportAttribute(): AstImportAttribute { - return new AstNode(SyntaxKind.ImportAttribute, new AstImportAttributeData(), ImportAttribute); + return new AstNode(SyntaxKind.ImportAttribute, new AstImportAttributeData(), AnyNode /* ImportAttribute */); } static ImportAttributes(): AstImportAttributes { - return new AstNode(SyntaxKind.ImportAttributes, new AstImportAttributesData(), ImportAttributes); + return new AstNode(SyntaxKind.ImportAttributes, new AstImportAttributesData(), AnyNode /* ImportAttributes */); } static NamespaceImport(): AstNamespaceImport { - return new AstNode(SyntaxKind.NamespaceImport, new AstNamespaceImportData(), NamespaceImport); + return new AstNode(SyntaxKind.NamespaceImport, new AstNamespaceImportData(), AnyNode /* NamespaceImport */); } static NamespaceExport(): AstNamespaceExport { - return new AstNode(SyntaxKind.NamespaceExport, new AstNamespaceExportData(), NamespaceExport); + return new AstNode(SyntaxKind.NamespaceExport, new AstNamespaceExportData(), AnyNode /* NamespaceExport */); } static NamespaceExportDeclaration(): AstNamespaceExportDeclaration { - return new AstNode(SyntaxKind.NamespaceExportDeclaration, new AstNamespaceExportDeclarationData(), NamespaceExportDeclaration); + return new AstNode(SyntaxKind.NamespaceExportDeclaration, new AstNamespaceExportDeclarationData(), AnyNode /* NamespaceExportDeclaration */); } static ExportDeclaration(): AstExportDeclaration { - return new AstNode(SyntaxKind.ExportDeclaration, new AstExportDeclarationData(), ExportDeclaration); + return new AstNode(SyntaxKind.ExportDeclaration, new AstExportDeclarationData(), AnyNode /* ExportDeclaration */); } static NamedImports(): AstNamedImports { - return new AstNode(SyntaxKind.NamedImports, new AstNamedImportsData(), NamedImports); + return new AstNode(SyntaxKind.NamedImports, new AstNamedImportsData(), AnyNode /* NamedImports */); } static NamedExports(): AstNamedExports { - return new AstNode(SyntaxKind.NamedExports, new AstNamedExportsData(), NamedExports); + return new AstNode(SyntaxKind.NamedExports, new AstNamedExportsData(), AnyNode /* NamedExports */); } static ImportSpecifier(): AstImportSpecifier { - return new AstNode(SyntaxKind.ImportSpecifier, new AstImportSpecifierData(), ImportSpecifier); + return new AstNode(SyntaxKind.ImportSpecifier, new AstImportSpecifierData(), AnyNode /* ImportSpecifier */); } static ExportSpecifier(): AstExportSpecifier { - return new AstNode(SyntaxKind.ExportSpecifier, new AstExportSpecifierData(), ExportSpecifier); + return new AstNode(SyntaxKind.ExportSpecifier, new AstExportSpecifierData(), AnyNode /* ExportSpecifier */); } static ExportAssignment(): AstExportAssignment { - return new AstNode(SyntaxKind.ExportAssignment, new AstExportAssignmentData(), ExportAssignment); + return new AstNode(SyntaxKind.ExportAssignment, new AstExportAssignmentData(), AnyNode /* ExportAssignment */); } static JSDocTypeExpression(): AstJSDocTypeExpression { - return new AstNode(SyntaxKind.JSDocTypeExpression, new AstJSDocTypeExpressionData(), JSDocTypeExpression); + return new AstNode(SyntaxKind.JSDocTypeExpression, new AstJSDocTypeExpressionData(), AnyNode /* JSDocTypeExpression */); } static JSDocNameReference(): AstJSDocNameReference { - return new AstNode(SyntaxKind.JSDocNameReference, new AstJSDocNameReferenceData(), JSDocNameReference); + return new AstNode(SyntaxKind.JSDocNameReference, new AstJSDocNameReferenceData(), AnyNode /* JSDocNameReference */); } static JSDocMemberName(): AstJSDocMemberName { - return new AstNode(SyntaxKind.JSDocMemberName, new AstJSDocMemberNameData(), JSDocMemberName); + return new AstNode(SyntaxKind.JSDocMemberName, new AstJSDocMemberNameData(), AnyNode /* JSDocMemberName */); } static JSDocAllType(): AstJSDocAllType { - return new AstNode(SyntaxKind.JSDocAllType, new AstJSDocAllTypeData(), JSDocAllType); + return new AstNode(SyntaxKind.JSDocAllType, new AstJSDocAllTypeData(), AnyNode /* JSDocAllType */); } static JSDocUnknownType(): AstJSDocUnknownType { - return new AstNode(SyntaxKind.JSDocUnknownType, new AstJSDocUnknownTypeData(), JSDocUnknownType); + return new AstNode(SyntaxKind.JSDocUnknownType, new AstJSDocUnknownTypeData(), AnyNode /* JSDocUnknownType */); } static JSDocNonNullableType(): AstJSDocNonNullableType { - return new AstNode(SyntaxKind.JSDocNonNullableType, new AstJSDocNonNullableTypeData(), JSDocNonNullableType); + return new AstNode(SyntaxKind.JSDocNonNullableType, new AstJSDocNonNullableTypeData(), AnyNode /* JSDocNonNullableType */); } static JSDocNullableType(): AstJSDocNullableType { - return new AstNode(SyntaxKind.JSDocNullableType, new AstJSDocNullableTypeData(), JSDocNullableType); + return new AstNode(SyntaxKind.JSDocNullableType, new AstJSDocNullableTypeData(), AnyNode /* JSDocNullableType */); } static JSDocOptionalType(): AstJSDocOptionalType { - return new AstNode(SyntaxKind.JSDocOptionalType, new AstJSDocOptionalTypeData(), JSDocOptionalType); + return new AstNode(SyntaxKind.JSDocOptionalType, new AstJSDocOptionalTypeData(), AnyNode /* JSDocOptionalType */); } static JSDocFunctionType(): AstJSDocFunctionType { - return new AstNode(SyntaxKind.JSDocFunctionType, new AstJSDocFunctionTypeData(), JSDocFunctionType); + return new AstNode(SyntaxKind.JSDocFunctionType, new AstJSDocFunctionTypeData(), AnyNode /* JSDocFunctionType */); } static JSDocVariadicType(): AstJSDocVariadicType { - return new AstNode(SyntaxKind.JSDocVariadicType, new AstJSDocVariadicTypeData(), JSDocVariadicType); + return new AstNode(SyntaxKind.JSDocVariadicType, new AstJSDocVariadicTypeData(), AnyNode /* JSDocVariadicType */); } static JSDocNamepathType(): AstJSDocNamepathType { - return new AstNode(SyntaxKind.JSDocNamepathType, new AstJSDocNamepathTypeData(), JSDocNamepathType); + return new AstNode(SyntaxKind.JSDocNamepathType, new AstJSDocNamepathTypeData(), AnyNode /* JSDocNamepathType */); } static JSDocNode(): AstJSDoc { - return new AstNode(SyntaxKind.JSDoc, new AstJSDocData(), JSDoc); + return new AstNode(SyntaxKind.JSDoc, new AstJSDocData(), AnyNode /* JSDoc */); } static JSDocLink(): AstJSDocLink { - return new AstNode(SyntaxKind.JSDocLink, new AstJSDocLinkData(), JSDocLink); + return new AstNode(SyntaxKind.JSDocLink, new AstJSDocLinkData(), AnyNode /* JSDocLink */); } static JSDocLinkCode(): AstJSDocLinkCode { - return new AstNode(SyntaxKind.JSDocLinkCode, new AstJSDocLinkCodeData(), JSDocLinkCode); + return new AstNode(SyntaxKind.JSDocLinkCode, new AstJSDocLinkCodeData(), AnyNode /* JSDocLinkCode */); } static JSDocLinkPlain(): AstJSDocLinkPlain { - return new AstNode(SyntaxKind.JSDocLinkPlain, new AstJSDocLinkPlainData(), JSDocLinkPlain); + return new AstNode(SyntaxKind.JSDocLinkPlain, new AstJSDocLinkPlainData(), AnyNode /* JSDocLinkPlain */); } static JSDocText(): AstJSDocText { - return new AstNode(SyntaxKind.JSDocText, new AstJSDocTextData(), JSDocText); + return new AstNode(SyntaxKind.JSDocText, new AstJSDocTextData(), AnyNode /* JSDocText */); } static JSDocUnknownTag(): AstJSDocUnknownTag { - return new AstNode(SyntaxKind.JSDocTag, new AstJSDocUnknownTagData(), JSDocUnknownTag); + return new AstNode(SyntaxKind.JSDocTag, new AstJSDocUnknownTagData(), AnyNode /* JSDocUnknownTag */); } static JSDocAugmentsTag(): AstJSDocAugmentsTag { - return new AstNode(SyntaxKind.JSDocAugmentsTag, new AstJSDocAugmentsTagData(), JSDocAugmentsTag); + return new AstNode(SyntaxKind.JSDocAugmentsTag, new AstJSDocAugmentsTagData(), AnyNode /* JSDocAugmentsTag */); } static JSDocImplementsTag(): AstJSDocImplementsTag { - return new AstNode(SyntaxKind.JSDocImplementsTag, new AstJSDocImplementsTagData(), JSDocImplementsTag); + return new AstNode(SyntaxKind.JSDocImplementsTag, new AstJSDocImplementsTagData(), AnyNode /* JSDocImplementsTag */); } static JSDocAuthorTag(): AstJSDocAuthorTag { - return new AstNode(SyntaxKind.JSDocAuthorTag, new AstJSDocAuthorTagData(), JSDocAuthorTag); + return new AstNode(SyntaxKind.JSDocAuthorTag, new AstJSDocAuthorTagData(), AnyNode /* JSDocAuthorTag */); } static JSDocDeprecatedTag(): AstJSDocDeprecatedTag { - return new AstNode(SyntaxKind.JSDocDeprecatedTag, new AstJSDocDeprecatedTagData(), JSDocDeprecatedTag); + return new AstNode(SyntaxKind.JSDocDeprecatedTag, new AstJSDocDeprecatedTagData(), AnyNode /* JSDocDeprecatedTag */); } static JSDocClassTag(): AstJSDocClassTag { - return new AstNode(SyntaxKind.JSDocClassTag, new AstJSDocClassTagData(), JSDocClassTag); + return new AstNode(SyntaxKind.JSDocClassTag, new AstJSDocClassTagData(), AnyNode /* JSDocClassTag */); } static JSDocPublicTag(): AstJSDocPublicTag { - return new AstNode(SyntaxKind.JSDocPublicTag, new AstJSDocPublicTagData(), JSDocPublicTag); + return new AstNode(SyntaxKind.JSDocPublicTag, new AstJSDocPublicTagData(), AnyNode /* JSDocPublicTag */); } static JSDocPrivateTag(): AstJSDocPrivateTag { - return new AstNode(SyntaxKind.JSDocPrivateTag, new AstJSDocPrivateTagData(), JSDocPrivateTag); + return new AstNode(SyntaxKind.JSDocPrivateTag, new AstJSDocPrivateTagData(), AnyNode /* JSDocPrivateTag */); } static JSDocProtectedTag(): AstJSDocProtectedTag { - return new AstNode(SyntaxKind.JSDocProtectedTag, new AstJSDocProtectedTagData(), JSDocProtectedTag); + return new AstNode(SyntaxKind.JSDocProtectedTag, new AstJSDocProtectedTagData(), AnyNode /* JSDocProtectedTag */); } static JSDocReadonlyTag(): AstJSDocReadonlyTag { - return new AstNode(SyntaxKind.JSDocReadonlyTag, new AstJSDocReadonlyTagData(), JSDocReadonlyTag); + return new AstNode(SyntaxKind.JSDocReadonlyTag, new AstJSDocReadonlyTagData(), AnyNode /* JSDocReadonlyTag */); } static JSDocOverrideTag(): AstJSDocOverrideTag { - return new AstNode(SyntaxKind.JSDocOverrideTag, new AstJSDocOverrideTagData(), JSDocOverrideTag); + return new AstNode(SyntaxKind.JSDocOverrideTag, new AstJSDocOverrideTagData(), AnyNode /* JSDocOverrideTag */); } static JSDocEnumTag(): AstJSDocEnumTag { - return new AstNode(SyntaxKind.JSDocEnumTag, new AstJSDocEnumTagData(), JSDocEnumTag); + return new AstNode(SyntaxKind.JSDocEnumTag, new AstJSDocEnumTagData(), AnyNode /* JSDocEnumTag */); } static JSDocThisTag(): AstJSDocThisTag { - return new AstNode(SyntaxKind.JSDocThisTag, new AstJSDocThisTagData(), JSDocThisTag); + return new AstNode(SyntaxKind.JSDocThisTag, new AstJSDocThisTagData(), AnyNode /* JSDocThisTag */); } static JSDocTemplateTag(): AstJSDocTemplateTag { - return new AstNode(SyntaxKind.JSDocTemplateTag, new AstJSDocTemplateTagData(), JSDocTemplateTag); + return new AstNode(SyntaxKind.JSDocTemplateTag, new AstJSDocTemplateTagData(), AnyNode /* JSDocTemplateTag */); } static JSDocSeeTag(): AstJSDocSeeTag { - return new AstNode(SyntaxKind.JSDocSeeTag, new AstJSDocSeeTagData(), JSDocSeeTag); + return new AstNode(SyntaxKind.JSDocSeeTag, new AstJSDocSeeTagData(), AnyNode /* JSDocSeeTag */); } static JSDocReturnTag(): AstJSDocReturnTag { - return new AstNode(SyntaxKind.JSDocReturnTag, new AstJSDocReturnTagData(), JSDocReturnTag); + return new AstNode(SyntaxKind.JSDocReturnTag, new AstJSDocReturnTagData(), AnyNode /* JSDocReturnTag */); } static JSDocTypeTag(): AstJSDocTypeTag { - return new AstNode(SyntaxKind.JSDocTypeTag, new AstJSDocTypeTagData(), JSDocTypeTag); + return new AstNode(SyntaxKind.JSDocTypeTag, new AstJSDocTypeTagData(), AnyNode /* JSDocTypeTag */); } static JSDocTypedefTag(): AstJSDocTypedefTag { - return new AstNode(SyntaxKind.JSDocTypedefTag, new AstJSDocTypedefTagData(), JSDocTypedefTag); + return new AstNode(SyntaxKind.JSDocTypedefTag, new AstJSDocTypedefTagData(), AnyNode /* JSDocTypedefTag */); } static JSDocCallbackTag(): AstJSDocCallbackTag { - return new AstNode(SyntaxKind.JSDocCallbackTag, new AstJSDocCallbackTagData(), JSDocCallbackTag); + return new AstNode(SyntaxKind.JSDocCallbackTag, new AstJSDocCallbackTagData(), AnyNode /* JSDocCallbackTag */); } static JSDocOverloadTag(): AstJSDocOverloadTag { - return new AstNode(SyntaxKind.JSDocOverloadTag, new AstJSDocOverloadTagData(), JSDocOverloadTag); + return new AstNode(SyntaxKind.JSDocOverloadTag, new AstJSDocOverloadTagData(), AnyNode /* JSDocOverloadTag */); } static JSDocThrowsTag(): AstJSDocThrowsTag { - return new AstNode(SyntaxKind.JSDocThrowsTag, new AstJSDocThrowsTagData(), JSDocThrowsTag); + return new AstNode(SyntaxKind.JSDocThrowsTag, new AstJSDocThrowsTagData(), AnyNode /* JSDocThrowsTag */); } static JSDocSignature(): AstJSDocSignature { - return new AstNode(SyntaxKind.JSDocSignature, new AstJSDocSignatureData(), JSDocSignature); + return new AstNode(SyntaxKind.JSDocSignature, new AstJSDocSignatureData(), AnyNode /* JSDocSignature */); } static JSDocPropertyTag(): AstJSDocPropertyTag { - return new AstNode(SyntaxKind.JSDocPropertyTag, new AstJSDocPropertyTagData(), JSDocPropertyTag); + return new AstNode(SyntaxKind.JSDocPropertyTag, new AstJSDocPropertyTagData(), AnyNode /* JSDocPropertyTag */); } static JSDocParameterTag(): AstJSDocParameterTag { - return new AstNode(SyntaxKind.JSDocParameterTag, new AstJSDocParameterTagData(), JSDocParameterTag); + return new AstNode(SyntaxKind.JSDocParameterTag, new AstJSDocParameterTagData(), AnyNode /* JSDocParameterTag */); } static JSDocTypeLiteral(): AstJSDocTypeLiteral { - return new AstNode(SyntaxKind.JSDocTypeLiteral, new AstJSDocTypeLiteralData(), JSDocTypeLiteral); + return new AstNode(SyntaxKind.JSDocTypeLiteral, new AstJSDocTypeLiteralData(), AnyNode /* JSDocTypeLiteral */); } static JSDocSatisfiesTag(): AstJSDocSatisfiesTag { - return new AstNode(SyntaxKind.JSDocSatisfiesTag, new AstJSDocSatisfiesTagData(), JSDocSatisfiesTag); + return new AstNode(SyntaxKind.JSDocSatisfiesTag, new AstJSDocSatisfiesTagData(), AnyNode /* JSDocSatisfiesTag */); } static JSDocImportTag(): AstJSDocImportTag { - return new AstNode(SyntaxKind.JSDocImportTag, new AstJSDocImportTagData(), JSDocImportTag); + return new AstNode(SyntaxKind.JSDocImportTag, new AstJSDocImportTagData(), AnyNode /* JSDocImportTag */); } static SourceFile(): AstSourceFile { return new AstNode(SyntaxKind.SourceFile, new AstSourceFileData(), SourceFile); } static SyntheticExpression(): AstSyntheticExpression { - return new AstNode(SyntaxKind.SyntheticExpression, new AstSyntheticExpressionData(), SyntheticExpression); + return new AstNode(SyntaxKind.SyntheticExpression, new AstSyntheticExpressionData(), AnyNode /* SyntheticExpression */); } static Bundle(): AstBundle { return new AstNode(SyntaxKind.Bundle, new AstBundleData(), Bundle); @@ -1304,19 +1306,19 @@ export class AstNode = Node extends Node { + declare _literalExpressionBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _declarationBrand: any; + declare _signatureDeclarationBrand: any; + declare _typeElementBrand: any; + declare _jsdocContainerBrand: any; + declare _localsContainerBrand: any; + declare _flowContainerBrand: any; + declare _classElementBrand: any; + declare _objectLiteralBrand: any; + declare _functionLikeDeclarationBrand: any; + declare _typeNodeBrand: any; + declare _statementBrand: any; + declare _jsDocTypeBrand: any; + + override getChildCount(sourceFile?: SourceFileLike): number { + if (isTokenKind(this.kind)) { + return this.getChildren().length; + } + return super.getChildCount(sourceFile); + } + + override getChildAt(index: number, sourceFile?: SourceFileLike): Node { + if (isTokenKind(this.kind)) { + return this.getChildren()[index]; + } + return super.getChildAt(index, sourceFile); + } + + override getChildren(sourceFile?: SourceFileLike): readonly Node[] { + if (isTokenKind(this.kind)) { + return this.kind === SyntaxKind.EndOfFileToken ? (this as Node as EndOfFileToken).jsDoc ?? emptyArray : emptyArray; + } + return super.getChildren(sourceFile); + } + + override getFirstToken(sourceFile?: SourceFileLike): Node | undefined { + if (isTokenKind(this.kind)) { + return undefined; + } + return super.getFirstToken(sourceFile); + } + + override getLastToken(sourceFile?: SourceFileLike): Node | undefined { + if (isTokenKind(this.kind)) { + return undefined; + } + return super.getLastToken(sourceFile); + } + + override forEachChild(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined { + if (isTokenKind(this.kind)) { + return undefined; + } + return super.forEachChild(cbNode, cbNodeArray); + } + + override get parent(): any { return super.parent; } + override set parent(value) { super.parent = value; } + + get left() { return this.ast.data.left?.node; } + set left(value) { this.ast.data.left = value?.ast; } + get right() { return this.ast.data.right?.node; } + set right(value) { this.ast.data.right = value?.ast; } + get expression() { return this.ast.data.expression?.node; } + set expression(value) { this.ast.data.expression = value?.ast; } + get modifiers() { return this.ast.data.modifiers?.nodes; } + set modifiers(value) { this.ast.data.modifiers = value?.ast; } + get name() { return this.ast.data.name?.node; } + set name(value) { this.ast.data.name = value?.ast; } + get constraint() { return this.ast.data.constraint?.node; } + set constraint(value) { this.ast.data.constraint = value?.ast; } + get default() { return this.ast.data.default?.node; } + set default(value) { this.ast.data.default = value?.ast; } + get typeParameters() { return this.ast.data.typeParameters?.nodes; } + set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } + get parameters() { return this.ast.data.parameters?.nodes; } + set parameters(value) { this.ast.data.parameters = value?.ast; } + get type() { + if (this.kind === SyntaxKind.SyntheticExpression) { + return this.ast.data.type; + } + return this.ast.data.type?.node; + } + set type(value) { + if (this.kind === SyntaxKind.SyntheticExpression) { + this.ast.data.type = value; + } + else { + this.ast.data.type = value?.ast; + } + } + get typeArguments() { return this.ast.data.typeArguments?.nodes; } + set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } + get exclamationToken() { return this.ast.data.exclamationToken?.node; } + set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } + get initializer() { return this.ast.data.initializer?.node; } + set initializer(value) { this.ast.data.initializer = value?.ast; } + get declarations() { return this.ast.data.declarations.nodes; } + set declarations(value) { this.ast.data.declarations = value.ast; } + get dotDotDotToken() { return this.ast.data.dotDotDotToken?.node; } + set dotDotDotToken(value) { this.ast.data.dotDotDotToken = value?.ast; } + get questionToken() { return this.ast.data.questionToken?.node; } + set questionToken(value) { this.ast.data.questionToken = value?.ast; } + get propertyName() { return this.ast.data.propertyName?.node; } + set propertyName(value) { this.ast.data.propertyName = value?.ast; } + get equalsToken() { return this.ast.data.equalsToken?.node; } + set equalsToken(value) { this.ast.data.equalsToken = value?.ast; } + get objectAssignmentInitializer() { return this.ast.data.objectAssignmentInitializer?.node; } + set objectAssignmentInitializer(value) { this.ast.data.objectAssignmentInitializer = value?.ast; } + get elements() { return this.ast.data.elements.nodes; } + set elements(value) { this.ast.data.elements = value.ast; } + get asteriskToken() { return this.ast.data.asteriskToken?.node; } + set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } + get body() { return this.ast.data.body?.node; } + set body(value) { this.ast.data.body = value?.ast; } + get assertClause() { return this.ast.data.assertClause?.node; } + set assertClause(value) { this.ast.data.assertClause = value?.ast; } + get multiLine() { return this.ast.data.multiLine; } + set multiLine(value) { this.ast.data.multiLine = value; } + get isTypeOf() { return this.ast.data.isTypeOf; } + set isTypeOf(value) { this.ast.data.isTypeOf = value; } + get argument() { return this.ast.data.argument.node; } + set argument(value) { this.ast.data.argument = value.ast; } + get attributes() { return this.ast.data.attributes?.node; } + set attributes(value) { this.ast.data.attributes = value?.ast; } + get assertions() { return this.ast.data.assertions?.node; } + set assertions(value) { this.ast.data.assertions = value?.ast; } + get qualifier() { return this.ast.data.qualifier?.node; } + set qualifier(value) { this.ast.data.qualifier = value?.ast; } + get typeName() { return this.ast.data.typeName.node; } + set typeName(value) { this.ast.data.typeName = value.ast; } + get assertsModifier() { return this.ast.data.assertsModifier?.node; } + set assertsModifier(value) { this.ast.data.assertsModifier = value?.ast; } + get parameterName() { return this.ast.data.parameterName.node; } + set parameterName(value) { this.ast.data.parameterName = value.ast; } + get exprName() { return this.ast.data.exprName.node; } + set exprName(value) { this.ast.data.exprName = value.ast; } + get members() { return this.ast.data.members?.nodes; } + set members(value) { this.ast.data.members = value?.ast; } + get elementType() { return this.ast.data.elementType.node; } + set elementType(value) { this.ast.data.elementType = value.ast; } + get types() { return this.ast.data.types.nodes; } + set types(value) { this.ast.data.types = value.ast; } + get checkType() { return this.ast.data.checkType.node; } + set checkType(value) { this.ast.data.checkType = value.ast; } + get extendsType() { return this.ast.data.extendsType.node; } + set extendsType(value) { this.ast.data.extendsType = value.ast; } + get trueType() { return this.ast.data.trueType.node; } + set trueType(value) { this.ast.data.trueType = value.ast; } + get falseType() { return this.ast.data.falseType.node; } + set falseType(value) { this.ast.data.falseType = value.ast; } + get typeParameter() { return this.ast.data.typeParameter.node; } + set typeParameter(value) { this.ast.data.typeParameter = value.ast; } + get operator() { return this.ast.data.operator; } + set operator(value) { this.ast.data.operator = value; } + get objectType() { return this.ast.data.objectType.node; } + set objectType(value) { this.ast.data.objectType = value.ast; } + get indexType() { return this.ast.data.indexType.node; } + set indexType(value) { this.ast.data.indexType = value.ast; } + get readonlyToken() { return this.ast.data.readonlyToken?.node; } + set readonlyToken(value) { this.ast.data.readonlyToken = value?.ast; } + get nameType() { return this.ast.data.nameType?.node; } + set nameType(value) { this.ast.data.nameType = value?.ast; } + get literal() { return this.ast.data.literal.node; } + set literal(value) { this.ast.data.literal = value.ast; } + get head() { return this.ast.data.head.node; } + set head(value) { this.ast.data.head = value.ast; } + get templateSpans() { return this.ast.data.templateSpans.nodes; } + set templateSpans(value) { this.ast.data.templateSpans = value.ast; } + get operand() { return this.ast.data.operand.node; } + set operand(value) { this.ast.data.operand = value.ast; } + get isSpread() { return this.ast.data.isSpread; } + set isSpread(value) { this.ast.data.isSpread = value; } + get tupleNameSource() { return this.ast.data.tupleNameSource?.node; } + set tupleNameSource(value) { this.ast.data.tupleNameSource = value?.ast; } + get operatorToken() { return this.ast.data.operatorToken.node; } + set operatorToken(value) { this.ast.data.operatorToken = value.ast; } + get condition() { return this.ast.data.condition?.node; } + set condition(value) { this.ast.data.condition = value?.ast; } + get whenTrue() { return this.ast.data.whenTrue.node; } + set whenTrue(value) { this.ast.data.whenTrue = value.ast; } + get colonToken() { return this.ast.data.colonToken.node; } + set colonToken(value) { this.ast.data.colonToken = value.ast; } + get whenFalse() { return this.ast.data.whenFalse.node; } + set whenFalse(value) { this.ast.data.whenFalse = value.ast; } + get equalsGreaterThanToken() { return this.ast.data.equalsGreaterThanToken.node; } + set equalsGreaterThanToken(value) { this.ast.data.equalsGreaterThanToken = value.ast; } + get properties() { return this.ast.data.properties?.nodes; } + set properties(value) { this.ast.data.properties = value?.ast; } + get questionDotToken() { return this.ast.data.questionDotToken?.node; } + set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } + get argumentExpression() { return this.ast.data.argumentExpression.node; } + set argumentExpression(value) { this.ast.data.argumentExpression = value.ast; } + get arguments() { return this.ast.data.arguments?.nodes; } + set arguments(value) { this.ast.data.arguments = value?.ast; } + get tag() { return this.ast.data.tag.node; } + set tag(value) { this.ast.data.tag = value.ast; } + get template() { return this.ast.data.template.node; } + set template(value) { this.ast.data.template = value.ast; } + get keywordToken() { return this.ast.data.keywordToken; } + set keywordToken(value) { this.ast.data.keywordToken = value; } + get openingElement() { return this.ast.data.openingElement.node; } + set openingElement(value) { this.ast.data.openingElement = value.ast; } + get children() { return this.ast.data.children.nodes; } + set children(value) { this.ast.data.children = value.ast; } + get closingElement() { return this.ast.data.closingElement.node; } + set closingElement(value) { this.ast.data.closingElement = value.ast; } + get namespace() { return this.ast.data.namespace.node; } + set namespace(value) { this.ast.data.namespace = value.ast; } + get tagName() { return this.ast.data.tagName.node; } + set tagName(value) { this.ast.data.tagName = value.ast; } + get openingFragment() { return this.ast.data.openingFragment.node; } + set openingFragment(value) { this.ast.data.openingFragment = value.ast; } + get closingFragment() { return this.ast.data.closingFragment.node; } + set closingFragment(value) { this.ast.data.closingFragment = value.ast; } + get thisArg() { return this.ast.data.thisArg.node; } + set thisArg(value) { this.ast.data.thisArg = value.ast; } + get statements() { return this.ast.data.statements.nodes; } + set statements(value) { this.ast.data.statements = value.ast; } + get declarationList() { return this.ast.data.declarationList.node; } + set declarationList(value) { this.ast.data.declarationList = value.ast; } + get thenStatement() { return this.ast.data.thenStatement.node; } + set thenStatement(value) { this.ast.data.thenStatement = value.ast; } + get elseStatement() { return this.ast.data.elseStatement?.node; } + set elseStatement(value) { this.ast.data.elseStatement = value?.ast; } + get statement() { return this.ast.data.statement.node; } + set statement(value) { this.ast.data.statement = value.ast; } + get incrementor() { return this.ast.data.incrementor?.node; } + set incrementor(value) { this.ast.data.incrementor = value?.ast; } + get awaitModifier() { return this.ast.data.awaitModifier?.node; } + set awaitModifier(value) { this.ast.data.awaitModifier = value?.ast; } + get label() { return this.ast.data.label?.node; } + set label(value) { this.ast.data.label = value?.ast; } + get caseBlock() { return this.ast.data.caseBlock.node; } + set caseBlock(value) { this.ast.data.caseBlock = value.ast; } + get possiblyExhaustive() { return this.ast.data.possiblyExhaustive; } + set possiblyExhaustive(value) { this.ast.data.possiblyExhaustive = value; } + get clauses() { return this.ast.data.clauses?.nodes; } + set clauses(value) { this.ast.data.clauses = value?.ast; } + get tryBlock() { return this.ast.data.tryBlock.node; } + set tryBlock(value) { this.ast.data.tryBlock = value.ast; } + get catchClause() { return this.ast.data.catchClause?.node; } + set catchClause(value) { this.ast.data.catchClause = value?.ast; } + get finallyBlock() { return this.ast.data.finallyBlock?.node; } + set finallyBlock(value) { this.ast.data.finallyBlock = value?.ast; } + get variableDeclaration() { return this.ast.data.variableDeclaration?.node; } + set variableDeclaration(value) { this.ast.data.variableDeclaration = value?.ast; } + get block() { return this.ast.data.block?.node; } + set block(value) { this.ast.data.block = value?.ast; } + get heritageClauses() { return this.ast.data.heritageClauses?.nodes; } + set heritageClauses(value) { this.ast.data.heritageClauses = value?.ast; } + get token() { return this.ast.data.token; } + set token(value) { this.ast.data.token = value; } + get isTypeOnly() { return this.ast.data.isTypeOnly; } + set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } + get moduleReference() { return this.ast.data.moduleReference.node; } + set moduleReference(value) { this.ast.data.moduleReference = value.ast; } + get importClause() { return this.ast.data.importClause?.node; } + set importClause(value) { this.ast.data.importClause = value?.ast; } + get moduleSpecifier() { return this.ast.data.moduleSpecifier?.node; } + set moduleSpecifier(value) { this.ast.data.moduleSpecifier = value?.ast; } + get namedBindings() { return this.ast.data.namedBindings?.node; } + set namedBindings(value) { this.ast.data.namedBindings = value?.ast; } + get value() { return this.ast.data.value.node; } + set value(value) { this.ast.data.value = value.ast; } + get exportClause() { return this.ast.data.exportClause?.node; } + set exportClause(value) { this.ast.data.exportClause = value?.ast; } + get isExportEquals() { return this.ast.data.isExportEquals; } + set isExportEquals(value) { this.ast.data.isExportEquals = value; } + get postfix() { return this.ast.data.postfix; } + set postfix(value) { this.ast.data.postfix = value; } + get tags() { return this.ast.data.tags?.nodes; } + set tags(value) { this.ast.data.tags = value?.ast; } + get comment() { + const comment = this.ast.data.comment; + return typeof comment === "string" ? comment : comment?.nodes; + } + set comment(value) { this.ast.data.comment = typeof value === "string" ? value : value?.ast; } + get class() { return this.ast.data.class.node; } + set class(value) { this.ast.data.class = value.ast; } + get typeExpression() { return this.ast.data.typeExpression?.node; } + set typeExpression(value) { this.ast.data.typeExpression = value?.ast; } + get fullName() { return this.ast.data.fullName?.node; } + set fullName(value) { this.ast.data.fullName = value?.ast; } + get isNameFirst() { return this.ast.data.isNameFirst; } + set isNameFirst(value) { this.ast.data.isNameFirst = value; } + get isBracketed() { return this.ast.data.isBracketed; } + set isBracketed(value) { this.ast.data.isBracketed = value; } + get jsDocPropertyTags() { return this.ast.data.jsDocPropertyTags?.nodes; } + set jsDocPropertyTags(value) { this.ast.data.jsDocPropertyTags = value?.ast; } + get isArrayType() { return this.ast.data.isArrayType; } + set isArrayType(value) { this.ast.data.isArrayType = value; } + get escapedText() { return this.ast.data.escapedText; } + set escapedText(value) { this.ast.data.escapedText = value; } + get text() { + switch (this.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.PrivateIdentifier: + return idText(this as unknown as Identifier | PrivateIdentifier); + default: + return this.data.text; + } + } + set text(value) { this.ast.data.text = value; } + get isUnterminated() { return this.ast.data.isUnterminated; } + set isUnterminated(value) { this.ast.data.isUnterminated = value; } + get hasExtendedUnicodeEscape() { return this.ast.data.hasExtendedUnicodeEscape; } + set hasExtendedUnicodeEscape(value) { this.ast.data.hasExtendedUnicodeEscape = value; } + get singleQuote() { return this.ast.data.singleQuote; } + set singleQuote(value) { this.ast.data.singleQuote = value; } + get textSourceNode() { return this.ast.data.textSourceNode?.node; } + set textSourceNode(value) { this.ast.data.textSourceNode = value?.ast; } + get rawText() { return this.ast.data.rawText; } + set rawText(value) { this.ast.data.rawText = value; } + get templateFlags() { return this.ast.data.templateFlags; } + set templateFlags(value) { this.ast.data.templateFlags = value; } + get numericLiteralFlags() { return this.ast.data.numericLiteralFlags; } + set numericLiteralFlags(value) { this.ast.data.numericLiteralFlags = value; } + get containsOnlyTriviaWhiteSpaces() { return this.ast.data.containsOnlyTriviaWhiteSpaces; } + set containsOnlyTriviaWhiteSpaces(value) { this.ast.data.containsOnlyTriviaWhiteSpaces = value; } + get resolvedSymbol() { return this.ast.data.resolvedSymbol; } + set resolvedSymbol(value) { this.ast.data.resolvedSymbol = value; } + get symbol() { return this.ast.data.symbol; } + set symbol(value) { this.ast.data.symbol = value; } + get localSymbol() { return this.ast.data.localSymbol; } + set localSymbol(value) { this.ast.data.localSymbol = value; } + get jsDoc() { return this.ast.data.jsDoc; } + set jsDoc(value) { this.ast.data.jsDoc = value; } + get flowNode() { return this.ast.data.flowNode; } + set flowNode(value) { this.ast.data.flowNode = value; } + get locals() { return this.ast.data.locals; } + set locals(value) { this.ast.data.locals = value; } + get nextContainer() { return this.ast.data.nextContainer?.node; } + set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } + get endFlowNode() { return this.ast.data.endFlowNode; } + set endFlowNode(value) { this.ast.data.endFlowNode = value; } + get returnFlowNode() { return this.ast.data.returnFlowNode; } + set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } + get fallthroughFlowNode() { return this.ast.data.fallthroughFlowNode; } + set fallthroughFlowNode(value) { this.ast.data.fallthroughFlowNode = value; } +} \ No newline at end of file diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 867b9baf91440..8388266c1014c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -335,7 +335,6 @@ import { writeFileEnsuringDirectories, PartialSourceFile, PackageJsonInfo, - JSDocParsingMode, } from "./_namespaces/ts.js"; import * as performance from "./_namespaces/ts.performance.js"; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6e4161fb4ac6f..84ae4ec30ae0a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5603,8 +5603,9 @@ export class SyntheticReferenceExpression extends Node Date: Wed, 2 Oct 2024 10:45:49 -0400 Subject: [PATCH 09/10] Temporary monomorphic Node projection --- src/compiler/ast.ts | 8 ++++---- src/compiler/types.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/ast.ts b/src/compiler/ast.ts index 11d3b356eb487..824bbc46a2298 100644 --- a/src/compiler/ast.ts +++ b/src/compiler/ast.ts @@ -940,19 +940,19 @@ export class AstNode = Node = Node = undefined!; constructor(ast: AstNode>) { - this.ast = ast as AstNode; Object.preventExtensions(this); + this.ast = ast as AstNode; } get kind(): K { return this.ast.kind; } @@ -5050,7 +5050,7 @@ export class CallExpression extends Node | undefined { return this.ast.data.typeArguments?.nodes; } get arguments(): NodeArray { return this.ast.data.arguments.nodes; } - + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } /** @internal */ set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } From 29d90a6d04444e51ae57729f4ddd468d2b4808ff Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 2 Oct 2024 18:35:44 -0400 Subject: [PATCH 10/10] Partial migration of utilities.ts, data property dispatch --- src/compiler/ast.ts | 3083 +++++++++++++++-- src/compiler/astForEachChild.ts | 26 +- src/compiler/binder.ts | 444 ++- src/compiler/checker.ts | 127 +- src/compiler/core.ts | 8 +- src/compiler/debug.ts | 2 + src/compiler/factory/astNodeFactory.ts | 140 +- src/compiler/factory/astNodeTests.ts | 537 ++- src/compiler/factory/astParenthesizerRules.ts | 84 +- src/compiler/factory/nodeTests.ts | 2 +- src/compiler/factory/utilities.ts | 27 +- src/compiler/nodes.ts | 214 +- src/compiler/parser.ts | 177 +- src/compiler/readonlyArray.ts | 116 + src/compiler/tsconfig.json | 3 +- src/compiler/types.ts | 501 ++- src/compiler/utilities.ts | 1495 ++++++-- src/compiler/utilitiesPublic.ts | 456 ++- src/compiler/visitorPublic.ts | 10 +- src/services/jsDoc.ts | 2 +- src/services/services.ts | 17 +- src/services/types.ts | 2 +- ...ocComments.parsesCorrectly.@link tags.json | 8 +- ...DocComments.parsesCorrectly.authorTag.json | 26 +- tests/baselines/reference/api/typescript.d.ts | 184 +- .../link-ParseForTypeInfo-file.ts.diff | 2 +- .../link-ParseNone-file.js.diff | 2 +- .../link-ParseNone-file.ts.diff | 2 +- .../see-ParseForTypeInfo-file.ts.diff | 6 +- .../see-ParseNone-file.js.diff | 6 +- .../see-ParseNone-file.ts.diff | 6 +- 31 files changed, 6111 insertions(+), 1604 deletions(-) create mode 100644 src/compiler/readonlyArray.ts diff --git a/src/compiler/ast.ts b/src/compiler/ast.ts index 824bbc46a2298..d1f54d5534012 100644 --- a/src/compiler/ast.ts +++ b/src/compiler/ast.ts @@ -118,14 +118,13 @@ import { getTransformFlagsSubtreeExclusions, HasChildren, HasDecorators, + HasExpression, HasJSDoc, HasLocals, HasModifiers, HasName, - hasProperty, HeritageClause, Identifier, - idText, IfStatement, ImportAttribute, ImportAttributeName, @@ -143,7 +142,9 @@ import { InKeyword, InterfaceDeclaration, IntersectionTypeNode, - isAstParenthesizedExpression, + astIsElementAccessExpression, + astIsParenthesizedExpression, + astIsPropertyAccessExpression, IScriptSnapshot, isLogicalOrCoalescingAssignmentOperator, isParseTreeNode, @@ -291,7 +292,6 @@ import { OptionalChainRoot, OptionalTypeNode, OuterExpression, - OuterExpressionKinds, OutKeyword, OverrideKeyword, PackageJsonInfo, @@ -402,9 +402,59 @@ import { VoidExpression, WhileStatement, WithStatement, - YieldExpression + YieldExpression, + HasFlowNode, + BindableStaticNameExpression, + BindableObjectDefinePropertyCall, + BindableStaticAccessExpression, + BindableStaticElementAccessExpression, + LiteralLikeElementAccessExpression, + AccessExpression, + WrappedExpression, + AssignmentExpression, + AssignmentOperatorToken, + BindableStaticPropertyAssignmentExpression, + BindablePropertyAssignmentExpression, + ThisContainer, + DynamicNamedDeclaration, + DynamicNamedBinaryExpression, + VariableLikeDeclaration, + HasInitializer, + AutoAccessorPropertyDeclaration, + PrologueDirective, + HasText, + AmbientModuleDeclaration, + NonGlobalAmbientModuleDeclaration, + HasSymbol, + HasType, + HasTypeParameters, + HasParameters, + HasBody, + HasQuestionToken, + HasEndFlowNode, + HasTypeArguments, + InternalHasTypeArguments, + HasElements, + HasMembers, + HasStatement, + HasExclamationToken, + HasAsteriskToken, + HasQuestionDotToken, + HasComment, + HasStatements, + astIdText, + HasTypes, + HasTagName, + HasIsTypeOnly, + InternalHasModifiers, } from "./_namespaces/ts.js"; +const cloneNodeMap: Partial AstNode>> = {}; +const createDataInstanceMap: Partial AstData>> = {}; +const copyDataPropertiesMap: Partial void>> = {}; +const shadowNodeMap: Partial AstNode>> = {}; +const shadowDataMap: Partial AstData>> = {}; + // dprint-ignore class AstNodeArrayExtraFields { /** @internal */ nodes: NodeArray | undefined = undefined; @@ -513,14 +563,14 @@ class AstNodeExtraFields { /** @internal */ __end: number = -1; } -let astNodeCloneCore: (node: AstNode) => AstNode; -let astNodeShadowCore: (node: AstNode) => AstNode; +let cloneNodeCore: (node: AstNode) => AstNode; +let shadowCore: (node: AstNode) => AstNode; // dprint-ignore export class AstNode = Node> { static { - astNodeCloneCore = node => node.cloneCore(); - astNodeShadowCore = node => node.shadowCore(); + cloneNodeCore = node => node.cloneCore(); + shadowCore = node => node.shadowCore(); } private _node: N | undefined = undefined; @@ -530,7 +580,7 @@ export class AstNode = Node> | undefined = undefined; // Parent node (initialized by binding) + parent: AstNodeOneOf = undefined!; // Parent node (initialized by binding) flags: NodeFlags = NodeFlags.None; pos = -1; end = -1; @@ -608,7 +658,7 @@ export class AstNode = Node = Node = Node = Node = Node; +/** @internal */ +export type AstHasEndFlowNode = AstNodeOneOf; /** @internal */ export type AstHasLocals = AstNodeOneOf; export type AstHasDecorators = AstNodeOneOf; export type AstHasModifiers = AstNodeOneOf; /** @internal */ +export type AstInternalHasModifiers = AstNodeOneOf; +/** @internal */ export type AstHasChildren = AstNodeOneOf; /** @internal */ +export type AstHasSymbol = AstNodeOneOf; +/** @internal */ +export type AstHasType = AstNodeOneOf; +/** @internal */ +export type AstHasTypes = AstNodeOneOf; +/** @internal */ +export type AstHasTypeParameters = AstNodeOneOf; +/** @internal */ +export type AstHasTypeArguments = AstNodeOneOf; +/** @internal */ +export type AstInternalHasTypeArguments = AstNodeOneOf; +/** @internal */ +export type AstHasParameters = AstNodeOneOf; +/** @internal */ +export type AstHasBody = AstNodeOneOf; +/** @internal */ +export type AstHasQuestionToken = AstNodeOneOf; +/** @internal */ +export type AstHasElements = AstNodeOneOf; +/** @internal */ +export type AstHasMembers = AstNodeOneOf; +/** @internal */ +export type AstHasStatement = AstNodeOneOf; +/** @internal */ +export type AstHasStatements = AstNodeOneOf; +/** @internal */ +export type AstHasExclamationToken = AstNodeOneOf; +/** @internal */ +export type AstHasAsteriskToken = AstNodeOneOf; +/** @internal */ +export type AstHasQuestionDotToken = AstNodeOneOf; +/** @internal */ +export type AstHasIsTypeOnly = AstNodeOneOf; +/** @internal */ +export type AstHasTagName = AstNodeOneOf; +/** @internal */ +export type AstHasComment = AstNodeOneOf; +/** @internal */ export type AstForEachChildNodes = AstNodeOneOf; export type AstDeclaration = AstNode; export type AstTypeNode = AstNode>; @@ -1490,6 +1528,10 @@ export type AstEndOfFileToken = AstNode; // dprint-ignore export class AstEndOfFileTokenData extends AstTokenData { /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + static { + createDataInstanceMap[SyntaxKind.EndOfFileToken] = _ => new this(); + } } export type AstThisExpression = AstNode; @@ -1497,6 +1539,10 @@ export type AstThisExpression = AstNode; // dprint-ignore export class AstThisExpressionData extends AstTokenData { /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + static { + createDataInstanceMap[SyntaxKind.ThisKeyword] = _ => new this(); + } } export type AstSuperExpression = AstNode; @@ -1504,6 +1550,10 @@ export type AstSuperExpression = AstNode; // dprint-ignore export class AstSuperExpressionData extends AstTokenData { /** @internal */ flowNode: FlowNode | undefined = undefined; // initialized by checker (FlowContainer) + + static { + createDataInstanceMap[SyntaxKind.SuperKeyword] = _ => new this(); + } } export type AstImportExpression = AstNode; @@ -1581,6 +1631,20 @@ export class AstIdentifierData extends AstTokenData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.Identifier] = _ => new AstIdentifierData(); + copyDataPropertiesMap[SyntaxKind.Identifier] = (data, clone) => { + Debug.assert(data instanceof this); + Debug.assert(clone instanceof this); + clone.escapedText = data.escapedText; + clone.resolvedSymbol = data.resolvedSymbol; + clone.jsDoc = data.jsDoc; + clone.symbol = data.symbol; + clone.localSymbol = data.localSymbol; + clone.flowNode = data.flowNode; + } + } } export type AstQualifiedName = AstNode; @@ -1596,6 +1660,10 @@ export class AstQualifiedNameData extends AstData { return propagateChildFlags(this.left) | propagateIdentifierNameFlags(this.right); } + + static { + createDataInstanceMap[SyntaxKind.QualifiedName] = _ => new this(); + } } export type AstEntityName = AstNodeOneOf; @@ -1614,6 +1682,10 @@ export class AstComputedPropertyNameData extends AstData { TransformFlags.ContainsES2015 | TransformFlags.ContainsComputedPropertyName; } + + static { + createDataInstanceMap[SyntaxKind.ComputedPropertyName] = _ => new this(); + } } export type AstPrivateIdentifier = AstNode; @@ -1625,6 +1697,10 @@ export class AstPrivateIdentifierData extends AstTokenData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsClassFields; } + + static { + createDataInstanceMap[SyntaxKind.PrivateIdentifier] = _ => new this(); + } } export type AstTypeParameterDeclaration = AstNode; @@ -1640,6 +1716,11 @@ export class AstTypeParameterDeclarationData extends AstTypeScriptNodeData { /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + + static { + createDataInstanceMap[SyntaxKind.TypeParameter] = _ => new this(); + } } export type AstParameterDeclaration = AstNode; @@ -1672,6 +1753,11 @@ export class AstParameterDeclarationData extends AstData { (this.dotDotDotToken ?? this.initializer ? TransformFlags.ContainsES2015 : TransformFlags.None) | (modifiersToFlags(this.modifiers?.items) & ModifierFlags.ParameterPropertyModifier ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None); } + + + static { + createDataInstanceMap[SyntaxKind.Parameter] = _ => new this(); + } } export type AstDecorator = AstNode; @@ -1686,6 +1772,10 @@ export class AstDecoratorData extends AstData { TransformFlags.ContainsTypeScriptClassSyntax | TransformFlags.ContainsDecorators; } + + static { + createDataInstanceMap[SyntaxKind.Decorator] = _ => new this(); + } } export type AstPropertySignature = AstNode; @@ -1701,6 +1791,11 @@ export class AstPropertySignatureData extends AstTypeScriptNodeData { /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + + static { + createDataInstanceMap[SyntaxKind.PropertySignature] = _ => new this(); + } } export type AstSignatureDeclaration = AstNodeOneOf; @@ -1718,6 +1813,11 @@ export class AstCallSignatureDeclarationData extends AstTypeScriptNodeData { /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + + static { + createDataInstanceMap[SyntaxKind.CallSignature] = _ => new this(); + } } export type AstConstructSignatureDeclaration = AstNode; @@ -1734,6 +1834,11 @@ export class AstConstructSignatureDeclarationData extends AstTypeScriptNodeData /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + + + static { + createDataInstanceMap[SyntaxKind.ConstructSignature] = _ => new this(); + } } export type AstVariableDeclaration = AstNode; @@ -1754,8 +1859,15 @@ export class AstVariableDeclarationData extends AstData { propagateChildFlags(this.initializer) | (this.exclamationToken ?? this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); } + + + static { + createDataInstanceMap[SyntaxKind.VariableDeclaration] = _ => new this(); + } } +export type AstVariableLikeDeclaration = AstNodeOneOf; + export type AstVariableDeclarationList = AstNode; // dprint-ignore @@ -1774,6 +1886,11 @@ export class AstVariableDeclarationListData extends AstData { } return transformFlags; } + + + static { + createDataInstanceMap[SyntaxKind.VariableDeclarationList] = _ => new this(); + } } export type AstBindingElement = AstNode; @@ -1797,9 +1914,14 @@ export class AstBindingElementData extends AstData { (this.dotDotDotToken ? TransformFlags.ContainsRestOrSpread : TransformFlags.None) | TransformFlags.ContainsES2015; } + + static { + createDataInstanceMap[SyntaxKind.BindingElement] = _ => new this(); + } } export type AstPropertyDeclaration = AstNode; +export type AstAutoAccessorPropertyDeclaration = AstNode; // dprint-ignore export class AstPropertyDeclarationData extends AstData { @@ -1825,6 +1947,10 @@ export class AstPropertyDeclarationData extends AstData { (this.name.kind === SyntaxKind.ComputedPropertyName || modifierFlags & ModifierFlags.Static && this.initializer ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None) | TransformFlags.ContainsClassFields; } + + static { + createDataInstanceMap[SyntaxKind.PropertyDeclaration] = _ => new this(); + } } export type AstPropertyAssignment = AstNode; @@ -1845,6 +1971,10 @@ export class AstPropertyAssignmentData extends AstData { return propagateNameFlags(this.name) | propagateChildFlags(this.initializer); } + + static { + createDataInstanceMap[SyntaxKind.PropertyAssignment] = _ => new this(); + } } export type AstShorthandPropertyAssignment = AstNode; @@ -1869,6 +1999,10 @@ export class AstShorthandPropertyAssignmentData extends AstData { propagateChildFlags(this.objectAssignmentInitializer) | TransformFlags.ContainsES2015; } + + static { + createDataInstanceMap[SyntaxKind.ShorthandPropertyAssignment] = _ => new this(); + } } export type AstSpreadAssignment = AstNode; @@ -1886,6 +2020,10 @@ export class AstSpreadAssignmentData extends AstData { TransformFlags.ContainsES2018 | TransformFlags.ContainsObjectRestOrSpread; } + + static { + createDataInstanceMap[SyntaxKind.SpreadAssignment] = _ => new this(); + } } export type AstBindingPattern = AstNodeOneOf; @@ -1904,6 +2042,10 @@ export class AstObjectBindingPatternData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.ObjectBindingPattern] = _ => new this(); + } } export type AstArrayBindingElement = AstNodeOneOf; @@ -1918,6 +2060,10 @@ export class AstArrayBindingPatternData extends AstData { TransformFlags.ContainsES2015 | TransformFlags.ContainsBindingPattern; } + + static { + createDataInstanceMap[SyntaxKind.ArrayBindingPattern] = _ => new this(); + } } export type AstFunctionDeclaration = AstNode; @@ -1965,6 +2111,10 @@ export class AstFunctionDeclarationData extends AstData { TransformFlags.ContainsHoistedDeclarationOrCompletion; } } + + static { + createDataInstanceMap[SyntaxKind.FunctionDeclaration] = _ => new this(); + } } // dprint-ignore @@ -1982,6 +2132,10 @@ export class AstMethodSignatureData extends AstTypeScriptNodeData { /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.MethodSignature] = _ => new this(); + } } // dprint-ignore @@ -2031,6 +2185,10 @@ export class AstMethodDeclarationData extends AstData { TransformFlags.ContainsES2015; } } + + static { + createDataInstanceMap[SyntaxKind.MethodDeclaration] = _ => new this(); + } } // dprint-ignore @@ -2061,6 +2219,10 @@ export class AstConstructorDeclarationData extends AstData { TransformFlags.ContainsES2015; } } + + static { + createDataInstanceMap[SyntaxKind.Constructor] = _ => new this(); + } } // dprint-ignore @@ -2070,6 +2232,10 @@ export class AstSemicolonClassElementData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; } + + static { + createDataInstanceMap[SyntaxKind.SemicolonClassElement] = _ => new this(); + } } // dprint-ignore @@ -2104,6 +2270,10 @@ export class AstGetAccessorDeclarationData extends AstData { (this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); } } + + static { + createDataInstanceMap[SyntaxKind.GetAccessor] = _ => new this(); + } } // dprint-ignore @@ -2137,6 +2307,10 @@ export class AstSetAccessorDeclarationData extends AstData { (this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); } } + + static { + createDataInstanceMap[SyntaxKind.SetAccessor] = _ => new this(); + } } export type AstAccessorDeclaration = AstNodeOneOf; @@ -2154,6 +2328,10 @@ export class AstIndexSignatureDeclarationData extends AstTypeScriptNodeData { /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.IndexSignature] = _ => new this(); + } } // dprint-ignore @@ -2172,6 +2350,10 @@ export class AstClassStaticBlockDeclarationData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.body) | TransformFlags.ContainsClassFields; } + + static { + createDataInstanceMap[SyntaxKind.ClassStaticBlockDeclaration] = _ => new this(); + } } /** @@ -2185,6 +2367,10 @@ export type AstImportTypeAssertionContainer = AstNode new this(); + } } // dprint-ignore @@ -2195,12 +2381,20 @@ export class AstImportTypeNodeData extends AstTypeScriptNodeData { attributes: AstImportAttributes | undefined = undefined; qualifier: AstEntityName | undefined = undefined; typeArguments: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.ImportType] = _ => new this(); + } } export type AstKeywordTypeNode = AstNode>; // dprint-ignore export class AstThisTypeNodeData extends AstTypeScriptNodeData { + + static { + createDataInstanceMap[SyntaxKind.ThisType] = _ => new this(); + } } export type AstFunctionOrConstructorTypeNode = AstNodeOneOf; @@ -2218,6 +2412,10 @@ export class AstFunctionTypeNodeData extends AstTypeScriptNodeData { /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.FunctionType] = _ => new this(); + } } // dprint-ignore @@ -2233,12 +2431,20 @@ export class AstConstructorTypeNodeData extends AstTypeScriptNodeData { /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.ConstructorType] = _ => new this(); + } } // dprint-ignore export class AstTypeReferenceNodeData extends AstTypeScriptNodeData { typeName: AstEntityName = undefined!; typeArguments: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.TypeReference] = _ => new this(); + } } // dprint-ignore @@ -2246,12 +2452,20 @@ export class AstTypePredicateNodeData extends AstTypeScriptNodeData { assertsModifier: AstAssertsKeyword | undefined = undefined; parameterName: AstIdentifier | AstThisTypeNode = undefined!; type: AstTypeNode | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.TypePredicate] = _ => new this(); + } } // dprint-ignore export class AstTypeQueryNodeData extends AstTypeScriptNodeData { exprName: AstEntityName = undefined!; typeArguments: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.TypeQuery] = _ => new this(); + } } // dprint-ignore @@ -2260,16 +2474,28 @@ export class AstTypeLiteralNodeData extends AstTypeScriptNodeData { /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + static { + createDataInstanceMap[SyntaxKind.TypeLiteral] = _ => new this(); + } } // dprint-ignore export class AstArrayTypeNodeData extends AstTypeScriptNodeData { elementType: AstTypeNode = undefined!; + + static { + createDataInstanceMap[SyntaxKind.ArrayType] = _ => new this(); + } } // dprint-ignore export class AstTupleTypeNodeData extends AstTypeScriptNodeData { elements: AstNodeArray = undefined!; + + static { + createDataInstanceMap[SyntaxKind.TupleType] = _ => new this(); + } } // dprint-ignore @@ -2282,16 +2508,28 @@ export class AstNamedTupleMemberData extends AstTypeScriptNodeData { /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + static { + createDataInstanceMap[SyntaxKind.NamedTupleMember] = _ => new this(); + } } // dprint-ignore export class AstOptionalTypeNodeData extends AstTypeScriptNodeData { type: AstTypeNode = undefined!; + + static { + createDataInstanceMap[SyntaxKind.OptionalType] = _ => new this(); + } } // dprint-ignore export class AstRestTypeNodeData extends AstTypeScriptNodeData { type: AstTypeNode = undefined!; + + static { + createDataInstanceMap[SyntaxKind.RestType] = _ => new this(); + } } export type AstUnionOrIntersectionTypeNode = AstNodeOneOf; @@ -2299,11 +2537,19 @@ export type AstUnionOrIntersectionTypeNode = AstNodeOneOf = undefined!; + + static { + createDataInstanceMap[SyntaxKind.UnionType] = _ => new this(); + } } // dprint-ignore export class AstIntersectionTypeNodeData extends AstTypeScriptNodeData { types: AstNodeArray = undefined!; + + static { + createDataInstanceMap[SyntaxKind.IntersectionType] = _ => new this(); + } } // dprint-ignore @@ -2315,28 +2561,48 @@ export class AstConditionalTypeNodeData extends AstTypeScriptNodeData { /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.ConditionalType] = _ => new this(); + } } // dprint-ignore export class AstInferTypeNodeData extends AstTypeScriptNodeData { typeParameter: AstTypeParameterDeclaration = undefined!; + + static { + createDataInstanceMap[SyntaxKind.InferType] = _ => new this(); + } } // dprint-ignore export class AstParenthesizedTypeNodeData extends AstTypeScriptNodeData { type: AstTypeNode = undefined!; + + static { + createDataInstanceMap[SyntaxKind.ParenthesizedType] = _ => new this(); + } } // dprint-ignore export class AstTypeOperatorNodeData extends AstTypeScriptNodeData { operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword = undefined!; type: AstTypeNode = undefined!; + + static { + createDataInstanceMap[SyntaxKind.TypeOperator] = _ => new this(); + } } // dprint-ignore export class AstIndexedAccessTypeNodeData extends AstTypeScriptNodeData { objectType: AstTypeNode = undefined!; indexType: AstTypeNode = undefined!; + + static { + createDataInstanceMap[SyntaxKind.IndexedAccessType] = _ => new this(); + } } // dprint-ignore @@ -2352,11 +2618,19 @@ export class AstMappedTypeNodeData extends AstTypeScriptNodeData { /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.MappedType] = _ => new this(); + } } // dprint-ignore export class AstLiteralTypeNodeData extends AstTypeScriptNodeData { literal: AstNullLiteral | AstBooleanLiteral | AstLiteralExpression | AstPrefixUnaryExpression = undefined!; + + static { + createDataInstanceMap[SyntaxKind.LiteralType] = _ => new this(); + } } export type AstPropertyNameLiteral = AstNodeOneOf; @@ -2365,12 +2639,20 @@ export type AstPropertyNameLiteral = AstNodeOneOf; export class AstTemplateLiteralTypeNodeData extends AstTypeScriptNodeData { head: AstTemplateHead = undefined!; templateSpans: AstNodeArray = undefined!; + + static { + createDataInstanceMap[SyntaxKind.TemplateLiteralType] = _ => new this(); + } } // dprint-ignore export class AstTemplateLiteralTypeSpanData extends AstTypeScriptNodeData { type: AstTypeNode = undefined!; literal: AstTemplateMiddle | AstTemplateTail = undefined!; + + static { + createDataInstanceMap[SyntaxKind.TemplateLiteralTypeSpan] = _ => new this(); + } } // dprint-ignore @@ -2378,6 +2660,10 @@ export class AstOmittedExpressionData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; } + + static { + createDataInstanceMap[SyntaxKind.OmittedExpression] = _ => new this(); + } } // dprint-ignore @@ -2400,6 +2686,10 @@ export class AstPrefixUnaryExpressionData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.PrefixUnaryExpression] = _ => new this(); + } } // dprint-ignore @@ -2421,6 +2711,10 @@ export class AstPostfixUnaryExpressionData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.PostfixUnaryExpression] = _ => new this(); + } } // dprint-ignore @@ -2430,6 +2724,10 @@ export class AstDeleteExpressionData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression); } + + static { + createDataInstanceMap[SyntaxKind.DeleteExpression] = _ => new this(); + } } // dprint-ignore @@ -2439,6 +2737,10 @@ export class AstTypeOfExpressionData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression); } + + static { + createDataInstanceMap[SyntaxKind.TypeOfExpression] = _ => new this(); + } } // dprint-ignore @@ -2448,6 +2750,10 @@ export class AstVoidExpressionData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression); } + + static { + createDataInstanceMap[SyntaxKind.VoidExpression] = _ => new this(); + } } // dprint-ignore @@ -2460,9 +2766,13 @@ export class AstAwaitExpressionData extends AstData { TransformFlags.ContainsES2018 | TransformFlags.ContainsAwait; } -} -// dprint-ignore + static { + createDataInstanceMap[SyntaxKind.AwaitExpression] = _ => new this(); + } +} + +// dprint-ignore export class AstYieldExpressionData extends AstData { asteriskToken: AstAsteriskToken | undefined = undefined; expression: AstExpression | undefined = undefined; @@ -2474,6 +2784,10 @@ export class AstYieldExpressionData extends AstData { TransformFlags.ContainsES2018 | TransformFlags.ContainsYield; } + + static { + createDataInstanceMap[SyntaxKind.YieldExpression] = _ => new this(); + } } export type AstBinaryOperatorToken = AstNode; @@ -2521,8 +2835,13 @@ export class AstBinaryExpressionData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.BinaryExpression] = _ => new this(); + } } +export type AstAssignmentExpression = AstNodeOneOf>; export type AstDestructuringAssignment = AstNodeOneOf; // dprint-ignore @@ -2540,6 +2859,10 @@ export class AstConditionalExpressionData extends AstData { propagateChildFlags(this.colonToken) | propagateChildFlags(this.whenFalse); } + + static { + createDataInstanceMap[SyntaxKind.ConditionalExpression] = _ => new this(); + } } export type AstFunctionBody = AstNodeOneOf; @@ -2583,6 +2906,10 @@ export class AstFunctionExpressionData extends AstData { (this.typeParameters || this.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | TransformFlags.ContainsHoistedDeclarationOrCompletion; } + + static { + createDataInstanceMap[SyntaxKind.FunctionExpression] = _ => new this(); + } } // dprint-ignore @@ -2616,6 +2943,10 @@ export class AstArrowFunctionData extends AstData { (isAsync ? TransformFlags.ContainsES2017 | TransformFlags.ContainsLexicalThis : TransformFlags.None) | TransformFlags.ContainsES2015; } + + static { + createDataInstanceMap[SyntaxKind.ArrowFunction] = _ => new this(); + } } // dprint-ignore @@ -2627,6 +2958,10 @@ export class AstRegularExpressionLiteralData extends AstTokenData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; } + + static { + createDataInstanceMap[SyntaxKind.RegularExpressionLiteral] = _ => new this(); + } } // dprint-ignore @@ -2643,6 +2978,10 @@ export class AstStringLiteralData extends AstTokenData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return this.hasExtendedUnicodeEscape ? TransformFlags.ContainsES2015 : TransformFlags.None; } + + static { + createDataInstanceMap[SyntaxKind.StringLiteral] = _ => new this(); + } } // dprint-ignore @@ -2659,11 +2998,17 @@ export class AstNoSubstitutionTemplateLiteralData extends AstTokenData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); } + + static { + createDataInstanceMap[SyntaxKind.NoSubstitutionTemplateLiteral] = _ => new this(); + } } export type AstPseudoLiteralToken = AstNodeOneOf; export type AstTemplateLiteralToken = AstNodeOneOf; export type AstStringLiteralLike = AstNodeOneOf; +/** @internal */ +export type AstHasText = AstNodeOneOf; // dprint-ignore export class AstNumericLiteralData extends AstTokenData { @@ -2676,6 +3021,10 @@ export class AstNumericLiteralData extends AstTokenData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return this.numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier ? TransformFlags.ContainsES2015 : TransformFlags.None; } + + static { + createDataInstanceMap[SyntaxKind.NumericLiteral] = _ => new this(); + } } // dprint-ignore @@ -2685,6 +3034,10 @@ export class AstBigIntLiteralData extends AstTokenData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsES2020; } + + static { + createDataInstanceMap[SyntaxKind.BigIntLiteral] = _ => new this(); + } } export type AstLiteralToken = AstNodeOneOf; @@ -2701,6 +3054,10 @@ export class AstTemplateHeadData extends AstTokenData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); } + + static { + createDataInstanceMap[SyntaxKind.TemplateHead] = _ => new this(); + } } // dprint-ignore @@ -2715,6 +3072,10 @@ export class AstTemplateMiddleData extends AstTokenData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); } + + static { + createDataInstanceMap[SyntaxKind.TemplateMiddle] = _ => new this(); + } } // dprint-ignore @@ -2729,6 +3090,10 @@ export class AstTemplateTailData extends AstTokenData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return getTransformFlagsOfTemplateLiteralLike(this.templateFlags); } + + static { + createDataInstanceMap[SyntaxKind.TemplateTail] = _ => new this(); + } } // dprint-ignore @@ -2741,6 +3106,10 @@ export class AstTemplateExpressionData extends AstData { propagateChildrenFlags(this.templateSpans) | TransformFlags.ContainsES2015; } + static { + createDataInstanceMap[SyntaxKind.TemplateExpression] = _ => new this(); + } + } // dprint-ignore @@ -2753,6 +3122,10 @@ export class AstTemplateSpanData extends AstData { propagateChildFlags(this.literal) | TransformFlags.ContainsES2015; } + + static { + createDataInstanceMap[SyntaxKind.TemplateSpan] = _ => new this(); + } } // dprint-ignore @@ -2763,6 +3136,10 @@ export class AstParenthesizedExpressionData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression); } + + static { + createDataInstanceMap[SyntaxKind.ParenthesizedExpression] = _ => new this(); + } } /** @internal */ @@ -2777,6 +3154,10 @@ export class AstArrayLiteralExpressionData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.elements); } + + static { + createDataInstanceMap[SyntaxKind.ArrayLiteralExpression] = _ => new this(); + } } // dprint-ignore @@ -2788,6 +3169,10 @@ export class AstSpreadElementData extends AstData { TransformFlags.ContainsES2015 | TransformFlags.ContainsRestOrSpread; } + + static { + createDataInstanceMap[SyntaxKind.SpreadElement] = _ => new this(); + } } export type AstObjectLiteralElement = AstNode; @@ -2805,6 +3190,10 @@ export class AstObjectLiteralExpressionData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.properties); } + + static { + createDataInstanceMap[SyntaxKind.ObjectLiteralExpression] = _ => new this(); + } } export type AstPropertyAccessExpression = AstNode; @@ -2837,9 +3226,14 @@ export class AstPropertyAccessExpressionData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.PropertyAccessExpression] = _ => new this(); + } } export type AstPropertyAccessEntityNameExpression = AstNode; +export type AstAccessExpression = AstNodeOneOf; export type AstEntityNameExpression = AstNodeOneOf; export type AstPropertyAccessChain = AstNode; /** @internal */ @@ -2871,6 +3265,10 @@ export class AstElementAccessExpressionData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.ElementAccessExpression] = _ => new this(); + } } export type AstElementAccessChain = AstNode; @@ -2896,9 +3294,9 @@ export class AstCallExpressionData extends AstData { transformFlags |= TransformFlags.ContainsTypeScript; } if ( - (this.expression.kind === SyntaxKind.PropertyAccessExpression || - this.expression.kind === SyntaxKind.ElementAccessExpression) && - (this.expression as AstNode).data.expression.kind === SyntaxKind.SuperKeyword + (astIsPropertyAccessExpression(this.expression) || + astIsElementAccessExpression(this.expression)) && + astGetExpression(this.expression).kind === SyntaxKind.SuperKeyword ) { transformFlags |= TransformFlags.ContainsLexicalThis; } @@ -2910,6 +3308,10 @@ export class AstCallExpressionData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.CallExpression] = _ => new this(); + } } export type AstCallChain = AstNode; @@ -2917,6 +3319,20 @@ export type AstCallChain = AstNode; export type AstCallChainRoot = AstNode; /** @internal */ export type AstOptionalChainRoot = AstNodeOneOf; +/** @internal */ +export type AstLiteralLikeElementAccessExpression = AstNodeOneOf; +/** @internal */ +export type AstBindableStaticNameExpression = AstNodeOneOf; +/** @internal */ +export type AstBindableStaticAccessExpression = AstNodeOneOf; +/** @internal */ +export type AstBindableStaticPropertyAssignmentExpression = AstNodeOneOf; +/** @internal */ +export type AstBindableStaticElementAccessExpression = AstNodeOneOf; +/** @internal */ +export type AstBindablePropertyAssignmentExpression = AstNodeOneOf; +/** @internal */ +export type AstBindableObjectDefinePropertyCall = AstNodeOneOf; // dprint-ignore export class AstExpressionWithTypeArgumentsData extends AstData { @@ -2928,6 +3344,10 @@ export class AstExpressionWithTypeArgumentsData extends AstData { propagateChildrenFlags(this.typeArguments) | TransformFlags.ContainsES2015; } + + static { + createDataInstanceMap[SyntaxKind.ExpressionWithTypeArguments] = _ => new this(); + } } // dprint-ignore @@ -2949,6 +3369,10 @@ export class AstNewExpressionData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.NewExpression] = _ => new this(); + } } export type AstTemplateLiteral = AstNodeOneOf; @@ -2973,6 +3397,10 @@ export class AstTaggedTemplateExpressionData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.TaggedTemplateExpression] = _ => new this(); + } } // dprint-ignore @@ -2985,10 +3413,14 @@ export class AstAsExpressionData extends AstData { propagateChildFlags(this.type) | TransformFlags.ContainsTypeScript; } + + static { + createDataInstanceMap[SyntaxKind.AsExpression] = _ => new this(); + } } // dprint-ignore -export class AstTypeAssertionData extends AstData { +export class AstTypeAssertionExpressionData extends AstData { type: AstTypeNode = undefined!; expression: AstUnaryExpression = undefined!; @@ -2997,6 +3429,10 @@ export class AstTypeAssertionData extends AstData { propagateChildFlags(this.type) | TransformFlags.ContainsTypeScript; } + + static { + createDataInstanceMap[SyntaxKind.TypeAssertionExpression] = _ => new this(); + } } // dprint-ignore @@ -3009,6 +3445,10 @@ export class AstSatisfiesExpressionData extends AstData { propagateChildFlags(this.type) | TransformFlags.ContainsTypeScript; } + + static { + createDataInstanceMap[SyntaxKind.SatisfiesExpression] = _ => new this(); + } } // dprint-ignore @@ -3019,6 +3459,10 @@ export class AstNonNullExpressionData extends AstData { return propagateChildFlags(this.expression) | TransformFlags.ContainsTypeScript; } + + static { + createDataInstanceMap[SyntaxKind.NonNullExpression] = _ => new this(); + } } export type AstNonNullChain = AstNode; @@ -3044,6 +3488,10 @@ export class AstMetaPropertyData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.MetaProperty] = _ => new this(); + } } // dprint-ignore @@ -3058,6 +3506,10 @@ export class AstJsxElementData extends AstData { propagateChildFlags(this.closingElement) | TransformFlags.ContainsJsx; } + + static { + createDataInstanceMap[SyntaxKind.JsxElement] = _ => new this(); + } } export type AstJsxOpeningLikeElement = AstNodeOneOf; @@ -3081,6 +3533,10 @@ export class AstJsxAttributesData extends AstData { return propagateChildrenFlags(this.properties) | TransformFlags.ContainsJsx; } + + static { + createDataInstanceMap[SyntaxKind.JsxAttributes] = _ => new this(); + } } // dprint-ignore @@ -3093,6 +3549,10 @@ export class AstJsxNamespacedNameData extends AstData { propagateChildFlags(this.name) | TransformFlags.ContainsJsx; } + + static { + createDataInstanceMap[SyntaxKind.JsxNamespacedName] = _ => new this(); + } } // dprint-ignore @@ -3111,6 +3571,10 @@ export class AstJsxOpeningElementData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.JsxOpeningElement] = _ => new this(); + } } // dprint-ignore @@ -3121,6 +3585,10 @@ export class AstJsxClosingElementData extends AstData { return propagateChildFlags(this.tagName) | TransformFlags.ContainsJsx; } + + static { + createDataInstanceMap[SyntaxKind.JsxClosingElement] = _ => new this(); + } } // dprint-ignore @@ -3139,6 +3607,10 @@ export class AstJsxSelfClosingElementData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.JsxSelfClosingElement] = _ => new this(); + } } // dprint-ignore @@ -3153,6 +3625,10 @@ export class AstJsxFragmentData extends AstData { propagateChildFlags(this.closingFragment) | TransformFlags.ContainsJsx; } + + static { + createDataInstanceMap[SyntaxKind.JsxFragment] = _ => new this(); + } } // dprint-ignore @@ -3160,6 +3636,10 @@ export class AstJsxOpeningFragmentData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsJsx; } + + static { + createDataInstanceMap[SyntaxKind.JsxOpeningFragment] = _ => new this(); + } } // dprint-ignore @@ -3167,6 +3647,10 @@ export class AstJsxClosingFragmentData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsJsx; } + + static { + createDataInstanceMap[SyntaxKind.JsxClosingFragment] = _ => new this(); + } } // dprint-ignore @@ -3182,6 +3666,10 @@ export class AstJsxAttributeData extends AstData { propagateChildFlags(this.initializer) | TransformFlags.ContainsJsx; } + + static { + createDataInstanceMap[SyntaxKind.JsxAttribute] = _ => new this(); + } } export type AstJsxAttributeValue = AstNodeOneOf; @@ -3194,6 +3682,10 @@ export class AstJsxSpreadAttributeData extends AstData { return propagateChildFlags(this.expression) | TransformFlags.ContainsJsx; } + + static { + createDataInstanceMap[SyntaxKind.JsxSpreadAttribute] = _ => new this(); + } } // dprint-ignore @@ -3206,6 +3698,10 @@ export class AstJsxExpressionData extends AstData { propagateChildFlags(this.expression) | TransformFlags.ContainsJsx; } + + static { + createDataInstanceMap[SyntaxKind.JsxExpression] = _ => new this(); + } } // dprint-ignore @@ -3218,6 +3714,10 @@ export class AstJsxTextData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsJsx; } + + static { + createDataInstanceMap[SyntaxKind.JsxText] = _ => new this(); + } } export type AstJsxChild = AstNodeOneOf; @@ -3230,6 +3730,10 @@ export class AstEmptyStatementData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; } + + static { + createDataInstanceMap[SyntaxKind.EmptyStatement] = _ => new this(); + } } // dprint-ignore @@ -3240,6 +3744,10 @@ export class AstDebuggerStatementData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; } + + static { + createDataInstanceMap[SyntaxKind.DebuggerStatement] = _ => new this(); + } } // dprint-ignore @@ -3254,6 +3762,10 @@ export class AstMissingDeclarationData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; } + + static { + createDataInstanceMap[SyntaxKind.MissingDeclaration] = _ => new this(); + } } // dprint-ignore @@ -3268,6 +3780,10 @@ export class AstBlockData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.statements); } + + static { + createDataInstanceMap[SyntaxKind.Block] = _ => new this(); + } } // dprint-ignore @@ -3286,8 +3802,15 @@ export class AstVariableStatementData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.VariableStatement] = _ => new this(); + } } +/** @internal */ +export type AstPrologueDirective = AstNodeOneOf; + // dprint-ignore export class AstExpressionStatementData extends AstData { expression: AstExpression = undefined!; @@ -3298,6 +3821,10 @@ export class AstExpressionStatementData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression); } + + static { + createDataInstanceMap[SyntaxKind.ExpressionStatement] = _ => new this(); + } } // dprint-ignore @@ -3314,6 +3841,10 @@ export class AstIfStatementData extends AstData { propagateChildFlags(this.thenStatement) | propagateChildFlags(this.elseStatement); } + + static { + createDataInstanceMap[SyntaxKind.IfStatement] = _ => new this(); + } } // dprint-ignore @@ -3328,6 +3859,10 @@ export class AstDoStatementData extends AstData { return propagateChildFlags(this.statement) | propagateChildFlags(this.expression); } + + static { + createDataInstanceMap[SyntaxKind.DoStatement] = _ => new this(); + } } // dprint-ignore @@ -3342,6 +3877,10 @@ export class AstWhileStatementData extends AstData { return propagateChildFlags(this.expression) | propagateChildFlags(this.statement); } + + static { + createDataInstanceMap[SyntaxKind.WhileStatement] = _ => new this(); + } } export type AstForInitializer = AstNodeOneOf; @@ -3364,6 +3903,10 @@ export class AstForStatementData extends AstData { propagateChildFlags(this.incrementor) | propagateChildFlags(this.statement); } + + static { + createDataInstanceMap[SyntaxKind.ForStatement] = _ => new this(); + } } export type AstForInOrOfStatement = AstNodeOneOf; @@ -3384,6 +3927,10 @@ export class AstForInStatementData extends AstData { propagateChildFlags(this.expression) | propagateChildFlags(this.statement); } + + static { + createDataInstanceMap[SyntaxKind.ForInStatement] = _ => new this(); + } } // dprint-ignore @@ -3409,6 +3956,10 @@ export class AstForOfStatementData extends AstData { } return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.ForOfStatement] = _ => new this(); + } } // dprint-ignore @@ -3422,6 +3973,10 @@ export class AstBreakStatementData extends AstData { return propagateChildFlags(this.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; } + + static { + createDataInstanceMap[SyntaxKind.BreakStatement] = _ => new this(); + } } export type AstBreakOrContinueStatement = AstNodeOneOf; @@ -3437,6 +3992,10 @@ export class AstContinueStatementData extends AstData { return propagateChildFlags(this.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; } + + static { + createDataInstanceMap[SyntaxKind.ContinueStatement] = _ => new this(); + } } // dprint-ignore @@ -3452,6 +4011,10 @@ export class AstReturnStatementData extends AstData { TransformFlags.ContainsES2018 | TransformFlags.ContainsHoistedDeclarationOrCompletion; } + + static { + createDataInstanceMap[SyntaxKind.ReturnStatement] = _ => new this(); + } } // dprint-ignore @@ -3466,6 +4029,10 @@ export class AstWithStatementData extends AstData { return propagateChildFlags(this.expression) | propagateChildFlags(this.statement); } + + static { + createDataInstanceMap[SyntaxKind.WithStatement] = _ => new this(); + } } // dprint-ignore @@ -3481,6 +4048,10 @@ export class AstSwitchStatementData extends AstData { return propagateChildFlags(this.expression) | propagateChildFlags(this.caseBlock); } + + static { + createDataInstanceMap[SyntaxKind.SwitchStatement] = _ => new this(); + } } // dprint-ignore @@ -3493,6 +4064,10 @@ export class AstCaseBlockData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.clauses); } + + static { + createDataInstanceMap[SyntaxKind.CaseBlock] = _ => new this(); + } } // dprint-ignore @@ -3507,6 +4082,10 @@ export class AstCaseClauseData extends AstData { return propagateChildFlags(this.expression) | propagateChildrenFlags(this.statements); } + + static { + createDataInstanceMap[SyntaxKind.CaseClause] = _ => new this(); + } } // dprint-ignore @@ -3518,6 +4097,10 @@ export class AstDefaultClauseData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.statements); } + + static { + createDataInstanceMap[SyntaxKind.DefaultClause] = _ => new this(); + } } export type AstCaseOrDefaultClause = AstNodeOneOf; @@ -3534,6 +4117,10 @@ export class AstLabeledStatementData extends AstData { return propagateChildFlags(this.label) | propagateChildFlags(this.statement); } + + static { + createDataInstanceMap[SyntaxKind.LabeledStatement] = _ => new this(); + } } // dprint-ignore @@ -3546,6 +4133,10 @@ export class AstThrowStatementData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression); } + + static { + createDataInstanceMap[SyntaxKind.ThrowStatement] = _ => new this(); + } } // dprint-ignore @@ -3562,6 +4153,10 @@ export class AstTryStatementData extends AstData { propagateChildFlags(this.catchClause) | propagateChildFlags(this.finallyBlock); } + + static { + createDataInstanceMap[SyntaxKind.TryStatement] = _ => new this(); + } } // dprint-ignore @@ -3577,6 +4172,10 @@ export class AstCatchClauseData extends AstData { propagateChildFlags(this.block) | (!this.variableDeclaration ? TransformFlags.ContainsES2019 : TransformFlags.None); } + + static { + createDataInstanceMap[SyntaxKind.CatchClause] = _ => new this(); + } } export type AstObjectTypeDeclaration = AstNodeOneOf; @@ -3615,6 +4214,10 @@ export class AstClassDeclarationData extends AstData { return transformFlags; } } + + static { + createDataInstanceMap[SyntaxKind.ClassDeclaration] = _ => new this(); + } } // dprint-ignore @@ -3638,6 +4241,10 @@ export class AstClassExpressionData extends AstData { (this.typeParameters ? TransformFlags.ContainsTypeScript : TransformFlags.None) | TransformFlags.ContainsES2015; } + + static { + createDataInstanceMap[SyntaxKind.ClassExpression] = _ => new this(); + } } export type AstTypeElement = AstNode; @@ -3653,6 +4260,10 @@ export class AstInterfaceDeclarationData extends AstTypeScriptNodeData { /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + static { + createDataInstanceMap[SyntaxKind.InterfaceDeclaration] = _ => new this(); + } } // dprint-ignore @@ -3670,6 +4281,10 @@ export class AstHeritageClauseData extends AstData { return Debug.assertNever(this.token); } } + + static { + createDataInstanceMap[SyntaxKind.HeritageClause] = _ => new this(); + } } // dprint-ignore @@ -3684,6 +4299,10 @@ export class AstTypeAliasDeclarationData extends AstTypeScriptNodeData { /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.TypeAliasDeclaration] = _ => new this(); + } } // dprint-ignore @@ -3704,6 +4323,10 @@ export class AstEnumDeclarationData extends AstData { transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Enum declarations cannot contain `await` return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.EnumDeclaration] = _ => new this(); + } } // dprint-ignore @@ -3720,6 +4343,10 @@ export class AstEnumMemberData extends AstData { propagateChildFlags(this.initializer) | TransformFlags.ContainsTypeScript; } + + static { + createDataInstanceMap[SyntaxKind.EnumMember] = _ => new this(); + } } export type AstModuleName = AstNodeOneOf; @@ -3750,8 +4377,17 @@ export class AstModuleDeclarationData extends AstData { return transformFlags; } } + + static { + createDataInstanceMap[SyntaxKind.ModuleDeclaration] = _ => new this(); + } } +/** @internal */ +export type AstAmbientModuleDeclaration = AstNodeOneOf; +/** @internal */ +export type AstNonGlobalAmbientModuleDeclaration = AstNodeOneOf; + export type AstNamespaceBody = AstNodeOneOf; export type AstNamespaceDeclaration = AstNode; @@ -3779,6 +4415,10 @@ export class AstModuleBlockData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.statements); } + + static { + createDataInstanceMap[SyntaxKind.ModuleBlock] = _ => new this(); + } } export type AstModuleReference = AstNodeOneOf; @@ -3805,6 +4445,10 @@ export class AstImportEqualsDeclarationData extends AstData { return transformFlags & ~TransformFlags.ContainsPossibleTopLevelAwait; // Import= declaration is always parsed in an Await context } + + static { + createDataInstanceMap[SyntaxKind.ImportEqualsDeclaration] = _ => new this(); + } } // dprint-ignore @@ -3815,6 +4459,10 @@ export class AstExternalModuleReferenceData extends AstData { // always parsed in an Await context return propagateChildFlags(this.expression) & ~TransformFlags.ContainsPossibleTopLevelAwait; } + + static { + createDataInstanceMap[SyntaxKind.ExternalModuleReference] = _ => new this(); + } } // dprint-ignore @@ -3835,6 +4483,10 @@ export class AstImportDeclarationData extends AstData { transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.ImportDeclaration] = _ => new this(); + } } export type AstNamedImportBindings = AstNodeOneOf; @@ -3858,7 +4510,11 @@ export class AstImportClauseData extends AstData { transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } -} + + static { + createDataInstanceMap[SyntaxKind.ImportClause] = _ => new this(); + } +} export type AstAssertionKey = AstNodeOneOf; /** @deprecated */ @@ -3873,6 +4529,10 @@ export class AstImportAttributeData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsESNext; } + + static { + createDataInstanceMap[SyntaxKind.ImportAttribute] = _ => new this(); + } } /** @deprecated */ @@ -3887,6 +4547,10 @@ export class AstImportAttributesData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.ContainsESNext; } + + static { + createDataInstanceMap[SyntaxKind.ImportAttributes] = _ => new this(); + } } // dprint-ignore @@ -3901,6 +4565,10 @@ export class AstNamespaceImportData extends AstData { transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.NamespaceImport] = _ => new this(); + } } // dprint-ignore @@ -3916,6 +4584,10 @@ export class AstNamespaceExportData extends AstData { transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.NamespaceExport] = _ => new this(); + } } // dprint-ignore @@ -3931,6 +4603,10 @@ export class AstNamespaceExportDeclarationData extends AstData { return propagateIdentifierNameFlags(this.name) | TransformFlags.ContainsTypeScript; } + + static { + createDataInstanceMap[SyntaxKind.NamespaceExportDeclaration] = _ => new this(); + } } // dprint-ignore @@ -3952,6 +4628,10 @@ export class AstExportDeclarationData extends AstData { transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.ExportDeclaration] = _ => new this(); + } } // dprint-ignore @@ -3963,6 +4643,10 @@ export class AstNamedImportsData extends AstData { transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.NamedImports] = _ => new this(); + } } // dprint-ignore @@ -3974,6 +4658,10 @@ export class AstNamedExportsData extends AstData { transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.NamedExports] = _ => new this(); + } } // dprint-ignore @@ -3991,6 +4679,10 @@ export class AstImportSpecifierData extends AstData { transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.ImportSpecifier] = _ => new this(); + } } // dprint-ignore @@ -4009,6 +4701,10 @@ export class AstExportSpecifierData extends AstData { transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.ExportSpecifier] = _ => new this(); + } } export type AstModuleExportName = AstNodeOneOf; @@ -4028,49 +4724,85 @@ export class AstExportAssignmentData extends AstData { transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return transformFlags; } + + static { + createDataInstanceMap[SyntaxKind.ExportAssignment] = _ => new this(); + } } // dprint-ignore export class AstJSDocTypeExpressionData extends AstData { type: AstTypeNode = undefined!; + + static { + createDataInstanceMap[SyntaxKind.JSDocTypeExpression] = _ => new this(); + } } // dprint-ignore export class AstJSDocNameReferenceData extends AstData { name: AstEntityName | AstJSDocMemberName = undefined!; + + static { + createDataInstanceMap[SyntaxKind.JSDocNameReference] = _ => new this(); + } } // dprint-ignore export class AstJSDocMemberNameData extends AstData { left: AstEntityName | AstJSDocMemberName = undefined!; right: AstIdentifier = undefined!; + + static { + createDataInstanceMap[SyntaxKind.JSDocMemberName] = _ => new this(); + } } export type AstJSDocType = AstNodeOneOf; // dprint-ignore export class AstJSDocAllTypeData extends AstData { + + static { + createDataInstanceMap[SyntaxKind.JSDocAllType] = _ => new this(); + } } // dprint-ignore export class AstJSDocUnknownTypeData extends AstData { + + static { + createDataInstanceMap[SyntaxKind.JSDocUnknownType] = _ => new this(); + } } // dprint-ignore export class AstJSDocNonNullableTypeData extends AstData { type: AstTypeNode = undefined!; postfix = false; + + static { + createDataInstanceMap[SyntaxKind.JSDocNonNullableType] = _ => new this(); + } } // dprint-ignore export class AstJSDocNullableTypeData extends AstData { type: AstTypeNode = undefined!; postfix = false; + + static { + createDataInstanceMap[SyntaxKind.JSDocNullableType] = _ => new this(); + } } // dprint-ignore export class AstJSDocOptionalTypeData extends AstData { type: AstTypeNode = undefined!; + + static { + createDataInstanceMap[SyntaxKind.JSDocOptionalType] = _ => new this(); + } } // dprint-ignore @@ -4085,22 +4817,39 @@ export class AstJSDocFunctionTypeData extends AstData { /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.JSDocFunctionType] = _ => new this(); + } } // dprint-ignore export class AstJSDocVariadicTypeData extends AstData { type: AstTypeNode = undefined!; + + static { + createDataInstanceMap[SyntaxKind.JSDocVariadicType] = _ => new this(); + } } // dprint-ignore export class AstJSDocNamepathTypeData extends AstData { type: AstTypeNode = undefined!; + + static { + createDataInstanceMap[SyntaxKind.JSDocNamepathType] = _ => new this(); + } } // dprint-ignore export class AstJSDocData extends AstData { - comment: string | AstNodeArray | undefined = undefined; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; tags: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.JSDoc] = _ => new this(); + } } export type AstHasJSDoc = AstNodeOneOf; @@ -4110,18 +4859,30 @@ export type AstJSDocTag = AstNodeOneOf; export class AstJSDocLinkData extends AstData { name: AstEntityName | AstJSDocMemberName | undefined = undefined; text = ""; + + static { + createDataInstanceMap[SyntaxKind.JSDocLink] = _ => new this(); + } } // dprint-ignore export class AstJSDocLinkCodeData extends AstData { name: AstEntityName | AstJSDocMemberName | undefined = undefined; text = ""; + + static { + createDataInstanceMap[SyntaxKind.JSDocLinkCode] = _ => new this(); + } } // dprint-ignore export class AstJSDocLinkPlainData extends AstData { name: AstEntityName | AstJSDocMemberName | undefined = undefined; text = ""; + + static { + createDataInstanceMap[SyntaxKind.JSDocLinkPlain] = _ => new this(); + } } export type AstJSDocComment = AstNodeOneOf; @@ -4129,14 +4890,19 @@ export type AstJSDocComment = AstNodeOneOf; // dprint-ignore export class AstJSDocTextData extends AstData { text = ""; + + static { + createDataInstanceMap[SyntaxKind.JSDocText] = _ => new this(); + } } export type AstBaseJSDocTag = AstNode>; // dprint-ignore -export class AstJSDocTagData extends AstData { - tagName: AstIdentifier = undefined!; - comment: string | AstNodeArray | undefined = undefined; +export abstract class AstJSDocTagData extends AstData { + abstract tagName: AstIdentifier; + abstract comment: string | undefined; + abstract commentArray: AstNodeArray | undefined; /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return TransformFlags.None; @@ -4145,6 +4911,13 @@ export class AstJSDocTagData extends AstData { // dprint-ignore export class AstJSDocUnknownTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.JSDocTag] = _ => new this(); + } } export type AstJSDocClassReference = AstNode; @@ -4155,84 +4928,193 @@ export interface AstJSDocClassReferenceData extends AstExpressionWithTypeArgumen // dprint-ignore export class AstJSDocAugmentsTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; class: AstJSDocClassReference = undefined!; + + static { + createDataInstanceMap[SyntaxKind.JSDocAugmentsTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocImplementsTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; class: AstJSDocClassReference = undefined!; + + static { + createDataInstanceMap[SyntaxKind.JSDocImplementsTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocAuthorTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.JSDocAuthorTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocDeprecatedTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.JSDocDeprecatedTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocClassTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.JSDocClassTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocPublicTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.JSDocPublicTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocPrivateTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.JSDocPrivateTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocProtectedTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.JSDocProtectedTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocReadonlyTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.JSDocReadonlyTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocOverrideTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.JSDocOverrideTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocEnumTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; typeExpression: AstJSDocTypeExpression = undefined!; /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + static { + createDataInstanceMap[SyntaxKind.JSDocEnumTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocThisTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; typeExpression: AstJSDocTypeExpression = undefined!; + static { + createDataInstanceMap[SyntaxKind.JSDocThisTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocTemplateTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; constraint: AstJSDocTypeExpression | undefined = undefined; typeParameters: AstNodeArray = undefined!; + static { + createDataInstanceMap[SyntaxKind.JSDocTemplateTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocSeeTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; name: AstJSDocNameReference | undefined = undefined; + static { + createDataInstanceMap[SyntaxKind.JSDocSeeTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocReturnTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; typeExpression: AstJSDocTypeExpression | undefined = undefined; + static { + createDataInstanceMap[SyntaxKind.JSDocReturnTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocTypeTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; typeExpression: AstJSDocTypeExpression = undefined!; + static { + createDataInstanceMap[SyntaxKind.JSDocTypeTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocTypedefTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; typeExpression: AstJSDocTypeExpression | AstJSDocTypeLiteral | undefined = undefined; fullName: AstJSDocNamespaceDeclaration | AstIdentifier | undefined = undefined; name: AstIdentifier | undefined = undefined; @@ -4241,10 +5123,16 @@ export class AstJSDocTypedefTagData extends AstJSDocTagData { /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + static { + createDataInstanceMap[SyntaxKind.JSDocTypedefTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocCallbackTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; fullName: AstJSDocNamespaceDeclaration | AstIdentifier | undefined = undefined; name: AstIdentifier | undefined = undefined; typeExpression: AstJSDocSignature = undefined!; @@ -4253,16 +5141,31 @@ export class AstJSDocCallbackTagData extends AstJSDocTagData { /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + static { + createDataInstanceMap[SyntaxKind.JSDocCallbackTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocOverloadTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; typeExpression: AstJSDocSignature = undefined!; + static { + createDataInstanceMap[SyntaxKind.JSDocOverloadTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocThrowsTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; typeExpression: AstJSDocTypeExpression | undefined = undefined; + static { + createDataInstanceMap[SyntaxKind.JSDocThrowsTag] = _ => new this(); + } } // dprint-ignore @@ -4276,10 +5179,17 @@ export class AstJSDocSignatureData extends AstData { /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) /** @internal */ locals: SymbolTable | undefined = undefined; /** @internal */ nextContainer: AstHasLocals | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.JSDocSignature] = _ => new this(); + } } // dprint-ignore export class AstJSDocPropertyTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; typeExpression: AstJSDocTypeExpression | undefined = undefined; name: AstEntityName = undefined!; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ @@ -4288,10 +5198,16 @@ export class AstJSDocPropertyTagData extends AstJSDocTagData { /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + static { + createDataInstanceMap[SyntaxKind.JSDocPropertyTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocParameterTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; typeExpression: AstJSDocTypeExpression | undefined = undefined; name: AstEntityName = undefined!; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ @@ -4300,6 +5216,9 @@ export class AstJSDocParameterTagData extends AstJSDocTagData { /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + static { + createDataInstanceMap[SyntaxKind.JSDocParameterTag] = _ => new this(); + } } export type AstJSDocPropertyLikeTag = AstNodeOneOf; @@ -4312,18 +5231,34 @@ export class AstJSDocTypeLiteralData extends AstData { /** @internal */ symbol: Symbol = undefined!; // initialized by binder (Declaration) /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + static { + createDataInstanceMap[SyntaxKind.JSDocTypeLiteral] = _ => new this(); + } } // dprint-ignore export class AstJSDocSatisfiesTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; typeExpression: AstJSDocTypeExpression = undefined!; + static { + createDataInstanceMap[SyntaxKind.JSDocSatisfiesTag] = _ => new this(); + } } // dprint-ignore export class AstJSDocImportTagData extends AstJSDocTagData { + tagName: AstIdentifier = undefined!; + comment: string | undefined = undefined; + commentArray: AstNodeArray | undefined = undefined; importClause: AstImportClause | undefined = undefined; moduleSpecifier: AstExpression = undefined!; attributes: AstImportAttributes | undefined = undefined; + static { + createDataInstanceMap[SyntaxKind.JSDocImportTag] = _ => new this(); + } } // dprint-ignore @@ -4331,6 +5266,10 @@ export class AstSyntheticExpressionData extends AstData { isSpread = false; type: Type = undefined!; tupleNameSource: AstParameterDeclaration | AstNamedTupleMember | undefined = undefined; + + static { + createDataInstanceMap[SyntaxKind.SyntheticExpression] = _ => new this(); + } } // dprint-ignore @@ -4340,22 +5279,38 @@ export class AstBundleData extends AstData { /** @internal */ syntheticTypeReferences?: readonly FileReference[]; /** @internal */ syntheticLibReferences?: readonly FileReference[]; /** @internal */ hasNoDefaultLib?: boolean; + + static { + createDataInstanceMap[SyntaxKind.Bundle] = _ => new this(); + } } // dprint-ignore export class AstSyntaxListData extends AstData { /** @internal */ _children!: readonly Node[]; + + static { + createDataInstanceMap[SyntaxKind.SyntaxList] = _ => new this(); + } } // dprint-ignore export class AstNotEmittedStatementData extends AstData { /** @internal */ jsDoc: JSDocArray | undefined = undefined; // initialized by parser (JSDocContainer) + + static { + createDataInstanceMap[SyntaxKind.NotEmittedStatement] = _ => new this(); + } } // dprint-ignore export class AstNotEmittedTypeElementData extends AstData { /** @internal */ symbol: Symbol = undefined!; /** @internal */ localSymbol: Symbol | undefined = undefined; // initialized by binder (Declaration) + + static { + createDataInstanceMap[SyntaxKind.NotEmittedTypeElement] = _ => new this(); + } } // dprint-ignore @@ -4365,6 +5320,10 @@ export class AstPartiallyEmittedExpressionData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildFlags(this.expression); } + + static { + createDataInstanceMap[SyntaxKind.PartiallyEmittedExpression] = _ => new this(); + } } // dprint-ignore @@ -4374,6 +5333,10 @@ export class AstCommaListExpressionData extends AstData { /** @internal */ override computeTransformFlags(_: AstNode): TransformFlags { return propagateChildrenFlags(this.elements); } + + static { + createDataInstanceMap[SyntaxKind.CommaListExpression] = _ => new this(); + } } /** @internal */ @@ -4386,6 +5349,10 @@ export class AstSyntheticReferenceExpressionData extends AstData { return propagateChildFlags(this.expression) | propagateChildFlags(this.thisArg); } + + static { + createDataInstanceMap[SyntaxKind.SyntheticReferenceExpression] = _ => new this(); + } } // dprint-ignore @@ -4560,14 +5527,21 @@ export class AstSourceFileData extends AstData { propagateChildFlags(this.endOfFileToken); } - override cloneNode(node: AstNode): AstNode { - if (this.redirectInfo) { - const clone = this.redirectInfo.redirectTarget.ast.shadow() as AstSourceFile; - this.copyProperties(clone.data); - clone.emitNode = undefined; - return clone; - } - return super.cloneNode(node); + static { + cloneNodeMap[SyntaxKind.SourceFile] = (node: AstNode) => { + Debug.assert(node.data instanceof this); + if (node.data.redirectInfo) { + const clone = node.data.redirectInfo.redirectTarget.ast.shadow() as AstSourceFile; + copyDataProperties(node, clone.data); + clone.emitNode = undefined; + return clone; + } + return cloneNodeCore(node); + }; + } + + static { + createDataInstanceMap[SyntaxKind.SourceFile] = _ => new this(); } } @@ -4899,7 +5873,7 @@ function propagateChildFlags(child: AstNode | undefined): TransformFlags { if (!child) return TransformFlags.None; const childFlags = child.transformFlags & ~getTransformFlagsSubtreeExclusions(child.kind); const name = astGetName(child); - return name && isAstPropertyName(name) ? propagatePropertyNameFlagsOfChild(name, childFlags) : childFlags; + return name && astIsPropertyName(name) ? propagatePropertyNameFlagsOfChild(name, childFlags) : childFlags; } function propagateChildrenFlags(children: AstNodeArray | undefined): TransformFlags { @@ -4919,14 +5893,32 @@ function getTransformFlagsOfTemplateLiteralLike(templateFlags: TokenFlags) { return transformFlags; } -/** @internal */ export type AstNamedDeclaration = AstNodeOneOf; +/** @internal */ +export type AstDynamicNamedDeclaration = AstNodeOneOf; + +/** @internal */ +export type AstDynamicNamedBinaryExpression = AstNodeOneOf; + /** @internal */ export type AstHasName = AstNodeOneOf; +/** @internal */ +export type AstHasExpression = AstNodeOneOf; + +/** @internal */ +export type AstHasInitializer = AstNodeOneOf; + +/** @internal */ +export type AstThisContainer = AstNodeOneOf; + +/** @internal */ +export type AstGetResult = T extends Base ? T["data"][K] : Base["data"][K] | undefined; + /** @internal */ export function astCanHaveName(node: AstNode): node is AstHasName { + Debug.type(node); // ensures `astCanHaveName` is up-to-date with `AstHasName`/`HasName` switch (node.kind) { case SyntaxKind.BindingElement: case SyntaxKind.ClassDeclaration: @@ -4973,8 +5965,10 @@ export function astCanHaveName(node: AstNode): node is AstHasName { case SyntaxKind.TypeParameter: case SyntaxKind.VariableDeclaration: return true; + default: + Debug.assertNeverTypeOnly(node); // ensures `astCanHaveName` is up-to-date with `AstHasName`/`HasName` + return false; } - return false; } /** @internal */ @@ -4983,10 +5977,10 @@ export function astHasName(node: AstNode): node is AstNodeOneOf(node: T): T extends AstHasName ? T["data"]["name"] : undefined; +export function astGetName(node: T): AstGetResult; export function astGetName(node: AstNode) { - Debug.type(node); - // NOTE: each branch is monomorphic + Debug.type(node); // ensures `astGetName` is up-to-date with `AstHasName`/`HasName` + // NOTE: each branch is duplicated to remain monomorphic switch (node.kind) { case SyntaxKind.BindingElement: return node.data.name; case SyntaxKind.ClassDeclaration: return node.data.name; @@ -5032,12 +6026,15 @@ export function astGetName(node: AstNode) { case SyntaxKind.TypeAliasDeclaration: return node.data.name; case SyntaxKind.TypeParameter: return node.data.name; case SyntaxKind.VariableDeclaration: return node.data.name; - default: return undefined; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetName` is up-to-date with `AstHasName`/`HasName` + return undefined; } } /** @internal */ export function astCanHaveJSDoc(node: AstNode): node is AstHasJSDoc { + Debug.type(node); // ensures `astCanHaveJSDoc` is up-to-date with `AstHasJSDoc`/`HasJSDoc` switch (node.kind) { case SyntaxKind.ArrowFunction: case SyntaxKind.BinaryExpression: @@ -5110,6 +6107,7 @@ export function astCanHaveJSDoc(node: AstNode): node is AstHasJSDoc { case SyntaxKind.NotEmittedStatement: return true; default: + Debug.assertNeverTypeOnly(node); // ensures `astCanHaveJSDoc` is up-to-date with `AstHasJSDoc`/`HasJSDoc` return false; } } @@ -5121,8 +6119,8 @@ export function astHasJSDoc(node: AstNode): node is AstNodeOneOf(node); + Debug.type(node); // ensures `astGetJSDoc` is up-to-date with `AstHasJSDoc`/`HasJSDoc` + // NOTE: each branch is duplicated to remain monomorphic switch (node.kind) { case SyntaxKind.ArrowFunction: return node.data.jsDoc; case SyntaxKind.BinaryExpression: return node.data.jsDoc; @@ -5193,226 +6191,1563 @@ export function astGetJSDoc(node: AstNode): JSDocArray | undefined { case SyntaxKind.ModuleBlock: return node.data.jsDoc; case SyntaxKind.MissingDeclaration: return node.data.jsDoc; case SyntaxKind.NotEmittedStatement: return node.data.jsDoc; - default: Debug.assertNever(node); + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetJSDoc` is up-to-date with `AstHasJSDoc`/`HasJSDoc` + return undefined; } } /** @internal */ -export function astSetJSDoc(node: AstHasJSDoc, value: JSDocArray | undefined): void { - // each branch is monomorphic +export function astSetJSDoc(node: AstHasJSDoc, value: JSDocArray | undefined): JSDocArray | undefined { + // NOTE: each branch is duplicated to remain monomorphic switch (node.kind) { - case SyntaxKind.ArrowFunction: - node.data.jsDoc = value; - break; - case SyntaxKind.BinaryExpression: - node.data.jsDoc = value; - break; - case SyntaxKind.Block: - node.data.jsDoc = value; - break; - case SyntaxKind.BreakStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.CallSignature: - node.data.jsDoc = value; - break; - case SyntaxKind.CaseClause: - node.data.jsDoc = value; - break; - case SyntaxKind.ClassDeclaration: - node.data.jsDoc = value; - break; - case SyntaxKind.ClassExpression: - node.data.jsDoc = value; - break; - case SyntaxKind.ClassStaticBlockDeclaration: - node.data.jsDoc = value; - break; - case SyntaxKind.Constructor: - node.data.jsDoc = value; - break; - case SyntaxKind.ConstructorType: - node.data.jsDoc = value; - break; - case SyntaxKind.ConstructSignature: - node.data.jsDoc = value; - break; - case SyntaxKind.ContinueStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.DebuggerStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.DoStatement: - node.data.jsDoc = value; - break; + case SyntaxKind.ArrowFunction: return node.data.jsDoc = value; + case SyntaxKind.BinaryExpression: return node.data.jsDoc = value; + case SyntaxKind.Block: return node.data.jsDoc = value; + case SyntaxKind.BreakStatement: return node.data.jsDoc = value; + case SyntaxKind.CallSignature: return node.data.jsDoc = value; + case SyntaxKind.CaseClause: return node.data.jsDoc = value; + case SyntaxKind.ClassDeclaration: return node.data.jsDoc = value; + case SyntaxKind.ClassExpression: return node.data.jsDoc = value; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.jsDoc = value; + case SyntaxKind.Constructor: return node.data.jsDoc = value; + case SyntaxKind.ConstructorType: return node.data.jsDoc = value; + case SyntaxKind.ConstructSignature: return node.data.jsDoc = value; + case SyntaxKind.ContinueStatement: return node.data.jsDoc = value; + case SyntaxKind.DebuggerStatement: return node.data.jsDoc = value; + case SyntaxKind.DoStatement: return node.data.jsDoc = value; + case SyntaxKind.ElementAccessExpression: return node.data.jsDoc = value; + case SyntaxKind.EmptyStatement: return node.data.jsDoc = value; + case SyntaxKind.EndOfFileToken: return node.data.jsDoc = value; + case SyntaxKind.EnumDeclaration: return node.data.jsDoc = value; + case SyntaxKind.EnumMember: return node.data.jsDoc = value; + case SyntaxKind.ExportAssignment: return node.data.jsDoc = value; + case SyntaxKind.ExportDeclaration: return node.data.jsDoc = value; + case SyntaxKind.ExportSpecifier: return node.data.jsDoc = value; + case SyntaxKind.ExpressionStatement: return node.data.jsDoc = value; + case SyntaxKind.ForInStatement: return node.data.jsDoc = value; + case SyntaxKind.ForOfStatement: return node.data.jsDoc = value; + case SyntaxKind.ForStatement: return node.data.jsDoc = value; + case SyntaxKind.FunctionDeclaration: return node.data.jsDoc = value; + case SyntaxKind.FunctionExpression: return node.data.jsDoc = value; + case SyntaxKind.FunctionType: return node.data.jsDoc = value; + case SyntaxKind.GetAccessor: return node.data.jsDoc = value; + case SyntaxKind.Identifier: return node.data.jsDoc = value; + case SyntaxKind.IfStatement: return node.data.jsDoc = value; + case SyntaxKind.ImportDeclaration: return node.data.jsDoc = value; + case SyntaxKind.ImportEqualsDeclaration: return node.data.jsDoc = value; + case SyntaxKind.IndexSignature: return node.data.jsDoc = value; + case SyntaxKind.InterfaceDeclaration: return node.data.jsDoc = value; + case SyntaxKind.JSDocFunctionType: return node.data.jsDoc = value; + case SyntaxKind.JSDocSignature: return node.data.jsDoc = value; + case SyntaxKind.LabeledStatement: return node.data.jsDoc = value; + case SyntaxKind.MethodDeclaration: return node.data.jsDoc = value; + case SyntaxKind.MethodSignature: return node.data.jsDoc = value; + case SyntaxKind.ModuleDeclaration: return node.data.jsDoc = value; + case SyntaxKind.NamedTupleMember: return node.data.jsDoc = value; + case SyntaxKind.NamespaceExportDeclaration: return node.data.jsDoc = value; + case SyntaxKind.ObjectLiteralExpression: return node.data.jsDoc = value; + case SyntaxKind.Parameter: return node.data.jsDoc = value; + case SyntaxKind.ParenthesizedExpression: return node.data.jsDoc = value; + case SyntaxKind.PropertyAccessExpression: return node.data.jsDoc = value; + case SyntaxKind.PropertyAssignment: return node.data.jsDoc = value; + case SyntaxKind.PropertyDeclaration: return node.data.jsDoc = value; + case SyntaxKind.PropertySignature: return node.data.jsDoc = value; + case SyntaxKind.ReturnStatement: return node.data.jsDoc = value; + case SyntaxKind.SemicolonClassElement: return node.data.jsDoc = value; + case SyntaxKind.SetAccessor: return node.data.jsDoc = value; + case SyntaxKind.ShorthandPropertyAssignment: return node.data.jsDoc = value; + case SyntaxKind.SpreadAssignment: return node.data.jsDoc = value; + case SyntaxKind.SwitchStatement: return node.data.jsDoc = value; + case SyntaxKind.ThrowStatement: return node.data.jsDoc = value; + case SyntaxKind.TryStatement: return node.data.jsDoc = value; + case SyntaxKind.TypeAliasDeclaration: return node.data.jsDoc = value; + case SyntaxKind.TypeParameter: return node.data.jsDoc = value; + case SyntaxKind.VariableDeclaration: return node.data.jsDoc = value; + case SyntaxKind.VariableStatement: return node.data.jsDoc = value; + case SyntaxKind.WhileStatement: return node.data.jsDoc = value; + case SyntaxKind.WithStatement: return node.data.jsDoc = value; + case SyntaxKind.ModuleBlock: return node.data.jsDoc = value; + case SyntaxKind.MissingDeclaration: return node.data.jsDoc = value; + case SyntaxKind.NotEmittedStatement: return node.data.jsDoc = value; + default: + Debug.assertNever(node); // ensures `astSetJSDoc` is up-to-date with `AstHasJSDoc`/`HasJSDoc` + } +} + +/** @internal */ +export function astCanHaveExpression(node: AstNode): node is AstHasExpression { + Debug.type(node); // ensures `astCanHaveExpression` is up-to-date with `AstHasExpression`/`HasExpression` + switch (node.kind) { + case SyntaxKind.ComputedPropertyName: + case SyntaxKind.TypeParameter: + case SyntaxKind.Decorator: + case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ElementAccessExpression: - node.data.jsDoc = value; - break; - case SyntaxKind.EmptyStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.EndOfFileToken: - node.data.jsDoc = value; - break; - case SyntaxKind.EnumDeclaration: - node.data.jsDoc = value; - break; - case SyntaxKind.EnumMember: - node.data.jsDoc = value; - break; - case SyntaxKind.ExportAssignment: - node.data.jsDoc = value; - break; - case SyntaxKind.ExportDeclaration: - node.data.jsDoc = value; - break; - case SyntaxKind.ExportSpecifier: - node.data.jsDoc = value; - break; - case SyntaxKind.ExpressionStatement: - node.data.jsDoc = value; - break; + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.DeleteExpression: + case SyntaxKind.TypeOfExpression: + case SyntaxKind.VoidExpression: + case SyntaxKind.AwaitExpression: case SyntaxKind.ForInStatement: - node.data.jsDoc = value; - break; case SyntaxKind.ForOfStatement: - node.data.jsDoc = value; - break; + case SyntaxKind.ExpressionStatement: + case SyntaxKind.IfStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.WhileStatement: + case SyntaxKind.YieldExpression: + case SyntaxKind.SpreadElement: + case SyntaxKind.ExpressionWithTypeArguments: + case SyntaxKind.AsExpression: + case SyntaxKind.NonNullExpression: + case SyntaxKind.SatisfiesExpression: + case SyntaxKind.TemplateSpan: + case SyntaxKind.ReturnStatement: + case SyntaxKind.WithStatement: + case SyntaxKind.SwitchStatement: + case SyntaxKind.ThrowStatement: + case SyntaxKind.ExportAssignment: + case SyntaxKind.ExternalModuleReference: + case SyntaxKind.JsxSpreadAttribute: + case SyntaxKind.JsxExpression: + case SyntaxKind.CaseClause: + case SyntaxKind.SpreadAssignment: + case SyntaxKind.PartiallyEmittedExpression: + case SyntaxKind.SyntheticReferenceExpression: + return true; + default: + Debug.assertNeverTypeOnly(node); // ensures `astCanHaveExpression` is up-to-date with `AstHasExpression`/`HasExpression` + return false; + } +} + +/** @internal */ +export function astGetExpression(node: T): AstGetResult; +export function astGetExpression(node: AstNode) { + Debug.type(node); // ensures `astGetExpression` is up-to-date with `AstHasExpression`/`HasExpression` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.ComputedPropertyName: return node.data.expression; + case SyntaxKind.TypeParameter: return node.data.expression; + case SyntaxKind.Decorator: return node.data.expression; + case SyntaxKind.PropertyAccessExpression: return node.data.expression; + case SyntaxKind.ElementAccessExpression: return node.data.expression; + case SyntaxKind.CallExpression: return node.data.expression; + case SyntaxKind.NewExpression: return node.data.expression; + case SyntaxKind.TypeAssertionExpression: return node.data.expression; + case SyntaxKind.ParenthesizedExpression: return node.data.expression; + case SyntaxKind.DeleteExpression: return node.data.expression; + case SyntaxKind.TypeOfExpression: return node.data.expression; + case SyntaxKind.VoidExpression: return node.data.expression; + case SyntaxKind.AwaitExpression: return node.data.expression; + case SyntaxKind.ForInStatement: return node.data.expression; + case SyntaxKind.ForOfStatement: return node.data.expression; + case SyntaxKind.ExpressionStatement: return node.data.expression; + case SyntaxKind.IfStatement: return node.data.expression; + case SyntaxKind.DoStatement: return node.data.expression; + case SyntaxKind.WhileStatement: return node.data.expression; + case SyntaxKind.YieldExpression: return node.data.expression; + case SyntaxKind.SpreadElement: return node.data.expression; + case SyntaxKind.ExpressionWithTypeArguments: return node.data.expression; + case SyntaxKind.AsExpression: return node.data.expression; + case SyntaxKind.NonNullExpression: return node.data.expression; + case SyntaxKind.SatisfiesExpression: return node.data.expression; + case SyntaxKind.TemplateSpan: return node.data.expression; + case SyntaxKind.ReturnStatement: return node.data.expression; + case SyntaxKind.WithStatement: return node.data.expression; + case SyntaxKind.SwitchStatement: return node.data.expression; + case SyntaxKind.ThrowStatement: return node.data.expression; + case SyntaxKind.ExportAssignment: return node.data.expression; + case SyntaxKind.ExternalModuleReference: return node.data.expression; + case SyntaxKind.JsxSpreadAttribute: return node.data.expression; + case SyntaxKind.JsxExpression: return node.data.expression; + case SyntaxKind.CaseClause: return node.data.expression; + case SyntaxKind.SpreadAssignment: return node.data.expression; + case SyntaxKind.PartiallyEmittedExpression: return node.data.expression; + case SyntaxKind.SyntheticReferenceExpression: return node.data.expression; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetExpression` is up-to-date with `AstHasExpression`/`HasExpression` + return undefined; + } +} + +/** @internal */ +export function astCanHaveFlowNode(node: AstNode): node is AstHasFlowNode { + Debug.type(node); // ensures `astCanHaveFlowNode` is up-to-date with `AstHasFlowNode`/`HasFlowNode` + switch (node.kind) { + case SyntaxKind.VariableStatement: + case SyntaxKind.ExpressionStatement: + case SyntaxKind.IfStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.WhileStatement: case SyntaxKind.ForStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.FunctionDeclaration: - node.data.jsDoc = value; - break; + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + case SyntaxKind.ContinueStatement: + case SyntaxKind.BreakStatement: + case SyntaxKind.ReturnStatement: + case SyntaxKind.WithStatement: + case SyntaxKind.SwitchStatement: + case SyntaxKind.LabeledStatement: + case SyntaxKind.ThrowStatement: + case SyntaxKind.TryStatement: + case SyntaxKind.DebuggerStatement: + case SyntaxKind.Identifier: + case SyntaxKind.ThisKeyword: + case SyntaxKind.SuperKeyword: + case SyntaxKind.QualifiedName: + case SyntaxKind.MetaProperty: + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.BindingElement: case SyntaxKind.FunctionExpression: - node.data.jsDoc = value; - break; - case SyntaxKind.FunctionType: - node.data.jsDoc = value; - break; + case SyntaxKind.ArrowFunction: + case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: - node.data.jsDoc = value; - break; - case SyntaxKind.Identifier: - node.data.jsDoc = value; - break; - case SyntaxKind.IfStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.ImportDeclaration: - node.data.jsDoc = value; - break; - case SyntaxKind.ImportEqualsDeclaration: - node.data.jsDoc = value; - break; + case SyntaxKind.SetAccessor: + return true; + default: + Debug.assertNeverTypeOnly(node); // ensures `astCanHaveFlowNode` is up-to-date with `AstHasFlowNode`/`HasFlowNode` + return false; + } +} + +/** @internal */ +export function astGetFlowNode(node: AstNode): FlowNode | undefined { + Debug.type(node); // ensures `astGetFlowNode` is up-to-date with `AstHasFlowNode`/`HasFlowNode` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.VariableStatement: return node.data.flowNode; + case SyntaxKind.ExpressionStatement: return node.data.flowNode; + case SyntaxKind.IfStatement: return node.data.flowNode; + case SyntaxKind.DoStatement: return node.data.flowNode; + case SyntaxKind.WhileStatement: return node.data.flowNode; + case SyntaxKind.ForStatement: return node.data.flowNode; + case SyntaxKind.ForInStatement: return node.data.flowNode; + case SyntaxKind.ForOfStatement: return node.data.flowNode; + case SyntaxKind.ContinueStatement: return node.data.flowNode; + case SyntaxKind.BreakStatement: return node.data.flowNode; + case SyntaxKind.ReturnStatement: return node.data.flowNode; + case SyntaxKind.WithStatement: return node.data.flowNode; + case SyntaxKind.SwitchStatement: return node.data.flowNode; + case SyntaxKind.LabeledStatement: return node.data.flowNode; + case SyntaxKind.ThrowStatement: return node.data.flowNode; + case SyntaxKind.TryStatement: return node.data.flowNode; + case SyntaxKind.DebuggerStatement: return node.data.flowNode; + case SyntaxKind.Identifier: return node.data.flowNode; + case SyntaxKind.ThisKeyword: return node.data.flowNode; + case SyntaxKind.SuperKeyword: return node.data.flowNode; + case SyntaxKind.QualifiedName: return node.data.flowNode; + case SyntaxKind.MetaProperty: return node.data.flowNode; + case SyntaxKind.ElementAccessExpression: return node.data.flowNode; + case SyntaxKind.PropertyAccessExpression: return node.data.flowNode; + case SyntaxKind.BindingElement: return node.data.flowNode; + case SyntaxKind.FunctionExpression: return node.data.flowNode; + case SyntaxKind.ArrowFunction: return node.data.flowNode; + case SyntaxKind.MethodDeclaration: return node.data.flowNode; + case SyntaxKind.GetAccessor: return node.data.flowNode; + case SyntaxKind.SetAccessor: return node.data.flowNode; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetFlowNode` is up-to-date with `AstHasFlowNode`/`HasFlowNode` + return undefined; + } +} + +/** @internal */ +export function astSetFlowNode(node: AstHasFlowNode, value: FlowNode | undefined): FlowNode | undefined { + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.VariableStatement: return node.data.flowNode = value; + case SyntaxKind.ExpressionStatement: return node.data.flowNode = value; + case SyntaxKind.IfStatement: return node.data.flowNode = value; + case SyntaxKind.DoStatement: return node.data.flowNode = value; + case SyntaxKind.WhileStatement: return node.data.flowNode = value; + case SyntaxKind.ForStatement: return node.data.flowNode = value; + case SyntaxKind.ForInStatement: return node.data.flowNode = value; + case SyntaxKind.ForOfStatement: return node.data.flowNode = value; + case SyntaxKind.ContinueStatement: return node.data.flowNode = value; + case SyntaxKind.BreakStatement: return node.data.flowNode = value; + case SyntaxKind.ReturnStatement: return node.data.flowNode = value; + case SyntaxKind.WithStatement: return node.data.flowNode = value; + case SyntaxKind.SwitchStatement: return node.data.flowNode = value; + case SyntaxKind.LabeledStatement: return node.data.flowNode = value; + case SyntaxKind.ThrowStatement: return node.data.flowNode = value; + case SyntaxKind.TryStatement: return node.data.flowNode = value; + case SyntaxKind.DebuggerStatement: return node.data.flowNode = value; + case SyntaxKind.Identifier: return node.data.flowNode = value; + case SyntaxKind.ThisKeyword: return node.data.flowNode = value; + case SyntaxKind.SuperKeyword: return node.data.flowNode = value; + case SyntaxKind.QualifiedName: return node.data.flowNode = value; + case SyntaxKind.MetaProperty: return node.data.flowNode = value; + case SyntaxKind.ElementAccessExpression: return node.data.flowNode = value; + case SyntaxKind.PropertyAccessExpression: return node.data.flowNode = value; + case SyntaxKind.BindingElement: return node.data.flowNode = value; + case SyntaxKind.FunctionExpression: return node.data.flowNode = value; + case SyntaxKind.ArrowFunction: return node.data.flowNode = value; + case SyntaxKind.MethodDeclaration: return node.data.flowNode = value; + case SyntaxKind.GetAccessor: return node.data.flowNode = value; + case SyntaxKind.SetAccessor: return node.data.flowNode = value; + default: + return Debug.assertNever(node); // ensures `astSetFlowNode` is up-to-date with `AstHasFlowNode`/`HasFlowNode` + } +} + +/** @internal */ +export function astGetEndFlowNode(node: AstNode): FlowNode | undefined { + Debug.type(node); // ensures `astGetEndFlowNode` is up-to-date with `AstHasEndFlowNode`/`HasEndFlowNode` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.MethodDeclaration: return node.data.endFlowNode; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.endFlowNode; + case SyntaxKind.Constructor: return node.data.endFlowNode; + case SyntaxKind.GetAccessor: return node.data.endFlowNode; + case SyntaxKind.SetAccessor: return node.data.endFlowNode; + case SyntaxKind.FunctionExpression: return node.data.endFlowNode; + case SyntaxKind.ArrowFunction: return node.data.endFlowNode; + case SyntaxKind.FunctionDeclaration: return node.data.endFlowNode; + case SyntaxKind.SourceFile: return node.data.endFlowNode; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetEndFlowNode` is up-to-date with `AstHasEndFlowNode`/`HasEndFlowNode` + return undefined; + } +} + +/** @internal */ +export function astSetEndFlowNode(node: AstHasEndFlowNode, value: FlowNode | undefined): FlowNode | undefined { + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.MethodDeclaration: return node.data.endFlowNode = value; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.endFlowNode = value; + case SyntaxKind.Constructor: return node.data.endFlowNode = value; + case SyntaxKind.GetAccessor: return node.data.endFlowNode = value; + case SyntaxKind.SetAccessor: return node.data.endFlowNode = value; + case SyntaxKind.FunctionExpression: return node.data.endFlowNode = value; + case SyntaxKind.ArrowFunction: return node.data.endFlowNode = value; + case SyntaxKind.FunctionDeclaration: return node.data.endFlowNode = value; + case SyntaxKind.SourceFile: return node.data.endFlowNode = value; + default: + return Debug.assertNever(node); // ensures `astSetEndFlowNode` is up-to-date with `AstHasEndFlowNode`/`HasEndFlowNode` + } +} + +/** @internal */ +export function astCanHaveInitializer(node: AstNode): node is AstHasInitializer { + Debug.type(node); // ensures `astCanHaveInitializer` is up-to-date with `AstHasInitializer`/`HasInitializer` + switch (node.kind) { + case SyntaxKind.Parameter: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.BindingElement: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + case SyntaxKind.VariableDeclaration: + case SyntaxKind.JsxAttribute: + case SyntaxKind.PropertyAssignment: + case SyntaxKind.PropertySignature: + case SyntaxKind.EnumMember: + return true; + default: + Debug.assertNeverTypeOnly(node); // ensures `astCanHaveInitializer` is up-to-date with `AstHasInitializer`/`HasInitializer` + return false; + } +} + +/** @internal */ +export function astGetInitializer(node: T): AstGetResult; +export function astGetInitializer(node: AstNode) { + Debug.type(node); // ensures `astGetInitializer` is up-to-date with `AstHasInitializer`/`HasInitializer` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.Parameter: return node.data.initializer; + case SyntaxKind.PropertyDeclaration: return node.data.initializer; + case SyntaxKind.BindingElement: return node.data.initializer; + case SyntaxKind.ForStatement: return node.data.initializer; + case SyntaxKind.ForInStatement: return node.data.initializer; + case SyntaxKind.ForOfStatement: return node.data.initializer; + case SyntaxKind.VariableDeclaration: return node.data.initializer; + case SyntaxKind.JsxAttribute: return node.data.initializer; + case SyntaxKind.PropertyAssignment: return node.data.initializer; + case SyntaxKind.PropertySignature: return node.data.initializer; + case SyntaxKind.EnumMember: return node.data.initializer; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetInitializer` is up-to-date with `AstHasInitializer`/`HasInitializer` + return undefined; + } +} + +/** @internal */ +export function astCanHaveModifiers(node: AstNode): node is AstHasModifiers { + Debug.type(node); // ensures `astCanHaveModifiers` is up-to-date with `AstHasModifiers`/`HasModifiers` + switch (node.kind) { + case SyntaxKind.TypeParameter: + case SyntaxKind.Parameter: + case SyntaxKind.PropertySignature: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.Constructor: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: case SyntaxKind.IndexSignature: - node.data.jsDoc = value; - break; + case SyntaxKind.ConstructorType: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.ClassExpression: + case SyntaxKind.VariableStatement: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: - node.data.jsDoc = value; - break; - case SyntaxKind.JSDocFunctionType: - node.data.jsDoc = value; - break; - case SyntaxKind.JSDocSignature: - node.data.jsDoc = value; - break; - case SyntaxKind.LabeledStatement: - node.data.jsDoc = value; - break; + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ImportDeclaration: + case SyntaxKind.ExportAssignment: + case SyntaxKind.ExportDeclaration: + return true; + default: + Debug.assertNeverTypeOnly(node); // ensures `astCanHaveModifiers` is up-to-date with `AstHasModifiers`/`HasModifiers` + return false; + } +} + +/** @internal */ +export function astGetModifiers(node: T): AstGetResult; +export function astGetModifiers(node: AstNode) { + Debug.type(node); // ensures `astGetModifiers` is up-to-date with `AstHasModifiers`/`HasModifiers` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.TypeParameter: return node.data.modifiers; + case SyntaxKind.Parameter: return node.data.modifiers; + case SyntaxKind.PropertySignature: return node.data.modifiers; + case SyntaxKind.PropertyDeclaration: return node.data.modifiers; + case SyntaxKind.MethodSignature: return node.data.modifiers; + case SyntaxKind.MethodDeclaration: return node.data.modifiers; + case SyntaxKind.Constructor: return node.data.modifiers; + case SyntaxKind.GetAccessor: return node.data.modifiers; + case SyntaxKind.SetAccessor: return node.data.modifiers; + case SyntaxKind.IndexSignature: return node.data.modifiers; + case SyntaxKind.ConstructorType: return node.data.modifiers; + case SyntaxKind.FunctionExpression: return node.data.modifiers; + case SyntaxKind.ArrowFunction: return node.data.modifiers; + case SyntaxKind.ClassExpression: return node.data.modifiers; + case SyntaxKind.VariableStatement: return node.data.modifiers; + case SyntaxKind.FunctionDeclaration: return node.data.modifiers; + case SyntaxKind.ClassDeclaration: return node.data.modifiers; + case SyntaxKind.InterfaceDeclaration: return node.data.modifiers; + case SyntaxKind.TypeAliasDeclaration: return node.data.modifiers; + case SyntaxKind.EnumDeclaration: return node.data.modifiers; + case SyntaxKind.ModuleDeclaration: return node.data.modifiers; + case SyntaxKind.ImportEqualsDeclaration: return node.data.modifiers; + case SyntaxKind.ImportDeclaration: return node.data.modifiers; + case SyntaxKind.ExportAssignment: return node.data.modifiers; + case SyntaxKind.ExportDeclaration: return node.data.modifiers; + case SyntaxKind.MissingDeclaration: return node.data.modifiers; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.modifiers; + case SyntaxKind.NamespaceExportDeclaration: return node.data.modifiers; + case SyntaxKind.PropertyAssignment: return node.data.modifiers; + case SyntaxKind.ShorthandPropertyAssignment: return node.data.modifiers; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetModifiers` is up-to-date with `AstHasModifiers`/`HasModifiers` + return undefined; + } +} + +/** @internal */ +export function astCanHaveDecorators(node: AstNode): node is AstHasDecorators { + Debug.type(node); // ensures `astCanHaveDecorators` is up-to-date with `AstHasDecorators`/`HasDecorators` + switch (node.kind) { + case SyntaxKind.Parameter: + case SyntaxKind.PropertyDeclaration: case SyntaxKind.MethodDeclaration: - node.data.jsDoc = value; - break; + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.ClassExpression: + case SyntaxKind.ClassDeclaration: + return true; + default: + Debug.assertNeverTypeOnly(node); // ensures `astCanHaveDecorators` is up-to-date with `AstHasDecorators`/`HasDecorators` + return false; + } +} + +/** @internal */ +export function astGetRawText(node: AstNode): string | undefined { + Debug.type(node); // ensures `astGetRawText` is up-to-date with `AstTemplateLiteralToken`/`TemplateLiteralToken` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.NoSubstitutionTemplateLiteral: return node.data.rawText; + case SyntaxKind.TemplateHead: return node.data.rawText; + case SyntaxKind.TemplateMiddle: return node.data.rawText; + case SyntaxKind.TemplateTail: return node.data.rawText; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetRawText` is up-to-date with `AstTemplateLiteralToken`/`TemplateLiteralToken` + return undefined; + } +} + +/** @internal */ +export function astGetText(node: T): AstGetResult; +export function astGetText(node: AstNode): string | undefined { + Debug.type(node); // ensures `astGetText` is up-to-date with `AstHasText`/`HasText` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.NumericLiteral: return node.data.text; + case SyntaxKind.BigIntLiteral: return node.data.text; + case SyntaxKind.StringLiteral: return node.data.text; + case SyntaxKind.RegularExpressionLiteral: return node.data.text; + case SyntaxKind.NoSubstitutionTemplateLiteral: return node.data.text; + case SyntaxKind.TemplateHead: return node.data.text; + case SyntaxKind.TemplateMiddle: return node.data.text; + case SyntaxKind.TemplateTail: return node.data.text; + case SyntaxKind.JsxText: return node.data.text; + case SyntaxKind.JSDocText: return node.data.text; + case SyntaxKind.JSDocLink: return node.data.text; + case SyntaxKind.JSDocLinkCode: return node.data.text; + case SyntaxKind.JSDocLinkPlain: return node.data.text; + case SyntaxKind.SourceFile: return node.data.text; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetText` is up-to-date with `AstHasText`/`HasText` + return undefined; + } +} + +/** @internal */ +export function astCanHaveSymbol(node: AstNode): node is AstHasSymbol { + Debug.type(node); // ensures `astCanHaveSymbol` is up-to-date with `AstHasSymbol`/`HasSymbol` + switch (node.kind) { + case SyntaxKind.NumericLiteral: + case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.Identifier: + case SyntaxKind.TypeParameter: + case SyntaxKind.Parameter: + case SyntaxKind.PropertySignature: + case SyntaxKind.PropertyDeclaration: case SyntaxKind.MethodSignature: - node.data.jsDoc = value; - break; - case SyntaxKind.ModuleDeclaration: - node.data.jsDoc = value; - break; + case SyntaxKind.MethodDeclaration: + case SyntaxKind.ClassStaticBlockDeclaration: + case SyntaxKind.Constructor: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.CallSignature: + case SyntaxKind.ConstructSignature: + case SyntaxKind.IndexSignature: + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + case SyntaxKind.TypeLiteral: + case SyntaxKind.MappedType: case SyntaxKind.NamedTupleMember: - node.data.jsDoc = value; - break; - case SyntaxKind.NamespaceExportDeclaration: - node.data.jsDoc = value; - break; + case SyntaxKind.BindingElement: case SyntaxKind.ObjectLiteralExpression: - node.data.jsDoc = value; - break; - case SyntaxKind.Parameter: - node.data.jsDoc = value; - break; - case SyntaxKind.ParenthesizedExpression: - node.data.jsDoc = value; - break; case SyntaxKind.PropertyAccessExpression: - node.data.jsDoc = value; - break; + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.BinaryExpression: + case SyntaxKind.ClassExpression: + case SyntaxKind.VariableDeclaration: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.NamespaceExportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportClause: + case SyntaxKind.NamespaceImport: + case SyntaxKind.ImportSpecifier: + case SyntaxKind.ExportAssignment: + case SyntaxKind.ExportDeclaration: + case SyntaxKind.NamespaceExport: + case SyntaxKind.ExportSpecifier: + case SyntaxKind.MissingDeclaration: + case SyntaxKind.JsxAttribute: + case SyntaxKind.JsxAttributes: case SyntaxKind.PropertyAssignment: - node.data.jsDoc = value; - break; - case SyntaxKind.PropertyDeclaration: - node.data.jsDoc = value; - break; - case SyntaxKind.PropertySignature: - node.data.jsDoc = value; - break; - case SyntaxKind.ReturnStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.SemicolonClassElement: - node.data.jsDoc = value; - break; - case SyntaxKind.SetAccessor: - node.data.jsDoc = value; - break; case SyntaxKind.ShorthandPropertyAssignment: - node.data.jsDoc = value; - break; case SyntaxKind.SpreadAssignment: - node.data.jsDoc = value; - break; - case SyntaxKind.SwitchStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.ThrowStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.TryStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.TypeAliasDeclaration: - node.data.jsDoc = value; - break; - case SyntaxKind.TypeParameter: - node.data.jsDoc = value; - break; - case SyntaxKind.VariableDeclaration: - node.data.jsDoc = value; - break; - case SyntaxKind.VariableStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.WhileStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.WithStatement: - node.data.jsDoc = value; - break; - case SyntaxKind.ModuleBlock: - node.data.jsDoc = value; - break; - case SyntaxKind.MissingDeclaration: - node.data.jsDoc = value; - break; - case SyntaxKind.NotEmittedStatement: - node.data.jsDoc = value; - break; - default: Debug.assertNever(node); + case SyntaxKind.EnumMember: + case SyntaxKind.SourceFile: + case SyntaxKind.JSDocFunctionType: + case SyntaxKind.JSDocTypeLiteral: + case SyntaxKind.JSDocSignature: + case SyntaxKind.JSDocCallbackTag: + case SyntaxKind.JSDocEnumTag: + case SyntaxKind.JSDocParameterTag: + case SyntaxKind.JSDocTypedefTag: + case SyntaxKind.JSDocPropertyTag: + case SyntaxKind.NotEmittedTypeElement: + return true; + default: + Debug.assertNeverTypeOnly(node); // ensures `astCanHaveSymbol` is up-to-date with `AstHasSymbol`/`HasSymbol` + return false; + } +} + +/** @internal */ +export function astGetSymbol(node: T): T extends AstHasSymbol ? Symbol : Symbol | undefined; +export function astGetSymbol(node: T) { + Debug.type(node); // ensures `astGetSymbol` is up-to-date with `AstHasSymbol`/`HasSymbol` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.NumericLiteral: return node.data.symbol; + case SyntaxKind.StringLiteral: return node.data.symbol; + case SyntaxKind.NoSubstitutionTemplateLiteral: return node.data.symbol; + case SyntaxKind.Identifier: return node.data.symbol; + case SyntaxKind.TypeParameter: return node.data.symbol; + case SyntaxKind.Parameter: return node.data.symbol; + case SyntaxKind.PropertySignature: return node.data.symbol; + case SyntaxKind.PropertyDeclaration: return node.data.symbol; + case SyntaxKind.MethodSignature: return node.data.symbol; + case SyntaxKind.MethodDeclaration: return node.data.symbol; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.symbol; + case SyntaxKind.Constructor: return node.data.symbol; + case SyntaxKind.GetAccessor: return node.data.symbol; + case SyntaxKind.SetAccessor: return node.data.symbol; + case SyntaxKind.CallSignature: return node.data.symbol; + case SyntaxKind.ConstructSignature: return node.data.symbol; + case SyntaxKind.IndexSignature: return node.data.symbol; + case SyntaxKind.FunctionType: return node.data.symbol; + case SyntaxKind.ConstructorType: return node.data.symbol; + case SyntaxKind.TypeLiteral: return node.data.symbol; + case SyntaxKind.MappedType: return node.data.symbol; + case SyntaxKind.NamedTupleMember: return node.data.symbol; + case SyntaxKind.BindingElement: return node.data.symbol; + case SyntaxKind.ObjectLiteralExpression: return node.data.symbol; + case SyntaxKind.PropertyAccessExpression: return node.data.symbol; + case SyntaxKind.ElementAccessExpression: return node.data.symbol; + case SyntaxKind.CallExpression: return node.data.symbol; + case SyntaxKind.NewExpression: return node.data.symbol; + case SyntaxKind.FunctionExpression: return node.data.symbol; + case SyntaxKind.ArrowFunction: return node.data.symbol; + case SyntaxKind.BinaryExpression: return node.data.symbol; + case SyntaxKind.ClassExpression: return node.data.symbol; + case SyntaxKind.VariableDeclaration: return node.data.symbol; + case SyntaxKind.FunctionDeclaration: return node.data.symbol; + case SyntaxKind.ClassDeclaration: return node.data.symbol; + case SyntaxKind.InterfaceDeclaration: return node.data.symbol; + case SyntaxKind.TypeAliasDeclaration: return node.data.symbol; + case SyntaxKind.EnumDeclaration: return node.data.symbol; + case SyntaxKind.ModuleDeclaration: return node.data.symbol; + case SyntaxKind.NamespaceExportDeclaration: return node.data.symbol; + case SyntaxKind.ImportEqualsDeclaration: return node.data.symbol; + case SyntaxKind.ImportDeclaration: return node.data.symbol; + case SyntaxKind.ImportClause: return node.data.symbol; + case SyntaxKind.NamespaceImport: return node.data.symbol; + case SyntaxKind.ImportSpecifier: return node.data.symbol; + case SyntaxKind.ExportAssignment: return node.data.symbol; + case SyntaxKind.ExportDeclaration: return node.data.symbol; + case SyntaxKind.NamespaceExport: return node.data.symbol; + case SyntaxKind.ExportSpecifier: return node.data.symbol; + case SyntaxKind.MissingDeclaration: return node.data.symbol; + case SyntaxKind.JsxAttribute: return node.data.symbol; + case SyntaxKind.JsxAttributes: return node.data.symbol; + case SyntaxKind.PropertyAssignment: return node.data.symbol; + case SyntaxKind.ShorthandPropertyAssignment: return node.data.symbol; + case SyntaxKind.SpreadAssignment: return node.data.symbol; + case SyntaxKind.EnumMember: return node.data.symbol; + case SyntaxKind.SourceFile: return node.data.declaration.symbol; + case SyntaxKind.JSDocFunctionType: return node.data.symbol; + case SyntaxKind.JSDocTypeLiteral: return node.data.symbol; + case SyntaxKind.JSDocSignature: return node.data.symbol; + case SyntaxKind.JSDocCallbackTag: return node.data.symbol; + case SyntaxKind.JSDocEnumTag: return node.data.symbol; + case SyntaxKind.JSDocParameterTag: return node.data.symbol; + case SyntaxKind.JSDocTypedefTag: return node.data.symbol; + case SyntaxKind.JSDocPropertyTag: return node.data.symbol; + case SyntaxKind.NotEmittedTypeElement: return node.data.symbol; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetSymbol` is up-to-date with `AstHasSymbol`/`HasSymbol` + return undefined; + } +} + +/** @internal */ +export function astSetSymbol(node: AstHasSymbol, value: Symbol): Symbol { + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.NumericLiteral: return node.data.symbol = value; + case SyntaxKind.StringLiteral: return node.data.symbol = value; + case SyntaxKind.NoSubstitutionTemplateLiteral: return node.data.symbol = value; + case SyntaxKind.Identifier: return node.data.symbol = value; + case SyntaxKind.TypeParameter: return node.data.symbol = value; + case SyntaxKind.Parameter: return node.data.symbol = value; + case SyntaxKind.PropertySignature: return node.data.symbol = value; + case SyntaxKind.PropertyDeclaration: return node.data.symbol = value; + case SyntaxKind.MethodSignature: return node.data.symbol = value; + case SyntaxKind.MethodDeclaration: return node.data.symbol = value; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.symbol = value; + case SyntaxKind.Constructor: return node.data.symbol = value; + case SyntaxKind.GetAccessor: return node.data.symbol = value; + case SyntaxKind.SetAccessor: return node.data.symbol = value; + case SyntaxKind.CallSignature: return node.data.symbol = value; + case SyntaxKind.ConstructSignature: return node.data.symbol = value; + case SyntaxKind.IndexSignature: return node.data.symbol = value; + case SyntaxKind.FunctionType: return node.data.symbol = value; + case SyntaxKind.ConstructorType: return node.data.symbol = value; + case SyntaxKind.TypeLiteral: return node.data.symbol = value; + case SyntaxKind.MappedType: return node.data.symbol = value; + case SyntaxKind.NamedTupleMember: return node.data.symbol = value; + case SyntaxKind.BindingElement: return node.data.symbol = value; + case SyntaxKind.ObjectLiteralExpression: return node.data.symbol = value; + case SyntaxKind.PropertyAccessExpression: return node.data.symbol = value; + case SyntaxKind.ElementAccessExpression: return node.data.symbol = value; + case SyntaxKind.CallExpression: return node.data.symbol = value; + case SyntaxKind.NewExpression: return node.data.symbol = value; + case SyntaxKind.FunctionExpression: return node.data.symbol = value; + case SyntaxKind.ArrowFunction: return node.data.symbol = value; + case SyntaxKind.BinaryExpression: return node.data.symbol = value; + case SyntaxKind.ClassExpression: return node.data.symbol = value; + case SyntaxKind.VariableDeclaration: return node.data.symbol = value; + case SyntaxKind.FunctionDeclaration: return node.data.symbol = value; + case SyntaxKind.ClassDeclaration: return node.data.symbol = value; + case SyntaxKind.InterfaceDeclaration: return node.data.symbol = value; + case SyntaxKind.TypeAliasDeclaration: return node.data.symbol = value; + case SyntaxKind.EnumDeclaration: return node.data.symbol = value; + case SyntaxKind.ModuleDeclaration: return node.data.symbol = value; + case SyntaxKind.NamespaceExportDeclaration: return node.data.symbol = value; + case SyntaxKind.ImportEqualsDeclaration: return node.data.symbol = value; + case SyntaxKind.ImportDeclaration: return node.data.symbol = value; + case SyntaxKind.ImportClause: return node.data.symbol = value; + case SyntaxKind.NamespaceImport: return node.data.symbol = value; + case SyntaxKind.ImportSpecifier: return node.data.symbol = value; + case SyntaxKind.ExportAssignment: return node.data.symbol = value; + case SyntaxKind.ExportDeclaration: return node.data.symbol = value; + case SyntaxKind.NamespaceExport: return node.data.symbol = value; + case SyntaxKind.ExportSpecifier: return node.data.symbol = value; + case SyntaxKind.MissingDeclaration: return node.data.symbol = value; + case SyntaxKind.JsxAttribute: return node.data.symbol = value; + case SyntaxKind.JsxAttributes: return node.data.symbol = value; + case SyntaxKind.PropertyAssignment: return node.data.symbol = value; + case SyntaxKind.ShorthandPropertyAssignment: return node.data.symbol = value; + case SyntaxKind.SpreadAssignment: return node.data.symbol = value; + case SyntaxKind.EnumMember: return node.data.symbol = value; + case SyntaxKind.SourceFile: return node.data.declaration.symbol = value; + case SyntaxKind.JSDocFunctionType: return node.data.symbol = value; + case SyntaxKind.JSDocTypeLiteral: return node.data.symbol = value; + case SyntaxKind.JSDocSignature: return node.data.symbol = value; + case SyntaxKind.JSDocCallbackTag: return node.data.symbol = value; + case SyntaxKind.JSDocEnumTag: return node.data.symbol = value; + case SyntaxKind.JSDocParameterTag: return node.data.symbol = value; + case SyntaxKind.JSDocTypedefTag: return node.data.symbol = value; + case SyntaxKind.JSDocPropertyTag: return node.data.symbol = value; + case SyntaxKind.NotEmittedTypeElement: return node.data.symbol = value; + default: + Debug.assertNever(node); // ensures `astSetSymbol` is up-to-date with `AstHasSymbol`/`HasSymbol` + } +} + +/** @internal */ +export function astGetLocalSymbol(node: AstNode): Symbol | undefined; +export function astGetLocalSymbol(node: AstNode) { + Debug.type(node); // ensures `astGetLocalSymbol` is up-to-date with `AstHasSymbol`/`HasSymbol` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.NumericLiteral: return node.data.localSymbol; + case SyntaxKind.StringLiteral: return node.data.localSymbol; + case SyntaxKind.NoSubstitutionTemplateLiteral: return node.data.localSymbol; + case SyntaxKind.Identifier: return node.data.localSymbol; + case SyntaxKind.TypeParameter: return node.data.localSymbol; + case SyntaxKind.Parameter: return node.data.localSymbol; + case SyntaxKind.PropertySignature: return node.data.localSymbol; + case SyntaxKind.PropertyDeclaration: return node.data.localSymbol; + case SyntaxKind.MethodSignature: return node.data.localSymbol; + case SyntaxKind.MethodDeclaration: return node.data.localSymbol; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.localSymbol; + case SyntaxKind.Constructor: return node.data.localSymbol; + case SyntaxKind.GetAccessor: return node.data.localSymbol; + case SyntaxKind.SetAccessor: return node.data.localSymbol; + case SyntaxKind.CallSignature: return node.data.localSymbol; + case SyntaxKind.ConstructSignature: return node.data.localSymbol; + case SyntaxKind.IndexSignature: return node.data.localSymbol; + case SyntaxKind.FunctionType: return node.data.localSymbol; + case SyntaxKind.ConstructorType: return node.data.localSymbol; + case SyntaxKind.TypeLiteral: return node.data.localSymbol; + case SyntaxKind.MappedType: return node.data.localSymbol; + case SyntaxKind.NamedTupleMember: return node.data.localSymbol; + case SyntaxKind.BindingElement: return node.data.localSymbol; + case SyntaxKind.ObjectLiteralExpression: return node.data.localSymbol; + case SyntaxKind.PropertyAccessExpression: return node.data.localSymbol; + case SyntaxKind.ElementAccessExpression: return node.data.localSymbol; + case SyntaxKind.CallExpression: return node.data.localSymbol; + case SyntaxKind.NewExpression: return node.data.localSymbol; + case SyntaxKind.FunctionExpression: return node.data.localSymbol; + case SyntaxKind.ArrowFunction: return node.data.localSymbol; + case SyntaxKind.BinaryExpression: return node.data.localSymbol; + case SyntaxKind.ClassExpression: return node.data.localSymbol; + case SyntaxKind.VariableDeclaration: return node.data.localSymbol; + case SyntaxKind.FunctionDeclaration: return node.data.localSymbol; + case SyntaxKind.ClassDeclaration: return node.data.localSymbol; + case SyntaxKind.InterfaceDeclaration: return node.data.localSymbol; + case SyntaxKind.TypeAliasDeclaration: return node.data.localSymbol; + case SyntaxKind.EnumDeclaration: return node.data.localSymbol; + case SyntaxKind.ModuleDeclaration: return node.data.localSymbol; + case SyntaxKind.NamespaceExportDeclaration: return node.data.localSymbol; + case SyntaxKind.ImportEqualsDeclaration: return node.data.localSymbol; + case SyntaxKind.ImportDeclaration: return node.data.localSymbol; + case SyntaxKind.ImportClause: return node.data.localSymbol; + case SyntaxKind.NamespaceImport: return node.data.localSymbol; + case SyntaxKind.ImportSpecifier: return node.data.localSymbol; + case SyntaxKind.ExportAssignment: return node.data.localSymbol; + case SyntaxKind.ExportDeclaration: return node.data.localSymbol; + case SyntaxKind.NamespaceExport: return node.data.localSymbol; + case SyntaxKind.ExportSpecifier: return node.data.localSymbol; + case SyntaxKind.MissingDeclaration: return node.data.localSymbol; + case SyntaxKind.JsxAttribute: return node.data.localSymbol; + case SyntaxKind.JsxAttributes: return node.data.localSymbol; + case SyntaxKind.PropertyAssignment: return node.data.localSymbol; + case SyntaxKind.ShorthandPropertyAssignment: return node.data.localSymbol; + case SyntaxKind.SpreadAssignment: return node.data.localSymbol; + case SyntaxKind.EnumMember: return node.data.localSymbol; + case SyntaxKind.SourceFile: return node.data.declaration.localSymbol; + case SyntaxKind.JSDocFunctionType: return node.data.localSymbol; + case SyntaxKind.JSDocTypeLiteral: return node.data.localSymbol; + case SyntaxKind.JSDocSignature: return node.data.localSymbol; + case SyntaxKind.JSDocCallbackTag: return node.data.localSymbol; + case SyntaxKind.JSDocEnumTag: return node.data.localSymbol; + case SyntaxKind.JSDocParameterTag: return node.data.localSymbol; + case SyntaxKind.JSDocTypedefTag: return node.data.localSymbol; + case SyntaxKind.JSDocPropertyTag: return node.data.localSymbol; + case SyntaxKind.NotEmittedTypeElement: return node.data.localSymbol; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetLocalSymbol` is up-to-date with `AstHasSymbol`/`HasSymbol` + return undefined; + } +} + +/** @internal */ +export function astSetLocalSymbol(node: AstHasSymbol, value: Symbol | undefined): Symbol | undefined { + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.NumericLiteral: return node.data.localSymbol = value; + case SyntaxKind.StringLiteral: return node.data.localSymbol = value; + case SyntaxKind.NoSubstitutionTemplateLiteral: return node.data.localSymbol = value; + case SyntaxKind.Identifier: return node.data.localSymbol = value; + case SyntaxKind.TypeParameter: return node.data.localSymbol = value; + case SyntaxKind.Parameter: return node.data.localSymbol = value; + case SyntaxKind.PropertySignature: return node.data.localSymbol = value; + case SyntaxKind.PropertyDeclaration: return node.data.localSymbol = value; + case SyntaxKind.MethodSignature: return node.data.localSymbol = value; + case SyntaxKind.MethodDeclaration: return node.data.localSymbol = value; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.localSymbol = value; + case SyntaxKind.Constructor: return node.data.localSymbol = value; + case SyntaxKind.GetAccessor: return node.data.localSymbol = value; + case SyntaxKind.SetAccessor: return node.data.localSymbol = value; + case SyntaxKind.CallSignature: return node.data.localSymbol = value; + case SyntaxKind.ConstructSignature: return node.data.localSymbol = value; + case SyntaxKind.IndexSignature: return node.data.localSymbol = value; + case SyntaxKind.FunctionType: return node.data.localSymbol = value; + case SyntaxKind.ConstructorType: return node.data.localSymbol = value; + case SyntaxKind.TypeLiteral: return node.data.localSymbol = value; + case SyntaxKind.MappedType: return node.data.localSymbol = value; + case SyntaxKind.NamedTupleMember: return node.data.localSymbol = value; + case SyntaxKind.BindingElement: return node.data.localSymbol = value; + case SyntaxKind.ObjectLiteralExpression: return node.data.localSymbol = value; + case SyntaxKind.PropertyAccessExpression: return node.data.localSymbol = value; + case SyntaxKind.ElementAccessExpression: return node.data.localSymbol = value; + case SyntaxKind.CallExpression: return node.data.localSymbol = value; + case SyntaxKind.NewExpression: return node.data.localSymbol = value; + case SyntaxKind.FunctionExpression: return node.data.localSymbol = value; + case SyntaxKind.ArrowFunction: return node.data.localSymbol = value; + case SyntaxKind.BinaryExpression: return node.data.localSymbol = value; + case SyntaxKind.ClassExpression: return node.data.localSymbol = value; + case SyntaxKind.VariableDeclaration: return node.data.localSymbol = value; + case SyntaxKind.FunctionDeclaration: return node.data.localSymbol = value; + case SyntaxKind.ClassDeclaration: return node.data.localSymbol = value; + case SyntaxKind.InterfaceDeclaration: return node.data.localSymbol = value; + case SyntaxKind.TypeAliasDeclaration: return node.data.localSymbol = value; + case SyntaxKind.EnumDeclaration: return node.data.localSymbol = value; + case SyntaxKind.ModuleDeclaration: return node.data.localSymbol = value; + case SyntaxKind.NamespaceExportDeclaration: return node.data.localSymbol = value; + case SyntaxKind.ImportEqualsDeclaration: return node.data.localSymbol = value; + case SyntaxKind.ImportDeclaration: return node.data.localSymbol = value; + case SyntaxKind.ImportClause: return node.data.localSymbol = value; + case SyntaxKind.NamespaceImport: return node.data.localSymbol = value; + case SyntaxKind.ImportSpecifier: return node.data.localSymbol = value; + case SyntaxKind.ExportAssignment: return node.data.localSymbol = value; + case SyntaxKind.ExportDeclaration: return node.data.localSymbol = value; + case SyntaxKind.NamespaceExport: return node.data.localSymbol = value; + case SyntaxKind.ExportSpecifier: return node.data.localSymbol = value; + case SyntaxKind.MissingDeclaration: return node.data.localSymbol = value; + case SyntaxKind.JsxAttribute: return node.data.localSymbol = value; + case SyntaxKind.JsxAttributes: return node.data.localSymbol = value; + case SyntaxKind.PropertyAssignment: return node.data.localSymbol = value; + case SyntaxKind.ShorthandPropertyAssignment: return node.data.localSymbol = value; + case SyntaxKind.SpreadAssignment: return node.data.localSymbol = value; + case SyntaxKind.EnumMember: return node.data.localSymbol = value; + case SyntaxKind.SourceFile: return node.data.declaration.localSymbol = value; + case SyntaxKind.JSDocFunctionType: return node.data.localSymbol = value; + case SyntaxKind.JSDocTypeLiteral: return node.data.localSymbol = value; + case SyntaxKind.JSDocSignature: return node.data.localSymbol = value; + case SyntaxKind.JSDocCallbackTag: return node.data.localSymbol = value; + case SyntaxKind.JSDocEnumTag: return node.data.localSymbol = value; + case SyntaxKind.JSDocParameterTag: return node.data.localSymbol = value; + case SyntaxKind.JSDocTypedefTag: return node.data.localSymbol = value; + case SyntaxKind.JSDocPropertyTag: return node.data.localSymbol = value; + case SyntaxKind.NotEmittedTypeElement: return node.data.localSymbol = value; + default: + Debug.assertNever(node); // ensures `astSetLocalSymbol` is up-to-date with `AstHasSymbol`/`HasSymbol` + } +} + +/** @internal */ +export function astGetLocals(node: AstNode): SymbolTable | undefined { + Debug.type(node); // ensures `astGetLocals` is up-to-date with `AstHasLocals`/`HasLocals` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.MethodSignature: return node.data.locals; + case SyntaxKind.MethodDeclaration: return node.data.locals; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.locals; + case SyntaxKind.Constructor: return node.data.locals; + case SyntaxKind.GetAccessor: return node.data.locals; + case SyntaxKind.SetAccessor: return node.data.locals; + case SyntaxKind.CallSignature: return node.data.locals; + case SyntaxKind.ConstructSignature: return node.data.locals; + case SyntaxKind.IndexSignature: return node.data.locals; + case SyntaxKind.FunctionType: return node.data.locals; + case SyntaxKind.ConstructorType: return node.data.locals; + case SyntaxKind.ConditionalType: return node.data.locals; + case SyntaxKind.MappedType: return node.data.locals; + case SyntaxKind.FunctionExpression: return node.data.locals; + case SyntaxKind.ArrowFunction: return node.data.locals; + case SyntaxKind.Block: return node.data.locals; + case SyntaxKind.ForStatement: return node.data.locals; + case SyntaxKind.ForInStatement: return node.data.locals; + case SyntaxKind.ForOfStatement: return node.data.locals; + case SyntaxKind.FunctionDeclaration: return node.data.locals; + case SyntaxKind.TypeAliasDeclaration: return node.data.locals; + case SyntaxKind.ModuleDeclaration: return node.data.locals; + case SyntaxKind.CaseBlock: return node.data.locals; + case SyntaxKind.CatchClause: return node.data.locals; + case SyntaxKind.SourceFile: return node.data.locals; + case SyntaxKind.JSDocFunctionType: return node.data.locals; + case SyntaxKind.JSDocSignature: return node.data.locals; + case SyntaxKind.JSDocCallbackTag: return node.data.locals; + case SyntaxKind.JSDocEnumTag: return node.data.locals; + case SyntaxKind.JSDocTypedefTag: return node.data.locals; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetLocals` is up-to-date with `AstHasLocals`/`HasLocals` + return undefined; + } +} + +/** @internal */ +export function astSetLocals(node: AstHasLocals, value: SymbolTable | undefined): SymbolTable | undefined { + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.MethodSignature: return node.data.locals = value; + case SyntaxKind.MethodDeclaration: return node.data.locals = value; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.locals = value; + case SyntaxKind.Constructor: return node.data.locals = value; + case SyntaxKind.GetAccessor: return node.data.locals = value; + case SyntaxKind.SetAccessor: return node.data.locals = value; + case SyntaxKind.CallSignature: return node.data.locals = value; + case SyntaxKind.ConstructSignature: return node.data.locals = value; + case SyntaxKind.IndexSignature: return node.data.locals = value; + case SyntaxKind.FunctionType: return node.data.locals = value; + case SyntaxKind.ConstructorType: return node.data.locals = value; + case SyntaxKind.ConditionalType: return node.data.locals = value; + case SyntaxKind.MappedType: return node.data.locals = value; + case SyntaxKind.FunctionExpression: return node.data.locals = value; + case SyntaxKind.ArrowFunction: return node.data.locals = value; + case SyntaxKind.Block: return node.data.locals = value; + case SyntaxKind.ForStatement: return node.data.locals = value; + case SyntaxKind.ForInStatement: return node.data.locals = value; + case SyntaxKind.ForOfStatement: return node.data.locals = value; + case SyntaxKind.FunctionDeclaration: return node.data.locals = value; + case SyntaxKind.TypeAliasDeclaration: return node.data.locals = value; + case SyntaxKind.ModuleDeclaration: return node.data.locals = value; + case SyntaxKind.CaseBlock: return node.data.locals = value; + case SyntaxKind.CatchClause: return node.data.locals = value; + case SyntaxKind.SourceFile: return node.data.locals = value; + case SyntaxKind.JSDocFunctionType: return node.data.locals = value; + case SyntaxKind.JSDocSignature: return node.data.locals = value; + case SyntaxKind.JSDocCallbackTag: return node.data.locals = value; + case SyntaxKind.JSDocEnumTag: return node.data.locals = value; + case SyntaxKind.JSDocTypedefTag: return node.data.locals = value; + default: + Debug.assertNever(node); // ensures `astSetLocals` is up-to-date with `AstHasLocals`/`HasLocals` + } +} + +/** @internal */ +export function astGetNextContainer(node: AstNode): AstHasLocals | undefined { + Debug.type(node); // ensures `astGetNextContainer` is up-to-date with `AstHasLocals`/`HasLocals` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.MethodSignature: return node.data.nextContainer; + case SyntaxKind.MethodDeclaration: return node.data.nextContainer; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.nextContainer; + case SyntaxKind.Constructor: return node.data.nextContainer; + case SyntaxKind.GetAccessor: return node.data.nextContainer; + case SyntaxKind.SetAccessor: return node.data.nextContainer; + case SyntaxKind.CallSignature: return node.data.nextContainer; + case SyntaxKind.ConstructSignature: return node.data.nextContainer; + case SyntaxKind.IndexSignature: return node.data.nextContainer; + case SyntaxKind.FunctionType: return node.data.nextContainer; + case SyntaxKind.ConstructorType: return node.data.nextContainer; + case SyntaxKind.ConditionalType: return node.data.nextContainer; + case SyntaxKind.MappedType: return node.data.nextContainer; + case SyntaxKind.FunctionExpression: return node.data.nextContainer; + case SyntaxKind.ArrowFunction: return node.data.nextContainer; + case SyntaxKind.Block: return node.data.nextContainer; + case SyntaxKind.ForStatement: return node.data.nextContainer; + case SyntaxKind.ForInStatement: return node.data.nextContainer; + case SyntaxKind.ForOfStatement: return node.data.nextContainer; + case SyntaxKind.FunctionDeclaration: return node.data.nextContainer; + case SyntaxKind.TypeAliasDeclaration: return node.data.nextContainer; + case SyntaxKind.ModuleDeclaration: return node.data.nextContainer; + case SyntaxKind.CaseBlock: return node.data.nextContainer; + case SyntaxKind.CatchClause: return node.data.nextContainer; + case SyntaxKind.SourceFile: return node.data.nextContainer; + case SyntaxKind.JSDocFunctionType: return node.data.nextContainer; + case SyntaxKind.JSDocSignature: return node.data.nextContainer; + case SyntaxKind.JSDocCallbackTag: return node.data.nextContainer; + case SyntaxKind.JSDocEnumTag: return node.data.nextContainer; + case SyntaxKind.JSDocTypedefTag: return node.data.nextContainer; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetNextContainer` is up-to-date with `AstHasLocals`/`HasLocals` + return undefined; + } +} + +/** @internal */ +export function astSetNextContainer(node: AstHasLocals, value: AstHasLocals | undefined): AstHasLocals | undefined { + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.MethodSignature: return node.data.nextContainer = value; + case SyntaxKind.MethodDeclaration: return node.data.nextContainer = value; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.nextContainer = value; + case SyntaxKind.Constructor: return node.data.nextContainer = value; + case SyntaxKind.GetAccessor: return node.data.nextContainer = value; + case SyntaxKind.SetAccessor: return node.data.nextContainer = value; + case SyntaxKind.CallSignature: return node.data.nextContainer = value; + case SyntaxKind.ConstructSignature: return node.data.nextContainer = value; + case SyntaxKind.IndexSignature: return node.data.nextContainer = value; + case SyntaxKind.FunctionType: return node.data.nextContainer = value; + case SyntaxKind.ConstructorType: return node.data.nextContainer = value; + case SyntaxKind.ConditionalType: return node.data.nextContainer = value; + case SyntaxKind.MappedType: return node.data.nextContainer = value; + case SyntaxKind.FunctionExpression: return node.data.nextContainer = value; + case SyntaxKind.ArrowFunction: return node.data.nextContainer = value; + case SyntaxKind.Block: return node.data.nextContainer = value; + case SyntaxKind.ForStatement: return node.data.nextContainer = value; + case SyntaxKind.ForInStatement: return node.data.nextContainer = value; + case SyntaxKind.ForOfStatement: return node.data.nextContainer = value; + case SyntaxKind.FunctionDeclaration: return node.data.nextContainer = value; + case SyntaxKind.TypeAliasDeclaration: return node.data.nextContainer = value; + case SyntaxKind.ModuleDeclaration: return node.data.nextContainer = value; + case SyntaxKind.CaseBlock: return node.data.nextContainer = value; + case SyntaxKind.CatchClause: return node.data.nextContainer = value; + case SyntaxKind.SourceFile: return node.data.nextContainer = value; + case SyntaxKind.JSDocFunctionType: return node.data.nextContainer = value; + case SyntaxKind.JSDocSignature: return node.data.nextContainer = value; + case SyntaxKind.JSDocCallbackTag: return node.data.nextContainer = value; + case SyntaxKind.JSDocEnumTag: return node.data.nextContainer = value; + case SyntaxKind.JSDocTypedefTag: return node.data.nextContainer = value; + default: + Debug.assertNever(node); // ensures `astSetNextContainer` is up-to-date with `AstHasLocals`/`HasLocals` + } +} + +/** @internal */ +export function astGetType(node: T): AstGetResult; +export function astGetType(node: T) { + Debug.type(node); // ensures `astGetType` is up-to-date with `AstHasType`/`HasType` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.Parameter: return node.data.type; + case SyntaxKind.PropertySignature: return node.data.type; + case SyntaxKind.PropertyDeclaration: return node.data.type; + case SyntaxKind.MethodSignature: return node.data.type; + case SyntaxKind.MethodDeclaration: return node.data.type; + case SyntaxKind.Constructor: return node.data.type; + case SyntaxKind.GetAccessor: return node.data.type; + case SyntaxKind.SetAccessor: return node.data.type; + case SyntaxKind.CallSignature: return node.data.type; + case SyntaxKind.ConstructSignature: return node.data.type; + case SyntaxKind.IndexSignature: return node.data.type; + case SyntaxKind.TypePredicate: return node.data.type; + case SyntaxKind.FunctionType: return node.data.type; + case SyntaxKind.ConstructorType: return node.data.type; + case SyntaxKind.ParenthesizedType: return node.data.type; + case SyntaxKind.TypeOperator: return node.data.type; + case SyntaxKind.MappedType: return node.data.type; + case SyntaxKind.TypeAssertionExpression: return node.data.type; + case SyntaxKind.FunctionExpression: return node.data.type; + case SyntaxKind.ArrowFunction: return node.data.type; + case SyntaxKind.AsExpression: return node.data.type; + case SyntaxKind.VariableDeclaration: return node.data.type; + case SyntaxKind.FunctionDeclaration: return node.data.type; + case SyntaxKind.TypeAliasDeclaration: return node.data.type; + case SyntaxKind.JSDocTypeExpression: return node.data.type; + case SyntaxKind.JSDocNullableType: return node.data.type; + case SyntaxKind.JSDocNonNullableType: return node.data.type; + case SyntaxKind.JSDocOptionalType: return node.data.type; + case SyntaxKind.JSDocFunctionType: return node.data.type; + case SyntaxKind.JSDocVariadicType: return node.data.type; + case SyntaxKind.OptionalType: return node.data.type; + case SyntaxKind.RestType: return node.data.type; + case SyntaxKind.NamedTupleMember: return node.data.type; + case SyntaxKind.TemplateLiteralTypeSpan: return node.data.type; + case SyntaxKind.SatisfiesExpression: return node.data.type; + case SyntaxKind.JSDocNamepathType: return node.data.type; + case SyntaxKind.JSDocSignature: return node.data.type; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetType` is up-to-date with `AstHasType`/`HasType` + return undefined; + } +} + +/** @internal */ +export function astGetTypes(node: T): AstGetResult; +export function astGetTypes(node: AstNode) { + Debug.type(node); // ensures `astGetTypes` is up-to-date with `AstHasTypes`/`HasTypes` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.UnionType: return node.data.types; + case SyntaxKind.IntersectionType: return node.data.types; + case SyntaxKind.HeritageClause: return node.data.types; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetTypes` is up-to-date with `AstHasTypes`/`HasTypes` + return undefined; + } +} + +/** @internal */ +export function astGetTypeParameters(node: T): AstGetResult; +export function astGetTypeParameters(node: AstNode) { + Debug.type(node); // ensures `astGetTypeParameters` is up-to-date with `AstHasTypeParameters`/`HasTypeParameters` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.MethodSignature: return node.data.typeParameters; + case SyntaxKind.MethodDeclaration: return node.data.typeParameters; + case SyntaxKind.Constructor: return node.data.typeParameters; + case SyntaxKind.GetAccessor: return node.data.typeParameters; + case SyntaxKind.SetAccessor: return node.data.typeParameters; + case SyntaxKind.CallSignature: return node.data.typeParameters; + case SyntaxKind.ConstructSignature: return node.data.typeParameters; + case SyntaxKind.IndexSignature: return node.data.typeParameters; + case SyntaxKind.FunctionType: return node.data.typeParameters; + case SyntaxKind.ConstructorType: return node.data.typeParameters; + case SyntaxKind.FunctionExpression: return node.data.typeParameters; + case SyntaxKind.ArrowFunction: return node.data.typeParameters; + case SyntaxKind.ClassExpression: return node.data.typeParameters; + case SyntaxKind.FunctionDeclaration: return node.data.typeParameters; + case SyntaxKind.ClassDeclaration: return node.data.typeParameters; + case SyntaxKind.InterfaceDeclaration: return node.data.typeParameters; + case SyntaxKind.TypeAliasDeclaration: return node.data.typeParameters; + case SyntaxKind.JSDocFunctionType: return node.data.typeParameters; + case SyntaxKind.JSDocSignature: return node.data.typeParameters; + case SyntaxKind.JSDocTemplateTag: return node.data.typeParameters; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetTypeParameters` is up-to-date with `AstHasTypeParameters`/`HasTypeParameters` + return undefined; + } +} + +/** @internal */ +export function astGetParameters(node: T): AstGetResult; +export function astGetParameters(node: AstNode) { + Debug.type(node); // ensures `astGetParameters` is up-to-date with `AstHasParameters`/`HasParameters` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.MethodSignature: return node.data.parameters; + case SyntaxKind.MethodDeclaration: return node.data.parameters; + case SyntaxKind.Constructor: return node.data.parameters; + case SyntaxKind.GetAccessor: return node.data.parameters; + case SyntaxKind.SetAccessor: return node.data.parameters; + case SyntaxKind.CallSignature: return node.data.parameters; + case SyntaxKind.ConstructSignature: return node.data.parameters; + case SyntaxKind.IndexSignature: return node.data.parameters; + case SyntaxKind.FunctionType: return node.data.parameters; + case SyntaxKind.ConstructorType: return node.data.parameters; + case SyntaxKind.FunctionExpression: return node.data.parameters; + case SyntaxKind.ArrowFunction: return node.data.parameters; + case SyntaxKind.FunctionDeclaration: return node.data.parameters; + case SyntaxKind.JSDocFunctionType: return node.data.parameters; + case SyntaxKind.JSDocSignature: return node.data.parameters; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetParameters` is up-to-date with `AstHasParameters`/`HasParameters` + return undefined; + } +} + +/** @internal */ +export function astGetBody(node: T): AstGetResult; +export function astGetBody(node: AstNode) { + Debug.type(node); // ensures `astGetBody` is up-to-date with `AstHasBody`/`HasBody` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.MethodDeclaration: return node.data.body; + case SyntaxKind.ClassStaticBlockDeclaration: return node.data.body; + case SyntaxKind.Constructor: return node.data.body; + case SyntaxKind.GetAccessor: return node.data.body; + case SyntaxKind.SetAccessor: return node.data.body; + case SyntaxKind.FunctionExpression: return node.data.body; + case SyntaxKind.ArrowFunction: return node.data.body; + case SyntaxKind.FunctionDeclaration: return node.data.body; + case SyntaxKind.ModuleDeclaration: return node.data.body; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetBody` is up-to-date with `AstHasBody`/`HasBody` + return undefined; + } +} + +/** @internal */ +export function astGetQuestionToken(node: T): AstGetResult; +export function astGetQuestionToken(node: AstNode) { + Debug.type(node); // ensures `astGetQuestionToken` is up-to-date with `AstHasQuestionToken`/`HasQuestionToken` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.Parameter: return node.data.questionToken; + case SyntaxKind.PropertySignature: return node.data.questionToken; + case SyntaxKind.PropertyDeclaration: return node.data.questionToken; + case SyntaxKind.MethodSignature: return node.data.questionToken; + case SyntaxKind.MethodDeclaration: return node.data.questionToken; + case SyntaxKind.MappedType: return node.data.questionToken; + case SyntaxKind.NamedTupleMember: return node.data.questionToken; + case SyntaxKind.ConditionalExpression: return node.data.questionToken; + case SyntaxKind.PropertyAssignment: return node.data.questionToken; + case SyntaxKind.ShorthandPropertyAssignment: return node.data.questionToken; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetQuestionToken` is up-to-date with `AstHasQuestionToken`/`HasQuestionToken` + return undefined; + } +} + +/** @internal */ +export function astGetTypeArguments(node: T): AstGetResult; +export function astGetTypeArguments(node: AstNode) { + Debug.type(node); // ensures `astGetTypeArguments` is up-to-date with `AstInternalHasTypeArguments`/`InternalHasTypeArguments` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.MethodSignature: return node.data.typeArguments; + case SyntaxKind.MethodDeclaration: return node.data.typeArguments; + case SyntaxKind.Constructor: return node.data.typeArguments; + case SyntaxKind.GetAccessor: return node.data.typeArguments; + case SyntaxKind.SetAccessor: return node.data.typeArguments; + case SyntaxKind.CallSignature: return node.data.typeArguments; + case SyntaxKind.ConstructSignature: return node.data.typeArguments; + case SyntaxKind.IndexSignature: return node.data.typeArguments; + case SyntaxKind.TypeReference: return node.data.typeArguments; + case SyntaxKind.FunctionType: return node.data.typeArguments; + case SyntaxKind.ConstructorType: return node.data.typeArguments; + case SyntaxKind.TypeQuery: return node.data.typeArguments; + case SyntaxKind.ImportType: return node.data.typeArguments; + case SyntaxKind.CallExpression: return node.data.typeArguments; + case SyntaxKind.NewExpression: return node.data.typeArguments; + case SyntaxKind.TaggedTemplateExpression: return node.data.typeArguments; + case SyntaxKind.FunctionExpression: return node.data.typeArguments; + case SyntaxKind.ArrowFunction: return node.data.typeArguments; + case SyntaxKind.ExpressionWithTypeArguments: return node.data.typeArguments; + case SyntaxKind.FunctionDeclaration: return node.data.typeArguments; + case SyntaxKind.JsxSelfClosingElement: return node.data.typeArguments; + case SyntaxKind.JsxOpeningElement: return node.data.typeArguments; + case SyntaxKind.JSDocFunctionType: return node.data.typeArguments; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetTypeArguments` is up-to-date with `AstInternalHasTypeArguments`/`InternalHasTypeArguments` + return undefined; + } +} + +/** @internal */ +export function astGetElements(node: T): AstGetResult; +export function astGetElements(node: AstNode) { + Debug.type(node); // ensures `astGetElements` is up-to-date with `AstHasElements`/`HasElements` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.TupleType: return node.data.elements; + case SyntaxKind.ObjectBindingPattern: return node.data.elements; + case SyntaxKind.ArrayBindingPattern: return node.data.elements; + case SyntaxKind.ArrayLiteralExpression: return node.data.elements; + case SyntaxKind.NamedImports: return node.data.elements; + case SyntaxKind.NamedExports: return node.data.elements; + case SyntaxKind.CommaListExpression: return node.data.elements; + case SyntaxKind.ImportAttributes: return node.data.elements; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetElements` is up-to-date with `AstHasElements`/`HasElements` + return undefined; + } +} + +/** @internal */ +export function astGetMembers(node: T): AstGetResult; +export function astGetMembers(node: AstNode) { + Debug.type(node); // ensures `astGetMembers` is up-to-date with `AstHasMembers`/`HasMembers` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.TypeLiteral: return node.data.members; + case SyntaxKind.MappedType: return node.data.members; + case SyntaxKind.ClassExpression: return node.data.members; + case SyntaxKind.ClassDeclaration: return node.data.members; + case SyntaxKind.InterfaceDeclaration: return node.data.members; + case SyntaxKind.EnumDeclaration: return node.data.members; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetMembers` is up-to-date with `AstHasMembers`/`HasMembers` + return undefined; + } +} + +/** @internal */ +export function astGetStatement(node: T): AstGetResult; +export function astGetStatement(node: AstNode) { + Debug.type(node); // ensures `astGetStatement` is up-to-date with `AstHasStatement`/`HasStatement` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.DoStatement: return node.data.statement; + case SyntaxKind.WhileStatement: return node.data.statement; + case SyntaxKind.ForStatement: return node.data.statement; + case SyntaxKind.ForInStatement: return node.data.statement; + case SyntaxKind.ForOfStatement: return node.data.statement; + case SyntaxKind.WithStatement: return node.data.statement; + case SyntaxKind.LabeledStatement: return node.data.statement; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetStatement` is up-to-date with `AstHasStatement`/`HasStatement` + return undefined; + } +} + +/** @internal */ +export function astGetStatements(node: T): AstGetResult; +export function astGetStatements(node: AstNode) { + Debug.type(node); // ensures `astGetStatements` is up-to-date with `AstHasStatements`/`HasStatements` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.Block: return node.data.statements; + case SyntaxKind.ModuleBlock: return node.data.statements; + case SyntaxKind.CaseClause: return node.data.statements; + case SyntaxKind.DefaultClause: return node.data.statements; + case SyntaxKind.SourceFile: return node.data.statements; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetStatements` is up-to-date with `AstHasStatements`/`HasStatements` + return undefined; + } +} + +/** @internal */ +export function astGetExclamationToken(node: T): AstGetResult; +export function astGetExclamationToken(node: AstNode) { + Debug.type(node); // ensures `astGetExclamationToken` is up-to-date with `AstHasExclamationToken`/`HasExclamationToken` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.PropertyDeclaration: return node.data.exclamationToken; + case SyntaxKind.MethodDeclaration: return node.data.exclamationToken; + case SyntaxKind.VariableDeclaration: return node.data.exclamationToken; + case SyntaxKind.PropertyAssignment: return node.data.exclamationToken; + case SyntaxKind.ShorthandPropertyAssignment: return node.data.exclamationToken; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetExclamationToken` is up-to-date with `AstHasExclamationToken`/`HasExclamationToken` + return undefined; + } +} + +/** @internal */ +export function astGetAsteriskToken(node: T): AstGetResult; +export function astGetAsteriskToken(node: AstNode) { + Debug.type(node); // ensures `astGetAsteriskToken` is up-to-date with `AstHasAsteriskToken`/`HasAsteriskToken` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.MethodDeclaration: return node.data.asteriskToken; + case SyntaxKind.FunctionExpression: return node.data.asteriskToken; + case SyntaxKind.YieldExpression: return node.data.asteriskToken; + case SyntaxKind.FunctionDeclaration: return node.data.asteriskToken; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetAsteriskToken` is up-to-date with `AstHasAsteriskToken`/`HasAsteriskToken` + return undefined; + } +} + +/** @internal */ +export function astGetQuestionDotToken(node: T): AstGetResult; +export function astGetQuestionDotToken(node: AstNode) { + Debug.type(node); // ensures `astGetQuestionDotToken` is up-to-date with `AstHasQuestionDotToken`/`HasQuestionDotToken` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.PropertyAccessExpression: return node.data.questionDotToken; + case SyntaxKind.ElementAccessExpression: return node.data.questionDotToken; + case SyntaxKind.CallExpression: return node.data.questionDotToken; + case SyntaxKind.TaggedTemplateExpression: return node.data.questionDotToken; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetQuestionDotToken` is up-to-date with `AstHasQuestionDotToken`/`HasQuestionDotToken` + return undefined; + } +} + +/** @internal */ +export function astGetIsTypeOnly(node: T): AstGetResult; +export function astGetIsTypeOnly(node: AstNode) { + Debug.type(node); // ensures `astGetIsTypeOnly` is up-to-date with `AstHasIsTypeOnly`/`HasIsTypeOnly` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.ImportEqualsDeclaration: return node.data.isTypeOnly; + case SyntaxKind.ImportClause: return node.data.isTypeOnly; + case SyntaxKind.ImportSpecifier: return node.data.isTypeOnly; + case SyntaxKind.ExportDeclaration: return node.data.isTypeOnly; + case SyntaxKind.ExportSpecifier: return node.data.isTypeOnly; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetIsTypeOnly` is up-to-date with `AstHasIsTypeOnly`/`HasIsTypeOnly` + return undefined; + } +} + +/** @internal */ +export function astGetTagName(node: T): AstGetResult; +export function astGetTagName(node: AstNode) { + Debug.type(node); // ensures `astGetTagName` is up-to-date with `AstHasTagName`/`HasTagName` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.JsxSelfClosingElement: return node.data.tagName; + case SyntaxKind.JsxOpeningElement: return node.data.tagName; + case SyntaxKind.JsxClosingElement: return node.data.tagName; + case SyntaxKind.JSDocTag: return node.data.tagName; + case SyntaxKind.JSDocAugmentsTag: return node.data.tagName; + case SyntaxKind.JSDocImplementsTag: return node.data.tagName; + case SyntaxKind.JSDocAuthorTag: return node.data.tagName; + case SyntaxKind.JSDocDeprecatedTag: return node.data.tagName; + case SyntaxKind.JSDocClassTag: return node.data.tagName; + case SyntaxKind.JSDocPublicTag: return node.data.tagName; + case SyntaxKind.JSDocPrivateTag: return node.data.tagName; + case SyntaxKind.JSDocProtectedTag: return node.data.tagName; + case SyntaxKind.JSDocReadonlyTag: return node.data.tagName; + case SyntaxKind.JSDocOverrideTag: return node.data.tagName; + case SyntaxKind.JSDocCallbackTag: return node.data.tagName; + case SyntaxKind.JSDocOverloadTag: return node.data.tagName; + case SyntaxKind.JSDocEnumTag: return node.data.tagName; + case SyntaxKind.JSDocParameterTag: return node.data.tagName; + case SyntaxKind.JSDocReturnTag: return node.data.tagName; + case SyntaxKind.JSDocThisTag: return node.data.tagName; + case SyntaxKind.JSDocTypeTag: return node.data.tagName; + case SyntaxKind.JSDocTemplateTag: return node.data.tagName; + case SyntaxKind.JSDocTypedefTag: return node.data.tagName; + case SyntaxKind.JSDocSeeTag: return node.data.tagName; + case SyntaxKind.JSDocPropertyTag: return node.data.tagName; + case SyntaxKind.JSDocThrowsTag: return node.data.tagName; + case SyntaxKind.JSDocSatisfiesTag: return node.data.tagName; + case SyntaxKind.JSDocImportTag: return node.data.tagName; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetTagName` is up-to-date with `AstHasTagName`/`HasTagName` + return undefined; + } +} + +/** @internal */ +export function astGetComment(node: T): AstGetResult; +export function astGetComment(node: AstNode) { + Debug.type(node); // ensures `astGetComment` is up-to-date with `AstHasComment`/`HasComment` + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.JSDoc: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocAugmentsTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocImplementsTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocAuthorTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocDeprecatedTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocClassTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocPublicTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocPrivateTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocProtectedTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocReadonlyTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocOverrideTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocCallbackTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocOverloadTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocEnumTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocParameterTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocReturnTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocThisTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocTypeTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocTemplateTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocTypedefTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocSeeTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocPropertyTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocThrowsTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocSatisfiesTag: return node.data.comment ?? node.data.commentArray; + case SyntaxKind.JSDocImportTag: return node.data.comment ?? node.data.commentArray; + default: + Debug.assertNeverTypeOnly(node); // ensures `astGetComment` is up-to-date with `AstHasComment`/`HasComment` + return undefined; } } -// NOTE: each branch is monomorphic +/** @internal */ +export function astSetComment(node: T, value: string | AstNodeArray | undefined): string | AstNodeArray | undefined { + if (typeof value === "string") { + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.JSDoc: return node.data.comment = value; + case SyntaxKind.JSDocTag: return node.data.comment = value; + case SyntaxKind.JSDocAugmentsTag: return node.data.comment = value; + case SyntaxKind.JSDocImplementsTag: return node.data.comment = value; + case SyntaxKind.JSDocAuthorTag: return node.data.comment = value; + case SyntaxKind.JSDocDeprecatedTag: return node.data.comment = value; + case SyntaxKind.JSDocClassTag: return node.data.comment = value; + case SyntaxKind.JSDocPublicTag: return node.data.comment = value; + case SyntaxKind.JSDocPrivateTag: return node.data.comment = value; + case SyntaxKind.JSDocProtectedTag: return node.data.comment = value; + case SyntaxKind.JSDocReadonlyTag: return node.data.comment = value; + case SyntaxKind.JSDocOverrideTag: return node.data.comment = value; + case SyntaxKind.JSDocCallbackTag: return node.data.comment = value; + case SyntaxKind.JSDocOverloadTag: return node.data.comment = value; + case SyntaxKind.JSDocEnumTag: return node.data.comment = value; + case SyntaxKind.JSDocParameterTag: return node.data.comment = value; + case SyntaxKind.JSDocReturnTag: return node.data.comment = value; + case SyntaxKind.JSDocThisTag: return node.data.comment = value; + case SyntaxKind.JSDocTypeTag: return node.data.comment = value; + case SyntaxKind.JSDocTemplateTag: return node.data.comment = value; + case SyntaxKind.JSDocTypedefTag: return node.data.comment = value; + case SyntaxKind.JSDocSeeTag: return node.data.comment = value; + case SyntaxKind.JSDocPropertyTag: return node.data.comment = value; + case SyntaxKind.JSDocThrowsTag: return node.data.comment = value; + case SyntaxKind.JSDocSatisfiesTag: return node.data.comment = value; + case SyntaxKind.JSDocImportTag: return node.data.comment = value; + default: + Debug.assertNever(node); // ensures `astSetComment` is up-to-date with `AstHasComment`/`HasComment` + } + } + else { + // NOTE: each branch is duplicated to remain monomorphic + switch (node.kind) { + case SyntaxKind.JSDoc: return node.data.commentArray = value; + case SyntaxKind.JSDocTag: return node.data.commentArray = value; + case SyntaxKind.JSDocAugmentsTag: return node.data.commentArray = value; + case SyntaxKind.JSDocImplementsTag: return node.data.commentArray = value; + case SyntaxKind.JSDocAuthorTag: return node.data.commentArray = value; + case SyntaxKind.JSDocDeprecatedTag: return node.data.commentArray = value; + case SyntaxKind.JSDocClassTag: return node.data.commentArray = value; + case SyntaxKind.JSDocPublicTag: return node.data.commentArray = value; + case SyntaxKind.JSDocPrivateTag: return node.data.commentArray = value; + case SyntaxKind.JSDocProtectedTag: return node.data.commentArray = value; + case SyntaxKind.JSDocReadonlyTag: return node.data.commentArray = value; + case SyntaxKind.JSDocOverrideTag: return node.data.commentArray = value; + case SyntaxKind.JSDocCallbackTag: return node.data.commentArray = value; + case SyntaxKind.JSDocOverloadTag: return node.data.commentArray = value; + case SyntaxKind.JSDocEnumTag: return node.data.commentArray = value; + case SyntaxKind.JSDocParameterTag: return node.data.commentArray = value; + case SyntaxKind.JSDocReturnTag: return node.data.commentArray = value; + case SyntaxKind.JSDocThisTag: return node.data.commentArray = value; + case SyntaxKind.JSDocTypeTag: return node.data.commentArray = value; + case SyntaxKind.JSDocTemplateTag: return node.data.commentArray = value; + case SyntaxKind.JSDocTypedefTag: return node.data.commentArray = value; + case SyntaxKind.JSDocSeeTag: return node.data.commentArray = value; + case SyntaxKind.JSDocPropertyTag: return node.data.commentArray = value; + case SyntaxKind.JSDocThrowsTag: return node.data.commentArray = value; + case SyntaxKind.JSDocSatisfiesTag: return node.data.commentArray = value; + case SyntaxKind.JSDocImportTag: return node.data.commentArray = value; + default: + Debug.assertNever(node); // ensures `astSetComment` is up-to-date with `AstHasComment`/`HasComment` + } + } +} + +// NOTE: each branch is duplicated to remain monomorphic const computeTransformFlagsMap: Partial TransformFlags>> = { [SyntaxKind.EndOfFileToken]: node => node.data.computeTransformFlags(node), [SyntaxKind.ThisKeyword]: node => node.data.computeTransformFlags(node), @@ -5583,7 +7918,52 @@ function computeTransformFlags(node: AstNode) { return fn !== undefined ? fn(node) : node.data.computeTransformFlags(node); } -function isAstPropertyName(node: AstNode): node is AstPropertyName { +function copyDataPropertiesCore(data: AstData, clone: AstData) { + Object.assign(clone, data); +} + +function copyDataProperties(node: AstNode, clone: AstData) { + const fn = copyDataPropertiesMap[node.kind]; + return fn !== undefined ? fn(node.data, clone) : copyDataPropertiesCore(node.data, clone); +} + +function createDataInstanceCore(data: AstData) { + return Object.create(Object.getPrototypeOf(data)); +} + +function createDataInstance(node: AstNode) { + const fn = createDataInstanceMap[node.kind]; + return fn !== undefined ? fn(node.data) : + isTokenKind(node.kind) ? new AstTokenData() : + createDataInstanceCore(node.data); +} + +function cloneData(node: AstNode) { + const clone = createDataInstance(node); + copyDataProperties(node, clone); + return clone; +} + +function cloneNode(node: AstNode) { + const fn = cloneNodeMap[node.kind]; + return fn !== undefined ? fn(node) : cloneNodeCore(node); +} + +function shadowDataCore(data: AstData) { + return Object.create(data); +} + +function shadowData(node: AstNode) { + const fn = shadowDataMap[node.kind]; + return fn !== undefined ? fn(node.data) : shadowDataCore(node.data); +} + +function shadowNode(node: AstNode) { + const fn = shadowNodeMap[node.kind]; + return fn !== undefined ? fn(node) : shadowCore(node); +} + +function astIsPropertyName(node: AstNode): node is AstPropertyName { const kind = node.kind; return kind === SyntaxKind.Identifier || kind === SyntaxKind.PrivateIdentifier @@ -5641,8 +8021,8 @@ export function getAstParseTreeNode(node: AstNode | undefined, nodeTest?: (node: } /** @internal */ -export function isAstJSDocTypeAssertion(node: AstNode): node is AstJSDocTypeAssertion { - return isAstParenthesizedExpression(node) +export function astIsJSDocTypeAssertion(node: AstNode): node is AstJSDocTypeAssertion { + return astIsParenthesizedExpression(node) && !!(node.flags & NodeFlags.JavaScriptFile) && !!getJSDocTypeTag(node.node); // TODO: don't invoke node } @@ -5651,34 +8031,7 @@ export function isAstJSDocTypeAssertion(node: AstNode): node is AstJSDocTypeAsse export type AstOuterExpression = AstNodeOneOf; /** @internal */ -export function isAstOuterExpression(node: AstNode, kinds: OuterExpressionKinds = OuterExpressionKinds.All): node is AstOuterExpression { - switch (node.kind) { - case SyntaxKind.ParenthesizedExpression: - if (kinds & OuterExpressionKinds.ExcludeJSDocTypeAssertion && isAstJSDocTypeAssertion(node)) { - return false; - } - return (kinds & OuterExpressionKinds.Parentheses) !== 0; - case SyntaxKind.TypeAssertionExpression: - case SyntaxKind.AsExpression: - case SyntaxKind.SatisfiesExpression: - return (kinds & OuterExpressionKinds.TypeAssertions) !== 0; - case SyntaxKind.ExpressionWithTypeArguments: - return (kinds & OuterExpressionKinds.ExpressionsWithTypeArguments) !== 0; - case SyntaxKind.NonNullExpression: - return (kinds & OuterExpressionKinds.NonNullAssertions) !== 0; - case SyntaxKind.PartiallyEmittedExpression: - return (kinds & OuterExpressionKinds.PartiallyEmittedExpressions) !== 0; - } - return false; -} - -/** @internal */ -export function skipAstOuterExpressions(node: AstNode, kinds: OuterExpressionKinds = OuterExpressionKinds.All): AstNode { - while (isAstOuterExpression(node, kinds)) { - node = node.data.expression; - } - return node; -} +export type AstWrappedExpression = AstNodeOneOf>; // Temporary `Node` implementation representing every possible `Node` shape. // This is only used for testing and will be removed in favor of the node classes in types.ts @@ -5702,7 +8055,7 @@ class AnyNode extends Node { declare _typeNodeBrand: any; declare _statementBrand: any; declare _jsDocTypeBrand: any; - + override getChildCount(sourceFile?: SourceFileLike): number { if (isTokenKind(this.kind)) { return this.getChildren().length; @@ -5752,25 +8105,25 @@ class AnyNode extends Node { set left(value) { this.ast.data.left = value?.ast; } get right() { return this.ast.data.right?.node; } set right(value) { this.ast.data.right = value?.ast; } - get expression() { return this.ast.data.expression?.node; } + get expression() { return astGetExpression(this.ast)?.node; } set expression(value) { this.ast.data.expression = value?.ast; } - get modifiers() { return this.ast.data.modifiers?.nodes; } + get modifiers() { return astGetModifiers(this.ast)?.nodes; } set modifiers(value) { this.ast.data.modifiers = value?.ast; } - get name() { return this.ast.data.name?.node; } + get name() { return astGetName(this.ast)?.node; } set name(value) { this.ast.data.name = value?.ast; } get constraint() { return this.ast.data.constraint?.node; } set constraint(value) { this.ast.data.constraint = value?.ast; } get default() { return this.ast.data.default?.node; } set default(value) { this.ast.data.default = value?.ast; } - get typeParameters() { return this.ast.data.typeParameters?.nodes; } + get typeParameters(): any { return astGetTypeParameters(this.ast)?.nodes; } set typeParameters(value) { this.ast.data.typeParameters = value?.ast; } - get parameters() { return this.ast.data.parameters?.nodes; } + get parameters() { return astGetParameters(this.ast)?.nodes; } set parameters(value) { this.ast.data.parameters = value?.ast; } get type() { if (this.kind === SyntaxKind.SyntheticExpression) { return this.ast.data.type; } - return this.ast.data.type?.node; + return astGetType(this.ast)?.node; } set type(value) { if (this.kind === SyntaxKind.SyntheticExpression) { @@ -5780,17 +8133,17 @@ class AnyNode extends Node { this.ast.data.type = value?.ast; } } - get typeArguments() { return this.ast.data.typeArguments?.nodes; } + get typeArguments() { return astGetTypeArguments(this.ast)?.nodes; } set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } - get exclamationToken() { return this.ast.data.exclamationToken?.node; } + get exclamationToken() { return astGetExclamationToken(this.ast)?.node; } set exclamationToken(value) { this.ast.data.exclamationToken = value?.ast; } - get initializer() { return this.ast.data.initializer?.node; } + get initializer() { return astGetInitializer(this.ast)?.node; } set initializer(value) { this.ast.data.initializer = value?.ast; } get declarations() { return this.ast.data.declarations.nodes; } set declarations(value) { this.ast.data.declarations = value.ast; } get dotDotDotToken() { return this.ast.data.dotDotDotToken?.node; } set dotDotDotToken(value) { this.ast.data.dotDotDotToken = value?.ast; } - get questionToken() { return this.ast.data.questionToken?.node; } + get questionToken() { return astGetQuestionToken(this.ast)?.node; } set questionToken(value) { this.ast.data.questionToken = value?.ast; } get propertyName() { return this.ast.data.propertyName?.node; } set propertyName(value) { this.ast.data.propertyName = value?.ast; } @@ -5798,11 +8151,11 @@ class AnyNode extends Node { set equalsToken(value) { this.ast.data.equalsToken = value?.ast; } get objectAssignmentInitializer() { return this.ast.data.objectAssignmentInitializer?.node; } set objectAssignmentInitializer(value) { this.ast.data.objectAssignmentInitializer = value?.ast; } - get elements() { return this.ast.data.elements.nodes; } + get elements(): any { return astGetElements(this.ast)?.nodes; } set elements(value) { this.ast.data.elements = value.ast; } - get asteriskToken() { return this.ast.data.asteriskToken?.node; } + get asteriskToken() { return astGetAsteriskToken(this.ast)?.node; } set asteriskToken(value) { this.ast.data.asteriskToken = value?.ast; } - get body() { return this.ast.data.body?.node; } + get body() { return astGetBody(this.ast)?.node; } set body(value) { this.ast.data.body = value?.ast; } get assertClause() { return this.ast.data.assertClause?.node; } set assertClause(value) { this.ast.data.assertClause = value?.ast; } @@ -5826,11 +8179,11 @@ class AnyNode extends Node { set parameterName(value) { this.ast.data.parameterName = value.ast; } get exprName() { return this.ast.data.exprName.node; } set exprName(value) { this.ast.data.exprName = value.ast; } - get members() { return this.ast.data.members?.nodes; } + get members() { return astGetMembers(this.ast)?.nodes; } set members(value) { this.ast.data.members = value?.ast; } get elementType() { return this.ast.data.elementType.node; } set elementType(value) { this.ast.data.elementType = value.ast; } - get types() { return this.ast.data.types.nodes; } + get types() { return astGetTypes(this.ast).nodes; } set types(value) { this.ast.data.types = value.ast; } get checkType() { return this.ast.data.checkType.node; } set checkType(value) { this.ast.data.checkType = value.ast; } @@ -5878,7 +8231,7 @@ class AnyNode extends Node { set equalsGreaterThanToken(value) { this.ast.data.equalsGreaterThanToken = value.ast; } get properties() { return this.ast.data.properties?.nodes; } set properties(value) { this.ast.data.properties = value?.ast; } - get questionDotToken() { return this.ast.data.questionDotToken?.node; } + get questionDotToken() { return astGetQuestionDotToken(this.ast)?.node; } set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } get argumentExpression() { return this.ast.data.argumentExpression.node; } set argumentExpression(value) { this.ast.data.argumentExpression = value.ast; } @@ -5898,7 +8251,7 @@ class AnyNode extends Node { set closingElement(value) { this.ast.data.closingElement = value.ast; } get namespace() { return this.ast.data.namespace.node; } set namespace(value) { this.ast.data.namespace = value.ast; } - get tagName() { return this.ast.data.tagName.node; } + get tagName() { return astGetTagName(this.ast).node; } set tagName(value) { this.ast.data.tagName = value.ast; } get openingFragment() { return this.ast.data.openingFragment.node; } set openingFragment(value) { this.ast.data.openingFragment = value.ast; } @@ -5906,7 +8259,7 @@ class AnyNode extends Node { set closingFragment(value) { this.ast.data.closingFragment = value.ast; } get thisArg() { return this.ast.data.thisArg.node; } set thisArg(value) { this.ast.data.thisArg = value.ast; } - get statements() { return this.ast.data.statements.nodes; } + get statements() { return astGetStatements(this.ast).nodes; } set statements(value) { this.ast.data.statements = value.ast; } get declarationList() { return this.ast.data.declarationList.node; } set declarationList(value) { this.ast.data.declarationList = value.ast; } @@ -5914,7 +8267,7 @@ class AnyNode extends Node { set thenStatement(value) { this.ast.data.thenStatement = value.ast; } get elseStatement() { return this.ast.data.elseStatement?.node; } set elseStatement(value) { this.ast.data.elseStatement = value?.ast; } - get statement() { return this.ast.data.statement.node; } + get statement() { return astGetStatement(this.ast).node; } set statement(value) { this.ast.data.statement = value.ast; } get incrementor() { return this.ast.data.incrementor?.node; } set incrementor(value) { this.ast.data.incrementor = value?.ast; } @@ -5942,7 +8295,7 @@ class AnyNode extends Node { set heritageClauses(value) { this.ast.data.heritageClauses = value?.ast; } get token() { return this.ast.data.token; } set token(value) { this.ast.data.token = value; } - get isTypeOnly() { return this.ast.data.isTypeOnly; } + get isTypeOnly(): any { return astGetIsTypeOnly(this.ast); } set isTypeOnly(value) { this.ast.data.isTypeOnly = value; } get moduleReference() { return this.ast.data.moduleReference.node; } set moduleReference(value) { this.ast.data.moduleReference = value.ast; } @@ -5963,7 +8316,7 @@ class AnyNode extends Node { get tags() { return this.ast.data.tags?.nodes; } set tags(value) { this.ast.data.tags = value?.ast; } get comment() { - const comment = this.ast.data.comment; + const comment = astGetComment(this.ast); return typeof comment === "string" ? comment : comment?.nodes; } set comment(value) { this.ast.data.comment = typeof value === "string" ? value : value?.ast; } @@ -5983,13 +8336,13 @@ class AnyNode extends Node { set isArrayType(value) { this.ast.data.isArrayType = value; } get escapedText() { return this.ast.data.escapedText; } set escapedText(value) { this.ast.data.escapedText = value; } - get text() { + get text(): any { switch (this.kind) { case SyntaxKind.Identifier: case SyntaxKind.PrivateIdentifier: - return idText(this as unknown as Identifier | PrivateIdentifier); + return astIdText(this.ast as unknown as AstIdentifier | AstPrivateIdentifier); default: - return this.data.text; + return astGetText(this.ast); } } set text(value) { this.ast.data.text = value; } @@ -6011,20 +8364,20 @@ class AnyNode extends Node { set containsOnlyTriviaWhiteSpaces(value) { this.ast.data.containsOnlyTriviaWhiteSpaces = value; } get resolvedSymbol() { return this.ast.data.resolvedSymbol; } set resolvedSymbol(value) { this.ast.data.resolvedSymbol = value; } - get symbol() { return this.ast.data.symbol; } - set symbol(value) { this.ast.data.symbol = value; } - get localSymbol() { return this.ast.data.localSymbol; } - set localSymbol(value) { this.ast.data.localSymbol = value; } - get jsDoc() { return this.ast.data.jsDoc; } - set jsDoc(value) { this.ast.data.jsDoc = value; } - get flowNode() { return this.ast.data.flowNode; } - set flowNode(value) { this.ast.data.flowNode = value; } - get locals() { return this.ast.data.locals; } - set locals(value) { this.ast.data.locals = value; } - get nextContainer() { return this.ast.data.nextContainer?.node; } - set nextContainer(value) { this.ast.data.nextContainer = value?.ast; } - get endFlowNode() { return this.ast.data.endFlowNode; } - set endFlowNode(value) { this.ast.data.endFlowNode = value; } + get symbol(): any { return astGetSymbol(this.ast); } + set symbol(value) { astSetSymbol(this.ast as AstHasSymbol, value); } + get localSymbol(): any { return astGetLocalSymbol(this.ast); } + set localSymbol(value) { astSetLocalSymbol(this.ast as AstHasSymbol, value); } + get jsDoc() { return astGetJSDoc(this.ast); } + set jsDoc(value) { astSetJSDoc(this.ast as AstHasJSDoc, value); } + get flowNode() { return astGetFlowNode(this.ast); } + set flowNode(value) { astSetFlowNode(this.ast as AstHasFlowNode, value); } + get locals(): any { return astGetLocals(this.ast); } + set locals(value) { astSetLocals(this.ast as AstHasLocals, value); } + get nextContainer(): any { return astGetNextContainer(this.ast)?.node; } + set nextContainer(value) { astSetNextContainer(this.ast as AstHasLocals, value?.ast); } + get endFlowNode() { return astGetEndFlowNode(this.ast); } + set endFlowNode(value) { astSetEndFlowNode(this.ast as AstHasEndFlowNode, value); } get returnFlowNode() { return this.ast.data.returnFlowNode; } set returnFlowNode(value) { this.ast.data.returnFlowNode = value; } get fallthroughFlowNode() { return this.ast.data.fallthroughFlowNode; } diff --git a/src/compiler/astForEachChild.ts b/src/compiler/astForEachChild.ts index f182752c23fd7..5f3087480d65b 100644 --- a/src/compiler/astForEachChild.ts +++ b/src/compiler/astForEachChild.ts @@ -757,13 +757,13 @@ const astForEachChildTable: AstForEachChildTable = { visitNode(cbNode, node.data.type); }, [SyntaxKind.JSDoc]: function forEachChildInJSDoc(node: AstJSDoc, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { - return (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)) + return visitNodes(cbNode, cbNodes, node.data.commentArray) || visitNodes(cbNode, cbNodes, node.data.tags); }, [SyntaxKind.JSDocSeeTag]: function forEachChildInJSDocSeeTag(node: AstJSDocSeeTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { return visitNode(cbNode, node.data.tagName) || visitNode(cbNode, node.data.name) || - (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + visitNodes(cbNode, cbNodes, node.data.commentArray); }, [SyntaxKind.JSDocNameReference]: function forEachChildInJSDocNameReference(node: AstJSDocNameReference, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { return visitNode(cbNode, node.data.name); @@ -776,23 +776,23 @@ const astForEachChildTable: AstForEachChildTable = { [SyntaxKind.JSDocPropertyTag]: forEachChildInJSDocParameterOrPropertyTag, [SyntaxKind.JSDocAuthorTag]: function forEachChildInJSDocAuthorTag(node: AstJSDocAuthorTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { return visitNode(cbNode, node.data.tagName) || - (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + visitNodes(cbNode, cbNodes, node.data.commentArray); }, [SyntaxKind.JSDocImplementsTag]: function forEachChildInJSDocImplementsTag(node: AstJSDocImplementsTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { return visitNode(cbNode, node.data.tagName) || visitNode(cbNode, node.data.class) || - (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + visitNodes(cbNode, cbNodes, node.data.commentArray); }, [SyntaxKind.JSDocAugmentsTag]: function forEachChildInJSDocAugmentsTag(node: AstJSDocAugmentsTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { return visitNode(cbNode, node.data.tagName) || visitNode(cbNode, node.data.class) || - (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + visitNodes(cbNode, cbNodes, node.data.commentArray); }, [SyntaxKind.JSDocTemplateTag]: function forEachChildInJSDocTemplateTag(node: AstJSDocTemplateTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { return visitNode(cbNode, node.data.tagName) || visitNode(cbNode, node.data.constraint) || visitNodes(cbNode, cbNodes, node.data.typeParameters) || - (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + visitNodes(cbNode, cbNodes, node.data.commentArray); }, [SyntaxKind.JSDocTypedefTag]: function forEachChildInJSDocTypedefTag(node: AstJSDocTypedefTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { return visitNode(cbNode, node.data.tagName) || @@ -800,16 +800,16 @@ const astForEachChildTable: AstForEachChildTable = { node.data.typeExpression.kind === SyntaxKind.JSDocTypeExpression ? visitNode(cbNode, node.data.typeExpression) || visitNode(cbNode, node.data.fullName) || - (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)) + visitNodes(cbNode, cbNodes, node.data.commentArray) : visitNode(cbNode, node.data.fullName) || visitNode(cbNode, node.data.typeExpression) || - (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment))); + visitNodes(cbNode, cbNodes, node.data.commentArray)); }, [SyntaxKind.JSDocCallbackTag]: function forEachChildInJSDocCallbackTag(node: AstJSDocCallbackTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { return visitNode(cbNode, node.data.tagName) || visitNode(cbNode, node.data.fullName) || visitNode(cbNode, node.data.typeExpression) || - (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + visitNodes(cbNode, cbNodes, node.data.commentArray); }, [SyntaxKind.JSDocReturnTag]: forEachChildInJSDocTypeLikeTag, [SyntaxKind.JSDocTypeTag]: forEachChildInJSDocTypeLikeTag, @@ -901,13 +901,13 @@ function forEachChildInJSDocParameterOrPropertyTag(node: AstJSDocParameterTag (node.data.isNameFirst ? visitNode(cbNode, node.data.name) || visitNode(cbNode, node.data.typeExpression) : visitNode(cbNode, node.data.typeExpression) || visitNode(cbNode, node.data.name)) || - (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + visitNodes(cbNode, cbNodes, node.data.commentArray); } function forEachChildInJSDocTypeLikeTag(node: AstJSDocReturnTag | AstJSDocTypeTag | AstJSDocThisTag | AstJSDocEnumTag | AstJSDocThrowsTag | AstJSDocOverloadTag | AstJSDocSatisfiesTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { return visitNode(cbNode, node.data.tagName) || visitNode(cbNode, node.data.typeExpression) || - (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + visitNodes(cbNode, cbNodes, node.data.commentArray); } function forEachChildInJSDocLinkCodeOrPlain(node: AstJSDocLink | AstJSDocLinkCode | AstJSDocLinkPlain, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { @@ -916,7 +916,7 @@ function forEachChildInJSDocLinkCodeOrPlain(node: AstJSDocLink | AstJSDocLink function forEachChildInJSDocTag(node: AstJSDocUnknownTag | AstJSDocClassTag | AstJSDocPublicTag | AstJSDocPrivateTag | AstJSDocProtectedTag | AstJSDocReadonlyTag | AstJSDocDeprecatedTag | AstJSDocOverrideTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { return visitNode(cbNode, node.data.tagName) - || (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + || visitNodes(cbNode, cbNodes, node.data.commentArray); } function forEachChildInJSDocImportTag(node: AstJSDocImportTag, cbNode: (node: AstNode) => T | undefined, cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { @@ -924,7 +924,7 @@ function forEachChildInJSDocImportTag(node: AstJSDocImportTag, cbNode: (node: || visitNode(cbNode, node.data.importClause) || visitNode(cbNode, node.data.moduleSpecifier) || visitNode(cbNode, node.data.attributes) - || (typeof node.data.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.data.comment)); + || visitNodes(cbNode, cbNodes, node.data.commentArray); } function forEachChildInPartiallyEmittedExpression(node: AstPartiallyEmittedExpression, cbNode: (node: AstNode) => T | undefined, _cbNodes?: (nodes: AstNodeArray) => T | undefined): T | undefined { diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 347970f24f55c..130cc7b22ff9f 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -8,6 +8,94 @@ import { ArrayLiteralExpression, ArrowFunction, AssignmentDeclarationKind, + AstAccessExpression, + AstArrowFunction, + AstBinaryExpression, + AstBindableObjectDefinePropertyCall, + AstBindablePropertyAssignmentExpression, + AstBindableStaticPropertyAssignmentExpression, + AstBindingElement, + AstBlock, + AstCallExpression, + AstCatchClause, + AstClassLikeDeclaration, + AstDeclaration, + AstDeleteExpression, + AstElementAccessExpression, + AstEnumDeclaration, + AstExportAssignment, + AstExportDeclaration, + AstExpression, + AstFunctionDeclaration, + AstFunctionExpression, + astGetAssignmentDeclarationKind, + astGetExpression, + astGetNameOfDeclaration, + astHasDynamicName, + astHasName, + astHasSyntacticModifier, + AstIdentifier, + astIdentifierToKeywordKind, + AstImportClause, + astIsBindableStaticAccessExpression, + astIsEntityNameExpression, + astIsExportSpecifier, + astIsExpression, + astIsIdentifier, + astIsIdentifierName, + astIsInJSFile, + astIsInTopLevelContext, + astIsJSDocTypeAlias, + astIsLeftHandSideExpression, + astIsModuleExportsAccessExpression, + astIsPartOfTypeQuery, + astIsPrototypeAccess, + astIsSpecialPropertyDeclaration, + astIsStringOrNumericLiteralLike, + astIsTypeAliasDeclaration, + AstJSDocCallbackTag, + AstJSDocClassTag, + AstJSDocEnumTag, + AstJSDocImportTag, + AstJSDocOverloadTag, + AstJSDocParameterTag, + AstJSDocPropertyLikeTag, + AstJSDocSignature, + AstJSDocTypedefTag, + AstJSDocTypeLiteral, + AstJsxAttribute, + AstJsxAttributes, + AstLabeledStatement, + AstLiteralLikeElementAccessExpression, + AstMappedTypeNode, + AstMetaProperty, + AstMethodDeclaration, + AstModuleBlock, + AstModuleDeclaration, + astModuleExportNameIsDefault, + AstNamespaceExportDeclaration, + AstNode, + astNodeIsMissing, + AstNonNullExpression, + AstObjectLiteralExpression, + AstParameterDeclaration, + AstParenthesizedExpression, + AstPostfixUnaryExpression, + AstPrefixUnaryExpression, + AstPrivateIdentifier, + AstPropertyAccessExpression, + AstPropertyDeclaration, + AstPropertySignature, + AstQualifiedName, + astSetFlowNode, + AstSignatureDeclaration, + AstSourceFile, + AstSuperExpression, + AstThisExpression, + AstTypeLiteralNode, + AstTypeParameterDeclaration, + AstVariableDeclaration, + AstWithStatement, BinaryExpression, BinaryOperatorToken, BindableAccessExpression, @@ -123,7 +211,6 @@ import { hasName, hasSyntacticModifier, Identifier, - identifierToKeywordKind, idText, IfStatement, ImportClause, @@ -153,13 +240,10 @@ import { isDestructuringAssignment, isDottedName, isEmptyObjectLiteral, - isEntityNameExpression, isEnumConst, isExportAssignment, isExportDeclaration, isExportsIdentifier, - isExportSpecifier, - isExpression, isExpressionOfOptionalChainRoot, isExternalModule, isExternalOrCommonJsModule, @@ -171,9 +255,7 @@ import { isFunctionSymbol, isGlobalScopeAugmentation, isIdentifier, - isIdentifierName, isInJSFile, - isInTopLevelContext, isJSDocConstructSignature, isJSDocEnumTag, isJSDocTemplateTag, @@ -203,7 +285,6 @@ import { isParameterPropertyDeclaration, isParenthesizedExpression, isPartOfParameterDeclaration, - isPartOfTypeQuery, isPrefixUnaryExpression, isPrivateIdentifier, isPrologueDirective, @@ -216,7 +297,6 @@ import { isShorthandPropertyAssignment, isSignedNumericLiteral, isSourceFile, - isSpecialPropertyDeclaration, isStatement, isStatementButNotDeclaration, isStatic, @@ -224,7 +304,6 @@ import { isStringLiteralLike, isStringOrNumericLiteralLike, isThisInitializedDeclaration, - isTypeAliasDeclaration, isTypeOfExpression, isVariableDeclaration, isVariableDeclarationInitializedToBareOrAccessedRequire, @@ -234,9 +313,7 @@ import { JSDocEnumTag, JSDocFunctionType, JSDocImportTag, - JSDocOverloadTag, JSDocParameterTag, - JSDocPropertyLikeTag, JSDocSignature, JSDocTypedefTag, JSDocTypeLiteral, @@ -246,19 +323,15 @@ import { length, LiteralLikeElementAccessExpression, MappedTypeNode, - MetaProperty, MethodDeclaration, ModifierFlags, - ModuleBlock, ModuleDeclaration, - moduleExportNameIsDefault, Mutable, NamespaceExportDeclaration, Node, NodeArray, NodeFlags, nodeHasName, - nodeIsMissing, nodeIsPresent, NonNullChain, NonNullExpression, @@ -271,13 +344,11 @@ import { PatternAmbientModule, PostfixUnaryExpression, PrefixUnaryExpression, - PrivateIdentifier, PropertyAccessChain, PropertyAccessEntityNameExpression, PropertyAccessExpression, PropertyDeclaration, PropertySignature, - QualifiedName, removeFileExtension, ReturnStatement, ScriptTarget, @@ -295,7 +366,6 @@ import { SpreadElement, Statement, StringLiteral, - SuperExpression, SwitchStatement, Symbol, SymbolFlags, @@ -303,7 +373,6 @@ import { SymbolTable, SyntaxKind, TextRange, - ThisExpression, ThrowStatement, tokenToString, tracing, @@ -647,7 +716,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { symbol.flags |= symbolFlags; node.symbol = symbol; - symbol.declarations = appendIfUnique(symbol.declarations, node); + symbol.astDeclarations = appendIfUnique(symbol.astDeclarations, node.ast); if (symbolFlags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.Module | SymbolFlags.Variable) && !symbol.exports) { symbol.exports = createSymbolTable(); @@ -757,15 +826,15 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { * @param includes - The SymbolFlags that node has in addition to its declaration type (eg: export, ambient, etc.) * @param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations. */ - function declareSymbol(symbolTable: SymbolTable, parent: Symbol | undefined, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags, isReplaceableByMethod?: boolean, isComputedName?: boolean): Symbol { - Debug.assert(isComputedName || !hasDynamicName(node)); + function declareSymbol(symbolTable: SymbolTable, parent: Symbol | undefined, node: AstDeclaration, includes: SymbolFlags, excludes: SymbolFlags, isReplaceableByMethod?: boolean, isComputedName?: boolean): Symbol { + Debug.assert(isComputedName || !astHasDynamicName(node)); - const isDefaultExport = hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && moduleExportNameIsDefault(node.name); + const isDefaultExport = astHasSyntacticModifier(node, ModifierFlags.Default) || astIsExportSpecifier(node) && astModuleExportNameIsDefault(node.data.name); // The exported symbol for an export default function/class node is always named "default" const name = isComputedName ? InternalSymbolName.Computed : isDefaultExport && parent ? InternalSymbolName.Default - : getDeclarationName(node); + : getDeclarationName(node.node); // TODO(rbuckton): do not instantiate `.node` let symbol: Symbol | undefined; if (name === undefined) { @@ -817,8 +886,8 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { } else if (!(includes & SymbolFlags.Variable && symbol.flags & SymbolFlags.Assignment)) { // Assignment declarations are allowed to merge with variables, no matter what other flags they have. - if (isNamedDeclaration(node)) { - setParent(node.name, node); + if (astHasName(node)) { + node.data.name.parent = node; } // Report errors every position with duplicate declaration // Report errors on previous encountered declarations @@ -849,7 +918,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers) if ( symbol.declarations && symbol.declarations.length && - (node.kind === SyntaxKind.ExportAssignment && !(node as ExportAssignment).isExportEquals) + (node.kind === SyntaxKind.ExportAssignment && !(node as AstExportAssignment).data.isExportEquals) ) { message = Diagnostics.A_module_cannot_have_multiple_default_exports; messageNeedsName = false; @@ -859,24 +928,24 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { } const relatedInformation: DiagnosticRelatedInformation[] = []; - if (isTypeAliasDeclaration(node) && nodeIsMissing(node.type) && hasSyntacticModifier(node, ModifierFlags.Export) && symbol.flags & (SymbolFlags.Alias | SymbolFlags.Type | SymbolFlags.Namespace)) { + if (astIsTypeAliasDeclaration(node) && astNodeIsMissing(node.data.type) && astHasSyntacticModifier(node, ModifierFlags.Export) && symbol.flags & (SymbolFlags.Alias | SymbolFlags.Type | SymbolFlags.Namespace)) { // export type T; - may have meant export type { T }? - relatedInformation.push(createDiagnosticForNode(node, Diagnostics.Did_you_mean_0, `export type { ${unescapeLeadingUnderscores(node.name.escapedText)} }`)); + relatedInformation.push(createDiagnosticForNode(node.node, Diagnostics.Did_you_mean_0, `export type { ${unescapeLeadingUnderscores(node.data.name.data.escapedText)} }`)); // TODO(rbuckton): do not instantiate `.node` } - const declarationName = getNameOfDeclaration(node) || node; - forEach(symbol.declarations, (declaration, index) => { + const declarationName = astGetNameOfDeclaration(node) ?? node; + forEach(symbol.declarations, (declaration, index) => { // TODO(rbuckton): AstNode version of `declarations` const decl = getNameOfDeclaration(declaration) || declaration; const diag = messageNeedsName ? createDiagnosticForNode(decl, message, getDisplayName(declaration)) : createDiagnosticForNode(decl, message); file.bindDiagnostics.push( - multipleDefaultExports ? addRelatedInfo(diag, createDiagnosticForNode(declarationName, index === 0 ? Diagnostics.Another_export_default_is_here : Diagnostics.and_here)) : diag, + multipleDefaultExports ? addRelatedInfo(diag, createDiagnosticForNode(declarationName.node, index === 0 ? Diagnostics.Another_export_default_is_here : Diagnostics.and_here)) : diag, // TODO(rbuckton): do not instantiate `.node` ); if (multipleDefaultExports) { relatedInformation.push(createDiagnosticForNode(decl, Diagnostics.The_first_export_default_is_here)); } }); - const diag = messageNeedsName ? createDiagnosticForNode(declarationName, message, getDisplayName(node)) : createDiagnosticForNode(declarationName, message); + const diag = messageNeedsName ? createDiagnosticForNode(declarationName.node, message, getDisplayName(node.node)) : createDiagnosticForNode(declarationName.node, message); // TODO(rbuckton): do not instantiate `.node` file.bindDiagnostics.push(addRelatedInfo(diag, ...relatedInformation)); symbol = createSymbol(SymbolFlags.None, name); @@ -884,7 +953,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { } } - addDeclarationToSymbol(symbol, node, includes); + addDeclarationToSymbol(symbol, node.node, includes); // TODO(rbuckton): do not instantiate `.node` if (symbol.parent) { Debug.assert(symbol.parent === parent, "Existing symbol parent should match new one"); } @@ -899,11 +968,11 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { const hasExportModifier = !!(getCombinedModifierFlags(node) & ModifierFlags.Export) || jsdocTreatAsExported(node); if (symbolFlags & SymbolFlags.Alias) { if (node.kind === SyntaxKind.ExportSpecifier || (node.kind === SyntaxKind.ImportEqualsDeclaration && hasExportModifier)) { - return declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes); + return declareSymbol(container.symbol.exports!, container.symbol, node.ast, symbolFlags, symbolExcludes); } else { Debug.assertNode(container, canHaveLocals); - return declareSymbol(container.locals!, /*parent*/ undefined, node, symbolFlags, symbolExcludes); + return declareSymbol(container.locals!, /*parent*/ undefined, node.ast, symbolFlags, symbolExcludes); } } else { @@ -925,17 +994,17 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { if (isJSDocTypeAlias(node)) Debug.assert(isInJSFile(node)); // We shouldn't add symbols for JSDoc nodes if not in a JS file. if (!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) { if (!canHaveLocals(container) || !container.locals || (hasSyntacticModifier(node, ModifierFlags.Default) && !getDeclarationName(node))) { - return declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes); // No local symbol for an unnamed default! + return declareSymbol(container.symbol.exports!, container.symbol, node.ast, symbolFlags, symbolExcludes); // No local symbol for an unnamed default! } const exportKind = symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0; - const local = declareSymbol(container.locals, /*parent*/ undefined, node, exportKind, symbolExcludes); - local.exportSymbol = declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes); + const local = declareSymbol(container.locals, /*parent*/ undefined, node.ast, exportKind, symbolExcludes); + local.exportSymbol = declareSymbol(container.symbol.exports!, container.symbol, node.ast, symbolFlags, symbolExcludes); node.localSymbol = local; return local; } else { Debug.assertNode(container, canHaveLocals); - return declareSymbol(container.locals!, /*parent*/ undefined, node, symbolFlags, symbolExcludes); + return declareSymbol(container.locals!, /*parent*/ undefined, node.ast, symbolFlags, symbolExcludes); } } } @@ -1254,7 +1323,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { return false; } - function isNarrowableReference(expr: Expression): boolean { + function isNarrowableReference(expr: AstExpression): boolean { switch (expr.kind) { case SyntaxKind.Identifier: case SyntaxKind.ThisKeyword: @@ -1264,19 +1333,19 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ParenthesizedExpression: case SyntaxKind.NonNullExpression: - return isNarrowableReference((expr as PropertyAccessExpression | ParenthesizedExpression | NonNullExpression).expression); + return isNarrowableReference(astGetExpression(expr as AstPropertyAccessExpression | AstParenthesizedExpression | AstNonNullExpression)); case SyntaxKind.ElementAccessExpression: - return (isStringOrNumericLiteralLike((expr as ElementAccessExpression).argumentExpression) || isEntityNameExpression((expr as ElementAccessExpression).argumentExpression)) && - isNarrowableReference((expr as ElementAccessExpression).expression); + return (astIsStringOrNumericLiteralLike((expr as AstElementAccessExpression).data.argumentExpression) || astIsEntityNameExpression((expr as AstElementAccessExpression).data.argumentExpression)) && + isNarrowableReference((expr as AstElementAccessExpression).data.expression); case SyntaxKind.BinaryExpression: - return (expr as BinaryExpression).operatorToken.kind === SyntaxKind.CommaToken && isNarrowableReference((expr as BinaryExpression).right) || - isAssignmentOperator((expr as BinaryExpression).operatorToken.kind) && isLeftHandSideExpression((expr as BinaryExpression).left); + return (expr as AstBinaryExpression).data.operatorToken.kind === SyntaxKind.CommaToken && isNarrowableReference((expr as AstBinaryExpression).data.right) || + isAssignmentOperator((expr as AstBinaryExpression).data.operatorToken.kind) && astIsLeftHandSideExpression((expr as AstBinaryExpression).data.left); } return false; } function containsNarrowableReference(expr: Expression): boolean { - return isNarrowableReference(expr) || isOptionalChain(expr) && containsNarrowableReference(expr.expression); + return isNarrowableReference(expr.ast) || isOptionalChain(expr) && containsNarrowableReference(expr.expression); } function hasNarrowableArgument(expr: CallExpression) { @@ -1796,7 +1865,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { } function bindAssignmentTargetFlow(node: Expression) { - if (isNarrowableReference(node)) { + if (isNarrowableReference(node.ast)) { currentFlow = createFlowMutation(FlowFlags.Assignment, currentFlow, node); } else if (node.kind === SyntaxKind.ArrayLiteralExpression) { @@ -1906,7 +1975,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { // `bindBinaryExpressionFlow` will already have done this work. setParent(node, parent); const saveInStrictMode = inStrictMode; - bindWorker(node); + bindWorker(node.ast); const saveParent = parent; parent = node; state.skip = false; @@ -2252,7 +2321,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { return declareClassMember(node, symbolFlags, symbolExcludes); case SyntaxKind.EnumDeclaration: - return declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes); + return declareSymbol(container.symbol.exports!, container.symbol, node.ast, symbolFlags, symbolExcludes); case SyntaxKind.TypeLiteral: case SyntaxKind.JSDocTypeLiteral: @@ -2264,7 +2333,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { // container, and are never in scope otherwise (even inside the body of the // object / type / interface declaring them). An exception is type parameters, // which are in scope without qualification (similar to 'locals'). - return declareSymbol(container.symbol.members!, container.symbol, node, symbolFlags, symbolExcludes); + return declareSymbol(container.symbol.members!, container.symbol, node.ast, symbolFlags, symbolExcludes); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: @@ -2291,20 +2360,20 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { // symbol to the 'locals' of the container. These symbols can then be found as // the type checker walks up the containers, checking them for matching names. if (container.locals) Debug.assertNode(container, canHaveLocals); - return declareSymbol(container.locals!, /*parent*/ undefined, node, symbolFlags, symbolExcludes); + return declareSymbol(container.locals!, /*parent*/ undefined, node.ast, symbolFlags, symbolExcludes); } } function declareClassMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { return isStatic(node) - ? declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes) - : declareSymbol(container.symbol.members!, container.symbol, node, symbolFlags, symbolExcludes); + ? declareSymbol(container.symbol.exports!, container.symbol, node.ast, symbolFlags, symbolExcludes) + : declareSymbol(container.symbol.members!, container.symbol, node.ast, symbolFlags, symbolExcludes); } function declareSourceFileMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { return isExternalModule(file) ? declareModuleMember(node, symbolFlags, symbolExcludes) - : declareSymbol(file.locals!, /*parent*/ undefined, node, symbolFlags, symbolExcludes); + : declareSymbol(file.locals!, /*parent*/ undefined, node.ast, symbolFlags, symbolExcludes); } function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean { @@ -2408,14 +2477,14 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { return symbol; } - function bindBlockScopedDeclaration(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { + function bindBlockScopedDeclaration(node: AstDeclaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { switch (blockScopeContainer.kind) { case SyntaxKind.ModuleDeclaration: - declareModuleMember(node, symbolFlags, symbolExcludes); + declareModuleMember(node.node, symbolFlags, symbolExcludes); // TODO(rbuckton): do not instantiate `.node` break; case SyntaxKind.SourceFile: if (isExternalOrCommonJsModule(container as SourceFile)) { - declareModuleMember(node, symbolFlags, symbolExcludes); + declareModuleMember(node.node, symbolFlags, symbolExcludes); // TODO(rbuckton): do not instantiate `.node` break; } // falls through @@ -2425,7 +2494,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { blockScopeContainer.locals = createSymbolTable(); addToContainerChain(blockScopeContainer); } - declareSymbol(blockScopeContainer.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes); + declareSymbol(blockScopeContainer.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes); // TODO(rbuckton): do not instantiate `.node` } } @@ -2484,7 +2553,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { } else if (isJSDocEnumTag(typeAlias) || !typeAlias.fullName || typeAlias.fullName.kind === SyntaxKind.Identifier) { parent = typeAlias.parent; - bindBlockScopedDeclaration(typeAlias, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); + bindBlockScopedDeclaration(typeAlias.ast, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); } else { bind(typeAlias.fullName); @@ -2529,16 +2598,16 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { // The binder visits every node in the syntax tree so it is a convenient place to perform a single localized // check for reserved words used as identifiers in strict mode code, as well as `yield` or `await` in // [Yield] or [Await] contexts, respectively. - function checkContextualIdentifier(node: Identifier) { + function checkContextualIdentifier(node: AstIdentifier) { // Report error only if there are no parse errors in file if ( !file.parseDiagnostics.length && !(node.flags & NodeFlags.Ambient) && !(node.flags & NodeFlags.JSDoc) && - !isIdentifierName(node) + !astIsIdentifierName(node) ) { // strict mode identifiers - const originalKeywordKind = identifierToKeywordKind(node); + const originalKeywordKind = astIdentifierToKeywordKind(node); if (originalKeywordKind === undefined) { return; } @@ -2548,18 +2617,18 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { originalKeywordKind >= SyntaxKind.FirstFutureReservedWord && originalKeywordKind <= SyntaxKind.LastFutureReservedWord ) { - file.bindDiagnostics.push(createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), declarationNameToString(node))); + file.bindDiagnostics.push(createDiagnosticForNode(node.node, getStrictModeIdentifierMessage(node.node), declarationNameToString(node.node))); // TODO(rbuckton): do not instantiate `.node` } else if (originalKeywordKind === SyntaxKind.AwaitKeyword) { - if (isExternalModule(file) && isInTopLevelContext(node)) { - file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, declarationNameToString(node))); + if (isExternalModule(file) && astIsInTopLevelContext(node)) { + file.bindDiagnostics.push(createDiagnosticForNode(node.node, Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, declarationNameToString(node.node))); // TODO(rbuckton): do not instantiate `.node` } else if (node.flags & NodeFlags.AwaitContext) { - file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, declarationNameToString(node))); + file.bindDiagnostics.push(createDiagnosticForNode(node.node, Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, declarationNameToString(node.node))); // TODO(rbuckton): do not instantiate `.node` } } else if (originalKeywordKind === SyntaxKind.YieldKeyword && node.flags & NodeFlags.YieldContext) { - file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, declarationNameToString(node))); + file.bindDiagnostics.push(createDiagnosticForNode(node.node, Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, declarationNameToString(node.node))); // TODO(rbuckton): do not instantiate `.node` } } } @@ -2580,11 +2649,11 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { // The binder visits every node, so this is a good place to check for // the reserved private name (there is only one) - function checkPrivateIdentifier(node: PrivateIdentifier) { - if (node.escapedText === "#constructor") { + function checkPrivateIdentifier(node: AstPrivateIdentifier) { + if (node.data.escapedText === "#constructor") { // Report error only if there are no parse errors in file if (!file.parseDiagnostics.length) { - file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.constructor_is_a_reserved_word, declarationNameToString(node))); + file.bindDiagnostics.push(createDiagnosticForNode(node.node, Diagnostics.constructor_is_a_reserved_word, declarationNameToString(node.node))); // TODO(rbuckton): do not instantiate `.node` } } } @@ -2768,7 +2837,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { // // However, not all symbols will end up in any of these tables. 'Anonymous' symbols // (like TypeLiterals for example) will not be put in any table. - bindWorker(node); + bindWorker(node.ast); // Then we recurse into the children of the node to bind them as well. For certain // symbols we do specialized work when we recurse. For example, we'll keep track of // the current 'container' node when it changes. This helps us know which symbol table @@ -2835,7 +2904,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { return nodeText === '"use strict"' || nodeText === "'use strict'"; } - function bindWorker(node: Node) { + function bindWorker(node: AstNode) { switch (node.kind) { /* Strict mode checks */ case SyntaxKind.Identifier: @@ -2844,77 +2913,80 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { // current "blockScopeContainer" needs to be set to its immediate namespace parent. if (node.flags & NodeFlags.IdentifierIsInJSDocNamespace) { let parentNode = node.parent; - while (parentNode && !isJSDocTypeAlias(parentNode)) { + while (parentNode && !astIsJSDocTypeAlias(parentNode)) { parentNode = parentNode.parent; } - bindBlockScopedDeclaration(parentNode as Declaration, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); + bindBlockScopedDeclaration(parentNode as AstDeclaration, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); break; } - // falls through + // TODO: Why use `isExpression` here? both Identifier and ThisKeyword are expressions. + if (currentFlow && (astIsExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) { + astSetFlowNode(node as AstIdentifier, currentFlow); + } + return checkContextualIdentifier(node as AstIdentifier); case SyntaxKind.ThisKeyword: // TODO: Why use `isExpression` here? both Identifier and ThisKeyword are expressions. - if (currentFlow && (isExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) { - (node as Identifier | ThisExpression).flowNode = currentFlow; + if (currentFlow && (astIsExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) { + astSetFlowNode(node as AstThisExpression, currentFlow); } - // TODO: a `ThisExpression` is not an Identifier, this cast is unsound - return checkContextualIdentifier(node as Identifier); + return; case SyntaxKind.QualifiedName: - if (currentFlow && isPartOfTypeQuery(node)) { - (node as QualifiedName).flowNode = currentFlow; + if (currentFlow && astIsPartOfTypeQuery(node)) { + astSetFlowNode(node as AstQualifiedName, currentFlow); } break; case SyntaxKind.MetaProperty: case SyntaxKind.SuperKeyword: - (node as MetaProperty | SuperExpression).flowNode = currentFlow; + astSetFlowNode(node as AstMetaProperty | AstSuperExpression, currentFlow); break; case SyntaxKind.PrivateIdentifier: - return checkPrivateIdentifier(node as PrivateIdentifier); + return checkPrivateIdentifier(node as AstPrivateIdentifier); case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ElementAccessExpression: - const expr = node as PropertyAccessExpression | ElementAccessExpression; + const expr = node as AstPropertyAccessExpression | AstElementAccessExpression; if (currentFlow && isNarrowableReference(expr)) { - expr.flowNode = currentFlow; + astSetFlowNode(expr, currentFlow); } - if (isSpecialPropertyDeclaration(expr)) { + if (astIsSpecialPropertyDeclaration(expr)) { bindSpecialPropertyDeclaration(expr); } if ( - isInJSFile(expr) && + astIsInJSFile(expr) && file.commonJsModuleIndicator && - isModuleExportsAccessExpression(expr) && + astIsModuleExportsAccessExpression(expr) && !lookupSymbolForName(blockScopeContainer, "module" as __String) ) { - declareSymbol(file.locals!, /*parent*/ undefined, expr.expression, SymbolFlags.FunctionScopedVariable | SymbolFlags.ModuleExports, SymbolFlags.FunctionScopedVariableExcludes); + declareSymbol(file.locals!, /*parent*/ undefined, astGetExpression(expr) as AstNode as AstDeclaration, SymbolFlags.FunctionScopedVariable | SymbolFlags.ModuleExports, SymbolFlags.FunctionScopedVariableExcludes); // TODO(rbuckton): do not instantiate `.node` } break; case SyntaxKind.BinaryExpression: - const specialKind = getAssignmentDeclarationKind(node as BinaryExpression); + const specialKind = astGetAssignmentDeclarationKind(node as AstBinaryExpression); switch (specialKind) { case AssignmentDeclarationKind.ExportsProperty: - bindExportsPropertyAssignment(node as BindableStaticPropertyAssignmentExpression); + bindExportsPropertyAssignment((node as AstBindableStaticPropertyAssignmentExpression).node); // TODO(rbuckton): do not instantiate `.node` break; case AssignmentDeclarationKind.ModuleExports: - bindModuleExportsAssignment(node as BindablePropertyAssignmentExpression); + bindModuleExportsAssignment((node as AstBindablePropertyAssignmentExpression).node); // TODO(rbuckton): do not instantiate `.node` break; case AssignmentDeclarationKind.PrototypeProperty: - bindPrototypePropertyAssignment((node as BindableStaticPropertyAssignmentExpression).left, node); + bindPrototypePropertyAssignment((node as AstBindableStaticPropertyAssignmentExpression).data.left.node, node.node); // TODO(rbuckton): do not instantiate `.node` break; case AssignmentDeclarationKind.Prototype: - bindPrototypeAssignment(node as BindableStaticPropertyAssignmentExpression); + bindPrototypeAssignment((node as AstBindableStaticPropertyAssignmentExpression).node); // TODO(rbuckton): do not instantiate `.node` break; case AssignmentDeclarationKind.ThisProperty: - bindThisPropertyAssignment(node as BindablePropertyAssignmentExpression); + bindThisPropertyAssignment((node as AstBindablePropertyAssignmentExpression).node); // TODO(rbuckton): do not instantiate `.node` break; case AssignmentDeclarationKind.Property: - const expression = ((node as BinaryExpression).left as AccessExpression).expression; - if (isInJSFile(node) && isIdentifier(expression)) { - const symbol = lookupSymbolForName(blockScopeContainer, expression.escapedText); - if (isThisInitializedDeclaration(symbol?.valueDeclaration)) { - bindThisPropertyAssignment(node as BindablePropertyAssignmentExpression); + const expression = ((node as AstBinaryExpression).data.left as AstAccessExpression).data.expression; + if (astIsInJSFile(node) && astIsIdentifier(expression)) { + const symbol = lookupSymbolForName(blockScopeContainer, expression.data.escapedText); + if (isThisInitializedDeclaration(symbol?.valueDeclaration)) { // TODO(rbuckton): ast variant of `valueDeclaration` + bindThisPropertyAssignment((node as AstBindablePropertyAssignmentExpression).node); // TODO(rbuckton): do not instantiate `.node` break; } } - bindSpecialPropertyAssignment(node as BindablePropertyAssignmentExpression); + bindSpecialPropertyAssignment((node as AstBindablePropertyAssignmentExpression).node); // TODO(rbuckton): do not instantiate `.node` break; case AssignmentDeclarationKind.None: // Nothing to do @@ -2922,94 +2994,94 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { default: Debug.fail("Unknown binary expression special property assignment kind"); } - return checkStrictModeBinaryExpression(node as BinaryExpression); + return checkStrictModeBinaryExpression((node as AstBinaryExpression).node); case SyntaxKind.CatchClause: - return checkStrictModeCatchClause(node as CatchClause); + return checkStrictModeCatchClause((node as AstCatchClause).node); case SyntaxKind.DeleteExpression: - return checkStrictModeDeleteExpression(node as DeleteExpression); + return checkStrictModeDeleteExpression((node as AstDeleteExpression).node); case SyntaxKind.PostfixUnaryExpression: - return checkStrictModePostfixUnaryExpression(node as PostfixUnaryExpression); + return checkStrictModePostfixUnaryExpression((node as AstPostfixUnaryExpression).node); case SyntaxKind.PrefixUnaryExpression: - return checkStrictModePrefixUnaryExpression(node as PrefixUnaryExpression); + return checkStrictModePrefixUnaryExpression((node as AstPrefixUnaryExpression).node); case SyntaxKind.WithStatement: - return checkStrictModeWithStatement(node as WithStatement); + return checkStrictModeWithStatement((node as AstWithStatement).node); case SyntaxKind.LabeledStatement: - return checkStrictModeLabeledStatement(node as LabeledStatement); + return checkStrictModeLabeledStatement((node as AstLabeledStatement).node); case SyntaxKind.ThisType: seenThisKeyword = true; return; case SyntaxKind.TypePredicate: break; // Binding the children will handle everything case SyntaxKind.TypeParameter: - return bindTypeParameter(node as TypeParameterDeclaration); + return bindTypeParameter((node as AstTypeParameterDeclaration).node); case SyntaxKind.Parameter: - return bindParameter(node as ParameterDeclaration); + return bindParameter((node as AstParameterDeclaration).node); case SyntaxKind.VariableDeclaration: - return bindVariableDeclarationOrBindingElement(node as VariableDeclaration); + return bindVariableDeclarationOrBindingElement((node as AstVariableDeclaration).node); case SyntaxKind.BindingElement: - (node as BindingElement).flowNode = currentFlow; - return bindVariableDeclarationOrBindingElement(node as BindingElement); + astSetFlowNode(node as AstBindingElement, currentFlow); + return bindVariableDeclarationOrBindingElement((node as AstBindingElement).node); case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: - return bindPropertyWorker(node as PropertyDeclaration | PropertySignature); + return bindPropertyWorker((node as AstPropertyDeclaration | AstPropertySignature).node); case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: - return bindPropertyOrMethodOrAccessor(node as Declaration, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + return bindPropertyOrMethodOrAccessor((node as AstDeclaration).node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); case SyntaxKind.EnumMember: - return bindPropertyOrMethodOrAccessor(node as Declaration, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes); + return bindPropertyOrMethodOrAccessor((node as AstDeclaration).node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes); case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: - return declareSymbolAndAddToSymbolTable(node as Declaration, SymbolFlags.Signature, SymbolFlags.None); + return declareSymbolAndAddToSymbolTable((node as AstDeclaration).node, SymbolFlags.Signature, SymbolFlags.None); case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. - return bindPropertyOrMethodOrAccessor(node as Declaration, SymbolFlags.Method | ((node as MethodDeclaration).questionToken ? SymbolFlags.Optional : SymbolFlags.None), isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes); + return bindPropertyOrMethodOrAccessor((node as AstDeclaration).node, SymbolFlags.Method | (((node as AstMethodDeclaration).node).questionToken ? SymbolFlags.Optional : SymbolFlags.None), isObjectLiteralMethod(node.node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.FunctionDeclaration: - return bindFunctionDeclaration(node as FunctionDeclaration); + return bindFunctionDeclaration((node as AstFunctionDeclaration).node); case SyntaxKind.Constructor: - return declareSymbolAndAddToSymbolTable(node as Declaration, SymbolFlags.Constructor, /*symbolExcludes:*/ SymbolFlags.None); + return declareSymbolAndAddToSymbolTable((node as AstDeclaration).node, SymbolFlags.Constructor, /*symbolExcludes:*/ SymbolFlags.None); case SyntaxKind.GetAccessor: - return bindPropertyOrMethodOrAccessor(node as Declaration, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes); + return bindPropertyOrMethodOrAccessor((node as AstDeclaration).node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes); case SyntaxKind.SetAccessor: - return bindPropertyOrMethodOrAccessor(node as Declaration, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes); + return bindPropertyOrMethodOrAccessor((node as AstDeclaration).node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes); case SyntaxKind.FunctionType: case SyntaxKind.JSDocFunctionType: case SyntaxKind.JSDocSignature: case SyntaxKind.ConstructorType: - return bindFunctionOrConstructorType(node as SignatureDeclaration | JSDocSignature); + return bindFunctionOrConstructorType((node as AstSignatureDeclaration | AstJSDocSignature).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.TypeLiteral: case SyntaxKind.JSDocTypeLiteral: case SyntaxKind.MappedType: - return bindAnonymousTypeWorker(node as TypeLiteralNode | MappedTypeNode | JSDocTypeLiteral); + return bindAnonymousTypeWorker((node as AstTypeLiteralNode | AstMappedTypeNode | AstJSDocTypeLiteral).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.JSDocClassTag: - return bindJSDocClassTag(node as JSDocClassTag); + return bindJSDocClassTag((node as AstJSDocClassTag).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.ObjectLiteralExpression: - return bindObjectLiteralExpression(node as ObjectLiteralExpression); + return bindObjectLiteralExpression((node as AstObjectLiteralExpression).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - return bindFunctionExpression(node as FunctionExpression | ArrowFunction); + return bindFunctionExpression((node as AstFunctionExpression | AstArrowFunction).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.CallExpression: - const assignmentKind = getAssignmentDeclarationKind(node as CallExpression); + const assignmentKind = getAssignmentDeclarationKind((node as AstCallExpression).node); // TODO(rbuckton): do not instantiate `.node` switch (assignmentKind) { case AssignmentDeclarationKind.ObjectDefinePropertyValue: - return bindObjectDefinePropertyAssignment(node as BindableObjectDefinePropertyCall); + return bindObjectDefinePropertyAssignment((node as AstBindableObjectDefinePropertyCall).node); // TODO(rbuckton): do not instantiate `.node` case AssignmentDeclarationKind.ObjectDefinePropertyExports: - return bindObjectDefinePropertyExport(node as BindableObjectDefinePropertyCall); + return bindObjectDefinePropertyExport((node as AstBindableObjectDefinePropertyCall).node); // TODO(rbuckton): do not instantiate `.node` case AssignmentDeclarationKind.ObjectDefinePrototypeProperty: - return bindObjectDefinePrototypeProperty(node as BindableObjectDefinePropertyCall); + return bindObjectDefinePrototypeProperty((node as AstBindableObjectDefinePropertyCall).node); // TODO(rbuckton): do not instantiate `.node` case AssignmentDeclarationKind.None: break; // Nothing to do default: return Debug.fail("Unknown call expression assignment declaration kind"); } - if (isInJSFile(node)) { - bindCallExpression(node as CallExpression); + if (astIsInJSFile(node)) { + bindCallExpression((node as AstCallExpression).node); // TODO(rbuckton): do not instantiate `.node` } break; @@ -3018,68 +3090,68 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { case SyntaxKind.ClassDeclaration: // All classes are automatically in strict mode in ES6. inStrictMode = true; - return bindClassLikeDeclaration(node as ClassLikeDeclaration); + return bindClassLikeDeclaration((node as AstClassLikeDeclaration).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.InterfaceDeclaration: - return bindBlockScopedDeclaration(node as Declaration, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes); + return bindBlockScopedDeclaration(node as AstDeclaration, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.TypeAliasDeclaration: - return bindBlockScopedDeclaration(node as Declaration, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); + return bindBlockScopedDeclaration(node as AstDeclaration, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.EnumDeclaration: - return bindEnumDeclaration(node as EnumDeclaration); + return bindEnumDeclaration((node as AstEnumDeclaration).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.ModuleDeclaration: - return bindModuleDeclaration(node as ModuleDeclaration); + return bindModuleDeclaration((node as AstModuleDeclaration).node); // TODO(rbuckton): do not instantiate `.node` // Jsx-attributes case SyntaxKind.JsxAttributes: - return bindJsxAttributes(node as JsxAttributes); + return bindJsxAttributes((node as AstJsxAttributes).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.JsxAttribute: - return bindJsxAttribute(node as JsxAttribute, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + return bindJsxAttribute((node as AstJsxAttribute).node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); // TODO(rbuckton): do not instantiate `.node` // Imports and exports case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.NamespaceImport: case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: - return declareSymbolAndAddToSymbolTable(node as Declaration, SymbolFlags.Alias, SymbolFlags.AliasExcludes); + return declareSymbolAndAddToSymbolTable((node as AstDeclaration).node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.NamespaceExportDeclaration: - return bindNamespaceExportDeclaration(node as NamespaceExportDeclaration); + return bindNamespaceExportDeclaration((node as AstNamespaceExportDeclaration).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.ImportClause: - return bindImportClause(node as ImportClause); + return bindImportClause((node as AstImportClause).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.ExportDeclaration: - return bindExportDeclaration(node as ExportDeclaration); + return bindExportDeclaration((node as AstExportDeclaration).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.ExportAssignment: - return bindExportAssignment(node as ExportAssignment); + return bindExportAssignment((node as AstExportAssignment).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.SourceFile: - updateStrictModeStatementList((node as SourceFile).statements); + updateStrictModeStatementList((node as AstSourceFile).data.statements.nodes); // TODO(rbuckton): do not instantiate `.nodes` return bindSourceFileIfExternalModule(); case SyntaxKind.Block: - if (!isFunctionLikeOrClassStaticBlockDeclaration(node.parent)) { + if (!isFunctionLikeOrClassStaticBlockDeclaration(node.parent?.node)) { // TODO(rbuckton): do not instantiate `.node` return; } // falls through case SyntaxKind.ModuleBlock: - return updateStrictModeStatementList((node as Block | ModuleBlock).statements); + return updateStrictModeStatementList((node as AstBlock | AstModuleBlock).data.statements.nodes); // TODO(rbuckton): do not instantiate `.nodes` case SyntaxKind.JSDocParameterTag: if (node.parent.kind === SyntaxKind.JSDocSignature) { - return bindParameter(node as JSDocParameterTag); + return bindParameter((node as AstJSDocParameterTag).node); // TODO(rbuckton): do not instantiate `.node` } if (node.parent.kind !== SyntaxKind.JSDocTypeLiteral) { break; } // falls through case SyntaxKind.JSDocPropertyTag: - const propTag = node as JSDocPropertyLikeTag; - const flags = propTag.isBracketed || propTag.typeExpression && propTag.typeExpression.type.kind === SyntaxKind.JSDocOptionalType ? + const propTag = node as AstJSDocPropertyLikeTag; + const flags = propTag.data.isBracketed || propTag.data.typeExpression && propTag.data.typeExpression.data.type.kind === SyntaxKind.JSDocOptionalType ? SymbolFlags.Property | SymbolFlags.Optional : SymbolFlags.Property; - return declareSymbolAndAddToSymbolTable(propTag, flags, SymbolFlags.PropertyExcludes); + return declareSymbolAndAddToSymbolTable(propTag.node, flags, SymbolFlags.PropertyExcludes); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.JSDocTypedefTag: case SyntaxKind.JSDocCallbackTag: case SyntaxKind.JSDocEnumTag: - return (delayedTypeAliases || (delayedTypeAliases = [])).push(node as JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag); + return (delayedTypeAliases || (delayedTypeAliases = [])).push((node as AstJSDocTypedefTag | AstJSDocCallbackTag | AstJSDocEnumTag).node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.JSDocOverloadTag: - return bind((node as JSDocOverloadTag).typeExpression); + return bind((node as AstJSDocOverloadTag).data.typeExpression.node); // TODO(rbuckton): do not instantiate `.node` case SyntaxKind.JSDocImportTag: - return (jsDocImports || (jsDocImports = [])).push(node as JSDocImportTag); + return (jsDocImports || (jsDocImports = [])).push((node as AstJSDocImportTag).node); // TODO(rbuckton): do not instantiate `.node` } } @@ -3103,7 +3175,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { bindSourceFileAsExternalModule(); // Create symbol equivalent for the module.exports = {} const originalSymbol = file.symbol; - declareSymbol(file.symbol.exports!, file.symbol, file, SymbolFlags.Property, SymbolFlags.All); + declareSymbol(file.symbol.exports!, file.symbol, file.ast, SymbolFlags.Property, SymbolFlags.All); file.symbol = originalSymbol; } } @@ -3125,7 +3197,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { : SymbolFlags.Property; // If there is an `export default x;` alias declaration, can't `export default` anything else. // (In contrast, you can still have `export default function f() {}` and `export default interface I {}`.) - const symbol = declareSymbol(container.symbol.exports, container.symbol, node, flags, SymbolFlags.All); + const symbol = declareSymbol(container.symbol.exports, container.symbol, node.ast, flags, SymbolFlags.All); if (node.isExportEquals) { // Will be an error later, since the module already has other exports. Just make sure this has a valueDeclaration set. @@ -3147,7 +3219,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { } else { file.symbol.globalExports = file.symbol.globalExports || createSymbolTable(); - declareSymbol(file.symbol.globalExports, file.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); + declareSymbol(file.symbol.globalExports, file.symbol, node.ast, SymbolFlags.Alias, SymbolFlags.AliasExcludes); } } @@ -3158,13 +3230,13 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { } else if (!node.exportClause) { // All export * declarations are collected in an __export symbol - declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.ExportStar, SymbolFlags.None); + declareSymbol(container.symbol.exports, container.symbol, node.ast, SymbolFlags.ExportStar, SymbolFlags.None); } else if (isNamespaceExport(node.exportClause)) { // declareSymbol walks up parents to find name text, parent _must_ be set // but won't be set by the normal binder walk until `bindChildren` later on. setParent(node.exportClause, node); - declareSymbol(container.symbol.exports, container.symbol, node.exportClause, SymbolFlags.Alias, SymbolFlags.AliasExcludes); + declareSymbol(container.symbol.exports, container.symbol, node.exportClause.ast, SymbolFlags.Alias, SymbolFlags.AliasExcludes); } } @@ -3199,7 +3271,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { }); if (symbol) { const flags = SymbolFlags.Property | SymbolFlags.ExportValue; - declareSymbol(symbol.exports!, symbol, node, flags, SymbolFlags.None); + declareSymbol(symbol.exports!, symbol, node.ast, flags, SymbolFlags.None); } } @@ -3219,7 +3291,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { const isAlias = isAliasableExpression(node.right) && (isExportsIdentifier(node.left.expression) || isModuleExportsAccessExpression(node.left.expression)); const flags = isAlias ? SymbolFlags.Alias : SymbolFlags.Property | SymbolFlags.ExportValue; setParent(node.left, node); - declareSymbol(symbol.exports!, symbol, node.left, flags, SymbolFlags.None); + declareSymbol(symbol.exports!, symbol, node.left.ast, flags, SymbolFlags.None); } } @@ -3245,12 +3317,12 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { const flags = exportAssignmentIsAlias(node) ? SymbolFlags.Alias // An export= with an EntityNameExpression or a ClassExpression exports all meanings of that identifier or class : SymbolFlags.Property | SymbolFlags.ExportValue | SymbolFlags.ValueModule; - const symbol = declareSymbol(file.symbol.exports!, file.symbol, node, flags | SymbolFlags.Assignment, SymbolFlags.None); + const symbol = declareSymbol(file.symbol.exports!, file.symbol, node.ast, flags | SymbolFlags.Assignment, SymbolFlags.None); setValueDeclaration(symbol, node); } function bindExportAssignedObjectMemberAlias(node: ShorthandPropertyAssignment) { - declareSymbol(file.symbol.exports!, file.symbol, node, SymbolFlags.Alias | SymbolFlags.Assignment, SymbolFlags.None); + declareSymbol(file.symbol.exports!, file.symbol, node.ast, SymbolFlags.Alias | SymbolFlags.Assignment, SymbolFlags.None); } function bindThisPropertyAssignment(node: BindablePropertyAssignmentExpression | PropertyAccessExpression | LiteralLikeElementAccessExpression) { @@ -3282,7 +3354,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { bindDynamicallyNamedThisPropertyAssignment(node, constructorSymbol, constructorSymbol.members); } else { - declareSymbol(constructorSymbol.members, constructorSymbol, node, SymbolFlags.Property | SymbolFlags.Assignment, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property); + declareSymbol(constructorSymbol.members, constructorSymbol, node.ast, SymbolFlags.Property | SymbolFlags.Assignment, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property); } addDeclarationToSymbol(constructorSymbol, constructorSymbol.valueDeclaration, SymbolFlags.Class); } @@ -3302,7 +3374,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { bindDynamicallyNamedThisPropertyAssignment(node, containingClass.symbol, symbolTable); } else { - declareSymbol(symbolTable, containingClass.symbol, node, SymbolFlags.Property | SymbolFlags.Assignment, SymbolFlags.None, /*isReplaceableByMethod*/ true); + declareSymbol(symbolTable, containingClass.symbol, node.ast, SymbolFlags.Property | SymbolFlags.Assignment, SymbolFlags.None, /*isReplaceableByMethod*/ true); } break; case SyntaxKind.SourceFile: @@ -3311,7 +3383,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { break; } else if (thisContainer.commonJsModuleIndicator) { - declareSymbol(thisContainer.symbol.exports!, thisContainer.symbol, node, SymbolFlags.Property | SymbolFlags.ExportValue, SymbolFlags.None); + declareSymbol(thisContainer.symbol.exports!, thisContainer.symbol, node.ast, SymbolFlags.Property | SymbolFlags.ExportValue, SymbolFlags.None); } else { declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes); @@ -3326,7 +3398,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { } function bindDynamicallyNamedThisPropertyAssignment(node: BinaryExpression | DynamicNamedDeclaration, symbol: Symbol, symbolTable: SymbolTable) { - declareSymbol(symbolTable, symbol, node, SymbolFlags.Property, SymbolFlags.None, /*isReplaceableByMethod*/ true, /*isComputedName*/ true); + declareSymbol(symbolTable, symbol, node.ast, SymbolFlags.Property, SymbolFlags.None, /*isReplaceableByMethod*/ true, /*isComputedName*/ true); addLateBoundAssignmentDeclarationToSymbol(node, symbol); } @@ -3336,16 +3408,16 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { } } - function bindSpecialPropertyDeclaration(node: PropertyAccessExpression | LiteralLikeElementAccessExpression) { - if (node.expression.kind === SyntaxKind.ThisKeyword) { - bindThisPropertyAssignment(node); + function bindSpecialPropertyDeclaration(node: AstPropertyAccessExpression | AstLiteralLikeElementAccessExpression) { + if (node.data.expression.kind === SyntaxKind.ThisKeyword) { + bindThisPropertyAssignment(node.node); // TODO(rbuckton): do not instantiate `.node` } - else if (isBindableStaticAccessExpression(node) && node.parent.parent.kind === SyntaxKind.SourceFile) { - if (isPrototypeAccess(node.expression)) { - bindPrototypePropertyAssignment(node, node.parent); + else if (astIsBindableStaticAccessExpression(node) && node.parent.parent.kind === SyntaxKind.SourceFile) { + if (astIsPrototypeAccess(node.data.expression)) { + bindPrototypePropertyAssignment(node.node, node.parent.node); // TODO(rbuckton): do not instantiate `.node` } else { - bindStaticPropertyAssignment(node); + bindStaticPropertyAssignment(node.node); // TODO(rbuckton): do not instantiate `.node` } } } @@ -3446,7 +3518,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { else { const table = parent ? parent.exports! : file.jsGlobalAugmentations || (file.jsGlobalAugmentations = createSymbolTable()); - return declareSymbol(table, parent, id, flags, excludeFlags); + return declareSymbol(table, parent, id.ast, flags, excludeFlags); } }); } @@ -3502,7 +3574,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { excludes = SymbolFlags.PropertyExcludes; } - declareSymbol(symbolTable, namespaceSymbol, declaration, includes | SymbolFlags.Assignment, excludes & ~SymbolFlags.Assignment); + declareSymbol(symbolTable, namespaceSymbol, declaration.ast, includes | SymbolFlags.Assignment, excludes & ~SymbolFlags.Assignment); } function isTopLevelNamespaceAssignment(propertyAccess: BindableAccessExpression) { @@ -3594,7 +3666,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { function bindClassLikeDeclaration(node: ClassLikeDeclaration) { if (node.kind === SyntaxKind.ClassDeclaration) { - bindBlockScopedDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes); + bindBlockScopedDeclaration(node.ast, SymbolFlags.Class, SymbolFlags.ClassExcludes); } else { const bindingName = node.name ? node.name.escapedText : InternalSymbolName.Class; @@ -3630,8 +3702,8 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { function bindEnumDeclaration(node: EnumDeclaration) { return isEnumConst(node) - ? bindBlockScopedDeclaration(node, SymbolFlags.ConstEnum, SymbolFlags.ConstEnumExcludes) - : bindBlockScopedDeclaration(node, SymbolFlags.RegularEnum, SymbolFlags.RegularEnumExcludes); + ? bindBlockScopedDeclaration(node.ast, SymbolFlags.ConstEnum, SymbolFlags.ConstEnumExcludes) + : bindBlockScopedDeclaration(node.ast, SymbolFlags.RegularEnum, SymbolFlags.RegularEnumExcludes); } function bindVariableDeclarationOrBindingElement(node: VariableDeclaration | BindingElement) { @@ -3650,7 +3722,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { declareSymbolAndAddToSymbolTable(node as Declaration, SymbolFlags.Alias, SymbolFlags.AliasExcludes); } else if (isBlockOrCatchScoped(node)) { - bindBlockScopedDeclaration(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); + bindBlockScopedDeclaration(node.ast, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); } else if (isPartOfParameterDeclaration(node)) { // It is safe to walk up parent chain to find whether the node is a destructuring parameter declaration @@ -3691,7 +3763,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { // containing class. if (isParameterPropertyDeclaration(node, node.parent)) { const classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members!, classDeclaration.symbol, node, SymbolFlags.Property | (node.questionToken ? SymbolFlags.Optional : SymbolFlags.None), SymbolFlags.PropertyExcludes); + declareSymbol(classDeclaration.symbol.members!, classDeclaration.symbol, node.ast, SymbolFlags.Property | (node.questionToken ? SymbolFlags.Optional : SymbolFlags.None), SymbolFlags.PropertyExcludes); } } @@ -3705,7 +3777,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { checkStrictModeFunctionName(node); if (inStrictMode) { checkStrictModeFunctionDeclaration(node); - bindBlockScopedDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes); + bindBlockScopedDeclaration(node.ast, SymbolFlags.Function, SymbolFlags.FunctionExcludes); } else { declareSymbolAndAddToSymbolTable(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes); @@ -3751,7 +3823,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { if (container) { Debug.assertNode(container, canHaveLocals); container.locals ??= createSymbolTable(); - declareSymbol(container.locals, /*parent*/ undefined, node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); + declareSymbol(container.locals, /*parent*/ undefined, node.ast, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); } else { declareSymbolAndAddToSymbolTable(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); @@ -3762,7 +3834,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { if (container) { Debug.assertNode(container, canHaveLocals); container.locals ??= createSymbolTable(); - declareSymbol(container.locals, /*parent*/ undefined, node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); + declareSymbol(container.locals, /*parent*/ undefined, node.ast, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); } else { bindAnonymousDeclaration(node, SymbolFlags.TypeParameter, getDeclarationName(node)!); // TODO: GH#18217 diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2aa5e6c7afa07..f9f990b0d0717 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1134,6 +1134,7 @@ import { hasName, canHaveQuestionToken, hasAsteriskToken, + AstDeclaration, } from "./_namespaces/ts.js"; import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers.js"; import * as performance from "./_namespaces/ts.performance.js"; @@ -1539,11 +1540,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { var globals = createSymbolTable(); var undefinedSymbol = createSymbol(SymbolFlags.Property, "undefined" as __String); - undefinedSymbol.declarations = []; + undefinedSymbol.astDeclarations = []; var globalThisSymbol = createSymbol(SymbolFlags.Module, "globalThis" as __String, CheckFlags.Readonly); globalThisSymbol.exports = globals; - globalThisSymbol.declarations = []; + globalThisSymbol.astDeclarations = []; globals.set(globalThisSymbol.escapedName, globalThisSymbol); var argumentsSymbol = createSymbol(SymbolFlags.Property, "arguments" as __String); @@ -2545,8 +2546,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return diagnostic; } - function addDeprecatedSuggestionWorker(declarations: Node | Node[], diagnostic: DiagnosticWithLocation) { - const deprecatedTag = Array.isArray(declarations) ? forEach(declarations, getJSDocDeprecatedTag) : getJSDocDeprecatedTag(declarations); + function addDeprecatedSuggestionWorker(declarations: Node | readonly Node[], diagnostic: DiagnosticWithLocation) { + const deprecatedTag = isArray(declarations) ? forEach(declarations, getJSDocDeprecatedTag) : getJSDocDeprecatedTag(declarations); if (deprecatedTag) { addRelatedInfo( diagnostic, @@ -2571,7 +2572,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return !!(getCombinedNodeFlagsCached(declaration) & NodeFlags.Deprecated); } - function addDeprecatedSuggestion(location: Node, declarations: Node[], deprecatedEntity: string) { + function addDeprecatedSuggestion(location: Node, declarations: readonly Node[], deprecatedEntity: string) { const diagnostic = createDiagnosticForNode(location, Diagnostics._0_is_deprecated, deprecatedEntity); return addDeprecatedSuggestionWorker(declarations, diagnostic); } @@ -2634,9 +2635,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function cloneSymbol(symbol: Symbol): TransientSymbol { const result = createSymbol(symbol.flags, symbol.escapedName); - result.declarations = symbol.declarations ? symbol.declarations.slice() : []; + result.astDeclarations = symbol.astDeclarations ? symbol.astDeclarations.slice() : []; result.parent = symbol.parent; - if (symbol.valueDeclaration) result.valueDeclaration = symbol.valueDeclaration; + if (symbol.astValueDeclaration) result.astValueDeclaration = symbol.astValueDeclaration; if (symbol.constEnumOnlyModule) result.constEnumOnlyModule = true; if (symbol.members) result.members = new Map(symbol.members); if (symbol.exports) result.exports = new Map(symbol.exports); @@ -2683,7 +2684,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (source.valueDeclaration) { setValueDeclaration(target, source.valueDeclaration); } - addRange(target.declarations, source.declarations); + addRange(target.astDeclarations, source.astDeclarations); if (source.members) { if (!target.members) target.members = createSymbolTable(); mergeSymbolTable(target.members, source.members, unidirectional); @@ -3906,9 +3907,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } const result = createSymbol(valueSymbol.flags | typeSymbol.flags, valueSymbol.escapedName); Debug.assert(valueSymbol.declarations || typeSymbol.declarations); - result.declarations = deduplicate(concatenate(valueSymbol.declarations!, typeSymbol.declarations), equateValues); + result.astDeclarations = deduplicate(concatenate(valueSymbol.astDeclarations!, typeSymbol.astDeclarations), equateValues); result.parent = valueSymbol.parent || typeSymbol.parent; - if (valueSymbol.valueDeclaration) result.valueDeclaration = valueSymbol.valueDeclaration; + if (valueSymbol.astValueDeclaration) result.astValueDeclaration = valueSymbol.astValueDeclaration; if (typeSymbol.members) result.members = new Map(typeSymbol.members); if (valueSymbol.exports) result.exports = new Map(valueSymbol.exports); return result; @@ -4964,11 +4965,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { */ function cloneTypeAsModuleType(symbol: Symbol, moduleType: Type, referenceParent: ImportDeclaration | ImportCall) { const result = createSymbol(symbol.flags, symbol.escapedName); - result.declarations = symbol.declarations ? symbol.declarations.slice() : []; + result.astDeclarations = symbol.astDeclarations ? symbol.astDeclarations.slice() : []; result.parent = symbol.parent; result.links.target = symbol; result.links.originatingImport = referenceParent; - if (symbol.valueDeclaration) result.valueDeclaration = symbol.valueDeclaration; + if (symbol.astValueDeclaration) result.astValueDeclaration = symbol.astValueDeclaration; if (symbol.constEnumOnlyModule) result.constEnumOnlyModule = true; if (symbol.members) result.members = new Map(symbol.members); if (symbol.exports) result.exports = new Map(symbol.exports); @@ -9727,7 +9728,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { ); } - function getSomeTargetNameFromDeclarations(declarations: Declaration[] | undefined) { + function getSomeTargetNameFromDeclarations(declarations: readonly Declaration[] | undefined) { return firstDefined(declarations, d => { if (isImportSpecifier(d) || isExportSpecifier(d)) { return moduleExportNameTextUnescaped(d.propertyName || d.name); @@ -10729,7 +10730,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } return result; - function buildVisibleNodeList(declarations: Declaration[] | undefined) { + function buildVisibleNodeList(declarations: readonly Declaration[] | undefined) { forEach(declarations, declaration => { const resultNode = getAnyImportSyntax(declaration) || declaration; if (setVisibility) { @@ -11560,8 +11561,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } const union = createSymbol(s.flags | exportedMember.flags, name); union.links.type = getUnionType([getTypeOfSymbol(s), getTypeOfSymbol(exportedMember)]); - union.valueDeclaration = exportedMember.valueDeclaration; - union.declarations = concatenate(exportedMember.declarations, s.declarations); + union.astValueDeclaration = exportedMember.astValueDeclaration; + union.astDeclarations = concatenate(exportedMember.astDeclarations, s.astDeclarations); members.set(name, union); } else { @@ -11618,7 +11619,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { (thisContainer.kind === SyntaxKind.FunctionExpression && !isPrototypePropertyAssignment(thisContainer.parent)); } - function getConstructorDefinedThisAssignmentTypes(types: Type[], declarations: Declaration[]): Type[] | undefined { + function getConstructorDefinedThisAssignmentTypes(types: Type[], declarations: readonly Declaration[]): Type[] | undefined { Debug.assert(types.length === declarations.length); return types.filter((_, i) => { const declaration = declarations[i]; @@ -11846,10 +11847,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (symbol.flags & SymbolFlags.ModuleExports && symbol.valueDeclaration) { const fileSymbol = getSymbolOfDeclaration(getSourceFileOfNode(symbol.valueDeclaration)); const result = createSymbol(fileSymbol.flags, "exports" as __String); - result.declarations = fileSymbol.declarations ? fileSymbol.declarations.slice() : []; + result.astDeclarations = fileSymbol.astDeclarations ? fileSymbol.astDeclarations.slice() : []; result.parent = symbol; result.links.target = fileSymbol; - if (fileSymbol.valueDeclaration) result.valueDeclaration = fileSymbol.valueDeclaration; + if (fileSymbol.astValueDeclaration) result.astValueDeclaration = fileSymbol.astValueDeclaration; if (fileSymbol.members) result.members = new Map(fileSymbol.members); if (fileSymbol.exports) result.exports = new Map(fileSymbol.exports); const members = createSymbolTable(); @@ -13118,15 +13119,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { Debug.assert(!!(getCheckFlags(symbol) & CheckFlags.Late), "Expected a late-bound symbol."); symbol.flags |= symbolFlags; getSymbolLinks(member.symbol).lateSymbol = symbol; - if (!symbol.declarations) { - symbol.declarations = [member]; + if (!symbol.astDeclarations) { + symbol.astDeclarations = [member.ast]; } else if (!member.symbol.isReplaceableByMethod) { - symbol.declarations.push(member); + symbol.astDeclarations.push(member.ast); } if (symbolFlags & SymbolFlags.Value) { - if (!symbol.valueDeclaration || symbol.valueDeclaration.kind !== member.kind) { - symbol.valueDeclaration = member; + if (!symbol.astValueDeclaration || symbol.astValueDeclaration.kind !== member.kind) { + symbol.astValueDeclaration = member.ast; } } } @@ -13219,11 +13220,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // Then just add the computed name as a late bound declaration // (note: unlike `addDeclarationToLateBoundSymbol` we do not set up a `.lateSymbol` on `decl`'s links, // since that would point at an index symbol and not a single property symbol, like most consumers would expect) - if (!indexSymbol.declarations) { - indexSymbol.declarations = [decl]; + if (!indexSymbol.astDeclarations) { + indexSymbol.astDeclarations = [decl.ast]; } else if (!decl.symbol.isReplaceableByMethod) { - indexSymbol.declarations.push(decl); + indexSymbol.astDeclarations.push(decl.ast); } } @@ -14010,7 +14011,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } const checkFlags = CheckFlags.ReverseMapped | (readonlyMask && isReadonlySymbol(prop) ? CheckFlags.Readonly : 0); const inferredProp = createSymbol(SymbolFlags.Property | prop.flags & optionalMask, prop.escapedName, checkFlags) as ReverseMappedSymbol; - inferredProp.declarations = prop.declarations; + inferredProp.astDeclarations = prop.astDeclarations; inferredProp.links.nameType = getSymbolLinks(prop).nameType; inferredProp.links.propertyType = getTypeOfSymbol(prop); if ( @@ -14146,7 +14147,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { prop.links.keyType = keyType; if (modifiersProp) { prop.links.syntheticOrigin = modifiersProp; - prop.declarations = shouldLinkPropDeclarations ? modifiersProp.declarations : undefined; + prop.astDeclarations = shouldLinkPropDeclarations ? modifiersProp.astDeclarations : undefined; } members.set(propName, prop); } @@ -14948,7 +14949,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } const props = propSet ? arrayFrom(propSet.values()) : [singleProp]; - let declarations: Declaration[] | undefined; + let declarations: AstDeclaration[] | undefined; let firstType: Type | undefined; let nameType: Type | undefined; const propTypes: Type[] = []; @@ -14962,7 +14963,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else if (prop.valueDeclaration && prop.valueDeclaration !== firstValueDeclaration) { hasNonUniformValueDeclaration = true; } - declarations = addRange(declarations, prop.declarations); + declarations = addRange(declarations, prop.astDeclarations); const type = getTypeOfSymbol(prop); if (!firstType) { firstType = type; @@ -14987,7 +14988,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const result = createSymbol(SymbolFlags.Property | (optionalFlag ?? 0), name, syntheticFlag | checkFlags); result.links.containingType = containingType; if (!hasNonUniformValueDeclaration && firstValueDeclaration) { - result.valueDeclaration = firstValueDeclaration; + result.astValueDeclaration = firstValueDeclaration.ast; // Inherit information about parent type. if (firstValueDeclaration.symbol.parent) { @@ -14995,7 +14996,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - result.declarations = declarations; + result.astDeclarations = declarations; result.links.nameType = nameType; if (propTypes.length > 2) { // When `propTypes` has the potential to explode in size when normalized, defer normalization until absolutely needed @@ -15935,8 +15936,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // type variables by `couldContainTypeVariables` const type = createObjectType(ObjectFlags.Anonymous | ObjectFlags.SingleSignatureType, createSymbol(SymbolFlags.Function, InternalSymbolName.Function)) as SingleSignatureType; if (signature.declaration && !nodeIsSynthesized(signature.declaration)) { // skip synthetic declarations - keeping those around could be bad, since they lack a parent pointer - type.symbol.declarations = [signature.declaration]; - type.symbol.valueDeclaration = signature.declaration; + type.symbol.astDeclarations = [signature.declaration.ast]; + type.symbol.astValueDeclaration = signature.declaration.ast; } outerTypeParameters ||= signature.declaration && getOuterTypeParameters(signature.declaration, /*includeThisTypes*/ true); type.outerTypeParameters = outerTypeParameters; @@ -19424,7 +19425,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const flags = SymbolFlags.Property | SymbolFlags.Optional; const result = createSymbol(flags, prop.escapedName, getIsLateCheckFlag(prop) | (readonly ? CheckFlags.Readonly : 0)); result.links.type = isSetonlyAccessor ? undefinedType : addOptionality(getTypeOfSymbol(prop), /*isProperty*/ true); - result.declarations = prop.declarations; + result.astDeclarations = prop.astDeclarations; result.links.nameType = getSymbolLinks(prop).nameType; result.links.syntheticOrigin = prop; members.set(prop.escapedName, result); @@ -19508,7 +19509,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const rightProp = members.get(leftProp.escapedName)!; const rightType = getTypeOfSymbol(rightProp); if (rightProp.flags & SymbolFlags.Optional) { - const declarations = concatenate(leftProp.declarations, rightProp.declarations); + const declarations = concatenate(leftProp.astDeclarations, rightProp.astDeclarations); const flags = SymbolFlags.Property | (leftProp.flags & SymbolFlags.Optional); const result = createSymbol(flags, leftProp.escapedName); // Optimization: avoid calculating the union type if spreading into the exact same type. @@ -19521,7 +19522,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { result.links.type = leftTypeWithoutUndefined === rightTypeWithoutUndefined ? leftType : getUnionType([leftType, rightTypeWithoutUndefined], UnionReduction.Subtype); result.links.leftSpread = leftProp; result.links.rightSpread = rightProp; - result.declarations = declarations; + result.astDeclarations = declarations; result.links.nameType = getSymbolLinks(leftProp).nameType; members.set(leftProp.escapedName, result); } @@ -19551,7 +19552,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const flags = SymbolFlags.Property | (prop.flags & SymbolFlags.Optional); const result = createSymbol(flags, prop.escapedName, getIsLateCheckFlag(prop) | (readonly ? CheckFlags.Readonly : 0)); result.links.type = isSetonlyAccessor ? undefinedType : getTypeOfSymbol(prop); - result.declarations = prop.declarations; + result.astDeclarations = prop.astDeclarations; result.links.nameType = getSymbolLinks(prop).nameType; result.links.syntheticOrigin = prop; return result; @@ -20003,12 +20004,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // Keep the flags from the symbol we're instantiating. Mark that is instantiated, and // also transient so that we can just store data on it directly. const result = createSymbol(symbol.flags, symbol.escapedName, CheckFlags.Instantiated | getCheckFlags(symbol) & (CheckFlags.Readonly | CheckFlags.Late | CheckFlags.OptionalParameter | CheckFlags.RestParameter)); - result.declarations = symbol.declarations; + result.astDeclarations = symbol.astDeclarations; result.parent = symbol.parent; result.links.target = symbol; result.links.mapper = mapper; - if (symbol.valueDeclaration) { - result.valueDeclaration = symbol.valueDeclaration; + if (symbol.astValueDeclaration) { + result.astValueDeclaration = symbol.astValueDeclaration; } if (links.nameType) { result.links.nameType = links.nameType; @@ -20035,7 +20036,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { outerTypeParameters = addRange(outerTypeParameters, templateTagParameters); } typeParameters = outerTypeParameters || emptyArray; - const allDeclarations = type.objectFlags & (ObjectFlags.Reference | ObjectFlags.InstantiationExpressionType) ? [declaration] : type.symbol.declarations!; + const allDeclarations: readonly Node[] = type.objectFlags & (ObjectFlags.Reference | ObjectFlags.InstantiationExpressionType) ? [declaration] : type.symbol.declarations!; typeParameters = (target.objectFlags & (ObjectFlags.Reference | ObjectFlags.InstantiationExpressionType) || target.symbol.flags & SymbolFlags.Method || target.symbol.flags & SymbolFlags.TypeLiteral) && !target.aliasTypeArguments ? filter(typeParameters, tp => some(allDeclarations, d => isTypeParameterPossiblyReferenced(tp, d))) : typeParameters; @@ -25102,12 +25103,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function createSymbolWithType(source: Symbol, type: Type | undefined) { const symbol = createSymbol(source.flags, source.escapedName, getCheckFlags(source) & CheckFlags.Readonly); - symbol.declarations = source.declarations; + symbol.astDeclarations = source.astDeclarations; symbol.parent = source.parent; symbol.links.type = type; symbol.links.target = source; - if (source.valueDeclaration) { - symbol.valueDeclaration = source.valueDeclaration; + if (source.astValueDeclaration) { + symbol.astValueDeclaration = source.astValueDeclaration; } const nameType = getSymbolLinks(source).nameType; if (nameType) { @@ -25647,8 +25648,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const literalProp = createSymbol(SymbolFlags.Property, name); literalProp.links.type = anyType; if (t.symbol) { - literalProp.declarations = t.symbol.declarations; - literalProp.valueDeclaration = t.symbol.valueDeclaration; + literalProp.astDeclarations = t.symbol.astDeclarations; + literalProp.astValueDeclaration = t.symbol.astValueDeclaration; } members.set(name, literalProp); }); @@ -32746,10 +32747,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - prop.declarations = member.declarations; + prop.astDeclarations = member.astDeclarations; prop.parent = member.parent; - if (member.valueDeclaration) { - prop.valueDeclaration = member.valueDeclaration; + if (member.astValueDeclaration) { + prop.astValueDeclaration = member.astValueDeclaration; } prop.links.type = type; @@ -32979,10 +32980,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { objectFlags |= getObjectFlags(exprType) & ObjectFlags.PropagatingFlags; const attributeSymbol = createSymbol(SymbolFlags.Property | member.flags, member.escapedName); - attributeSymbol.declarations = member.declarations; + attributeSymbol.astDeclarations = member.astDeclarations; attributeSymbol.parent = member.parent; - if (member.valueDeclaration) { - attributeSymbol.valueDeclaration = member.valueDeclaration; + if (member.astValueDeclaration) { + attributeSymbol.astValueDeclaration = member.astValueDeclaration; } attributeSymbol.links.type = exprType; attributeSymbol.links.target = member; @@ -33059,9 +33060,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { childrenContextualType && someType(childrenContextualType, isTupleLikeType) ? createTupleType(childrenTypes) : createArrayType(getUnionType(childrenTypes)); // Fake up a property declaration for the children - childrenPropSymbol.valueDeclaration = factory.createPropertySignature(/*modifiers*/ undefined, unescapeLeadingUnderscores(jsxChildrenPropertyName), /*questionToken*/ undefined, /*type*/ undefined); + childrenPropSymbol.astValueDeclaration = factory.createPropertySignature(/*modifiers*/ undefined, unescapeLeadingUnderscores(jsxChildrenPropertyName), /*questionToken*/ undefined, /*type*/ undefined).ast; setParent(childrenPropSymbol.valueDeclaration, attributeParent); - childrenPropSymbol.valueDeclaration.symbol = childrenPropSymbol; + childrenPropSymbol.valueDeclaration!.symbol = childrenPropSymbol; const childPropMap = createSymbolTable(); childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol); spread = getSpreadType(spread, createAnonymousType(attributesSymbol, childPropMap, emptyArray, emptyArray, emptyArray), attributesSymbol, objectFlags, /*readonly*/ false); @@ -42095,7 +42096,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return implementationSharesContainerWithFirstOverload ? implementation : overloads[0]; } - function checkFlagAgreementBetweenOverloads(overloads: Declaration[], implementation: FunctionLikeDeclaration | undefined, flagsToCheck: ModifierFlags, someOverloadFlags: ModifierFlags, allOverloadFlags: ModifierFlags): void { + function checkFlagAgreementBetweenOverloads(overloads: readonly Declaration[], implementation: FunctionLikeDeclaration | undefined, flagsToCheck: ModifierFlags, someOverloadFlags: ModifierFlags, allOverloadFlags: ModifierFlags): void { // Error if some overloads have a flag that is not shared by all overloads. To find the // deviations, we XOR someOverloadFlags with allOverloadFlags const someButNotAllOverloadFlags = someOverloadFlags ^ allOverloadFlags; @@ -42135,7 +42136,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - function checkQuestionTokenAgreementBetweenOverloads(overloads: Declaration[], implementation: FunctionLikeDeclaration | undefined, someHaveQuestionToken: boolean, allHaveQuestionToken: boolean): void { + function checkQuestionTokenAgreementBetweenOverloads(overloads: readonly Declaration[], implementation: FunctionLikeDeclaration | undefined, someHaveQuestionToken: boolean, allHaveQuestionToken: boolean): void { if (someHaveQuestionToken !== allHaveQuestionToken) { const canonicalHasQuestionToken = hasQuestionToken(getCanonicalOverload(overloads, implementation)); forEach(overloads, o => { @@ -45732,7 +45733,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // and properties with literal names were already checked. if (!isStatic(member) && !hasBindableName(member)) { const symbol = getSymbolOfDeclaration(member); - checkIndexConstraintForProperty(type, symbol, getTypeOfExpression((member as DynamicNamedDeclaration).name.expression), getNonMissingTypeOfSymbol(symbol)); + checkIndexConstraintForProperty(type, symbol, getTypeOfExpression((member as NamedDeclaration as DynamicNamedDeclaration).name.expression), getNonMissingTypeOfSymbol(symbol)); } } } @@ -47964,7 +47965,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - function isDuplicatedCommonJSExport(declarations: Declaration[] | undefined) { + function isDuplicatedCommonJSExport(declarations: readonly Declaration[] | undefined) { return declarations && declarations.length > 1 && declarations.every(d => isInJSFile(d) && isAccessExpression(d) && (isExportsIdentifier(d.expression) || isModuleExportsAccessExpression(d.expression))); @@ -48982,8 +48983,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } else { const copy = createSymbol(SymbolFlags.Signature, InternalSymbolName.Index); - copy.declarations = mapDefined(infos, i => i.declaration); - copy.parent = type.aliasSymbol ? type.aliasSymbol : type.symbol ? type.symbol : getSymbolAtLocation(copy.declarations[0].parent); + copy.astDeclarations = mapDefined(infos, i => i.declaration?.ast); + copy.parent = type.aliasSymbol ? type.aliasSymbol : type.symbol ? type.symbol : getSymbolAtLocation(copy.astDeclarations[0].parent.node); symbolLinks.filteredIndexSymbolCache.set(nodeListId, copy); return copy; } @@ -50133,7 +50134,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return true; } return false; - }); + })?.slice(); } } } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ef83fefd533e0..565e875fe8fff 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -10,6 +10,7 @@ import { SortedReadonlyArray, TextSpan, } from "./_namespaces/ts.js"; +import { ReadonlyArrayView } from "./readonlyArray.js"; /* eslint-disable @typescript-eslint/prefer-for-of */ @@ -1749,7 +1750,7 @@ export function createSet(getHashCode: (element: TElem */ export function isArray(value: any): value is readonly unknown[] { // See: https://github.com/microsoft/TypeScript/issues/17002 - return Array.isArray(value); + return Array.isArray(value) || ReadonlyArrayView.isReadonlyArrayView(value); } /** @internal */ @@ -2591,3 +2592,8 @@ export function isNodeLikeSystem(): boolean { && !(process as any).browser && typeof require !== "undefined"; } + +/** @internal */ +export function createReadOnlyArrayView(source: readonly T[], mapper: (value: T) => U): readonly U[] { + return new ReadonlyArrayView(source, mapper); +} \ No newline at end of file diff --git a/src/compiler/debug.ts b/src/compiler/debug.ts index d4c818a6c0cc0..b7d37321a6b28 100644 --- a/src/compiler/debug.ts +++ b/src/compiler/debug.ts @@ -233,6 +233,8 @@ export namespace Debug { return fail(`${message} ${detail}`, stackCrawlMark || assertNever); } + export function assertNeverTypeOnly(_: never): void {} + export function assertEachNode(nodes: NodeArray, test: (node: T) => node is U, message?: string, stackCrawlMark?: AnyFunction): asserts nodes is NodeArray; export function assertEachNode(nodes: readonly T[], test: (node: T) => node is U, message?: string, stackCrawlMark?: AnyFunction): asserts nodes is readonly U[]; export function assertEachNode(nodes: NodeArray | undefined, test: (node: T) => node is U, message?: string, stackCrawlMark?: AnyFunction): asserts nodes is NodeArray | undefined; diff --git a/src/compiler/factory/astNodeFactory.ts b/src/compiler/factory/astNodeFactory.ts index 6a532abf9604a..d84b8fdfa8424 100644 --- a/src/compiler/factory/astNodeFactory.ts +++ b/src/compiler/factory/astNodeFactory.ts @@ -293,22 +293,21 @@ import { getSyntheticLeadingComments, getSyntheticTrailingComments, identity, - isAstBinaryExpression, - isAstCallChain, - isAstCommaListExpression, - isAstCommaToken, - isAstElementAccessChain, - isAstExclamationToken, - isAstIdentifier, - isAstNonNullChain, - isAstNotEmittedStatement, - isAstOmittedExpression, - isAstOuterExpression, - isAstParenthesizedExpression, - isAstPrivateIdentifier, - isAstPropertyAccessChain, - isAstQuestionToken, - isAstVariableDeclaration, + astIsBinaryExpression, + astIsCallChain, + astIsCommaListExpression, + astIsCommaToken, + astIsElementAccessChain, + astIsExclamationToken, + astIsIdentifier, + astIsNonNullChain, + astIsNotEmittedStatement, + astIsOmittedExpression, + astIsParenthesizedExpression, + astIsPrivateIdentifier, + astIsPropertyAccessChain, + astIsQuestionToken, + astIsVariableDeclaration, isParseTreeNode, KeywordSyntaxKind, KeywordTypeSyntaxKind, @@ -347,6 +346,11 @@ import { TokenSyntaxKind, TransformFlags, Type, + astIsOuterExpression, + astNodeIsSynthesized, + astSetComment, + astGetComment, + AstHasComment, } from "../_namespaces/ts.js"; /** @internal */ @@ -2006,8 +2010,8 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no const node = AstNode.PropertyDeclaration(); node.data.modifiers = asNodeArray(modifiers); node.data.name = asName(name); - node.data.questionToken = questionOrExclamationToken && isAstQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined; - node.data.exclamationToken = questionOrExclamationToken && isAstExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined; + node.data.questionToken = questionOrExclamationToken && astIsQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined; + node.data.exclamationToken = questionOrExclamationToken && astIsExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined; node.data.type = type; node.data.initializer = asInitializer(initializer); return finish(node); @@ -2024,8 +2028,8 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no ) { return !sameNodeArray(node.data.modifiers, modifiers) || node.data.name !== name - || node.data.questionToken !== (questionOrExclamationToken !== undefined && isAstQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined) - || node.data.exclamationToken !== (questionOrExclamationToken !== undefined && isAstExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined) + || node.data.questionToken !== (questionOrExclamationToken !== undefined && astIsQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined) + || node.data.exclamationToken !== (questionOrExclamationToken !== undefined && astIsExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined) || node.data.type !== type || node.data.initializer !== initializer ? update(createPropertyDeclaration(modifiers, name, questionOrExclamationToken, type, initializer), node) @@ -2856,7 +2860,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no // we end up with `[1, 2, ,]` instead of `[1, 2, ]` otherwise the `OmittedExpression` will just end up being treated like // a trailing comma. const lastElement = elements && lastOrUndefined(arrayItems(elements)); - const elementsArray = createNodeArray(elements, lastElement && isAstOmittedExpression(lastElement) ? true : undefined); + const elementsArray = createNodeArray(elements, lastElement && astIsOmittedExpression(lastElement) ? true : undefined); node.data.elements = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(elementsArray); node.data.multiLine = multiLine; return finish(node); @@ -2902,8 +2906,8 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no // @api function updatePropertyAccessExpression(node: AstPropertyAccessExpression, expression: AstExpression, name: AstIdentifier | AstPrivateIdentifier) { - if (isAstPropertyAccessChain(node)) { - return updatePropertyAccessChain(node, expression, node.data.questionDotToken, cast(name, isAstIdentifier)); + if (astIsPropertyAccessChain(node)) { + return updatePropertyAccessChain(node, expression, node.data.questionDotToken, cast(name, astIsIdentifier)); } return node.data.expression !== expression || node.data.name !== name @@ -2950,7 +2954,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no // @api function updateElementAccessExpression(node: AstElementAccessExpression, expression: AstExpression, argumentExpression: AstExpression) { - if (isAstElementAccessChain(node)) { + if (astIsElementAccessChain(node)) { return updateElementAccessChain(node, expression, node.data.questionDotToken, argumentExpression); } return node.data.expression !== expression @@ -2990,7 +2994,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no // @api function updateCallExpression(node: AstCallExpression, expression: AstExpression, typeArguments: AstNodeArrayLike | undefined, argumentsArray: AstNodeArrayLike) { - if (isAstCallChain(node)) { + if (astIsCallChain(node)) { return updateCallChain(node, expression, node.data.questionDotToken, typeArguments, argumentsArray); } return node.data.expression !== expression @@ -3528,7 +3532,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no // @api function updateNonNullExpression(node: AstNonNullExpression, expression: AstExpression) { - if (isAstNonNullChain(node)) { + if (astIsNonNullChain(node)) { return updateNonNullChain(node, expression); } return node.data.expression !== expression @@ -4695,7 +4699,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function createJSDocTemplateTag(tagName: AstIdentifier | undefined, constraint: AstJSDocTypeExpression | undefined, typeParameters: AstNodeArrayLike, comment?: string | AstNodeArray): AstJSDocTemplateTag { const node = AstNode.JSDocTemplateTag(); node.data.tagName = tagName ?? createIdentifier("template"); - node.data.comment = comment; + astSetComment(node, comment); node.data.constraint = constraint; node.data.typeParameters = createNodeArray(typeParameters); return finish(node); @@ -4706,7 +4710,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no return node.data.tagName !== tagName || node.data.constraint !== constraint || !sameNodeArray(node.data.typeParameters, typeParameters) - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocTemplateTag(tagName, constraint, typeParameters, comment), node) : node; } @@ -4715,7 +4719,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function createJSDocTypedefTag(tagName: AstIdentifier | undefined, typeExpression?: AstJSDocTypeExpression, fullName?: AstIdentifier | AstJSDocNamespaceDeclaration, comment?: string | AstNodeArray): AstJSDocTypedefTag { const node = AstNode.JSDocTypedefTag(); node.data.tagName = tagName ?? createIdentifier("typedef"); - node.data.comment = comment; + astSetComment(node, comment); node.data.typeExpression = typeExpression; node.data.fullName = fullName; node.data.name = getJSDocTypeAliasName(fullName); @@ -4727,7 +4731,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no return node.data.tagName !== tagName || node.data.typeExpression !== typeExpression || node.data.fullName !== fullName - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocTypedefTag(tagName, typeExpression, fullName, comment), node) : node; } @@ -4736,7 +4740,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function createJSDocParameterTag(tagName: AstIdentifier | undefined, name: AstEntityName, isBracketed: boolean, typeExpression?: AstJSDocTypeExpression, isNameFirst?: boolean, comment?: string | AstNodeArray): AstJSDocParameterTag { const node = AstNode.JSDocParameterTag(); node.data.tagName = tagName ?? createIdentifier("param"); - node.data.comment = comment; + astSetComment(node, comment); node.data.typeExpression = typeExpression; node.data.name = name; node.data.isNameFirst = !!isNameFirst; @@ -4751,7 +4755,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no || node.data.isBracketed !== isBracketed || node.data.typeExpression !== typeExpression || node.data.isNameFirst !== isNameFirst - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocParameterTag(tagName, name, isBracketed, typeExpression, isNameFirst, comment), node) : node; } @@ -4760,7 +4764,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function createJSDocPropertyTag(tagName: AstIdentifier | undefined, name: AstEntityName, isBracketed: boolean, typeExpression?: AstJSDocTypeExpression, isNameFirst?: boolean, comment?: string | AstNodeArray): AstJSDocPropertyTag { const node = AstNode.JSDocPropertyTag(); node.data.tagName = tagName ?? createIdentifier("prop"); - node.data.comment = comment; + astSetComment(node, comment); node.data.typeExpression = typeExpression; node.data.name = name; node.data.isNameFirst = !!isNameFirst; @@ -4775,7 +4779,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no || node.data.isBracketed !== isBracketed || node.data.typeExpression !== typeExpression || node.data.isNameFirst !== isNameFirst - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocPropertyTag(tagName, name, isBracketed, typeExpression, isNameFirst, comment), node) : node; } @@ -4784,7 +4788,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function createJSDocCallbackTag(tagName: AstIdentifier | undefined, typeExpression: AstJSDocSignature, fullName?: AstIdentifier | AstJSDocNamespaceDeclaration, comment?: string | AstNodeArray): AstJSDocCallbackTag { const node = AstNode.JSDocCallbackTag(); node.data.tagName = tagName ?? createIdentifier("callback"); - node.data.comment = comment; + astSetComment(node, comment); node.data.typeExpression = typeExpression; node.data.fullName = fullName; node.data.name = getJSDocTypeAliasName(fullName); @@ -4799,7 +4803,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no return node.data.tagName !== tagName || node.data.typeExpression !== typeExpression || node.data.fullName !== fullName - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocCallbackTag(tagName, typeExpression, fullName, comment), node) : node; } @@ -4808,7 +4812,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function createJSDocOverloadTag(tagName: AstIdentifier | undefined, typeExpression: AstJSDocSignature, comment?: string | AstNodeArray): AstJSDocOverloadTag { const node = AstNode.JSDocOverloadTag(); node.data.tagName = tagName ?? createIdentifier("overload"); - node.data.comment = comment; + astSetComment(node, comment); node.data.typeExpression = typeExpression; return finish(node); } @@ -4817,7 +4821,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function updateJSDocOverloadTag(node: AstJSDocOverloadTag, tagName: AstIdentifier = getDefaultTagName(node), typeExpression: AstJSDocSignature, comment: string | AstNodeArray | undefined): AstJSDocOverloadTag { return node.data.tagName !== tagName || node.data.typeExpression !== typeExpression - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocOverloadTag(tagName, typeExpression, comment), node) : node; } @@ -4826,7 +4830,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function createJSDocAugmentsTag(tagName: AstIdentifier | undefined, className: AstJSDocAugmentsTag["data"]["class"], comment?: string | AstNodeArray): AstJSDocAugmentsTag { const node = AstNode.JSDocAugmentsTag(); node.data.tagName = tagName ?? createIdentifier("augments"); - node.data.comment = comment; + astSetComment(node, comment); node.data.class = className; return finish(node); } @@ -4835,7 +4839,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function updateJSDocAugmentsTag(node: AstJSDocAugmentsTag, tagName: AstIdentifier = getDefaultTagName(node), className: AstJSDocAugmentsTag["data"]["class"], comment: string | AstNodeArray | undefined): AstJSDocAugmentsTag { return node.data.tagName !== tagName || node.data.class !== className - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocAugmentsTag(tagName, className, comment), node) : node; } @@ -4844,7 +4848,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function createJSDocImplementsTag(tagName: AstIdentifier | undefined, className: AstJSDocImplementsTag["data"]["class"], comment?: string | AstNodeArray): AstJSDocImplementsTag { const node = AstNode.JSDocImplementsTag(); node.data.tagName = tagName ?? createIdentifier("implements"); - node.data.comment = comment; + astSetComment(node, comment); node.data.class = className; return finish(node); } @@ -4853,7 +4857,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function createJSDocSeeTag(tagName: AstIdentifier | undefined, name: AstJSDocNameReference | undefined, comment?: string | AstNodeArray): AstJSDocSeeTag { const node = AstNode.JSDocSeeTag(); node.data.tagName = tagName ?? createIdentifier("see"); - node.data.comment = comment; + astSetComment(node, comment); node.data.name = name; return finish(node); } @@ -4862,7 +4866,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function updateJSDocSeeTag(node: AstJSDocSeeTag, tagName: AstIdentifier | undefined, name: AstJSDocNameReference | undefined, comment?: string | AstNodeArray): AstJSDocSeeTag { return node.data.tagName !== tagName || node.data.name !== name - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocSeeTag(tagName, name, comment), node) : node; } @@ -4946,7 +4950,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function updateJSDocImplementsTag(node: AstJSDocImplementsTag, tagName: AstIdentifier = getDefaultTagName(node), className: AstJSDocImplementsTag["data"]["class"], comment: string | AstNodeArray | undefined): AstJSDocImplementsTag { return node.data.tagName !== tagName || node.data.class !== className - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocImplementsTag(tagName, className, comment), node) : node; } @@ -4962,7 +4966,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function createJSDocSimpleTag(makeTag: () => T, tagName: AstIdentifier | undefined, comment?: string | AstNodeArray) { const node = makeTag(); node.data.tagName = tagName ?? createIdentifier(getDefaultTagNameForKind(node.kind)); - node.data.comment = comment; + astSetComment(node as AstHasComment, comment); return finish(node); } @@ -4976,7 +4980,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no // updateJSDocDeprecatedTag function updateJSDocSimpleTag(makeTag: () => T, node: T, tagName: AstIdentifier = getDefaultTagName(node), comment: string | AstNodeArray | undefined) { return node.data.tagName !== tagName - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocSimpleTag(makeTag, tagName, comment), node) : node; } @@ -5002,7 +5006,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function updateJSDocTypeLikeTag(makeTag: () => T, node: T, tagName: AstIdentifier = getDefaultTagName(node), typeExpression: AstJSDocTypeExpression | undefined, comment: string | AstNodeArray | undefined) { return node.data.tagName !== tagName || node.data.typeExpression !== typeExpression - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocTypeLikeTag(makeTag, tagName, typeExpression, comment), node) : node; } @@ -5016,7 +5020,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no // @api function updateJSDocUnknownTag(node: AstJSDocUnknownTag, tagName: AstIdentifier, comment: string | AstNodeArray | undefined): AstJSDocUnknownTag { return node.data.tagName !== tagName - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocUnknownTag(tagName, comment), node) : node; } @@ -5032,7 +5036,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function updateJSDocEnumTag(node: AstJSDocEnumTag, tagName: AstIdentifier = getDefaultTagName(node), typeExpression: AstJSDocTypeExpression, comment: string | AstNodeArray | undefined) { return node.data.tagName !== tagName || node.data.typeExpression !== typeExpression - || node.data.comment !== comment + || astGetComment(node) !== comment ? update(createJSDocEnumTag(tagName, typeExpression, comment), node) : node; } @@ -5041,17 +5045,17 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function createJSDocImportTag(tagName: AstIdentifier | undefined, importClause: AstImportClause | undefined, moduleSpecifier: AstExpression, attributes?: AstImportAttributes, comment?: string | AstNodeArray): AstJSDocImportTag { const node = AstNode.JSDocImportTag(); node.data.tagName = tagName ?? createIdentifier("import"); - node.data.comment = comment; + astSetComment(node, comment); node.data.importClause = importClause; node.data.moduleSpecifier = moduleSpecifier; node.data.attributes = attributes; - node.data.comment = comment; + astSetComment(node, comment); return finish(node); } function updateJSDocImportTag(node: AstJSDocImportTag, tagName: AstIdentifier | undefined, importClause: AstImportClause | undefined, moduleSpecifier: AstExpression, attributes: AstImportAttributes | undefined, comment: string | AstNodeArray | undefined): AstJSDocImportTag { return node.data.tagName !== tagName - || node.data.comment !== comment + || astGetComment(node) !== comment || node.data.importClause !== importClause || node.data.moduleSpecifier !== moduleSpecifier || node.data.attributes !== attributes @@ -5076,14 +5080,14 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no // @api function createJSDocComment(comment?: string | AstNodeArray | undefined, tags?: AstNodeArrayLike | undefined) { const node = AstNode.JSDocNode(); - node.data.comment = comment; + astSetComment(node, comment); node.data.tags = asNodeArray(tags); return finish(node); } // @api function updateJSDocComment(node: AstJSDoc, comment: string | AstNodeArray | undefined, tags: AstNodeArrayLike | undefined) { - return node.data.comment !== comment + return astGetComment(node) !== comment || !sameNodeArray(node.data.tags, tags) ? update(createJSDocComment(comment, tags), node) : node; @@ -5588,11 +5592,11 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no } function flattenCommaElements(node: AstExpression): AstExpression | readonly AstExpression[] { - if (nodeIsSynthesized(node) && !isParseTreeNode(node) && !node.original && !node.emitNode && !node.id) { - if (isAstCommaListExpression(node)) { + if (astNodeIsSynthesized(node) && !isParseTreeNode(node) && !node.original && !node.emitNode && !node.id) { + if (astIsCommaListExpression(node)) { return node.data.elements.items; } - if (isAstBinaryExpression(node) && isAstCommaToken(node.data.operatorToken)) { + if (astIsBinaryExpression(node) && astIsCommaToken(node.data.operatorToken)) { return [node.data.left, node.data.right]; } } @@ -5645,8 +5649,8 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no clone.emitNode = undefined; setOriginal(clone, node); - if (isAstIdentifier(node)) { - Debug.assert(isAstIdentifier(clone)); + if (astIsIdentifier(node)) { + Debug.assert(astIsIdentifier(clone)); const typeArguments = getIdentifierTypeArguments(node); if (typeArguments) setIdentifierTypeArguments(clone, typeArguments); @@ -5654,8 +5658,8 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no const autoGenerate = getIdentifierAutoGenerate(node); if (autoGenerate) setIdentifierAutoGenerate(clone, { ...autoGenerate }); } - else if (isAstPrivateIdentifier(node)) { - Debug.assert(isAstPrivateIdentifier(clone)); + else if (astIsPrivateIdentifier(node)) { + Debug.assert(astIsPrivateIdentifier(clone)); const autoGenerate = getIdentifierAutoGenerate(node); if (autoGenerate) setIdentifierAutoGenerate(clone, { ...autoGenerate }); @@ -5702,8 +5706,8 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no * the containing expression is created/updated. */ function isIgnorableParen(node: AstExpression) { - return isAstParenthesizedExpression(node) - && nodeIsSynthesized(node) + return astIsParenthesizedExpression(node) + && astNodeIsSynthesized(node) && nodeIsSynthesized(getSourceMapRange(node)) && nodeIsSynthesized(getCommentRange(node)) && !some(getSyntheticLeadingComments(node)) @@ -5711,7 +5715,7 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no } function restoreOuterExpressions(outerExpression: AstExpression | undefined, innerExpression: AstExpression, kinds = OuterExpressionKinds.All): AstExpression { - if (outerExpression && isAstOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) { + if (outerExpression && astIsOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) { return updateOuterExpression( outerExpression, restoreOuterExpressions(outerExpression.data.expression, innerExpression), @@ -5749,11 +5753,11 @@ export function createAstNodeFactory(flags: NodeFactoryFlags, onFinishNode?: (no function asEmbeddedStatement(statement: T): T | AstEmptyStatement; function asEmbeddedStatement(statement: T | undefined): T | AstEmptyStatement | undefined; function asEmbeddedStatement(statement: T | undefined): T | AstEmptyStatement | undefined { - return statement && isAstNotEmittedStatement(statement) ? setTextRange(setOriginal(createEmptyStatement(), statement), statement) : statement; + return statement && astIsNotEmittedStatement(statement) ? setTextRange(setOriginal(createEmptyStatement(), statement), statement) : statement; } function asVariableDeclaration(variableDeclaration: string | AstBindingName | AstVariableDeclaration | undefined) { - if (typeof variableDeclaration === "string" || variableDeclaration && !isAstVariableDeclaration(variableDeclaration)) { + if (typeof variableDeclaration === "string" || variableDeclaration && !astIsVariableDeclaration(variableDeclaration)) { return createVariableDeclaration( variableDeclaration, /*exclamationToken*/ undefined, @@ -5911,8 +5915,8 @@ function getJSDocTypeAliasName(fullName: AstJSDocNamespaceBody | undefined) { if (fullName) { let rightNode = fullName; while (true) { - if (isAstIdentifier(rightNode) || !rightNode.data.body) { - return isAstIdentifier(rightNode) ? rightNode : rightNode.data.name; + if (astIsIdentifier(rightNode) || !rightNode.data.body) { + return astIsIdentifier(rightNode) ? rightNode : rightNode.data.name; } rightNode = rightNode.data.body; } diff --git a/src/compiler/factory/astNodeTests.ts b/src/compiler/factory/astNodeTests.ts index 6a891f0b8b424..a67fa7d9f752e 100644 --- a/src/compiler/factory/astNodeTests.ts +++ b/src/compiler/factory/astNodeTests.ts @@ -13,9 +13,8 @@ import { AstDeclareKeyword, AstElementAccessChain, AsteriskToken, - AstHasDecorators, + AstExpression, AstHasJSDoc, - AstHasModifiers, AstLeftHandSideExpression, AstNode, AstNonNullChain, @@ -96,6 +95,7 @@ import { InferTypeNode, InterfaceDeclaration, IntersectionTypeNode, + isExpressionKind, isLeftHandSideExpressionKind, JSDoc, JSDocAllType, @@ -205,7 +205,7 @@ import { SemicolonClassElement, SetAccessorDeclaration, ShorthandPropertyAssignment, - skipAstOuterExpressions, + astSkipOuterExpressions, SourceFile, SpreadAssignment, SpreadElement, @@ -252,757 +252,757 @@ import { // Literals /** @internal */ -export function isAstNumericLiteral(node: AstNode): node is AstNode { +export function astIsNumericLiteral(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NumericLiteral; } /** @internal */ -export function isAstBigIntLiteral(node: AstNode): node is AstNode { +export function astIsBigIntLiteral(node: AstNode): node is AstNode { return node.kind === SyntaxKind.BigIntLiteral; } /** @internal */ -export function isAstStringLiteral(node: AstNode): node is AstNode { +export function astIsStringLiteral(node: AstNode): node is AstNode { return node.kind === SyntaxKind.StringLiteral; } /** @internal */ -export function isAstJsxText(node: AstNode): node is AstNode { +export function astIsJsxText(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxText; } /** @internal */ -export function isAstRegularExpressionLiteral(node: AstNode): node is AstNode { +export function astIsRegularExpressionLiteral(node: AstNode): node is AstNode { return node.kind === SyntaxKind.RegularExpressionLiteral; } /** @internal */ -export function isAstNoSubstitutionTemplateLiteral(node: AstNode): node is AstNode { +export function astIsNoSubstitutionTemplateLiteral(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NoSubstitutionTemplateLiteral; } // Pseudo-literals /** @internal */ -export function isAstTemplateHead(node: AstNode): node is AstNode { +export function astIsTemplateHead(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateHead; } /** @internal */ -export function isAstTemplateMiddle(node: AstNode): node is AstNode { +export function astIsTemplateMiddle(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateMiddle; } /** @internal */ -export function isAstTemplateTail(node: AstNode): node is AstNode { +export function astIsTemplateTail(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateTail; } // Punctuation /** @internal */ -export function isAstDotDotDotToken(node: AstNode): node is AstNode { +export function astIsDotDotDotToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.DotDotDotToken; } /** @internal */ -export function isAstCommaToken(node: AstNode): node is AstNode> { +export function astIsCommaToken(node: AstNode): node is AstNode> { return node.kind === SyntaxKind.CommaToken; } /** @internal */ -export function isAstPlusToken(node: AstNode): node is AstNode { +export function astIsPlusToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PlusToken; } /** @internal */ -export function isAstMinusToken(node: AstNode): node is AstNode { +export function astIsMinusToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.MinusToken; } /** @internal */ -export function isAstAsteriskToken(node: AstNode): node is AstNode { +export function astIsAsteriskToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AsteriskToken; } /** @internal */ -export function isAstExclamationToken(node: AstNode): node is AstNode { +export function astIsExclamationToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExclamationToken; } /** @internal */ -export function isAstQuestionToken(node: AstNode): node is AstNode { +export function astIsQuestionToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.QuestionToken; } /** @internal */ -export function isAstColonToken(node: AstNode): node is AstNode { +export function astIsColonToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ColonToken; } /** @internal */ -export function isAstQuestionDotToken(node: AstNode): node is AstNode { +export function astIsQuestionDotToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.QuestionDotToken; } /** @internal */ -export function isAstEqualsGreaterThanToken(node: AstNode): node is AstNode { +export function astIsEqualsGreaterThanToken(node: AstNode): node is AstNode { return node.kind === SyntaxKind.EqualsGreaterThanToken; } // Identifiers /** @internal */ -export function isAstIdentifier(node: AstNode): node is AstNode { +export function astIsIdentifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Identifier; } /** @internal */ -export function isAstPrivateIdentifier(node: AstNode): node is AstNode { +export function astIsPrivateIdentifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PrivateIdentifier; } // Reserved Words /** @internal */ -export function isAstExportModifier(node: AstNode): node is AstNode { +export function astIsExportModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExportKeyword; } /** @internal */ -export function isAstDefaultModifier(node: AstNode): node is AstNode { +export function astIsDefaultModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.DefaultKeyword; } /** @internal */ -export function isAstAsyncModifier(node: AstNode): node is AstNode { +export function astIsAsyncModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AsyncKeyword; } /** @internal */ -export function isAstAssertsKeyword(node: AstNode): node is AstNode { +export function astIsAssertsKeyword(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AssertsKeyword; } /** @internal */ -export function isAstAwaitKeyword(node: AstNode): node is AstNode { +export function astIsAwaitKeyword(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AwaitKeyword; } /** @internal */ -export function isAstReadonlyKeyword(node: AstNode): node is AstNode { +export function astIsReadonlyKeyword(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ReadonlyKeyword; } /** @internal */ -export function isAstStaticModifier(node: AstNode): node is AstNode { +export function astIsStaticModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.StaticKeyword; } /** @internal */ -export function isAstAbstractModifier(node: AstNode): node is AstNode { +export function astIsAbstractModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AbstractKeyword; } /** @internal */ -export function isAstOverrideModifier(node: AstNode): node is AstNode { +export function astIsOverrideModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.OverrideKeyword; } /** @internal */ -export function isAstAccessorModifier(node: AstNode): node is AstNode { +export function astIsAccessorModifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AccessorKeyword; } /** @internal */ -export function isAstSuperKeyword(node: AstNode): node is AstNode { +export function astIsSuperKeyword(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SuperKeyword; } /** @internal */ -export function isAstImportKeyword(node: AstNode): node is AstNode { +export function astIsImportKeyword(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportKeyword; } /** @internal */ -export function isAstCaseKeyword(node: AstNode): node is AstNode { +export function astIsCaseKeyword(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CaseKeyword; } /** @internal */ -export function isAstDeclareKeyword(node: AstNode): node is AstDeclareKeyword { +export function astIsDeclareKeyword(node: AstNode): node is AstDeclareKeyword { return node.kind === SyntaxKind.DeclareKeyword; } // Names /** @internal */ -export function isAstQualifiedName(node: AstNode): node is AstNode { +export function astIsQualifiedName(node: AstNode): node is AstNode { return node.kind === SyntaxKind.QualifiedName; } /** @internal */ -export function isAstComputedPropertyName(node: AstNode): node is AstNode { +export function astIsComputedPropertyName(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ComputedPropertyName; } // Signature elements /** @internal */ -export function isAstTypeParameterDeclaration(node: AstNode): node is AstNode { +export function astIsTypeParameterDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeParameter; } /** @internal */ // TODO(rbuckton): Rename to 'isParameterDeclaration' -export function isAstParameter(node: AstNode): node is AstNode { +export function astIsParameter(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Parameter; } /** @internal */ -export function isAstDecorator(node: AstNode): node is AstNode { +export function astIsDecorator(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Decorator; } // TypeMember /** @internal */ -export function isAstPropertySignature(node: AstNode): node is AstNode { +export function astIsPropertySignature(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PropertySignature; } /** @internal */ -export function isAstPropertyDeclaration(node: AstNode): node is AstNode { +export function astIsPropertyDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PropertyDeclaration; } /** @internal */ -export function isAstMethodSignature(node: AstNode): node is AstNode { +export function astIsMethodSignature(node: AstNode): node is AstNode { return node.kind === SyntaxKind.MethodSignature; } /** @internal */ -export function isAstMethodDeclaration(node: AstNode): node is AstNode { +export function astIsMethodDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.MethodDeclaration; } /** @internal */ -export function isAstClassStaticBlockDeclaration(node: AstNode): node is AstNode { +export function astIsClassStaticBlockDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ClassStaticBlockDeclaration; } /** @internal */ -export function isAstConstructorDeclaration(node: AstNode): node is AstNode { +export function astIsConstructorDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Constructor; } /** @internal */ -export function isAstGetAccessorDeclaration(node: AstNode): node is AstNode { +export function astIsGetAccessorDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.GetAccessor; } /** @internal */ -export function isAstSetAccessorDeclaration(node: AstNode): node is AstNode { +export function astIsSetAccessorDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SetAccessor; } /** @internal */ -export function isAstCallSignatureDeclaration(node: AstNode): node is AstNode { +export function astIsCallSignatureDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CallSignature; } /** @internal */ -export function isAstConstructSignatureDeclaration(node: AstNode): node is AstNode { +export function astIsConstructSignatureDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ConstructSignature; } /** @internal */ -export function isAstIndexSignatureDeclaration(node: AstNode): node is AstNode { +export function astIsIndexSignatureDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.IndexSignature; } // Type /** @internal */ -export function isAstTypePredicateNode(node: AstNode): node is AstNode { +export function astIsTypePredicateNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypePredicate; } /** @internal */ -export function isAstTypeReferenceNode(node: AstNode): node is AstNode { +export function astIsTypeReferenceNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeReference; } /** @internal */ -export function isAstFunctionTypeNode(node: AstNode): node is AstNode { +export function astIsFunctionTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.FunctionType; } /** @internal */ -export function isAstConstructorTypeNode(node: AstNode): node is AstNode { +export function astIsConstructorTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ConstructorType; } /** @internal */ -export function isAstTypeQueryNode(node: AstNode): node is AstNode { +export function astIsTypeQueryNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeQuery; } /** @internal */ -export function isAstTypeLiteralNode(node: AstNode): node is AstNode { +export function astIsTypeLiteralNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeLiteral; } /** @internal */ -export function isAstArrayTypeNode(node: AstNode): node is AstNode { +export function astIsArrayTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ArrayType; } /** @internal */ -export function isAstTupleTypeNode(node: AstNode): node is AstNode { +export function astIsTupleTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TupleType; } /** @internal */ -export function isAstNamedTupleMember(node: AstNode): node is AstNode { +export function astIsNamedTupleMember(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NamedTupleMember; } /** @internal */ -export function isAstOptionalTypeNode(node: AstNode): node is AstNode { +export function astIsOptionalTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.OptionalType; } /** @internal */ -export function isAstRestTypeNode(node: AstNode): node is AstNode { +export function astIsRestTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.RestType; } /** @internal */ -export function isAstUnionTypeNode(node: AstNode): node is AstNode { +export function astIsUnionTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.UnionType; } /** @internal */ -export function isAstIntersectionTypeNode(node: AstNode): node is AstNode { +export function astIsIntersectionTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.IntersectionType; } /** @internal */ -export function isAstConditionalTypeNode(node: AstNode): node is AstNode { +export function astIsConditionalTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ConditionalType; } /** @internal */ -export function isAstInferTypeNode(node: AstNode): node is AstNode { +export function astIsInferTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.InferType; } /** @internal */ -export function isAstParenthesizedTypeNode(node: AstNode): node is AstNode { +export function astIsParenthesizedTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ParenthesizedType; } /** @internal */ -export function isAstThisTypeNode(node: AstNode): node is AstNode { +export function astIsThisTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ThisType; } /** @internal */ -export function isAstTypeOperatorNode(node: AstNode): node is AstNode { +export function astIsTypeOperatorNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeOperator; } /** @internal */ -export function isAstIndexedAccessTypeNode(node: AstNode): node is AstNode { +export function astIsIndexedAccessTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.IndexedAccessType; } /** @internal */ -export function isAstMappedTypeNode(node: AstNode): node is AstNode { +export function astIsMappedTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.MappedType; } /** @internal */ -export function isAstLiteralTypeNode(node: AstNode): node is AstNode { +export function astIsLiteralTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.LiteralType; } /** @internal */ -export function isAstImportTypeNode(node: AstNode): node is AstNode { +export function astIsImportTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportType; } /** @internal */ -export function isAstTemplateLiteralTypeSpan(node: AstNode): node is AstNode { +export function astIsTemplateLiteralTypeSpan(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateLiteralTypeSpan; } /** @internal */ -export function isAstTemplateLiteralTypeNode(node: AstNode): node is AstNode { +export function astIsTemplateLiteralTypeNode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateLiteralType; } // Binding patterns /** @internal */ -export function isAstObjectBindingPattern(node: AstNode): node is AstNode { +export function astIsObjectBindingPattern(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ObjectBindingPattern; } /** @internal */ -export function isAstArrayBindingPattern(node: AstNode): node is AstNode { +export function astIsArrayBindingPattern(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ArrayBindingPattern; } /** @internal */ -export function isAstBindingElement(node: AstNode): node is AstNode { +export function astIsBindingElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.BindingElement; } // Expression /** @internal */ -export function isAstArrayLiteralExpression(node: AstNode): node is AstNode { +export function astIsArrayLiteralExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ArrayLiteralExpression; } /** @internal */ -export function isAstObjectLiteralExpression(node: AstNode): node is AstNode { +export function astIsObjectLiteralExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ObjectLiteralExpression; } /** @internal */ -export function isAstPropertyAccessExpression(node: AstNode): node is AstNode { +export function astIsPropertyAccessExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PropertyAccessExpression; } /** @internal */ -export function isAstElementAccessExpression(node: AstNode): node is AstNode { +export function astIsElementAccessExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ElementAccessExpression; } /** @internal */ -export function isAstCallExpression(node: AstNode): node is AstNode { +export function astIsCallExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CallExpression; } /** @internal */ -export function isAstNewExpression(node: AstNode): node is AstNode { +export function astIsNewExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NewExpression; } /** @internal */ -export function isAstTaggedTemplateExpression(node: AstNode): node is AstNode { +export function astIsTaggedTemplateExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TaggedTemplateExpression; } /** @internal */ -export function isAstTypeAssertionExpression(node: AstNode): node is AstNode { +export function astIsTypeAssertionExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeAssertionExpression; } /** @internal */ -export function isAstParenthesizedExpression(node: AstNode): node is AstNode { +export function astIsParenthesizedExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ParenthesizedExpression; } /** @internal */ -export function isAstFunctionExpression(node: AstNode): node is AstNode { +export function astIsFunctionExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.FunctionExpression; } /** @internal */ -export function isAstArrowFunction(node: AstNode): node is AstNode { +export function astIsArrowFunction(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ArrowFunction; } /** @internal */ -export function isAstDeleteExpression(node: AstNode): node is AstNode { +export function astIsDeleteExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.DeleteExpression; } /** @internal */ -export function isAstTypeOfExpression(node: AstNode): node is AstNode { +export function astIsTypeOfExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeOfExpression; } /** @internal */ -export function isAstVoidExpression(node: AstNode): node is AstNode { +export function astIsVoidExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.VoidExpression; } /** @internal */ -export function isAstAwaitExpression(node: AstNode): node is AstNode { +export function astIsAwaitExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AwaitExpression; } /** @internal */ -export function isAstPrefixUnaryExpression(node: AstNode): node is AstNode { +export function astIsPrefixUnaryExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PrefixUnaryExpression; } /** @internal */ -export function isAstPostfixUnaryExpression(node: AstNode): node is AstNode { +export function astIsPostfixUnaryExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PostfixUnaryExpression; } /** @internal */ -export function isAstBinaryExpression(node: AstNode): node is AstNode { +export function astIsBinaryExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.BinaryExpression; } /** @internal */ -export function isAstConditionalExpression(node: AstNode): node is AstNode { +export function astIsConditionalExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ConditionalExpression; } /** @internal */ -export function isAstTemplateExpression(node: AstNode): node is AstNode { +export function astIsTemplateExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateExpression; } /** @internal */ -export function isAstYieldExpression(node: AstNode): node is AstNode { +export function astIsYieldExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.YieldExpression; } /** @internal */ -export function isAstSpreadElement(node: AstNode): node is AstNode { +export function astIsSpreadElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SpreadElement; } /** @internal */ -export function isAstClassExpression(node: AstNode): node is AstNode { +export function astIsClassExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ClassExpression; } /** @internal */ -export function isAstOmittedExpression(node: AstNode): node is AstNode { +export function astIsOmittedExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.OmittedExpression; } /** @internal */ -export function isAstExpressionWithTypeArguments(node: AstNode): node is AstNode { +export function astIsExpressionWithTypeArguments(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExpressionWithTypeArguments; } /** @internal */ -export function isAstAsExpression(node: AstNode): node is AstNode { +export function astIsAsExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AsExpression; } /** @internal */ -export function isAstSatisfiesExpression(node: AstNode): node is AstNode { +export function astIsSatisfiesExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SatisfiesExpression; } /** @internal */ -export function isAstNonNullExpression(node: AstNode): node is AstNode { +export function astIsNonNullExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NonNullExpression; } /** @internal */ -export function isAstMetaProperty(node: AstNode): node is AstNode { +export function astIsMetaProperty(node: AstNode): node is AstNode { return node.kind === SyntaxKind.MetaProperty; } /** @internal */ -export function isAstSyntheticExpression(node: AstNode): node is AstNode { +export function astIsSyntheticExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SyntheticExpression; } /** @internal */ -export function isAstPartiallyEmittedExpression(node: AstNode): node is AstNode { +export function astIsPartiallyEmittedExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PartiallyEmittedExpression; } /** @internal */ -export function isAstCommaListExpression(node: AstNode): node is AstNode { +export function astIsCommaListExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CommaListExpression; } // Misc /** @internal */ -export function isAstTemplateSpan(node: AstNode): node is AstNode { +export function astIsTemplateSpan(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TemplateSpan; } /** @internal */ -export function isAstSemicolonClassElement(node: AstNode): node is AstNode { +export function astIsSemicolonClassElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SemicolonClassElement; } // Elements /** @internal */ -export function isAstBlock(node: AstNode): node is AstNode { +export function astIsBlock(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Block; } /** @internal */ -export function isAstVariableStatement(node: AstNode): node is AstNode { +export function astIsVariableStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.VariableStatement; } /** @internal */ -export function isAstEmptyStatement(node: AstNode): node is AstNode { +export function astIsEmptyStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.EmptyStatement; } /** @internal */ -export function isAstExpressionStatement(node: AstNode): node is AstNode { +export function astIsExpressionStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExpressionStatement; } /** @internal */ -export function isAstIfStatement(node: AstNode): node is AstNode { +export function astIsIfStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.IfStatement; } /** @internal */ -export function isAstDoStatement(node: AstNode): node is AstNode { +export function astIsDoStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.DoStatement; } /** @internal */ -export function isAstWhileStatement(node: AstNode): node is AstNode { +export function astIsWhileStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.WhileStatement; } /** @internal */ -export function isAstForStatement(node: AstNode): node is AstNode { +export function astIsForStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ForStatement; } /** @internal */ -export function isAstForInStatement(node: AstNode): node is AstNode { +export function astIsForInStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ForInStatement; } /** @internal */ -export function isAstForOfStatement(node: AstNode): node is AstNode { +export function astIsForOfStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ForOfStatement; } /** @internal */ -export function isAstContinueStatement(node: AstNode): node is AstNode { +export function astIsContinueStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ContinueStatement; } /** @internal */ -export function isAstBreakStatement(node: AstNode): node is AstNode { +export function astIsBreakStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.BreakStatement; } /** @internal */ -export function isAstReturnStatement(node: AstNode): node is AstNode { +export function astIsReturnStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ReturnStatement; } /** @internal */ -export function isAstWithStatement(node: AstNode): node is AstNode { +export function astIsWithStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.WithStatement; } /** @internal */ -export function isAstSwitchStatement(node: AstNode): node is AstNode { +export function astIsSwitchStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SwitchStatement; } /** @internal */ -export function isAstLabeledStatement(node: AstNode): node is AstNode { +export function astIsLabeledStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.LabeledStatement; } /** @internal */ -export function isAstThrowStatement(node: AstNode): node is AstNode { +export function astIsThrowStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ThrowStatement; } /** @internal */ -export function isAstTryStatement(node: AstNode): node is AstNode { +export function astIsTryStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TryStatement; } /** @internal */ -export function isAstDebuggerStatement(node: AstNode): node is AstNode { +export function astIsDebuggerStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.DebuggerStatement; } /** @internal */ -export function isAstVariableDeclaration(node: AstNode): node is AstNode { +export function astIsVariableDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.VariableDeclaration; } /** @internal */ -export function isAstVariableDeclarationList(node: AstNode): node is AstNode { +export function astIsVariableDeclarationList(node: AstNode): node is AstNode { return node.kind === SyntaxKind.VariableDeclarationList; } /** @internal */ -export function isAstFunctionDeclaration(node: AstNode): node is AstNode { +export function astIsFunctionDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.FunctionDeclaration; } /** @internal */ -export function isAstClassDeclaration(node: AstNode): node is AstNode { +export function astIsClassDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ClassDeclaration; } /** @internal */ -export function isAstInterfaceDeclaration(node: AstNode): node is AstNode { +export function astIsInterfaceDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.InterfaceDeclaration; } /** @internal */ -export function isAstTypeAliasDeclaration(node: AstNode): node is AstNode { +export function astIsTypeAliasDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.TypeAliasDeclaration; } /** @internal */ -export function isAstEnumDeclaration(node: AstNode): node is AstNode { +export function astIsEnumDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.EnumDeclaration; } /** @internal */ -export function isAstModuleDeclaration(node: AstNode): node is AstNode { +export function astIsModuleDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ModuleDeclaration; } /** @internal */ -export function isAstModuleBlock(node: AstNode): node is AstNode { +export function astIsModuleBlock(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ModuleBlock; } /** @internal */ -export function isAstCaseBlock(node: AstNode): node is AstNode { +export function astIsCaseBlock(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CaseBlock; } /** @internal */ -export function isAstNamespaceExportDeclaration(node: AstNode): node is AstNode { +export function astIsNamespaceExportDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NamespaceExportDeclaration; } /** @internal */ -export function isAstImportEqualsDeclaration(node: AstNode): node is AstNode { +export function astIsImportEqualsDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportEqualsDeclaration; } /** @internal */ -export function isAstImportDeclaration(node: AstNode): node is AstNode { +export function astIsImportDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportDeclaration; } /** @internal */ -export function isAstImportClause(node: AstNode): node is AstNode { +export function astIsImportClause(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportClause; } /** @internal */ -export function isAstImportTypeAssertionContainer(node: AstNode): node is AstNode { +export function astIsImportTypeAssertionContainer(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportTypeAssertionContainer; } @@ -1010,7 +1010,7 @@ export function isAstImportTypeAssertionContainer(node: AstNode): node is AstNod * @deprecated * @internal */ -export function isAstAssertClause(node: AstNode): node is AstNode { +export function astIsAssertClause(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AssertClause; } @@ -1018,203 +1018,203 @@ export function isAstAssertClause(node: AstNode): node is AstNode * @deprecated * @internal */ -export function isAstAssertEntry(node: AstNode): node is AstNode { +export function astIsAssertEntry(node: AstNode): node is AstNode { return node.kind === SyntaxKind.AssertEntry; } /** @internal */ -export function isAstImportAttributes(node: AstNode): node is AstNode { +export function astIsImportAttributes(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportAttributes; } /** @internal */ -export function isAstImportAttribute(node: AstNode): node is AstNode { +export function astIsImportAttribute(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportAttribute; } /** @internal */ -export function isAstNamespaceImport(node: AstNode): node is AstNode { +export function astIsNamespaceImport(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NamespaceImport; } /** @internal */ -export function isAstNamespaceExport(node: AstNode): node is AstNode { +export function astIsNamespaceExport(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NamespaceExport; } /** @internal */ -export function isAstNamedImports(node: AstNode): node is AstNode { +export function astIsNamedImports(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NamedImports; } /** @internal */ -export function isAstImportSpecifier(node: AstNode): node is AstNode { +export function astIsImportSpecifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ImportSpecifier; } /** @internal */ -export function isAstExportAssignment(node: AstNode): node is AstNode { +export function astIsExportAssignment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExportAssignment; } /** @internal */ -export function isAstExportDeclaration(node: AstNode): node is AstNode { +export function astIsExportDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExportDeclaration; } /** @internal */ -export function isAstNamedExports(node: AstNode): node is AstNode { +export function astIsNamedExports(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NamedExports; } /** @internal */ -export function isAstExportSpecifier(node: AstNode): node is AstNode { +export function astIsExportSpecifier(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExportSpecifier; } /** @internal */ -export function isAstModuleExportName(node: AstNode): node is AstNode { +export function astIsModuleExportName(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral; } /** @internal */ -export function isAstMissingDeclaration(node: AstNode): node is AstNode { +export function astIsMissingDeclaration(node: AstNode): node is AstNode { return node.kind === SyntaxKind.MissingDeclaration; } /** @internal */ -export function isAstNotEmittedStatement(node: AstNode): node is AstNode { +export function astIsNotEmittedStatement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.NotEmittedStatement; } /** @internal */ -export function isAstSyntheticReference(node: AstNode): node is AstNode { +export function astIsSyntheticReference(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SyntheticReferenceExpression; } // Module References /** @internal */ -export function isAstExternalModuleReference(node: AstNode): node is AstNode { +export function astIsExternalModuleReference(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ExternalModuleReference; } // JSX /** @internal */ -export function isAstJsxElement(node: AstNode): node is AstNode { +export function astIsJsxElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxElement; } /** @internal */ -export function isAstJsxSelfClosingElement(node: AstNode): node is AstNode { +export function astIsJsxSelfClosingElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxSelfClosingElement; } /** @internal */ -export function isAstJsxOpeningElement(node: AstNode): node is AstNode { +export function astIsJsxOpeningElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxOpeningElement; } /** @internal */ -export function isAstJsxClosingElement(node: AstNode): node is AstNode { +export function astIsJsxClosingElement(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxClosingElement; } /** @internal */ -export function isAstJsxFragment(node: AstNode): node is AstNode { +export function astIsJsxFragment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxFragment; } /** @internal */ -export function isAstJsxOpeningFragment(node: AstNode): node is AstNode { +export function astIsJsxOpeningFragment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxOpeningFragment; } /** @internal */ -export function isAstJsxClosingFragment(node: AstNode): node is AstNode { +export function astIsJsxClosingFragment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxClosingFragment; } /** @internal */ -export function isAstJsxAttribute(node: AstNode): node is AstNode { +export function astIsJsxAttribute(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxAttribute; } /** @internal */ -export function isAstJsxAttributes(node: AstNode): node is AstNode { +export function astIsJsxAttributes(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxAttributes; } /** @internal */ -export function isAstJsxSpreadAttribute(node: AstNode): node is AstNode { +export function astIsJsxSpreadAttribute(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxSpreadAttribute; } /** @internal */ -export function isAstJsxExpression(node: AstNode): node is AstNode { +export function astIsJsxExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxExpression; } /** @internal */ -export function isAstJsxNamespacedName(node: AstNode): node is AstNode { +export function astIsJsxNamespacedName(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JsxNamespacedName; } // Clauses /** @internal */ -export function isAstCaseClause(node: AstNode): node is AstNode { +export function astIsCaseClause(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CaseClause; } /** @internal */ -export function isAstDefaultClause(node: AstNode): node is AstNode { +export function astIsDefaultClause(node: AstNode): node is AstNode { return node.kind === SyntaxKind.DefaultClause; } /** @internal */ -export function isAstHeritageClause(node: AstNode): node is AstNode { +export function astIsHeritageClause(node: AstNode): node is AstNode { return node.kind === SyntaxKind.HeritageClause; } /** @internal */ -export function isAstCatchClause(node: AstNode): node is AstNode { +export function astIsCatchClause(node: AstNode): node is AstNode { return node.kind === SyntaxKind.CatchClause; } // Property assignments /** @internal */ -export function isAstPropertyAssignment(node: AstNode): node is AstNode { +export function astIsPropertyAssignment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.PropertyAssignment; } /** @internal */ -export function isAstShorthandPropertyAssignment(node: AstNode): node is AstNode { +export function astIsShorthandPropertyAssignment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.ShorthandPropertyAssignment; } /** @internal */ -export function isAstSpreadAssignment(node: AstNode): node is AstNode { +export function astIsSpreadAssignment(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SpreadAssignment; } // Enum /** @internal */ -export function isAstEnumMember(node: AstNode): node is AstNode { +export function astIsEnumMember(node: AstNode): node is AstNode { return node.kind === SyntaxKind.EnumMember; } /** @internal */ // Top-level nodes -export function isAstSourceFile(node: AstNode): node is AstNode { +export function astIsSourceFile(node: AstNode): node is AstNode { return node.kind === SyntaxKind.SourceFile; } /** @internal */ -export function isAstBundle(node: AstNode): node is AstNode { +export function astIsBundle(node: AstNode): node is AstNode { return node.kind === SyntaxKind.Bundle; } @@ -1223,228 +1223,228 @@ export function isAstBundle(node: AstNode): node is AstNode { // JSDoc Elements /** @internal */ -export function isAstJSDocTypeExpression(node: AstNode): node is AstNode { +export function astIsJSDocTypeExpression(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocTypeExpression; } /** @internal */ -export function isAstJSDocNameReference(node: AstNode): node is AstNode { +export function astIsJSDocNameReference(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocNameReference; } /** @internal */ -export function isAstJSDocMemberName(node: AstNode): node is AstNode { +export function astIsJSDocMemberName(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocMemberName; } /** @internal */ -export function isAstJSDocLink(node: AstNode): node is AstNode { +export function astIsJSDocLink(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocLink; } /** @internal */ -export function isAstJSDocLinkCode(node: AstNode): node is AstNode { +export function astIsJSDocLinkCode(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocLinkCode; } /** @internal */ -export function isAstJSDocLinkPlain(node: AstNode): node is AstNode { +export function astIsJSDocLinkPlain(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocLinkPlain; } /** @internal */ -export function isAstJSDocAllType(node: AstNode): node is AstNode { +export function astIsJSDocAllType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocAllType; } /** @internal */ -export function isAstJSDocUnknownType(node: AstNode): node is AstNode { +export function astIsJSDocUnknownType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocUnknownType; } /** @internal */ -export function isAstJSDocNullableType(node: AstNode): node is AstNode { +export function astIsJSDocNullableType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocNullableType; } /** @internal */ -export function isAstJSDocNonNullableType(node: AstNode): node is AstNode { +export function astIsJSDocNonNullableType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocNonNullableType; } /** @internal */ -export function isAstJSDocOptionalType(node: AstNode): node is AstNode { +export function astIsJSDocOptionalType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocOptionalType; } /** @internal */ -export function isAstJSDocFunctionType(node: AstNode): node is AstNode { +export function astIsJSDocFunctionType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocFunctionType; } /** @internal */ -export function isAstJSDocVariadicType(node: AstNode): node is AstNode { +export function astIsJSDocVariadicType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocVariadicType; } /** @internal */ -export function isAstJSDocNamepathType(node: AstNode): node is AstNode { +export function astIsJSDocNamepathType(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocNamepathType; } /** @internal */ -export function isAstJSDoc(node: AstNode): node is AstNode { +export function astIsJSDoc(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDoc; } /** @internal */ -export function isAstJSDocTypeLiteral(node: AstNode): node is AstNode { +export function astIsJSDocTypeLiteral(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocTypeLiteral; } /** @internal */ -export function isAstJSDocSignature(node: AstNode): node is AstNode { +export function astIsJSDocSignature(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocSignature; } // JSDoc Tags /** @internal */ -export function isAstJSDocAugmentsTag(node: AstNode): node is AstNode { +export function astIsJSDocAugmentsTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocAugmentsTag; } /** @internal */ -export function isAstJSDocAuthorTag(node: AstNode): node is AstNode { +export function astIsJSDocAuthorTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocAuthorTag; } /** @internal */ -export function isAstJSDocClassTag(node: AstNode): node is AstNode { +export function astIsJSDocClassTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocClassTag; } /** @internal */ -export function isAstJSDocCallbackTag(node: AstNode): node is AstNode { +export function astIsJSDocCallbackTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocCallbackTag; } /** @internal */ -export function isAstJSDocPublicTag(node: AstNode): node is AstNode { +export function astIsJSDocPublicTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocPublicTag; } /** @internal */ -export function isAstJSDocPrivateTag(node: AstNode): node is AstNode { +export function astIsJSDocPrivateTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocPrivateTag; } /** @internal */ -export function isAstJSDocProtectedTag(node: AstNode): node is AstNode { +export function astIsJSDocProtectedTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocProtectedTag; } /** @internal */ -export function isAstJSDocReadonlyTag(node: AstNode): node is AstNode { +export function astIsJSDocReadonlyTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocReadonlyTag; } /** @internal */ -export function isAstJSDocOverrideTag(node: AstNode): node is AstNode { +export function astIsJSDocOverrideTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocOverrideTag; } /** @internal */ -export function isAstJSDocOverloadTag(node: AstNode): node is AstNode { +export function astIsJSDocOverloadTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocOverloadTag; } /** @internal */ -export function isAstJSDocDeprecatedTag(node: AstNode): node is AstNode { +export function astIsJSDocDeprecatedTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocDeprecatedTag; } /** @internal */ -export function isAstJSDocSeeTag(node: AstNode): node is AstNode { +export function astIsJSDocSeeTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocSeeTag; } /** @internal */ -export function isAstJSDocEnumTag(node: AstNode): node is AstNode { +export function astIsJSDocEnumTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocEnumTag; } /** @internal */ -export function isAstJSDocParameterTag(node: AstNode): node is AstNode { +export function astIsJSDocParameterTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocParameterTag; } /** @internal */ -export function isAstJSDocReturnTag(node: AstNode): node is AstNode { +export function astIsJSDocReturnTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocReturnTag; } /** @internal */ -export function isAstJSDocThisTag(node: AstNode): node is AstNode { +export function astIsJSDocThisTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocThisTag; } /** @internal */ -export function isAstJSDocTypeTag(node: AstNode): node is AstNode { +export function astIsJSDocTypeTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocTypeTag; } /** @internal */ -export function isAstJSDocTemplateTag(node: AstNode): node is AstNode { +export function astIsJSDocTemplateTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocTemplateTag; } /** @internal */ -export function isAstJSDocTypedefTag(node: AstNode): node is AstNode { +export function astIsJSDocTypedefTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocTypedefTag; } /** @internal */ -export function isAstJSDocUnknownTag(node: AstNode): node is AstNode { +export function astIsJSDocUnknownTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocTag; } /** @internal */ -export function isAstJSDocPropertyTag(node: AstNode): node is AstNode { +export function astIsJSDocPropertyTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocPropertyTag; } /** @internal */ -export function isAstJSDocImplementsTag(node: AstNode): node is AstNode { +export function astIsJSDocImplementsTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocImplementsTag; } /** @internal */ -export function isAstJSDocSatisfiesTag(node: AstNode): node is AstNode { +export function astIsJSDocSatisfiesTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocSatisfiesTag; } /** @internal */ -export function isAstJSDocThrowsTag(node: AstNode): node is AstNode { +export function astIsJSDocThrowsTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocThrowsTag; } /** @internal */ -export function isAstJSDocImportTag(node: AstNode): node is AstNode { +export function astIsJSDocImportTag(node: AstNode): node is AstNode { return node.kind === SyntaxKind.JSDocImportTag; } // Synthesized list /** @internal */ -export function isAstSyntaxList(n: Node): n is SyntaxList { +export function astIsSyntaxList(n: Node): n is SyntaxList { return n.kind === SyntaxKind.SyntaxList; } // Unions /** @internal */ -export function isAstPropertyName(node: AstNode): node is AstPropertyName { +export function astIsPropertyName(node: AstNode): node is AstPropertyName { const kind = node.kind; return kind === SyntaxKind.Identifier || kind === SyntaxKind.PrivateIdentifier @@ -1454,27 +1454,27 @@ export function isAstPropertyName(node: AstNode): node is AstPropertyName { } /** @internal */ -export function isAstPropertyAccessChain(node: AstNode): node is AstPropertyAccessChain { - return isAstPropertyAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +export function astIsPropertyAccessChain(node: AstNode): node is AstPropertyAccessChain { + return astIsPropertyAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } /** @internal */ -export function isAstElementAccessChain(node: AstNode): node is AstElementAccessChain { - return isAstElementAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +export function astIsElementAccessChain(node: AstNode): node is AstElementAccessChain { + return astIsElementAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } /** @internal */ -export function isAstCallChain(node: AstNode): node is AstCallChain { - return isAstCallExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +export function astIsCallChain(node: AstNode): node is AstCallChain { + return astIsCallExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } /** @internal */ -export function isAstNonNullChain(node: AstNode): node is AstNonNullChain { - return isAstNonNullExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +export function astIsNonNullChain(node: AstNode): node is AstNonNullChain { + return astIsNonNullExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } /** @internal */ -export function isAstOptionalChain(node: AstNode): node is AstPropertyAccessChain | AstElementAccessChain | AstCallChain | AstNonNullChain { +export function astIsOptionalChain(node: AstNode): node is AstPropertyAccessChain | AstElementAccessChain | AstCallChain | AstNonNullChain { const kind = node.kind; return !!(node.flags & NodeFlags.OptionalChain) && (kind === SyntaxKind.PropertyAccessExpression @@ -1484,22 +1484,22 @@ export function isAstOptionalChain(node: AstNode): node is AstPropertyAccessChai } /** @internal */ -export function isAstOptionalChainRoot(node: AstNode): node is AstOptionalChainRoot { - return isAstOptionalChain(node) && !isAstNonNullExpression(node) && !!node.data.questionDotToken; +export function astIsOptionalChainRoot(node: AstNode): node is AstOptionalChainRoot { + return astIsOptionalChain(node) && !astIsNonNullExpression(node) && !!node.data.questionDotToken; } /** @internal */ -export function isAstLeftHandSideExpression(node: AstNode): node is AstLeftHandSideExpression { - return isLeftHandSideExpressionKind(skipAstOuterExpressions(node, OuterExpressionKinds.PartiallyEmittedExpressions).kind); +export function astIsLeftHandSideExpression(node: AstNode): node is AstLeftHandSideExpression { + return isLeftHandSideExpressionKind(astSkipOuterExpressions(node, OuterExpressionKinds.PartiallyEmittedExpressions).kind); } /** @internal */ -export function isAstStringOrNumericLiteralLike(node: AstNode): node is AstStringLiteralLike | AstNumericLiteral { - return isAstStringLiteralLike(node) || isAstNumericLiteral(node); +export function astIsStringOrNumericLiteralLike(node: AstNode): node is AstStringLiteralLike | AstNumericLiteral { + return astIsStringLiteralLike(node) || astIsNumericLiteral(node); } /** @internal */ -export function isAstStringLiteralLike(node: AstNode): node is AstStringLiteralLike { +export function astIsStringLiteralLike(node: AstNode): node is AstStringLiteralLike { return node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NoSubstitutionTemplateLiteral; } @@ -1516,43 +1516,6 @@ export function astHasJSDocNodes(node: AstNode): node is AstHasJSDoc { } /** @internal */ -export function astCanHaveModifiers(node: AstNode): node is AstHasModifiers { - const kind = node.kind; - return kind === SyntaxKind.TypeParameter - || kind === SyntaxKind.Parameter - || kind === SyntaxKind.PropertySignature - || kind === SyntaxKind.PropertyDeclaration - || kind === SyntaxKind.MethodSignature - || kind === SyntaxKind.MethodDeclaration - || kind === SyntaxKind.Constructor - || kind === SyntaxKind.GetAccessor - || kind === SyntaxKind.SetAccessor - || kind === SyntaxKind.IndexSignature - || kind === SyntaxKind.ConstructorType - || kind === SyntaxKind.FunctionExpression - || kind === SyntaxKind.ArrowFunction - || kind === SyntaxKind.ClassExpression - || kind === SyntaxKind.VariableStatement - || kind === SyntaxKind.FunctionDeclaration - || kind === SyntaxKind.ClassDeclaration - || kind === SyntaxKind.InterfaceDeclaration - || kind === SyntaxKind.TypeAliasDeclaration - || kind === SyntaxKind.EnumDeclaration - || kind === SyntaxKind.ModuleDeclaration - || kind === SyntaxKind.ImportEqualsDeclaration - || kind === SyntaxKind.ImportDeclaration - || kind === SyntaxKind.ExportAssignment - || kind === SyntaxKind.ExportDeclaration; -} - -/** @internal */ -export function astCanHaveDecorators(node: AstNode): node is AstHasDecorators { - const kind = node.kind; - return kind === SyntaxKind.Parameter - || kind === SyntaxKind.PropertyDeclaration - || kind === SyntaxKind.MethodDeclaration - || kind === SyntaxKind.GetAccessor - || kind === SyntaxKind.SetAccessor - || kind === SyntaxKind.ClassExpression - || kind === SyntaxKind.ClassDeclaration; +export function astIsExpression(node: AstNode): node is AstExpression { + return isExpressionKind(astSkipOuterExpressions(node, OuterExpressionKinds.PartiallyEmittedExpressions).kind); } diff --git a/src/compiler/factory/astParenthesizerRules.ts b/src/compiler/factory/astParenthesizerRules.ts index a57fd4bfdf867..7f24303422d54 100644 --- a/src/compiler/factory/astParenthesizerRules.ts +++ b/src/compiler/factory/astParenthesizerRules.ts @@ -21,21 +21,20 @@ import { AstTaggedTemplateExpression, AstTypeNode, AstUnaryExpression, - isAstBinaryExpression, - isAstBlock, - isAstCallExpression, - isAstCommaListExpression, - isAstConditionalTypeNode, - isAstConstructorTypeNode, - isAstFunctionTypeNode, - isAstInferTypeNode, - isAstIntersectionTypeNode, - isAstJSDocNullableType, - isAstNamedTupleMember, - isAstOptionalChain, - isAstTypeOperatorNode, - isAstUnionTypeNode, - skipAstOuterExpressions, + astIsBinaryExpression, + astIsBlock, + astIsCallExpression, + astIsCommaListExpression, + astIsConditionalTypeNode, + astIsConstructorTypeNode, + astIsFunctionTypeNode, + astIsInferTypeNode, + astIsIntersectionTypeNode, + astIsJSDocNullableType, + astIsNamedTupleMember, + astIsOptionalChain, + astIsTypeOperatorNode, + astIsUnionTypeNode, Associativity, BinaryOperator, compareValues, @@ -56,6 +55,7 @@ import { setTextRange, SyntaxKind, TextRange, + astSkipOuterExpressions, } from "../_namespaces/ts.js"; /** @internal */ @@ -179,7 +179,7 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth // the intended order of operations: `(a ** b) ** c` const binaryOperatorPrecedence = getOperatorPrecedence(SyntaxKind.BinaryExpression, binaryOperator); const binaryOperatorAssociativity = getOperatorAssociativity(SyntaxKind.BinaryExpression, binaryOperator); - const emittedOperand = skipAstOuterExpressions(operand, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + const emittedOperand = astSkipOuterExpressions(operand, OuterExpressionKinds.PartiallyEmittedExpressions); if (!isLeftSideOfBinary && operand.kind === SyntaxKind.ArrowFunction && binaryOperatorPrecedence > OperatorPrecedence.Assignment) { // We need to parenthesize arrow functions on the right side to avoid it being // parsed as parenthesized expression: `a && (() => {})` @@ -218,7 +218,7 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth } else { if ( - isAstBinaryExpression(emittedOperand) + astIsBinaryExpression(emittedOperand) && emittedOperand.data.operatorToken.kind === binaryOperator ) { // No need to parenthesize the right operand when the binary operator and @@ -289,13 +289,13 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth * emitted without parentheses. */ function getLiteralKindOfBinaryPlusOperand(node: AstExpression): SyntaxKind { - node = skipAstOuterExpressions(node, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + node = astSkipOuterExpressions(node, OuterExpressionKinds.PartiallyEmittedExpressions); if (isLiteralKind(node.kind)) { return node.kind; } - if (isAstBinaryExpression(node) && (node as AstBinaryExpression).data.operatorToken.kind === SyntaxKind.PlusToken) { + if (astIsBinaryExpression(node) && (node as AstBinaryExpression).data.operatorToken.kind === SyntaxKind.PlusToken) { if (node.data.cachedLiteralKind !== undefined) { return node.data.cachedLiteralKind; } @@ -323,7 +323,7 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth * BinaryExpression. */ function parenthesizeBinaryOperand(binaryOperator: SyntaxKind, operand: AstExpression, isLeftSideOfBinary: boolean, leftOperand?: AstExpression) { - const skipped = skipAstOuterExpressions(operand, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + const skipped = astSkipOuterExpressions(operand, OuterExpressionKinds.PartiallyEmittedExpressions); // If the resulting expression is already parenthesized, we do not need to do any further processing. if (skipped.kind === SyntaxKind.ParenthesizedExpression) { @@ -349,7 +349,7 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth function parenthesizeConditionOfConditionalExpression(condition: AstExpression): AstExpression { const conditionalPrecedence = getOperatorPrecedence(SyntaxKind.ConditionalExpression, SyntaxKind.QuestionToken); - const emittedCondition = skipAstOuterExpressions(condition, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + const emittedCondition = astSkipOuterExpressions(condition, OuterExpressionKinds.PartiallyEmittedExpressions); const conditionPrecedence = getExpressionPrecedence(emittedCondition); if (compareValues(conditionPrecedence, conditionalPrecedence) !== Comparison.GreaterThan) { return factory.createParenthesizedExpression(condition); @@ -358,14 +358,14 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth } function isCommaSequence(expression: AstExpression): boolean { - return isAstCommaListExpression(expression) || isAstBinaryExpression(expression) && expression.node.data.operatorToken.kind === SyntaxKind.CommaToken; + return astIsCommaListExpression(expression) || astIsBinaryExpression(expression) && expression.node.data.operatorToken.kind === SyntaxKind.CommaToken; } function parenthesizeBranchOfConditionalExpression(branch: AstExpression): AstExpression { // per ES grammar both 'whenTrue' and 'whenFalse' parts of conditional expression are assignment expressions // so in case when comma expression is introduced as a part of previous transformations // if should be wrapped in parens since comma operator has the lowest precedence - const emittedExpression = skipAstOuterExpressions(branch, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + const emittedExpression = astSkipOuterExpressions(branch, OuterExpressionKinds.PartiallyEmittedExpressions); return isCommaSequence(emittedExpression) ? factory.createParenthesizedExpression(branch) : branch; @@ -383,7 +383,7 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth * - ClassExpression */ function parenthesizeExpressionOfExportDefault(expression: AstExpression): AstExpression { - const check = skipAstOuterExpressions(expression, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + const check = astSkipOuterExpressions(expression, OuterExpressionKinds.PartiallyEmittedExpressions); let needsParens = isCommaSequence(check); if (!needsParens) { switch (getLeftmostExpression(check, /*stopAtCallExpressions*/ false).kind) { @@ -425,11 +425,11 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth // NewExpression: // new C.x -> not the same as (new C).x // - const emittedExpression = skipAstOuterExpressions(expression, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + const emittedExpression = astSkipOuterExpressions(expression, OuterExpressionKinds.PartiallyEmittedExpressions); if ( - isLeftHandSideExpressionKind(skipAstOuterExpressions(emittedExpression, OuterExpressionKinds.PartiallyEmittedExpressions).kind) + isLeftHandSideExpressionKind(astSkipOuterExpressions(emittedExpression, OuterExpressionKinds.PartiallyEmittedExpressions).kind) && (emittedExpression.kind !== SyntaxKind.NewExpression || (emittedExpression as AstNewExpression).data.arguments) - && (optionalChain || !isAstOptionalChain(emittedExpression)) + && (optionalChain || !astIsOptionalChain(emittedExpression)) ) { // TODO(rbuckton): Verify whether this assertion holds. return expression as AstLeftHandSideExpression; @@ -441,12 +441,12 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth function parenthesizeOperandOfPostfixUnary(operand: AstExpression): AstLeftHandSideExpression { // TODO(rbuckton): Verifiy whether `setTextRange` is needed. - return isLeftHandSideExpressionKind(skipAstOuterExpressions(operand, OuterExpressionKinds.PartiallyEmittedExpressions).kind) ? operand as AstLeftHandSideExpression : setTextRange(factory.createParenthesizedExpression(operand), operand); + return isLeftHandSideExpressionKind(astSkipOuterExpressions(operand, OuterExpressionKinds.PartiallyEmittedExpressions).kind) ? operand as AstLeftHandSideExpression : setTextRange(factory.createParenthesizedExpression(operand), operand); } function parenthesizeOperandOfPrefixUnary(operand: AstExpression): AstUnaryExpression { // TODO(rbuckton): Verifiy whether `setTextRange` is needed. - return isUnaryExpressionKind(skipAstOuterExpressions(operand, OuterExpressionKinds.PartiallyEmittedExpressions).kind) ? operand as AstUnaryExpression : setTextRange(factory.createParenthesizedExpression(operand), operand); + return isUnaryExpressionKind(astSkipOuterExpressions(operand, OuterExpressionKinds.PartiallyEmittedExpressions).kind) ? operand as AstUnaryExpression : setTextRange(factory.createParenthesizedExpression(operand), operand); } function parenthesizeExpressionsOfCommaDelimitedList(elements: AstNodeArrayLike): AstNodeArray { @@ -466,7 +466,7 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth } function parenthesizeExpressionForDisallowedComma(expression: AstExpression): AstExpression { - const emittedExpression = skipAstOuterExpressions(expression, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; + const emittedExpression = astSkipOuterExpressions(expression, OuterExpressionKinds.PartiallyEmittedExpressions); const expressionPrecedence = getExpressionPrecedence(emittedExpression); const commaPrecedence = getOperatorPrecedence(SyntaxKind.BinaryExpression, SyntaxKind.CommaToken); // TODO(rbuckton): Verifiy whether `setTextRange` is needed. @@ -474,10 +474,10 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth } function parenthesizeExpressionOfExpressionStatement(expression: AstExpression): AstExpression { - const emittedExpression = skipAstOuterExpressions(expression, OuterExpressionKinds.PartiallyEmittedExpressions) as AstExpression; - if (isAstCallExpression(emittedExpression)) { + const emittedExpression = astSkipOuterExpressions(expression, OuterExpressionKinds.PartiallyEmittedExpressions); + if (astIsCallExpression(emittedExpression)) { const callee = emittedExpression.data.expression; - const kind = skipAstOuterExpressions(callee, OuterExpressionKinds.PartiallyEmittedExpressions).kind; + const kind = astSkipOuterExpressions(callee, OuterExpressionKinds.PartiallyEmittedExpressions).kind; if (kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction) { // TODO(rbuckton): Verifiy whether `setTextRange` is needed. const updated = factory.updateCallExpression( @@ -502,7 +502,7 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth function parenthesizeConciseBodyOfArrowFunction(body: AstExpression): AstExpression; function parenthesizeConciseBodyOfArrowFunction(body: AstConciseBody): AstConciseBody; function parenthesizeConciseBodyOfArrowFunction(body: AstConciseBody): AstConciseBody { - if (!isAstBlock(body) && (isCommaSequence(body) || getLeftmostExpression(body, /*stopAtCallExpressions*/ false).kind === SyntaxKind.ObjectLiteralExpression)) { + if (!astIsBlock(body) && (isCommaSequence(body) || getLeftmostExpression(body, /*stopAtCallExpressions*/ false).kind === SyntaxKind.ObjectLiteralExpression)) { // TODO(rbuckton): Verifiy whether `setTextRange` is needed. return setTextRange(factory.createParenthesizedExpression(body), body); } @@ -660,13 +660,13 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth } function hasJSDocPostfixQuestion(type: AstTypeNode | AstNamedTupleMember): boolean { - if (isAstJSDocNullableType(type)) return type.data.postfix; - if (isAstNamedTupleMember(type)) return hasJSDocPostfixQuestion(type.data.type); - if (isAstFunctionTypeNode(type) || isAstConstructorTypeNode(type) || isAstTypeOperatorNode(type)) return hasJSDocPostfixQuestion(type.data.type); - if (isAstConditionalTypeNode(type)) return hasJSDocPostfixQuestion(type.data.falseType); - if (isAstUnionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types.items)); - if (isAstIntersectionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types.items)); - if (isAstInferTypeNode(type)) return !!type.data.typeParameter.data.constraint && hasJSDocPostfixQuestion(type.data.typeParameter.data.constraint); + if (astIsJSDocNullableType(type)) return type.data.postfix; + if (astIsNamedTupleMember(type)) return hasJSDocPostfixQuestion(type.data.type); + if (astIsFunctionTypeNode(type) || astIsConstructorTypeNode(type) || astIsTypeOperatorNode(type)) return hasJSDocPostfixQuestion(type.data.type); + if (astIsConditionalTypeNode(type)) return hasJSDocPostfixQuestion(type.data.falseType); + if (astIsUnionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types.items)); + if (astIsIntersectionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.data.types.items)); + if (astIsInferTypeNode(type)) return !!type.data.typeParameter.data.constraint && hasJSDocPostfixQuestion(type.data.typeParameter.data.constraint); return false; } @@ -697,7 +697,7 @@ export function createAstParenthesizerRules(factory: AstNodeFactory): AstParenth // } function parenthesizeLeadingTypeArgument(node: AstTypeNode) { - return (isAstFunctionTypeNode(node) || isAstConstructorTypeNode(node)) && node.data.typeParameters ? factory.createParenthesizedType(node) : node; + return (astIsFunctionTypeNode(node) || astIsConstructorTypeNode(node)) && node.data.typeParameters ? factory.createParenthesizedType(node) : node; } function parenthesizeOrdinalTypeArgument(node: AstTypeNode, i: number) { diff --git a/src/compiler/factory/nodeTests.ts b/src/compiler/factory/nodeTests.ts index ba20a858f5bf3..98b2a49c3ed64 100644 --- a/src/compiler/factory/nodeTests.ts +++ b/src/compiler/factory/nodeTests.ts @@ -289,7 +289,7 @@ export function isMinusToken(node: Node): node is MinusToken { return node.kind === SyntaxKind.MinusToken; } -export function isAsteriskToken(node: Node): node is AsteriskToken { +export function astIseriskToken(node: Node): node is AsteriskToken { return node.kind === SyntaxKind.AsteriskToken; } diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index 43d7bfa0178fb..d4ce2c4a71c56 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -8,6 +8,11 @@ import { AssignmentExpression, AssignmentOperatorOrHigher, AssignmentPattern, + AstExpression, + astIsJSDocTypeAssertion, + AstNode, + AstOuterExpression, + AstWrappedExpression, BinaryExpression, BinaryOperator, BinaryOperatorToken, @@ -628,9 +633,14 @@ export function getJSDocTypeAssertionType(node: JSDocTypeAssertion): TypeNode { /** @internal */ export function isOuterExpression(node: Node, kinds: OuterExpressionKinds = OuterExpressionKinds.All): node is OuterExpression { + return astIsOuterExpression(node.ast, kinds); +} + +/** @internal */ +export function astIsOuterExpression(node: AstNode, kinds: OuterExpressionKinds = OuterExpressionKinds.All): node is AstOuterExpression { switch (node.kind) { case SyntaxKind.ParenthesizedExpression: - if (kinds & OuterExpressionKinds.ExcludeJSDocTypeAssertion && isJSDocTypeAssertion(node)) { + if (kinds & OuterExpressionKinds.ExcludeJSDocTypeAssertion && astIsJSDocTypeAssertion(node)) { return false; } return (kinds & OuterExpressionKinds.Parentheses) !== 0; @@ -656,8 +666,19 @@ export function skipOuterExpressions(node: Expression, kinds?: OuterExpressionKi export function skipOuterExpressions(node: Node, kinds?: OuterExpressionKinds): Node; /** @internal */ export function skipOuterExpressions(node: Node, kinds = OuterExpressionKinds.All) { - while (isOuterExpression(node, kinds)) { - node = node.expression; + return astSkipOuterExpressions(node.ast, kinds).node; +} + +/** @internal */ +export function astSkipOuterExpressions(node: AstWrappedExpression): T; +/** @internal */ +export function astSkipOuterExpressions(node: AstExpression, kinds?: OuterExpressionKinds): AstExpression; +/** @internal */ +export function astSkipOuterExpressions(node: AstNode, kinds?: OuterExpressionKinds): AstNode; +/** @internal */ +export function astSkipOuterExpressions(node: AstNode, kinds: OuterExpressionKinds = OuterExpressionKinds.All): AstNode { + while (astIsOuterExpression(node, kinds)) { + node = node.data.expression; } return node; } diff --git a/src/compiler/nodes.ts b/src/compiler/nodes.ts index 9e2a506f06b31..3cdeacfdeca6e 100644 --- a/src/compiler/nodes.ts +++ b/src/compiler/nodes.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import { ArrayBindingPattern, ArrayLiteralExpression, @@ -52,13 +53,35 @@ import { FunctionExpression, FunctionTypeNode, GetAccessorDeclaration, + HasAsteriskToken, + HasBody, + HasComment, + HasElements, + HasEndFlowNode, + HasExclamationToken, + HasExpression, + HasInitializer, + HasIsTypeOnly, HasJSDoc, HasLocals, + HasMembers, HasName, + HasParameters, + HasQuestionDotToken, + HasQuestionToken, + HasStatement, + HasStatements, + HasSymbol, + HasTagName, + HasText, + HasType, + HasTypeParameters, + HasTypes, HeritageClause, Identifier, IfStatement, ImportAttribute, + ImportAttributes, ImportClause, ImportDeclaration, ImportEqualsDeclaration, @@ -70,6 +93,7 @@ import { IndexSignatureDeclaration, InferTypeNode, InterfaceDeclaration, + InternalHasTypeArguments, IntersectionTypeNode, IsFunctionLike, JSDoc, @@ -144,6 +168,7 @@ import { NamespaceExportDeclaration, NamespaceImport, NewExpression, + Node, NonNullExpression, NoSubstitutionTemplateLiteral, NotEmittedStatement, @@ -213,7 +238,6 @@ import { } from "./_namespaces/ts.js"; { - // eslint-disable-next-line @typescript-eslint/naming-convention type _ = [ __Expect>, __Expect, IsFunctionLike>, @@ -221,7 +245,6 @@ import { } { - // eslint-disable-next-line @typescript-eslint/naming-convention type _ = [ __Expect>, __Expect, HasLocals>, @@ -229,7 +252,6 @@ import { } { - // eslint-disable-next-line @typescript-eslint/naming-convention type _ = [ __Expect>, __Expect, HasName>, @@ -237,13 +259,195 @@ import { } { - // eslint-disable-next-line @typescript-eslint/naming-convention type _ = [ __Expect>, __Expect, HasJSDoc>, ]; } +{ + type _ = [ + __Expect>, + __Expect, HasExpression>, + ]; +} + +{ + type _ = [ + __Expect>, + __Expect, HasInitializer>, + ]; + type __ = Exclude, HasInitializer>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasText>, + ]; + type __ = Exclude, HasText>; +} + +{ + type _ = [ + __Expect, { symbol: never }>>, + __Expect, { symbol: never }>, HasSymbol>, + ]; + type __ = Exclude, { symbol: never }>, HasSymbol>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasType>, + ]; + type __ = Exclude, HasType>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasLocals>, + ]; + type __ = Exclude, HasLocals>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasTypeParameters>, + ]; + type __ = Exclude, HasTypeParameters>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasParameters>, + ]; + type __ = Exclude, HasParameters>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasBody>, + ]; + type __ = Exclude, HasBody>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasQuestionToken>, + ]; + type __ = Exclude, HasQuestionToken>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasEndFlowNode>, + ]; + type __ = Exclude, HasEndFlowNode>; +} + +{ + type _ = [ + __Expect>, + __Expect, InternalHasTypeArguments>, + ]; + type __ = Exclude, InternalHasTypeArguments>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasElements>, + ]; + type __ = Exclude, HasElements>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasMembers>, + ]; + type __ = Exclude, HasMembers>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasStatement>, + ]; + type __ = Exclude, HasStatement>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasStatements>, + ]; + type __ = Exclude, HasStatements>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasExclamationToken>, + ]; + type __ = Exclude, HasExclamationToken>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasAsteriskToken>, + ]; + type __ = Exclude, HasAsteriskToken>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasQuestionDotToken>, + ]; + type __ = Exclude, HasQuestionDotToken>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasComment>, + ]; + type __ = Exclude, HasComment>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasTypes>, + ]; + type __ = Exclude, HasTypes>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasTagName>, + ]; + type __ = Exclude, HasTagName>; +} + +{ + type _ = [ + __Expect>, + __Expect, HasIsTypeOnly>, + ]; + type __ = Exclude, HasIsTypeOnly>; +} + // Registry /** @@ -619,4 +823,4 @@ export interface NodeMap { */ export type Nodes = NodeMap[keyof NodeMap]; -type __Expect = never; // eslint-disable-line @typescript-eslint/naming-convention +type __Expect = never; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 959c97890c0b7..47c90807da7d9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -35,6 +35,7 @@ import { AstConciseBody, AstConstructorDeclaration, AstConstructSignatureDeclaration, + astContainsParseError, AstDecorator, AstDefaultClause, AstDoStatement, @@ -58,6 +59,9 @@ import { AstFunctionDeclaration, AstFunctionExpression, AstFunctionOrConstructorTypeNode, + astGetFullWidth, + astGetModifiers, + astGetTextOfNodeFromSourceText, AstHasJSDoc, astHasJSDoc, astHasJSDocNodes, @@ -75,6 +79,32 @@ import { AstIndexSignatureDeclaration, AstInferTypeNode, AstInterfaceDeclaration, + astIsAsyncModifier, + astIsDeclareKeyword, + astIsExportAssignment, + astIsExportDeclaration, + astIsExportModifier, + astIsExpressionWithTypeArguments, + astIsExternalModuleReference, + astIsFunctionTypeNode, + astIsIdentifier, + astIsImportDeclaration, + astIsImportEqualsDeclaration, + astIsJSDocFunctionType, + astIsJSDocNullableType, + astIsJSDocReturnTag, + astIsJSDocTypeTag, + astIsJsxNamespacedName, + astIsJsxOpeningElement, + astIsJsxOpeningFragment, + astIsLeftHandSideExpression, + astIsMetaProperty, + astIsNonNullExpression, + astIsPrivateIdentifier, + astIsSetAccessorDeclaration, + astIsStringOrNumericLiteralLike, + astIsTaggedTemplateExpression, + astIsTypeReferenceNode, AstIterationStatement, AstJSDoc, AstJSDocAllType, @@ -145,6 +175,7 @@ import { AstMissingDeclaration, AstModifier, AstModifierLike, + astModifiersToFlags, AstModuleBlock, AstModuleDeclaration, AstModuleExportName, @@ -159,6 +190,8 @@ import { AstNode, AstNodeArray, AstNodeArrayLike, + astNodeIsMissing, + astNodeIsPresent, AstNoSubstitutionTemplateLiteral, AstNullLiteral, AstNumericLiteral, @@ -230,7 +263,6 @@ import { commentPragmas, CommentRange, concatenate, - containsParseError, convertToJson, createAstNodeFactory, createDetachedDiagnostic, @@ -256,42 +288,14 @@ import { getAnyExtensionFromPath, getBaseFileName, getBinaryOperatorPrecedence, - getFullWidth, getJSDocCommentRanges, getLanguageVariant, getLastChild, getLeadingCommentRanges, getSpellingSuggestion, - getTextOfNodeFromSourceText, identity, isArray, isAssignmentOperator, - isAstAsyncModifier, - isAstDeclareKeyword, - isAstExportAssignment, - isAstExportDeclaration, - isAstExportModifier, - isAstExpressionWithTypeArguments, - isAstExternalModuleReference, - isAstFunctionTypeNode, - isAstIdentifier, - isAstImportDeclaration, - isAstImportEqualsDeclaration, - isAstJSDocFunctionType, - isAstJSDocNullableType, - isAstJSDocReturnTag, - isAstJSDocTypeTag, - isAstJsxNamespacedName, - isAstJsxOpeningElement, - isAstJsxOpeningFragment, - isAstLeftHandSideExpression, - isAstMetaProperty, - isAstNonNullExpression, - isAstPrivateIdentifier, - isAstSetAccessorDeclaration, - isAstStringOrNumericLiteralLike, - isAstTaggedTemplateExpression, - isAstTypeReferenceNode, isClassMemberModifier, isIdentifierText, isKeyword, @@ -311,15 +315,12 @@ import { map, mapDefined, ModifierFlags, - modifiersToFlags, ModuleKind, Mutable, Node, NodeFactory, NodeFactoryFlags, NodeFlags, - nodeIsMissing, - nodeIsPresent, noop, normalizePath, OperatorPrecedence, @@ -406,10 +407,10 @@ export function isFileProbablyExternalModule(sourceFile: SourceFile): Node | und function isAnExternalModuleIndicatorNode(node: AstNode) { return astCanHaveModifiers(node) && hasModifierOfKind(node, SyntaxKind.ExportKeyword) - || isAstImportEqualsDeclaration(node) && isAstExternalModuleReference(node.data.moduleReference) - || isAstImportDeclaration(node) - || isAstExportAssignment(node) - || isAstExportDeclaration(node) ? node : undefined; + || astIsImportEqualsDeclaration(node) && astIsExternalModuleReference(node.data.moduleReference) + || astIsImportDeclaration(node) + || astIsExportAssignment(node) + || astIsExportDeclaration(node) ? node : undefined; } function getImportMetaIfNecessary(sourceFile: SourceFile) { @@ -424,11 +425,11 @@ function walkTreeForImportMeta(node: AstNode): AstNode | undefined { /** Do not use hasModifier inside the parser; it relies on parent pointers. Use this instead. */ function hasModifierOfKind(node: AstHasModifiers, kind: SyntaxKind) { - return some(node.data.modifiers?.items, m => m.kind === kind); + return some(astGetModifiers(node)?.items, m => m.kind === kind); } function isImportMeta(node: AstNode): boolean { - return isAstMetaProperty(node) && node.data.keywordToken === SyntaxKind.ImportKeyword && node.data.name.data.escapedText === "meta"; + return astIsMetaProperty(node) && node.data.keywordToken === SyntaxKind.ImportKeyword && node.data.name.data.escapedText === "meta"; } export interface CreateSourceFileOptions { @@ -497,7 +498,13 @@ export function parseJsonText(fileName: string, sourceText: string): JsonSourceF // See also `isExternalOrCommonJsModule` in utilities.ts export function isExternalModule(file: SourceFile): boolean { - return file.externalModuleIndicator !== undefined; + return astIsExternalModule(file.ast); +} + +// See also `isExternalOrCommonJsModule` in utilities.ts +/** @internal */ +export function astIsExternalModule(file: AstSourceFile): boolean { + return file.data.externalModuleIndicator !== undefined; } // Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter @@ -1456,13 +1463,13 @@ namespace Parser { // Tagged template literals are sometimes used in places where only simple strings are allowed, i.e.: // module `M1` { // ^^^^^^^^^^^ This block is parsed as a template literal like module`M1`. - if (isAstTaggedTemplateExpression(node)) { + if (astIsTaggedTemplateExpression(node)) { parseErrorAt(skipTrivia(sourceText, node.data.template.pos), node.data.template.end, Diagnostics.Module_declaration_names_may_only_use_or_quoted_strings); return; } // Otherwise, if this isn't a well-known keyword-like identifier, give the generic fallback message. - const expressionText = isAstIdentifier(node) ? unescapeLeadingUnderscores(node.data.escapedText) : undefined; + const expressionText = astIsIdentifier(node) ? unescapeLeadingUnderscores(node.data.escapedText) : undefined; if (!expressionText || !isIdentifierText(expressionText, languageVersion)) { parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(SyntaxKind.SemicolonToken)); return; @@ -2226,7 +2233,7 @@ namespace Parser { // Can't reuse a node that intersected the change range. // Can't reuse a node that contains a parse error. This is necessary so that we // produce the same set of errors again. - if (nodeIsMissing(node) || intersectsIncrementalChange(node) || containsParseError(node)) { + if (astNodeIsMissing(node) || intersectsIncrementalChange(node) || astContainsParseError(node)) { return undefined; } @@ -2898,7 +2905,7 @@ namespace Parser { function typeHasArrowFunctionBlockingParseError(node: AstTypeNode): boolean { switch (node.kind) { case SyntaxKind.TypeReference: - return nodeIsMissing((node as AstTypeReferenceNode).data.typeName); + return astNodeIsMissing((node as AstTypeReferenceNode).data.typeName); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: { const { data: { parameters, type } } = node as AstFunctionOrConstructorTypeNode; @@ -3091,7 +3098,7 @@ namespace Parser { // FormalParameter [Yield,Await]: // BindingElement[?Yield,?Await] const name = parseIdentifierOrPattern(Diagnostics.Private_identifiers_cannot_be_used_as_parameters); - if (getFullWidth(name) === 0 && !some(modifiers?.items) && isModifierKind(token())) { + if (astGetFullWidth(name) === 0 && !some(modifiers?.items) && isModifierKind(token())) { // in cases like // 'use strict' // function foo(static) @@ -3532,7 +3539,7 @@ namespace Parser { return finishNode(factory.createRestTypeNode(parseType()), pos); } const type = parseType(); - if (isAstJSDocNullableType(type) && type.pos === type.data.type.pos) { + if (astIsJSDocNullableType(type) && type.pos === type.data.type.pos) { const node = factory.createOptionalTypeNode(type.data.type); setTextRange(node, type); node.flags = type.flags; @@ -3890,7 +3897,7 @@ namespace Parser { if (isStartOfFunctionTypeOrConstructorType()) { const type = parseFunctionOrConstructorType(); let diagnostic: DiagnosticMessage; - if (isAstFunctionTypeNode(type)) { + if (astIsFunctionTypeNode(type)) { diagnostic = isInUnionType ? Diagnostics.Function_type_notation_must_be_parenthesized_when_used_in_a_union_type : Diagnostics.Function_type_notation_must_be_parenthesized_when_used_in_an_intersection_type; @@ -4215,7 +4222,7 @@ namespace Parser { // // Note: we call reScanGreaterToken so that we get an appropriately merged token // for cases like `> > =` becoming `>>=` - if (isAstLeftHandSideExpression(expr) && isAssignmentOperator(reScanGreaterToken())) { + if (astIsLeftHandSideExpression(expr) && isAssignmentOperator(reScanGreaterToken())) { return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction), pos); } @@ -4521,7 +4528,7 @@ namespace Parser { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); const modifiers = parseModifiersForArrowFunction(); - const isAsync = some(modifiers?.items, isAstAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; + const isAsync = some(modifiers?.items, astIsAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; // Arrow functions are never generators. // // If we're speculatively parsing a signature for a parenthesized arrow function, then @@ -4576,7 +4583,7 @@ namespace Parser { unwrappedType = (unwrappedType as AstParenthesizedTypeNode).data.type; // Skip parens if need be } - const hasJSDocFunctionType = unwrappedType && isAstJSDocFunctionType(unwrappedType); + const hasJSDocFunctionType = unwrappedType && astIsJSDocFunctionType(unwrappedType); if (!allowAmbiguity && token() !== SyntaxKind.EqualsGreaterThanToken && (hasJSDocFunctionType || token() !== SyntaxKind.OpenBraceToken)) { // Returning undefined here will cause our caller to rewind to where we started from. return undefined; @@ -4587,7 +4594,7 @@ namespace Parser { const lastToken = token(); const equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken); const body = (lastToken === SyntaxKind.EqualsGreaterThanToken || lastToken === SyntaxKind.OpenBraceToken) - ? parseArrowFunctionExpressionBody(some(modifiers?.items, isAstAsyncModifier), allowReturnTypeInArrowFunction) + ? parseArrowFunctionExpressionBody(some(modifiers?.items, astIsAsyncModifier), allowReturnTypeInArrowFunction) : parseIdentifier(); // Given: @@ -4674,7 +4681,7 @@ namespace Parser { questionToken, doOutsideOfContext(disallowInAndDecoratorContext, () => parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ false)), colonToken = parseExpectedToken(SyntaxKind.ColonToken), - nodeIsPresent(colonToken) + astNodeIsPresent(colonToken) ? parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction) : createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.ColonToken)), ), @@ -4971,7 +4978,7 @@ namespace Parser { const expression = parseLeftHandSideExpressionOrHigher(); - Debug.assert(isAstLeftHandSideExpression(expression)); + Debug.assert(astIsLeftHandSideExpression(expression)); if ((token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) && !scanner.hasPrecedingLineBreak()) { const operator = token() as PostfixUnaryOperator; nextToken(); @@ -5158,13 +5165,13 @@ namespace Parser { else { closingElement = parseJsxClosingElement(opening, inExpressionContext); if (!tagNamesAreEquivalent(opening.data.tagName, closingElement.data.tagName)) { - if (openingTag && isAstJsxOpeningElement(openingTag) && tagNamesAreEquivalent(closingElement.data.tagName, openingTag.data.tagName)) { + if (openingTag && astIsJsxOpeningElement(openingTag) && tagNamesAreEquivalent(closingElement.data.tagName, openingTag.data.tagName)) { // opening incorrectly matched with its parent's closing -- put error on opening - parseErrorAtRange(opening.data.tagName, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, opening.data.tagName)); + parseErrorAtRange(opening.data.tagName, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, astGetTextOfNodeFromSourceText(sourceText, opening.data.tagName)); } else { // other opening/closing mismatches -- put error on closing - parseErrorAtRange(closingElement.data.tagName, Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, getTextOfNodeFromSourceText(sourceText, opening.data.tagName)); + parseErrorAtRange(closingElement.data.tagName, Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, astGetTextOfNodeFromSourceText(sourceText, opening.data.tagName)); } } } @@ -5215,7 +5222,7 @@ namespace Parser { case SyntaxKind.EndOfFileToken: // If we hit EOF, issue the error at the tag that lacks the closing element // rather than at the end of the file (which is useless) - if (isAstJsxOpeningFragment(openingTag)) { + if (astIsJsxOpeningFragment(openingTag)) { parseErrorAtRange(openingTag, Diagnostics.JSX_fragment_has_no_corresponding_closing_tag); } else { @@ -5223,7 +5230,7 @@ namespace Parser { // or to cover only 'Foo' in < Foo > const tag = openingTag.data.tagName; const start = Math.min(skipTrivia(sourceText, tag.pos), tag.end); - parseErrorAt(start, tag.end, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.data.tagName)); + parseErrorAt(start, tag.end, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, astGetTextOfNodeFromSourceText(sourceText, openingTag.data.tagName)); } return undefined; case SyntaxKind.LessThanSlashToken: @@ -5252,7 +5259,7 @@ namespace Parser { if (!child) break; list.push(child); if ( - isAstJsxOpeningElement(openingTag) + astIsJsxOpeningElement(openingTag) && child?.kind === SyntaxKind.JsxElement && !tagNamesAreEquivalent(child.data.openingElement.data.tagName, child.data.closingElement.data.tagName) && tagNamesAreEquivalent(openingTag.data.tagName, child.data.closingElement.data.tagName) @@ -5319,7 +5326,7 @@ namespace Parser { // We can't just simply use parseLeftHandSideExpressionOrHigher because then we will start consider class,function etc as a keyword // We only want to consider "this" as a primaryExpression const initialExpression = parseJsxTagName(); - if (isAstJsxNamespacedName(initialExpression)) { + if (astIsJsxNamespacedName(initialExpression)) { return initialExpression; // `a:b.c` is invalid syntax, don't even look for the `.` if we parse `a:b`, and let `parseAttribute` report "unexpected :" instead. } let expression: AstPropertyAccessExpression | AstIdentifier | AstThisExpression = initialExpression; @@ -5475,14 +5482,14 @@ namespace Parser { return true; } // check for an optional chain in a non-null expression - if (isAstNonNullExpression(node)) { + if (astIsNonNullExpression(node)) { let expr = node.data.expression; - while (isAstNonNullExpression(expr) && !(expr.flags & NodeFlags.OptionalChain)) { + while (astIsNonNullExpression(expr) && !(expr.flags & NodeFlags.OptionalChain)) { expr = expr.data.expression; } if (expr.flags & NodeFlags.OptionalChain) { // this is part of an optional chain. Walk down from `node` to `expression` and set the flag. - while (isAstNonNullExpression(node)) { + while (astIsNonNullExpression(node)) { node.flags |= NodeFlags.OptionalChain; node = node.data.expression; } @@ -5498,10 +5505,10 @@ namespace Parser { const propertyAccess = isOptionalChain ? factoryCreatePropertyAccessChain(expression, questionDotToken, name) : factoryCreatePropertyAccessExpression(expression, name); - if (isOptionalChain && isAstPrivateIdentifier(propertyAccess.data.name)) { + if (isOptionalChain && astIsPrivateIdentifier(propertyAccess.data.name)) { parseErrorAtRange(propertyAccess.data.name, Diagnostics.An_optional_chain_cannot_contain_private_identifiers); } - if (isAstExpressionWithTypeArguments(expression) && expression.data.typeArguments) { + if (astIsExpressionWithTypeArguments(expression) && expression.data.typeArguments) { const pos = expression.data.typeArguments.pos - 1; const end = skipTrivia(sourceText, expression.data.typeArguments.end) + 1; parseErrorAt(pos, end, Diagnostics.An_instantiation_expression_cannot_be_followed_by_a_property_access); @@ -5516,7 +5523,7 @@ namespace Parser { } else { const argument = allowInAnd(parseExpression); - if (isAstStringOrNumericLiteralLike(argument)) { + if (astIsStringOrNumericLiteralLike(argument)) { argument.data.text = internIdentifier(argument.data.text); } argumentExpression = argument; @@ -5555,7 +5562,7 @@ namespace Parser { if (isTemplateStartOfTaggedTemplate()) { // Absorb type arguments into TemplateExpression when preceding expression is ExpressionWithTypeArguments - expression = !questionDotToken && isAstExpressionWithTypeArguments(expression) ? + expression = !questionDotToken && astIsExpressionWithTypeArguments(expression) ? parseTaggedTemplateRest(pos, expression.data.expression, questionDotToken, expression.data.typeArguments) : parseTaggedTemplateRest(pos, expression, questionDotToken, /*typeArguments*/ undefined); continue; @@ -5611,7 +5618,7 @@ namespace Parser { } if (typeArguments || token() === SyntaxKind.OpenParenToken) { // Absorb type arguments into CallExpression when preceding expression is ExpressionWithTypeArguments - if (!questionDotToken && isAstExpressionWithTypeArguments(expression)) { + if (!questionDotToken && astIsExpressionWithTypeArguments(expression)) { typeArguments = expression.data.typeArguments; expression = expression.data.expression; } @@ -5857,7 +5864,7 @@ namespace Parser { parseExpected(SyntaxKind.FunctionKeyword); const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); const isGenerator = asteriskToken ? SignatureFlags.Yield : SignatureFlags.None; - const isAsync = some(modifiers?.items, isAstAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; + const isAsync = some(modifiers?.items, astIsAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; const name = isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalBindingIdentifier) : isGenerator ? doInYieldContext(parseOptionalBindingIdentifier) : isAsync ? doInAwaitContext(parseOptionalBindingIdentifier) : @@ -5889,12 +5896,12 @@ namespace Parser { let expression: AstLeftHandSideExpression = parseMemberExpressionRest(expressionPos, parsePrimaryExpression(), /*allowOptionalChain*/ false); let typeArguments: AstNodeArray | undefined; // Absorb type arguments into NewExpression when preceding expression is ExpressionWithTypeArguments - if (isAstExpressionWithTypeArguments(expression)) { + if (astIsExpressionWithTypeArguments(expression)) { typeArguments = expression.data.typeArguments; expression = expression.data.expression; } if (token() === SyntaxKind.QuestionDotToken) { - parseErrorAtCurrentToken(Diagnostics.Invalid_optional_chain_from_new_expression_Did_you_mean_to_call_0, getTextOfNodeFromSourceText(sourceText, expression)); + parseErrorAtCurrentToken(Diagnostics.Invalid_optional_chain_from_new_expression_Did_you_mean_to_call_0, astGetTextOfNodeFromSourceText(sourceText, expression)); } const argumentList = token() === SyntaxKind.OpenParenToken ? parseArgumentList() : undefined; return finishNode(factoryCreateNewExpression(expression, typeArguments, argumentList), pos); @@ -6209,7 +6216,7 @@ namespace Parser { let node: AstExpressionStatement | AstLabeledStatement; const hasParen = token() === SyntaxKind.OpenParenToken; const expression = allowInAnd(parseExpression); - if (isAstIdentifier(expression) && parseOptional(SyntaxKind.ColonToken)) { + if (astIsIdentifier(expression) && parseOptional(SyntaxKind.ColonToken)) { node = factory.createLabeledStatement(expression, parseStatement()); } else { @@ -6538,7 +6545,7 @@ namespace Parser { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); const modifiers = parseModifiers(/*allowDecorators*/ true); - const isAmbient = some(modifiers?.items, isAstDeclareKeyword); + const isAmbient = some(modifiers?.items, astIsDeclareKeyword); if (isAmbient) { const node = tryReuseAmbientDeclaration(pos); if (node) { @@ -6795,7 +6802,7 @@ namespace Parser { function parseFunctionDeclaration(pos: number, hasJSDoc: boolean, modifiers: AstNodeArray | undefined): AstFunctionDeclaration { const savedAwaitContext = inAwaitContext(); - const modifierFlags = modifiersToFlags(modifiers?.items); + const modifierFlags = astModifiersToFlags(modifiers?.items); parseExpected(SyntaxKind.FunctionKeyword); const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); // We don't parse the name here in await context, instead we will report a grammar error in the checker. @@ -6852,7 +6859,7 @@ namespace Parser { diagnosticMessage?: DiagnosticMessage, ): AstMethodDeclaration { const isGenerator = asteriskToken ? SignatureFlags.Yield : SignatureFlags.None; - const isAsync = some(modifiers?.items, isAstAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; + const isAsync = some(modifiers?.items, astIsAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; const typeParameters = parseTypeParameters(); const parameters = parseParameters(isGenerator | isAsync); const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); @@ -6921,7 +6928,7 @@ namespace Parser { : factory.createSetAccessorDeclaration(modifiers, name, parameters, body); // Keep track of `typeParameters` (for both) and `type` (for setters) if they were parsed those indicate grammar errors node.data.typeParameters = typeParameters; - if (isAstSetAccessorDeclaration(node)) { + if (astIsSetAccessorDeclaration(node)) { node.data.type = type; } return withJSDoc(finishNode(node, pos), hasJSDoc); @@ -7171,7 +7178,7 @@ namespace Parser { token() === SyntaxKind.AsteriskToken || token() === SyntaxKind.OpenBracketToken ) { - const isAmbient = some(modifiers?.items, isAstDeclareKeyword); + const isAmbient = some(modifiers?.items, astIsDeclareKeyword); if (isAmbient) { for (const m of modifiers!.items) { m.flags |= NodeFlags.Ambient; @@ -7222,7 +7229,7 @@ namespace Parser { // We don't parse the name here in await context, instead we will report a grammar error in the checker. const name = parseNameOfClassDeclarationOrExpression(); const typeParameters = parseTypeParameters(); - if (some(modifiers?.items, isAstExportModifier)) setAwaitContext(/*value*/ true); + if (some(modifiers?.items, astIsExportModifier)) setAwaitContext(/*value*/ true); const heritageClauses = parseHeritageClauses(); let members; @@ -8466,7 +8473,7 @@ namespace Parser { case SyntaxKind.ArrayType: return isObjectOrObjectArrayTypeReference((node as AstArrayTypeNode).data.elementType); default: - return isAstTypeReferenceNode(node) && isAstIdentifier(node.data.typeName) && node.data.typeName.data.escapedText === "Object" && !node.data.typeArguments; + return astIsTypeReferenceNode(node) && astIsIdentifier(node.data.typeName) && node.data.typeName.data.escapedText === "Object" && !node.data.typeArguments; } } @@ -8516,7 +8523,7 @@ namespace Parser { } function parseReturnTag(start: number, tagName: AstIdentifier, indent: number, indentText: string): AstJSDocReturnTag { - if (some(tags, isAstJSDocReturnTag)) { + if (some(tags, astIsJSDocReturnTag)) { parseErrorAt(tagName.pos, scanner.getTokenStart(), Diagnostics._0_tag_already_specified, unescapeLeadingUnderscores(tagName.data.escapedText)); } @@ -8525,7 +8532,7 @@ namespace Parser { } function parseTypeTag(start: number, tagName: AstIdentifier, indent?: number, indentText?: string): AstJSDocTypeTag { - if (some(tags, isAstJSDocTypeTag)) { + if (some(tags, astIsJSDocTypeTag)) { parseErrorAt(tagName.pos, scanner.getTokenStart(), Diagnostics._0_tag_already_specified, unescapeLeadingUnderscores(tagName.data.escapedText)); } @@ -8790,8 +8797,8 @@ namespace Parser { } function escapedTextsEqual(a: AstEntityName, b: AstEntityName): boolean { - while (!isAstIdentifier(a) || !isAstIdentifier(b)) { - if (!isAstIdentifier(a) && !isAstIdentifier(b) && a.data.right.data.escapedText === b.data.right.data.escapedText) { + while (!astIsIdentifier(a) || !astIsIdentifier(b)) { + if (!astIsIdentifier(a) && !astIsIdentifier(b) && a.data.right.data.escapedText === b.data.right.data.escapedText) { a = a.data.left; b = b.data.left; } @@ -8816,7 +8823,7 @@ namespace Parser { const child = tryParseChildTag(target, indent); if ( child && (child.kind === SyntaxKind.JSDocParameterTag || child.kind === SyntaxKind.JSDocPropertyTag) && - name && (isAstIdentifier(child.data.name) || !escapedTextsEqual(name, child.data.name.data.left)) + name && (astIsIdentifier(child.data.name) || !escapedTextsEqual(name, child.data.name.data.left)) ) { return false; } @@ -8893,7 +8900,7 @@ namespace Parser { parseExpected(SyntaxKind.CloseBracketToken); } - if (nodeIsMissing(name)) { + if (astNodeIsMissing(name)) { return undefined; } return finishNode(factory.createTypeParameterDeclaration(modifiers, name, /*constraint*/ undefined, defaultType), typeParameterPos); @@ -9415,7 +9422,7 @@ namespace IncrementalParser { } function visit(child: AstNode) { - if (nodeIsMissing(child)) { + if (astNodeIsMissing(child)) { // Missing nodes are effectively invisible to us. We never even consider them // When trying to find the nearest node before us. return; diff --git a/src/compiler/readonlyArray.ts b/src/compiler/readonlyArray.ts new file mode 100644 index 0000000000000..4080fde94227c --- /dev/null +++ b/src/compiler/readonlyArray.ts @@ -0,0 +1,116 @@ +function canonicalNumericIndexString(argument: string) { + if (argument === "-0") { + return -0; + } + const n = Number(argument); + if (String(n) === argument) { + return n; + } + return undefined; +} + +function isValidIntegerIndex(argument: string | symbol) { + if (typeof argument === "string") { + const index = canonicalNumericIndexString(argument); + if (index !== undefined && Number.isInteger(index)) { + return true; + } + } + return false; +} + +const readonlyArrayViewBrand = new WeakSet(); +const readonlyArrayViewData = new WeakMap any}>(); +const readonlyArrayViewHandler: ProxyHandler = { + defineProperty(o, p, desc) { + if (p === "length" || isValidIntegerIndex(p)) { + const { source, mapper } = readonlyArrayViewData.get(o)!; + const existing = Reflect.getOwnPropertyDescriptor(source, p); + if (!existing) { + return false; + } + if (p !== "length") { + existing.value = mapper(existing.value); + } + return existing.get === desc.get && + existing.set === desc.set && + existing.configurable === desc.configurable && + existing.enumerable === desc.enumerable && + existing.writable === desc.writable && + existing.value === desc.value; + } + return Reflect.defineProperty(o, p, desc); + }, + getOwnPropertyDescriptor(o, p) { + const { source, mapper } = readonlyArrayViewData.get(o)!; + if (p === "length") { + return Reflect.getOwnPropertyDescriptor(source, p); + } + if (isValidIntegerIndex(p)) { + const existing = Reflect.getOwnPropertyDescriptor(source, p); + if (existing?.value !== undefined) { + existing.value = mapper(existing.value); + } + return existing; + } + return Reflect.getOwnPropertyDescriptor(o, p); + }, + has(o, p) { + const { source } = readonlyArrayViewData.get(o)!; + if (p === "length" || isValidIntegerIndex(p)) { + return Reflect.has(source, p); + } + return Reflect.has(o, p); + }, + get(o, p, receiver) { + const { source, mapper } = readonlyArrayViewData.get(o)!; + if (p === "length") { + return Reflect.get(source, p, receiver); + } + if (isValidIntegerIndex(p)) { + const value = Reflect.get(source, p, receiver); + return value !== undefined ? mapper(value) : value; + } + return Reflect.get(o, p, receiver); + }, + set(o, p, v, receiver) { + if (p === "length" || isValidIntegerIndex(p)) { + return false; + } + return Reflect.set(o, p, v, receiver); + }, + deleteProperty(o, p) { + if (p === "length" || isValidIntegerIndex(p)) { + return false; + } + return Reflect.deleteProperty(o, p); + }, + preventExtensions(_o) { + return false; + }, +}; + +/** @internal */ +export interface ReadonlyArrayView extends ReadonlyArray { + _readonlyArrayViewBrand: any; +} + +/** @internal */ +export interface ReadonlyArrayViewConstructor { + new (source: readonly T[], mapper: (value: T) => U): ReadonlyArrayView; + isReadonlyArrayView(obj: unknown): obj is ReadonlyArrayView; +} + +/** @internal */ +// eslint-disable-next-line local/only-arrow-functions +export const ReadonlyArrayView = function (source: readonly T[], mapper: (value: T) => U) { + const array: readonly U[] = []; + const proxy = new Proxy(array, readonlyArrayViewHandler); + readonlyArrayViewData.set(array, { source, mapper }); + readonlyArrayViewBrand.add(proxy); + return proxy; +} as unknown as ReadonlyArrayViewConstructor; + +ReadonlyArrayView.isReadonlyArrayView = (obj): obj is ReadonlyArrayView => { + return typeof obj === "object" && !!obj && readonlyArrayViewBrand.has(obj); +}; diff --git a/src/compiler/tsconfig.json b/src/compiler/tsconfig.json index cbbd3df0beb72..cfb7213a17e20 100644 --- a/src/compiler/tsconfig.json +++ b/src/compiler/tsconfig.json @@ -1,7 +1,8 @@ { "extends": "../tsconfig-base", "compilerOptions": { - "types": ["node"] + "types": ["node"], + "experimentalDecorators": true }, "references": [], diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 34d36d5714df1..4ab24b73c6768 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -209,7 +209,7 @@ import { AstTryStatementData, AstTupleTypeNodeData, AstTypeAliasDeclarationData, - AstTypeAssertionData, + AstTypeAssertionExpressionData, AstTypeLiteralNodeData, AstTypeOfExpressionData, AstTypeOperatorNodeData, @@ -315,6 +315,24 @@ import { AstEntityNameExpression, AstQuestionDotToken, AstMemberName, + AstStringLiteralLike, + AstNumericLiteral, + AstObjectLiteralExpression, + AstBindableStaticNameExpression, + AstWrappedExpression, + AstNodeOneOf, + AstLeftHandSideExpression, + AstBindableStaticAccessExpression, + AstEntityName, + AstJSDocTypeExpression, + AstComputedPropertyName, + AstElementAccessExpression, + AstDeclaration, + AstModuleBlock, + AstStringLiteral, + astGetComment, + astSetComment, + AstJSDocUnknownTag, } from "./_namespaces/ts.js"; // branded string type used to store absolute, normalized and canonicalized paths @@ -1254,12 +1272,12 @@ export class Node< get pos(): number { return this.ast.pos; } get end(): number { return this.ast.end; } get flags(): NodeFlags { return this.ast.flags; } - get parent(): Node { return this.ast.parent?.node!; } + get parent(): Node { return this.ast.parent?.node; } /** @internal */ set pos(value) { this.ast.pos = value; } /** @internal */ set end(value) { this.ast.end = value; } /** @internal */ set flags(value) { this.ast.flags = value; } - /** @internal */ set parent(value) { this.ast.parent = value?.ast; } + /** @internal */ set parent(value) { this.ast.parent = value?.ast as typeof this.ast.parent; } /** @internal */ get modifierFlagsCache(): ModifierFlags { return this.ast.modifierFlagsCache; } /** @internal */ set modifierFlagsCache(value) { this.ast.modifierFlagsCache = value; } /** @internal */ get transformFlags(): TransformFlags { return this.ast.transformFlags; } @@ -1520,11 +1538,22 @@ export type HasFlowNode = | TryStatement | DebuggerStatement; +/** @internal */ +export type HasEndFlowNode = + | MethodDeclaration + | ClassStaticBlockDeclaration + | ConstructorDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration + | FunctionExpression + | ArrowFunction + | FunctionDeclaration + | SourceFile; + // Ideally, `ForEachChildNodes` and `VisitEachChildNodes` would not differ. // However, `forEachChild` currently processes JSDoc comment syntax and missing declarations more thoroughly. // On the other hand, `visitEachChild` actually processes `Identifier`s (which really *shouldn't* have children, // but are constructed as if they could for faked-up `QualifiedName`s in the language service.) - /** @internal */ export type ForEachChildNodes = | HasChildren @@ -1794,7 +1823,20 @@ export type HasType = | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType - | JSDocVariadicType; + | JSDocVariadicType + | OptionalTypeNode + | RestTypeNode + | NamedTupleMember + | TemplateLiteralTypeSpan + | SatisfiesExpression + | JSDocNamepathType + | JSDocSignature; + +/** @internal */ +export type HasTypes = + | UnionTypeNode + | IntersectionTypeNode + | HeritageClause; // NOTE: Changing the following list requires changes to: // - `canHaveIllegalType` in factory/utilities.ts @@ -1803,6 +1845,29 @@ export type HasIllegalType = | ConstructorDeclaration | SetAccessorDeclaration; +/** @internal */ +export type HasTypeParameters = + | ConstructorDeclaration + | SetAccessorDeclaration + | GetAccessorDeclaration + | CallSignatureDeclaration + | ConstructSignatureDeclaration + | MethodSignature + | IndexSignatureDeclaration + | MethodDeclaration + | FunctionDeclaration + | JSDocSignature + | JSDocFunctionType + | FunctionTypeNode + | ConstructorTypeNode + | FunctionExpression + | ArrowFunction + | ClassExpression + | ClassDeclaration + | InterfaceDeclaration + | TypeAliasDeclaration + | JSDocTemplateTag; + // NOTE: Changing the following list requires changes to: // - `canHaveIllegalTypeParameters` in factory/utilities.ts /** @internal */ @@ -1811,13 +1876,186 @@ export type HasIllegalTypeParameters = | SetAccessorDeclaration | GetAccessorDeclaration; +/** @internal */ +export type HasParameters = + | ConstructorDeclaration + | SetAccessorDeclaration + | GetAccessorDeclaration + | CallSignatureDeclaration + | ConstructSignatureDeclaration + | MethodSignature + | IndexSignatureDeclaration + | MethodDeclaration + | FunctionDeclaration + | JSDocSignature + | JSDocFunctionType + | FunctionTypeNode + | ConstructorTypeNode + | FunctionExpression + | ArrowFunction; + +/** @internal */ +export type HasBody = + | MethodDeclaration + | ClassStaticBlockDeclaration + | ConstructorDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration + | FunctionDeclaration + | FunctionExpression + | ArrowFunction + | ModuleDeclaration; + export type HasTypeArguments = | CallExpression | NewExpression | TaggedTemplateExpression + | ExpressionWithTypeArguments + | TypeQueryNode + | ImportTypeNode + | TypeReferenceNode | JsxOpeningElement | JsxSelfClosingElement; +/** @internal */ +export type InternalHasTypeArguments = + | HasTypeArguments + | MethodSignature + | MethodDeclaration + | ConstructorDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration + | CallSignatureDeclaration + | ConstructSignatureDeclaration + | IndexSignatureDeclaration + | FunctionTypeNode + | ConstructorTypeNode + | FunctionExpression + | ArrowFunction + | FunctionDeclaration + | JSDocFunctionType; + +/** @internal */ +export type HasElements = + | TupleTypeNode + | ObjectBindingPattern + | ArrayBindingPattern + | ArrayLiteralExpression + | ImportAttributes + | NamedImports + | NamedExports + | CommaListExpression; + +/** @internal */ +export type HasMembers = + | TypeLiteralNode + | MappedTypeNode + | ClassExpression + | ClassDeclaration + | InterfaceDeclaration + | EnumDeclaration; + +/** @internal */ +export type HasStatement = + | DoStatement + | WhileStatement + | ForStatement + | ForInStatement + | ForOfStatement + | WithStatement + | LabeledStatement; + +/** @internal */ +export type HasStatements = + | Block + | ModuleBlock + | CaseClause + | DefaultClause + | SourceFile; + +/** @internal */ +export type HasExclamationToken = + | MethodDeclaration + | PropertyAssignment + | PropertyDeclaration + | ShorthandPropertyAssignment + | VariableDeclaration; + +/** @internal */ +export type HasQuestionDotToken = + | PropertyAccessExpression + | ElementAccessExpression + | CallExpression + | TaggedTemplateExpression; + +/** @internal */ +export type HasTagName = + | JsxSelfClosingElement + | JsxOpeningElement + | JsxClosingElement + | JSDocUnknownTag + | JSDocAugmentsTag + | JSDocImplementsTag + | JSDocAuthorTag + | JSDocDeprecatedTag + | JSDocClassTag + | JSDocPublicTag + | JSDocPrivateTag + | JSDocProtectedTag + | JSDocReadonlyTag + | JSDocOverrideTag + | JSDocCallbackTag + | JSDocOverloadTag + | JSDocEnumTag + | JSDocParameterTag + | JSDocReturnTag + | JSDocThisTag + | JSDocTypedefTag + | JSDocSeeTag + | JSDocPropertyTag + | JSDocTemplateTag + | JSDocTypeTag + | JSDocThrowsTag + | JSDocSatisfiesTag + | JSDocImportTag; + +/** @internal */ +export type HasIsTypeOnly = + | ImportEqualsDeclaration + | ExportDeclaration + | ExportSpecifier + | ImportClause + | ImportSpecifier; + +/** @internal */ +export type HasComment = + | JSDoc + | JSDocUnknownTag + | JSDocAugmentsTag + | JSDocImplementsTag + | JSDocAuthorTag + | JSDocDeprecatedTag + | JSDocClassTag + | JSDocPublicTag + | JSDocPrivateTag + | JSDocProtectedTag + | JSDocReadonlyTag + | JSDocOverrideTag + | JSDocCallbackTag + | JSDocOverloadTag + | JSDocEnumTag + | JSDocParameterTag + | JSDocReturnTag + | JSDocThisTag + | JSDocTypeTag + | JSDocTemplateTag + | JSDocTypedefTag + | JSDocSeeTag + | JSDocPropertyTag + | JSDocThrowsTag + | JSDocSatisfiesTag + | JSDocImportTag; + export type HasInitializer = | HasExpressionInitializer | ForStatement @@ -1831,6 +2069,7 @@ export type HasExpressionInitializer = | BindingElement | PropertyDeclaration | PropertyAssignment + | PropertySignature | EnumMember; /** @internal @knipignore */ @@ -1910,6 +2149,80 @@ export type HasIllegalModifiers = | MissingDeclaration | NamespaceExportDeclaration; +/** @internal */ +export type InternalHasModifiers = + | HasModifiers + | HasIllegalModifiers; + +/** @internal */ +export type HasSymbol = + | NumericLiteral + | StringLiteral + | NoSubstitutionTemplateLiteral + | Identifier + | TypeParameterDeclaration + | ParameterDeclaration + | PropertySignature + | PropertyDeclaration + | MethodSignature + | MethodDeclaration + | ClassStaticBlockDeclaration + | ConstructorDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration + | CallSignatureDeclaration + | ConstructSignatureDeclaration + | IndexSignatureDeclaration + | FunctionTypeNode + | ConstructorTypeNode + | TypeLiteralNode + | MappedTypeNode + | NamedTupleMember + | BindingElement + | ObjectLiteralExpression + | PropertyAccessExpression + | ElementAccessExpression + | CallExpression + | NewExpression + | FunctionExpression + | ArrowFunction + | BinaryExpression + | ClassExpression + | VariableDeclaration + | FunctionDeclaration + | ClassDeclaration + | InterfaceDeclaration + | TypeAliasDeclaration + | EnumDeclaration + | ModuleDeclaration + | NamespaceExportDeclaration + | ImportEqualsDeclaration + | ImportDeclaration + | ImportClause + | NamespaceImport + | ImportSpecifier + | ExportAssignment + | ExportDeclaration + | NamespaceExport + | ExportSpecifier + | MissingDeclaration + | JsxAttribute + | JsxAttributes + | SourceFile + | JSDocCallbackTag + | JSDocEnumTag + | JSDocFunctionType + | JSDocSignature + | JSDocTypedefTag + | PropertyAssignment + | ShorthandPropertyAssignment + | SpreadAssignment + | EnumMember + | JSDocParameterTag + | JSDocPropertyTag + | JSDocTypeLiteral + | NotEmittedTypeElement; + /** @internal */ export type PrimitiveLiteral = | BooleanLiteral @@ -1920,6 +2233,21 @@ export type PrimitiveLiteral = | PrefixUnaryExpression & { operator: SyntaxKind.PlusToken; operand: NumericLiteral; } | PrefixUnaryExpression & { operator: SyntaxKind.MinusToken; operand: NumericLiteral | BigIntLiteral; }; +/** @internal */ +export type HasText = + | NumericLiteral + | BigIntLiteral + | StringLiteral + | RegularExpressionLiteral + | TemplateLiteralToken + | JsxText + | JSDocText + | JSDocLink + | JSDocLinkCode + | JSDocLinkPlain + | SourceFile + ; + /** * Declarations that can contain other declarations. Corresponds with `ContainerFlags.IsContainer` in binder.ts. * @@ -2432,15 +2760,65 @@ export type HasName = | JSDocPropertyTag | MissingDeclaration; +// NOTE: Changing the following list requires changes to: +// - `astCanHaveExpression` in ast.ts +// - `astGetExpression` in ast.ts /** @internal */ -export interface DynamicNamedDeclaration extends NamedDeclaration { +export type HasExpression = + | ComputedPropertyName + | TypeParameterDeclaration + | Decorator + | PropertyAccessExpression + | ElementAccessExpression + | CallExpression + | NewExpression + | TypeAssertionExpression + | ParenthesizedExpression + | DeleteExpression + | TypeOfExpression + | VoidExpression + | AwaitExpression + | ForInStatement + | ForOfStatement + | ExpressionStatement + | IfStatement + | DoStatement + | WhileStatement + | YieldExpression + | SpreadElement + | ExpressionWithTypeArguments + | AsExpression + | NonNullExpression + | SatisfiesExpression + | TemplateSpan + | ReturnStatement + | WithStatement + | SwitchStatement + | ThrowStatement + | ExportAssignment + | ExternalModuleReference + | JsxSpreadAttribute + | JsxExpression + | CaseClause + | SpreadAssignment + | PartiallyEmittedExpression + | SyntheticReferenceExpression; + +/** @internal */ +export type DynamicNamedDeclaration = NamedDeclaration & { readonly name: ComputedPropertyName; -} + readonly data: { + readonly name: AstComputedPropertyName; + }; +}; /** @internal */ -export interface DynamicNamedBinaryExpression extends BinaryExpression { +export type DynamicNamedBinaryExpression = BinaryExpression & { readonly left: ElementAccessExpression; -} + readonly data: { + readonly left: AstElementAccessExpression; + }; +}; /** @internal */ // A declaration that supports late-binding (used in checker) @@ -4304,10 +4682,14 @@ export class BinaryExpression extends Node; -export interface AssignmentExpression extends BinaryExpression { +export type AssignmentExpression = BinaryExpression & { readonly left: LeftHandSideExpression; readonly operatorToken: TOperator; -} + readonly data: { + readonly left: AstLeftHandSideExpression; + readonly operatorToken: TOperator; + }; +}; export interface ObjectDestructuringAssignment extends AssignmentExpression { readonly left: ObjectLiteralExpression; @@ -5050,7 +5432,7 @@ export class CallExpression extends Node | undefined { return this.ast.data.typeArguments?.nodes; } get arguments(): NodeArray { return this.ast.data.arguments.nodes; } - + /** @internal */ set expression(value) { this.ast.data.expression = value.ast; } /** @internal */ set questionDotToken(value) { this.ast.data.questionDotToken = value?.ast; } /** @internal */ set typeArguments(value) { this.ast.data.typeArguments = value?.ast; } @@ -5086,6 +5468,9 @@ export type OptionalChainRoot = /** @internal */ export type BindableObjectDefinePropertyCall = CallExpression & { readonly arguments: readonly [BindableStaticNameExpression, StringLiteralLike | NumericLiteral, ObjectLiteralExpression] & Readonly; + readonly data: { + readonly arguments: { readonly items: readonly [AstBindableStaticNameExpression, AstStringLiteralLike | AstNumericLiteral, AstObjectLiteralExpression]; } & Readonly + }; }; /** @internal */ @@ -5096,16 +5481,25 @@ export type BindableStaticNameExpression = /** @internal */ export type LiteralLikeElementAccessExpression = ElementAccessExpression & Declaration & { readonly argumentExpression: StringLiteralLike | NumericLiteral; + readonly data: { + readonly argumentExpression: AstStringLiteralLike | AstNumericLiteral; + }; }; /** @internal */ export type BindableStaticElementAccessExpression = LiteralLikeElementAccessExpression & { readonly expression: BindableStaticNameExpression; + readonly data: { + readonly expression: AstBindableStaticNameExpression; + }; }; /** @internal */ export type BindableElementAccessExpression = ElementAccessExpression & { readonly expression: BindableStaticNameExpression; + readonly data: { + readonly expression: AstBindableStaticNameExpression; + }; }; /** @internal */ @@ -5119,14 +5513,20 @@ export type BindableAccessExpression = | BindableElementAccessExpression; /** @internal */ -export interface BindableStaticPropertyAssignmentExpression extends BinaryExpression { +export type BindableStaticPropertyAssignmentExpression = BinaryExpression & { readonly left: BindableStaticAccessExpression; -} + readonly data: { + readonly left: AstBindableStaticAccessExpression; + }; +}; /** @internal */ -export interface BindablePropertyAssignmentExpression extends BinaryExpression { +export type BindablePropertyAssignmentExpression = BinaryExpression & { readonly left: BindableAccessExpression; -} + readonly data: { + readonly left: AstBindableStaticAccessExpression; + }; +}; // see: https://tc39.github.io/ecma262/#prod-SuperCall export interface SuperCall extends CallExpression { @@ -5219,7 +5619,7 @@ export class AsExpression extends Node implements UnaryExpression { +export class TypeAssertionExpression extends Node implements UnaryExpression { declare _unaryExpressionBrand: any; declare _expressionBrand: any; // declare readonly ast: AstTypeAssertion; @@ -6320,9 +6720,23 @@ export type ModuleBody = // TODO(rbuckton): Move after ModuleDeclaration /** @internal */ -export interface AmbientModuleDeclaration extends ModuleDeclaration { +export type AmbientModuleDeclaration = ModuleDeclaration & { + readonly name: StringLiteral; readonly body: ModuleBlock | undefined; -} + readonly data: { + readonly name: AstStringLiteral; + readonly body: AstModuleBlock | undefined; + }; +}; + +// TODO(rbuckton): Move after ModuleDeclaration +/** @internal */ +export type NonGlobalAmbientModuleDeclaration = AmbientModuleDeclaration & { + readonly name: StringLiteral; + readonly data: { + readonly name: AstStringLiteral; + }; +}; // dprint-ignore export class ModuleDeclaration extends Node implements DeclarationStatement, JSDocContainer, LocalsContainer { @@ -6960,13 +7374,13 @@ export class JSDoc extends Node { get tags(): NodeArray | undefined { return this.ast.data.tags?.nodes; } get comment(): string | NodeArray | undefined { - const comment = this.ast.data.comment; + const comment = astGetComment(this.ast); return typeof comment === "string" ? comment : comment?.nodes; } /** @internal */ override set parent(value) { super.parent = value; } /** @internal */ set tags(value) { this.ast.data.tags = value?.ast; } - /** @internal */ set comment(value) { this.ast.data.comment = typeof value === "string" ? value : value?.ast; } + /** @internal */ set comment(value) { astSetComment(this.ast, typeof value === "string" ? value : value?.ast); } } // TODO(rbuckton): Move after JSDocText @@ -6978,13 +7392,13 @@ export class JSDocTag | undefined { - const comment = this.ast.data.comment; + const comment = astGetComment(this.ast); return typeof comment === "string" ? comment : comment?.nodes; } /** @internal */ override set parent(value) { super.parent = value; } /** @internal */ set tagName(value) { this.ast.data.tagName = value.ast; } - /** @internal */ set comment(value) { this.ast.data.comment = typeof value === "string" ? value : value?.ast; } + /** @internal */ set comment(value) { astSetComment(this.ast as AstJSDocUnknownTag, typeof value === "string" ? value : value?.ast); } } // dprint-ignore @@ -7277,13 +7691,18 @@ export class JSDocSignature extends Node i } /** @internal */ -export type PartialSourceFile = +export type PartialSourceFile = & Pick & Partial>; @@ -9482,21 +9901,23 @@ export type SymbolId = number; // dprint-ignore export interface Symbol { - flags: SymbolFlags; // Symbol flags - escapedName: __String; // Name of symbol - declarations?: Declaration[]; // Declarations associated with this symbol - valueDeclaration?: Declaration; // First value declaration of the symbol - members?: SymbolTable; // Class, interface or object literal instance members - exports?: SymbolTable; // Module exports - globalExports?: SymbolTable; // Conditional global UMD exports - /** @internal */ id: SymbolId; // Unique id (used to look up SymbolLinks) - /** @internal */ mergeId: number; // Merge id (used to look up merged symbol) - /** @internal */ parent?: Symbol; // Parent symbol - /** @internal */ exportSymbol?: Symbol; // Exported symbol associated with this symbol + flags: SymbolFlags; // Symbol flags + escapedName: __String; // Name of symbol + readonly declarations?: readonly Declaration[]; // Declarations associated with this symbol + readonly valueDeclaration?: Declaration; // First value declaration of the symbol + members?: SymbolTable; // Class, interface or object literal instance members + exports?: SymbolTable; // Module exports + globalExports?: SymbolTable; // Conditional global UMD exports + /** @internal */ astValueDeclaration?: AstDeclaration; // Declarations associated with this symbol + /** @internal */ astDeclarations?: AstDeclaration[]; // First value declaration of the symbol + /** @internal */ id: SymbolId; // Unique id (used to look up SymbolLinks) + /** @internal */ mergeId: number; // Merge id (used to look up merged symbol) + /** @internal */ parent?: Symbol; // Parent symbol + /** @internal */ exportSymbol?: Symbol; // Exported symbol associated with this symbol /** @internal */ constEnumOnlyModule: boolean | undefined; // True if module contains only const enums or other modules with only const enums - /** @internal */ isReferenced?: SymbolFlags; // True if the symbol is referenced elsewhere. Keeps track of the meaning of a reference in case a symbol is both a type parameter and parameter. - /** @internal */ lastAssignmentPos?: number; // Source position of last node that assigns value to symbol. Negative if it is assigned anywhere definitely - /** @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol? + /** @internal */ isReferenced?: SymbolFlags; // True if the symbol is referenced elsewhere. Keeps track of the meaning of a reference in case a symbol is both a type parameter and parameter. + /** @internal */ lastAssignmentPos?: number; // Source position of last node that assigns value to symbol. Negative if it is assigned anywhere definitely + /** @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol? /** @internal */ assignmentDeclarationMembers?: Map; // detected late-bound assignment declarations associated with the symbol } @@ -12082,7 +12503,7 @@ export type OuterExpression = /** @internal */ export type WrappedExpression = - | OuterExpression & { readonly expression: WrappedExpression; } + | OuterExpression & { readonly expression: WrappedExpression; readonly data: { readonly expression: AstWrappedExpression>; }; } | T; /** @internal */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index eb91b187ecad5..e58229dcc0ad8 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -180,21 +180,12 @@ import { getDirectoryPath, getImpliedNodeFormatForEmitWorker, getJSDocAugmentsTag, - getJSDocDeprecatedTagNoCache, getJSDocImplementsTags, - getJSDocOverrideTagNoCache, getJSDocParameterTags, - getJSDocParameterTagsNoCache, - getJSDocPrivateTagNoCache, - getJSDocProtectedTagNoCache, - getJSDocPublicTagNoCache, - getJSDocReadonlyTagNoCache, getJSDocReturnType, getJSDocSatisfiesTag, getJSDocTags, getJSDocType, - getJSDocTypeParameterTags, - getJSDocTypeParameterTagsNoCache, getJSDocTypeTag, getLeadingCommentRanges, getLineAndCharacterOfPosition, @@ -221,7 +212,6 @@ import { HasFlowNode, HasInferredType, HasInitializer, - hasInitializer, HasJSDoc, hasJSDocNodes, HasModifiers, @@ -261,8 +251,7 @@ import { isArrayLiteralExpression, isArrowFunction, isAssertionExpression, - isAstJSDocTypeExpression, - isAutoAccessorPropertyDeclaration, + astIsJSDocTypeExpression, isBigIntLiteral, isBinaryExpression, isBindingElement, @@ -329,7 +318,6 @@ import { isJsxNamespacedName, isJsxOpeningLikeElement, isJsxText, - isLeftHandSideExpression, isLineBreak, isLiteralTypeNode, isMappedTypeNode, @@ -337,7 +325,6 @@ import { isMetaProperty, isMethodDeclaration, isMethodOrAccessor, - isModifierLike, isModuleDeclaration, isModuleOrEnumDeclaration, isNamedDeclaration, @@ -356,7 +343,6 @@ import { isParameterPropertyDeclaration, isParenthesizedExpression, isParenthesizedTypeNode, - isPrefixUnaryExpression, isPrivateIdentifier, isPropertyAccessExpression, isPropertyAssignment, @@ -376,7 +362,6 @@ import { isTypeElement, isTypeLiteralNode, isTypeNode, - isTypeParameterDeclaration, isTypeQueryNode, isTypeReferenceNode, isVariableDeclaration, @@ -499,7 +484,6 @@ import { QuestionQuestionEqualsToken, ReadonlyCollection, ReadonlyTextRange, - RegularExpressionLiteral, removeTrailingDirectorySeparator, RequireOrImportCall, RequireVariableStatement, @@ -538,7 +522,6 @@ import { Statement, StringLiteral, StringLiteralLike, - StringLiteralLikeNode, StringLiteralType, stringToToken, SuperCall, @@ -552,7 +535,6 @@ import { targetOptionDeclaration, TemplateExpression, TemplateLiteral, - TemplateLiteralLikeNode, TemplateLiteralToken, TemplateLiteralTypeSpan, TemplateSpan, @@ -604,7 +586,127 @@ import { WriteFileCallback, WriteFileCallbackData, YieldExpression, + AstCallExpression, + astIsCallExpression, + AstBindableObjectDefinePropertyCall, + astIsPropertyAccessExpression, + astIsIdentifier, + astIdText, + astIsStringOrNumericLiteralLike, + AstBindableStaticNameExpression, + AstEntityNameExpression, + AstPropertyAccessEntityNameExpression, + AstBindableStaticAccessExpression, + AstBindableStaticElementAccessExpression, + astIsObjectLiteralExpression, + AstIdentifier, + RefineNode, + AstLiteralLikeElementAccessExpression, + AstPropertyAccessExpression, + AstAccessExpression, + AstPrivateIdentifier, + AstStringLiteralLike, + AstNumericLiteral, + AstElementAccessExpression, + astSkipOuterExpressions, + astIsElementAccessExpression, + AstAssignmentExpression, + astIsBinaryExpression, + astIsLeftHandSideExpression, + astIsVoidExpression, + astIsNumericLiteral, + AstDeclarationName, + astIsStringLiteralLike, + astIsPrefixUnaryExpression, + AstJSDocEnumTag, + AstJSDocCallbackTag, + AstJSDocTypedefTag, + astGetName, + AstQualifiedName, + AstImportSpecifier, + AstBindingElement, + AstThisContainer, + AstComputedPropertyName, + AstArrowFunction, + astIsClassLike, + astIsClassElement, + astIsClassDeclaration, + astIsFunctionDeclaration, + astIsSourceFile, + AstDeclaration, + AstDynamicNamedBinaryExpression, + AstDynamicNamedDeclaration, + astGetNameOfDeclaration, + astCanHaveModifiers, + astIsParameter, + AstVariableLikeDeclaration, + astHasJSDocNodes, + astGetInitializer, + AstParameterDeclaration, + AstTypeParameterDeclaration, + astGetJSDocParameterTagsNoCache, + astGetJSDocParameterTags, + astGetJSDocTypeParameterTagsNoCache, + astGetJSDocTypeParameterTags, + astIsModuleDeclaration, + AstVariableDeclaration, + astIsVariableStatement, + AstPropertyDeclaration, + AstPropertyAssignment, + astIsExpressionStatement, + astGetJSDocPublicTagNoCache, + astGetJSDocPrivateTagNoCache, + astGetJSDocProtectedTagNoCache, + astGetJSDocReadonlyTagNoCache, + astGetJSDocOverrideTagNoCache, + astGetJSDocDeprecatedTagNoCache, + AstModuleExportName, + astForEachChild, + AstSourceFile, + AstNodeArray, + astIsTypeParameterDeclaration, + astIsClassStaticBlockDeclaration, + astIsPropertySignature, + astIsPropertyDeclaration, + astIsPropertyAssignment, + astIsShorthandPropertyAssignment, + astIsMethodDeclaration, + astIsConstructorDeclaration, + astIsGetAccessorDeclaration, + astIsSetAccessorDeclaration, + astIsNamespaceExportDeclaration, + astIsAutoAccessorPropertyDeclaration, + astIsModifierLike, + AstStatement, + AstPrologueDirective, + AstExpressionStatement, + astGetJSDoc, + astIsDecorator, + astGetModifiers, + astCanHaveDecorators, + astIsExportDeclaration, + astIsNamespaceExport, + AstLiteralLikeNode, + AstStringLiteralLikeNode, + astIsBigIntLiteral, + AstStringLiteral, + astGetRawText, + astGetText, + AstRegularExpressionLiteral, + astGetCombinedNodeFlags, + AstAmbientModuleDeclaration, + AstModuleDeclaration, + astIsStringLiteral, + AstNonGlobalAmbientModuleDeclaration, + NonGlobalAmbientModuleDeclaration, + astIsFunctionLikeOrClassStaticBlockDeclaration, + astIsExternalModule, + astIsJSDocNode, + astIsBindingPattern, + astIsDeclaration, + astCanHaveName, } from "./_namespaces/ts.js"; +import { ReadonlyArrayView } from "./readonlyArray.js"; /** @internal */ export const resolvingEmptyArray: never[] = []; @@ -733,6 +835,17 @@ export function forEachAncestor(node: Node, callback: (n: Node) => T | undefi } } +/** @internal */ +export function astForEachAncestor(node: AstNode, callback: (n: AstNode) => T | undefined | "quit"): T | undefined { + while (node) { + const res = callback(node); + if (res === "quit") return undefined; + if (res !== undefined) return res; + if (astIsSourceFile(node)) return undefined; + node = node.parent; + } +} + /** * Calls `callback` for each entry in the map, returning the first truthy result. * Use `map.forEach` instead for normal iteration. @@ -791,7 +904,12 @@ export function usingSingleLineStringWriter(action: (writer: EmitTextWriter) => } /** @internal */ -export function getFullWidth(node: Node | AstNode): number { +export function getFullWidth(node: Node): number { + return astGetFullWidth(node.ast); +} + +/** @internal */ +export function astGetFullWidth(node: AstNode): number { return node.end - node.pos; } @@ -945,57 +1063,103 @@ export function hasChangesInResolutions( return false; } +// Returns true if this node contains a parse error anywhere underneath it. +/** + * @deprecated use {@link astContainsParseError} + * @internal + */ +export function containsParseError(node: Node): boolean { + return astContainsParseError(node.ast); +} + // Returns true if this node contains a parse error anywhere underneath it. /** @internal */ -export function containsParseError(node: Node | AstNode): boolean { - aggregateChildData(node instanceof AstNode ? node.node : node); // TODO(rbuckton): do not instantiate node +export function astContainsParseError(node: AstNode): boolean { + astAggregateChildData(node); return (node.flags & NodeFlags.ThisNodeOrAnySubNodesHasError) !== 0; } -function aggregateChildData(node: Node): void { +function astAggregateChildData(node: AstNode): void { if (!(node.flags & NodeFlags.HasAggregatedChildData)) { // A node is considered to contain a parse error if: // a) the parser explicitly marked that it had an error // b) any of it's children reported that it had an error. const thisNodeOrAnySubNodesHasError = ((node.flags & NodeFlags.ThisNodeHasError) !== 0) || - forEachChild(node, containsParseError); + astForEachChild(node, astContainsParseError); // If so, mark ourselves accordingly. if (thisNodeOrAnySubNodesHasError) { - (node as Mutable).flags |= NodeFlags.ThisNodeOrAnySubNodesHasError; + node.flags |= NodeFlags.ThisNodeOrAnySubNodesHasError; } // Also mark that we've propagated the child information to this node. This way we can // always consult the bit directly on this node without needing to check its children // again. - (node as Mutable).flags |= NodeFlags.HasAggregatedChildData; + node.flags |= NodeFlags.HasAggregatedChildData; } } -/** @internal */ +/** + * @deprecated use {@link astGetSourceFileOfNode} + * @internal + */ export function getSourceFileOfNode(node: Node): SourceFile; -/** @internal */ +/** + * @deprecated use {@link astGetSourceFileOfNode} + * @internal + */ export function getSourceFileOfNode(node: Node | undefined): SourceFile | undefined; -/** @internal */ export function getSourceFileOfNode(node: Node | undefined): SourceFile | undefined { + return astGetSourceFileOfNode(node?.ast)?.node; +} + +/** @internal */ +export function astGetSourceFileOfNode(node: AstNode): AstSourceFile; +/** @internal */ +export function astGetSourceFileOfNode(node: AstNode | undefined): AstSourceFile | undefined; +export function astGetSourceFileOfNode(node: AstNode | undefined): AstSourceFile | undefined { while (node && node.kind !== SyntaxKind.SourceFile) { node = node.parent; } - return node as SourceFile; + return node as AstSourceFile; } -/** @internal */ +/** + * @deprecated use {@link astGetSourceFileOfModule} + * @internal + */ export function getSourceFileOfModule(module: Symbol): SourceFile | undefined { return getSourceFileOfNode(module.valueDeclaration || getNonAugmentationDeclaration(module)); } /** @internal */ +export function astGetSourceFileOfModule(module: Symbol): AstSourceFile | undefined { + return astGetSourceFileOfNode(module.valueDeclaration?.ast || getNonAugmentationDeclaration(module)?.ast); +} + +/** + * @deprecated use {@link astIsPlainJsFile} + * @internal + */ export function isPlainJsFile(file: SourceFile | undefined, checkJs: boolean | undefined): boolean { - return !!file && (file.scriptKind === ScriptKind.JS || file.scriptKind === ScriptKind.JSX) && !file.checkJsDirective && checkJs === undefined; + return astIsPlainJsFile(file?.ast, checkJs); } /** @internal */ +export function astIsPlainJsFile(file: AstSourceFile | undefined, checkJs: boolean | undefined): boolean { + return !!file && (file.data.scriptKind === ScriptKind.JS || file.data.scriptKind === ScriptKind.JSX) && !file.data.checkJsDirective && checkJs === undefined; +} + +/** + * @deprecated use {@link astIsStatementWithLocals} + * @internal + */ export function isStatementWithLocals(node: Node): boolean { + return astIsStatementWithLocals(node.ast); +} + +/** @internal */ +export function astIsStatementWithLocals(node: AstNode): boolean { switch (node.kind) { case SyntaxKind.Block: case SyntaxKind.CaseBlock: @@ -1053,10 +1217,41 @@ export function getEndLinePosition(line: number, sourceFile: SourceFileLike): nu * Returns a value indicating whether a name is unique globally or within the current file. * Note: This does not consider whether a name appears as a free identifier or not, so at the expression `x.y` this includes both `x` and `y`. * + * @deprecated use {@link astIsFileLevelUniqueName} * @internal */ export function isFileLevelUniqueName(sourceFile: SourceFile, name: string, hasGlobalName?: PrintHandlers["hasGlobalName"]): boolean { - return !(hasGlobalName && hasGlobalName(name)) && !sourceFile.identifiers.has(name); + return astIsFileLevelUniqueName(sourceFile.ast, name, hasGlobalName); +} + +/** + * Returns a value indicating whether a name is unique globally or within the current file. + * Note: This does not consider whether a name appears as a free identifier or not, so at the expression `x.y` this includes both `x` and `y`. + * + * @internal + */ +export function astIsFileLevelUniqueName(sourceFile: AstSourceFile, name: string, hasGlobalName?: PrintHandlers["hasGlobalName"]): boolean { + return !(hasGlobalName && hasGlobalName(name)) && !sourceFile.data.identifiers.has(name); +} + +// Returns true if this node is missing from the actual source code. A 'missing' node is different +// from 'undefined/defined'. When a node is undefined (which can happen for optional nodes +// in the tree), it is definitely missing. However, a node may be defined, but still be +// missing. This happens whenever the parser knows it needs to parse something, but can't +// get anything in the source code that it expects at that location. For example: +// +// let a: ; +// +// Here, the Type in the Type-Annotation is not-optional (as there is a colon in the source +// code). So the parser will attempt to parse out a type, and will create an actual node. +// However, this node will be 'missing' in the sense that no actual source-code/tokens are +// contained within it. +/** + * @deprecated use {@link astNodeIsMissing} + * @internal + */ +export function nodeIsMissing(node: Node | undefined): boolean { + return astNodeIsMissing(node?.ast); } // Returns true if this node is missing from the actual source code. A 'missing' node is different @@ -1072,7 +1267,7 @@ export function isFileLevelUniqueName(sourceFile: SourceFile, name: string, hasG // However, this node will be 'missing' in the sense that no actual source-code/tokens are // contained within it. /** @internal */ -export function nodeIsMissing(node: Node | AstNode | undefined): boolean { +export function astNodeIsMissing(node: AstNode | undefined): boolean { if (node === undefined) { return true; } @@ -1080,33 +1275,50 @@ export function nodeIsMissing(node: Node | AstNode | undefined): boolean { return node.pos === node.end && node.pos >= 0 && node.kind !== SyntaxKind.EndOfFileToken; } -/** @internal */ -export function nodeIsPresent(node: Node | AstNode | undefined): boolean { +/** + * @deprecated use {@link astNodeIsPresent} + * @internal + */ +export function nodeIsPresent(node: Node | undefined): boolean { return !nodeIsMissing(node); } +/** @internal */ +export function astNodeIsPresent(node: AstNode | undefined): boolean { + return !astNodeIsMissing(node); +} + /** * Tests whether `child` is a grammar error on `parent`. + * @deprecated use {@link astIsGrammarError} * @internal */ export function isGrammarError(parent: Node, child: Node | NodeArray): boolean { - if (isTypeParameterDeclaration(parent)) return child === parent.expression; - if (isClassStaticBlockDeclaration(parent)) return child === parent.modifiers; - if (isPropertySignature(parent)) return child === parent.initializer; - if (isPropertyDeclaration(parent)) return child === parent.questionToken && isAutoAccessorPropertyDeclaration(parent); - if (isPropertyAssignment(parent)) return child === parent.modifiers || child === parent.questionToken || child === parent.exclamationToken || isGrammarErrorElement(parent.modifiers, child, isModifierLike); - if (isShorthandPropertyAssignment(parent)) return child === parent.equalsToken || child === parent.modifiers || child === parent.questionToken || child === parent.exclamationToken || isGrammarErrorElement(parent.modifiers, child, isModifierLike); - if (isMethodDeclaration(parent)) return child === parent.exclamationToken; - if (isConstructorDeclaration(parent)) return child === parent.typeParameters || child === parent.type || isGrammarErrorElement(parent.typeParameters, child, isTypeParameterDeclaration); - if (isGetAccessorDeclaration(parent)) return child === parent.typeParameters || isGrammarErrorElement(parent.typeParameters, child, isTypeParameterDeclaration); - if (isSetAccessorDeclaration(parent)) return child === parent.typeParameters || child === parent.type || isGrammarErrorElement(parent.typeParameters, child, isTypeParameterDeclaration); - if (isNamespaceExportDeclaration(parent)) return child === parent.modifiers || isGrammarErrorElement(parent.modifiers, child, isModifierLike); + return astIsGrammarError(parent.ast, child.ast); +} + +/** + * Tests whether `child` is a grammar error on `parent`. + * @internal + */ +export function astIsGrammarError(parent: AstNode, child: AstNode | AstNodeArray): boolean { + if (astIsTypeParameterDeclaration(parent)) return child === parent.data.expression; + if (astIsClassStaticBlockDeclaration(parent)) return child === parent.data.modifiers; + if (astIsPropertySignature(parent)) return child === parent.data.initializer; + if (astIsPropertyDeclaration(parent)) return child === parent.data.questionToken && astIsAutoAccessorPropertyDeclaration(parent); + if (astIsPropertyAssignment(parent)) return child === parent.data.modifiers || child === parent.data.questionToken || child === parent.data.exclamationToken || astIsGrammarErrorElement(parent.data.modifiers, child, astIsModifierLike); + if (astIsShorthandPropertyAssignment(parent)) return child === parent.data.equalsToken || child === parent.data.modifiers || child === parent.data.questionToken || child === parent.data.exclamationToken || astIsGrammarErrorElement(parent.data.modifiers, child, astIsModifierLike); + if (astIsMethodDeclaration(parent)) return child === parent.data.exclamationToken; + if (astIsConstructorDeclaration(parent)) return child === parent.data.typeParameters || child === parent.data.type || astIsGrammarErrorElement(parent.data.typeParameters, child, astIsTypeParameterDeclaration); + if (astIsGetAccessorDeclaration(parent)) return child === parent.data.typeParameters || astIsGrammarErrorElement(parent.data.typeParameters, child, astIsTypeParameterDeclaration); + if (astIsSetAccessorDeclaration(parent)) return child === parent.data.typeParameters || child === parent.data.type || astIsGrammarErrorElement(parent.data.typeParameters, child, astIsTypeParameterDeclaration); + if (astIsNamespaceExportDeclaration(parent)) return child === parent.data.modifiers || astIsGrammarErrorElement(parent.data.modifiers, child, astIsModifierLike); return false; } -function isGrammarErrorElement(nodeArray: NodeArray | undefined, child: Node | NodeArray, isElement: (node: Node) => node is T) { - if (!nodeArray || isArray(child) || !isElement(child)) return false; - return contains(nodeArray, child); +function astIsGrammarErrorElement(nodeArray: AstNodeArray | undefined, child: AstNode | AstNodeArray, isElement: (node: AstNode) => node is T) { + if (!nodeArray || child instanceof AstNodeArray || !isElement(child)) return false; + return contains(nodeArray.items, child); } function insertStatementsAfterPrologue(to: T[], from: readonly T[] | undefined, isPrologueDirective: (node: Node) => boolean): T[] { @@ -1122,6 +1334,19 @@ function insertStatementsAfterPrologue(to: T[], from: reado return to; } +function astInsertStatementsAfterPrologue(to: T[], from: readonly T[] | undefined, isPrologueDirective: (node: AstNode) => boolean): T[] { + if (from === undefined || from.length === 0) return to; + let statementIndex = 0; + // skip all prologue directives to insert at the correct position + for (; statementIndex < to.length; ++statementIndex) { + if (!isPrologueDirective(to[statementIndex])) { + break; + } + } + to.splice(statementIndex, 0, ...from); + return to; +} + function insertStatementAfterPrologue(to: T[], statement: T | undefined, isPrologueDirective: (node: Node) => boolean): T[] { if (statement === undefined) return to; let statementIndex = 0; @@ -1135,27 +1360,63 @@ function insertStatementAfterPrologue(to: T[], statement: T return to; } +function astInsertStatementAfterPrologue(to: T[], statement: T | undefined, isPrologueDirective: (node: AstNode) => boolean): T[] { + if (statement === undefined) return to; + let statementIndex = 0; + // skip all prologue directives to insert at the correct position + for (; statementIndex < to.length; ++statementIndex) { + if (!isPrologueDirective(to[statementIndex])) { + break; + } + } + to.splice(statementIndex, 0, statement); + return to; +} + function isAnyPrologueDirective(node: Node) { - return isPrologueDirective(node) || !!(getEmitFlags(node) & EmitFlags.CustomPrologue); + return astIsAnyPrologueDirective(node.ast); +} + +function astIsAnyPrologueDirective(node: AstNode) { + return astIsPrologueDirective(node) || !!(astGetEmitFlags(node) & EmitFlags.CustomPrologue); } /** * Prepends statements to an array while taking care of prologue directives. * + * @deprecated use {@link astInsertStatementsAfterStandardPrologue} * @internal */ export function insertStatementsAfterStandardPrologue(to: T[], from: readonly T[] | undefined): T[] { return insertStatementsAfterPrologue(to, from, isPrologueDirective); } -/** @internal */ +/** + * Prepends statements to an array while taking care of prologue directives. + * + * @internal + */ +export function astInsertStatementsAfterStandardPrologue(to: T[], from: readonly T[] | undefined): T[] { + return astInsertStatementsAfterPrologue(to, from, astIsPrologueDirective); +} + +/** + * @deprecated use {@link astInsertStatementsAfterCustomPrologue} + * @internal + */ export function insertStatementsAfterCustomPrologue(to: T[], from: readonly T[] | undefined): T[] { return insertStatementsAfterPrologue(to, from, isAnyPrologueDirective); } +/** @internal */ +export function astInsertStatementsAfterCustomPrologue(to: T[], from: readonly T[] | undefined): T[] { + return astInsertStatementsAfterPrologue(to, from, astIsAnyPrologueDirective); +} + /** * Prepends statements to an array while taking care of prologue directives. * + * @deprecated use {@link astInsertStatementAfterStandardPrologue} * @internal * @knipignore */ @@ -1163,11 +1424,29 @@ export function insertStatementAfterStandardPrologue(to: T[ return insertStatementAfterPrologue(to, statement, isPrologueDirective); } -/** @internal */ +/** + * Prepends statements to an array while taking care of prologue directives. + * + * @internal + * @knipignore + */ +export function astInsertStatementAfterStandardPrologue(to: T[], statement: T | undefined): T[] { + return astInsertStatementAfterPrologue(to, statement, astIsPrologueDirective); +} + +/** + * @deprecated use {@link astInsertStatementAfterCustomPrologue} + * @internal + */ export function insertStatementAfterCustomPrologue(to: T[], statement: T | undefined): T[] { return insertStatementAfterPrologue(to, statement, isAnyPrologueDirective); } +/** @internal */ +export function astInsertStatementAfterCustomPrologue(to: T[], statement: T | undefined): T[] { + return astInsertStatementAfterPrologue(to, statement, astIsAnyPrologueDirective); +} + /** * Determine if the given comment is a triple-slash * @@ -1230,21 +1509,39 @@ export function createCommentDirectivesMap(sourceFile: SourceFile, commentDirect } } -/** @internal */ +/** + * @deprecated use {@link astGetTokenPosOfNode} + * @internal + */ export function getTokenPosOfNode(node: Node, sourceFile?: SourceFileLike, includeJsDoc?: boolean): number { + return astGetTokenPosOfNode(node.ast, sourceFile, includeJsDoc); +} + +function getTextOfContainingSourceFile(node: AstNode, sourceFile: SourceFileLike | AstSourceFile | undefined) { + if (sourceFile instanceof AstNode) { + return sourceFile.data.text; + } + return sourceFile?.text ?? astGetSourceFileOfNode(node).data.text; +} + +/** @internal */ +export function astGetTokenPosOfNode(node: AstNode, sourceFile?: SourceFileLike | AstSourceFile, includeJsDoc?: boolean): number { // With nodes that have no width (i.e. 'Missing' nodes), we actually *don't* // want to skip trivia because this will launch us forward to the next token. - if (nodeIsMissing(node)) { + if (astNodeIsMissing(node)) { return node.pos; } - if (isJSDocNode(node) || node.kind === SyntaxKind.JsxText) { + if (astIsJSDocNode(node) || node.kind === SyntaxKind.JsxText) { // JsxText cannot actually contain comments, even though the scanner will think it sees comments - return skipTrivia((sourceFile ?? getSourceFileOfNode(node)).text, node.pos, /*stopAfterLineBreak*/ false, /*stopAtComments*/ true); + return skipTrivia(getTextOfContainingSourceFile(node, sourceFile), node.pos, /*stopAfterLineBreak*/ false, /*stopAtComments*/ true); // TODO(rbuckton): don't instantiate `.node` } - if (includeJsDoc && hasJSDocNodes(node)) { - return getTokenPosOfNode(node.jsDoc![0], sourceFile); + if (includeJsDoc) { + const jsDoc = firstOrUndefined(astGetJSDoc(node)); + if (jsDoc) { + return astGetTokenPosOfNode(jsDoc.ast, sourceFile); + } } // For a syntax list, it is possible that one of its children has JSDocComment nodes, while @@ -1252,66 +1549,117 @@ export function getTokenPosOfNode(node: Node, sourceFile?: SourceFileLike, inclu // trivia for the list, we may have skipped the JSDocComment as well. So we should process its // first child to determine the actual position of its first token. if (node.kind === SyntaxKind.SyntaxList) { - sourceFile ??= getSourceFileOfNode(node); - const first = firstOrUndefined(getNodeChildren(node, sourceFile)); + sourceFile ??= astGetSourceFileOfNode(node); + if (sourceFile instanceof AstNode) { + sourceFile = sourceFile.node; // TODO(rbuckton): don't instantiate `.node` + } + const first = firstOrUndefined(getNodeChildren(node.node, sourceFile)); // TODO(rbuckton): don't instantiate `.node` if (first) { - return getTokenPosOfNode(first, sourceFile, includeJsDoc); + return astGetTokenPosOfNode(first.ast, sourceFile, includeJsDoc); } } return skipTrivia( - (sourceFile ?? getSourceFileOfNode(node)).text, + getTextOfContainingSourceFile(node, sourceFile), node.pos, /*stopAfterLineBreak*/ false, /*stopAtComments*/ false, - isInJSDoc(node), + astIsInJSDoc(node), ); } -/** @internal */ +/** + * @deprecated use {@link astGetNonDecoratorTokenPosOfNode} + * @internal + */ export function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFileLike): number { - const lastDecorator = !nodeIsMissing(node) && canHaveModifiers(node) ? findLast(node.modifiers, isDecorator) : undefined; + return astGetNonDecoratorTokenPosOfNode(node.ast, sourceFile); +} + +/** @internal */ +export function astGetNonDecoratorTokenPosOfNode(node: AstNode, sourceFile?: AstSourceFile | SourceFileLike): number { + const lastDecorator = !astNodeIsMissing(node) && astCanHaveDecorators(node) ? findLast(astGetModifiers(node)?.items, astIsDecorator) : undefined; if (!lastDecorator) { - return getTokenPosOfNode(node, sourceFile); + return astGetTokenPosOfNode(node, sourceFile); } - return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, lastDecorator.end); + return skipTrivia(getTextOfContainingSourceFile(node, sourceFile), lastDecorator.end); } -/** @internal */ +/** + * @deprecated use {@link astGetNonModifierTokenPosOfNode} + * @internal + */ export function getNonModifierTokenPosOfNode(node: Node, sourceFile?: SourceFileLike): number { - const lastModifier = !nodeIsMissing(node) && canHaveModifiers(node) && node.modifiers ? last(node.modifiers) : undefined; + return astGetNonModifierTokenPosOfNode(node.ast, sourceFile); +} + +/** @internal */ +export function astGetNonModifierTokenPosOfNode(node: AstNode, sourceFile?: AstSourceFile | SourceFileLike): number { + const lastModifier = !astNodeIsMissing(node) ? lastOrUndefined(astGetModifiers(node)?.items) : undefined; if (!lastModifier) { - return getTokenPosOfNode(node, sourceFile); + return astGetTokenPosOfNode(node, sourceFile); } - return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, lastModifier.end); + return skipTrivia(getTextOfContainingSourceFile(node, sourceFile), lastModifier.end); } -/** @internal */ +/** + * @deprecated use {@link astGetSourceTextOfNodeFromSourceFile} + * @internal + */ export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node, includeTrivia = false): string { - return getTextOfNodeFromSourceText(sourceFile.text, node, includeTrivia); + return astGetSourceTextOfNodeFromSourceFile(sourceFile.ast, node.ast, includeTrivia); +} + +/** @internal */ +export function astGetSourceTextOfNodeFromSourceFile(sourceFile: AstSourceFile, node: AstNode, includeTrivia = false): string { + return astGetTextOfNodeFromSourceText(sourceFile.data.text, node, includeTrivia); } function isJSDocTypeExpressionOrChild(node: Node | AstNode): boolean { return node instanceof AstNode ? - !!findAncestor(node, isAstJSDocTypeExpression) : + !!findAncestor(node, astIsJSDocTypeExpression) : !!findAncestor(node, isJSDocTypeExpression); } -/** @internal */ +/** + * @deprecated use {@link astIsExportNamespaceAsDefaultDeclaration} + * @internal + */ export function isExportNamespaceAsDefaultDeclaration(node: Node): boolean { - return !!(isExportDeclaration(node) && node.exportClause && isNamespaceExport(node.exportClause) && moduleExportNameIsDefault(node.exportClause.name)); + return astIsExportNamespaceAsDefaultDeclaration(node.ast); } /** @internal */ +export function astIsExportNamespaceAsDefaultDeclaration(node: AstNode): boolean { + return !!(astIsExportDeclaration(node) && node.data.exportClause && astIsNamespaceExport(node.data.exportClause) && astModuleExportNameIsDefault(node.data.exportClause.data.name)); +} + +/** + * @deprecated use {@link astModuleExportNameTextUnescaped} + * @internal + */ export function moduleExportNameTextUnescaped(node: ModuleExportName): string { - return node.kind === SyntaxKind.StringLiteral ? node.text : unescapeLeadingUnderscores(node.escapedText); + return astModuleExportNameTextUnescaped(node.ast); } /** @internal */ +export function astModuleExportNameTextUnescaped(node: AstModuleExportName): string { + return node.kind === SyntaxKind.StringLiteral ? node.data.text : unescapeLeadingUnderscores(node.data.escapedText); +} + +/** + * @deprecated use {@link astModuleExportNameTextEscaped} + * @internal + */ export function moduleExportNameTextEscaped(node: ModuleExportName): __String { - return node.kind === SyntaxKind.StringLiteral ? escapeLeadingUnderscores(node.text) : node.escapedText; + return astModuleExportNameTextEscaped(node.ast); +} + +/** @internal */ +export function astModuleExportNameTextEscaped(node: AstModuleExportName): __String { + return node.kind === SyntaxKind.StringLiteral ? escapeLeadingUnderscores(node.data.text) : node.data.escapedText; } /** @@ -1319,14 +1667,29 @@ export function moduleExportNameTextEscaped(node: ModuleExportName): __String { * to turn "__" into "___" or vice versa, since they will never be equal in * either case. So we can ignore those cases to improve performance. * + * @deprecated use {@link astModuleExportNameIsDefault} * @internal */ export function moduleExportNameIsDefault(node: ModuleExportName): boolean { - return (node.kind === SyntaxKind.StringLiteral ? node.text : node.escapedText) === InternalSymbolName.Default; + return astModuleExportNameIsDefault(node.ast); } -/** @internal */ -export function getTextOfNodeFromSourceText(sourceText: string, node: Node | AstNode, includeTrivia = false): string { +/** + * Equality checks against a keyword without underscores don't need to bother + * to turn "__" into "___" or vice versa, since they will never be equal in + * either case. So we can ignore those cases to improve performance. + * + * @internal + */ +export function astModuleExportNameIsDefault(node: AstModuleExportName): boolean { + return (node.kind === SyntaxKind.StringLiteral ? node.data.text : node.data.escapedText) === InternalSymbolName.Default; +} + +/** + * @deprecated use {@link astGetTextOfNodeFromSourceText} + * @internal + */ +export function getTextOfNodeFromSourceText(sourceText: string, node: Node, includeTrivia = false): string { if (nodeIsMissing(node)) { return ""; } @@ -1342,30 +1705,79 @@ export function getTextOfNodeFromSourceText(sourceText: string, node: Node | Ast } /** @internal */ +export function astGetTextOfNodeFromSourceText(sourceText: string, node: AstNode, includeTrivia = false): string { + if (astNodeIsMissing(node)) { + return ""; + } + + let text = sourceText.substring(includeTrivia ? node.pos : skipTrivia(sourceText, node.pos), node.end); + + if (isJSDocTypeExpressionOrChild(node)) { + // strip space + asterisk at line start + text = text.split(/\r\n|\n|\r/).map(line => line.replace(/^\s*\*/, "").trimStart()).join("\n"); + } + + return text; +} + +/** + * @deprecated use {@link astGetTextOfNode} + * @internal + */ export function getTextOfNode(node: Node, includeTrivia = false): string { - return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node, includeTrivia); + return astGetTextOfNode(node.ast, includeTrivia); +} + +/** @internal */ +export function astGetTextOfNode(node: AstNode, includeTrivia = false): string { + return astGetSourceTextOfNodeFromSourceFile(astGetSourceFileOfNode(node), node, includeTrivia); } function getPos(range: Node) { - return range.pos; + return astGetPos(range.ast); } /** * Note: it is expected that the `nodeArray` and the `node` are within the same file. * For example, searching for a `SourceFile` in a `SourceFile[]` wouldn't work. * + * @deprecated use {@link astIndexOfNode} * @internal */ export function indexOfNode(nodeArray: readonly Node[], node: Node): number { return binarySearch(nodeArray, node, getPos, compareValues); } +function astGetPos(range: AstNode) { + return range.pos; +} + +/** + * Note: it is expected that the `nodeArray` and the `node` are within the same file. + * For example, searching for a `SourceFile` in a `SourceFile[]` wouldn't work. + * + * @internal + */ +export function astIndexOfNode(nodeArray: readonly AstNode[], node: AstNode): number { + return binarySearch(nodeArray, node, astGetPos, compareValues); +} + /** * Gets flags that control emit behavior of a node. * + * @deprecated use {@link astGetEmitFlags} * @internal */ export function getEmitFlags(node: Node): EmitFlags { + return astGetEmitFlags(node.ast); +} + +/** + * Gets flags that control emit behavior of a node. + * + * @internal + */ +export function astGetEmitFlags(node: AstNode): EmitFlags { const emitNode = node.emitNode; return emitNode && emitNode.flags || 0; } @@ -1373,9 +1785,19 @@ export function getEmitFlags(node: Node): EmitFlags { /** * Gets flags that control emit behavior of a node. * + * @deprecated use {@link astGetInternalEmitFlags} * @internal */ export function getInternalEmitFlags(node: Node): InternalEmitFlags { + return astGetInternalEmitFlags(node.ast); +} + +/** + * Gets flags that control emit behavior of a node. + * + * @internal + */ +export function astGetInternalEmitFlags(node: AstNode): InternalEmitFlags { const emitNode = node.emitNode; return emitNode && emitNode.internalFlags || 0; } @@ -1912,12 +2334,37 @@ export const enum GetLiteralTextFlags { AllowNumericSeparator = 1 << 3, } -/** @internal */ +/** + * @deprecated use {@link astGetLiteralText} + * @internal + */ export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile | undefined, flags: GetLiteralTextFlags): string { + return astGetLiteralText(node.ast, sourceFile?.ast, flags); +} + +function astCanUseOriginalText(node: AstLiteralLikeNode, flags: GetLiteralTextFlags): boolean { + if (astNodeIsSynthesized(node) || !node.parent || (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && (node as AstStringLiteralLikeNode).data.isUnterminated)) { + return false; + } + + if (astIsNumericLiteral(node)) { + if (node.data.numericLiteralFlags & TokenFlags.IsInvalid) { + return false; + } + if (node.data.numericLiteralFlags & TokenFlags.ContainsSeparator) { + return !!(flags & GetLiteralTextFlags.AllowNumericSeparator); + } + } + + return !astIsBigIntLiteral(node); +} + +/** @internal */ +export function astGetLiteralText(node: AstLiteralLikeNode, sourceFile: AstSourceFile | undefined, flags: GetLiteralTextFlags): string { // If we don't need to downlevel and we can reach the original source text using // the node's parent reference, then simply get the text as it was originally written. - if (sourceFile && canUseOriginalText(node, flags)) { - return getSourceTextOfNodeFromSourceFile(sourceFile, node); + if (sourceFile && astCanUseOriginalText(node, flags)) { + return astGetSourceTextOfNodeFromSourceFile(sourceFile, node); } // If we can't reach the original source text, use the canonical form if it's a number, @@ -1925,13 +2372,13 @@ export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile | u switch (node.kind) { case SyntaxKind.StringLiteral: { const escapeText = flags & GetLiteralTextFlags.JsxAttributeEscape ? escapeJsxAttributeString : - flags & GetLiteralTextFlags.NeverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? escapeString : + flags & GetLiteralTextFlags.NeverAsciiEscape || (astGetEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? escapeString : escapeNonAsciiString; - if ((node as StringLiteral).singleQuote) { - return "'" + escapeText(node.text, CharacterCodes.singleQuote) + "'"; + if ((node as AstStringLiteral).data.singleQuote) { + return "'" + escapeText(node.data.text, CharacterCodes.singleQuote) + "'"; } else { - return '"' + escapeText(node.text, CharacterCodes.doubleQuote) + '"'; + return '"' + escapeText(node.data.text, CharacterCodes.doubleQuote) + '"'; } } case SyntaxKind.NoSubstitutionTemplateLiteral: @@ -1940,10 +2387,10 @@ export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile | u case SyntaxKind.TemplateTail: { // If a NoSubstitutionTemplateLiteral appears to have a substitution in it, the original text // had to include a backslash: `not \${a} substitution`. - const escapeText = flags & GetLiteralTextFlags.NeverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? escapeString : + const escapeText = flags & GetLiteralTextFlags.NeverAsciiEscape || (astGetEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? escapeString : escapeNonAsciiString; - const rawText = (node as TemplateLiteralLikeNode).rawText ?? escapeTemplateSubstitution(escapeText(node.text, CharacterCodes.backtick)); + const rawText = astGetRawText(node) ?? escapeTemplateSubstitution(escapeText(astGetText(node), CharacterCodes.backtick)); switch (node.kind) { case SyntaxKind.NoSubstitutionTemplateLiteral: return "`" + rawText + "`"; @@ -1958,34 +2405,17 @@ export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile | u } case SyntaxKind.NumericLiteral: case SyntaxKind.BigIntLiteral: - return node.text; + return node.data.text; case SyntaxKind.RegularExpressionLiteral: - if (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && (node as RegularExpressionLiteral).isUnterminated) { - return node.text + (node.text.charCodeAt(node.text.length - 1) === CharacterCodes.backslash ? " /" : "/"); + if (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && (node as AstRegularExpressionLiteral).data.isUnterminated) { + return node.data.text + (node.data.text.charCodeAt(node.data.text.length - 1) === CharacterCodes.backslash ? " /" : "/"); } - return node.text; + return node.data.text; } return Debug.fail(`Literal kind '${node.kind}' not accounted for.`); } -function canUseOriginalText(node: LiteralLikeNode, flags: GetLiteralTextFlags): boolean { - if (nodeIsSynthesized(node) || !node.parent || (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && (node as StringLiteralLikeNode).isUnterminated)) { - return false; - } - - if (isNumericLiteral(node)) { - if (node.numericLiteralFlags & TokenFlags.IsInvalid) { - return false; - } - if (node.numericLiteralFlags & TokenFlags.ContainsSeparator) { - return !!(flags & GetLiteralTextFlags.AllowNumericSeparator); - } - } - - return !isBigIntLiteral(node); -} - /** @internal */ export function getTextOfConstantValue(value: string | number): string { return isString(value) ? `"${escapeString(value)}"` : "" + value; @@ -1998,31 +2428,66 @@ export function makeIdentifierFromModuleName(moduleName: string): string { return getBaseFileName(moduleName).replace(/^(\d)/, "_$1").replace(/\W/g, "_"); } -/** @internal */ +/** + * @deprecated Use {@link astIsBlockOrCatchScoped} + * @internal + */ export function isBlockOrCatchScoped(declaration: Declaration): boolean { - return (getCombinedNodeFlags(declaration) & NodeFlags.BlockScoped) !== 0 || - isCatchClauseVariableDeclarationOrBindingElement(declaration); + return astIsBlockOrCatchScoped(declaration.ast); } /** @internal */ +export function astIsBlockOrCatchScoped(declaration: AstDeclaration): boolean { + return (astGetCombinedNodeFlags(declaration) & NodeFlags.BlockScoped) !== 0 || + astIsCatchClauseVariableDeclarationOrBindingElement(declaration); +} + +/** + * @deprecated Use {@link astIsCatchClauseVariableDeclarationOrBindingElement} + * @internal + */ export function isCatchClauseVariableDeclarationOrBindingElement(declaration: Declaration): boolean { - const node = getRootDeclaration(declaration); - return node.kind === SyntaxKind.VariableDeclaration && node.parent.kind === SyntaxKind.CatchClause; + return astIsCatchClauseVariableDeclarationOrBindingElement(declaration.ast); } /** @internal */ +export function astIsCatchClauseVariableDeclarationOrBindingElement(declaration: AstDeclaration): boolean { + const node = astGetRootDeclaration(declaration); + return node.kind === SyntaxKind.VariableDeclaration && node.parent.kind === SyntaxKind.CatchClause; +} + +/** + * @deprecated Use {@link astIsAmbientModule} + * @internal + */ export function isAmbientModule(node: Node): node is AmbientModuleDeclaration { - return isModuleDeclaration(node) && (node.name.kind === SyntaxKind.StringLiteral || isGlobalScopeAugmentation(node)); + return astIsAmbientModule(node.ast); } /** @internal */ +export function astIsAmbientModule(node: AstNode): node is AstAmbientModuleDeclaration { + return astIsModuleDeclaration(node) && (node.data.name.kind === SyntaxKind.StringLiteral || astIsGlobalScopeAugmentation(node)); +} + +/** + * @deprecated Use {@link astIsNonGlobalAmbientModule} + * @internal + */ export function isModuleWithStringLiteralName(node: Node): node is ModuleDeclaration { - return isModuleDeclaration(node) && node.name.kind === SyntaxKind.StringLiteral; + return astIsNonGlobalAmbientModule(node.ast); +} + +/** + * @deprecated Use {@link astIsNonGlobalAmbientModule} + * @internal + */ +export function isNonGlobalAmbientModule(node: Node): node is NonGlobalAmbientModuleDeclaration { + return astIsNonGlobalAmbientModule(node.ast); } /** @internal */ -export function isNonGlobalAmbientModule(node: Node): node is ModuleDeclaration & { name: StringLiteral; } { - return isModuleDeclaration(node) && isStringLiteral(node.name); +export function astIsNonGlobalAmbientModule(node: AstNode): node is AstNonGlobalAmbientModuleDeclaration { + return astIsModuleDeclaration(node) && astIsStringLiteral(node.data.name); } /** @@ -2031,8 +2496,8 @@ export function isNonGlobalAmbientModule(node: Node): node is ModuleDeclaration * 2. A Javascript declaration, which is: * An identifier in a nested property access expression: Y in `X.Y.Z = { ... }` */ -function isEffectiveModuleDeclaration(node: Node) { - return isModuleDeclaration(node) || isIdentifier(node); +function astIsEffectiveModuleDeclaration(node: AstNode) { + return astIsModuleDeclaration(node) || astIsIdentifier(node); } /** @@ -2041,41 +2506,73 @@ function isEffectiveModuleDeclaration(node: Node) { * @internal */ export function isShorthandAmbientModuleSymbol(moduleSymbol: Symbol): boolean { - return isShorthandAmbientModule(moduleSymbol.valueDeclaration); + return isShorthandAmbientModule(moduleSymbol.astValueDeclaration); } -function isShorthandAmbientModule(node: Node | undefined): boolean { +function isShorthandAmbientModule(node: AstNode | undefined): boolean { // The only kind of module that can be missing a body is a shorthand ambient module. - return !!node && node.kind === SyntaxKind.ModuleDeclaration && (!(node as ModuleDeclaration).body); + return !!node && node.kind === SyntaxKind.ModuleDeclaration && (!(node as AstModuleDeclaration).data.body); } -/** @internal */ +/** + * @deprecated Use {@link astIsBlockScopedContainerTopLevel} + * @internal + */ export function isBlockScopedContainerTopLevel(node: Node): boolean { + return astIsBlockScopedContainerTopLevel(node.ast); +} + +/** @internal */ +export function astIsBlockScopedContainerTopLevel(node: AstNode): boolean { return node.kind === SyntaxKind.SourceFile || node.kind === SyntaxKind.ModuleDeclaration || - isFunctionLikeOrClassStaticBlockDeclaration(node); + astIsFunctionLikeOrClassStaticBlockDeclaration(node); } -/** @internal */ +/** + * @deprecated Use {@link astIsGlobalScopeAugmentation} + * @internal + */ export function isGlobalScopeAugmentation(module: ModuleDeclaration): boolean { - return !!(module.flags & NodeFlags.GlobalAugmentation); + return astIsGlobalScopeAugmentation(module.ast); } /** @internal */ +export function astIsGlobalScopeAugmentation(module: AstModuleDeclaration): boolean { + return !!(module.flags & NodeFlags.GlobalAugmentation); +} + +/** + * @deprecated Use {@link astIsExternalModuleAugmentation} + * @internal + */ export function isExternalModuleAugmentation(node: Node): node is AmbientModuleDeclaration { return isAmbientModule(node) && isModuleAugmentationExternal(node); } /** @internal */ +export function astIsExternalModuleAugmentation(node: AstNode): node is AstAmbientModuleDeclaration { + return astIsAmbientModule(node) && astIsModuleAugmentationExternal(node); +} + +/** + * @deprecated Use {@link astIsModuleAugmentationExternal} + * @internal + */ export function isModuleAugmentationExternal(node: AmbientModuleDeclaration): boolean { + return astIsModuleAugmentationExternal(node.ast); +} + +/** @internal */ +export function astIsModuleAugmentationExternal(node: AstAmbientModuleDeclaration): boolean { // external module augmentation is a ambient module declaration that is either: // - defined in the top level scope and source file is an external module // - defined inside ambient module declaration located in the top level scope and source file not an external module switch (node.parent.kind) { case SyntaxKind.SourceFile: - return isExternalModule(node.parent); + return astIsExternalModule(node.parent); case SyntaxKind.ModuleBlock: - return isAmbientModule(node.parent.parent) && isSourceFile(node.parent.parent.parent) && !isExternalModule(node.parent.parent.parent); + return astIsAmbientModule(node.parent.parent) && astIsSourceFile(node.parent.parent.parent) && !astIsExternalModule(node.parent.parent.parent); } return false; } @@ -2085,13 +2582,26 @@ export function getNonAugmentationDeclaration(symbol: Symbol): Declaration | und return symbol.declarations?.find(d => !isExternalModuleAugmentation(d) && !(isModuleDeclaration(d) && isGlobalScopeAugmentation(d))); } +/** @internal */ +export function astGetNonAugmentationDeclaration(symbol: Symbol): AstDeclaration | undefined { + return symbol.astDeclarations?.find(d => !astIsExternalModuleAugmentation(d) && !(astIsModuleDeclaration(d) && astIsGlobalScopeAugmentation(d))); +} + function isCommonJSContainingModuleKind(kind: ModuleKind) { return kind === ModuleKind.CommonJS || kind === ModuleKind.Node16 || kind === ModuleKind.NodeNext; } -/** @internal */ +/** + * @deprecated Use {@link astIsEffectiveExternalModule} + * @internal + */ export function isEffectiveExternalModule(node: SourceFile, compilerOptions: CompilerOptions): boolean { - return isExternalModule(node) || (isCommonJSContainingModuleKind(getEmitModuleKind(compilerOptions)) && !!node.commonJsModuleIndicator); + return astIsEffectiveExternalModule(node.ast, compilerOptions); +} + +/** @internal */ +export function astIsEffectiveExternalModule(node: AstSourceFile, compilerOptions: CompilerOptions): boolean { + return astIsExternalModule(node) || (isCommonJSContainingModuleKind(getEmitModuleKind(compilerOptions)) && !!node.data.commonJsModuleIndicator); } /** @@ -2655,10 +3165,18 @@ export function isLiteralImportTypeNode(n: Node): n is LiteralImportTypeNode { return isImportTypeNode(n) && isLiteralTypeNode(n.argument) && isStringLiteral(n.argument.literal); } -/** @internal */ +/** + * @deprecated use {@link astIsPrologueDirective} + * @internal + */ export function isPrologueDirective(node: Node): node is PrologueDirective { + return astIsPrologueDirective(node.ast); +} + +/** @internal */ +export function astIsPrologueDirective(node: AstNode): node is AstPrologueDirective { return node.kind === SyntaxKind.ExpressionStatement - && (node as ExpressionStatement).expression.kind === SyntaxKind.StringLiteral; + && (node as AstExpressionStatement).data.expression.kind === SyntaxKind.StringLiteral; } /** @internal */ @@ -2920,6 +3438,11 @@ export function getMembersOfDeclaration(node: Declaration): NodeArray> { + return (astIsPropertyAccessExpression(node) || astIsLiteralLikeElementAccess(node)) + && astIsModuleIdentifier(node.data.expression) + && astGetElementOrPropertyAccessName(node) === "exports"; } /// Given a BinaryExpression, returns SpecialPropertyAssignmentKind for the various kinds of property /// assignments we treat as special in the binder /** @internal */ export function getAssignmentDeclarationKind(expr: BinaryExpression | CallExpression): AssignmentDeclarationKind { - const special = getAssignmentDeclarationKindWorker(expr); - return special === AssignmentDeclarationKind.Property || isInJSFile(expr) ? special : AssignmentDeclarationKind.None; + return astGetAssignmentDeclarationKind(expr.ast); +} + +/// Given a BinaryExpression, returns SpecialPropertyAssignmentKind for the various kinds of property +/// assignments we treat as special in the binder +/** @internal */ +export function astGetAssignmentDeclarationKind(expr: AstBinaryExpression | AstCallExpression): AssignmentDeclarationKind { + const special = astGetAssignmentDeclarationKindWorker(expr); + return special === AssignmentDeclarationKind.Property || astIsInJSFile(expr) ? special : AssignmentDeclarationKind.None; } /** @internal */ export function isBindableObjectDefinePropertyCall(expr: CallExpression): expr is BindableObjectDefinePropertyCall { - return length(expr.arguments) === 3 && - isPropertyAccessExpression(expr.expression) && - isIdentifier(expr.expression.expression) && - idText(expr.expression.expression) === "Object" && - idText(expr.expression.name) === "defineProperty" && - isStringOrNumericLiteralLike(expr.arguments[1]) && - isBindableStaticNameExpression(expr.arguments[0], /*excludeThisKeyword*/ true); + return astIsBindableObjectDefinePropertyCall(expr.ast); +} + +/** @internal */ +export function astIsBindableObjectDefinePropertyCall(expr: AstCallExpression): expr is AstBindableObjectDefinePropertyCall { + return length(expr.data.arguments.items) === 3 && + astIsPropertyAccessExpression(expr.data.expression) && + astIsIdentifier(expr.data.expression.data.expression) && + astIdText(expr.data.expression.data.expression) === "Object" && + astIdText(expr.data.expression.data.name) === "defineProperty" && + astIsStringOrNumericLiteralLike(expr.data.arguments.items[1]) && + astIsBindableStaticNameExpression(expr.data.arguments.items[0], /*excludeThisKeyword*/ true); } /** @@ -4055,7 +4655,14 @@ function isLiteralLikeAccess(node: Node): node is LiteralLikeElementAccessExpres * x[0] OR x['a'] OR x[Symbol.y] */ function isLiteralLikeElementAccess(node: Node): node is LiteralLikeElementAccessExpression { - return isElementAccessExpression(node) && isStringOrNumericLiteralLike(node.argumentExpression); + return astIsLiteralLikeElementAccess(node.ast); +} + +/** + * x[0] OR x['a'] OR x[Symbol.y] + */ +function astIsLiteralLikeElementAccess(node: AstNode): node is AstLiteralLikeElementAccessExpression { + return astIsElementAccessExpression(node) && astIsStringOrNumericLiteralLike(node.data.argumentExpression); } /** @@ -4064,8 +4671,17 @@ function isLiteralLikeElementAccess(node: Node): node is LiteralLikeElementAcces * @internal */ export function isBindableStaticAccessExpression(node: Node, excludeThisKeyword?: boolean): node is BindableStaticAccessExpression { - return isPropertyAccessExpression(node) && (!excludeThisKeyword && node.expression.kind === SyntaxKind.ThisKeyword || isIdentifier(node.name) && isBindableStaticNameExpression(node.expression, /*excludeThisKeyword*/ true)) - || isBindableStaticElementAccessExpression(node, excludeThisKeyword); + return astIsBindableStaticAccessExpression(node.ast, excludeThisKeyword); +} + +/** + * Any series of property and element accesses. + * + * @internal + */ +export function astIsBindableStaticAccessExpression(node: AstNode, excludeThisKeyword?: boolean): node is AstBindableStaticAccessExpression { + return astIsPropertyAccessExpression(node) && (!excludeThisKeyword && node.data.expression.kind === SyntaxKind.ThisKeyword || astIsIdentifier(node.data.name) && astIsBindableStaticNameExpression(node.data.expression, /*excludeThisKeyword*/ true)) + || astIsBindableStaticElementAccessExpression(node, excludeThisKeyword); } /** @@ -4074,15 +4690,29 @@ export function isBindableStaticAccessExpression(node: Node, excludeThisKeyword? * @internal */ export function isBindableStaticElementAccessExpression(node: Node, excludeThisKeyword?: boolean): node is BindableStaticElementAccessExpression { - return isLiteralLikeElementAccess(node) - && ((!excludeThisKeyword && node.expression.kind === SyntaxKind.ThisKeyword) || - isEntityNameExpression(node.expression) || - isBindableStaticAccessExpression(node.expression, /*excludeThisKeyword*/ true)); + return astIsBindableStaticElementAccessExpression(node.ast, excludeThisKeyword); +} + +/** + * Any series of property and element accesses, ending in a literal element access + * + * @internal + */ +export function astIsBindableStaticElementAccessExpression(node: AstNode, excludeThisKeyword?: boolean): node is AstBindableStaticElementAccessExpression { + return astIsLiteralLikeElementAccess(node) + && ((!excludeThisKeyword && node.data.expression.kind === SyntaxKind.ThisKeyword) || + astIsEntityNameExpression(node.data.expression) || + astIsBindableStaticAccessExpression(node.data.expression, /*excludeThisKeyword*/ true)); } /** @internal */ export function isBindableStaticNameExpression(node: Node, excludeThisKeyword?: boolean): node is BindableStaticNameExpression { - return isEntityNameExpression(node) || isBindableStaticAccessExpression(node, excludeThisKeyword); + return astIsBindableStaticNameExpression(node.ast, excludeThisKeyword); +} + +/** @internal */ +export function astIsBindableStaticNameExpression(node: AstNode, excludeThisKeyword?: boolean): node is AstBindableStaticNameExpression { + return astIsEntityNameExpression(node) || astIsBindableStaticAccessExpression(node, excludeThisKeyword); } /** @internal */ @@ -4093,32 +4723,32 @@ export function getNameOrArgument(expr: PropertyAccessExpression | LiteralLikeEl return expr.argumentExpression; } -function getAssignmentDeclarationKindWorker(expr: BinaryExpression | CallExpression): AssignmentDeclarationKind { - if (isCallExpression(expr)) { - if (!isBindableObjectDefinePropertyCall(expr)) { +function astGetAssignmentDeclarationKindWorker(expr: AstBinaryExpression | AstCallExpression): AssignmentDeclarationKind { + if (astIsCallExpression(expr)) { + if (!astIsBindableObjectDefinePropertyCall(expr)) { return AssignmentDeclarationKind.None; } - const entityName = expr.arguments[0]; - if (isExportsIdentifier(entityName) || isModuleExportsAccessExpression(entityName)) { + const entityName = expr.data.arguments.items[0]; + if (astIsExportsIdentifier(entityName) || astIsModuleExportsAccessExpression(entityName)) { return AssignmentDeclarationKind.ObjectDefinePropertyExports; } - if (isBindableStaticAccessExpression(entityName) && getElementOrPropertyAccessName(entityName) === "prototype") { + if (astIsBindableStaticAccessExpression(entityName) && astGetElementOrPropertyAccessName(entityName) === "prototype") { return AssignmentDeclarationKind.ObjectDefinePrototypeProperty; } return AssignmentDeclarationKind.ObjectDefinePropertyValue; } - if (expr.operatorToken.kind !== SyntaxKind.EqualsToken || !isAccessExpression(expr.left) || isVoidZero(getRightMostAssignedExpression(expr))) { + if (expr.data.operatorToken.kind !== SyntaxKind.EqualsToken || !astIsAccessExpression(expr.data.left) || astIsVoidZero(astGetRightMostAssignedExpression(expr))) { return AssignmentDeclarationKind.None; } - if (isBindableStaticNameExpression(expr.left.expression, /*excludeThisKeyword*/ true) && getElementOrPropertyAccessName(expr.left) === "prototype" && isObjectLiteralExpression(getInitializerOfBinaryExpression(expr))) { + if (astIsBindableStaticNameExpression(expr.data.left.data.expression, /*excludeThisKeyword*/ true) && astGetElementOrPropertyAccessName(expr.data.left) === "prototype" && astIsObjectLiteralExpression(astGetInitializerOfBinaryExpression(expr))) { // F.prototype = { ... } return AssignmentDeclarationKind.Prototype; } - return getAssignmentDeclarationPropertyAccessKind(expr.left); + return astGetAssignmentDeclarationPropertyAccessKind(expr.data.left); } -function isVoidZero(node: Node) { - return isVoidExpression(node) && isNumericLiteral(node.expression) && node.expression.text === "0"; +function astIsVoidZero(node: AstNode) { + return astIsVoidExpression(node) && astIsNumericLiteral(node.data.expression) && node.data.expression.data.text === "0"; } /** @@ -4128,11 +4758,21 @@ function isVoidZero(node: Node) { * @internal */ export function getElementOrPropertyAccessArgumentExpressionOrName(node: AccessExpression): Identifier | PrivateIdentifier | StringLiteralLike | NumericLiteral | ElementAccessExpression | undefined { - if (isPropertyAccessExpression(node)) { - return node.name; + return astGetElementOrPropertyAccessArgumentExpressionOrName(node.ast)?.node; +} + +/** + * Does not handle signed numeric names like `a[+0]` - handling those would require handling prefix unary expressions + * throughout late binding handling as well, which is awkward (but ultimately probably doable if there is demand) + * + * @internal + */ +export function astGetElementOrPropertyAccessArgumentExpressionOrName(node: AstAccessExpression): AstIdentifier | AstPrivateIdentifier | AstStringLiteralLike | AstNumericLiteral | AstElementAccessExpression | undefined { + if (astIsPropertyAccessExpression(node)) { + return node.data.name; } - const arg = skipParentheses(node.argumentExpression); - if (isNumericLiteral(arg) || isStringLiteralLike(arg)) { + const arg = astSkipParentheses(node.data.argumentExpression); + if (astIsNumericLiteral(arg) || astIsStringLiteralLike(arg)) { return arg; } return node; @@ -4144,13 +4784,22 @@ export function getElementOrPropertyAccessName(node: LiteralLikeElementAccessExp export function getElementOrPropertyAccessName(node: AccessExpression): __String | undefined; /** @internal */ export function getElementOrPropertyAccessName(node: AccessExpression): __String | undefined { - const name = getElementOrPropertyAccessArgumentExpressionOrName(node); + return astGetElementOrPropertyAccessName(node.ast); +} + +/** @internal */ +export function astGetElementOrPropertyAccessName(node: AstLiteralLikeElementAccessExpression | AstPropertyAccessExpression): __String; +/** @internal */ +export function astGetElementOrPropertyAccessName(node: AstAccessExpression): __String | undefined; +/** @internal */ +export function astGetElementOrPropertyAccessName(node: AstAccessExpression): __String | undefined { + const name = astGetElementOrPropertyAccessArgumentExpressionOrName(node); if (name) { - if (isIdentifier(name)) { - return name.escapedText; + if (astIsIdentifier(name)) { + return name.data.escapedText; } - if (isStringLiteralLike(name) || isNumericLiteral(name)) { - return escapeLeadingUnderscores(name.text); + if (astIsStringLiteralLike(name) || astIsNumericLiteral(name)) { + return escapeLeadingUnderscores(name.data.text); } } return undefined; @@ -4158,34 +4807,39 @@ export function getElementOrPropertyAccessName(node: AccessExpression): __String /** @internal */ export function getAssignmentDeclarationPropertyAccessKind(lhs: AccessExpression): AssignmentDeclarationKind { - if (lhs.expression.kind === SyntaxKind.ThisKeyword) { + return astGetAssignmentDeclarationPropertyAccessKind(lhs.ast); +} + +/** @internal */ +export function astGetAssignmentDeclarationPropertyAccessKind(lhs: AstAccessExpression): AssignmentDeclarationKind { + if (lhs.data.expression.kind === SyntaxKind.ThisKeyword) { return AssignmentDeclarationKind.ThisProperty; } - else if (isModuleExportsAccessExpression(lhs)) { + else if (astIsModuleExportsAccessExpression(lhs)) { // module.exports = expr return AssignmentDeclarationKind.ModuleExports; } - else if (isBindableStaticNameExpression(lhs.expression, /*excludeThisKeyword*/ true)) { - if (isPrototypeAccess(lhs.expression)) { + else if (astIsBindableStaticNameExpression(lhs.data.expression, /*excludeThisKeyword*/ true)) { + if (astIsPrototypeAccess(lhs.data.expression)) { // F.G....prototype.x = expr return AssignmentDeclarationKind.PrototypeProperty; } let nextToLast = lhs; - while (!isIdentifier(nextToLast.expression)) { - nextToLast = nextToLast.expression as Exclude; + while (!astIsIdentifier(nextToLast.data.expression)) { + nextToLast = nextToLast.data.expression as Exclude; } - const id = nextToLast.expression; + const id = nextToLast.data.expression; if ( - (id.escapedText === "exports" || - id.escapedText === "module" && getElementOrPropertyAccessName(nextToLast) === "exports") && + (id.data.escapedText === "exports" || + id.data.escapedText === "module" && astGetElementOrPropertyAccessName(nextToLast) === "exports") && // ExportsProperty does not support binding with computed names - isBindableStaticAccessExpression(lhs) + astIsBindableStaticAccessExpression(lhs) ) { // exports.name = expr OR module.exports.name = expr OR exports["name"] = expr ... return AssignmentDeclarationKind.ExportsProperty; } - if (isBindableStaticNameExpression(lhs, /*excludeThisKeyword*/ true) || (isElementAccessExpression(lhs) && isDynamicName(lhs))) { + if (astIsBindableStaticNameExpression(lhs, /*excludeThisKeyword*/ true) || (astIsElementAccessExpression(lhs) && astIsDynamicName(lhs))) { // F.G...x = expr return AssignmentDeclarationKind.Property; } @@ -4196,10 +4850,15 @@ export function getAssignmentDeclarationPropertyAccessKind(lhs: AccessExpression /** @internal */ export function getInitializerOfBinaryExpression(expr: BinaryExpression): Expression { - while (isBinaryExpression(expr.right)) { - expr = expr.right; + return astGetInitializerOfBinaryExpression(expr.ast).node; +} + +/** @internal */ +export function astGetInitializerOfBinaryExpression(expr: AstBinaryExpression): AstExpression { + while (astIsBinaryExpression(expr.data.right)) { + expr = expr.data.right; } - return expr.right; + return expr.data.right; } /** @internal */ @@ -4215,23 +4874,33 @@ export function isPrototypePropertyAssignment(node: Node): node is PrototypeProp /** @internal */ export function isSpecialPropertyDeclaration(expr: PropertyAccessExpression | ElementAccessExpression): expr is PropertyAccessExpression | LiteralLikeElementAccessExpression { - return isInJSFile(expr) && + return astIsSpecialPropertyDeclaration(expr.ast); +} + +/** @internal */ +export function astIsSpecialPropertyDeclaration(expr: AstPropertyAccessExpression | AstElementAccessExpression): expr is AstPropertyAccessExpression | AstLiteralLikeElementAccessExpression { + return astIsInJSFile(expr) && expr.parent && expr.parent.kind === SyntaxKind.ExpressionStatement && - (!isElementAccessExpression(expr) || isLiteralLikeElementAccess(expr)) && - !!getJSDocTypeTag(expr.parent); + (!astIsElementAccessExpression(expr) || astIsLiteralLikeElementAccess(expr)) && + !!getJSDocTypeTag(expr.parent.node); // TODO(rbuckton): do not instantiate `.node` } /** @internal */ export function setValueDeclaration(symbol: Symbol, node: Declaration): void { - const { valueDeclaration } = symbol; + astSetValueDeclaration(symbol, node.ast); +} + +/** @internal */ +export function astSetValueDeclaration(symbol: Symbol, node: AstDeclaration): void { + const { astValueDeclaration } = symbol; if ( - !valueDeclaration || - !(node.flags & NodeFlags.Ambient && !isInJSFile(node) && !(valueDeclaration.flags & NodeFlags.Ambient)) && - (isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node)) || - (valueDeclaration.kind !== node.kind && isEffectiveModuleDeclaration(valueDeclaration)) + !astValueDeclaration || + !(node.flags & NodeFlags.Ambient && !astIsInJSFile(node) && !(astValueDeclaration.flags & NodeFlags.Ambient)) && + (astIsAssignmentDeclaration(astValueDeclaration) && !astIsAssignmentDeclaration(node)) || + (astValueDeclaration.kind !== node.kind && astIsEffectiveModuleDeclaration(astValueDeclaration)) ) { // other kinds of value declarations take precedence over modules and assignment declarations - symbol.valueDeclaration = node; + symbol.astValueDeclaration = node; } } @@ -4398,6 +5067,11 @@ export function isJSDocConstructSignature(node: Node): boolean { /** @internal */ export function isJSDocTypeAlias(node: Node): node is JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag { + return astIsJSDocTypeAlias(node.ast); +} + +/** @internal */ +export function astIsJSDocTypeAlias(node: AstNode): node is AstJSDocTypedefTag | AstJSDocCallbackTag | AstJSDocEnumTag { return node.kind === SyntaxKind.JSDocTypedefTag || node.kind === SyntaxKind.JSDocCallbackTag || node.kind === SyntaxKind.JSDocEnumTag; } @@ -4415,37 +5089,55 @@ function getSourceOfAssignment(node: Node): Node | undefined { } function getSourceOfDefaultedAssignment(node: Node): Node | undefined { - return isExpressionStatement(node) && - isBinaryExpression(node.expression) && - getAssignmentDeclarationKind(node.expression) !== AssignmentDeclarationKind.None && - isBinaryExpression(node.expression.right) && - (node.expression.right.operatorToken.kind === SyntaxKind.BarBarToken || node.expression.right.operatorToken.kind === SyntaxKind.QuestionQuestionToken) - ? node.expression.right.right + return astGetSourceOfDefaultedAssignment(node.ast)?.node; +} + +function astGetSourceOfDefaultedAssignment(node: AstNode): AstNode | undefined { + return astIsExpressionStatement(node) && + astIsBinaryExpression(node.data.expression) && + astGetAssignmentDeclarationKind(node.data.expression) !== AssignmentDeclarationKind.None && + astIsBinaryExpression(node.data.expression.data.right) && + (node.data.expression.data.right.data.operatorToken.kind === SyntaxKind.BarBarToken || + node.data.expression.data.right.data.operatorToken.kind === SyntaxKind.QuestionQuestionToken) + ? node.data.expression.data.right.data.right : undefined; } function getSingleInitializerOfVariableStatementOrPropertyDeclaration(node: Node): Expression | undefined { + return astGetSingleInitializerOfVariableStatementOrPropertyDeclaration(node.ast)?.node; +} + +function astGetSingleInitializerOfVariableStatementOrPropertyDeclaration(node: AstNode): AstExpression | undefined { switch (node.kind) { case SyntaxKind.VariableStatement: - const v = getSingleVariableOfVariableStatement(node); - return v && v.initializer; + const v = astGetSingleVariableOfVariableStatement(node); + return v && astGetInitializer(v); case SyntaxKind.PropertyDeclaration: - return (node as PropertyDeclaration).initializer; + return (node as AstPropertyDeclaration).data.initializer; case SyntaxKind.PropertyAssignment: - return (node as PropertyAssignment).initializer; + return (node as AstPropertyAssignment).data.initializer; } } /** @internal */ export function getSingleVariableOfVariableStatement(node: Node): VariableDeclaration | undefined { - return isVariableStatement(node) ? firstOrUndefined(node.declarationList.declarations) : undefined; + return astGetSingleVariableOfVariableStatement(node.ast)?.node; +} + +/** @internal */ +export function astGetSingleVariableOfVariableStatement(node: AstNode): AstVariableDeclaration | undefined { + return astIsVariableStatement(node) ? firstOrUndefined(node.data.declarationList.data.declarations.items) : undefined; } function getNestedModuleDeclaration(node: Node): Node | undefined { - return isModuleDeclaration(node) && - node.body && - node.body.kind === SyntaxKind.ModuleDeclaration - ? node.body + return astGetNestedModuleDeclaration(node.ast)?.node; +} + +function astGetNestedModuleDeclaration(node: AstNode): AstNode | undefined { + return astIsModuleDeclaration(node) && + node.data.body && + node.data.body.kind === SyntaxKind.ModuleDeclaration + ? node.data.body : undefined; } @@ -4577,36 +5269,66 @@ export function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDoc // eslint-disable-next-line @typescript-eslint/unified-signatures export function getJSDocCommentsAndTags(hostNode: Node, noCache?: boolean): readonly (JSDoc | JSDocTag)[]; export function getJSDocCommentsAndTags(hostNode: Node, noCache?: boolean): readonly (JSDoc | JSDocTag)[] { + return astGetJSDocCommentsAndTags(hostNode.ast, noCache); +} + +/** + * This function checks multiple locations for JSDoc comments that apply to a host node. + * At each location, the whole comment may apply to the node, or only a specific tag in + * the comment. In the first case, location adds the entire {@link JSDoc} object. In the + * second case, it adds the applicable {@link JSDocTag}. + * + * For example, a JSDoc comment before a parameter adds the entire {@link JSDoc}. But a + * `@param` tag on the parent function only adds the {@link JSDocTag} for the `@param`. + * + * ```ts + * /** JSDoc will be returned for `a` *\/ + * const a = 0 + * /** + * * Entire JSDoc will be returned for `b` + * * @param c JSDocTag will be returned for `c` + * *\/ + * function b(/** JSDoc will be returned for `c` *\/ c) {} + * ``` + */ +export function astGetJSDocCommentsAndTags(hostNode: AstNode): readonly (JSDoc | JSDocTag)[]; +/** @internal separate signature so that stripInternal can remove noCache from the public API */ +// eslint-disable-next-line @typescript-eslint/unified-signatures +export function astGetJSDocCommentsAndTags(hostNode: AstNode, noCache?: boolean): readonly (JSDoc | JSDocTag)[]; +export function astGetJSDocCommentsAndTags(hostNode: AstNode, noCache?: boolean): readonly (JSDoc | JSDocTag)[] { let result: (JSDoc | JSDocTag)[] | undefined; // Pull parameter comments from declaring function as well - if (isVariableLike(hostNode) && hasInitializer(hostNode) && hasJSDocNodes(hostNode.initializer!)) { - result = addRange(result, filterOwnedJSDocTags(hostNode, hostNode.initializer.jsDoc!)); + if (astIsVariableLike(hostNode)) { + const initializer = astGetInitializer(hostNode); + if (initializer && astHasJSDocNodes(initializer)) { + result = addRange(result, astFilterOwnedJSDocTags(hostNode, initializer.data.jsDoc!)); + } } - let node: Node | undefined = hostNode; + let node: AstNode | undefined = hostNode; while (node && node.parent) { - if (hasJSDocNodes(node)) { - result = addRange(result, filterOwnedJSDocTags(hostNode, node.jsDoc!)); + if (astHasJSDocNodes(node)) { + result = addRange(result, astFilterOwnedJSDocTags(hostNode, node.data.jsDoc!)); } if (node.kind === SyntaxKind.Parameter) { - result = addRange(result, (noCache ? getJSDocParameterTagsNoCache : getJSDocParameterTags)(node as ParameterDeclaration)); + result = addRange(result, (noCache ? astGetJSDocParameterTagsNoCache : astGetJSDocParameterTags)(node as AstParameterDeclaration)); break; } if (node.kind === SyntaxKind.TypeParameter) { - result = addRange(result, (noCache ? getJSDocTypeParameterTagsNoCache : getJSDocTypeParameterTags)(node as TypeParameterDeclaration)); + result = addRange(result, (noCache ? astGetJSDocTypeParameterTagsNoCache : astGetJSDocTypeParameterTags)(node as AstTypeParameterDeclaration)); break; } - node = getNextJSDocCommentLocation(node); + node = astGetNextJSDocCommentLocation(node); } return result || emptyArray; } -function filterOwnedJSDocTags(hostNode: Node, comments: JSDocArray) { +function astFilterOwnedJSDocTags(hostNode: AstNode, comments: JSDocArray) { const lastJsDoc = last(comments); return flatMap(comments, jsDoc => { if (jsDoc === lastJsDoc) { - const ownedTags = filter(jsDoc.tags, tag => ownsJSDocTag(hostNode, tag)); + const ownedTags = filter(jsDoc.tags, tag => astOwnsJSDocTag(hostNode, tag)); return jsDoc.tags === ownedTags ? [jsDoc] : ownedTags; } else { @@ -4619,16 +5341,21 @@ function filterOwnedJSDocTags(hostNode: Node, comments: JSDocArray) { * Determines whether a host node owns a jsDoc tag. A `@type`/`@satisfies` tag attached to a * a ParenthesizedExpression belongs only to the ParenthesizedExpression. */ -function ownsJSDocTag(hostNode: Node, tag: JSDocTag) { +function astOwnsJSDocTag(hostNode: AstNode, tag: JSDocTag) { return !(isJSDocTypeTag(tag) || isJSDocSatisfiesTag(tag)) || !tag.parent || !isJSDoc(tag.parent) || !isParenthesizedExpression(tag.parent.parent) - || tag.parent.parent === hostNode; + || tag.parent.parent.ast === hostNode; } /** @internal */ export function getNextJSDocCommentLocation(node: Node): Node | undefined { + return astGetNextJSDocCommentLocation(node.ast)?.node; +} + +/** @internal */ +export function astGetNextJSDocCommentLocation(node: AstNode): AstNode | undefined { const parent = node.parent; if ( parent.kind === SyntaxKind.PropertyAssignment || @@ -4636,8 +5363,8 @@ export function getNextJSDocCommentLocation(node: Node): Node | undefined { parent.kind === SyntaxKind.PropertyDeclaration || parent.kind === SyntaxKind.ExpressionStatement && node.kind === SyntaxKind.PropertyAccessExpression || parent.kind === SyntaxKind.ReturnStatement || - getNestedModuleDeclaration(parent) || - isAssignmentExpression(node) + astGetNestedModuleDeclaration(parent) || + astIsAssignmentExpression(node) ) { return parent; } @@ -4649,15 +5376,15 @@ export function getNextJSDocCommentLocation(node: Node): Node | undefined { // var x = function(name) { return name.length; } else if ( parent.parent && - (getSingleVariableOfVariableStatement(parent.parent) === node || isAssignmentExpression(parent)) + (astGetSingleVariableOfVariableStatement(parent.parent) === node || astIsAssignmentExpression(parent)) ) { return parent.parent; } else if ( parent.parent && parent.parent.parent && - (getSingleVariableOfVariableStatement(parent.parent.parent) || - getSingleInitializerOfVariableStatementOrPropertyDeclaration(parent.parent.parent) === node || - getSourceOfDefaultedAssignment(parent.parent.parent)) + (astGetSingleVariableOfVariableStatement(parent.parent.parent) || + astGetSingleInitializerOfVariableStatementOrPropertyDeclaration(parent.parent.parent) === node || + astGetSourceOfDefaultedAssignment(parent.parent.parent)) ) { return parent.parent.parent; } @@ -4965,10 +5692,19 @@ export function skipParentheses(node: Expression, excludeJSDocTypeAssertions?: b export function skipParentheses(node: Node, excludeJSDocTypeAssertions?: boolean): Node; /** @internal */ export function skipParentheses(node: Node, excludeJSDocTypeAssertions?: boolean): Node { + return astSkipParentheses(node.ast, excludeJSDocTypeAssertions).node; +} + +/** @internal */ +export function astSkipParentheses(node: AstExpression, excludeJSDocTypeAssertions?: boolean): AstExpression; +/** @internal */ +export function astSkipParentheses(node: AstNode, excludeJSDocTypeAssertions?: boolean): AstNode; +/** @internal */ +export function astSkipParentheses(node: AstNode, excludeJSDocTypeAssertions?: boolean): AstNode { const flags = excludeJSDocTypeAssertions ? OuterExpressionKinds.Parentheses | OuterExpressionKinds.ExcludeJSDocTypeAssertion : OuterExpressionKinds.Parentheses; - return skipOuterExpressions(node, flags); + return astSkipOuterExpressions(node, flags); } // a node is delete target iff. it is PropertyAccessExpression/ElementAccessExpression with parentheses skipped @@ -4996,6 +5732,12 @@ export function isDeclarationName(name: Node): boolean { return !isSourceFile(name) && !isBindingPattern(name) && isDeclaration(name.parent) && name.parent.name === name; } +// True if `name` is the name of a declaration node +/** @internal */ +export function astIsDeclarationName(name: AstNode): boolean { + return !astIsSourceFile(name) && !astIsBindingPattern(name) && astIsDeclaration(name.parent) && astCanHaveName(name.parent) && name.parent.data.name === name; +} + // See GH#16030 /** @internal */ export function getDeclarationFromName(name: Node): Declaration | undefined { @@ -5040,6 +5782,12 @@ export function isLiteralComputedPropertyDeclarationName(node: Node): boolean { // Return true if the given identifier is classified as an IdentifierName /** @internal */ export function isIdentifierName(node: Identifier): boolean { + return astIsIdentifier(node.ast); +} + +// Return true if the given identifier is classified as an IdentifierName +/** @internal */ +export function astIsIdentifierName(node: AstIdentifier): boolean { const parent = node.parent; switch (parent.kind) { case SyntaxKind.PropertyDeclaration: @@ -5052,14 +5800,14 @@ export function isIdentifierName(node: Identifier): boolean { case SyntaxKind.PropertyAssignment: case SyntaxKind.PropertyAccessExpression: // Name in member declaration or property name in property access - return (parent as NamedDeclaration | PropertyAccessExpression).name === node; + return astGetName(parent) === node; case SyntaxKind.QualifiedName: // Name on right hand side of dot in a type query or type reference - return (parent as QualifiedName).right === node; + return (parent as AstQualifiedName).data.right === node; case SyntaxKind.BindingElement: + return (parent as AstBindingElement).data.propertyName === node; case SyntaxKind.ImportSpecifier: - // Property name in binding element or import specifier - return (parent as BindingElement | ImportSpecifier).propertyName === node; + return (parent as AstImportSpecifier).data.propertyName === node; case SyntaxKind.ExportSpecifier: case SyntaxKind.JsxAttribute: case SyntaxKind.JsxSelfClosingElement: @@ -5290,7 +6038,12 @@ export function isStringOrNumericLiteralLike(node: Node): node is StringLiteralL /** @internal */ export function isSignedNumericLiteral(node: Node): node is PrefixUnaryExpression & { operand: NumericLiteral; } { - return isPrefixUnaryExpression(node) && (node.operator === SyntaxKind.PlusToken || node.operator === SyntaxKind.MinusToken) && isNumericLiteral(node.operand); + return astIsSignedNumericLiteral(node.ast); +} + +/** @internal */ +export function astIsSignedNumericLiteral(node: AstNode): node is AstNode { + return astIsPrefixUnaryExpression(node) && (node.data.operator === SyntaxKind.PlusToken || node.data.operator === SyntaxKind.MinusToken) && astIsNumericLiteral(node.data.operand); } /** @@ -5304,18 +6057,37 @@ export function isSignedNumericLiteral(node: Node): node is PrefixUnaryExpressio * @internal */ export function hasDynamicName(declaration: Declaration): declaration is DynamicNamedDeclaration | DynamicNamedBinaryExpression { - const name = getNameOfDeclaration(declaration); - return !!name && isDynamicName(name); + return astHasDynamicName(declaration.ast); +} + +/** + * A declaration has a dynamic name if all of the following are true: + * 1. The declaration has a computed property name. + * 2. The computed name is *not* expressed as a StringLiteral. + * 3. The computed name is *not* expressed as a NumericLiteral. + * 4. The computed name is *not* expressed as a PlusToken or MinusToken + * immediately followed by a NumericLiteral. + * + * @internal + */ +export function astHasDynamicName(declaration: AstDeclaration): declaration is AstDynamicNamedDeclaration | AstDynamicNamedBinaryExpression { + const name = astGetNameOfDeclaration(declaration); + return !!name && astIsDynamicName(name); } /** @internal */ export function isDynamicName(name: DeclarationName): boolean { + return astIsDynamicName(name.ast); +} + +/** @internal */ +export function astIsDynamicName(name: AstDeclarationName): boolean { if (!(name.kind === SyntaxKind.ComputedPropertyName || name.kind === SyntaxKind.ElementAccessExpression)) { return false; } - const expr = isElementAccessExpression(name) ? skipParentheses(name.argumentExpression) : name.expression; - return !isStringOrNumericLiteralLike(expr) && - !isSignedNumericLiteral(expr); + const expr = astIsElementAccessExpression(name) ? astSkipParentheses(name.data.argumentExpression) : name.data.expression; + return !astIsStringOrNumericLiteralLike(expr) && + !astIsSignedNumericLiteral(expr); } /** @internal */ @@ -5524,8 +6296,16 @@ export function isPartOfParameterDeclaration(node: Declaration): boolean { return root.kind === SyntaxKind.Parameter; } -/** @internal */ +/** + * @deprecated Use {@link astGetRootDeclaration} + * @internal + */ export function getRootDeclaration(node: Node): Node { + return astGetRootDeclaration(node.ast).node; +} + +/** @internal */ +export function astGetRootDeclaration(node: AstNode): AstNode { while (node.kind === SyntaxKind.BindingElement) { node = node.parent.parent; } @@ -5547,7 +6327,15 @@ export function nodeStartsNewLexicalEnvironment(node: Node): boolean { } /** @internal */ -export function nodeIsSynthesized(range: TextRange): boolean { +export function nodeIsSynthesized(range: TextRange & { node?: never }): boolean { + return positionIsSynthesized(range.pos) + || positionIsSynthesized(range.end); +} + +/** + * A copy of `nodeIsSynthesized` for `AstNode` to ensure the function remains monomorphic + * @internal */ +export function astNodeIsSynthesized(range: AstNode): boolean { return positionIsSynthesized(range.pos) || positionIsSynthesized(range.end); } @@ -6802,14 +7590,15 @@ export function getAllAccessorDeclarations(declarations: readonly Declaration[] export function getEffectiveTypeAnnotationNode(node: Node): TypeNode | undefined { if (!isInJSFile(node) && isFunctionDeclaration(node)) return undefined; if (isTypeAliasDeclaration(node)) return undefined; // has a .type, is not a type annotation - const type = (node as HasType).type; + const type = getTypeAnnotationNode(node); if (type || !isInJSFile(node)) return type; return isJSDocPropertyLikeTag(node) ? node.typeExpression && node.typeExpression.type : getJSDocType(node); } /** @internal */ export function getTypeAnnotationNode(node: Node): TypeNode | undefined { - return (node as HasType).type; + const type = (node as HasType).type; + return !type || isJSDocReturnTag(type) ? undefined : type; } /** @@ -7103,7 +7892,12 @@ export function hasEffectiveModifier(node: Node, flags: ModifierFlags): boolean /** @internal */ export function hasSyntacticModifier(node: Node, flags: ModifierFlags): boolean { - return !!getSelectedSyntacticModifierFlags(node, flags); + return astHasSyntacticModifier(node.ast, flags); +} + +/** @internal */ +export function astHasSyntacticModifier(node: AstNode, flags: ModifierFlags): boolean { + return !!astGetSelectedSyntacticModifierFlags(node, flags); } /** @internal */ @@ -7132,9 +7926,17 @@ export function hasAmbientModifier(node: Node): boolean { return hasSyntacticModifier(node, ModifierFlags.Ambient); } -/** @internal */ +/** + * @deprecated use {@link astHasAccessorModifier} + * @internal + */ export function hasAccessorModifier(node: Node): boolean { - return hasSyntacticModifier(node, ModifierFlags.Accessor); + return astHasAccessorModifier(node.ast); +} + +/** @internal */ +export function astHasAccessorModifier(node: AstNode): boolean { + return astHasSyntacticModifier(node, ModifierFlags.Accessor); } /** @internal */ @@ -7154,21 +7956,30 @@ export function getSelectedEffectiveModifierFlags(node: Node, flags: ModifierFla /** @internal @knipignore */ export function getSelectedSyntacticModifierFlags(node: Node, flags: ModifierFlags): ModifierFlags { - return getSyntacticModifierFlags(node) & flags; + return astGetSelectedSyntacticModifierFlags(node.ast, flags); +} + +/** @internal @knipignore */ +export function astGetSelectedSyntacticModifierFlags(node: AstNode, flags: ModifierFlags): ModifierFlags { + return astGetSyntacticModifierFlags(node) & flags; } function getModifierFlagsWorker(node: Node, includeJSDoc: boolean, alwaysIncludeJSDoc?: boolean): ModifierFlags { + return astGetModifierFlagsWorker(node.ast, includeJSDoc, alwaysIncludeJSDoc); +} + +function astGetModifierFlagsWorker(node: AstNode, includeJSDoc: boolean, alwaysIncludeJSDoc?: boolean): ModifierFlags { if (node.kind >= SyntaxKind.FirstToken && node.kind <= SyntaxKind.LastToken) { return ModifierFlags.None; } if (!(node.modifierFlagsCache & ModifierFlags.HasComputedFlags)) { - node.modifierFlagsCache = getSyntacticModifierFlagsNoCache(node) | ModifierFlags.HasComputedFlags; + node.modifierFlagsCache = astGetSyntacticModifierFlagsNoCache(node) | ModifierFlags.HasComputedFlags; } - if (alwaysIncludeJSDoc || includeJSDoc && isInJSFile(node)) { + if (alwaysIncludeJSDoc || includeJSDoc && astIsInJSFile(node)) { if (!(node.modifierFlagsCache & ModifierFlags.HasComputedJSDocModifiers) && node.parent) { - node.modifierFlagsCache |= getRawJSDocModifierFlagsNoCache(node) | ModifierFlags.HasComputedJSDocModifiers; + node.modifierFlagsCache |= astGetRawJSDocModifierFlagsNoCache(node) | ModifierFlags.HasComputedJSDocModifiers; } return selectEffectiveModifierFlags(node.modifierFlagsCache); } @@ -7200,20 +8011,35 @@ export function getEffectiveModifierFlagsAlwaysIncludeJSDoc(node: Node): Modifie * @internal */ export function getSyntacticModifierFlags(node: Node): ModifierFlags { - return getModifierFlagsWorker(node, /*includeJSDoc*/ false); + return astGetSyntacticModifierFlags(node.ast); +} + +/** + * Gets the ModifierFlags for syntactic modifiers on the provided node. The modifiers will be cached on the node to improve performance. + * + * NOTE: This function does not use `parent` pointers and will not include modifiers from JSDoc. + * + * @internal + */ +export function astGetSyntacticModifierFlags(node: AstNode): ModifierFlags { + return astGetModifierFlagsWorker(node, /*includeJSDoc*/ false); } function getRawJSDocModifierFlagsNoCache(node: Node): ModifierFlags { + return astGetRawJSDocModifierFlagsNoCache(node.ast); +} + +function astGetRawJSDocModifierFlagsNoCache(node: AstNode): ModifierFlags { let flags = ModifierFlags.None; - if (!!node.parent && !isParameter(node)) { - if (isInJSFile(node)) { - if (getJSDocPublicTagNoCache(node)) flags |= ModifierFlags.JSDocPublic; - if (getJSDocPrivateTagNoCache(node)) flags |= ModifierFlags.JSDocPrivate; - if (getJSDocProtectedTagNoCache(node)) flags |= ModifierFlags.JSDocProtected; - if (getJSDocReadonlyTagNoCache(node)) flags |= ModifierFlags.JSDocReadonly; - if (getJSDocOverrideTagNoCache(node)) flags |= ModifierFlags.JSDocOverride; + if (!!node.parent && !astIsParameter(node)) { + if (astIsInJSFile(node)) { + if (astGetJSDocPublicTagNoCache(node)) flags |= ModifierFlags.JSDocPublic; + if (astGetJSDocPrivateTagNoCache(node)) flags |= ModifierFlags.JSDocPrivate; + if (astGetJSDocProtectedTagNoCache(node)) flags |= ModifierFlags.JSDocProtected; + if (astGetJSDocReadonlyTagNoCache(node)) flags |= ModifierFlags.JSDocReadonly; + if (astGetJSDocOverrideTagNoCache(node)) flags |= ModifierFlags.JSDocOverride; } - if (getJSDocDeprecatedTagNoCache(node)) flags |= ModifierFlags.Deprecated; + if (astGetJSDocDeprecatedTagNoCache(node)) flags |= ModifierFlags.Deprecated; } return flags; @@ -7252,7 +8078,19 @@ export function getEffectiveModifierFlagsNoCache(node: Node): ModifierFlags { * @knipignore */ export function getSyntacticModifierFlagsNoCache(node: Node): ModifierFlags { - let flags = canHaveModifiers(node) ? modifiersToFlags(node.modifiers) : ModifierFlags.None; + return astGetSyntacticModifierFlagsNoCache(node.ast); +} + +/** + * Gets the ModifierFlags for syntactic modifiers on the provided node. The modifier flags cache on the node is ignored. + * + * NOTE: This function does not use `parent` pointers and will not include modifiers from JSDoc. + * + * @internal + * @knipignore + */ +export function astGetSyntacticModifierFlagsNoCache(node: AstNode): ModifierFlags { + let flags = astCanHaveModifiers(node) ? astModifiersToFlags(node.data.modifiers?.items) : ModifierFlags.None; if (node.flags & NodeFlags.NestedNamespace || node.kind === SyntaxKind.Identifier && node.flags & NodeFlags.IdentifierIsInJSDocNamespace) { flags |= ModifierFlags.Export; } @@ -7260,7 +8098,18 @@ export function getSyntacticModifierFlagsNoCache(node: Node): ModifierFlags { } /** @internal */ -export function modifiersToFlags(modifiers: readonly ModifierLike[] | readonly AstModifierLike[] | undefined): ModifierFlags { +export function modifiersToFlags(modifiers: readonly ModifierLike[] | undefined): ModifierFlags { + let flags = ModifierFlags.None; + if (modifiers) { + for (const modifier of modifiers) { + flags |= modifierToFlag(modifier.kind); + } + } + return flags; +} + +/** @internal */ +export function astModifiersToFlags(modifiers: readonly AstModifierLike[] | undefined): ModifierFlags { let flags = ModifierFlags.None; if (modifiers) { for (const modifier of modifiers) { @@ -7383,11 +8232,20 @@ export function isAssignmentExpression(node: Node, excludeCompoundAssignment: tr export function isAssignmentExpression(node: Node, excludeCompoundAssignment?: false): node is AssignmentExpression; /** @internal */ export function isAssignmentExpression(node: Node, excludeCompoundAssignment?: boolean): node is AssignmentExpression { - return isBinaryExpression(node) + return astIsAssignmentExpression(node.ast, excludeCompoundAssignment); +} + +/** @internal */ +export function astIsAssignmentExpression(node: AstNode, excludeCompoundAssignment: true): node is AstAssignmentExpression; +/** @internal */ +export function astIsAssignmentExpression(node: AstNode, excludeCompoundAssignment?: boolean): node is AstAssignmentExpression; +/** @internal */ +export function astIsAssignmentExpression(node: AstNode, excludeCompoundAssignment?: boolean): node is AstAssignmentExpression { + return astIsBinaryExpression(node) && (excludeCompoundAssignment - ? node.operatorToken.kind === SyntaxKind.EqualsToken - : isAssignmentOperator(node.operatorToken.kind)) - && isLeftHandSideExpression(node.left); + ? node.data.operatorToken.kind === SyntaxKind.EqualsToken + : isAssignmentOperator(node.data.operatorToken.kind)) + && astIsLeftHandSideExpression(node.data.left); } /** @internal */ @@ -7408,7 +8266,12 @@ export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): n /** @internal */ export function isEntityNameExpression(node: Node): node is EntityNameExpression { - return node.kind === SyntaxKind.Identifier || isPropertyAccessEntityNameExpression(node); + return astIsEntityNameExpression(node.ast); +} + +/** @internal */ +export function astIsEntityNameExpression(node: AstNode): node is AstEntityNameExpression { + return node.kind === SyntaxKind.Identifier || astIsPropertyAccessEntityNameExpression(node); } /** @internal */ @@ -7443,7 +8306,12 @@ export function isDottedName(node: Expression): boolean { /** @internal */ export function isPropertyAccessEntityNameExpression(node: Node): node is PropertyAccessEntityNameExpression { - return isPropertyAccessExpression(node) && isIdentifier(node.name) && isEntityNameExpression(node.expression); + return astIsPropertyAccessEntityNameExpression(node.ast); +} + +/** @internal */ +export function astIsPropertyAccessEntityNameExpression(node: AstNode): node is AstPropertyAccessEntityNameExpression { + return astIsPropertyAccessExpression(node) && astIsIdentifier(node.data.name) && astIsEntityNameExpression(node.data.expression); } /** @internal */ @@ -7471,7 +8339,12 @@ export function tryGetPropertyAccessOrIdentifierToString(expr: Expression | JsxT /** @internal */ export function isPrototypeAccess(node: Node): node is BindableStaticAccessExpression { - return isBindableStaticAccessExpression(node) && getElementOrPropertyAccessName(node) === "prototype"; + return astIsPrototypeAccess(node.ast); +} + +/** @internal */ +export function astIsPrototypeAccess(node: AstNode): node is AstBindableStaticAccessExpression { + return astIsBindableStaticAccessExpression(node) && astGetElementOrPropertyAccessName(node) === "prototype"; } /** @internal */ @@ -8258,6 +9131,11 @@ export function isTypeNodeKind(kind: SyntaxKind): kind is TypeNodeSyntaxKind { /** @internal */ export function isAccessExpression(node: Node): node is AccessExpression { + return astIsAccessExpression(node.ast); +} + +/** @internal */ +export function astIsAccessExpression(node: AstNode): node is AstAccessExpression { return node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.ElementAccessExpression; } @@ -8368,23 +9246,36 @@ export interface ObjectAllocator { getSourceMapSourceConstructor(): new (fileName: string, text: string, skipTrivia?: (pos: number) => number) => SourceMapSource; } -function Symbol(this: Symbol, flags: SymbolFlags, name: __String): void { - // Note: if modifying this, be sure to update SymbolObject in src/services/services.ts - this.flags = flags; - this.escapedName = name; - this.declarations = undefined; - this.valueDeclaration = undefined; - this.id = 0; - this.mergeId = 0; - this.parent = undefined; - this.members = undefined; - this.exports = undefined; - this.exportSymbol = undefined; - this.constEnumOnlyModule = undefined; - this.isReferenced = undefined; - this.lastAssignmentPos = undefined; - (this as any).links = undefined; // used by TransientSymbol -} +// dprint-ignore +const Symbol: new (flags: SymbolFlags, name: __String) => Symbol = class implements Symbol { + flags: SymbolFlags = 0; + escapedName: __String = "" as __String; + private _declarations: readonly Declaration[] | undefined = undefined; + astValueDeclaration: AstDeclaration | undefined = undefined; + astDeclarations: AstDeclaration[] | undefined = undefined; + id: number = 0; + mergeId: number = 0; + parent: Symbol | undefined = undefined; + members: SymbolTable | undefined = undefined; + exports: SymbolTable | undefined = undefined; + exportSymbol: Symbol | undefined = undefined; + constEnumOnlyModule: boolean | undefined = undefined; + isReferenced: SymbolFlags | undefined = undefined; + lastAssignmentPos: number | undefined = undefined; + globalExports: SymbolTable | undefined = undefined; + isReplaceableByMethod: boolean | undefined = undefined; + assignmentDeclarationMembers: Map | undefined = undefined; + links: unknown = undefined; // used by TransientSymbol + + constructor(flags: SymbolFlags, name: __String) { + this.flags = flags; + this.escapedName = name; + } + + get valueDeclaration() { return this.astValueDeclaration?.node; } + set valueDeclaration(value) { this.astValueDeclaration = value?.ast; } + get declarations() { return this._declarations ??= this.astDeclarations && new ReadonlyArrayView(this.astDeclarations, ast => ast.node); } +}; function Type(this: Type, checker: TypeChecker, flags: TypeFlags): void { // Note: if modifying this, be sure to update TypeObject in src/services/services.ts diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 4dc62edbd2b95..00dae06868ef4 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1,6 +1,5 @@ import { __String, - AccessExpression, AccessorDeclaration, ArrayBindingElement, ArrayBindingOrAssignmentElement, @@ -11,7 +10,6 @@ import { AssignmentPattern, AutoAccessorPropertyDeclaration, BinaryExpression, - BindableObjectDefinePropertyCall, BindingElement, BindingName, BindingOrAssignmentElement, @@ -51,13 +49,11 @@ import { Diagnostics, diagnosticsEqualityComparer, ElementAccessChain, - ElementAccessExpression, emptyArray, EntityName, entityNameToString, EnumDeclaration, every, - ExportAssignment, ExportDeclaration, ExportSpecifier, Expression, @@ -76,11 +72,9 @@ import { GeneratedIdentifierFlags, GeneratedPrivateIdentifier, GetAccessorDeclaration, - getAssignmentDeclarationKind, getDirectoryPath, getEffectiveModifierFlags, getEffectiveModifierFlagsAlwaysIncludeJSDoc, - getElementOrPropertyAccessArgumentExpressionOrName, getEmitScriptTarget, getJSDocCommentsAndTags, getJSDocRoot, @@ -106,21 +100,17 @@ import { ImportEqualsDeclaration, ImportSpecifier, ImportTypeNode, - isAccessExpression, isAmbientModule, isAnyImportOrReExport, isArrowFunction, isAssignmentExpression, - isBinaryExpression, isBindableStaticAccessExpression, - isBindableStaticElementAccessExpression, isBindableStaticNameExpression, isBindingElement, isBlock, isCallExpression, isCallSignatureDeclaration, isClassExpression, - isClassStaticBlockDeclaration, isDecorator, isElementAccessExpression, isExpandoPropertyDeclaration, @@ -163,7 +153,6 @@ import { isParameter, isPrivateIdentifier, isPropertyAccessExpression, - isPropertyAssignment, isPropertyDeclaration, isPrototypeAccess, isRootedDiskPath, @@ -296,6 +285,56 @@ import { HasAsteriskToken, AsteriskToken, AstNode, + AstIdentifier, + AstPrivateIdentifier, + AstClassLikeDeclaration, + AstClassElement, + AstDeclaration, + AstExpression, + AstDeclarationName, + astIsFunctionExpression, + astIsArrowFunction, + astIsClassExpression, + AstJSDocPropertyLikeTag, + AstCallExpression, + AstBinaryExpression, + astGetAssignmentDeclarationKind, + astGetElementOrPropertyAccessArgumentExpressionOrName, + AstAccessExpression, + AstBindableObjectDefinePropertyCall, + AstJSDocTypedefTag, + AstJSDocEnumTag, + AstExportAssignment, + astIsIdentifier, + AstElementAccessExpression, + astIsBindableStaticElementAccessExpression, + astGetName, + AstNamedDeclaration, + astIsInJSFile, + astIsExpression, + AstPropertyAccessExpression, + astCanHaveJSDoc, + astGetJSDocCommentsAndTags, + AstParameterDeclaration, + AstTypeParameterDeclaration, + astIsPropertyAssignment, + astIsBindingElement, + astIsBinaryExpression, + astIsAccessExpression, + astIsVariableDeclaration, + AstAutoAccessorPropertyDeclaration, + astIsPropertyDeclaration, + astHasAccessorModifier, + AstModifierLike, + AstModifier, + astIsDecorator, + AstBindingElement, + AstVariableDeclaration, + AstSignatureDeclaration, + AstClassStaticBlockDeclaration, + astIsClassStaticBlockDeclaration, + isDeclarationName, + AstBindingPattern, } from "./_namespaces/ts.js"; export function isExternalModuleNameRelative(moduleName: string): boolean { @@ -638,6 +677,15 @@ export function walkUpBindingElementsAndPatterns(binding: BindingElement): Varia return node.parent; } +/** @internal */ +export function astWalkUpBindingElementsAndPatterns(binding: AstBindingElement): AstVariableDeclaration | AstParameterDeclaration { + let node = binding.parent; + while (astIsBindingElement(node.parent)) { + node = node.parent.parent; + } + return node.parent; +} + function getCombinedFlags(node: Node, getFlags: (n: Node) => number): number { if (isBindingElement(node)) { node = walkUpBindingElementsAndPatterns(node); @@ -656,6 +704,24 @@ function getCombinedFlags(node: Node, getFlags: (n: Node) => number): number { return flags; } +function astGetCombinedFlags(node: AstNode, getFlags: (n: AstNode) => number): number { + if (astIsBindingElement(node)) { + node = astWalkUpBindingElementsAndPatterns(node); + } + let flags = getFlags(node); + if (node.kind === SyntaxKind.VariableDeclaration) { + node = node.parent; + } + if (node && node.kind === SyntaxKind.VariableDeclarationList) { + flags |= getFlags(node); + node = node.parent; + } + if (node && node.kind === SyntaxKind.VariableStatement) { + flags |= getFlags(node); + } + return flags; +} + export function getCombinedModifierFlags(node: Declaration): ModifierFlags { return getCombinedFlags(node, getEffectiveModifierFlags); } @@ -673,10 +739,22 @@ export function getCombinedNodeFlagsAlwaysIncludeJSDoc(node: Declaration): Modif // list. By calling this function, all those flags are combined so that the client can treat // the node as if it actually had those flags. export function getCombinedNodeFlags(node: Node): NodeFlags { - return getCombinedFlags(node, getNodeFlags); + return astGetCombinedNodeFlags(node.ast); +} + +// Returns the node flags for this node and all relevant parent nodes. This is done so that +// nodes like variable declarations and binding elements can returned a view of their flags +// that includes the modifiers from their container. i.e. flags like export/declare aren't +// stored on the variable declaration directly, but on the containing variable statement +// (if it has one). Similarly, flags for let/const are stored on the variable declaration +// list. By calling this function, all those flags are combined so that the client can treat +// the node as if it actually had those flags. +/** @internal */ +export function astGetCombinedNodeFlags(node: AstNode): NodeFlags { + return astGetCombinedFlags(node, astGetNodeFlags); } -function getNodeFlags(node: Node) { +function astGetNodeFlags(node: AstNode) { return node.flags; } @@ -872,12 +950,28 @@ export function idText(identifierOrPrivateName: Identifier | PrivateIdentifier): return unescapeLeadingUnderscores(identifierOrPrivateName.escapedText); } +export function astIdText(identifierOrPrivateName: AstIdentifier | AstPrivateIdentifier): string { + // NOTE: each branch is duplicated to remain monomorphic + switch (identifierOrPrivateName.kind) { + case SyntaxKind.Identifier: return unescapeLeadingUnderscores(identifierOrPrivateName.data.escapedText); + case SyntaxKind.PrivateIdentifier: return unescapeLeadingUnderscores(identifierOrPrivateName.data.escapedText); + } +} + /** * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the * SyntaxKind for the matching keyword. */ export function identifierToKeywordKind(node: Identifier): KeywordSyntaxKind | undefined { - const token = stringToToken(node.escapedText as string); + return astIdentifierToKeywordKind(node.ast); +} + +/** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ +export function astIdentifierToKeywordKind(node: AstIdentifier): KeywordSyntaxKind | undefined { + const token = stringToToken(node.data.escapedText as string); return token ? tryCast(token, isKeyword) : undefined; } @@ -894,51 +988,60 @@ export function symbolName(symbol: Symbol): string { * will be merged with) */ function nameForNamelessJSDocTypedef(declaration: JSDocTypedefTag | JSDocEnumTag): Identifier | PrivateIdentifier | undefined { + return astNameForNamelessJSDocTypedef(declaration.ast)?.node; +} + +/** + * A JSDocTypedef tag has an _optional_ name field - if a name is not directly present, we should + * attempt to draw the name from the node the declaration is on (as that declaration is what its' symbol + * will be merged with) + */ +function astNameForNamelessJSDocTypedef(declaration: AstJSDocTypedefTag | AstJSDocEnumTag): AstIdentifier | AstPrivateIdentifier | undefined { const hostNode = declaration.parent.parent; if (!hostNode) { return undefined; } // Covers classes, functions - any named declaration host node - if (isDeclaration(hostNode)) { - return getDeclarationIdentifier(hostNode); + if (astIsDeclaration(hostNode)) { + return astGetDeclarationIdentifier(hostNode); } // Covers remaining cases (returning undefined if none match). switch (hostNode.kind) { case SyntaxKind.VariableStatement: - if (hostNode.declarationList && hostNode.declarationList.declarations[0]) { - return getDeclarationIdentifier(hostNode.declarationList.declarations[0]); + if (hostNode.data.declarationList?.data.declarations.items[0]) { + return astGetDeclarationIdentifier(hostNode.data.declarationList.data.declarations.items[0]); } break; case SyntaxKind.ExpressionStatement: - let expr = hostNode.expression; - if (expr.kind === SyntaxKind.BinaryExpression && (expr as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken) { - expr = (expr as BinaryExpression).left; + let expr = hostNode.data.expression; + if (expr.kind === SyntaxKind.BinaryExpression && (expr as AstBinaryExpression).data.operatorToken.kind === SyntaxKind.EqualsToken) { + expr = (expr as AstBinaryExpression).data.left; } switch (expr.kind) { case SyntaxKind.PropertyAccessExpression: - return (expr as PropertyAccessExpression).name; + return (expr as AstPropertyAccessExpression).data.name; case SyntaxKind.ElementAccessExpression: - const arg = (expr as ElementAccessExpression).argumentExpression; - if (isIdentifier(arg)) { + const arg = (expr as AstElementAccessExpression).data.argumentExpression; + if (astIsIdentifier(arg)) { return arg; } } break; case SyntaxKind.ParenthesizedExpression: { - return getDeclarationIdentifier(hostNode.expression); + return astGetDeclarationIdentifier(hostNode.data.expression); } case SyntaxKind.LabeledStatement: { - if (isDeclaration(hostNode.statement) || isExpression(hostNode.statement)) { - return getDeclarationIdentifier(hostNode.statement); + if (astIsDeclaration(hostNode.data.statement) || astIsExpression(hostNode.data.statement)) { + return astGetDeclarationIdentifier(hostNode.data.statement); } break; } } } -function getDeclarationIdentifier(node: Declaration | Expression): Identifier | undefined { - const name = getNameOfDeclaration(node); - return name && isIdentifier(name) ? name : undefined; +function astGetDeclarationIdentifier(node: AstDeclaration | AstExpression): AstIdentifier | undefined { + const name = astGetNameOfDeclaration(node); + return name && astIsIdentifier(name) ? name : undefined; } /** @internal */ @@ -956,6 +1059,10 @@ export function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier return declaration.name || nameForNamelessJSDocTypedef(declaration); } +export function astGetNameOfJSDocTypedef(declaration: AstJSDocTypedefTag): AstIdentifier | AstPrivateIdentifier | undefined { + return declaration.data.name || astNameForNamelessJSDocTypedef(declaration); +} + /** @internal */ export function isNamedDeclaration(node: Node): node is NamedDeclaration & { name: DeclarationName; } { return !!(node as NamedDeclaration).name; // A 'name' property should always be a DeclarationName. @@ -1055,49 +1162,73 @@ export function hasAsteriskToken(node: Node): node is HasAsteriskToken & { aster /** @internal */ export function getNonAssignedNameOfDeclaration(declaration: Declaration | Expression): DeclarationName | undefined { + return astGetNonAssignedNameOfDeclaration(declaration.ast)?.node; +} + +/** @internal */ +export function astGetNonAssignedNameOfDeclaration(declaration: AstDeclaration | AstExpression): AstDeclarationName | undefined { switch (declaration.kind) { case SyntaxKind.Identifier: - return declaration as Identifier; + return declaration as AstIdentifier; case SyntaxKind.JSDocPropertyTag: case SyntaxKind.JSDocParameterTag: { - const { name } = declaration as JSDocPropertyLikeTag; + const { data: { name } } = declaration as AstJSDocPropertyLikeTag; if (name.kind === SyntaxKind.QualifiedName) { - return name.right; + return name.data.right; } break; } case SyntaxKind.CallExpression: case SyntaxKind.BinaryExpression: { - const expr = declaration as BinaryExpression | CallExpression; - switch (getAssignmentDeclarationKind(expr)) { + const expr = declaration as AstBinaryExpression | AstCallExpression; + switch (astGetAssignmentDeclarationKind(expr)) { case AssignmentDeclarationKind.ExportsProperty: case AssignmentDeclarationKind.ThisProperty: case AssignmentDeclarationKind.Property: case AssignmentDeclarationKind.PrototypeProperty: - return getElementOrPropertyAccessArgumentExpressionOrName((expr as BinaryExpression).left as AccessExpression); + return astGetElementOrPropertyAccessArgumentExpressionOrName((expr as AstBinaryExpression).data.left as AstAccessExpression); case AssignmentDeclarationKind.ObjectDefinePropertyValue: case AssignmentDeclarationKind.ObjectDefinePropertyExports: case AssignmentDeclarationKind.ObjectDefinePrototypeProperty: - return (expr as BindableObjectDefinePropertyCall).arguments[1]; + return (expr as AstBindableObjectDefinePropertyCall).data.arguments.items[1]; default: return undefined; } } case SyntaxKind.JSDocTypedefTag: - return getNameOfJSDocTypedef(declaration as JSDocTypedefTag); + return astGetNameOfJSDocTypedef(declaration as AstJSDocTypedefTag); case SyntaxKind.JSDocEnumTag: - return nameForNamelessJSDocTypedef(declaration as JSDocEnumTag); + return astNameForNamelessJSDocTypedef(declaration as AstJSDocEnumTag); case SyntaxKind.ExportAssignment: { - const { expression } = declaration as ExportAssignment; - return isIdentifier(expression) ? expression : undefined; + const { data: { expression } } = declaration as AstExportAssignment; + return astIsIdentifier(expression) ? expression : undefined; } case SyntaxKind.ElementAccessExpression: - const expr = declaration as ElementAccessExpression; - if (isBindableStaticElementAccessExpression(expr)) { - return expr.argumentExpression; + const expr = declaration as AstElementAccessExpression; + if (astIsBindableStaticElementAccessExpression(expr)) { + return expr.data.argumentExpression; } } - return (declaration as NamedDeclaration).name; + const name = astGetName(declaration); + if (name) { + Debug.type(name); + switch (name.kind) { + case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: + case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.Identifier: + case SyntaxKind.PrivateIdentifier: + case SyntaxKind.ComputedPropertyName: + case SyntaxKind.ObjectBindingPattern: + case SyntaxKind.ArrayBindingPattern: + case SyntaxKind.JsxNamespacedName: + return name; + default: + Debug.assertNeverTypeOnly(name); + } + } + return undefined; } export function getNameOfDeclaration(declaration: Declaration | Expression | undefined): DeclarationName | undefined { @@ -1106,24 +1237,39 @@ export function getNameOfDeclaration(declaration: Declaration | Expression | und (isFunctionExpression(declaration) || isArrowFunction(declaration) || isClassExpression(declaration) ? getAssignedName(declaration) : undefined); } +export function astGetNameOfDeclaration(declaration: AstDeclaration | AstExpression | undefined): AstDeclarationName | undefined { + if (declaration === undefined) return undefined; + return astGetNonAssignedNameOfDeclaration(declaration) || + (astIsFunctionExpression(declaration) || astIsArrowFunction(declaration) || astIsClassExpression(declaration) ? astGetAssignedName(declaration) : undefined); +} + /** @internal */ export function getAssignedName(node: Node): DeclarationName | undefined { + return astGetAssignedName(node.ast)?.node; +} + +/** @internal */ +export function astGetAssignedName(node: AstNode): AstDeclarationName | undefined { + // NOTE: branches may be repeated to remain monomorphic if (!node.parent) { return undefined; } - else if (isPropertyAssignment(node.parent) || isBindingElement(node.parent)) { - return node.parent.name; + else if (astIsPropertyAssignment(node.parent)) { + return node.parent.data.name; + } + else if (astIsBindingElement(node.parent)) { + return node.parent.data.name; } - else if (isBinaryExpression(node.parent) && node === node.parent.right) { - if (isIdentifier(node.parent.left)) { - return node.parent.left; + else if (astIsBinaryExpression(node.parent) && node === node.parent.data.right) { + if (astIsIdentifier(node.parent.data.left)) { + return node.parent.data.left; } - else if (isAccessExpression(node.parent.left)) { - return getElementOrPropertyAccessArgumentExpressionOrName(node.parent.left); + else if (astIsAccessExpression(node.parent.data.left)) { + return astGetElementOrPropertyAccessArgumentExpressionOrName(node.parent.data.left); } } - else if (isVariableDeclaration(node.parent) && isIdentifier(node.parent.name)) { - return node.parent.name; + else if (astIsVariableDeclaration(node.parent) && astIsIdentifier(node.parent.data.name)) { + return node.parent.data.name; } } @@ -1139,16 +1285,16 @@ export function getModifiers(node: HasModifiers): readonly Modifier[] | undefine } } -function getJSDocParameterTagsWorker(param: ParameterDeclaration, noCache?: boolean): readonly JSDocParameterTag[] { - if (param.name) { - if (isIdentifier(param.name)) { - const name = param.name.escapedText; - return getJSDocTagsWorker(param.parent, noCache).filter((tag): tag is JSDocParameterTag => isJSDocParameterTag(tag) && isIdentifier(tag.name) && tag.name.escapedText === name); + function astGetJSDocParameterTagsWorker(param: AstParameterDeclaration, noCache?: boolean): readonly JSDocParameterTag[] { + if (param.data.name) { + if (astIsIdentifier(param.data.name)) { + const name = param.data.name.data.escapedText; + return astGetJSDocTagsWorker(param.parent, noCache).filter((tag): tag is JSDocParameterTag => isJSDocParameterTag(tag) && isIdentifier(tag.name) && tag.name.escapedText === name); } else { - const i = param.parent.parameters.indexOf(param); + const i = param.parent.data.parameters.items.indexOf(param); Debug.assert(i > -1, "Parameters should always be in their parents' parameter list"); - const paramTags = getJSDocTagsWorker(param.parent, noCache).filter(isJSDocParameterTag); + const paramTags = astGetJSDocTagsWorker(param.parent, noCache).filter(isJSDocParameterTag); if (i < paramTags.length) { return [paramTags[i]]; } @@ -1171,17 +1317,38 @@ function getJSDocParameterTagsWorker(param: ParameterDeclaration, noCache?: bool * For binding patterns, parameter tags are matched by position. */ export function getJSDocParameterTags(param: ParameterDeclaration): readonly JSDocParameterTag[] { - return getJSDocParameterTagsWorker(param, /*noCache*/ false); + return astGetJSDocParameterTags(param.ast); +} + +/** + * Gets the JSDoc parameter tags for the node if present. + * + * @remarks Returns any JSDoc param tag whose name matches the provided + * parameter, whether a param tag on a containing function + * expression, or a param tag on a variable declaration whose + * initializer is the containing function. The tags closest to the + * node are returned first, so in the previous example, the param + * tag on the containing function expression would be first. + * + * For binding patterns, parameter tags are matched by position. + */ +export function astGetJSDocParameterTags(param: AstParameterDeclaration): readonly JSDocParameterTag[] { + return astGetJSDocParameterTagsWorker(param, /*noCache*/ false); } /** @internal */ export function getJSDocParameterTagsNoCache(param: ParameterDeclaration): readonly JSDocParameterTag[] { - return getJSDocParameterTagsWorker(param, /*noCache*/ true); + return astGetJSDocParameterTagsNoCache(param.ast); +} + +/** @internal */ +export function astGetJSDocParameterTagsNoCache(param: AstParameterDeclaration): readonly JSDocParameterTag[] { + return astGetJSDocParameterTagsWorker(param, /*noCache*/ true); } -function getJSDocTypeParameterTagsWorker(param: TypeParameterDeclaration, noCache?: boolean): readonly JSDocTemplateTag[] { - const name = param.name.escapedText; - return getJSDocTagsWorker(param.parent, noCache).filter((tag): tag is JSDocTemplateTag => isJSDocTemplateTag(tag) && tag.typeParameters.some(tp => tp.name.escapedText === name)); +function astGetJSDocTypeParameterTagsWorker(param: AstTypeParameterDeclaration, noCache?: boolean): readonly JSDocTemplateTag[] { + const name = param.data.name.data.escapedText; + return astGetJSDocTagsWorker(param.parent, noCache).filter((tag): tag is JSDocTemplateTag => isJSDocTemplateTag(tag) && tag.typeParameters.some(tp => tp.name.escapedText === name)); } /** @@ -1195,12 +1362,31 @@ function getJSDocTypeParameterTagsWorker(param: TypeParameterDeclaration, noCach * tag on the containing function expression would be first. */ export function getJSDocTypeParameterTags(param: TypeParameterDeclaration): readonly JSDocTemplateTag[] { - return getJSDocTypeParameterTagsWorker(param, /*noCache*/ false); + return astGetJSDocTypeParameterTags(param.ast); +} + +/** + * Gets the JSDoc type parameter tags for the node if present. + * + * @remarks Returns any JSDoc template tag whose names match the provided + * parameter, whether a template tag on a containing function + * expression, or a template tag on a variable declaration whose + * initializer is the containing function. The tags closest to the + * node are returned first, so in the previous example, the template + * tag on the containing function expression would be first. + */ +export function astGetJSDocTypeParameterTags(param: AstTypeParameterDeclaration): readonly JSDocTemplateTag[] { + return astGetJSDocTypeParameterTagsWorker(param, /*noCache*/ false); } /** @internal */ export function getJSDocTypeParameterTagsNoCache(param: TypeParameterDeclaration): readonly JSDocTemplateTag[] { - return getJSDocTypeParameterTagsWorker(param, /*noCache*/ true); + return astGetJSDocTypeParameterTagsNoCache(param.ast); +} + +/** @internal */ +export function astGetJSDocTypeParameterTagsNoCache(param: AstTypeParameterDeclaration): readonly JSDocTemplateTag[] { + return astGetJSDocTypeParameterTagsWorker(param, /*noCache*/ true); } /** @@ -1235,7 +1421,12 @@ export function getJSDocPublicTag(node: Node): JSDocPublicTag | undefined { /** @internal */ export function getJSDocPublicTagNoCache(node: Node): JSDocPublicTag | undefined { - return getFirstJSDocTag(node, isJSDocPublicTag, /*noCache*/ true); + return astGetJSDocPublicTagNoCache(node.ast); +} + +/** @internal */ +export function astGetJSDocPublicTagNoCache(node: AstNode): JSDocPublicTag | undefined { + return astGetFirstJSDocTag(node, isJSDocPublicTag, /*noCache*/ true); } /** Gets the JSDoc private tag for the node if present */ @@ -1245,7 +1436,12 @@ export function getJSDocPrivateTag(node: Node): JSDocPrivateTag | undefined { /** @internal */ export function getJSDocPrivateTagNoCache(node: Node): JSDocPrivateTag | undefined { - return getFirstJSDocTag(node, isJSDocPrivateTag, /*noCache*/ true); + return astGetJSDocPrivateTagNoCache(node.ast); +} + +/** @internal */ +export function astGetJSDocPrivateTagNoCache(node: AstNode): JSDocPrivateTag | undefined { + return astGetFirstJSDocTag(node, isJSDocPrivateTag, /*noCache*/ true); } /** Gets the JSDoc protected tag for the node if present */ @@ -1255,7 +1451,12 @@ export function getJSDocProtectedTag(node: Node): JSDocProtectedTag | undefined /** @internal */ export function getJSDocProtectedTagNoCache(node: Node): JSDocProtectedTag | undefined { - return getFirstJSDocTag(node, isJSDocProtectedTag, /*noCache*/ true); + return astGetJSDocProtectedTagNoCache(node.ast); +} + +/** @internal */ +export function astGetJSDocProtectedTagNoCache(node: AstNode): JSDocProtectedTag | undefined { + return astGetFirstJSDocTag(node, isJSDocProtectedTag, /*noCache*/ true); } /** Gets the JSDoc protected tag for the node if present */ @@ -1265,11 +1466,26 @@ export function getJSDocReadonlyTag(node: Node): JSDocReadonlyTag | undefined { /** @internal */ export function getJSDocReadonlyTagNoCache(node: Node): JSDocReadonlyTag | undefined { - return getFirstJSDocTag(node, isJSDocReadonlyTag, /*noCache*/ true); + return astGetJSDocReadonlyTagNoCache(node.ast); } +/** @internal */ +export function astGetJSDocReadonlyTagNoCache(node: AstNode): JSDocReadonlyTag | undefined { + return astGetFirstJSDocTag(node, isJSDocReadonlyTag, /*noCache*/ true); +} + +export function getJSDocOverrideTag(node: Node): JSDocOverrideTag | undefined { + return getFirstJSDocTag(node, isJSDocOverrideTag); +} + +/** @internal */ export function getJSDocOverrideTagNoCache(node: Node): JSDocOverrideTag | undefined { - return getFirstJSDocTag(node, isJSDocOverrideTag, /*noCache*/ true); + return astGetJSDocOverrideTagNoCache(node.ast); +} + +/** @internal */ +export function astGetJSDocOverrideTagNoCache(node: AstNode): JSDocOverrideTag | undefined { + return astGetFirstJSDocTag(node, isJSDocOverrideTag, /*noCache*/ true); } /** Gets the JSDoc deprecated tag for the node if present */ @@ -1279,7 +1495,12 @@ export function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefine /** @internal */ export function getJSDocDeprecatedTagNoCache(node: Node): JSDocDeprecatedTag | undefined { - return getFirstJSDocTag(node, isJSDocDeprecatedTag, /*noCache*/ true); + return astGetJSDocDeprecatedTagNoCache(node.ast); +} + +/** @internal */ +export function astGetJSDocDeprecatedTagNoCache(node: AstNode): JSDocDeprecatedTag | undefined { + return astGetFirstJSDocTag(node, isJSDocDeprecatedTag, /*noCache*/ true); } /** Gets the JSDoc enum tag for the node if present */ @@ -1376,6 +1597,22 @@ function getJSDocTagsWorker(node: Node, noCache?: boolean): readonly JSDocTag[] return tags; } +function astGetJSDocTagsWorker(node: AstNode, noCache?: boolean): readonly JSDocTag[] { + if (!astCanHaveJSDoc(node)) return emptyArray; + let tags = node.data.jsDoc?.jsDocCache; + // If cache is 'null', that means we did the work of searching for JSDoc tags and came up with nothing. + if (tags === undefined || noCache) { + const comments = astGetJSDocCommentsAndTags(node, noCache); + Debug.assert(comments.length < 2 || comments[0] !== comments[1]); + tags = flatMap(comments, j => isJSDoc(j) ? j.tags : j); + if (!noCache) { + node.data.jsDoc ??= []; + node.data.jsDoc.jsDocCache = tags; + } + } + return tags; +} + /** Get all JSDoc tags related to a node, including those on parent nodes. */ export function getJSDocTags(node: Node): readonly JSDocTag[] { return getJSDocTagsWorker(node, /*noCache*/ false); @@ -1383,7 +1620,12 @@ export function getJSDocTags(node: Node): readonly JSDocTag[] { /** Get the first JSDoc tag of a specified kind, or undefined if not present. */ function getFirstJSDocTag(node: Node, predicate: (tag: JSDocTag) => tag is T, noCache?: boolean): T | undefined { - return find(getJSDocTagsWorker(node, noCache), predicate); + return astGetFirstJSDocTag(node.ast, predicate, noCache); +} + +/** Get the first JSDoc tag of a specified kind, or undefined if not present. */ +function astGetFirstJSDocTag(node: AstNode, predicate: (tag: JSDocTag) => tag is T, noCache?: boolean): T | undefined { + return find(astGetJSDocTagsWorker(node, noCache), predicate); } /** Gets all JSDoc tags that match a specified predicate */ @@ -1750,6 +1992,11 @@ export function isClassMemberModifier(idToken: SyntaxKind): boolean { } export function isModifier(node: Node): node is Modifier { + return astIsModifier(node.ast); +} + +/** @internal */ +export function astIsModifier(node: AstNode): node is AstModifier { return isModifierKind(node.kind); } @@ -1781,9 +2028,17 @@ export function isFunctionLike(node: Node | undefined): node is SignatureDeclara return !!node && isFunctionLikeKind(node.kind); } -/** @internal */ +/** + * @deprecated Use {@link astIsFunctionLikeOrClassStaticBlockDeclaration} + * @internal + */ export function isFunctionLikeOrClassStaticBlockDeclaration(node: Node | undefined): node is SignatureDeclaration | ClassStaticBlockDeclaration { - return !!node && (isFunctionLikeKind(node.kind) || isClassStaticBlockDeclaration(node)); + return astIsFunctionLikeOrClassStaticBlockDeclaration(node?.ast); +} + +/** @internal */ +export function astIsFunctionLikeOrClassStaticBlockDeclaration(node: AstNode | undefined): node is AstSignatureDeclaration | AstClassStaticBlockDeclaration { + return !!node && (isFunctionLikeKind(node.kind) || astIsClassStaticBlockDeclaration(node)); } /** @internal */ @@ -1835,6 +2090,11 @@ export function isFunctionOrModuleBlock(node: Node): boolean { // Classes export function isClassElement(node: Node): node is ClassElement { + return astIsClassElement(node.ast); +} + +// Classes +export function astIsClassElement(node: AstNode): node is AstClassElement { const kind = node.kind; return kind === SyntaxKind.Constructor || kind === SyntaxKind.PropertyDeclaration @@ -1847,6 +2107,10 @@ export function isClassElement(node: Node): node is ClassElement { } export function isClassLike(node: Node): node is ClassLikeDeclaration { + return node && astIsClassLike(node.ast); +} + +export function astIsClassLike(node: AstNode): node is AstClassLikeDeclaration { return node && (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression); } @@ -1858,6 +2122,11 @@ export function isAutoAccessorPropertyDeclaration(node: Node): node is AutoAcces return isPropertyDeclaration(node) && hasAccessorModifier(node); } +/** @internal */ +export function astIsAutoAccessorPropertyDeclaration(node: AstNode): node is AstAutoAccessorPropertyDeclaration { + return astIsPropertyDeclaration(node) && astHasAccessorModifier(node); +} + /** @internal */ export function isClassInstanceProperty(node: Declaration): boolean { if (isInJSFile(node) && isExpandoPropertyDeclaration(node)) { @@ -1881,7 +2150,12 @@ export function isMethodOrAccessor(node: Node): node is MethodDeclaration | Acce // Type members export function isModifierLike(node: Node): node is ModifierLike { - return isModifier(node) || isDecorator(node); + return astIsModifierLike(node.ast); +} + +/** @intenral */ +export function astIsModifierLike(node: AstNode): node is AstModifierLike { + return astIsModifier(node) || astIsDecorator(node); } export function isTypeElement(node: Node): node is TypeElement { @@ -1933,8 +2207,13 @@ export function isFunctionOrConstructorTypeNode(node: Node): node is FunctionTyp // Binding patterns -/** @internal */ +/** @deprecated @internal */ export function isBindingPattern(node: Node | undefined): node is BindingPattern { + return astIsBindingPattern(node?.ast); +} + +/** @internal */ +export function astIsBindingPattern(node: AstNode | undefined): node is AstBindingPattern { if (node) { const kind = node.kind; return kind === SyntaxKind.ArrayBindingPattern @@ -2194,7 +2473,8 @@ export function isExpression(node: Node): node is Expression { return isExpressionKind(skipPartiallyEmittedExpressions(node).kind); } -function isExpressionKind(kind: SyntaxKind): boolean { +/** @internal */ +export function isExpressionKind(kind: SyntaxKind): boolean { switch (kind) { case SyntaxKind.ConditionalExpression: case SyntaxKind.YieldExpression: @@ -2503,8 +2783,13 @@ function isStatementKindButNotDeclarationKind(kind: SyntaxKind) { /** @internal */ export function isDeclaration(node: Node): node is NamedDeclaration { + return astIsDeclaration(node.ast); +} + +/** @internal */ +export function astIsDeclaration(node: AstNode): node is AstNamedDeclaration { if (node.kind === SyntaxKind.TypeParameter) { - return (node.parent && node.parent.kind !== SyntaxKind.JSDocTemplateTag) || isInJSFile(node); + return (node.parent && node.parent.kind !== SyntaxKind.JSDocTemplateTag) || astIsInJSFile(node); } return isDeclarationKind(node.kind); @@ -2625,6 +2910,15 @@ export function isJSDocNode(node: Node): boolean { return node.kind >= SyntaxKind.FirstJSDocNode && node.kind <= SyntaxKind.LastJSDocNode; } +/** + * True if node is of some JSDoc syntax kind. + * + * @internal + */ +export function astIsJSDocNode(node: AstNode): boolean { + return node.kind >= SyntaxKind.FirstJSDocNode && node.kind <= SyntaxKind.LastJSDocNode; +} + /** True if node is of a kind that may contain comment text. */ export function isJSDocCommentContainingNode(node: Node): boolean { return node.kind === SyntaxKind.JSDoc diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index dbd49379e5750..82cfd149537cc 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -13,7 +13,7 @@ import { isArrayBindingElement, isAssertClause, isAssertsKeyword, - isAsteriskToken, + astIseriskToken, isAwaitKeyword, isBinaryOperatorToken, isBindingElement, @@ -705,7 +705,7 @@ const visitEachChildTable: VisitEachChildTable = { return context.factory.updateMethodDeclaration( node, nodesVisitor(node.modifiers, visitor, isModifierLike), - tokenVisitor ? nodeVisitor(node.asteriskToken, tokenVisitor, isAsteriskToken) : node.asteriskToken, + tokenVisitor ? nodeVisitor(node.asteriskToken, tokenVisitor, astIseriskToken) : node.asteriskToken, Debug.checkDefined(nodeVisitor(node.name, visitor, isPropertyName)), tokenVisitor ? nodeVisitor(node.questionToken, tokenVisitor, isQuestionToken) : node.questionToken, nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), @@ -1102,7 +1102,7 @@ const visitEachChildTable: VisitEachChildTable = { return context.factory.updateFunctionExpression( node, nodesVisitor(node.modifiers, visitor, isModifier), - tokenVisitor ? nodeVisitor(node.asteriskToken, tokenVisitor, isAsteriskToken) : node.asteriskToken, + tokenVisitor ? nodeVisitor(node.asteriskToken, tokenVisitor, astIseriskToken) : node.asteriskToken, nodeVisitor(node.name, visitor, isIdentifier), nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), visitParameterList(node.parameters, visitor, context, nodesVisitor), @@ -1196,7 +1196,7 @@ const visitEachChildTable: VisitEachChildTable = { [SyntaxKind.YieldExpression]: function visitEachChildOfYieldExpression(node, visitor, context, _nodesVisitor, nodeVisitor, tokenVisitor) { return context.factory.updateYieldExpression( node, - tokenVisitor ? nodeVisitor(node.asteriskToken, tokenVisitor, isAsteriskToken) : node.asteriskToken, + tokenVisitor ? nodeVisitor(node.asteriskToken, tokenVisitor, astIseriskToken) : node.asteriskToken, nodeVisitor(node.expression, visitor, isExpression), ); }, @@ -1430,7 +1430,7 @@ const visitEachChildTable: VisitEachChildTable = { return context.factory.updateFunctionDeclaration( node, nodesVisitor(node.modifiers, visitor, isModifier), - tokenVisitor ? nodeVisitor(node.asteriskToken, tokenVisitor, isAsteriskToken) : node.asteriskToken, + tokenVisitor ? nodeVisitor(node.asteriskToken, tokenVisitor, astIseriskToken) : node.asteriskToken, nodeVisitor(node.name, visitor, isIdentifier), nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), visitParameterList(node.parameters, visitor, context, nodesVisitor), diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 0f8cb859d6822..c6e93032c85cf 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -244,7 +244,7 @@ function getCommentHavingNodes(declaration: Declaration): readonly (JSDoc | JSDo } /** @internal */ -export function getJsDocTagsFromDeclarations(declarations?: Declaration[], checker?: TypeChecker): JSDocTagInfo[] { +export function getJsDocTagsFromDeclarations(declarations?: readonly Declaration[], checker?: TypeChecker): JSDocTagInfo[] { // Only collect doc comments from duplicate declarations once. const infos: JSDocTagInfo[] = []; forEachUnique(declarations, declaration => { diff --git a/src/services/services.ts b/src/services/services.ts index 6a8531f7dcd71..7621fec5047b7 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -299,6 +299,8 @@ import { UnionType, updateSourceFile, UserPreferences, + AstDeclaration, + createReadOnlyArrayView, } from "./_namespaces/ts.js"; import * as NavigateTo from "./_namespaces/ts.NavigateTo.js"; import * as NavigationBar from "./_namespaces/ts.NavigationBar.js"; @@ -316,8 +318,9 @@ export const servicesVersion = "0.8"; class SymbolObject implements Symbol { flags: SymbolFlags; escapedName: __String; - declarations?: Declaration[]; - valueDeclaration?: Declaration; + private _declarations: readonly Declaration[] | undefined = undefined; + astValueDeclaration: AstDeclaration | undefined = undefined; + astDeclarations: AstDeclaration[] | undefined = undefined; members?: SymbolTable; exports?: SymbolTable; id: number; @@ -344,8 +347,6 @@ class SymbolObject implements Symbol { // Note: if modifying this, be sure to update Symbol in src/compiler/types.ts this.flags = flags; this.escapedName = name; - this.declarations = undefined; - this.valueDeclaration = undefined; this.id = 0; this.mergeId = 0; this.parent = undefined; @@ -358,6 +359,10 @@ class SymbolObject implements Symbol { this.links = undefined; // used by TransientSymbol } + get valueDeclaration() { return this.astValueDeclaration?.node; } + set valueDeclaration(value) { this.astValueDeclaration = value?.ast; } + get declarations() { return this._declarations ??= this.astDeclarations && createReadOnlyArrayView(this.astDeclarations, ast => ast.node); } + getFlags(): SymbolFlags { return this.flags; } @@ -374,7 +379,7 @@ class SymbolObject implements Symbol { return this.name; } - getDeclarations(): Declaration[] | undefined { + getDeclarations(): readonly Declaration[] | undefined { return this.declarations; } @@ -617,7 +622,7 @@ function hasJSDocInheritDocTag(node: Node) { return getJSDocTags(node).some(tag => tag.tagName.text === "inheritDoc" || tag.tagName.text === "inheritdoc"); } -function getJsDocTagsOfDeclarations(declarations: Declaration[] | undefined, checker: TypeChecker | undefined): JSDocTagInfo[] { +function getJsDocTagsOfDeclarations(declarations: readonly Declaration[] | undefined, checker: TypeChecker | undefined): JSDocTagInfo[] { if (!declarations) return emptyArray; let tags = JsDoc.getJsDocTagsFromDeclarations(declarations, checker); diff --git a/src/services/types.ts b/src/services/types.ts index f15fb1cfcb1bb..5d9573421c7fd 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -51,7 +51,7 @@ declare module "../compiler/types.js" { getFlags(): SymbolFlags; getEscapedName(): __String; getName(): string; - getDeclarations(): Declaration[] | undefined; + getDeclarations(): readonly Declaration[] | undefined; getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[]; /** @internal */ getContextualDocumentationComment(context: Node | undefined, checker: TypeChecker | undefined): SymbolDisplayPart[]; diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@link tags.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@link tags.json index 0b04453b8c865..d0c11175d89ee 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@link tags.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@link tags.json @@ -5,7 +5,7 @@ "flags": "JSDoc", "modifierFlagsCache": 0, "transformFlags": 0, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 0, @@ -89,7 +89,7 @@ "transformFlags": 0, "escapedText": "param" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 70, @@ -164,7 +164,7 @@ "transformFlags": 0, "escapedText": "param" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 113, @@ -404,7 +404,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 597, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.authorTag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.authorTag.json index ff56dc4ecb864..bb4bc51e36c39 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.authorTag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.authorTag.json @@ -21,7 +21,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 15, @@ -87,7 +87,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 178, @@ -119,7 +119,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 235, @@ -168,7 +168,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 346, @@ -200,7 +200,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 389, @@ -232,7 +232,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 406, @@ -264,7 +264,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 437, @@ -296,7 +296,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 453, @@ -328,7 +328,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 461, @@ -360,7 +360,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 469, @@ -392,7 +392,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 497, @@ -424,7 +424,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 510, @@ -456,7 +456,7 @@ "transformFlags": 0, "escapedText": "author" }, - "comment": { + "commentArray": { "0": { "kind": "JSDocText", "pos": 530, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 436b60f503de6..f9d15c66f730d 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4444,10 +4444,10 @@ declare namespace ts { | ModuleBlock | MissingDeclaration | NotEmittedStatement; - export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType; - export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement; + export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType | OptionalTypeNode | RestTypeNode | NamedTupleMember | TemplateLiteralTypeSpan | SatisfiesExpression | JSDocNamepathType | JSDocSignature; + export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | ExpressionWithTypeArguments | TypeQueryNode | ImportTypeNode | TypeReferenceNode | JsxOpeningElement | JsxSelfClosingElement; export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute; - export type HasExpressionInitializer = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | EnumMember; + export type HasExpressionInitializer = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | PropertySignature | EnumMember; export type HasDecorators = ParameterDeclaration | PropertyDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ClassExpression | ClassDeclaration; export type HasModifiers = TypeParameterDeclaration | ParameterDeclaration | ConstructorTypeNode | PropertySignature | PropertyDeclaration | MethodSignature | MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | IndexSignatureDeclaration | FunctionExpression | ArrowFunction | ClassExpression | VariableStatement | FunctionDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | ExportAssignment | ExportDeclaration; export class NodeArray extends ReadonlyArray { @@ -5239,10 +5239,14 @@ declare namespace ts { get right(): Expression; } export type AssignmentOperatorToken = Token; - export interface AssignmentExpression extends BinaryExpression { + export type AssignmentExpression = BinaryExpression & { readonly left: LeftHandSideExpression; readonly operatorToken: TOperator; - } + readonly data: { + readonly left: AstLeftHandSideExpression; + readonly operatorToken: TOperator; + }; + }; export interface ObjectDestructuringAssignment extends AssignmentExpression { readonly left: ObjectLiteralExpression; } @@ -5586,7 +5590,7 @@ declare namespace ts { get expression(): Expression; get type(): TypeNode; } - export class TypeAssertionExpression extends Node implements UnaryExpression { + export class TypeAssertionExpression extends Node implements UnaryExpression { _unaryExpressionBrand: any; _expressionBrand: any; get type(): TypeNode; @@ -6417,13 +6421,18 @@ declare namespace ts { get type(): JSDocReturnTag | undefined; } export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { - readonly data: AstJSDocTagData & AstDeclarationData; readonly parent: JSDoc; readonly name: EntityName; readonly typeExpression?: JSDocTypeExpression | undefined; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ readonly isNameFirst: boolean; readonly isBracketed: boolean; + readonly data: AstJSDocTagData & AstDeclarationData & { + readonly name: AstEntityName; + readonly typeExpression?: AstJSDocTypeExpression | undefined; + readonly isNameFirst: boolean; + readonly isBracketed: boolean; + }; } export class JSDocPropertyTag extends JSDocTag implements JSDocPropertyLikeTag, Declaration { _declarationBrand: any; @@ -7126,8 +7135,8 @@ declare namespace ts { export interface Symbol { flags: SymbolFlags; escapedName: __String; - declarations?: Declaration[]; - valueDeclaration?: Declaration; + readonly declarations?: readonly Declaration[]; + readonly valueDeclaration?: Declaration; members?: SymbolTable; exports?: SymbolTable; globalExports?: SymbolTable; @@ -7137,7 +7146,7 @@ declare namespace ts { getFlags(): SymbolFlags; getEscapedName(): __String; getName(): string; - getDeclarations(): Declaration[] | undefined; + getDeclarations(): readonly Declaration[] | undefined; getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[]; getJsDocTags(checker?: TypeChecker): JSDocTagInfo[]; } @@ -9024,7 +9033,7 @@ declare namespace ts { private _extra; readonly kind: N["kind"]; readonly data: N["data"]; - parent: AstNode> | undefined; + parent: AstNodeOneOf; flags: NodeFlags; pos: number; end: number; @@ -9405,6 +9414,7 @@ declare namespace ts { type: AstTypeNode | undefined; initializer: AstExpression | undefined; } + export type AstVariableLikeDeclaration = AstNodeOneOf; export type AstVariableDeclarationList = AstNode; export class AstVariableDeclarationListData extends AstData { declarations: AstNodeArray; @@ -9417,6 +9427,7 @@ declare namespace ts { initializer: AstExpression | undefined; } export type AstPropertyDeclaration = AstNode; + export type AstAutoAccessorPropertyDeclaration = AstNode; export class AstPropertyDeclarationData extends AstData { modifiers: AstNodeArray | undefined; name: AstPropertyName; @@ -9669,6 +9680,7 @@ declare namespace ts { operatorToken: AstBinaryOperatorToken; right: AstExpression; } + export type AstAssignmentExpression = AstNodeOneOf>; export type AstDestructuringAssignment = AstNodeOneOf; export class AstConditionalExpressionData extends AstData { condition: AstExpression; @@ -9771,6 +9783,7 @@ declare namespace ts { name: AstMemberName; } export type AstPropertyAccessEntityNameExpression = AstNode; + export type AstAccessExpression = AstNodeOneOf; export type AstEntityNameExpression = AstNodeOneOf; export type AstPropertyAccessChain = AstNode; export class AstElementAccessExpressionData extends AstData { @@ -9806,7 +9819,7 @@ declare namespace ts { expression: AstExpression; type: AstTypeNode; } - export class AstTypeAssertionData extends AstData { + export class AstTypeAssertionExpressionData extends AstData { type: AstTypeNode; expression: AstUnaryExpression; } @@ -10164,7 +10177,8 @@ declare namespace ts { type: AstTypeNode; } export class AstJSDocData extends AstData { - comment: string | AstNodeArray | undefined; + comment: string | undefined; + commentArray: AstNodeArray | undefined; tags: AstNodeArray | undefined; } export type AstHasJSDoc = AstNodeOneOf; @@ -10186,71 +10200,135 @@ declare namespace ts { text: string; } export type AstBaseJSDocTag = AstNode>; - export class AstJSDocTagData extends AstData { - tagName: AstIdentifier; - comment: string | AstNodeArray | undefined; + export abstract class AstJSDocTagData extends AstData { + abstract tagName: AstIdentifier; + abstract comment: string | undefined; + abstract commentArray: AstNodeArray | undefined; } export class AstJSDocUnknownTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; } export type AstJSDocClassReference = AstNode; export interface AstJSDocClassReferenceData extends AstExpressionWithTypeArgumentsData { expression: AstIdentifier | AstPropertyAccessEntityNameExpression; } export class AstJSDocAugmentsTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; class: AstJSDocClassReference; } export class AstJSDocImplementsTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; class: AstJSDocClassReference; } export class AstJSDocAuthorTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; } export class AstJSDocDeprecatedTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; } export class AstJSDocClassTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; } export class AstJSDocPublicTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; } export class AstJSDocPrivateTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; } export class AstJSDocProtectedTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; } export class AstJSDocReadonlyTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; } export class AstJSDocOverrideTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; } export class AstJSDocEnumTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; typeExpression: AstJSDocTypeExpression; } export class AstJSDocThisTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; typeExpression: AstJSDocTypeExpression; } export class AstJSDocTemplateTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; constraint: AstJSDocTypeExpression | undefined; typeParameters: AstNodeArray; } export class AstJSDocSeeTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; name: AstJSDocNameReference | undefined; } export class AstJSDocReturnTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; typeExpression: AstJSDocTypeExpression | undefined; } export class AstJSDocTypeTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; typeExpression: AstJSDocTypeExpression; } export class AstJSDocTypedefTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; typeExpression: AstJSDocTypeExpression | AstJSDocTypeLiteral | undefined; fullName: AstJSDocNamespaceDeclaration | AstIdentifier | undefined; name: AstIdentifier | undefined; } export class AstJSDocCallbackTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; fullName: AstJSDocNamespaceDeclaration | AstIdentifier | undefined; name: AstIdentifier | undefined; typeExpression: AstJSDocSignature; } export class AstJSDocOverloadTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; typeExpression: AstJSDocSignature; } export class AstJSDocThrowsTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; typeExpression: AstJSDocTypeExpression | undefined; } export class AstJSDocSignatureData extends AstData { @@ -10259,6 +10337,9 @@ declare namespace ts { type: AstJSDocReturnTag | undefined; } export class AstJSDocPropertyTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; typeExpression: AstJSDocTypeExpression | undefined; name: AstEntityName; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ @@ -10266,6 +10347,9 @@ declare namespace ts { isBracketed: boolean; } export class AstJSDocParameterTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; typeExpression: AstJSDocTypeExpression | undefined; name: AstEntityName; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ @@ -10279,9 +10363,15 @@ declare namespace ts { isArrayType: boolean; } export class AstJSDocSatisfiesTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; typeExpression: AstJSDocTypeExpression; } export class AstJSDocImportTagData extends AstJSDocTagData { + tagName: AstIdentifier; + comment: string | undefined; + commentArray: AstNodeArray | undefined; importClause: AstImportClause | undefined; moduleSpecifier: AstExpression; attributes: AstImportAttributes | undefined; @@ -10350,7 +10440,6 @@ declare namespace ts { impliedNodeFormat: ResolutionMode | undefined; moduleName: string | undefined; namedDeclarations: Map | undefined; - cloneNode(node: AstNode): AstNode; } export type AstMethodSignature = AstNode; export type AstMethodDeclaration = AstNode; @@ -10587,6 +10676,7 @@ declare namespace ts { > > : never; + export type AstNamedDeclaration = AstNodeOneOf; export enum FileWatcherEventKind { Created = 0, Changed = 1, @@ -10801,14 +10891,22 @@ declare namespace ts { */ export function unescapeLeadingUnderscores(identifier: __String): string; export function idText(identifierOrPrivateName: Identifier | PrivateIdentifier): string; + export function astIdText(identifierOrPrivateName: AstIdentifier | AstPrivateIdentifier): string; /** * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the * SyntaxKind for the matching keyword. */ export function identifierToKeywordKind(node: Identifier): KeywordSyntaxKind | undefined; + /** + * If the text of an Identifier matches a keyword (including contextual and TypeScript-specific keywords), returns the + * SyntaxKind for the matching keyword. + */ + export function astIdentifierToKeywordKind(node: AstIdentifier): KeywordSyntaxKind | undefined; export function symbolName(symbol: Symbol): string; export function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | PrivateIdentifier | undefined; + export function astGetNameOfJSDocTypedef(declaration: AstJSDocTypedefTag): AstIdentifier | AstPrivateIdentifier | undefined; export function getNameOfDeclaration(declaration: Declaration | Expression | undefined): DeclarationName | undefined; + export function astGetNameOfDeclaration(declaration: AstDeclaration | AstExpression | undefined): AstDeclarationName | undefined; export function getDecorators(node: HasDecorators): readonly Decorator[] | undefined; export function getModifiers(node: HasModifiers): readonly Modifier[] | undefined; /** @@ -10824,6 +10922,19 @@ declare namespace ts { * For binding patterns, parameter tags are matched by position. */ export function getJSDocParameterTags(param: ParameterDeclaration): readonly JSDocParameterTag[]; + /** + * Gets the JSDoc parameter tags for the node if present. + * + * @remarks Returns any JSDoc param tag whose name matches the provided + * parameter, whether a param tag on a containing function + * expression, or a param tag on a variable declaration whose + * initializer is the containing function. The tags closest to the + * node are returned first, so in the previous example, the param + * tag on the containing function expression would be first. + * + * For binding patterns, parameter tags are matched by position. + */ + export function astGetJSDocParameterTags(param: AstParameterDeclaration): readonly JSDocParameterTag[]; /** * Gets the JSDoc type parameter tags for the node if present. * @@ -10835,6 +10946,17 @@ declare namespace ts { * tag on the containing function expression would be first. */ export function getJSDocTypeParameterTags(param: TypeParameterDeclaration): readonly JSDocTemplateTag[]; + /** + * Gets the JSDoc type parameter tags for the node if present. + * + * @remarks Returns any JSDoc template tag whose names match the provided + * parameter, whether a template tag on a containing function + * expression, or a template tag on a variable declaration whose + * initializer is the containing function. The tags closest to the + * node are returned first, so in the previous example, the template + * tag on the containing function expression would be first. + */ + export function astGetJSDocTypeParameterTags(param: AstTypeParameterDeclaration): readonly JSDocTemplateTag[]; /** * Return true if the node has JSDoc parameter tags. * @@ -10856,7 +10978,7 @@ declare namespace ts { export function getJSDocProtectedTag(node: Node): JSDocProtectedTag | undefined; /** Gets the JSDoc protected tag for the node if present */ export function getJSDocReadonlyTag(node: Node): JSDocReadonlyTag | undefined; - export function getJSDocOverrideTagNoCache(node: Node): JSDocOverrideTag | undefined; + export function getJSDocOverrideTag(node: Node): JSDocOverrideTag | undefined; /** Gets the JSDoc deprecated tag for the node if present */ export function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc enum tag for the node if present */ @@ -10950,10 +11072,14 @@ declare namespace ts { export function isBindingName(node: Node): node is BindingName; export function isFunctionLike(node: Node | undefined): node is SignatureDeclaration; export function isClassElement(node: Node): node is ClassElement; + export function astIsClassElement(node: AstNode): node is AstClassElement; export function isClassLike(node: Node): node is ClassLikeDeclaration; + export function astIsClassLike(node: AstNode): node is AstClassLikeDeclaration; export function isAccessor(node: Node): node is AccessorDeclaration; export function isAutoAccessorPropertyDeclaration(node: Node): node is AutoAccessorPropertyDeclaration; export function isModifierLike(node: Node): node is ModifierLike; + /** @intenral */ + export function astIsModifierLike(node: AstNode): node is AstModifierLike; export function isTypeElement(node: Node): node is TypeElement; export function isClassOrTypeElement(node: Node): node is ClassElement | TypeElement; export function isObjectLiteralElementLike(node: Node): node is ObjectLiteralElementLike; @@ -11030,6 +11156,26 @@ declare namespace ts { * ``` */ export function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDocTag)[]; + /** + * This function checks multiple locations for JSDoc comments that apply to a host node. + * At each location, the whole comment may apply to the node, or only a specific tag in + * the comment. In the first case, location adds the entire {@link JSDoc} object. In the + * second case, it adds the applicable {@link JSDocTag}. + * + * For example, a JSDoc comment before a parameter adds the entire {@link JSDoc}. But a + * `@param` tag on the parent function only adds the {@link JSDocTag} for the `@param`. + * + * ```ts + * /** JSDoc will be returned for `a` *\/ + * const a = 0 + * /** + * * Entire JSDoc will be returned for `b` + * * @param c JSDocTag will be returned for `c` + * *\/ + * function b(/** JSDoc will be returned for `c` *\/ c) {} + * ``` + */ + export function astGetJSDocCommentsAndTags(hostNode: AstNode): readonly (JSDoc | JSDocTag)[]; /** * Create an external source map source file reference */ @@ -11116,7 +11262,7 @@ declare namespace ts { export function isDotDotDotToken(node: Node): node is DotDotDotToken; export function isPlusToken(node: Node): node is PlusToken; export function isMinusToken(node: Node): node is MinusToken; - export function isAsteriskToken(node: Node): node is AsteriskToken; + export function astIseriskToken(node: Node): node is AsteriskToken; export function isExclamationToken(node: Node): node is ExclamationToken; export function isQuestionToken(node: Node): node is QuestionToken; export function isColonToken(node: Node): node is ColonToken; diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff index 124598753a8b7..be7f858ee0c77 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff @@ -15,7 +15,7 @@ - "flags": "JSDoc", - "modifierFlagsCache": 0, - "transformFlags": 0, -- "comment": { +- "commentArray": { - "0": { - "kind": "JSDocText", - "pos": 32, diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff index 41a1390a61b54..8bd36ef0ca199 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff @@ -15,7 +15,7 @@ - "flags": "JSDoc", - "modifierFlagsCache": 0, - "transformFlags": 0, -- "comment": { +- "commentArray": { - "0": { - "kind": "JSDocText", - "pos": 32, diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff index bcb71c32e1381..8a04321c7a037 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff @@ -15,7 +15,7 @@ - "flags": "JSDoc", - "modifierFlagsCache": 0, - "transformFlags": 0, -- "comment": { +- "commentArray": { - "0": { - "kind": "JSDocText", - "pos": 32, diff --git a/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.ts.diff index 3063fb1931b88..a985b14b0713d 100644 --- a/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.ts.diff @@ -93,7 +93,7 @@ - "transformFlags": 0, - "escapedText": "see" - }, -- "comment": { +- "commentArray": { - "0": { - "kind": "JSDocText", - "pos": 42, @@ -142,7 +142,7 @@ - "transformFlags": 0, - "escapedText": "see" - }, -- "comment": { +- "commentArray": { - "0": { - "kind": "JSDocText", - "pos": 60, @@ -191,7 +191,7 @@ - "transformFlags": 0, - "escapedText": "see" - }, -- "comment": { +- "commentArray": { - "0": { - "kind": "JSDocText", - "pos": 82, diff --git a/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.js.diff b/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.js.diff index a341a7806e2a8..53f7941fd032b 100644 --- a/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.js.diff @@ -93,7 +93,7 @@ - "transformFlags": 0, - "escapedText": "see" - }, -- "comment": { +- "commentArray": { - "0": { - "kind": "JSDocText", - "pos": 42, @@ -142,7 +142,7 @@ - "transformFlags": 0, - "escapedText": "see" - }, -- "comment": { +- "commentArray": { - "0": { - "kind": "JSDocText", - "pos": 60, @@ -191,7 +191,7 @@ - "transformFlags": 0, - "escapedText": "see" - }, -- "comment": { +- "commentArray": { - "0": { - "kind": "JSDocText", - "pos": 82, diff --git a/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.ts.diff index e8d9f5347f962..accc137cc5231 100644 --- a/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.ts.diff @@ -93,7 +93,7 @@ - "transformFlags": 0, - "escapedText": "see" - }, -- "comment": { +- "commentArray": { - "0": { - "kind": "JSDocText", - "pos": 42, @@ -142,7 +142,7 @@ - "transformFlags": 0, - "escapedText": "see" - }, -- "comment": { +- "commentArray": { - "0": { - "kind": "JSDocText", - "pos": 60, @@ -191,7 +191,7 @@ - "transformFlags": 0, - "escapedText": "see" - }, -- "comment": { +- "commentArray": { - "0": { - "kind": "JSDocText", - "pos": 82,