From 1d559fa6f2a078ccb00e42fcce50368b7599a922 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Tue, 11 Jun 2024 12:42:45 +0100 Subject: [PATCH 01/13] monomorphic node experiment. --- src/compiler/factory/nodeFactory.ts | 35 +- src/compiler/utilities.ts | 1382 ++++++++++++++++++++++++++- 2 files changed, 1365 insertions(+), 52 deletions(-) diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 024eaa5c7f687..e059afd814fd9 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -6118,15 +6118,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // 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)) { + copyBaseNodeProperties(source, node); + const sourceData = (source as any).data ?? source; + const nodeData = (node as any).data ?? node; + for (const p in sourceData) { + if (hasProperty(nodeData, p) || !hasProperty(sourceData, p)) { continue; } if (p === "emitNode") { - node.emitNode = undefined; + nodeData.emitNode = undefined; continue; } - (node as any)[p] = (source as any)[p]; + nodeData[p] = sourceData[p]; } return node; } @@ -6376,18 +6379,28 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (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)) { + copyBaseNodeProperties(node, clone); + const nodeData = (node as any).data ?? node; + const cloneData = (clone as any).data ?? clone; + for (const key in nodeData) { + if (hasProperty(cloneData, key) || !hasProperty(nodeData, key)) { continue; } - - clone[key] = node[key]; + cloneData[key] = nodeData[key]; } - return clone; } - + function copyBaseNodeProperties(node: Node, clone: Mutable) { + clone.pos = node.pos; + clone.end = node.end; + clone.kind = node.kind; + clone.id = node.id; + clone.modifierFlagsCache = node.modifierFlagsCache; + clone.transformFlags = node.transformFlags; + clone.parent = node.parent; + clone.original = node.original; + clone.emitNode = node.emitNode; + } // compound nodes function createImmediatelyInvokedFunctionExpression(statements: readonly Statement[]): ImmediatelyInvokedFunctionExpression; function createImmediatelyInvokedFunctionExpression(statements: readonly Statement[], param: ParameterDeclaration, paramValue: Expression): ImmediatelyInvokedFunctionExpression; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f9bd9b9b2511f..471221396bcb1 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -8291,44 +8291,1344 @@ 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; -} +class NodeImpl implements Node { + pos; + end; + kind; + id = 0; + flags = NodeFlags.None; + modifierFlagsCache = ModifierFlags.None; + transformFlags = TransformFlags.None; + parent = undefined!; + original = undefined; + emitNode = undefined; + constructor(kind: SyntaxKind, pos: number, end: number) { + this.pos = pos; + this.end = end; + this.kind = kind; + this.data = {}; + } + data: any; + + get jsDoc() { + return this.data.jsDoc; + } + set jsDoc(value: any) { + this.data.jsDoc = value; + } + + get escapedText() { + return this.data.escapedText; + } + set escapedText(value: any) { + this.data.escapedText = value; + } + + get symbol() { + return this.data.symbol; + } + set symbol(value: any) { + this.data.symbol = value; + } + + get localSymbol() { + return this.data.localSymbol; + } + set localSymbol(value: any) { + this.data.localSymbol = value; + } + + get flowNode() { + return this.data.flowNode; + } + set flowNode(value: any) { + this.data.flowNode = value; + } + + get resolvedSymbol() { + return this.data.resolvedSymbol; + } + set resolvedSymbol(value: any) { + this.data.resolvedSymbol = value; + } + + get modifiers() { + return this.data.modifiers; + } + set modifiers(value: any) { + this.data.modifiers = value; + } + + get name() { + return this.data.name; + } + set name(value: any) { + this.data.name = value; + } + + get constraint() { + return this.data.constraint; + } + set constraint(value: any) { + this.data.constraint = value; + } + + get default() { + return this.data.default; + } + set default(value: any) { + this.data.default = value; + } + + get expression() { + return this.data.expression; + } + set expression(value: any) { + this.data.expression = value; + } + + get typeParameters() { + return this.data.typeParameters; + } + set typeParameters(value: any) { + this.data.typeParameters = value; + } + + get parameters() { + return this.data.parameters; + } + set parameters(value: any) { + this.data.parameters = value; + } + + get type() { + return this.data.type; + } + set type(value: any) { + this.data.type = value; + } + + get typeArguments() { + return this.data.typeArguments; + } + set typeArguments(value: any) { + this.data.typeArguments = value; + } + + get questionToken() { + return this.data.questionToken; + } + set questionToken(value: any) { + this.data.questionToken = value; + } + + get locals() { + return this.data.locals; + } + set locals(value: any) { + this.data.locals = value; + } + + get nextContainer() { + return this.data.nextContainer; + } + set nextContainer(value: any) { + this.data.nextContainer = value; + } + + get asteriskToken() { + return this.data.asteriskToken; + } + set asteriskToken(value: any) { + this.data.asteriskToken = value; + } + + get exclamationToken() { + return this.data.exclamationToken; + } + set exclamationToken(value: any) { + this.data.exclamationToken = value; + } + + get body() { + return this.data.body; + } + set body(value: any) { + this.data.body = value; + } + + get endFlowNode() { + return this.data.endFlowNode; + } + set endFlowNode(value: any) { + this.data.endFlowNode = value; + } + + get returnFlowNode() { + return this.data.returnFlowNode; + } + set returnFlowNode(value: any) { + this.data.returnFlowNode = value; + } + + get equalsGreaterThanToken() { + return this.data.equalsGreaterThanToken; + } + set equalsGreaterThanToken(value: any) { + this.data.equalsGreaterThanToken = value; + } + + get initializer() { + return this.data.initializer; + } + set initializer(value: any) { + this.data.initializer = value; + } + + get dotDotDotToken() { + return this.data.dotDotDotToken; + } + set dotDotDotToken(value: any) { + this.data.dotDotDotToken = value; + } + + get equalsToken() { + return this.data.equalsToken; + } + set equalsToken(value: any) { + this.data.equalsToken = value; + } + + get objectAssignmentInitializer() { + return this.data.objectAssignmentInitializer; + } + set objectAssignmentInitializer(value: any) { + this.data.objectAssignmentInitializer = value; + } + + get left() { + return this.data.left; + } + set left(value: any) { + this.data.left = value; + } + + get operatorToken() { + return this.data.operatorToken; + } + set operatorToken(value: any) { + this.data.operatorToken = value; + } + + get right() { + return this.data.right; + } + set right(value: any) { + this.data.right = value; + } + + get multiLine() { + return this.data.multiLine; + } + set multiLine(value: any) { + this.data.multiLine = value; + } + + get properties() { + return this.data.properties; + } + set properties(value: any) { + this.data.properties = value; + } + + get questionDotToken() { + return this.data.questionDotToken; + } + set questionDotToken(value: any) { + this.data.questionDotToken = value; + } + + get argumentExpression() { + return this.data.argumentExpression; + } + set argumentExpression(value: any) { + this.data.argumentExpression = value; + } + + get heritageClauses() { + return this.data.heritageClauses; + } + set heritageClauses(value: any) { + this.data.heritageClauses = value; + } + + get members() { + return this.data.members; + } + set members(value: any) { + this.data.members = value; + } + + get isTypeOnly() { + return this.data.isTypeOnly; + } + set isTypeOnly(value: any) { + this.data.isTypeOnly = value; + } + + get moduleReference() { + return this.data.moduleReference; + } + set moduleReference(value: any) { + this.data.moduleReference = value; + } + + get exportClause() { + return this.data.exportClause; + } + set exportClause(value: any) { + this.data.exportClause = value; + } + + get moduleSpecifier() { + return this.data.moduleSpecifier; + } + set moduleSpecifier(value: any) { + this.data.moduleSpecifier = value; + } + + get assertClause() { + return this.data.assertClause; + } + set assertClause(value: any) { + this.data.assertClause = value; + } + + get attributes() { + return this.data.attributes; + } + set attributes(value: any) { + this.data.attributes = value; + } + + get isExportEquals() { + return this.data.isExportEquals; + } + set isExportEquals(value: any) { + this.data.isExportEquals = value; + } + + get statements() { + return this.data.statements; + } + set statements(value: any) { + this.data.statements = value; + } + + get declarationList() { + return this.data.declarationList; + } + set declarationList(value: any) { + this.data.declarationList = value; + } + + get thenStatement() { + return this.data.thenStatement; + } + set thenStatement(value: any) { + this.data.thenStatement = value; + } + + get elseStatement() { + return this.data.elseStatement; + } + set elseStatement(value: any) { + this.data.elseStatement = value; + } + + get statement() { + return this.data.statement; + } + set statement(value: any) { + this.data.statement = value; + } + + get condition() { + return this.data.condition; + } + set condition(value: any) { + this.data.condition = value; + } + + get incrementor() { + return this.data.incrementor; + } + set incrementor(value: any) { + this.data.incrementor = value; + } + + get awaitModifier() { + return this.data.awaitModifier; + } + set awaitModifier(value: any) { + this.data.awaitModifier = value; + } + + get label() { + return this.data.label; + } + set label(value: any) { + this.data.label = value; + } + + get caseBlock() { + return this.data.caseBlock; + } + set caseBlock(value: any) { + this.data.caseBlock = value; + } + + get possiblyExhaustive() { + return this.data.possiblyExhaustive; + } + set possiblyExhaustive(value: any) { + this.data.possiblyExhaustive = value; + } + + get tryBlock() { + return this.data.tryBlock; + } + set tryBlock(value: any) { + this.data.tryBlock = value; + } + + get catchClause() { + return this.data.catchClause; + } + set catchClause(value: any) { + this.data.catchClause = value; + } + + get finallyBlock() { + return this.data.finallyBlock; + } + set finallyBlock(value: any) { + this.data.finallyBlock = value; + } + + get importClause() { + return this.data.importClause; + } + set importClause(value: any) { + this.data.importClause = value; + } + + get fallthroughFlowNode() { + return this.data.fallthroughFlowNode; + } + set fallthroughFlowNode(value: any) { + this.data.fallthroughFlowNode = value; + } + + get propertyName() { + return this.data.propertyName; + } + set propertyName(value: any) { + this.data.propertyName = value; + } + + get checkType() { + return this.data.checkType; + } + set checkType(value: any) { + this.data.checkType = value; + } + + get extendsType() { + return this.data.extendsType; + } + set extendsType(value: any) { + this.data.extendsType = value; + } + + get trueType() { + return this.data.trueType; + } + set trueType(value: any) { + this.data.trueType = value; + } + + get falseType() { + return this.data.falseType; + } + set falseType(value: any) { + this.data.falseType = value; + } + + get readonlyToken() { + return this.data.readonlyToken; + } + set readonlyToken(value: any) { + this.data.readonlyToken = value; + } + + get typeParameter() { + return this.data.typeParameter; + } + set typeParameter(value: any) { + this.data.typeParameter = value; + } + + get nameType() { + return this.data.nameType; + } + set nameType(value: any) { + this.data.nameType = value; + } + + get clauses() { + return this.data.clauses; + } + set clauses(value: any) { + this.data.clauses = value; + } + + get variableDeclaration() { + return this.data.variableDeclaration; + } + set variableDeclaration(value: any) { + this.data.variableDeclaration = value; + } + + get block() { + return this.data.block; + } + set block(value: any) { + this.data.block = value; + } + + get typeExpression() { + return this.data.typeExpression; + } + set typeExpression(value: any) { + this.data.typeExpression = value; + } + + get tagName() { + return this.data.tagName; + } + set tagName(value: any) { + this.data.tagName = value; + } + + get comment() { + return this.data.comment; + } + set comment(value: any) { + this.data.comment = value; + } + + get fullName() { + return this.data.fullName; + } + set fullName(value: any) { + this.data.fullName = value; + } + + get endOfFileToken() { + return this.data.endOfFileToken; + } + set endOfFileToken(value: any) { + this.data.endOfFileToken = value; + } + + get fileName() { + return this.data.fileName; + } + set fileName(value: any) { + this.data.fileName = value; + } + + get path() { + return this.data.path; + } + set path(value: any) { + this.data.path = value; + } + + get text() { + return this.data.text; + } + set text(value: any) { + this.data.text = value; + } + + get resolvedPath() { + return this.data.resolvedPath; + } + set resolvedPath(value: any) { + this.data.resolvedPath = value; + } + + get originalFileName() { + return this.data.originalFileName; + } + set originalFileName(value: any) { + this.data.originalFileName = value; + } + + get redirectInfo() { + return this.data.redirectInfo; + } + set redirectInfo(value: any) { + this.data.redirectInfo = value; + } + + get amdDependencies() { + return this.data.amdDependencies; + } + set amdDependencies(value: any) { + this.data.amdDependencies = value; + } + + get moduleName() { + return this.data.moduleName; + } + set moduleName(value: any) { + this.data.moduleName = value; + } + + get referencedFiles() { + return this.data.referencedFiles; + } + set referencedFiles(value: any) { + this.data.referencedFiles = value; + } + + get typeReferenceDirectives() { + return this.data.typeReferenceDirectives; + } + set typeReferenceDirectives(value: any) { + this.data.typeReferenceDirectives = value; + } + + get libReferenceDirectives() { + return this.data.libReferenceDirectives; + } + set libReferenceDirectives(value: any) { + this.data.libReferenceDirectives = value; + } + + get languageVariant() { + return this.data.languageVariant; + } + set languageVariant(value: any) { + this.data.languageVariant = value; + } + + get isDeclarationFile() { + return this.data.isDeclarationFile; + } + set isDeclarationFile(value: any) { + this.data.isDeclarationFile = value; + } + + get renamedDependencies() { + return this.data.renamedDependencies; + } + set renamedDependencies(value: any) { + this.data.renamedDependencies = value; + } + + get hasNoDefaultLib() { + return this.data.hasNoDefaultLib; + } + set hasNoDefaultLib(value: any) { + this.data.hasNoDefaultLib = value; + } + + get languageVersion() { + return this.data.languageVersion; + } + set languageVersion(value: any) { + this.data.languageVersion = value; + } + + get impliedNodeFormat() { + return this.data.impliedNodeFormat; + } + set impliedNodeFormat(value: any) { + this.data.impliedNodeFormat = value; + } + + get packageJsonLocations() { + return this.data.packageJsonLocations; + } + set packageJsonLocations(value: any) { + this.data.packageJsonLocations = value; + } + + get packageJsonScope() { + return this.data.packageJsonScope; + } + set packageJsonScope(value: any) { + this.data.packageJsonScope = value; + } + + get scriptKind() { + return this.data.scriptKind; + } + set scriptKind(value: any) { + this.data.scriptKind = value; + } + + get externalModuleIndicator() { + return this.data.externalModuleIndicator; + } + set externalModuleIndicator(value: any) { + this.data.externalModuleIndicator = value; + } + + get setExternalModuleIndicator() { + return this.data.setExternalModuleIndicator; + } + set setExternalModuleIndicator(value: any) { + this.data.setExternalModuleIndicator = value; + } + + get commonJsModuleIndicator() { + return this.data.commonJsModuleIndicator; + } + set commonJsModuleIndicator(value: any) { + this.data.commonJsModuleIndicator = value; + } -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; + get jsGlobalAugmentations() { + return this.data.jsGlobalAugmentations; + } + set jsGlobalAugmentations(value: any) { + this.data.jsGlobalAugmentations = value; + } + + get identifiers() { + return this.data.identifiers; + } + set identifiers(value: any) { + this.data.identifiers = value; + } + + get nodeCount() { + return this.data.nodeCount; + } + set nodeCount(value: any) { + this.data.nodeCount = value; + } + + get identifierCount() { + return this.data.identifierCount; + } + set identifierCount(value: any) { + this.data.identifierCount = value; + } + + get symbolCount() { + return this.data.symbolCount; + } + set symbolCount(value: any) { + this.data.symbolCount = value; + } + + get parseDiagnostics() { + return this.data.parseDiagnostics; + } + set parseDiagnostics(value: any) { + this.data.parseDiagnostics = value; + } + + get bindDiagnostics() { + return this.data.bindDiagnostics; + } + set bindDiagnostics(value: any) { + this.data.bindDiagnostics = value; + } + + get bindSuggestionDiagnostics() { + return this.data.bindSuggestionDiagnostics; + } + set bindSuggestionDiagnostics(value: any) { + this.data.bindSuggestionDiagnostics = value; + } + + get jsDocDiagnostics() { + return this.data.jsDocDiagnostics; + } + set jsDocDiagnostics(value: any) { + this.data.jsDocDiagnostics = value; + } + + get additionalSyntacticDiagnostics() { + return this.data.additionalSyntacticDiagnostics; + } + set additionalSyntacticDiagnostics(value: any) { + this.data.additionalSyntacticDiagnostics = value; + } + + get lineMap() { + return this.data.lineMap; + } + set lineMap(value: any) { + this.data.lineMap = value; + } + + get classifiableNames() { + return this.data.classifiableNames; + } + set classifiableNames(value: any) { + this.data.classifiableNames = value; + } + + get commentDirectives() { + return this.data.commentDirectives; + } + set commentDirectives(value: any) { + this.data.commentDirectives = value; + } + + get imports() { + return this.data.imports; + } + set imports(value: any) { + this.data.imports = value; + } + + get moduleAugmentations() { + return this.data.moduleAugmentations; + } + set moduleAugmentations(value: any) { + this.data.moduleAugmentations = value; + } + + get patternAmbientModules() { + return this.data.patternAmbientModules; + } + set patternAmbientModules(value: any) { + this.data.patternAmbientModules = value; + } + + get ambientModuleNames() { + return this.data.ambientModuleNames; + } + set ambientModuleNames(value: any) { + this.data.ambientModuleNames = value; + } + + get checkJsDirective() { + return this.data.checkJsDirective; + } + set checkJsDirective(value: any) { + this.data.checkJsDirective = value; + } + + get version() { + return this.data.version; + } + set version(value: any) { + this.data.version = value; + } + + get pragmas() { + return this.data.pragmas; + } + set pragmas(value: any) { + this.data.pragmas = value; + } + + get localJsxNamespace() { + return this.data.localJsxNamespace; + } + set localJsxNamespace(value: any) { + this.data.localJsxNamespace = value; + } + + get localJsxFragmentNamespace() { + return this.data.localJsxFragmentNamespace; + } + set localJsxFragmentNamespace(value: any) { + this.data.localJsxFragmentNamespace = value; + } + + get localJsxFactory() { + return this.data.localJsxFactory; + } + set localJsxFactory(value: any) { + this.data.localJsxFactory = value; + } + + get localJsxFragmentFactory() { + return this.data.localJsxFragmentFactory; + } + set localJsxFragmentFactory(value: any) { + this.data.localJsxFragmentFactory = value; + } + + get jsDocParsingMode() { + return this.data.jsDocParsingMode; + } + set jsDocParsingMode(value: any) { + this.data.jsDocParsingMode = value; + } + + get extendedSourceFiles() { + return this.data.extendedSourceFiles; + } + set extendedSourceFiles(value: any) { + this.data.extendedSourceFiles = value; + } + + get configFileSpecs() { + return this.data.configFileSpecs; + } + set configFileSpecs(value: any) { + this.data.configFileSpecs = value; + } + + get keywordToken() { + return this.data.keywordToken; + } + set keywordToken(value: any) { + this.data.keywordToken = value; + } + + get namedBindings() { + return this.data.namedBindings; + } + set namedBindings(value: any) { + this.data.namedBindings = value; + } + + get textSourceNode() { + return this.data.textSourceNode; + } + set textSourceNode(value: any) { + this.data.textSourceNode = value; + } + + get singleQuote() { + return this.data.singleQuote; + } + set singleQuote(value: any) { + this.data.singleQuote = value; + } + + get isUnterminated() { + return this.data.isUnterminated; + } + set isUnterminated(value: any) { + this.data.isUnterminated = value; + } + + get hasExtendedUnicodeEscape() { + return this.data.hasExtendedUnicodeEscape; + } + set hasExtendedUnicodeEscape(value: any) { + this.data.hasExtendedUnicodeEscape = value; + } + + get templateFlags() { + return this.data.templateFlags; + } + set templateFlags(value: any) { + this.data.templateFlags = value; + } + + get rawText() { + return this.data.rawText; + } + set rawText(value: any) { + this.data.rawText = value; + } + + get numericLiteralFlags() { + return this.data.numericLiteralFlags; + } + set numericLiteralFlags(value: any) { + this.data.numericLiteralFlags = value; + } + + get arguments() { + return this.data.arguments; + } + set arguments(value: any) { + this.data.arguments = value; + } + + get isNameFirst() { + return this.data.isNameFirst; + } + set isNameFirst(value: any) { + this.data.isNameFirst = value; + } + + get isBracketed() { + return this.data.isBracketed; + } + set isBracketed(value: any) { + this.data.isBracketed = value; + } + + get jsDocPropertyTags() { + return this.data.jsDocPropertyTags; + } + set jsDocPropertyTags(value: any) { + this.data.jsDocPropertyTags = value; + } + + get isArrayType() { + return this.data.isArrayType; + } + set isArrayType(value: any) { + this.data.isArrayType = value; + } + + get declarations() { + return this.data.declarations; + } + set declarations(value: any) { + this.data.declarations = value; + } + + get elements() { + return this.data.elements; + } + set elements(value: any) { + this.data.elements = value; + } + + get isTypeOf() { + return this.data.isTypeOf; + } + set isTypeOf(value: any) { + this.data.isTypeOf = value; + } + + get argument() { + return this.data.argument; + } + set argument(value: any) { + this.data.argument = value; + } + + get assertions() { + return this.data.assertions; + } + set assertions(value: any) { + this.data.assertions = value; + } + + get qualifier() { + return this.data.qualifier; + } + set qualifier(value: any) { + this.data.qualifier = value; + } + + get typeName() { + return this.data.typeName; + } + set typeName(value: any) { + this.data.typeName = value; + } + + get exprName() { + return this.data.exprName; + } + set exprName(value: any) { + this.data.exprName = value; + } + + get assertsModifier() { + return this.data.assertsModifier; + } + set assertsModifier(value: any) { + this.data.assertsModifier = value; + } + + get parameterName() { + return this.data.parameterName; + } + set parameterName(value: any) { + this.data.parameterName = value; + } + + get elementType() { + return this.data.elementType; + } + set elementType(value: any) { + this.data.elementType = value; + } + + get types() { + return this.data.types; + } + set types(value: any) { + this.data.types = value; + } + + get operator() { + return this.data.operator; + } + set operator(value: any) { + this.data.operator = value; + } + + get objectType() { + return this.data.objectType; + } + set objectType(value: any) { + this.data.objectType = value; + } + + get indexType() { + return this.data.indexType; + } + set indexType(value: any) { + this.data.indexType = value; + } + + get literal() { + return this.data.literal; + } + set literal(value: any) { + this.data.literal = value; + } + + get head() { + return this.data.head; + } + set head(value: any) { + this.data.head = value; + } + + get templateSpans() { + return this.data.templateSpans; + } + set templateSpans(value: any) { + this.data.templateSpans = value; + } + + get postfix() { + return this.data.postfix; + } + set postfix(value: any) { + this.data.postfix = value; + } + + get operand() { + return this.data.operand; + } + set operand(value: any) { + this.data.operand = value; + } + + get openingElement() { + return this.data.openingElement; + } + set openingElement(value: any) { + this.data.openingElement = value; + } + + get children() { + return this.data.children; + } + set children(value: any) { + this.data.children = value; + } + + get closingElement() { + return this.data.closingElement; + } + set closingElement(value: any) { + this.data.closingElement = value; + } + + get openingFragment() { + return this.data.openingFragment; + } + set openingFragment(value: any) { + this.data.openingFragment = value; + } + + get closingFragment() { + return this.data.closingFragment; + } + set closingFragment(value: any) { + this.data.closingFragment = value; + } + + get tag() { + return this.data.tag; + } + set tag(value: any) { + this.data.tag = value; + } + + get template() { + return this.data.template; + } + set template(value: any) { + this.data.template = value; + } + + get thisArg() { + return this.data.thisArg; + } + set thisArg(value: any) { + this.data.thisArg = value; + } + + get isSpread() { + return this.data.isSpread; + } + set isSpread(value: any) { + this.data.isSpread = value; + } + + get tupleNameSource() { + return this.data.tupleNameSource; + } + set tupleNameSource(value: any) { + this.data.tupleNameSource = value; + } + + get whenTrue() { + return this.data.whenTrue; + } + set whenTrue(value: any) { + this.data.whenTrue = value; + } + + get colonToken() { + return this.data.colonToken; + } + set colonToken(value: any) { + this.data.colonToken = value; + } + + get whenFalse() { + return this.data.whenFalse; + } + set whenFalse(value: any) { + this.data.whenFalse = value; + } + + get containsOnlyTriviaWhiteSpaces() { + return this.data.containsOnlyTriviaWhiteSpaces; + } + set containsOnlyTriviaWhiteSpaces(value: any) { + this.data.containsOnlyTriviaWhiteSpaces = value; + } + + get namespace() { + return this.data.namespace; + } + set namespace(value: any) { + this.data.namespace = value; + } + + get token() { + return this.data.token; + } + set token(value: any) { + this.data.token = value; + } + + get value() { + return this.data.value; + } + set value(value: any) { + this.data.value = value; + } + + get tags() { + return this.data.tags; + } + set tags(value: any) { + this.data.tags = value; + } + + get class() { + return this.data.class; + } + set class(value: any) { + this.data.class = value; + } + + get sourceFiles() { + return this.data.sourceFiles; + } + set sourceFiles(value: any) { + this.data.sourceFiles = value; + } + + get syntheticFileReferences() { + return this.data.syntheticFileReferences; + } + set syntheticFileReferences(value: any) { + this.data.syntheticFileReferences = value; + } + + get syntheticTypeReferences() { + return this.data.syntheticTypeReferences; + } + set syntheticTypeReferences(value: any) { + this.data.syntheticTypeReferences = value; + } + + get syntheticLibReferences() { + return this.data.syntheticLibReferences; + } + set syntheticLibReferences(value: any) { + this.data.syntheticLibReferences = value; + } } +// 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 @@ -8339,11 +9639,11 @@ 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, + getNodeConstructor: () => NodeImpl as any, + getTokenConstructor: () => NodeImpl as any, + getIdentifierConstructor: () => NodeImpl as any, + getPrivateIdentifierConstructor: () => NodeImpl as any, + getSourceFileConstructor: () => NodeImpl as any, getSymbolConstructor: () => Symbol as any, getTypeConstructor: () => Type as any, getSignatureConstructor: () => Signature as any, From 14e032b94b6e4692b487127df468484fc7197f30 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Wed, 19 Jun 2024 16:10:46 +0100 Subject: [PATCH 02/13] Make types and signatures monomorphic too. --- src/compiler/checker.ts | 7 +- src/compiler/commandLineParser.ts | 1 + src/compiler/factory/nodeFactory.ts | 32 +- src/compiler/utilities.ts | 896 +++++++++++++++++++++++++++- src/harness/harnessUtils.ts | 60 +- src/services/services.ts | 808 ++++++++++--------------- 6 files changed, 1237 insertions(+), 567 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ad3ecc3d2ec91..d442ee660b443 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1416,9 +1416,10 @@ const SymbolLinks = class implements SymbolLinks { declare _symbolLinksBrand: any; }; -function NodeLinks(this: NodeLinks) { - this.flags = NodeCheckFlags.None; -} +const NodeLinks = class { + flags = NodeCheckFlags.None; + calculatedFlags = NodeCheckFlags.None; +}; /** @internal */ export function getNodeId(node: Node): number { diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 5c0a33c6e46bb..fd5e061e1f0d3 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -97,6 +97,7 @@ import { ParsedCommandLine, parseJsonText, Path, + PluginImport, PollingWatchKind, PrefixUnaryExpression, ProjectReference, diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index e059afd814fd9..100e400d7bb3e 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -327,6 +327,7 @@ import { NodeArray, NodeFactory, NodeFlags, + NodeImpl, nodeIsSynthesized, NonNullChain, NonNullExpression, @@ -6077,8 +6078,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } function createRedirectedSourceFile(redirectInfo: RedirectInfo) { - const node: SourceFile = Object.create(redirectInfo.redirectTarget); - Object.defineProperties(node, { + const nodeData: any = Object.create((redirectInfo.redirectTarget as any as NodeImpl).data); + Object.defineProperties(nodeData, { id: { get(this: SourceFile) { return this.redirectInfo!.redirectTarget.id; @@ -6095,9 +6096,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode this.redirectInfo!.redirectTarget.symbol = value; }, }, + redirectInfo: { + value: redirectInfo, + }, }); - node.redirectInfo = redirectInfo; - return node; + const sourceFile = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile); + (sourceFile as NodeImpl).data = nodeData; + return sourceFile as SourceFile; } function cloneRedirectedSourceFile(source: SourceFile) { @@ -6118,7 +6123,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // 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; - copyBaseNodeProperties(source, node); const sourceData = (source as any).data ?? source; const nodeData = (node as any).data ?? node; for (const p in sourceData) { @@ -6126,10 +6130,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode continue; } if (p === "emitNode") { - nodeData.emitNode = undefined; + node.emitNode = undefined; continue; } - nodeData[p] = sourceData[p]; + (node as any)[p] = sourceData[p]; } return node; } @@ -6379,28 +6383,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (clone as Mutable).flags |= node.flags & ~NodeFlags.Synthesized; (clone as Mutable).transformFlags = node.transformFlags; setOriginal(clone, node); - copyBaseNodeProperties(node, clone); const nodeData = (node as any).data ?? node; const cloneData = (clone as any).data ?? clone; for (const key in nodeData) { if (hasProperty(cloneData, key) || !hasProperty(nodeData, key)) { continue; } - cloneData[key] = nodeData[key]; + (clone as any)[key] = nodeData[key]; } return clone; } - function copyBaseNodeProperties(node: Node, clone: Mutable) { - clone.pos = node.pos; - clone.end = node.end; - clone.kind = node.kind; - clone.id = node.id; - clone.modifierFlagsCache = node.modifierFlagsCache; - clone.transformFlags = node.transformFlags; - clone.parent = node.parent; - clone.original = node.original; - clone.emitNode = node.emitNode; - } // compound nodes function createImmediatelyInvokedFunctionExpression(statements: readonly Statement[]): ImmediatelyInvokedFunctionExpression; function createImmediatelyInvokedFunctionExpression(statements: readonly Statement[], param: ParameterDeclaration, paramValue: Expression): ImmediatelyInvokedFunctionExpression; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 471221396bcb1..67cb1b5867837 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -545,7 +545,6 @@ import { TokenFlags, tokenToString, toPath, - tracing, TransformFlags, TransientSymbol, TriviaSyntaxKind, @@ -562,6 +561,7 @@ import { TypeElement, TypeFlags, TypeLiteralNode, + TypeMapper, TypeNode, TypeNodeSyntaxKind, TypeParameter, @@ -8275,41 +8275,882 @@ function Symbol(this: Symbol, flags: SymbolFlags, name: __String) { (this as any).links = undefined; // used by TransientSymbol } -function Type(this: Type, checker: TypeChecker, flags: TypeFlags) { - // Note: if modifying this, be sure to update TypeObject in src/services/services.ts - this.flags = flags; - if (Debug.isDebugging || tracing) { +class TypeDataImpl { +} +/** @internal */ +export class TypeImpl { + checker: TypeChecker; + flags: TypeFlags; + symbol: Symbol; + _data: any; + id: number; + objectFlags: number; + constructor(checker: TypeChecker, flags: TypeFlags) { + this.id = 0; this.checker = checker; + this.flags = flags; + this.symbol = undefined!; + this._data = undefined; + this.objectFlags = 0; } -} -function Signature(this: Signature, checker: TypeChecker, flags: SignatureFlags) { - // Note: if modifying this, be sure to update SignatureObject in src/services/services.ts - this.flags = flags; - if (Debug.isDebugging) { - this.checker = checker; + get data() { + return this._data ??= new TypeDataImpl(); + } + get pattern() { + return this._data?.pattern; + } + set pattern(value: any) { + this.data.pattern = value; + } + + get aliasSymbol() { + return this._data?.aliasSymbol; + } + set aliasSymbol(value: any) { + this.data.aliasSymbol = value; + } + + get aliasTypeArguments() { + return this._data?.aliasTypeArguments; + } + set aliasTypeArguments(value: any) { + this.data.aliasTypeArguments = value; + } + + get permissiveInstantiation() { + return this._data?.permissiveInstantiation; + } + set permissiveInstantiation(value: any) { + this.data.permissiveInstantiation = value; + } + + get restrictiveInstantiation() { + return this._data?.restrictiveInstantiation; + } + set restrictiveInstantiation(value: any) { + this.data.restrictiveInstantiation = value; + } + + get immediateBaseConstraint() { + return this._data?.immediateBaseConstraint; + } + set immediateBaseConstraint(value: any) { + this.data.immediateBaseConstraint = value; + } + + get widened() { + return this._data?.widened; + } + set widened(value: any) { + this.data.widened = value; + } + + get intrinsicName() { + return this._data?.intrinsicName; + } + set intrinsicName(value: any) { + this.data.intrinsicName = value; + } + + get debugIntrinsicName() { + return this._data?.debugIntrinsicName; + } + set debugIntrinsicName(value: any) { + this.data.debugIntrinsicName = value; + } + + // get objectFlags() { return this._data?.objectFlags; } + // set objectFlags(value: any) { this.data.objectFlags = value } + + get freshType() { + return this._data?.freshType; + } + set freshType(value: any) { + this.data.freshType = value; + } + + get regularType() { + return this._data?.regularType; + } + set regularType(value: any) { + this.data.regularType = value; + } + + get value() { + return this._data?.value; + } + set value(value: any) { + this.data.value = value; + } + + get escapedName() { + return this._data?.escapedName; + } + set escapedName(value: any) { + this.data.escapedName = value; + } + + get members() { + return this._data?.members; + } + set members(value: any) { + this.data.members = value; + } + + get properties() { + return this._data?.properties; + } + set properties(value: any) { + this.data.properties = value; + } + + get callSignatures() { + return this._data?.callSignatures; + } + set callSignatures(value: any) { + this.data.callSignatures = value; + } + + get constructSignatures() { + return this._data?.constructSignatures; + } + set constructSignatures(value: any) { + this.data.constructSignatures = value; + } + + get indexInfos() { + return this._data?.indexInfos; + } + set indexInfos(value: any) { + this.data.indexInfos = value; + } + + get objectTypeWithoutAbstractConstructSignatures() { + return this._data?.objectTypeWithoutAbstractConstructSignatures; + } + set objectTypeWithoutAbstractConstructSignatures(value: any) { + this.data.objectTypeWithoutAbstractConstructSignatures = value; + } + + get typeParameters() { + return this._data?.typeParameters; + } + set typeParameters(value: any) { + this.data.typeParameters = value; + } + + get outerTypeParameters() { + return this._data?.outerTypeParameters; + } + set outerTypeParameters(value: any) { + this.data.outerTypeParameters = value; + } + + get localTypeParameters() { + return this._data?.localTypeParameters; + } + set localTypeParameters(value: any) { + this.data.localTypeParameters = value; + } + + get thisType() { + return this._data?.thisType; + } + set thisType(value: any) { + this.data.thisType = value; + } + + get resolvedBaseConstructorType() { + return this._data?.resolvedBaseConstructorType; + } + set resolvedBaseConstructorType(value: any) { + this.data.resolvedBaseConstructorType = value; + } + + get resolvedBaseTypes() { + return this._data?.resolvedBaseTypes; + } + set resolvedBaseTypes(value: any) { + this.data.resolvedBaseTypes = value; + } + + get baseTypesResolved() { + return this._data?.baseTypesResolved; + } + set baseTypesResolved(value: any) { + this.data.baseTypesResolved = value; + } + + get declaredProperties() { + return this._data?.declaredProperties; + } + set declaredProperties(value: any) { + this.data.declaredProperties = value; + } + + get declaredCallSignatures() { + return this._data?.declaredCallSignatures; + } + set declaredCallSignatures(value: any) { + this.data.declaredCallSignatures = value; + } + + get declaredConstructSignatures() { + return this._data?.declaredConstructSignatures; + } + set declaredConstructSignatures(value: any) { + this.data.declaredConstructSignatures = value; + } + + get declaredIndexInfos() { + return this._data?.declaredIndexInfos; + } + set declaredIndexInfos(value: any) { + this.data.declaredIndexInfos = value; + } + + get instantiations() { + return this._data?.instantiations; + } + set instantiations(value: any) { + this.data.instantiations = value; + } + + get variances() { + return this._data?.variances; + } + set variances(value: any) { + this.data.variances = value; + } + + get target() { + return this._data?.target; + } + set target(value: any) { + this.data.target = value; + } + + get node() { + return this._data?.node; + } + set node(value: any) { + this.data.node = value; + } + + get mapper() { + return this._data?.mapper; + } + set mapper(value: any) { + this.data.mapper = value; + } + + get resolvedTypeArguments() { + return this._data?.resolvedTypeArguments; + } + set resolvedTypeArguments(value: any) { + this.data.resolvedTypeArguments = value; + } + + get literalType() { + return this._data?.literalType; + } + set literalType(value: any) { + this.data.literalType = value; + } + + get cachedEquivalentBaseType() { + return this._data?.cachedEquivalentBaseType; + } + set cachedEquivalentBaseType(value: any) { + this.data.cachedEquivalentBaseType = value; + } + + get elementFlags() { + return this._data?.elementFlags; + } + set elementFlags(value: any) { + this.data.elementFlags = value; + } + + get minLength() { + return this._data?.minLength; + } + set minLength(value: any) { + this.data.minLength = value; + } + + get fixedLength() { + return this._data?.fixedLength; + } + set fixedLength(value: any) { + this.data.fixedLength = value; + } + + get hasRestElement() { + return this._data?.hasRestElement; + } + set hasRestElement(value: any) { + this.data.hasRestElement = value; + } + + get combinedFlags() { + return this._data?.combinedFlags; + } + set combinedFlags(value: any) { + this.data.combinedFlags = value; + } + + get readonly() { + return this._data?.readonly; + } + set readonly(value: any) { + this.data.readonly = value; + } + + get labeledElementDeclarations() { + return this._data?.labeledElementDeclarations; + } + set labeledElementDeclarations(value: any) { + this.data.labeledElementDeclarations = value; + } + + get declaration() { + return this._data?.declaration; + } + set declaration(value: any) { + this.data.declaration = value; + } + + get typeParameter() { + return this._data?.typeParameter; + } + set typeParameter(value: any) { + this.data.typeParameter = value; + } + + get constraintType() { + return this._data?.constraintType; + } + set constraintType(value: any) { + this.data.constraintType = value; + } + + get nameType() { + return this._data?.nameType; + } + set nameType(value: any) { + this.data.nameType = value; + } + + get templateType() { + return this._data?.templateType; + } + set templateType(value: any) { + this.data.templateType = value; + } + + get modifiersType() { + return this._data?.modifiersType; + } + set modifiersType(value: any) { + this.data.modifiersType = value; + } + + get resolvedApparentType() { + return this._data?.resolvedApparentType; + } + set resolvedApparentType(value: any) { + this.data.resolvedApparentType = value; + } + + get containsError() { + return this._data?.containsError; + } + set containsError(value: any) { + this.data.containsError = value; + } + + get elementType() { + return this._data?.elementType; + } + set elementType(value: any) { + this.data.elementType = value; + } + + get finalArrayType() { + return this._data?.finalArrayType; + } + set finalArrayType(value: any) { + this.data.finalArrayType = value; + } + + get source() { + return this._data?.source; + } + set source(value: any) { + this.data.source = value; + } + + get mappedType() { + return this._data?.mappedType; } + set mappedType(value: any) { + this.data.mappedType = value; + } + + get types() { + return this._data?.types; + } + set types(value: any) { + this.data.types = value; + } + + get propertyCache() { + return this._data?.propertyCache; + } + set propertyCache(value: any) { + this.data.propertyCache = value; + } + + get propertyCacheWithoutObjectFunctionPropertyAugment() { + return this._data?.propertyCacheWithoutObjectFunctionPropertyAugment; + } + set propertyCacheWithoutObjectFunctionPropertyAugment(value: any) { + this.data.propertyCacheWithoutObjectFunctionPropertyAugment = value; + } + + get resolvedProperties() { + return this._data?.resolvedProperties; + } + set resolvedProperties(value: any) { + this.data.resolvedProperties = value; + } + + get resolvedIndexType() { + return this._data?.resolvedIndexType; + } + set resolvedIndexType(value: any) { + this.data.resolvedIndexType = value; + } + + get resolvedStringIndexType() { + return this._data?.resolvedStringIndexType; + } + set resolvedStringIndexType(value: any) { + this.data.resolvedStringIndexType = value; + } + + get resolvedBaseConstraint() { + return this._data?.resolvedBaseConstraint; + } + set resolvedBaseConstraint(value: any) { + this.data.resolvedBaseConstraint = value; + } + + get iterationTypesOfGeneratorReturnType() { + return this._data?.iterationTypesOfGeneratorReturnType; + } + set iterationTypesOfGeneratorReturnType(value: any) { + this.data.iterationTypesOfGeneratorReturnType = value; + } + + get iterationTypesOfAsyncGeneratorReturnType() { + return this._data?.iterationTypesOfAsyncGeneratorReturnType; + } + set iterationTypesOfAsyncGeneratorReturnType(value: any) { + this.data.iterationTypesOfAsyncGeneratorReturnType = value; + } + + get iterationTypesOfIterable() { + return this._data?.iterationTypesOfIterable; + } + set iterationTypesOfIterable(value: any) { + this.data.iterationTypesOfIterable = value; + } + + get iterationTypesOfIterator() { + return this._data?.iterationTypesOfIterator; + } + set iterationTypesOfIterator(value: any) { + this.data.iterationTypesOfIterator = value; + } + + get iterationTypesOfAsyncIterable() { + return this._data?.iterationTypesOfAsyncIterable; + } + set iterationTypesOfAsyncIterable(value: any) { + this.data.iterationTypesOfAsyncIterable = value; + } + + get iterationTypesOfAsyncIterator() { + return this._data?.iterationTypesOfAsyncIterator; + } + set iterationTypesOfAsyncIterator(value: any) { + this.data.iterationTypesOfAsyncIterator = value; + } + + get iterationTypesOfIteratorResult() { + return this._data?.iterationTypesOfIteratorResult; + } + set iterationTypesOfIteratorResult(value: any) { + this.data.iterationTypesOfIteratorResult = value; + } + + get resolvedReducedType() { + return this._data?.resolvedReducedType; + } + set resolvedReducedType(value: any) { + this.data.resolvedReducedType = value; + } + + get origin() { + return this._data?.origin; + } + set origin(value: any) { + this.data.origin = value; + } + + get keyPropertyName() { + return this._data?.keyPropertyName; + } + set keyPropertyName(value: any) { + this.data.keyPropertyName = value; + } + + get constituentMap() { + return this._data?.constituentMap; + } + set constituentMap(value: any) { + this.data.constituentMap = value; + } + + get arrayFallbackSignatures() { + return this._data?.arrayFallbackSignatures; + } + set arrayFallbackSignatures(value: any) { + this.data.arrayFallbackSignatures = value; + } + + get promiseTypeOfPromiseConstructor() { + return this._data?.promiseTypeOfPromiseConstructor; + } + set promiseTypeOfPromiseConstructor(value: any) { + this.data.promiseTypeOfPromiseConstructor = value; + } + + get promisedTypeOfPromise() { + return this._data?.promisedTypeOfPromise; + } + set promisedTypeOfPromise(value: any) { + this.data.promisedTypeOfPromise = value; + } + + get awaitedTypeOfType() { + return this._data?.awaitedTypeOfType; + } + set awaitedTypeOfType(value: any) { + this.data.awaitedTypeOfType = value; + } + + get uniqueLiteralFilledInstantiation() { + return this._data?.uniqueLiteralFilledInstantiation; + } + set uniqueLiteralFilledInstantiation(value: any) { + this.data.uniqueLiteralFilledInstantiation = value; + } + + get syntheticType() { + return this._data?.syntheticType; + } + set syntheticType(value: any) { + this.data.syntheticType = value; + } + + get defaultOnlyType() { + return this._data?.defaultOnlyType; + } + set defaultOnlyType(value: any) { + this.data.defaultOnlyType = value; + } + + get constraint() { + return this._data?.constraint; + } + set constraint(value: any) { + this.data.constraint = value; + } + + get default() { + return this._data?.default; + } + set default(value: any) { + this.data.default = value; + } + + get isThisType() { + return this._data?.isThisType; + } + set isThisType(value: any) { + this.data.isThisType = value; + } + + get resolvedDefaultType() { + return this._data?.resolvedDefaultType; + } + set resolvedDefaultType(value: any) { + this.data.resolvedDefaultType = value; + } + + get objectType() { + return this._data?.objectType; + } + set objectType(value: any) { + this.data.objectType = value; + } + + get indexType() { + return this._data?.indexType; + } + set indexType(value: any) { + this.data.indexType = value; + } + + get accessFlags() { + return this._data?.accessFlags; + } + set accessFlags(value: any) { + this.data.accessFlags = value; + } + + get simplifiedForReading() { + return this._data?.simplifiedForReading; + } + set simplifiedForReading(value: any) { + this.data.simplifiedForReading = value; + } + + get simplifiedForWriting() { + return this._data?.simplifiedForWriting; + } + set simplifiedForWriting(value: any) { + this.data.simplifiedForWriting = value; + } + + get type() { + return this._data?.type; + } + set type(value: any) { + this.data.type = value; + } + + get indexFlags() { + return this._data?.indexFlags; + } + set indexFlags(value: any) { + this.data.indexFlags = value; + } + + get root() { + return this._data?.root; + } + set root(value: any) { + this.data.root = value; + } + + get checkType() { + return this._data?.checkType; + } + set checkType(value: any) { + this.data.checkType = value; + } + + get extendsType() { + return this._data?.extendsType; + } + set extendsType(value: any) { + this.data.extendsType = value; + } + + get resolvedTrueType() { + return this._data?.resolvedTrueType; + } + set resolvedTrueType(value: any) { + this.data.resolvedTrueType = value; + } + + get resolvedFalseType() { + return this._data?.resolvedFalseType; + } + set resolvedFalseType(value: any) { + this.data.resolvedFalseType = value; + } + + get resolvedInferredTrueType() { + return this._data?.resolvedInferredTrueType; + } + set resolvedInferredTrueType(value: any) { + this.data.resolvedInferredTrueType = value; + } + + get resolvedDefaultConstraint() { + return this._data?.resolvedDefaultConstraint; + } + set resolvedDefaultConstraint(value: any) { + this.data.resolvedDefaultConstraint = value; + } + + get resolvedConstraintOfDistributive() { + return this._data?.resolvedConstraintOfDistributive; + } + set resolvedConstraintOfDistributive(value: any) { + this.data.resolvedConstraintOfDistributive = value; + } + + get combinedMapper() { + return this._data?.combinedMapper; + } + set combinedMapper(value: any) { + this.data.combinedMapper = value; + } + + get texts() { + return this._data?.texts; + } + set texts(value: any) { + this.data.texts = value; + } + + get baseType() { + return this._data?.baseType; + } + set baseType(value: any) { + this.data.baseType = value; + } +} +// function Type(this: Type, checker: TypeChecker, flags: TypeFlags) { +// // Note: if modifying this, be sure to update TypeObject in src/services/services.ts +// this.flags = flags; +// if (Debug.isDebugging || tracing) { +// this.checker = checker; +// } +// } +class SignatureDataImpl { } +/** @internal */ +export class SignatureImpl { + flags: SignatureFlags; + checker!: TypeChecker; + declaration?: SignatureDeclaration | JSDocSignature; // Originating declaration + typeParameters?: readonly TypeParameter[]; // Type parameters (undefined if non-generic) + parameters: readonly Symbol[]; // Parameters + thisParameter?: Symbol; // symbol of this-type parameter + resolvedReturnType?: Type; // Lazily set by `getReturnTypeOfSignature`. + resolvedTypePredicate?: TypePredicate; + minArgumentCount: number; // Number of non-optional parameters + resolvedMinArgumentCount?: number; // Number of non-optional parameters (excluding trailing `void`) + target?: Signature; // Instantiation target + mapper?: TypeMapper; // Instantiation mapper + compositeSignatures?: Signature[]; // Underlying signatures of a union/intersection signature + compositeKind?: TypeFlags; // TypeFlags.Union if the underlying signatures are from union members, otherwise TypeFlags.Intersection + + constructor(checker: TypeChecker, flags: SignatureFlags) { + // Note: if modifying this, be sure to update SignatureObject in src/services/services.ts + this.flags = flags; + if (Debug.isDebugging) { + this.checker = checker; + } + this.declaration = undefined; + this.typeParameters = undefined; + this.parameters = undefined!; + this.thisParameter = undefined; + this.resolvedReturnType = undefined; + this.resolvedTypePredicate = undefined; + this.minArgumentCount = undefined!; + this.resolvedMinArgumentCount = undefined; + this.target = undefined; + this.mapper = undefined; + this.compositeSignatures = undefined; + this.compositeKind = undefined; + } -class NodeImpl implements Node { - pos; - end; - kind; - id = 0; - flags = NodeFlags.None; + _data: any = undefined; + get data() { + return this._data ??= new SignatureDataImpl(); + } + get erasedSignatureCache() { + return this._data?.erasedSignatureCache; + } + set erasedSignatureCache(value: any) { + this.data.erasedSignatureCache = value; + } + get canonicalSignatureCache() { + return this._data?.canonicalSignatureCache; + } + set canonicalSignatureCache(value: any) { + this.data.canonicalSignatureCache = value; + } + get baseSignatureCache() { + return this._data?.baseSignatureCache; + } + set baseSignatureCache(value: any) { + this.data.baseSignatureCache = value; + } + get optionalCallSignatureCache() { + return this._data?.optionalCallSignatureCache; + } + set optionalCallSignatureCache(value: any) { + this.data.optionalCallSignatureCache = value; + } + get isolatedSignatureType() { + return this._data?.isolatedSignatureType; + } + set isolatedSignatureType(value: any) { + this.data.isolatedSignatureType = value; + } + get instantiations() { + return this._data?.instantiations; + } + set instantiations(value: any) { + this.data.instantiations = value; + } + get implementationSignatureCache() { + return this._data?.implementationSignatureCache; + } + set implementationSignatureCache(value: any) { + this.data.implementationSignatureCache = value; + } +} +class NodeDataImpl { +} +/** @internal */ +export class NodeImpl { + pos; // Node, Token, Identifier + end; // Node, Token, Identifier + kind; // Node, Token, Identifier + id = 0; // Node, Token, Identifier + flags = NodeFlags.None; // Node, Token, Identifier + transformFlags = TransformFlags.None; // Node, Token, Identifier + parent: Node = undefined!; // Node, Token, Identifier + original = undefined; // Node, Identifier + emitNode = undefined; // Node, Token, Identifier modifierFlagsCache = ModifierFlags.None; - transformFlags = TransformFlags.None; - parent = undefined!; - original = undefined; - emitNode = undefined; constructor(kind: SyntaxKind, pos: number, end: number) { + this.kind = kind; this.pos = pos; this.end = end; - this.kind = kind; - this.data = {}; + this.data = new NodeDataImpl(); } + data: any; + get sourceText() { + return this.data.sourceText; + } + set sourceText(value: any) { + this.data.sourceText = value; + } + get jsDoc() { return this.data.jsDoc; } @@ -8317,6 +9158,9 @@ class NodeImpl implements Node { this.data.jsDoc = value; } + // get modifierFlagsCache() { return this.data.modifierFlagsCache; } + // set modifierFlagsCache(value: any) { this.data.modifierFlagsCache = value } + get escapedText() { return this.data.escapedText; } @@ -8360,7 +9204,7 @@ class NodeImpl implements Node { } get name() { - return this.data.name; + return this.data?.name; } set name(value: any) { this.data.name = value; @@ -9645,8 +10489,8 @@ export const objectAllocator: ObjectAllocator = { getPrivateIdentifierConstructor: () => NodeImpl as any, getSourceFileConstructor: () => NodeImpl as any, getSymbolConstructor: () => Symbol as any, - getTypeConstructor: () => Type as any, - getSignatureConstructor: () => Signature as any, + getTypeConstructor: () => TypeImpl as any, + getSignatureConstructor: () => SignatureImpl as any, getSourceMapSourceConstructor: () => SourceMapSource as any, }; diff --git a/src/harness/harnessUtils.ts b/src/harness/harnessUtils.ts index d7989da8d6980..66de3bcec4b5a 100644 --- a/src/harness/harnessUtils.ts +++ b/src/harness/harnessUtils.ts @@ -177,13 +177,43 @@ export function sourceFileToJSON(file: ts.Node): string { return ts.Debug.formatNodeFlags(f); } + function addSerializableFlags(o: any, n: ts.Node) { + // 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)) { + if (flags & ts.NodeFlags.IdentifierHasExtendedUnicodeEscape) { + o.hasExtendedUnicodeEscape = true; + flags &= ~ts.NodeFlags.IdentifierHasExtendedUnicodeEscape; + } + } + if (flags) { + o.flags = getNodeFlagName(flags); + } + } function serializeNode(n: ts.Node): any { const o: any = { kind: getKindName(n.kind) }; if (ts.containsParseError(n)) { o.containsParseError = true; } + let nodeData; + if (n instanceof ts.NodeImpl) { + nodeData = (n as any as ts.NodeImpl).data; + o.pos = n.pos; + o.end = n.end; + addSerializableFlags(o, n); + if (ts.isNodeKind(n.kind) || ts.isLiteralKind(n.kind)) { + o.modifierFlagsCache = n.modifierFlagsCache; + } + o.transformFlags = n.transformFlags; + } + else { + nodeData = n; + } + if (!nodeData) return o; - for (const propertyName of Object.getOwnPropertyNames(n) as readonly (keyof ts.SourceFile | keyof ts.Identifier | keyof ts.StringLiteral)[]) { + for (const propertyName of Object.getOwnPropertyNames(nodeData) as readonly (keyof ts.SourceFile | keyof ts.Identifier | keyof ts.StringLiteral)[]) { switch (propertyName) { case "parent": case "symbol": @@ -198,29 +228,15 @@ export function sourceFileToJSON(file: ts.Node): string { case "emitNode": // Blocklist of items we never put in the baseline file. break; - + case "flags": + addSerializableFlags(o, nodeData); + break; case "hasExtendedUnicodeEscape": - if ((n as any).hasExtendedUnicodeEscape) { + if (nodeData.hasExtendedUnicodeEscape) { o.hasExtendedUnicodeEscape = true; } break; - case "flags": - // 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)) { - if (flags & ts.NodeFlags.IdentifierHasExtendedUnicodeEscape) { - o.hasExtendedUnicodeEscape = true; - flags &= ~ts.NodeFlags.IdentifierHasExtendedUnicodeEscape; - } - } - if (flags) { - o[propertyName] = getNodeFlagName(flags); - } - break; - case "parseDiagnostics": o[propertyName] = convertDiagnostics((n as any)[propertyName]); break; @@ -239,7 +255,7 @@ export function sourceFileToJSON(file: ts.Node): string { break; default: - o[propertyName] = (n as any)[propertyName]; + o[propertyName] = nodeData[propertyName]; } } @@ -319,8 +335,8 @@ function assertArrayStructuralEquals(array1: ts.NodeArray, array2: ts.N } function findChildName(parent: any, child: any) { - for (const name in parent) { - if (ts.hasProperty(parent, name) && parent[name] === child) { + for (const name in parent.data) { + if (ts.hasProperty(parent.data, name) && parent[name] === child) { return name; } } diff --git a/src/services/services.ts b/src/services/services.ts index 0afdecd646e0f..4b006d76a84eb 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -15,7 +15,6 @@ import { canIncludeBindAndCheckDiagnostics, changeCompilerHostLikeToUseCache, CharacterCodes, - CheckJsDirective, Classifications, ClassifiedSpan, ClassifiedSpan2020, @@ -61,17 +60,14 @@ import { EditorOptions, EditorSettings, ElementAccessExpression, - EmitNode, EmitTextWriter, emptyArray, emptyOptions, EndOfFileToken, - EntityName, equateValues, ExportDeclaration, Extension, extensionFromPath, - FileReference, FileTextChanges, filter, find, @@ -197,7 +193,6 @@ import { isTextWhiteSpaceLike, isThisTypeParameter, isTransientSymbol, - JSDoc, JsDoc, JSDocContainer, JSDocParsingMode, @@ -211,7 +206,6 @@ import { LanguageService, LanguageServiceHost, LanguageServiceMode, - LanguageVariant, lastOrUndefined, length, LineAndCharacter, @@ -233,6 +227,7 @@ import { Node, NodeArray, NodeFlags, + NodeImpl, noop, normalizePath, normalizeSpans, @@ -257,8 +252,6 @@ import { Path, positionIsSynthesized, PossibleProgramFileInfo, - PragmaMap, - PrivateIdentifier, Program, PropertyName, PropertySignature, @@ -291,6 +284,7 @@ import { SignatureHelp, SignatureHelpItems, SignatureHelpItemsOptions, + SignatureImpl, SignatureKind, singleElementArray, skipTypeChecking, @@ -301,8 +295,6 @@ import { SourceFileLike, SourceMapSource, startsWith, - Statement, - StringLiteral, StringLiteralLike, StringLiteralType, Symbol, @@ -328,16 +320,13 @@ import { timestamp, TodoComment, TodoCommentDescriptor, - Token, toPath, tracing, - TransformFlags, Type, TypeChecker, TypeFlags, - TypeNode, + TypeImpl, TypeParameter, - TypePredicate, TypeReference, typeToDisplayParts, UnionOrIntersectionType, @@ -359,44 +348,40 @@ 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); +function createNode(kind: TKind, pos: number, end: number, parent: Node): Node { + const node = new NodeObject(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; +class NodeObject extends NodeImpl implements Node { + override kind!: TKind; + + declare _declarationBrand: any; + declare _localsContainerBrand: any; + declare _primaryExpressionBrand: any; + declare _memberExpressionBrand: any; + declare _leftHandSideExpressionBrand: any; + declare _updateExpressionBrand: any; + declare _unaryExpressionBrand: any; + declare _expressionBrand: any; + declare _jsdocContainerBrand: any; + declare _flowContainerBrand: any; 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; + super(kind, pos, end); } + override get text(): string { + if (this.kind === SyntaxKind.Identifier || this.kind === SyntaxKind.PrivateIdentifier) { + return idText(this as any as Identifier); + } + return super.text; + } + override set text(value) { + super.text = value; + } 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"); @@ -458,37 +443,273 @@ class NodeObject implements Node { } public 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"); - return getNodeChildren(this) ?? setNodeChildren(this, createChildren(this, sourceFile)); + if (isNodeKind(this.kind)) { + 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) ?? setNodeChildren(this, createChildren(this, sourceFile)); + } + else { + return this.kind === SyntaxKind.EndOfFileToken ? (this as Node as EndOfFileToken).jsDoc || emptyArray : emptyArray; + } } public getFirstToken(sourceFile?: SourceFileLike): Node | undefined { - this.assertHasRealPosition(); - const children = this.getChildren(sourceFile); - if (!children.length) { + if (isNodeKind(this.kind)) { + 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); + } + else { 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); + if (isNodeKind(this.kind)) { + this.assertHasRealPosition(); + const children = this.getChildren(sourceFile); + + const child = lastOrUndefined(children); + if (!child) { + return undefined; + } - const child = lastOrUndefined(children); - if (!child) { + return child.kind < SyntaxKind.FirstNode ? child : child.getLastToken(sourceFile); + } + else { 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); + if (isNodeKind(this.kind)) { + return forEachChild(this, cbNode, cbNodeArray); + } + else { + return undefined; + } + } + + private get namedDeclarations(): Map | undefined { + return this.data.namedDeclarations; + } + private set namedDeclarations(value: Map | undefined) { + this.data.namedDeclarations = value; + } + + public get scriptSnapshot(): IScriptSnapshot { + return this.data.scriptSnapshot; + } + public set scriptSnapshot(value: IScriptSnapshot) { + this.data.scriptSnapshot = value; + } + + public get nameTable(): Map<__String, number> | undefined { + return this.data.nameTable; + } + public set nameTable(value: Map<__String, number> | undefined) { + this.data.nameTable = value; + } + + public update(newText: string, textChangeRange: TextChangeRange): SourceFile { + Debug.assertEqual(this.kind, SyntaxKind.SourceFile); + return updateSourceFile(this as SourceFile, newText, textChangeRange); + } + + public getLineAndCharacterOfPosition(position: number): LineAndCharacter { + Debug.assertEqual(this.kind, SyntaxKind.SourceFile); + return getLineAndCharacterOfPosition(this, position); + } + + public getLineStarts(): readonly number[] { + Debug.assertEqual(this.kind, SyntaxKind.SourceFile); + return getLineStarts(this); + } + + public getPositionOfLineAndCharacter(line: number, character: number, allowEdits?: true): number { + Debug.assertEqual(this.kind, SyntaxKind.SourceFile); + return computePositionOfLineAndCharacter(getLineStarts(this), line, character, this.text, allowEdits); + } + + public getLineEndOfPosition(pos: number): number { + Debug.assertEqual(this.kind, SyntaxKind.SourceFile); + 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 { + Debug.assertEqual(this.kind, SyntaxKind.SourceFile); + 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); + } + } } } @@ -538,117 +759,28 @@ function addSyntheticNodes(nodes: Node[], pos: number, end: number, parent: Node 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); - setNodeChildren(list, 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; + } + nodes.push(createNode(token, pos, textPos, parent)); + } + pos = textPos; + if (token === SyntaxKind.EndOfFileToken) { + break; + } } +} - public forEachChild(): T | undefined { - return undefined; +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); + setNodeChildren(list, children); + return list; } class SymbolObject implements Symbol { @@ -785,61 +917,7 @@ 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; - objectFlags?: ObjectFlags; - id!: number; - symbol!: Symbol; - constructor(checker: TypeChecker, flags: TypeFlags) { - // Note: if modifying this, be sure to update Type in src/compiler/types.ts - this.flags = flags; - this.checker = checker; - } +class TypeObject extends TypeImpl implements Type { getFlags(): TypeFlags { return this.flags; } @@ -927,37 +1005,19 @@ class TypeObject implements Type { } } -class SignatureObject implements Signature { - flags: SignatureFlags; - checker: TypeChecker; - declaration!: SignatureDeclaration; - typeParameters?: TypeParameter[]; - parameters!: Symbol[]; - thisParameter!: Symbol; - resolvedReturnType!: Type; - resolvedTypePredicate: TypePredicate | undefined; - minTypeArgumentCount!: number; - minArgumentCount!: number; - - // Undefined is used to indicate the value has not been computed. If, after computing, the - // symbol has no doc comment, then the empty array will be returned. - documentationComment?: SymbolDisplayPart[]; - jsDocTags?: JSDocTagInfo[]; // same - +class SignatureObject extends SignatureImpl implements Signature { constructor(checker: TypeChecker, flags: SignatureFlags) { - // Note: if modifying this, be sure to update Signature in src/compiler/types.ts - this.flags = flags; + super(checker, flags); this.checker = checker; } - getDeclaration(): SignatureDeclaration { - return this.declaration; + return this.declaration as SignatureDeclaration; } getTypeParameters(): TypeParameter[] | undefined { - return this.typeParameters; + return this.typeParameters as TypeParameter[]; } getParameters(): Symbol[] { - return this.parameters; + return this.parameters as Symbol[]; } getReturnType(): Type { return this.checker.getReturnTypeOfSignature(this); @@ -974,11 +1034,11 @@ class SignatureObject implements Signature { } getDocumentationComment(): SymbolDisplayPart[] { - return this.documentationComment || (this.documentationComment = getDocumentationComment(singleElementArray(this.declaration), this.checker)); + return this.data.documentationComment || (this.data.documentationComment = getDocumentationComment(singleElementArray(this.declaration), this.checker)); } getJsDocTags(): JSDocTagInfo[] { - return this.jsDocTags || (this.jsDocTags = getJsDocTagsOfDeclarations(singleElementArray(this.declaration), this.checker)); + return this.data.jsDocTags || (this.data.jsDocTags = getJsDocTagsOfDeclarations(singleElementArray(this.declaration), this.checker)); } } @@ -1051,250 +1111,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; @@ -1316,11 +1132,11 @@ class SourceMapSourceObject implements SourceMapSource { function getServicesObjectAllocator(): ObjectAllocator { return { getNodeConstructor: () => NodeObject, - getTokenConstructor: () => TokenObject, + getTokenConstructor: () => NodeObject, - getIdentifierConstructor: () => IdentifierObject, - getPrivateIdentifierConstructor: () => PrivateIdentifierObject, - getSourceFileConstructor: () => SourceFileObject, + getIdentifierConstructor: () => NodeObject, + getPrivateIdentifierConstructor: () => NodeObject, + getSourceFileConstructor: () => NodeObject, getSymbolConstructor: () => SymbolObject, getTypeConstructor: () => TypeObject, getSignatureConstructor: () => SignatureObject, From 977cbc5c8a01330fb3e691d6d7601ecdcd478f38 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Sat, 22 Jun 2024 14:43:42 +0100 Subject: [PATCH 03/13] Set properties directly on data in nodefactory reducing set accessor megamorphism. --- src/compiler/checker.ts | 194 +-- src/compiler/commandLineParser.ts | 1 - src/compiler/factory/nodeFactory.ts | 2133 ++++++++++++++------------- src/compiler/utilities.ts | 236 ++- 4 files changed, 1350 insertions(+), 1214 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d442ee660b443..dde5cd39eabe2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5335,9 +5335,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function createIntrinsicType(kind: TypeFlags, intrinsicName: string, objectFlags = ObjectFlags.None, debugIntrinsicName?: string): IntrinsicType { checkIntrinsicName(intrinsicName, debugIntrinsicName); - const type = createType(kind) as IntrinsicType; - type.intrinsicName = intrinsicName; - type.debugIntrinsicName = debugIntrinsicName; + const type = createType(kind) as TypeWithData; + type.data.intrinsicName = intrinsicName; + type.data.debugIntrinsicName = debugIntrinsicName; type.objectFlags = objectFlags | ObjectFlags.CouldContainTypeVariablesComputed | ObjectFlags.IsGenericTypeComputed | ObjectFlags.IsUnknownLikeUnionComputed | ObjectFlags.IsNeverIntersectionComputed; return type; } @@ -5349,15 +5349,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } seenIntrinsicNames.add(key); } - + type TypeWithData = T & { data: Omit; }; function createObjectType(objectFlags: ObjectFlags, symbol?: Symbol): ObjectType { - const type = createTypeWithSymbol(TypeFlags.Object, symbol!) as ObjectType; + const type = createTypeWithSymbol(TypeFlags.Object, symbol!) as TypeWithData; type.objectFlags = objectFlags; - type.members = undefined; - type.properties = undefined; - type.callSignatures = undefined; - type.constructSignatures = undefined; - type.indexInfos = undefined; + type.data.members = undefined; + type.data.properties = undefined; + type.data.callSignatures = undefined; + type.data.constructSignatures = undefined; + type.data.indexInfos = undefined; return type; } @@ -5402,14 +5402,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function setStructuredTypeMembers(type: StructuredType, members: SymbolTable, callSignatures: readonly Signature[], constructSignatures: readonly Signature[], indexInfos: readonly IndexInfo[]): ResolvedType { - const resolved = type as ResolvedType; - resolved.members = members; - resolved.properties = emptyArray; - resolved.callSignatures = callSignatures; - resolved.constructSignatures = constructSignatures; - resolved.indexInfos = indexInfos; + const resolved = type as TypeWithData; + resolved.data.members = members; + resolved.data.properties = emptyArray; + resolved.data.callSignatures = callSignatures; + resolved.data.constructSignatures = constructSignatures; + resolved.data.indexInfos = indexInfos; // This can loop back to getPropertyOfType() which would crash if `callSignatures` & `constructSignatures` are not initialized. - if (members !== emptySymbols) resolved.properties = getNamedMembers(members); + if (members !== emptySymbols) resolved.data.properties = getNamedMembers(members); return resolved; } @@ -13019,13 +13019,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return links.declaredType; } - function createComputedEnumType(symbol: Symbol) { - const regularType = createTypeWithSymbol(TypeFlags.Enum, symbol) as EnumType; - const freshType = createTypeWithSymbol(TypeFlags.Enum, symbol) as EnumType; - regularType.regularType = regularType; - regularType.freshType = freshType; - freshType.regularType = regularType; - freshType.freshType = freshType; + function createComputedEnumType(symbol: Symbol): EnumType { + const regularType = createTypeWithSymbol(TypeFlags.Enum, symbol) as TypeWithData; + const freshType = createTypeWithSymbol(TypeFlags.Enum, symbol) as TypeWithData; + regularType.data.regularType = regularType; + regularType.data.freshType = freshType; + freshType.data.regularType = regularType; + freshType.data.freshType = freshType; return regularType; } @@ -16258,22 +16258,22 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function createTypeReference(target: GenericType, typeArguments: readonly Type[] | undefined): TypeReference { const id = getTypeListId(typeArguments); - let type = target.instantiations.get(id); + let type = target.instantiations.get(id) as TypeWithData; if (!type) { - type = createObjectType(ObjectFlags.Reference, target.symbol) as TypeReference; + type = createObjectType(ObjectFlags.Reference, target.symbol) as TypeWithData; target.instantiations.set(id, type); type.objectFlags |= typeArguments ? getPropagatingFlagsOfTypes(typeArguments) : 0; - type.target = target; - type.resolvedTypeArguments = typeArguments; + type.data.target = target; + type.data.resolvedTypeArguments = typeArguments; } return type; } function cloneTypeReference(source: TypeReference): TypeReference { - const type = createTypeWithSymbol(source.flags, source.symbol) as TypeReference; + const type = createTypeWithSymbol(source.flags, source.symbol) as TypeWithData; type.objectFlags = source.objectFlags; - type.target = source.target; - type.resolvedTypeArguments = source.resolvedTypeArguments; + type.data.target = source.target; + type.data.resolvedTypeArguments = source.resolvedTypeArguments; return type; } @@ -16283,12 +16283,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const localAliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol); aliasTypeArguments = mapper ? instantiateTypes(localAliasTypeArguments, mapper) : localAliasTypeArguments; } - const type = createObjectType(ObjectFlags.Reference, target.symbol) as DeferredTypeReference; - type.target = target; - type.node = node; - type.mapper = mapper; - type.aliasSymbol = aliasSymbol; - type.aliasTypeArguments = aliasTypeArguments; + const type = createObjectType(ObjectFlags.Reference, target.symbol) as TypeWithData; + type.data.target = target; + type.data.node = node; + type.data.mapper = mapper; + type.data.aliasSymbol = aliasSymbol; + type.data.aliasTypeArguments = aliasTypeArguments; return type; } @@ -17206,28 +17206,28 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { lengthSymbol.links.type = getUnionType(literalTypes); } properties.push(lengthSymbol); - const type = createObjectType(ObjectFlags.Tuple | ObjectFlags.Reference) as TupleType & InterfaceTypeWithDeclaredMembers; - type.typeParameters = typeParameters; - type.outerTypeParameters = undefined; - type.localTypeParameters = typeParameters; - type.instantiations = new Map(); - type.instantiations.set(getTypeListId(type.typeParameters), type as GenericType); - type.target = type as GenericType; - type.resolvedTypeArguments = type.typeParameters; - type.thisType = createTypeParameter(); - type.thisType.isThisType = true; - type.thisType.constraint = type; - type.declaredProperties = properties; - type.declaredCallSignatures = emptyArray; - type.declaredConstructSignatures = emptyArray; - type.declaredIndexInfos = emptyArray; - type.elementFlags = elementFlags; - type.minLength = minLength; - type.fixedLength = fixedLength; - type.hasRestElement = !!(combinedFlags & ElementFlags.Variable); - type.combinedFlags = combinedFlags; - type.readonly = readonly; - type.labeledElementDeclarations = namedMemberDeclarations; + const type = createObjectType(ObjectFlags.Tuple | ObjectFlags.Reference) as TypeWithData; + type.data.typeParameters = typeParameters; + type.data.outerTypeParameters = undefined; + type.data.localTypeParameters = typeParameters; + type.data.instantiations = new Map(); + type.data.instantiations.set(getTypeListId(type.typeParameters), type as GenericType); + type.data.target = type as GenericType; + type.data.resolvedTypeArguments = type.typeParameters; + type.data.thisType = createTypeParameter(); + type.data.thisType.isThisType = true; + type.data.thisType.constraint = type; + type.data.declaredProperties = properties; + type.data.declaredCallSignatures = emptyArray; + type.data.declaredConstructSignatures = emptyArray; + type.data.declaredIndexInfos = emptyArray; + type.data.elementFlags = elementFlags; + type.data.minLength = minLength; + type.data.fixedLength = fixedLength; + type.data.hasRestElement = !!(combinedFlags & ElementFlags.Variable); + type.data.combinedFlags = combinedFlags; + type.data.readonly = readonly; + type.data.labeledElementDeclarations = namedMemberDeclarations; return type; } @@ -17925,12 +17925,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return true; } - function createIntersectionType(types: Type[], objectFlags: ObjectFlags, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[]) { - const result = createType(TypeFlags.Intersection) as IntersectionType; + function createIntersectionType(types: Type[], objectFlags: ObjectFlags, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[]): IntersectionType { + const result = createType(TypeFlags.Intersection) as TypeWithData; result.objectFlags = objectFlags | getPropagatingFlagsOfTypes(types, /*excludeKinds*/ TypeFlags.Nullable); - result.types = types; - result.aliasSymbol = aliasSymbol; - result.aliasTypeArguments = aliasTypeArguments; + result.data.types = types; + result.data.aliasSymbol = aliasSymbol; + result.data.aliasTypeArguments = aliasTypeArguments; return result; } @@ -18143,16 +18143,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return links.resolvedType; } - function createIndexType(type: InstantiableType | UnionOrIntersectionType, indexFlags: IndexFlags) { - const result = createType(TypeFlags.Index) as IndexType; - result.type = type; - result.indexFlags = indexFlags; + function createIndexType(type: InstantiableType | UnionOrIntersectionType, indexFlags: IndexFlags): IndexType { + const result = createType(TypeFlags.Index) as TypeWithData; + result.data.type = type; + result.data.indexFlags = indexFlags; return result; } - function createOriginIndexType(type: InstantiableType | UnionOrIntersectionType) { - const result = createOriginType(TypeFlags.Index) as IndexType; - result.type = type; + function createOriginIndexType(type: InstantiableType | UnionOrIntersectionType): IndexType { + const result = createOriginType(TypeFlags.Index) as TypeWithData; + result.data.type = type; return result; } @@ -18413,10 +18413,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { undefined; } - function createTemplateLiteralType(texts: readonly string[], types: readonly Type[]) { - const type = createType(TypeFlags.TemplateLiteral) as TemplateLiteralType; - type.texts = texts; - type.types = types; + function createTemplateLiteralType(texts: readonly string[], types: readonly Type[]): TemplateLiteralType { + const type = createType(TypeFlags.TemplateLiteral) as TypeWithData; + type.data.texts = texts; + type.data.types = types; return type; } @@ -18469,19 +18469,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return result; } - function createStringMappingType(symbol: Symbol, type: Type) { - const result = createTypeWithSymbol(TypeFlags.StringMapping, symbol) as StringMappingType; - result.type = type; + function createStringMappingType(symbol: Symbol, type: Type): StringMappingType { + const result = createTypeWithSymbol(TypeFlags.StringMapping, symbol) as TypeWithData; + result.data.type = type; return result; } - function createIndexedAccessType(objectType: Type, indexType: Type, accessFlags: AccessFlags, aliasSymbol: Symbol | undefined, aliasTypeArguments: readonly Type[] | undefined) { - const type = createType(TypeFlags.IndexedAccess) as IndexedAccessType; + function createIndexedAccessType(objectType: Type, indexType: Type, accessFlags: AccessFlags, aliasSymbol: Symbol | undefined, aliasTypeArguments: readonly Type[] | undefined): IndexedAccessType { + const type = createType(TypeFlags.IndexedAccess) as TypeWithData; type.objectType = objectType; - type.indexType = indexType; - type.accessFlags = accessFlags; - type.aliasSymbol = aliasSymbol; - type.aliasTypeArguments = aliasTypeArguments; + type.data.indexType = indexType; + type.data.accessFlags = accessFlags; + type.data.aliasSymbol = aliasSymbol; + type.data.aliasTypeArguments = aliasTypeArguments; return type; } @@ -19568,10 +19568,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return info.isReadonly !== readonly ? createIndexInfo(info.keyType, info.type, readonly, info.declaration) : info; } - function createLiteralType(flags: TypeFlags, value: string | number | PseudoBigInt, symbol?: Symbol, regularType?: LiteralType) { - const type = createTypeWithSymbol(flags, symbol!) as LiteralType; - type.value = value; - type.regularType = regularType || type; + function createLiteralType(flags: TypeFlags, value: string | number | PseudoBigInt, symbol?: Symbol, regularType?: LiteralType): LiteralType { + const type = createTypeWithSymbol(flags, symbol!) as TypeWithData; + type.data.value = value; + type.data.regularType = regularType || type; return type; } @@ -19635,9 +19635,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return links.resolvedType; } - function createUniqueESSymbolType(symbol: Symbol) { - const type = createTypeWithSymbol(TypeFlags.UniqueESSymbol, symbol) as UniqueESSymbolType; - type.escapedName = `__@${type.symbol.escapedName}@${getSymbolId(type.symbol)}` as __String; + function createUniqueESSymbolType(symbol: Symbol): UniqueESSymbolType { + const type = createTypeWithSymbol(TypeFlags.UniqueESSymbol, symbol) as TypeWithData; + type.data.escapedName = `__@${type.symbol.escapedName}@${getSymbolId(type.symbol)}` as __String; return type; } @@ -25681,10 +25681,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } // For all other object types we infer a new object type where the reverse mapping has been // applied to the type of each property. - const reversed = createObjectType(ObjectFlags.ReverseMapped | ObjectFlags.Anonymous, /*symbol*/ undefined) as ReverseMappedType; - reversed.source = source; - reversed.mappedType = target; - reversed.constraintType = constraint; + const reversed = createObjectType(ObjectFlags.ReverseMapped | ObjectFlags.Anonymous, /*symbol*/ undefined) as TypeWithData; + reversed.data.source = source; + reversed.data.mappedType = target; + reversed.data.constraintType = constraint; return reversed; } @@ -27807,8 +27807,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // array types are ultimately converted into manifest array types (using getFinalArrayType) // and never escape the getFlowTypeOfReference function. function createEvolvingArrayType(elementType: Type): EvolvingArrayType { - const result = createObjectType(ObjectFlags.EvolvingArray) as EvolvingArrayType; - result.elementType = elementType; + const result = createObjectType(ObjectFlags.EvolvingArray) as TypeWithData; + result.data.elementType = elementType; return result; } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index fd5e061e1f0d3..5c0a33c6e46bb 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -97,7 +97,6 @@ import { ParsedCommandLine, parseJsonText, Path, - PluginImport, PollingWatchKind, PrefixUnaryExpression, ProjectReference, diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 100e400d7bb3e..d3a8860744ad8 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -476,7 +476,13 @@ export const enum NodeFactoryFlags { } const nodeFactoryPatchers: ((factory: NodeFactory) => void)[] = []; - +type NodeData = Readonly> & { + flags: NodeFlags; + original?: Node; + transformFlags: TransformFlags; + emitNode: EmitNode | undefined; + data: Mutable>; +}; /** @internal */ export function addNodeFactoryPatcher(fn: (factory: NodeFactory) => void) { nodeFactoryPatchers.push(fn); @@ -1206,20 +1212,21 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } function createBaseNode(kind: T["kind"]) { - return baseFactory.createBaseNode(kind) as Mutable; + return baseFactory.createBaseNode(kind) as NodeData; } function createBaseDeclaration(kind: T["kind"]) { const node = createBaseNode(kind); - node.symbol = undefined!; // initialized by binder - node.localSymbol = undefined; // initialized by binder + const nodeData = node.data; + nodeData.symbol = undefined!; // initialized by binder + nodeData.localSymbol = undefined; // initialized by binder return node; } - function finishUpdateBaseSignatureDeclaration(updated: Mutable, original: T) { + function finishUpdateBaseSignatureDeclaration(updated: T, original: T) { if (updated !== original) { // copy children used for quick info - updated.typeArguments = original.typeArguments; + (updated as unknown as NodeData).data.typeArguments = original.typeArguments; } return update(updated, original); } @@ -1233,8 +1240,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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; + const nodeData = node.data; + nodeData.text = text; + nodeData.numericLiteralFlags = numericLiteralFlags; if (numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier) node.transformFlags |= TransformFlags.ContainsES2015; return node; } @@ -1242,22 +1250,23 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBigIntLiteral(value: string | PseudoBigInt): BigIntLiteral { const node = createBaseToken(SyntaxKind.BigIntLiteral); - node.text = typeof value === "string" ? value : pseudoBigIntToString(value) + "n"; + node.data.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; + const nodeData = node.data; + nodeData.text = text; + nodeData.singleQuote = isSingleQuote; return node; } // @api function createStringLiteral(text: string, isSingleQuote?: boolean, hasExtendedUnicodeEscape?: boolean): StringLiteral { const node = createBaseStringLiteral(text, isSingleQuote); - node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape; + node.data.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape; if (hasExtendedUnicodeEscape) node.transformFlags |= TransformFlags.ContainsES2015; return node; } @@ -1265,14 +1274,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createStringLiteralFromNode(sourceNode: PropertyNameLiteral | PrivateIdentifier): StringLiteral { const node = createBaseStringLiteral(getTextOfIdentifierOrLiteral(sourceNode), /*isSingleQuote*/ undefined); - node.textSourceNode = sourceNode; + node.data.textSourceNode = sourceNode; return node; } // @api function createRegularExpressionLiteral(text: string): RegularExpressionLiteral { const node = createBaseToken(SyntaxKind.RegularExpressionLiteral); - node.text = text; + node.data.text = text; return node; } @@ -1292,7 +1301,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode case SyntaxKind.RegularExpressionLiteral: return createRegularExpressionLiteral(text); case SyntaxKind.NoSubstitutionTemplateLiteral: - return createTemplateLiteralLikeNode(kind, text, /*rawText*/ undefined, /*templateFlags*/ 0) as NoSubstitutionTemplateLiteral; + return createTemplateLiteralLikeNode(kind, text, /*rawText*/ undefined, /*templateFlags*/ 0) as TemplateLiteralLikeNode as NoSubstitutionTemplateLiteral; } } @@ -1301,16 +1310,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // 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 + const node = baseFactory.createBaseIdentifierNode(SyntaxKind.Identifier) as NodeData; + const nodeData = node.data; + nodeData.escapedText = escapedText; + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.symbol = undefined!; // initialized by checker return node; } function createBaseGeneratedIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags, prefix: string | GeneratedNamePart | undefined, suffix: string | undefined) { - const node = createBaseIdentifier(escapeLeadingUnderscores(text)) as Mutable; + const node = createBaseIdentifier(escapeLeadingUnderscores(text)) as NodeData; setIdentifierAutoGenerate(node, { flags: autoGenerateFlags, id: nextAutoGenerateId, @@ -1352,7 +1362,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode if (recordTempVariable) { recordTempVariable(name); } - return name; + return name as GeneratedIdentifier; } /** Create a unique temporary variable for use in a loop. */ @@ -1385,8 +1395,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } function createBasePrivateIdentifier(escapedText: __String) { - const node = baseFactory.createBasePrivateIdentifierNode(SyntaxKind.PrivateIdentifier) as Mutable; - node.escapedText = escapedText; + const node = baseFactory.createBasePrivateIdentifierNode(SyntaxKind.PrivateIdentifier) as NodeData; + node.data.escapedText = escapedText; node.transformFlags |= TransformFlags.ContainsClassFields; return node; } @@ -1433,7 +1443,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // function createBaseToken(kind: T["kind"]) { - return baseFactory.createBaseTokenNode(kind) as Mutable; + return baseFactory.createBaseTokenNode(kind) as NodeData; } // @api @@ -1492,7 +1502,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode break; case SyntaxKind.SuperKeyword: transformFlags = TransformFlags.ContainsES2015 | TransformFlags.ContainsLexicalSuper; - (node as Mutable> as Mutable).flowNode = undefined; // initialized by binder (FlowContainer) + (node as NodeData> as NodeData).data.flowNode = undefined; // initialized by binder (FlowContainer) break; case SyntaxKind.StaticKeyword: transformFlags = TransformFlags.ContainsES2015; @@ -1503,13 +1513,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode case SyntaxKind.ThisKeyword: // 'this' indicates a lexical 'this' transformFlags = TransformFlags.ContainsLexicalThis; - (node as Mutable> as Mutable).flowNode = undefined; // initialized by binder (FlowContainer) + (node as NodeData> as NodeData).data.flowNode = undefined; // initialized by binder (FlowContainer) break; } if (transformFlags) { node.transformFlags |= transformFlags; } - return node; + return node as Token; } // @@ -1578,12 +1588,13 @@ 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); + const nodeData = node.data; + nodeData.left = left; + nodeData.right = asName(right); + node.transformFlags |= propagateChildFlags(nodeData.left) | + propagateIdentifierNameFlags(nodeData.right); - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -1598,7 +1609,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createComputedPropertyName(expression: Expression) { const node = createBaseNode(SyntaxKind.ComputedPropertyName); - node.expression = parenthesizerRules().parenthesizeExpressionOfComputedPropertyName(expression); + node.data.expression = parenthesizerRules().parenthesizeExpressionOfComputedPropertyName(expression); node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsES2015 | TransformFlags.ContainsComputedPropertyName; @@ -1619,14 +1630,15 @@ 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; + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.name = asName(name); + nodeData.constraint = constraint; + nodeData.default = defaultType; node.transformFlags = TransformFlags.ContainsTypeScript; - node.expression = undefined; // initialized by parser to report grammar errors - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.expression = undefined; // initialized by parser to report grammar errors + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -1650,28 +1662,29 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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)) { + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.dotDotDotToken = dotDotDotToken; + nodeData.name = asName(name); + nodeData.questionToken = questionToken; + nodeData.type = type; + nodeData.initializer = asInitializer(initializer); + + if (isThisIdentifier(nodeData.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.transformFlags = propagateChildrenFlags(nodeData.modifiers) | + propagateChildFlags(nodeData.dotDotDotToken) | + propagateNameFlags(nodeData.name) | + propagateChildFlags(nodeData.questionToken) | + propagateChildFlags(nodeData.initializer) | + (nodeData.questionToken ?? nodeData.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + (nodeData.dotDotDotToken ?? nodeData.initializer ? TransformFlags.ContainsES2015 : TransformFlags.None) | + (modifiersToFlags(nodeData.modifiers) & ModifierFlags.ParameterPropertyModifier ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None); } - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -1698,7 +1711,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createDecorator(expression: Expression) { const node = createBaseNode(SyntaxKind.Decorator); - node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsTypeScript | TransformFlags.ContainsTypeScriptClassSyntax | @@ -1723,16 +1736,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: PropertyName | string, 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; + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.name = asName(name); + nodeData.type = type; + nodeData.questionToken = questionToken; node.transformFlags = TransformFlags.ContainsTypeScript; - node.initializer = undefined; // initialized by parser to report grammar errors - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.initializer = undefined; // initialized by parser to report grammar errors + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -1752,10 +1766,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : node; } - function finishUpdatePropertySignature(updated: Mutable, original: PropertySignature) { + function finishUpdatePropertySignature(updated: NodeData, original: PropertySignature) { if (updated !== original) { // copy children used only for error reporting - updated.initializer = original.initializer; + updated.data.initializer = original.initializer; } return update(updated, original); } @@ -1769,23 +1783,24 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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) | + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.name = asName(name); + nodeData.questionToken = questionOrExclamationToken && isQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined; + nodeData.exclamationToken = questionOrExclamationToken && isExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined; + nodeData.type = type; + nodeData.initializer = asInitializer(initializer); + + const isAmbient = node.flags & NodeFlags.Ambient || modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient; + + node.transformFlags = propagateChildrenFlags(nodeData.modifiers) | + propagateNameFlags(nodeData.name) | + propagateChildFlags(nodeData.initializer) | + (isAmbient || nodeData.questionToken || nodeData.exclamationToken || nodeData.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + (isComputedPropertyName(nodeData.name) || modifiersToFlags(nodeData.modifiers) & ModifierFlags.Static && nodeData.initializer ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None) | TransformFlags.ContainsClassFields; - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -1818,18 +1833,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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; + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.name = asName(name); + nodeData.questionToken = questionToken; + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.parameters = asNodeArray(parameters); + nodeData.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 + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.typeArguments = undefined; // used in quick info return node; } @@ -1865,47 +1881,48 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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) { + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.asteriskToken = asteriskToken; + nodeData.name = asName(name); + nodeData.questionToken = questionToken; + nodeData.exclamationToken = undefined; // initialized by parser for grammar errors + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.parameters = createNodeArray(parameters); + nodeData.type = type; + nodeData.body = body; + + if (!nodeData.body) { node.transformFlags = TransformFlags.ContainsTypeScript; } else { - const isAsync = modifiersToFlags(node.modifiers) & ModifierFlags.Async; - const isGenerator = !!node.asteriskToken; + const isAsync = modifiersToFlags(nodeData.modifiers) & ModifierFlags.Async; + const isGenerator = !!nodeData.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) | + node.transformFlags = propagateChildrenFlags(nodeData.modifiers) | + propagateChildFlags(nodeData.asteriskToken) | + propagateNameFlags(nodeData.name) | + propagateChildFlags(nodeData.questionToken) | + propagateChildrenFlags(nodeData.typeParameters) | + propagateChildrenFlags(nodeData.parameters) | + propagateChildFlags(nodeData.type) | + (propagateChildFlags(nodeData.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | (isAsyncGenerator ? TransformFlags.ContainsES2018 : isAsync ? TransformFlags.ContainsES2017 : isGenerator ? TransformFlags.ContainsGenerator : TransformFlags.None) | - (node.questionToken || node.typeParameters || node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + (nodeData.questionToken || nodeData.typeParameters || nodeData.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; + nodeData.typeArguments = undefined; // used in quick info + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.endFlowNode = undefined; + nodeData.returnFlowNode = undefined; return node; } @@ -1933,10 +1950,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : node; } - function finishUpdateMethodDeclaration(updated: Mutable, original: MethodDeclaration) { + function finishUpdateMethodDeclaration(updated: NodeData, original: MethodDeclaration) { if (updated !== original) { // copy children used only for error reporting - updated.exclamationToken = original.exclamationToken; + updated.data.exclamationToken = original.exclamationToken; } return update(updated, original); } @@ -1944,17 +1961,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createClassStaticBlockDeclaration( body: Block, - ): ClassStaticBlockDeclaration { + ) { const node = createBaseDeclaration(SyntaxKind.ClassStaticBlockDeclaration); - node.body = body; + const nodeData = node.data; + nodeData.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; + nodeData.modifiers = undefined; // initialized by parser for grammar errors + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.endFlowNode = undefined; + nodeData.returnFlowNode = undefined; return node; } @@ -1968,10 +1986,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : node; } - function finishUpdateClassStaticBlockDeclaration(updated: Mutable, original: ClassStaticBlockDeclaration) { + function finishUpdateClassStaticBlockDeclaration(updated: NodeData, original: ClassStaticBlockDeclaration) { if (updated !== original) { // copy children used only for error reporting - updated.modifiers = original.modifiers; + updated.data.modifiers = original.modifiers; } return update(updated, original); } @@ -1983,23 +2001,24 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode body: Block | undefined, ) { const node = createBaseDeclaration(SyntaxKind.Constructor); - node.modifiers = asNodeArray(modifiers); - node.parameters = createNodeArray(parameters); - node.body = body; - - node.transformFlags = propagateChildrenFlags(node.modifiers) | - propagateChildrenFlags(node.parameters) | - (propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.parameters = createNodeArray(parameters); + nodeData.body = body; + + node.transformFlags = propagateChildrenFlags(nodeData.modifiers) | + propagateChildrenFlags(nodeData.parameters) | + (propagateChildFlags(nodeData.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; + nodeData.typeParameters = undefined; // initialized by parser for grammar errors + nodeData.type = undefined; // initialized by parser for grammar errors + nodeData.typeArguments = undefined; // used in quick info + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.endFlowNode = undefined; + nodeData.returnFlowNode = undefined; return node; } @@ -2017,10 +2036,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : node; } - function finishUpdateConstructorDeclaration(updated: Mutable, original: ConstructorDeclaration) { + function finishUpdateConstructorDeclaration(updated: NodeData, original: ConstructorDeclaration) { if (updated !== original) { - updated.typeParameters = original.typeParameters; - updated.type = original.type; + updated.data.typeParameters = original.typeParameters; + updated.data.type = original.type; } return finishUpdateBaseSignatureDeclaration(updated, original); } @@ -2034,32 +2053,33 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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) { + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.name = asName(name); + nodeData.parameters = createNodeArray(parameters); + nodeData.type = type; + nodeData.body = body; + + if (!nodeData.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.transformFlags = propagateChildrenFlags(nodeData.modifiers) | + propagateNameFlags(nodeData.name) | + propagateChildrenFlags(nodeData.parameters) | + propagateChildFlags(nodeData.type) | + (propagateChildFlags(nodeData.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | + (nodeData.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; + nodeData.typeArguments = undefined; // used in quick info + nodeData.typeParameters = undefined; // initialized by parser for grammar errors + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.endFlowNode = undefined; + nodeData.returnFlowNode = undefined; return node; } @@ -2081,10 +2101,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : node; } - function finishUpdateGetAccessorDeclaration(updated: Mutable, original: GetAccessorDeclaration) { + function finishUpdateGetAccessorDeclaration(updated: NodeData, original: GetAccessorDeclaration) { if (updated !== original) { // copy children used only for error reporting - updated.typeParameters = original.typeParameters; + updated.data.typeParameters = original.typeParameters; } return finishUpdateBaseSignatureDeclaration(updated, original); } @@ -2097,31 +2117,32 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode body: Block | undefined, ) { const node = createBaseDeclaration(SyntaxKind.SetAccessor); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.parameters = createNodeArray(parameters); - node.body = body; + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.name = asName(name); + nodeData.parameters = createNodeArray(parameters); + nodeData.body = body; - if (!node.body) { + if (!nodeData.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.transformFlags = propagateChildrenFlags(nodeData.modifiers) | + propagateNameFlags(nodeData.name) | + propagateChildrenFlags(nodeData.parameters) | + (propagateChildFlags(nodeData.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | + (nodeData.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; + nodeData.typeArguments = undefined; // used in quick info + nodeData.typeParameters = undefined; // initialized by parser for grammar errors + nodeData.type = undefined; // initialized by parser for grammar errors + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.endFlowNode = undefined; + nodeData.returnFlowNode = undefined; return node; } @@ -2141,11 +2162,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : node; } - function finishUpdateSetAccessorDeclaration(updated: Mutable, original: SetAccessorDeclaration) { + function finishUpdateSetAccessorDeclaration(updated: NodeData, original: SetAccessorDeclaration) { if (updated !== original) { // copy children used only for error reporting - updated.typeParameters = original.typeParameters; - updated.type = original.type; + updated.data.typeParameters = original.typeParameters; + updated.data.type = original.type; } return finishUpdateBaseSignatureDeclaration(updated, original); } @@ -2157,15 +2178,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode | undefined, ): CallSignatureDeclaration { const node = createBaseDeclaration(SyntaxKind.CallSignature); - node.typeParameters = asNodeArray(typeParameters); - node.parameters = asNodeArray(parameters); - node.type = type; + const nodeData = node.data; + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.parameters = asNodeArray(parameters); + nodeData.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 + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.typeArguments = undefined; // used in quick info return node; } @@ -2190,15 +2212,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode | undefined, ): ConstructSignatureDeclaration { const node = createBaseDeclaration(SyntaxKind.ConstructSignature); - node.typeParameters = asNodeArray(typeParameters); - node.parameters = asNodeArray(parameters); - node.type = type; + const nodeData = node.data; + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.parameters = asNodeArray(parameters); + nodeData.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 + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.typeArguments = undefined; // used in quick info return node; } @@ -2223,15 +2246,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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. + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.parameters = asNodeArray(parameters); + nodeData.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 + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.typeArguments = undefined; // used in quick info return node; } @@ -2252,8 +2276,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTemplateLiteralTypeSpan(type: TypeNode, literal: TemplateMiddle | TemplateTail) { const node = createBaseNode(SyntaxKind.TemplateLiteralTypeSpan); - node.type = type; - node.literal = literal; + const nodeData = node.data; + nodeData.type = type; + nodeData.literal = literal; node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2278,9 +2303,10 @@ 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; + const nodeData = node.data; + nodeData.assertsModifier = assertsModifier; + nodeData.parameterName = asName(parameterName); + nodeData.type = type; node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2297,8 +2323,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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)); + const nodeData = node.data; + nodeData.typeName = asName(typeName); + nodeData.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(createNodeArray(typeArguments)); node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2316,18 +2343,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: readonly TypeParameterDeclaration[] | undefined, parameters: readonly ParameterDeclaration[], type: TypeNode, - ): FunctionTypeNode { + ) { const node = createBaseDeclaration(SyntaxKind.FunctionType); - node.typeParameters = asNodeArray(typeParameters); - node.parameters = asNodeArray(parameters); - node.type = type; + const nodeData = node.data; + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.parameters = asNodeArray(parameters); + nodeData.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 + nodeData.modifiers = undefined; // initialized by parser for grammar errors + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.typeArguments = undefined; // used in quick info return node; } @@ -2345,10 +2373,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : node; } - function finishUpdateFunctionTypeNode(updated: Mutable, original: FunctionTypeNode) { + function finishUpdateFunctionTypeNode(updated: NodeData, original: FunctionTypeNode) { if (updated !== original) { // copy children used only for error reporting - updated.modifiers = original.modifiers; + updated.data.modifiers = original.modifiers; } return finishUpdateBaseSignatureDeclaration(updated, original); } @@ -2367,16 +2395,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode, ): ConstructorTypeNode { const node = createBaseDeclaration(SyntaxKind.ConstructorType); - node.modifiers = asNodeArray(modifiers); - node.typeParameters = asNodeArray(typeParameters); - node.parameters = asNodeArray(parameters); - node.type = type; + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.parameters = asNodeArray(parameters); + nodeData.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 + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.typeArguments = undefined; // used in quick info return node; } @@ -2424,8 +2453,9 @@ 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); + const nodeData = node.data; + nodeData.exprName = exprName; + nodeData.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2441,7 +2471,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeLiteralNode(members: readonly TypeElement[] | undefined) { const node = createBaseDeclaration(SyntaxKind.TypeLiteral); - node.members = createNodeArray(members); + node.data.members = createNodeArray(members); node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2456,7 +2486,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createArrayTypeNode(elementType: TypeNode) { const node = createBaseNode(SyntaxKind.ArrayType); - node.elementType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(elementType); + node.data.elementType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(elementType); node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2471,7 +2501,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTupleTypeNode(elements: readonly (TypeNode | NamedTupleMember)[]) { const node = createBaseNode(SyntaxKind.TupleType); - node.elements = createNodeArray(parenthesizerRules().parenthesizeElementTypesOfTupleType(elements)); + node.data.elements = createNodeArray(parenthesizerRules().parenthesizeElementTypesOfTupleType(elements)); node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2486,13 +2516,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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; + const nodeData = node.data; + nodeData.dotDotDotToken = dotDotDotToken; + nodeData.name = name; + nodeData.questionToken = questionToken; + nodeData.type = type; node.transformFlags = TransformFlags.ContainsTypeScript; - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -2509,7 +2540,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createOptionalTypeNode(type: TypeNode) { const node = createBaseNode(SyntaxKind.OptionalType); - node.type = parenthesizerRules().parenthesizeTypeOfOptionalType(type); + node.data.type = parenthesizerRules().parenthesizeTypeOfOptionalType(type); node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2524,7 +2555,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createRestTypeNode(type: TypeNode) { const node = createBaseNode(SyntaxKind.RestType); - node.type = type; + node.data.type = type; node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2538,7 +2569,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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.data.types = factory.createNodeArray(parenthesize(types)); node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2572,14 +2603,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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; + const nodeData = node.data; + nodeData.checkType = parenthesizerRules().parenthesizeCheckTypeOfConditionalType(checkType); + nodeData.extendsType = parenthesizerRules().parenthesizeExtendsTypeOfConditionalType(extendsType); + nodeData.trueType = trueType; + nodeData.falseType = falseType; node.transformFlags = TransformFlags.ContainsTypeScript; - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -2596,7 +2628,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createInferTypeNode(typeParameter: TypeParameterDeclaration) { const node = createBaseNode(SyntaxKind.InferType); - node.typeParameter = typeParameter; + node.data.typeParameter = typeParameter; node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2611,8 +2643,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTemplateLiteralType(head: TemplateHead, templateSpans: readonly TemplateLiteralTypeSpan[]) { const node = createBaseNode(SyntaxKind.TemplateLiteralType); - node.head = head; - node.templateSpans = createNodeArray(templateSpans); + const nodeData = node.data; + nodeData.head = head; + nodeData.templateSpans = createNodeArray(templateSpans); node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2634,14 +2667,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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; + const nodeData = node.data; + nodeData.argument = argument; + nodeData.attributes = attributes; + if (nodeData.assertions && nodeData.assertions.assertClause && nodeData.attributes) { + (nodeData.assertions as NodeData).data.assertClause = nodeData.attributes; } - node.qualifier = qualifier; - node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); - node.isTypeOf = isTypeOf; + nodeData.qualifier = qualifier; + nodeData.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); + nodeData.isTypeOf = isTypeOf; node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2667,7 +2701,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createParenthesizedType(type: TypeNode) { const node = createBaseNode(SyntaxKind.ParenthesizedType); - node.type = type; + node.data.type = type; node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2689,8 +2723,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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 ? + const nodeData = node.data; + nodeData.operator = operator; + nodeData.type = operator === SyntaxKind.ReadonlyKeyword ? parenthesizerRules().parenthesizeOperandOfReadonlyTypeOperator(type) : parenthesizerRules().parenthesizeOperandOfTypeOperator(type); node.transformFlags = TransformFlags.ContainsTypeScript; @@ -2707,8 +2742,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createIndexedAccessTypeNode(objectType: TypeNode, indexType: TypeNode) { const node = createBaseNode(SyntaxKind.IndexedAccessType); - node.objectType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(objectType); - node.indexType = indexType; + const nodeData = node.data; + nodeData.objectType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(objectType); + nodeData.indexType = indexType; node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2724,16 +2760,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.readonlyToken = readonlyToken; + nodeData.typeParameter = typeParameter; + nodeData.nameType = nameType; + nodeData.questionToken = questionToken; + nodeData.type = type; + nodeData.members = members && createNodeArray(members); node.transformFlags = TransformFlags.ContainsTypeScript; - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -2752,7 +2789,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createLiteralTypeNode(literal: LiteralTypeNode["literal"]) { const node = createBaseNode(SyntaxKind.LiteralType); - node.literal = literal; + node.data.literal = literal; node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2771,7 +2808,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createObjectBindingPattern(elements: readonly BindingElement[]) { const node = createBaseNode(SyntaxKind.ObjectBindingPattern); - node.elements = createNodeArray(elements); + node.data.elements = createNodeArray(elements); node.transformFlags |= propagateChildrenFlags(node.elements) | TransformFlags.ContainsES2015 | TransformFlags.ContainsBindingPattern; @@ -2792,7 +2829,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createArrayBindingPattern(elements: readonly ArrayBindingElement[]) { const node = createBaseNode(SyntaxKind.ArrayBindingPattern); - node.elements = createNodeArray(elements); + node.data.elements = createNodeArray(elements); node.transformFlags |= propagateChildrenFlags(node.elements) | TransformFlags.ContainsES2015 | TransformFlags.ContainsBindingPattern; @@ -2809,18 +2846,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) | + const nodeData = node.data; + nodeData.dotDotDotToken = dotDotDotToken; + nodeData.propertyName = asName(propertyName); + nodeData.name = asName(name); + nodeData.initializer = asInitializer(initializer); + node.transformFlags |= propagateChildFlags(nodeData.dotDotDotToken) | + propagateNameFlags(nodeData.propertyName) | + propagateNameFlags(nodeData.name) | + propagateChildFlags(nodeData.initializer) | + (nodeData.dotDotDotToken ? TransformFlags.ContainsRestOrSpread : TransformFlags.None) | TransformFlags.ContainsES2015; - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -2846,8 +2884,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // 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; + const nodeData = node.data; + nodeData.elements = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(elementsArray); + nodeData.multiLine = multiLine; node.transformFlags |= propagateChildrenFlags(node.elements); return node; } @@ -2862,11 +2901,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createObjectLiteralExpression(properties?: readonly ObjectLiteralElementLike[], multiLine?: boolean) { const node = createBaseDeclaration(SyntaxKind.ObjectLiteralExpression); - node.properties = createNodeArray(properties); - node.multiLine = multiLine; + const nodeData = node.data; + nodeData.properties = createNodeArray(properties); + nodeData.multiLine = multiLine; node.transformFlags |= propagateChildrenFlags(node.properties); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -2879,17 +2919,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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); + const nodeData = node.data; + nodeData.expression = expression; + nodeData.questionDotToken = questionDotToken; + nodeData.name = name; + node.transformFlags = propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.questionDotToken) | + (isIdentifier(nodeData.name) ? + propagateIdentifierNameFlags(nodeData.name) : + propagateChildFlags(nodeData.name) | TransformFlags.ContainsPrivateIdentifierInExpression); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -2926,7 +2967,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true), questionDotToken, asName(name), - ) as Mutable; + ) as NodeData; node.flags |= NodeFlags.OptionalChain; node.transformFlags |= TransformFlags.ContainsES2020; return node; @@ -2946,15 +2987,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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); + const nodeData = node.data; + nodeData.expression = expression; + nodeData.questionDotToken = questionDotToken; + nodeData.argumentExpression = argumentExpression; + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.questionDotToken) | + propagateChildFlags(nodeData.argumentExpression); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -2991,7 +3033,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true), questionDotToken, asExpression(index), - ) as Mutable; + ) as NodeData; node.flags |= NodeFlags.OptionalChain; node.transformFlags |= TransformFlags.ContainsES2020; return node; @@ -3011,18 +3053,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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) { + const nodeData = node.data; + nodeData.expression = expression; + nodeData.questionDotToken = questionDotToken; + nodeData.typeArguments = typeArguments; + nodeData.arguments = argumentsArray; + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.questionDotToken) | + propagateChildrenFlags(nodeData.typeArguments) | + propagateChildrenFlags(nodeData.arguments); + if (nodeData.typeArguments) { node.transformFlags |= TransformFlags.ContainsTypeScript; } - if (isSuperProperty(node.expression)) { + if (isSuperProperty(nodeData.expression)) { node.transformFlags |= TransformFlags.ContainsLexicalThis; } return node; @@ -3061,7 +3104,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionDotToken, asNodeArray(typeArguments), parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray)), - ) as Mutable; + ) as NodeData; node.flags |= NodeFlags.OptionalChain; node.transformFlags |= TransformFlags.ContainsES2020; return node; @@ -3081,14 +3124,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) | + const nodeData = node.data; + nodeData.expression = parenthesizerRules().parenthesizeExpressionOfNew(expression); + nodeData.typeArguments = asNodeArray(typeArguments); + nodeData.arguments = argumentsArray ? parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(argumentsArray) : undefined; + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildrenFlags(nodeData.typeArguments) | + propagateChildrenFlags(nodeData.arguments) | TransformFlags.ContainsES2020; - if (node.typeArguments) { + if (nodeData.typeArguments) { node.transformFlags |= TransformFlags.ContainsTypeScript; } return node; @@ -3106,17 +3150,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) | + const nodeData = node.data; + nodeData.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag, /*optionalChain*/ false); + nodeData.typeArguments = asNodeArray(typeArguments); + nodeData.template = template; + node.transformFlags |= propagateChildFlags(nodeData.tag) | + propagateChildrenFlags(nodeData.typeArguments) | + propagateChildFlags(nodeData.template) | TransformFlags.ContainsES2015; - if (node.typeArguments) { + if (nodeData.typeArguments) { node.transformFlags |= TransformFlags.ContainsTypeScript; } - if (hasInvalidEscape(node.template)) { + if (hasInvalidEscape(nodeData.template)) { node.transformFlags |= TransformFlags.ContainsES2018; } return node; @@ -3134,8 +3179,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeAssertion(type: TypeNode, expression: Expression) { const node = createBaseNode(SyntaxKind.TypeAssertionExpression); - node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); - node.type = type; + const nodeData = node.data; + nodeData.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + nodeData.type = type; node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.type) | TransformFlags.ContainsTypeScript; @@ -3153,10 +3199,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createParenthesizedExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.ParenthesizedExpression); - node.expression = expression; + const nodeData = node.data; + nodeData.expression = expression; node.transformFlags = propagateChildFlags(node.expression); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -3178,39 +3225,40 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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 nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.asteriskToken = asteriskToken; + nodeData.name = asName(name); + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.parameters = createNodeArray(parameters); + nodeData.type = type; + nodeData.body = body; + + const isAsync = modifiersToFlags(nodeData.modifiers) & ModifierFlags.Async; + const isGenerator = !!nodeData.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) | + node.transformFlags = propagateChildrenFlags(nodeData.modifiers) | + propagateChildFlags(nodeData.asteriskToken) | + propagateNameFlags(nodeData.name) | + propagateChildrenFlags(nodeData.typeParameters) | + propagateChildrenFlags(nodeData.parameters) | + propagateChildFlags(nodeData.type) | + (propagateChildFlags(nodeData.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | (isAsyncGenerator ? TransformFlags.ContainsES2018 : isAsync ? TransformFlags.ContainsES2017 : isGenerator ? TransformFlags.ContainsGenerator : TransformFlags.None) | - (node.typeParameters || node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + (nodeData.typeParameters || nodeData.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; + nodeData.typeArguments = undefined; // used in quick info + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.endFlowNode = undefined; + nodeData.returnFlowNode = undefined; return node; } @@ -3246,32 +3294,33 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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) | + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.parameters = createNodeArray(parameters); + nodeData.type = type; + nodeData.equalsGreaterThanToken = equalsGreaterThanToken ?? createToken(SyntaxKind.EqualsGreaterThanToken); + nodeData.body = parenthesizerRules().parenthesizeConciseBodyOfArrowFunction(body); + + const isAsync = modifiersToFlags(nodeData.modifiers) & ModifierFlags.Async; + + node.transformFlags = propagateChildrenFlags(nodeData.modifiers) | + propagateChildrenFlags(nodeData.typeParameters) | + propagateChildrenFlags(nodeData.parameters) | + propagateChildFlags(nodeData.type) | + propagateChildFlags(nodeData.equalsGreaterThanToken) | + (propagateChildFlags(nodeData.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | + (nodeData.typeParameters || nodeData.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; + nodeData.typeArguments = undefined; // used in quick info + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.endFlowNode = undefined; + nodeData.returnFlowNode = undefined; return node; } @@ -3298,7 +3347,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createDeleteExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.DeleteExpression); - node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); node.transformFlags |= propagateChildFlags(node.expression); return node; } @@ -3313,7 +3362,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeOfExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.TypeOfExpression); - node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); node.transformFlags |= propagateChildFlags(node.expression); return node; } @@ -3328,7 +3377,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createVoidExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.VoidExpression); - node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); node.transformFlags |= propagateChildFlags(node.expression); return node; } @@ -3343,7 +3392,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createAwaitExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.AwaitExpression); - node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsES2017 | TransformFlags.ContainsES2018 | @@ -3361,8 +3410,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createPrefixUnaryExpression(operator: PrefixUnaryOperator, operand: Expression) { const node = createBaseNode(SyntaxKind.PrefixUnaryExpression); - node.operator = operator; - node.operand = parenthesizerRules().parenthesizeOperandOfPrefixUnary(operand); + const nodeData = node.data; + nodeData.operator = operator; + nodeData.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 @@ -3387,8 +3437,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createPostfixUnaryExpression(operand: Expression, operator: PostfixUnaryOperator) { const node = createBaseNode(SyntaxKind.PostfixUnaryExpression); - node.operator = operator; - node.operand = parenthesizerRules().parenthesizeOperandOfPostfixUnary(operand); + const nodeData = node.data; + nodeData.operator = operator; + nodeData.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 @@ -3410,13 +3461,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function createBinaryExpression(left: Expression, operator: BinaryOperator | BinaryOperatorToken, right: Expression) { + function createBinaryExpression(left: Expression, operator: BinaryOperator | BinaryOperatorToken, right: Expression): BinaryExpression { 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); + const nodeData = node.data; + nodeData.left = parenthesizerRules().parenthesizeLeftSideOfBinary(operatorKind, left); + nodeData.operatorToken = operatorToken; + nodeData.right = parenthesizerRules().parenthesizeRightSideOfBinary(operatorKind, node.left, right); node.transformFlags |= propagateChildFlags(node.left) | propagateChildFlags(node.operatorToken) | propagateChildFlags(node.right); @@ -3446,7 +3498,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.transformFlags |= TransformFlags.ContainsPrivateIdentifierInExpression; } - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -3466,16 +3518,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.condition = parenthesizerRules().parenthesizeConditionOfConditionalExpression(condition); + nodeData.questionToken = questionToken ?? createToken(SyntaxKind.QuestionToken); + nodeData.whenTrue = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenTrue); + nodeData.colonToken = colonToken ?? createToken(SyntaxKind.ColonToken); + nodeData.whenFalse = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenFalse); + node.transformFlags |= propagateChildFlags(nodeData.condition) | + propagateChildFlags(nodeData.questionToken) | + propagateChildFlags(nodeData.whenTrue) | + propagateChildFlags(nodeData.colonToken) | + propagateChildFlags(nodeData.whenFalse); return node; } @@ -3500,8 +3553,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTemplateExpression(head: TemplateHead, templateSpans: readonly TemplateSpan[]) { const node = createBaseNode(SyntaxKind.TemplateExpression); - node.head = head; - node.templateSpans = createNodeArray(templateSpans); + const nodeData = node.data; + nodeData.head = head; + nodeData.templateSpans = createNodeArray(templateSpans); node.transformFlags |= propagateChildFlags(node.head) | propagateChildrenFlags(node.templateSpans) | TransformFlags.ContainsES2015; @@ -3552,19 +3606,21 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // 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); + const nodeData = node.data; + nodeData.text = text; + nodeData.rawText = rawText; + nodeData.templateFlags = templateFlags! & TokenFlags.TemplateLiteralLikeFlags; + node.transformFlags = getTransformFlagsOfTemplateLiteralLike(nodeData.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); + const nodeData = node.data; + nodeData.text = text; + nodeData.rawText = rawText; + nodeData.templateFlags = templateFlags! & TokenFlags.TemplateLiteralLikeFlags; + node.transformFlags = getTransformFlagsOfTemplateLiteralLike(nodeData.templateFlags); return node; } @@ -3579,19 +3635,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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 createTemplateLiteralLikeNode(SyntaxKind.TemplateHead, text, rawText, templateFlags) as TemplateLiteralLikeNode as TemplateHead; } // @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 createTemplateLiteralLikeNode(SyntaxKind.TemplateMiddle, text, rawText, templateFlags) as TemplateLiteralLikeNode as TemplateMiddle; } // @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 createTemplateLiteralLikeNode(SyntaxKind.TemplateTail, text, rawText, templateFlags) as TemplateLiteralLikeNode as TemplateTail; } // @api @@ -3604,10 +3660,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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) | + const nodeData = node.data; + nodeData.expression = expression && parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + nodeData.asteriskToken = asteriskToken; + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.asteriskToken) | TransformFlags.ContainsES2015 | TransformFlags.ContainsES2018 | TransformFlags.ContainsYield; @@ -3625,7 +3682,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createSpreadElement(expression: Expression) { const node = createBaseNode(SyntaxKind.SpreadElement); - node.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + node.data.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsES2015 | TransformFlags.ContainsRestOrSpread; @@ -3648,20 +3705,21 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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) | + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.name = asName(name); + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.heritageClauses = asNodeArray(heritageClauses); + nodeData.members = createNodeArray(members); + node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | + propagateNameFlags(nodeData.name) | + propagateChildrenFlags(nodeData.typeParameters) | + propagateChildrenFlags(nodeData.heritageClauses) | + propagateChildrenFlags(nodeData.members) | + (nodeData.typeParameters ? TransformFlags.ContainsTypeScript : TransformFlags.None) | TransformFlags.ContainsES2015; - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -3691,10 +3749,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) | + const nodeData = node.data; + nodeData.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); + nodeData.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildrenFlags(nodeData.typeArguments) | TransformFlags.ContainsES2015; return node; } @@ -3710,10 +3769,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) | + const nodeData = node.data; + nodeData.expression = expression; + nodeData.type = type; + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.type) | TransformFlags.ContainsTypeScript; return node; } @@ -3729,7 +3789,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNonNullExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.NonNullExpression); - node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsTypeScript; return node; @@ -3748,10 +3808,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) | + const nodeData = node.data; + nodeData.expression = expression; + nodeData.type = type; + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.type) | TransformFlags.ContainsTypeScript; return node; } @@ -3768,7 +3829,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createNonNullChain(expression: Expression) { const node = createBaseNode(SyntaxKind.NonNullExpression); node.flags |= NodeFlags.OptionalChain; - node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true); + node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true); node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsTypeScript; return node; @@ -3785,9 +3846,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createMetaProperty(keywordToken: MetaProperty["keywordToken"], name: Identifier) { const node = createBaseNode(SyntaxKind.MetaProperty); - node.keywordToken = keywordToken; - node.name = name; - node.transformFlags |= propagateChildFlags(node.name); + const nodeData = node.data; + nodeData.keywordToken = keywordToken; + nodeData.name = name; + node.transformFlags |= propagateChildFlags(nodeData.name); switch (keywordToken) { case SyntaxKind.NewKeyword: node.transformFlags |= TransformFlags.ContainsES2015; @@ -3799,7 +3861,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode return Debug.assertNever(keywordToken); } - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3817,10 +3879,11 @@ 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) | + const nodeData = node.data; + nodeData.expression = expression; + nodeData.literal = literal; + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.literal) | TransformFlags.ContainsES2015; return node; } @@ -3847,13 +3910,14 @@ 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); + const nodeData = node.data; + nodeData.statements = createNodeArray(statements); + nodeData.multiLine = multiLine; + node.transformFlags |= propagateChildrenFlags(nodeData.statements); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -3867,16 +3931,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) { + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.declarationList = isArray(declarationList) ? createVariableDeclarationList(declarationList) : declarationList; + node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | + propagateChildFlags(nodeData.declarationList); + if (modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; } - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3891,18 +3956,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createEmptyStatement() { const node = createBaseNode(SyntaxKind.EmptyStatement); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + node.data.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } // @api function createExpressionStatement(expression: Expression): ExpressionStatement { const node = createBaseNode(SyntaxKind.ExpressionStatement); - node.expression = parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression); - node.transformFlags |= propagateChildFlags(node.expression); + const nodeData = node.data; + nodeData.expression = parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression); + node.transformFlags |= propagateChildFlags(nodeData.expression); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3916,15 +3982,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.expression = expression; + nodeData.thenStatement = asEmbeddedStatement(thenStatement); + nodeData.elseStatement = asEmbeddedStatement(elseStatement); + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.thenStatement) | + propagateChildFlags(nodeData.elseStatement); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3940,13 +4007,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.statement = asEmbeddedStatement(statement); + nodeData.expression = expression; + node.transformFlags |= propagateChildFlags(nodeData.statement) | + propagateChildFlags(nodeData.expression); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3961,13 +4029,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.expression = expression; + nodeData.statement = asEmbeddedStatement(statement); + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.statement); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3982,19 +4051,20 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.initializer = initializer; + nodeData.condition = condition; + nodeData.incrementor = incrementor; + nodeData.statement = asEmbeddedStatement(statement); + node.transformFlags |= propagateChildFlags(nodeData.initializer) | + propagateChildFlags(nodeData.condition) | + propagateChildFlags(nodeData.incrementor) | + propagateChildFlags(nodeData.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) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4011,17 +4081,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.initializer = initializer; + nodeData.expression = expression; + nodeData.statement = asEmbeddedStatement(statement); + node.transformFlags |= propagateChildFlags(nodeData.initializer) | + propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.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) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4037,21 +4108,22 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) | + const nodeData = node.data; + nodeData.awaitModifier = awaitModifier; + nodeData.initializer = initializer; + nodeData.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + nodeData.statement = asEmbeddedStatement(statement); + node.transformFlags |= propagateChildFlags(nodeData.awaitModifier) | + propagateChildFlags(nodeData.initializer) | + propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.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) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4068,12 +4140,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createContinueStatement(label?: string | Identifier): ContinueStatement { const node = createBaseNode(SyntaxKind.ContinueStatement); - node.label = asName(label); - node.transformFlags |= propagateChildFlags(node.label) | + const nodeData = node.data; + nodeData.label = asName(label); + node.transformFlags |= propagateChildFlags(nodeData.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4087,12 +4160,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBreakStatement(label?: string | Identifier): BreakStatement { const node = createBaseNode(SyntaxKind.BreakStatement); - node.label = asName(label); - node.transformFlags |= propagateChildFlags(node.label) | + const nodeData = node.data; + nodeData.label = asName(label); + node.transformFlags |= propagateChildFlags(nodeData.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4106,14 +4180,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createReturnStatement(expression?: Expression): ReturnStatement { const node = createBaseNode(SyntaxKind.ReturnStatement); - node.expression = expression; + const nodeData = node.data; + nodeData.expression = expression; // return in an ES2018 async generator must be awaited - node.transformFlags |= propagateChildFlags(node.expression) | + node.transformFlags |= propagateChildFlags(nodeData.expression) | TransformFlags.ContainsES2018 | TransformFlags.ContainsHoistedDeclarationOrCompletion; - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4127,13 +4202,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.expression = expression; + nodeData.statement = asEmbeddedStatement(statement); + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.statement); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4148,14 +4224,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + nodeData.caseBlock = caseBlock; + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildFlags(nodeData.caseBlock); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) - node.possiblyExhaustive = false; // initialized by binder + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.possiblyExhaustive = false; // initialized by binder return node; } @@ -4170,13 +4247,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.label = asName(label); + nodeData.statement = asEmbeddedStatement(statement); + node.transformFlags |= propagateChildFlags(nodeData.label) | + propagateChildFlags(nodeData.statement); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4191,11 +4269,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createThrowStatement(expression: Expression) { const node = createBaseNode(SyntaxKind.ThrowStatement); - node.expression = expression; - node.transformFlags |= propagateChildFlags(node.expression); + const nodeData = node.data; + nodeData.expression = expression; + node.transformFlags |= propagateChildFlags(nodeData.expression); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4209,15 +4288,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.tryBlock = tryBlock; + nodeData.catchClause = catchClause; + nodeData.finallyBlock = finallyBlock; + node.transformFlags |= propagateChildFlags(nodeData.tryBlock) | + propagateChildFlags(nodeData.catchClause) | + propagateChildFlags(nodeData.finallyBlock); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4233,24 +4313,26 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createDebuggerStatement() { const node = createBaseNode(SyntaxKind.DebuggerStatement); + const nodeData = node.data; - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return 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); + const nodeData = node.data; + nodeData.name = asName(name); + nodeData.exclamationToken = exclamationToken; + nodeData.type = type; + nodeData.initializer = asInitializer(initializer); + node.transformFlags |= propagateNameFlags(nodeData.name) | + propagateChildFlags(nodeData.initializer) | + (nodeData.exclamationToken ?? nodeData.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -4268,7 +4350,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createVariableDeclarationList(declarations: readonly VariableDeclaration[], flags = NodeFlags.None) { const node = createBaseNode(SyntaxKind.VariableDeclarationList); node.flags |= flags & NodeFlags.BlockScoped; - node.declarations = createNodeArray(declarations); + node.data.declarations = createNodeArray(declarations); node.transformFlags |= propagateChildrenFlags(node.declarations) | TransformFlags.ContainsHoistedDeclarationOrCompletion; if (flags & NodeFlags.BlockScoped) { @@ -4299,43 +4381,44 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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) { + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.asteriskToken = asteriskToken; + nodeData.name = asName(name); + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.parameters = createNodeArray(parameters); + nodeData.type = type; + nodeData.body = body; + + if (!nodeData.body || modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; } else { - const isAsync = modifiersToFlags(node.modifiers) & ModifierFlags.Async; - const isGenerator = !!node.asteriskToken; + const isAsync = modifiersToFlags(nodeData.modifiers) & ModifierFlags.Async; + const isGenerator = !!nodeData.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) | + node.transformFlags = propagateChildrenFlags(nodeData.modifiers) | + propagateChildFlags(nodeData.asteriskToken) | + propagateNameFlags(nodeData.name) | + propagateChildrenFlags(nodeData.typeParameters) | + propagateChildrenFlags(nodeData.parameters) | + propagateChildFlags(nodeData.type) | + (propagateChildFlags(nodeData.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | (isAsyncGenerator ? TransformFlags.ContainsES2018 : isAsync ? TransformFlags.ContainsES2017 : isGenerator ? TransformFlags.ContainsGenerator : TransformFlags.None) | - (node.typeParameters || node.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | + (nodeData.typeParameters || nodeData.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; + nodeData.typeArguments = undefined; // used in quick info + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.endFlowNode = undefined; + nodeData.returnFlowNode = undefined; return node; } @@ -4361,11 +4444,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : node; } - function finishUpdateFunctionDeclaration(updated: Mutable, original: FunctionDeclaration) { + function finishUpdateFunctionDeclaration(updated: NodeData, original: FunctionDeclaration) { if (updated !== original) { // copy children used only for error reporting if (updated.modifiers === original.modifiers) { - updated.modifiers = original.modifiers; + updated.data.modifiers = original.modifiers; } } return finishUpdateBaseSignatureDeclaration(updated, original); @@ -4380,29 +4463,30 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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) { + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.name = asName(name); + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.heritageClauses = asNodeArray(heritageClauses); + nodeData.members = createNodeArray(members); + + if (modifiersToFlags(nodeData.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) | + node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | + propagateNameFlags(nodeData.name) | + propagateChildrenFlags(nodeData.typeParameters) | + propagateChildrenFlags(nodeData.heritageClauses) | + propagateChildrenFlags(nodeData.members) | + (nodeData.typeParameters ? TransformFlags.ContainsTypeScript : TransformFlags.None) | TransformFlags.ContainsES2015; if (node.transformFlags & TransformFlags.ContainsTypeScriptClassSyntax) { node.transformFlags |= TransformFlags.ContainsTypeScript; } } - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -4433,14 +4517,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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); + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.name = asName(name); + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.heritageClauses = asNodeArray(heritageClauses); + nodeData.members = createNodeArray(members); node.transformFlags = TransformFlags.ContainsTypeScript; - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -4470,15 +4555,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode, ) { const node = createBaseDeclaration(SyntaxKind.TypeAliasDeclaration); - node.modifiers = asNodeArray(modifiers); - node.name = asName(name); - node.typeParameters = asNodeArray(typeParameters); - node.type = type; + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.name = asName(name); + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.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) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -4505,16 +4591,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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) | + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.name = asName(name); + nodeData.members = createNodeArray(members); + node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | + propagateChildFlags(nodeData.name) | + propagateChildrenFlags(nodeData.members) | TransformFlags.ContainsTypeScript; node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Enum declarations cannot contain `await` - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -4540,24 +4627,25 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode flags = NodeFlags.None, ) { const node = createBaseDeclaration(SyntaxKind.ModuleDeclaration); - node.modifiers = asNodeArray(modifiers); + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); node.flags |= flags & (NodeFlags.Namespace | NodeFlags.NestedNamespace | NodeFlags.GlobalAugmentation); - node.name = name; - node.body = body; - if (modifiersToFlags(node.modifiers) & ModifierFlags.Ambient) { + nodeData.name = name; + nodeData.body = body; + if (modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; } else { - node.transformFlags |= propagateChildrenFlags(node.modifiers) | - propagateChildFlags(node.name) | - propagateChildFlags(node.body) | + node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | + propagateChildFlags(nodeData.name) | + propagateChildFlags(nodeData.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) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -4578,10 +4666,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createModuleBlock(statements: readonly Statement[]) { const node = createBaseNode(SyntaxKind.ModuleBlock); - node.statements = createNodeArray(statements); - node.transformFlags |= propagateChildrenFlags(node.statements); + const nodeData = node.data; + nodeData.statements = createNodeArray(statements); + node.transformFlags |= propagateChildrenFlags(nodeData.statements); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -4595,11 +4684,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createCaseBlock(clauses: readonly CaseOrDefaultClause[]): CaseBlock { const node = createBaseNode(SyntaxKind.CaseBlock); - node.clauses = createNodeArray(clauses); - node.transformFlags |= propagateChildrenFlags(node.clauses); + const nodeData = node.data; + nodeData.clauses = createNodeArray(clauses); + node.transformFlags |= propagateChildrenFlags(nodeData.clauses); - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -4613,12 +4703,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamespaceExportDeclaration(name: string | Identifier) { const node = createBaseDeclaration(SyntaxKind.NamespaceExportDeclaration); - node.name = asName(name); - node.transformFlags |= propagateIdentifierNameFlags(node.name) | + const nodeData = node.data; + nodeData.name = asName(name); + node.transformFlags |= propagateIdentifierNameFlags(nodeData.name) | TransformFlags.ContainsTypeScript; - node.modifiers = undefined; // initialized by parser to report grammar errors - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.modifiers = undefined; // initialized by parser to report grammar errors + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -4629,10 +4720,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : node; } - function finishUpdateNamespaceExportDeclaration(updated: Mutable, original: NamespaceExportDeclaration) { + function finishUpdateNamespaceExportDeclaration(updated: NodeData, original: NamespaceExportDeclaration) { if (updated !== original) { // copy children used only for error reporting - updated.modifiers = original.modifiers; + updated.data.modifiers = original.modifiers; } return update(updated, original); } @@ -4645,21 +4736,22 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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)) { + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.name = asName(name); + nodeData.isTypeOnly = isTypeOnly; + nodeData.moduleReference = moduleReference; + node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | + propagateIdentifierNameFlags(nodeData.name) | + propagateChildFlags(nodeData.moduleReference); + + if (!isExternalModuleReference(nodeData.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) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -4687,15 +4779,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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); + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.importClause = importClause; + nodeData.moduleSpecifier = moduleSpecifier; + nodeData.attributes = nodeData.assertClause = attributes; + node.transformFlags |= propagateChildFlags(nodeData.importClause) | + propagateChildFlags(nodeData.moduleSpecifier); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -4718,11 +4811,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.isTypeOnly = isTypeOnly; + nodeData.name = name; + nodeData.namedBindings = namedBindings; + node.transformFlags |= propagateChildFlags(nodeData.name) | + propagateChildFlags(nodeData.namedBindings); if (isTypeOnly) { node.transformFlags |= TransformFlags.ContainsTypeScript; } @@ -4742,9 +4836,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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; + const nodeData = node.data; + nodeData.elements = createNodeArray(elements); + nodeData.multiLine = multiLine; + nodeData.token = SyntaxKind.AssertKeyword; node.transformFlags |= TransformFlags.ContainsESNext; return node; } @@ -4760,8 +4855,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createAssertEntry(name: AssertionKey, value: Expression): AssertEntry { const node = createBaseNode(SyntaxKind.AssertEntry); - node.name = name; - node.value = value; + const nodeData = node.data; + nodeData.name = name; + nodeData.value = value; node.transformFlags |= TransformFlags.ContainsESNext; return node; } @@ -4777,8 +4873,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createImportTypeAssertionContainer(clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer { const node = createBaseNode(SyntaxKind.ImportTypeAssertionContainer); - node.assertClause = clause; - node.multiLine = multiLine; + const nodeData = node.data; + nodeData.assertClause = clause; + nodeData.multiLine = multiLine; return node; } @@ -4795,9 +4892,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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; + const nodeData = node.data; + nodeData.token = token ?? SyntaxKind.WithKeyword; + nodeData.elements = createNodeArray(elements); + nodeData.multiLine = multiLine; node.transformFlags |= TransformFlags.ContainsESNext; return node; } @@ -4813,8 +4911,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createImportAttribute(name: ImportAttributeName, value: Expression): ImportAttribute { const node = createBaseNode(SyntaxKind.ImportAttribute); - node.name = name; - node.value = value; + const nodeData = node.data; + nodeData.name = name; + nodeData.value = value; node.transformFlags |= TransformFlags.ContainsESNext; return node; } @@ -4830,7 +4929,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamespaceImport(name: Identifier): NamespaceImport { const node = createBaseDeclaration(SyntaxKind.NamespaceImport); - node.name = name; + node.data.name = name; node.transformFlags |= propagateChildFlags(node.name); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; @@ -4846,7 +4945,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamespaceExport(name: ModuleExportName): NamespaceExport { const node = createBaseDeclaration(SyntaxKind.NamespaceExport); - node.name = name; + node.data.name = name; node.transformFlags |= propagateChildFlags(node.name) | TransformFlags.ContainsES2020; node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context @@ -4863,7 +4962,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamedImports(elements: readonly ImportSpecifier[]): NamedImports { const node = createBaseNode(SyntaxKind.NamedImports); - node.elements = createNodeArray(elements); + node.data.elements = createNodeArray(elements); node.transformFlags |= propagateChildrenFlags(node.elements); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; @@ -4879,11 +4978,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.isTypeOnly = isTypeOnly; + nodeData.propertyName = propertyName; + nodeData.name = name; + node.transformFlags |= propagateChildFlags(nodeData.propertyName) | + propagateChildFlags(nodeData.name); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; } @@ -4904,15 +5004,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode expression: Expression, ) { const node = createBaseDeclaration(SyntaxKind.ExportAssignment); - node.modifiers = asNodeArray(modifiers); - node.isExportEquals = isExportEquals; - node.expression = isExportEquals + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.isExportEquals = isExportEquals; + nodeData.expression = isExportEquals ? parenthesizerRules().parenthesizeRightSideOfBinary(SyntaxKind.EqualsToken, /*leftSide*/ undefined, expression) : parenthesizerRules().parenthesizeExpressionOfExportDefault(expression); - node.transformFlags |= propagateChildrenFlags(node.modifiers) | propagateChildFlags(node.expression); + node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateChildFlags(nodeData.expression); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -4937,17 +5038,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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); + const nodeData = node.data; + nodeData.modifiers = asNodeArray(modifiers); + nodeData.isTypeOnly = isTypeOnly; + nodeData.exportClause = exportClause; + nodeData.moduleSpecifier = moduleSpecifier; + nodeData.attributes = nodeData.assertClause = attributes; + node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | + propagateChildFlags(nodeData.exportClause) | + propagateChildFlags(nodeData.moduleSpecifier); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -4969,11 +5071,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : node; } - function finishUpdateExportDeclaration(updated: Mutable, original: ExportDeclaration) { + function finishUpdateExportDeclaration(updated: NodeData, original: ExportDeclaration) { if (updated !== original) { // copy children used only for error reporting if (updated.modifiers === original.modifiers) { - updated.modifiers = original.modifiers; + updated.data.modifiers = original.modifiers; } } return update(updated, original); @@ -4982,7 +5084,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamedExports(elements: readonly ExportSpecifier[]) { const node = createBaseNode(SyntaxKind.NamedExports); - node.elements = createNodeArray(elements); + node.data.elements = createNodeArray(elements); node.transformFlags |= propagateChildrenFlags(node.elements); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; @@ -4998,14 +5100,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.isTypeOnly = isTypeOnly; + nodeData.propertyName = asName(propertyName); + nodeData.name = asName(name); + node.transformFlags |= propagateChildFlags(nodeData.propertyName) | + propagateChildFlags(nodeData.name); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -5022,7 +5125,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createMissingDeclaration(): MissingDeclaration { const node = createBaseDeclaration(SyntaxKind.MissingDeclaration); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + node.data.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -5033,7 +5136,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createExternalModuleReference(expression: Expression) { const node = createBaseNode(SyntaxKind.ExternalModuleReference); - node.expression = expression; + node.data.expression = expression; node.transformFlags |= propagateChildFlags(node.expression); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; @@ -5064,8 +5167,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createJSDocUnaryTypeWorker( kind, postfix ? type && parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(type) : type, - ) as Mutable; - node.postfix = postfix; + ); + (node as unknown as NodeData).data.postfix = postfix; return node; } @@ -5075,8 +5178,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // createJSDocNamepathType function createJSDocUnaryTypeWorker(kind: T["kind"], type: T["type"]): T { const node = createBaseNode(kind); - node.type = type; - return node; + node.data.type = type; + return node as unknown as T; } // @api @@ -5101,15 +5204,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.parameters = asNodeArray(parameters); + nodeData.type = type; + node.transformFlags = propagateChildrenFlags(nodeData.parameters) | + (nodeData.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 + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.typeArguments = undefined; // used in quick info return node; } @@ -5124,8 +5228,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocTypeLiteral(propertyTags?: readonly JSDocPropertyLikeTag[], isArrayType = false): JSDocTypeLiteral { const node = createBaseDeclaration(SyntaxKind.JSDocTypeLiteral); - node.jsDocPropertyTags = asNodeArray(propertyTags); - node.isArrayType = isArrayType; + const nodeData = node.data; + nodeData.jsDocPropertyTags = asNodeArray(propertyTags); + nodeData.isArrayType = isArrayType; return node; } @@ -5140,7 +5245,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocTypeExpression(type: TypeNode): JSDocTypeExpression { const node = createBaseNode(SyntaxKind.JSDocTypeExpression); - node.type = type; + node.data.type = type; return node; } @@ -5154,13 +5259,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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; + const nodeData = node.data; + nodeData.typeParameters = asNodeArray(typeParameters); + nodeData.parameters = createNodeArray(parameters); + nodeData.type = type; - node.jsDoc = undefined; // initialized by parser (JsDocContainer) - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -5183,23 +5289,26 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBaseJSDocTag(kind: T["kind"], tagName: Identifier, comment: string | NodeArray | undefined) { const node = createBaseNode(kind); - node.tagName = tagName; - node.comment = comment; + const nodeData = node.data; + nodeData.tagName = tagName; + nodeData.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; + const nodeData = node.data; + nodeData.tagName = tagName; + nodeData.comment = comment; return 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); + const nodeData = node.data; + nodeData.constraint = constraint; + nodeData.typeParameters = createNodeArray(typeParameters); return node; } @@ -5216,12 +5325,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.typeExpression = typeExpression; + nodeData.fullName = fullName; + nodeData.name = getJSDocTypeAliasName(fullName); - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -5238,10 +5348,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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; + const nodeData = node.data; + nodeData.typeExpression = typeExpression; + nodeData.name = name; + nodeData.isNameFirst = !!isNameFirst; + nodeData.isBracketed = isBracketed; return node; } @@ -5260,10 +5371,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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; + const nodeData = node.data; + nodeData.typeExpression = typeExpression; + nodeData.name = name; + nodeData.isNameFirst = !!isNameFirst; + nodeData.isBracketed = isBracketed; return node; } @@ -5282,12 +5394,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.typeExpression = typeExpression; + nodeData.fullName = fullName; + nodeData.name = getJSDocTypeAliasName(fullName); - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -5304,7 +5417,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocOverloadTag(tagName: Identifier | undefined, typeExpression: JSDocSignature, comment?: string | NodeArray): JSDocOverloadTag { const node = createBaseJSDocTag(SyntaxKind.JSDocOverloadTag, tagName ?? createIdentifier("overload"), comment); - node.typeExpression = typeExpression; + node.data.typeExpression = typeExpression; return node; } @@ -5320,7 +5433,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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; + node.data.class = className; return node; } @@ -5336,14 +5449,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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; + node.data.class = className; return 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; + node.data.name = name; return node; } @@ -5359,7 +5472,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocNameReference(name: EntityName | JSDocMemberName): JSDocNameReference { const node = createBaseNode(SyntaxKind.JSDocNameReference); - node.name = name; + node.data.name = name; return node; } @@ -5373,8 +5486,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocMemberName(left: EntityName | JSDocMemberName, right: Identifier) { const node = createBaseNode(SyntaxKind.JSDocMemberName); - node.left = left; - node.right = right; + const nodeData = node.data; + nodeData.left = left; + nodeData.right = right; node.transformFlags |= propagateChildFlags(node.left) | propagateChildFlags(node.right); return node; @@ -5391,8 +5505,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocLink(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLink { const node = createBaseNode(SyntaxKind.JSDocLink); - node.name = name; - node.text = text; + const nodeData = node.data; + nodeData.name = name; + nodeData.text = text; return node; } @@ -5406,8 +5521,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocLinkCode(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkCode { const node = createBaseNode(SyntaxKind.JSDocLinkCode); - node.name = name; - node.text = text; + const nodeData = node.data; + nodeData.name = name; + nodeData.text = text; return node; } @@ -5421,8 +5537,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocLinkPlain(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkPlain { const node = createBaseNode(SyntaxKind.JSDocLinkPlain); - node.name = name; - node.text = text; + const nodeData = node.data; + nodeData.name = name; + nodeData.text = text; return node; } @@ -5450,9 +5567,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // createJSDocProtectedTag // createJSDocReadonlyTag // createJSDocDeprecatedTag - function createJSDocSimpleTagWorker(kind: T["kind"], tagName: Identifier | undefined, comment?: string | NodeArray) { + function createJSDocSimpleTagWorker(kind: T["kind"], tagName: Identifier | undefined, comment?: string | NodeArray): T { const node = createBaseJSDocTag(kind, tagName ?? createIdentifier(getDefaultTagNameForKind(kind)), comment); - return node; + return node as unknown as T; } // @api @@ -5478,7 +5595,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // 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; + node.data.typeExpression = typeExpression; return node; } @@ -5492,7 +5609,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode return node.tagName !== tagName || node.typeExpression !== typeExpression || node.comment !== comment - ? update(createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment), node) + ? update(createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment), node as unknown as NodeData) : node; } @@ -5513,10 +5630,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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; + const nodeData = node.data; + nodeData.typeExpression = typeExpression; - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -5532,10 +5650,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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; + const nodeData = node.data; + nodeData.importClause = importClause; + nodeData.moduleSpecifier = moduleSpecifier; + nodeData.attributes = attributes; + nodeData.comment = comment; return node; } @@ -5552,7 +5671,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocText(text: string): JSDocText { const node = createBaseNode(SyntaxKind.JSDocText); - node.text = text; + node.data.text = text; return node; } @@ -5566,8 +5685,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocComment(comment?: string | NodeArray | undefined, tags?: readonly JSDocTag[] | undefined) { const node = createBaseNode(SyntaxKind.JSDoc); - node.comment = comment; - node.tags = asNodeArray(tags); + const nodeData = node.data; + nodeData.comment = comment; + nodeData.tags = asNodeArray(tags); return node; } @@ -5586,12 +5706,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) | + const nodeData = node.data; + nodeData.openingElement = openingElement; + nodeData.children = createNodeArray(children); + nodeData.closingElement = closingElement; + node.transformFlags |= propagateChildFlags(nodeData.openingElement) | + propagateChildrenFlags(nodeData.children) | + propagateChildFlags(nodeData.closingElement) | TransformFlags.ContainsJsx; return node; } @@ -5608,14 +5729,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) | + const nodeData = node.data; + nodeData.tagName = tagName; + nodeData.typeArguments = asNodeArray(typeArguments); + nodeData.attributes = attributes; + node.transformFlags |= propagateChildFlags(nodeData.tagName) | + propagateChildrenFlags(nodeData.typeArguments) | + propagateChildFlags(nodeData.attributes) | TransformFlags.ContainsJsx; - if (node.typeArguments) { + if (nodeData.typeArguments) { node.transformFlags |= TransformFlags.ContainsTypeScript; } return node; @@ -5633,12 +5755,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) | + const nodeData = node.data; + nodeData.tagName = tagName; + nodeData.typeArguments = asNodeArray(typeArguments); + nodeData.attributes = attributes; + node.transformFlags |= propagateChildFlags(nodeData.tagName) | + propagateChildrenFlags(nodeData.typeArguments) | + propagateChildFlags(nodeData.attributes) | TransformFlags.ContainsJsx; if (typeArguments) { node.transformFlags |= TransformFlags.ContainsTypeScript; @@ -5658,7 +5781,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxClosingElement(tagName: JsxTagNameExpression) { const node = createBaseNode(SyntaxKind.JsxClosingElement); - node.tagName = tagName; + node.data.tagName = tagName; node.transformFlags |= propagateChildFlags(node.tagName) | TransformFlags.ContainsJsx; return node; @@ -5674,12 +5797,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) | + const nodeData = node.data; + nodeData.openingFragment = openingFragment; + nodeData.children = createNodeArray(children); + nodeData.closingFragment = closingFragment; + node.transformFlags |= propagateChildFlags(nodeData.openingFragment) | + propagateChildrenFlags(nodeData.children) | + propagateChildFlags(nodeData.closingFragment) | TransformFlags.ContainsJsx; return node; } @@ -5696,8 +5820,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxText(text: string, containsOnlyTriviaWhiteSpaces?: boolean) { const node = createBaseNode(SyntaxKind.JsxText); - node.text = text; - node.containsOnlyTriviaWhiteSpaces = !!containsOnlyTriviaWhiteSpaces; + const nodeData = node.data; + nodeData.text = text; + nodeData.containsOnlyTriviaWhiteSpaces = !!containsOnlyTriviaWhiteSpaces; node.transformFlags |= TransformFlags.ContainsJsx; return node; } @@ -5727,8 +5852,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxAttribute(name: JsxAttributeName, initializer: JsxAttributeValue | undefined) { const node = createBaseDeclaration(SyntaxKind.JsxAttribute); - node.name = name; - node.initializer = initializer; + const nodeData = node.data; + nodeData.name = name; + nodeData.initializer = initializer; node.transformFlags |= propagateChildFlags(node.name) | propagateChildFlags(node.initializer) | TransformFlags.ContainsJsx; @@ -5746,7 +5872,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxAttributes(properties: readonly JsxAttributeLike[]) { const node = createBaseDeclaration(SyntaxKind.JsxAttributes); - node.properties = createNodeArray(properties); + node.data.properties = createNodeArray(properties); node.transformFlags |= propagateChildrenFlags(node.properties) | TransformFlags.ContainsJsx; return node; @@ -5762,7 +5888,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxSpreadAttribute(expression: Expression) { const node = createBaseNode(SyntaxKind.JsxSpreadAttribute); - node.expression = expression; + node.data.expression = expression; node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsJsx; return node; @@ -5778,8 +5904,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxExpression(dotDotDotToken: DotDotDotToken | undefined, expression: Expression | undefined) { const node = createBaseNode(SyntaxKind.JsxExpression); - node.dotDotDotToken = dotDotDotToken; - node.expression = expression; + const nodeData = node.data; + nodeData.dotDotDotToken = dotDotDotToken; + nodeData.expression = expression; node.transformFlags |= propagateChildFlags(node.dotDotDotToken) | propagateChildFlags(node.expression) | TransformFlags.ContainsJsx; @@ -5796,8 +5923,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxNamespacedName(namespace: Identifier, name: Identifier) { const node = createBaseNode(SyntaxKind.JsxNamespacedName); - node.namespace = namespace; - node.name = name; + const nodeData = node.data; + nodeData.namespace = namespace; + nodeData.name = name; node.transformFlags |= propagateChildFlags(node.namespace) | propagateChildFlags(node.name) | TransformFlags.ContainsJsx; @@ -5819,12 +5947,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + nodeData.statements = createNodeArray(statements); + node.transformFlags |= propagateChildFlags(nodeData.expression) | + propagateChildrenFlags(nodeData.statements); - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -5839,7 +5968,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createDefaultClause(statements: readonly Statement[]) { const node = createBaseNode(SyntaxKind.DefaultClause); - node.statements = createNodeArray(statements); + node.data.statements = createNodeArray(statements); node.transformFlags = propagateChildrenFlags(node.statements); return node; } @@ -5854,8 +5983,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createHeritageClause(token: HeritageClause["token"], types: readonly ExpressionWithTypeArguments[]) { const node = createBaseNode(SyntaxKind.HeritageClause); - node.token = token; - node.types = createNodeArray(types); + const nodeData = node.data; + nodeData.token = token; + nodeData.types = createNodeArray(types); node.transformFlags |= propagateChildrenFlags(node.types); switch (token) { case SyntaxKind.ExtendsKeyword: @@ -5880,15 +6010,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createCatchClause(variableDeclaration: string | BindingName | VariableDeclaration | undefined, block: Block) { const node = createBaseNode(SyntaxKind.CatchClause); - node.variableDeclaration = asVariableDeclaration(variableDeclaration); - node.block = block; + const nodeData = node.data; + nodeData.variableDeclaration = asVariableDeclaration(variableDeclaration); + nodeData.block = block; - node.transformFlags |= propagateChildFlags(node.variableDeclaration) | - propagateChildFlags(node.block) | + node.transformFlags |= propagateChildFlags(nodeData.variableDeclaration) | + propagateChildFlags(nodeData.block) | (!variableDeclaration ? TransformFlags.ContainsES2019 : TransformFlags.None); - node.locals = undefined; // initialized by binder (LocalsContainer) - node.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -5907,15 +6038,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); + const nodeData = node.data; + nodeData.name = asName(name); + nodeData.initializer = parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer); + node.transformFlags |= propagateNameFlags(nodeData.name) | + propagateChildFlags(nodeData.initializer); - 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) + nodeData.modifiers = undefined; // initialized by parser to report grammar errors + nodeData.questionToken = undefined; // initialized by parser to report grammar errors + nodeData.exclamationToken = undefined; // initialized by parser to report grammar errors + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -5927,13 +6059,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : node; } - function finishUpdatePropertyAssignment(updated: Mutable, original: PropertyAssignment) { + function finishUpdatePropertyAssignment(updated: NodeData, 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; + updated.data.modifiers = original.modifiers; + updated.data.questionToken = original.questionToken; + updated.data.exclamationToken = original.exclamationToken; } return update(updated, original); } @@ -5941,17 +6073,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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) | + const nodeData = node.data; + nodeData.name = asName(name); + nodeData.objectAssignmentInitializer = objectAssignmentInitializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(objectAssignmentInitializer); + node.transformFlags |= propagateIdentifierNameFlags(nodeData.name) | + propagateChildFlags(nodeData.objectAssignmentInitializer) | TransformFlags.ContainsES2015; - 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) + nodeData.equalsToken = undefined; // initialized by parser to report grammar errors + nodeData.modifiers = undefined; // initialized by parser to report grammar errors + nodeData.questionToken = undefined; // initialized by parser to report grammar errors + nodeData.exclamationToken = undefined; // initialized by parser to report grammar errors + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -5963,13 +6096,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : node; } - function finishUpdateShorthandPropertyAssignment(updated: Mutable, original: ShorthandPropertyAssignment) { + function finishUpdateShorthandPropertyAssignment(updated: NodeData, 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; + updated.data.modifiers = original.modifiers; + updated.data.questionToken = original.questionToken; + updated.data.exclamationToken = original.exclamationToken; + updated.data.equalsToken = original.equalsToken; } return update(updated, original); } @@ -5977,12 +6110,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createSpreadAssignment(expression: Expression) { const node = createBaseDeclaration(SyntaxKind.SpreadAssignment); - node.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + const nodeData = node.data; + nodeData.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsES2018 | TransformFlags.ContainsObjectRestOrSpread; - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -6000,13 +6134,14 @@ 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); + const nodeData = node.data; + nodeData.name = asName(name); + nodeData.initializer = initializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer); node.transformFlags |= propagateChildFlags(node.name) | propagateChildFlags(node.initializer) | TransformFlags.ContainsTypeScript; - node.jsDoc = undefined; // initialized by parser (JsDocContainer) + nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -6028,52 +6163,53 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode endOfFileToken: EndOfFileToken, flags: NodeFlags, ) { - const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as Mutable; - node.statements = createNodeArray(statements); - node.endOfFileToken = endOfFileToken; + const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as NodeData; + const nodeData = node.data; + nodeData.statements = createNodeArray(statements); + nodeData.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; + nodeData.text = ""; + nodeData.fileName = ""; + nodeData.path = "" as Path; + nodeData.resolvedPath = "" as Path; + nodeData.originalFileName = ""; + nodeData.languageVersion = ScriptTarget.ES5; + nodeData.languageVariant = 0; + nodeData.scriptKind = 0; + nodeData.isDeclarationFile = false; + nodeData.hasNoDefaultLib = false; + + node.transformFlags |= propagateChildrenFlags(nodeData.statements) | + propagateChildFlags(nodeData.endOfFileToken); + + nodeData.locals = undefined; // initialized by binder (LocalsContainer) + nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + nodeData.endFlowNode = undefined; + + nodeData.nodeCount = 0; + nodeData.identifierCount = 0; + nodeData.symbolCount = 0; + nodeData.parseDiagnostics = undefined!; + nodeData.bindDiagnostics = undefined!; + nodeData.bindSuggestionDiagnostics = undefined; + nodeData.lineMap = undefined!; + nodeData.externalModuleIndicator = undefined; + nodeData.setExternalModuleIndicator = undefined; + nodeData.pragmas = undefined!; + nodeData.checkJsDirective = undefined; + nodeData.referencedFiles = undefined!; + nodeData.typeReferenceDirectives = undefined!; + nodeData.libReferenceDirectives = undefined!; + nodeData.amdDependencies = undefined!; + nodeData.commentDirectives = undefined; + nodeData.identifiers = undefined!; + nodeData.packageJsonLocations = undefined; + nodeData.packageJsonScope = undefined; + nodeData.imports = undefined!; + nodeData.moduleAugmentations = undefined!; + nodeData.ambientModuleNames = undefined!; + nodeData.classifiableNames = undefined; + nodeData.impliedNodeFormat = undefined; return node; } @@ -6106,14 +6242,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } function cloneRedirectedSourceFile(source: SourceFile) { - const node = createRedirectedSourceFile(source.redirectInfo!) as Mutable; + const node = createRedirectedSourceFile(source.redirectInfo!) as NodeData; + const nodeData = node.data; 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; + nodeData.fileName = source.fileName; + nodeData.path = source.path; + nodeData.resolvedPath = source.resolvedPath; + nodeData.originalFileName = source.originalFileName; + nodeData.packageJsonLocations = source.packageJsonLocations; + nodeData.packageJsonScope = source.packageJsonScope; node.emitNode = undefined; return node; } @@ -6121,7 +6258,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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; + const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as NodeData; node.flags |= source.flags & ~NodeFlags.Synthesized; const sourceData = (source as any).data ?? source; const nodeData = (node as any).data ?? node; @@ -6154,14 +6291,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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); + const nodeData = node.data; + nodeData.statements = createNodeArray(statements); + nodeData.isDeclarationFile = isDeclarationFile; + nodeData.referencedFiles = referencedFiles; + nodeData.typeReferenceDirectives = typeReferences; + nodeData.hasNoDefaultLib = hasNoDefaultLib; + nodeData.libReferenceDirectives = libReferences; + node.transformFlags = propagateChildrenFlags(nodeData.statements) | + propagateChildFlags(nodeData.endOfFileToken); return node; } @@ -6188,11 +6326,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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; + const nodeData = node.data; + nodeData.sourceFiles = sourceFiles; + nodeData.syntheticFileReferences = undefined; + nodeData.syntheticTypeReferences = undefined; + nodeData.syntheticLibReferences = undefined; + nodeData.hasNoDefaultLib = undefined; return node; } @@ -6210,9 +6349,10 @@ 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; + const nodeData = node.data; + nodeData.type = type; + nodeData.isSpread = isSpread; + nodeData.tupleNameSource = tupleNameSource; return node; } @@ -6236,7 +6376,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNotEmittedStatement(original: Node) { const node = createBaseNode(SyntaxKind.NotEmittedStatement); - node.original = original; + (node as Mutable).original = original; setTextRange(node, original); return node; } @@ -6251,9 +6391,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createPartiallyEmittedExpression(expression: Expression, original?: Node) { const node = createBaseNode(SyntaxKind.PartiallyEmittedExpression); - node.expression = expression; + const nodeData = node.data; + nodeData.expression = expression; node.original = original; - node.transformFlags |= propagateChildFlags(node.expression) | + node.transformFlags |= propagateChildFlags(nodeData.expression) | TransformFlags.ContainsTypeScript; setTextRange(node, original); return node; @@ -6281,7 +6422,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createCommaListExpression(elements: readonly Expression[]) { const node = createBaseNode(SyntaxKind.CommaListExpression); - node.elements = createNodeArray(sameFlatMap(elements, flattenCommaElements)); + node.data.elements = createNodeArray(sameFlatMap(elements, flattenCommaElements)); node.transformFlags |= propagateChildrenFlags(node.elements); return node; } @@ -6296,8 +6437,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createSyntheticReferenceExpression(expression: Expression, thisArg: Expression) { const node = createBaseNode(SyntaxKind.SyntheticReferenceExpression); - node.expression = expression; - node.thisArg = thisArg; + const nodeData = node.data; + nodeData.expression = expression; + nodeData.thisArg = thisArg; node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.thisArg); return node; @@ -6312,20 +6454,21 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } function cloneGeneratedIdentifier(node: GeneratedIdentifier): GeneratedIdentifier { - const clone = createBaseIdentifier(node.escapedText) as Mutable; + const clone = createBaseIdentifier(node.escapedText) as NodeData; clone.flags |= node.flags & ~NodeFlags.Synthesized; clone.transformFlags = node.transformFlags; setOriginal(clone, node); setIdentifierAutoGenerate(clone, { ...node.emitNode.autoGenerate }); - return clone; + return clone as GeneratedIdentifier; } function cloneIdentifier(node: Identifier): Identifier { const clone = createBaseIdentifier(node.escapedText); + const cloneData = clone.data; clone.flags |= node.flags & ~NodeFlags.Synthesized; - clone.jsDoc = node.jsDoc; - clone.flowNode = node.flowNode; - clone.symbol = node.symbol; + cloneData.jsDoc = node.jsDoc; + cloneData.flowNode = node.flowNode; + cloneData.symbol = node.symbol; clone.transformFlags = node.transformFlags; setOriginal(clone, node); @@ -6336,12 +6479,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } function cloneGeneratedPrivateIdentifier(node: GeneratedPrivateIdentifier): GeneratedPrivateIdentifier { - const clone = createBasePrivateIdentifier(node.escapedText) as Mutable; + const clone = createBasePrivateIdentifier(node.escapedText) as NodeData; clone.flags |= node.flags & ~NodeFlags.Synthesized; clone.transformFlags = node.transformFlags; setOriginal(clone, node); setIdentifierAutoGenerate(clone, { ...node.emitNode.autoGenerate }); - return clone; + return clone as GeneratedPrivateIdentifier; } function clonePrivateIdentifier(node: PrivateIdentifier): PrivateIdentifier { @@ -6362,7 +6505,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode return node; } if (isSourceFile(node)) { - return cloneSourceFile(node) as T & SourceFile; + return cloneSourceFile(node) as SourceFile as T & SourceFile; } if (isGeneratedIdentifier(node)) { return cloneGeneratedIdentifier(node) as T & GeneratedIdentifier; @@ -6380,8 +6523,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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; + (clone as unknown as NodeData).flags |= node.flags & ~NodeFlags.Synthesized; + (clone as unknown as NodeData).transformFlags = node.transformFlags; setOriginal(clone, node); const nodeData = (node as any).data ?? node; const cloneData = (clone as any).data ?? clone; @@ -6396,7 +6539,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // compound nodes function createImmediatelyInvokedFunctionExpression(statements: readonly Statement[]): ImmediatelyInvokedFunctionExpression; function createImmediatelyInvokedFunctionExpression(statements: readonly Statement[], param: ParameterDeclaration, paramValue: Expression): ImmediatelyInvokedFunctionExpression; - function createImmediatelyInvokedFunctionExpression(statements: readonly Statement[], param?: ParameterDeclaration, paramValue?: Expression) { + function createImmediatelyInvokedFunctionExpression(statements: readonly Statement[], param?: ParameterDeclaration, paramValue?: Expression): CallExpression { return createCallExpression( createFunctionExpression( /*modifiers*/ undefined, @@ -6414,7 +6557,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createImmediatelyInvokedArrowFunction(statements: readonly Statement[]): ImmediatelyInvokedArrowFunction; function createImmediatelyInvokedArrowFunction(statements: readonly Statement[], param: ParameterDeclaration, paramValue: Expression): ImmediatelyInvokedArrowFunction; - function createImmediatelyInvokedArrowFunction(statements: readonly Statement[], param?: ParameterDeclaration, paramValue?: Expression) { + function createImmediatelyInvokedArrowFunction(statements: readonly Statement[], param?: ParameterDeclaration, paramValue?: Expression): CallExpression { return createCallExpression( createArrowFunction( /*modifiers*/ undefined, @@ -7160,7 +7303,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode return variableDeclaration; } - function update(updated: Mutable, original: T): T { + function update(updated: T, original: T): T { if (updated !== original) { setOriginal(updated, original); setTextRange(updated, original); @@ -7378,7 +7521,7 @@ export function getTransformFlagsSubtreeExclusions(kind: SyntaxKind) { const baseFactory = createBaseNodeFactory(); function makeSynthetic(node: Node) { - (node as Mutable).flags |= NodeFlags.Synthesized; + (node as NodeData).flags |= NodeFlags.Synthesized; return node; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 67cb1b5867837..d1f736b7cbf27 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -8282,7 +8282,7 @@ export class TypeImpl { checker: TypeChecker; flags: TypeFlags; symbol: Symbol; - _data: any; + data: any; id: number; objectFlags: number; constructor(checker: TypeChecker, flags: TypeFlags) { @@ -8290,739 +8290,736 @@ export class TypeImpl { this.checker = checker; this.flags = flags; this.symbol = undefined!; - this._data = undefined; this.objectFlags = 0; + this.data = new TypeDataImpl(); } - get data() { - return this._data ??= new TypeDataImpl(); - } get pattern() { - return this._data?.pattern; + return this.data.pattern; } set pattern(value: any) { this.data.pattern = value; } get aliasSymbol() { - return this._data?.aliasSymbol; + return this.data.aliasSymbol; } set aliasSymbol(value: any) { this.data.aliasSymbol = value; } get aliasTypeArguments() { - return this._data?.aliasTypeArguments; + return this.data.aliasTypeArguments; } set aliasTypeArguments(value: any) { this.data.aliasTypeArguments = value; } get permissiveInstantiation() { - return this._data?.permissiveInstantiation; + return this.data.permissiveInstantiation; } set permissiveInstantiation(value: any) { this.data.permissiveInstantiation = value; } get restrictiveInstantiation() { - return this._data?.restrictiveInstantiation; + return this.data.restrictiveInstantiation; } set restrictiveInstantiation(value: any) { this.data.restrictiveInstantiation = value; } get immediateBaseConstraint() { - return this._data?.immediateBaseConstraint; + return this.data.immediateBaseConstraint; } set immediateBaseConstraint(value: any) { this.data.immediateBaseConstraint = value; } get widened() { - return this._data?.widened; + return this.data.widened; } set widened(value: any) { this.data.widened = value; } get intrinsicName() { - return this._data?.intrinsicName; + return this.data.intrinsicName; } set intrinsicName(value: any) { this.data.intrinsicName = value; } get debugIntrinsicName() { - return this._data?.debugIntrinsicName; + return this.data.debugIntrinsicName; } set debugIntrinsicName(value: any) { this.data.debugIntrinsicName = value; } - // get objectFlags() { return this._data?.objectFlags; } + // get objectFlags() { return this.data.objectFlags; } // set objectFlags(value: any) { this.data.objectFlags = value } get freshType() { - return this._data?.freshType; + return this.data.freshType; } set freshType(value: any) { this.data.freshType = value; } get regularType() { - return this._data?.regularType; + return this.data.regularType; } set regularType(value: any) { this.data.regularType = value; } get value() { - return this._data?.value; + return this.data.value; } set value(value: any) { this.data.value = value; } get escapedName() { - return this._data?.escapedName; + return this.data.escapedName; } set escapedName(value: any) { this.data.escapedName = value; } get members() { - return this._data?.members; + return this.data.members; } set members(value: any) { this.data.members = value; } get properties() { - return this._data?.properties; + return this.data.properties; } set properties(value: any) { this.data.properties = value; } get callSignatures() { - return this._data?.callSignatures; + return this.data.callSignatures; } set callSignatures(value: any) { this.data.callSignatures = value; } get constructSignatures() { - return this._data?.constructSignatures; + return this.data.constructSignatures; } set constructSignatures(value: any) { this.data.constructSignatures = value; } get indexInfos() { - return this._data?.indexInfos; + return this.data.indexInfos; } set indexInfos(value: any) { this.data.indexInfos = value; } get objectTypeWithoutAbstractConstructSignatures() { - return this._data?.objectTypeWithoutAbstractConstructSignatures; + return this.data.objectTypeWithoutAbstractConstructSignatures; } set objectTypeWithoutAbstractConstructSignatures(value: any) { this.data.objectTypeWithoutAbstractConstructSignatures = value; } get typeParameters() { - return this._data?.typeParameters; + return this.data.typeParameters; } set typeParameters(value: any) { this.data.typeParameters = value; } get outerTypeParameters() { - return this._data?.outerTypeParameters; + return this.data.outerTypeParameters; } set outerTypeParameters(value: any) { this.data.outerTypeParameters = value; } get localTypeParameters() { - return this._data?.localTypeParameters; + return this.data.localTypeParameters; } set localTypeParameters(value: any) { this.data.localTypeParameters = value; } get thisType() { - return this._data?.thisType; + return this.data.thisType; } set thisType(value: any) { this.data.thisType = value; } get resolvedBaseConstructorType() { - return this._data?.resolvedBaseConstructorType; + return this.data.resolvedBaseConstructorType; } set resolvedBaseConstructorType(value: any) { this.data.resolvedBaseConstructorType = value; } get resolvedBaseTypes() { - return this._data?.resolvedBaseTypes; + return this.data.resolvedBaseTypes; } set resolvedBaseTypes(value: any) { this.data.resolvedBaseTypes = value; } get baseTypesResolved() { - return this._data?.baseTypesResolved; + return this.data.baseTypesResolved; } set baseTypesResolved(value: any) { this.data.baseTypesResolved = value; } get declaredProperties() { - return this._data?.declaredProperties; + return this.data.declaredProperties; } set declaredProperties(value: any) { this.data.declaredProperties = value; } get declaredCallSignatures() { - return this._data?.declaredCallSignatures; + return this.data.declaredCallSignatures; } set declaredCallSignatures(value: any) { this.data.declaredCallSignatures = value; } get declaredConstructSignatures() { - return this._data?.declaredConstructSignatures; + return this.data.declaredConstructSignatures; } set declaredConstructSignatures(value: any) { this.data.declaredConstructSignatures = value; } get declaredIndexInfos() { - return this._data?.declaredIndexInfos; + return this.data.declaredIndexInfos; } set declaredIndexInfos(value: any) { this.data.declaredIndexInfos = value; } get instantiations() { - return this._data?.instantiations; + return this.data.instantiations; } set instantiations(value: any) { this.data.instantiations = value; } get variances() { - return this._data?.variances; + return this.data.variances; } set variances(value: any) { this.data.variances = value; } get target() { - return this._data?.target; + return this.data.target; } set target(value: any) { this.data.target = value; } get node() { - return this._data?.node; + return this.data.node; } set node(value: any) { this.data.node = value; } get mapper() { - return this._data?.mapper; + return this.data.mapper; } set mapper(value: any) { this.data.mapper = value; } get resolvedTypeArguments() { - return this._data?.resolvedTypeArguments; + return this.data.resolvedTypeArguments; } set resolvedTypeArguments(value: any) { this.data.resolvedTypeArguments = value; } get literalType() { - return this._data?.literalType; + return this.data.literalType; } set literalType(value: any) { this.data.literalType = value; } get cachedEquivalentBaseType() { - return this._data?.cachedEquivalentBaseType; + return this.data.cachedEquivalentBaseType; } set cachedEquivalentBaseType(value: any) { this.data.cachedEquivalentBaseType = value; } get elementFlags() { - return this._data?.elementFlags; + return this.data.elementFlags; } set elementFlags(value: any) { this.data.elementFlags = value; } get minLength() { - return this._data?.minLength; + return this.data.minLength; } set minLength(value: any) { this.data.minLength = value; } get fixedLength() { - return this._data?.fixedLength; + return this.data.fixedLength; } set fixedLength(value: any) { this.data.fixedLength = value; } get hasRestElement() { - return this._data?.hasRestElement; + return this.data.hasRestElement; } set hasRestElement(value: any) { this.data.hasRestElement = value; } get combinedFlags() { - return this._data?.combinedFlags; + return this.data.combinedFlags; } set combinedFlags(value: any) { this.data.combinedFlags = value; } get readonly() { - return this._data?.readonly; + return this.data.readonly; } set readonly(value: any) { this.data.readonly = value; } get labeledElementDeclarations() { - return this._data?.labeledElementDeclarations; + return this.data.labeledElementDeclarations; } set labeledElementDeclarations(value: any) { this.data.labeledElementDeclarations = value; } get declaration() { - return this._data?.declaration; + return this.data.declaration; } set declaration(value: any) { this.data.declaration = value; } get typeParameter() { - return this._data?.typeParameter; + return this.data.typeParameter; } set typeParameter(value: any) { this.data.typeParameter = value; } get constraintType() { - return this._data?.constraintType; + return this.data.constraintType; } set constraintType(value: any) { this.data.constraintType = value; } get nameType() { - return this._data?.nameType; + return this.data.nameType; } set nameType(value: any) { this.data.nameType = value; } get templateType() { - return this._data?.templateType; + return this.data.templateType; } set templateType(value: any) { this.data.templateType = value; } get modifiersType() { - return this._data?.modifiersType; + return this.data.modifiersType; } set modifiersType(value: any) { this.data.modifiersType = value; } get resolvedApparentType() { - return this._data?.resolvedApparentType; + return this.data.resolvedApparentType; } set resolvedApparentType(value: any) { this.data.resolvedApparentType = value; } get containsError() { - return this._data?.containsError; + return this.data.containsError; } set containsError(value: any) { this.data.containsError = value; } get elementType() { - return this._data?.elementType; + return this.data.elementType; } set elementType(value: any) { this.data.elementType = value; } get finalArrayType() { - return this._data?.finalArrayType; + return this.data.finalArrayType; } set finalArrayType(value: any) { this.data.finalArrayType = value; } get source() { - return this._data?.source; + return this.data.source; } set source(value: any) { this.data.source = value; } get mappedType() { - return this._data?.mappedType; + return this.data.mappedType; } set mappedType(value: any) { this.data.mappedType = value; } get types() { - return this._data?.types; + return this.data.types; } set types(value: any) { this.data.types = value; } get propertyCache() { - return this._data?.propertyCache; + return this.data.propertyCache; } set propertyCache(value: any) { this.data.propertyCache = value; } get propertyCacheWithoutObjectFunctionPropertyAugment() { - return this._data?.propertyCacheWithoutObjectFunctionPropertyAugment; + return this.data.propertyCacheWithoutObjectFunctionPropertyAugment; } set propertyCacheWithoutObjectFunctionPropertyAugment(value: any) { this.data.propertyCacheWithoutObjectFunctionPropertyAugment = value; } get resolvedProperties() { - return this._data?.resolvedProperties; + return this.data.resolvedProperties; } set resolvedProperties(value: any) { this.data.resolvedProperties = value; } get resolvedIndexType() { - return this._data?.resolvedIndexType; + return this.data.resolvedIndexType; } set resolvedIndexType(value: any) { this.data.resolvedIndexType = value; } get resolvedStringIndexType() { - return this._data?.resolvedStringIndexType; + return this.data.resolvedStringIndexType; } set resolvedStringIndexType(value: any) { this.data.resolvedStringIndexType = value; } get resolvedBaseConstraint() { - return this._data?.resolvedBaseConstraint; + return this.data.resolvedBaseConstraint; } set resolvedBaseConstraint(value: any) { this.data.resolvedBaseConstraint = value; } get iterationTypesOfGeneratorReturnType() { - return this._data?.iterationTypesOfGeneratorReturnType; + return this.data.iterationTypesOfGeneratorReturnType; } set iterationTypesOfGeneratorReturnType(value: any) { this.data.iterationTypesOfGeneratorReturnType = value; } get iterationTypesOfAsyncGeneratorReturnType() { - return this._data?.iterationTypesOfAsyncGeneratorReturnType; + return this.data.iterationTypesOfAsyncGeneratorReturnType; } set iterationTypesOfAsyncGeneratorReturnType(value: any) { this.data.iterationTypesOfAsyncGeneratorReturnType = value; } get iterationTypesOfIterable() { - return this._data?.iterationTypesOfIterable; + return this.data.iterationTypesOfIterable; } set iterationTypesOfIterable(value: any) { this.data.iterationTypesOfIterable = value; } get iterationTypesOfIterator() { - return this._data?.iterationTypesOfIterator; + return this.data.iterationTypesOfIterator; } set iterationTypesOfIterator(value: any) { this.data.iterationTypesOfIterator = value; } get iterationTypesOfAsyncIterable() { - return this._data?.iterationTypesOfAsyncIterable; + return this.data.iterationTypesOfAsyncIterable; } set iterationTypesOfAsyncIterable(value: any) { this.data.iterationTypesOfAsyncIterable = value; } get iterationTypesOfAsyncIterator() { - return this._data?.iterationTypesOfAsyncIterator; + return this.data.iterationTypesOfAsyncIterator; } set iterationTypesOfAsyncIterator(value: any) { this.data.iterationTypesOfAsyncIterator = value; } get iterationTypesOfIteratorResult() { - return this._data?.iterationTypesOfIteratorResult; + return this.data.iterationTypesOfIteratorResult; } set iterationTypesOfIteratorResult(value: any) { this.data.iterationTypesOfIteratorResult = value; } get resolvedReducedType() { - return this._data?.resolvedReducedType; + return this.data.resolvedReducedType; } set resolvedReducedType(value: any) { this.data.resolvedReducedType = value; } get origin() { - return this._data?.origin; + return this.data.origin; } set origin(value: any) { this.data.origin = value; } get keyPropertyName() { - return this._data?.keyPropertyName; + return this.data.keyPropertyName; } set keyPropertyName(value: any) { this.data.keyPropertyName = value; } get constituentMap() { - return this._data?.constituentMap; + return this.data.constituentMap; } set constituentMap(value: any) { this.data.constituentMap = value; } get arrayFallbackSignatures() { - return this._data?.arrayFallbackSignatures; + return this.data.arrayFallbackSignatures; } set arrayFallbackSignatures(value: any) { this.data.arrayFallbackSignatures = value; } get promiseTypeOfPromiseConstructor() { - return this._data?.promiseTypeOfPromiseConstructor; + return this.data.promiseTypeOfPromiseConstructor; } set promiseTypeOfPromiseConstructor(value: any) { this.data.promiseTypeOfPromiseConstructor = value; } get promisedTypeOfPromise() { - return this._data?.promisedTypeOfPromise; + return this.data.promisedTypeOfPromise; } set promisedTypeOfPromise(value: any) { this.data.promisedTypeOfPromise = value; } get awaitedTypeOfType() { - return this._data?.awaitedTypeOfType; + return this.data.awaitedTypeOfType; } set awaitedTypeOfType(value: any) { this.data.awaitedTypeOfType = value; } get uniqueLiteralFilledInstantiation() { - return this._data?.uniqueLiteralFilledInstantiation; + return this.data.uniqueLiteralFilledInstantiation; } set uniqueLiteralFilledInstantiation(value: any) { this.data.uniqueLiteralFilledInstantiation = value; } get syntheticType() { - return this._data?.syntheticType; + return this.data.syntheticType; } set syntheticType(value: any) { this.data.syntheticType = value; } get defaultOnlyType() { - return this._data?.defaultOnlyType; + return this.data.defaultOnlyType; } set defaultOnlyType(value: any) { this.data.defaultOnlyType = value; } get constraint() { - return this._data?.constraint; + return this.data.constraint; } set constraint(value: any) { this.data.constraint = value; } get default() { - return this._data?.default; + return this.data.default; } set default(value: any) { this.data.default = value; } get isThisType() { - return this._data?.isThisType; + return this.data.isThisType; } set isThisType(value: any) { this.data.isThisType = value; } get resolvedDefaultType() { - return this._data?.resolvedDefaultType; + return this.data.resolvedDefaultType; } set resolvedDefaultType(value: any) { this.data.resolvedDefaultType = value; } get objectType() { - return this._data?.objectType; + return this.data.objectType; } set objectType(value: any) { this.data.objectType = value; } get indexType() { - return this._data?.indexType; + return this.data.indexType; } set indexType(value: any) { this.data.indexType = value; } get accessFlags() { - return this._data?.accessFlags; + return this.data.accessFlags; } set accessFlags(value: any) { this.data.accessFlags = value; } get simplifiedForReading() { - return this._data?.simplifiedForReading; + return this.data.simplifiedForReading; } set simplifiedForReading(value: any) { this.data.simplifiedForReading = value; } get simplifiedForWriting() { - return this._data?.simplifiedForWriting; + return this.data.simplifiedForWriting; } set simplifiedForWriting(value: any) { this.data.simplifiedForWriting = value; } get type() { - return this._data?.type; + return this.data.type; } set type(value: any) { this.data.type = value; } get indexFlags() { - return this._data?.indexFlags; + return this.data.indexFlags; } set indexFlags(value: any) { this.data.indexFlags = value; } get root() { - return this._data?.root; + return this.data.root; } set root(value: any) { this.data.root = value; } get checkType() { - return this._data?.checkType; + return this.data.checkType; } set checkType(value: any) { this.data.checkType = value; } get extendsType() { - return this._data?.extendsType; + return this.data.extendsType; } set extendsType(value: any) { this.data.extendsType = value; } get resolvedTrueType() { - return this._data?.resolvedTrueType; + return this.data.resolvedTrueType; } set resolvedTrueType(value: any) { this.data.resolvedTrueType = value; } get resolvedFalseType() { - return this._data?.resolvedFalseType; + return this.data.resolvedFalseType; } set resolvedFalseType(value: any) { this.data.resolvedFalseType = value; } get resolvedInferredTrueType() { - return this._data?.resolvedInferredTrueType; + return this.data.resolvedInferredTrueType; } set resolvedInferredTrueType(value: any) { this.data.resolvedInferredTrueType = value; } get resolvedDefaultConstraint() { - return this._data?.resolvedDefaultConstraint; + return this.data.resolvedDefaultConstraint; } set resolvedDefaultConstraint(value: any) { this.data.resolvedDefaultConstraint = value; } get resolvedConstraintOfDistributive() { - return this._data?.resolvedConstraintOfDistributive; + return this.data.resolvedConstraintOfDistributive; } set resolvedConstraintOfDistributive(value: any) { this.data.resolvedConstraintOfDistributive = value; } get combinedMapper() { - return this._data?.combinedMapper; + return this.data.combinedMapper; } set combinedMapper(value: any) { this.data.combinedMapper = value; } get texts() { - return this._data?.texts; + return this.data.texts; } set texts(value: any) { this.data.texts = value; } get baseType() { - return this._data?.baseType; + return this.data.baseType; } set baseType(value: any) { this.data.baseType = value; @@ -9079,43 +9076,43 @@ export class SignatureImpl { return this._data ??= new SignatureDataImpl(); } get erasedSignatureCache() { - return this._data?.erasedSignatureCache; + return this.data.erasedSignatureCache; } set erasedSignatureCache(value: any) { this.data.erasedSignatureCache = value; } get canonicalSignatureCache() { - return this._data?.canonicalSignatureCache; + return this.data.canonicalSignatureCache; } set canonicalSignatureCache(value: any) { this.data.canonicalSignatureCache = value; } get baseSignatureCache() { - return this._data?.baseSignatureCache; + return this.data.baseSignatureCache; } set baseSignatureCache(value: any) { this.data.baseSignatureCache = value; } get optionalCallSignatureCache() { - return this._data?.optionalCallSignatureCache; + return this.data.optionalCallSignatureCache; } set optionalCallSignatureCache(value: any) { this.data.optionalCallSignatureCache = value; } get isolatedSignatureType() { - return this._data?.isolatedSignatureType; + return this.data.isolatedSignatureType; } set isolatedSignatureType(value: any) { this.data.isolatedSignatureType = value; } get instantiations() { - return this._data?.instantiations; + return this.data.instantiations; } set instantiations(value: any) { this.data.instantiations = value; } get implementationSignatureCache() { - return this._data?.implementationSignatureCache; + return this.data.implementationSignatureCache; } set implementationSignatureCache(value: any) { this.data.implementationSignatureCache = value; @@ -9158,9 +9155,6 @@ export class NodeImpl { this.data.jsDoc = value; } - // get modifierFlagsCache() { return this.data.modifierFlagsCache; } - // set modifierFlagsCache(value: any) { this.data.modifierFlagsCache = value } - get escapedText() { return this.data.escapedText; } @@ -9204,7 +9198,7 @@ export class NodeImpl { } get name() { - return this.data?.name; + return this.data.name; } set name(value: any) { this.data.name = value; From ba162b812c4a253a8ed615a736ac59b576c96b5f Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Mon, 24 Jun 2024 12:01:21 +0100 Subject: [PATCH 04/13] Bring back separate shapes for Token and Identifier as distinct form node to reduce memory usage. --- src/compiler/factory/nodeFactory.ts | 47 +- src/compiler/utilities.ts | 705 +++++++++++++++------------- src/harness/typeWriter.ts | 6 +- src/services/services.ts | 150 +++++- 4 files changed, 548 insertions(+), 360 deletions(-) diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index d3a8860744ad8..9b51d733ed17c 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -178,6 +178,7 @@ import { isIndexSignatureDeclaration, isInterfaceDeclaration, isLabeledStatement, + isLiteralKind, isLocalName, isLogicalOrCoalescingAssignmentOperator, isMemberName, @@ -1280,7 +1281,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createRegularExpressionLiteral(text: string): RegularExpressionLiteral { - const node = createBaseToken(SyntaxKind.RegularExpressionLiteral); + const node = createBaseNode(SyntaxKind.RegularExpressionLiteral); node.data.text = text; return node; } @@ -1464,6 +1465,28 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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"); + + if (token === SyntaxKind.EndOfFileToken) { + const node = createBaseNode(token); + node.data.jsDoc = undefined; + return node; + } + if (token === SyntaxKind.ThisKeyword) { + const node = createBaseNode(token); + // 'this' indicates a lexical 'this' + node.transformFlags = TransformFlags.ContainsLexicalThis; + (node as NodeData> as NodeData).data.flowNode = undefined; // initialized by binder (FlowContainer) + return node; + } + + if (token === SyntaxKind.SuperKeyword) { + const node = createBaseNode(token); + + node.transformFlags = TransformFlags.ContainsES2015 | TransformFlags.ContainsLexicalSuper; + (node as NodeData> as NodeData).data.flowNode = undefined; // initialized by binder (FlowContainer) + return node; + } + const node = createBaseToken>(token); let transformFlags = TransformFlags.None; switch (token) { @@ -1500,21 +1523,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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 NodeData> as NodeData).data.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 NodeData> as NodeData).data.flowNode = undefined; // initialized by binder (FlowContainer) - break; } if (transformFlags) { node.transformFlags |= transformFlags; @@ -3605,7 +3619,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // 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); + const node = createBaseNode(kind); const nodeData = node.data; nodeData.text = text; nodeData.rawText = rawText; @@ -6520,8 +6534,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode return clonePrivateIdentifier(node) as T & PrivateIdentifier; } - const clone = !isNodeKind(node.kind) ? baseFactory.createBaseTokenNode(node.kind) as T : - baseFactory.createBaseNode(node.kind) as T; + const kind = node.kind; + const isSimpleToken = !isNodeKind(kind) + && kind !== SyntaxKind.SuperKeyword && kind !== SyntaxKind.ThisKeyword + && kind !== SyntaxKind.TemplateLiteralTypeSpan + && !isLiteralKind(kind); + + const clone = isSimpleToken ? + baseFactory.createBaseTokenNode(kind) as T : + baseFactory.createBaseNode(kind) as T; (clone as unknown as NodeData).flags |= node.flags & ~NodeFlags.Synthesized; (clone as unknown as NodeData).transformFlags = node.transformFlags; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index d1f736b7cbf27..4da3dd41635e6 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -8282,7 +8282,7 @@ export class TypeImpl { checker: TypeChecker; flags: TypeFlags; symbol: Symbol; - data: any; + _data: any = undefined; id: number; objectFlags: number; constructor(checker: TypeChecker, flags: TypeFlags) { @@ -8291,735 +8291,737 @@ export class TypeImpl { this.flags = flags; this.symbol = undefined!; this.objectFlags = 0; - this.data = new TypeDataImpl(); + } + get data() { + return this._data ??= new TypeDataImpl(); } get pattern() { - return this.data.pattern; + return this._data?.pattern; } set pattern(value: any) { this.data.pattern = value; } get aliasSymbol() { - return this.data.aliasSymbol; + return this._data?.aliasSymbol; } set aliasSymbol(value: any) { this.data.aliasSymbol = value; } get aliasTypeArguments() { - return this.data.aliasTypeArguments; + return this._data?.aliasTypeArguments; } set aliasTypeArguments(value: any) { this.data.aliasTypeArguments = value; } get permissiveInstantiation() { - return this.data.permissiveInstantiation; + return this._data?.permissiveInstantiation; } set permissiveInstantiation(value: any) { this.data.permissiveInstantiation = value; } get restrictiveInstantiation() { - return this.data.restrictiveInstantiation; + return this._data?.restrictiveInstantiation; } set restrictiveInstantiation(value: any) { this.data.restrictiveInstantiation = value; } get immediateBaseConstraint() { - return this.data.immediateBaseConstraint; + return this._data?.immediateBaseConstraint; } set immediateBaseConstraint(value: any) { this.data.immediateBaseConstraint = value; } get widened() { - return this.data.widened; + return this._data?.widened; } set widened(value: any) { this.data.widened = value; } get intrinsicName() { - return this.data.intrinsicName; + return this._data?.intrinsicName; } set intrinsicName(value: any) { this.data.intrinsicName = value; } get debugIntrinsicName() { - return this.data.debugIntrinsicName; + return this._data?.debugIntrinsicName; } set debugIntrinsicName(value: any) { this.data.debugIntrinsicName = value; } - // get objectFlags() { return this.data.objectFlags; } + // get objectFlags() { return this._data?.objectFlags; } // set objectFlags(value: any) { this.data.objectFlags = value } get freshType() { - return this.data.freshType; + return this._data?.freshType; } set freshType(value: any) { this.data.freshType = value; } get regularType() { - return this.data.regularType; + return this._data?.regularType; } set regularType(value: any) { this.data.regularType = value; } get value() { - return this.data.value; + return this._data?.value; } set value(value: any) { this.data.value = value; } get escapedName() { - return this.data.escapedName; + return this._data?.escapedName; } set escapedName(value: any) { this.data.escapedName = value; } get members() { - return this.data.members; + return this._data?.members; } set members(value: any) { this.data.members = value; } get properties() { - return this.data.properties; + return this._data?.properties; } set properties(value: any) { this.data.properties = value; } get callSignatures() { - return this.data.callSignatures; + return this._data?.callSignatures; } set callSignatures(value: any) { this.data.callSignatures = value; } get constructSignatures() { - return this.data.constructSignatures; + return this._data?.constructSignatures; } set constructSignatures(value: any) { this.data.constructSignatures = value; } get indexInfos() { - return this.data.indexInfos; + return this._data?.indexInfos; } set indexInfos(value: any) { this.data.indexInfos = value; } get objectTypeWithoutAbstractConstructSignatures() { - return this.data.objectTypeWithoutAbstractConstructSignatures; + return this._data?.objectTypeWithoutAbstractConstructSignatures; } set objectTypeWithoutAbstractConstructSignatures(value: any) { this.data.objectTypeWithoutAbstractConstructSignatures = value; } get typeParameters() { - return this.data.typeParameters; + return this._data?.typeParameters; } set typeParameters(value: any) { this.data.typeParameters = value; } get outerTypeParameters() { - return this.data.outerTypeParameters; + return this._data?.outerTypeParameters; } set outerTypeParameters(value: any) { this.data.outerTypeParameters = value; } get localTypeParameters() { - return this.data.localTypeParameters; + return this._data?.localTypeParameters; } set localTypeParameters(value: any) { this.data.localTypeParameters = value; } get thisType() { - return this.data.thisType; + return this._data?.thisType; } set thisType(value: any) { this.data.thisType = value; } get resolvedBaseConstructorType() { - return this.data.resolvedBaseConstructorType; + return this._data?.resolvedBaseConstructorType; } set resolvedBaseConstructorType(value: any) { this.data.resolvedBaseConstructorType = value; } get resolvedBaseTypes() { - return this.data.resolvedBaseTypes; + return this._data?.resolvedBaseTypes; } set resolvedBaseTypes(value: any) { this.data.resolvedBaseTypes = value; } get baseTypesResolved() { - return this.data.baseTypesResolved; + return this._data?.baseTypesResolved; } set baseTypesResolved(value: any) { this.data.baseTypesResolved = value; } get declaredProperties() { - return this.data.declaredProperties; + return this._data?.declaredProperties; } set declaredProperties(value: any) { this.data.declaredProperties = value; } get declaredCallSignatures() { - return this.data.declaredCallSignatures; + return this._data?.declaredCallSignatures; } set declaredCallSignatures(value: any) { this.data.declaredCallSignatures = value; } get declaredConstructSignatures() { - return this.data.declaredConstructSignatures; + return this._data?.declaredConstructSignatures; } set declaredConstructSignatures(value: any) { this.data.declaredConstructSignatures = value; } get declaredIndexInfos() { - return this.data.declaredIndexInfos; + return this._data?.declaredIndexInfos; } set declaredIndexInfos(value: any) { this.data.declaredIndexInfos = value; } get instantiations() { - return this.data.instantiations; + return this._data?.instantiations; } set instantiations(value: any) { this.data.instantiations = value; } get variances() { - return this.data.variances; + return this._data?.variances; } set variances(value: any) { this.data.variances = value; } get target() { - return this.data.target; + return this._data?.target; } set target(value: any) { this.data.target = value; } get node() { - return this.data.node; + return this._data?.node; } set node(value: any) { this.data.node = value; } get mapper() { - return this.data.mapper; + return this._data?.mapper; } set mapper(value: any) { this.data.mapper = value; } get resolvedTypeArguments() { - return this.data.resolvedTypeArguments; + return this._data?.resolvedTypeArguments; } set resolvedTypeArguments(value: any) { this.data.resolvedTypeArguments = value; } get literalType() { - return this.data.literalType; + return this._data?.literalType; } set literalType(value: any) { this.data.literalType = value; } get cachedEquivalentBaseType() { - return this.data.cachedEquivalentBaseType; + return this._data?.cachedEquivalentBaseType; } set cachedEquivalentBaseType(value: any) { this.data.cachedEquivalentBaseType = value; } get elementFlags() { - return this.data.elementFlags; + return this._data?.elementFlags; } set elementFlags(value: any) { this.data.elementFlags = value; } get minLength() { - return this.data.minLength; + return this._data?.minLength; } set minLength(value: any) { this.data.minLength = value; } get fixedLength() { - return this.data.fixedLength; + return this._data?.fixedLength; } set fixedLength(value: any) { this.data.fixedLength = value; } get hasRestElement() { - return this.data.hasRestElement; + return this._data?.hasRestElement; } set hasRestElement(value: any) { this.data.hasRestElement = value; } get combinedFlags() { - return this.data.combinedFlags; + return this._data?.combinedFlags; } set combinedFlags(value: any) { this.data.combinedFlags = value; } get readonly() { - return this.data.readonly; + return this._data?.readonly; } set readonly(value: any) { this.data.readonly = value; } get labeledElementDeclarations() { - return this.data.labeledElementDeclarations; + return this._data?.labeledElementDeclarations; } set labeledElementDeclarations(value: any) { this.data.labeledElementDeclarations = value; } get declaration() { - return this.data.declaration; + return this._data?.declaration; } set declaration(value: any) { this.data.declaration = value; } get typeParameter() { - return this.data.typeParameter; + return this._data?.typeParameter; } set typeParameter(value: any) { this.data.typeParameter = value; } get constraintType() { - return this.data.constraintType; + return this._data?.constraintType; } set constraintType(value: any) { this.data.constraintType = value; } get nameType() { - return this.data.nameType; + return this._data?.nameType; } set nameType(value: any) { this.data.nameType = value; } get templateType() { - return this.data.templateType; + return this._data?.templateType; } set templateType(value: any) { this.data.templateType = value; } get modifiersType() { - return this.data.modifiersType; + return this._data?.modifiersType; } set modifiersType(value: any) { this.data.modifiersType = value; } get resolvedApparentType() { - return this.data.resolvedApparentType; + return this._data?.resolvedApparentType; } set resolvedApparentType(value: any) { this.data.resolvedApparentType = value; } get containsError() { - return this.data.containsError; + return this._data?.containsError; } set containsError(value: any) { this.data.containsError = value; } get elementType() { - return this.data.elementType; + return this._data?.elementType; } set elementType(value: any) { this.data.elementType = value; } get finalArrayType() { - return this.data.finalArrayType; + return this._data?.finalArrayType; } set finalArrayType(value: any) { this.data.finalArrayType = value; } get source() { - return this.data.source; + return this._data?.source; } set source(value: any) { this.data.source = value; } get mappedType() { - return this.data.mappedType; + return this._data?.mappedType; } set mappedType(value: any) { this.data.mappedType = value; } get types() { - return this.data.types; + return this._data?.types; } set types(value: any) { this.data.types = value; } get propertyCache() { - return this.data.propertyCache; + return this._data?.propertyCache; } set propertyCache(value: any) { this.data.propertyCache = value; } get propertyCacheWithoutObjectFunctionPropertyAugment() { - return this.data.propertyCacheWithoutObjectFunctionPropertyAugment; + return this._data?.propertyCacheWithoutObjectFunctionPropertyAugment; } set propertyCacheWithoutObjectFunctionPropertyAugment(value: any) { this.data.propertyCacheWithoutObjectFunctionPropertyAugment = value; } get resolvedProperties() { - return this.data.resolvedProperties; + return this._data?.resolvedProperties; } set resolvedProperties(value: any) { this.data.resolvedProperties = value; } get resolvedIndexType() { - return this.data.resolvedIndexType; + return this._data?.resolvedIndexType; } set resolvedIndexType(value: any) { this.data.resolvedIndexType = value; } get resolvedStringIndexType() { - return this.data.resolvedStringIndexType; + return this._data?.resolvedStringIndexType; } set resolvedStringIndexType(value: any) { this.data.resolvedStringIndexType = value; } get resolvedBaseConstraint() { - return this.data.resolvedBaseConstraint; + return this._data?.resolvedBaseConstraint; } set resolvedBaseConstraint(value: any) { this.data.resolvedBaseConstraint = value; } get iterationTypesOfGeneratorReturnType() { - return this.data.iterationTypesOfGeneratorReturnType; + return this._data?.iterationTypesOfGeneratorReturnType; } set iterationTypesOfGeneratorReturnType(value: any) { this.data.iterationTypesOfGeneratorReturnType = value; } get iterationTypesOfAsyncGeneratorReturnType() { - return this.data.iterationTypesOfAsyncGeneratorReturnType; + return this._data?.iterationTypesOfAsyncGeneratorReturnType; } set iterationTypesOfAsyncGeneratorReturnType(value: any) { this.data.iterationTypesOfAsyncGeneratorReturnType = value; } get iterationTypesOfIterable() { - return this.data.iterationTypesOfIterable; + return this._data?.iterationTypesOfIterable; } set iterationTypesOfIterable(value: any) { this.data.iterationTypesOfIterable = value; } get iterationTypesOfIterator() { - return this.data.iterationTypesOfIterator; + return this._data?.iterationTypesOfIterator; } set iterationTypesOfIterator(value: any) { this.data.iterationTypesOfIterator = value; } get iterationTypesOfAsyncIterable() { - return this.data.iterationTypesOfAsyncIterable; + return this._data?.iterationTypesOfAsyncIterable; } set iterationTypesOfAsyncIterable(value: any) { this.data.iterationTypesOfAsyncIterable = value; } get iterationTypesOfAsyncIterator() { - return this.data.iterationTypesOfAsyncIterator; + return this._data?.iterationTypesOfAsyncIterator; } set iterationTypesOfAsyncIterator(value: any) { this.data.iterationTypesOfAsyncIterator = value; } get iterationTypesOfIteratorResult() { - return this.data.iterationTypesOfIteratorResult; + return this._data?.iterationTypesOfIteratorResult; } set iterationTypesOfIteratorResult(value: any) { this.data.iterationTypesOfIteratorResult = value; } get resolvedReducedType() { - return this.data.resolvedReducedType; + return this._data?.resolvedReducedType; } set resolvedReducedType(value: any) { this.data.resolvedReducedType = value; } get origin() { - return this.data.origin; + return this._data?.origin; } set origin(value: any) { this.data.origin = value; } get keyPropertyName() { - return this.data.keyPropertyName; + return this._data?.keyPropertyName; } set keyPropertyName(value: any) { this.data.keyPropertyName = value; } get constituentMap() { - return this.data.constituentMap; + return this._data?.constituentMap; } set constituentMap(value: any) { this.data.constituentMap = value; } get arrayFallbackSignatures() { - return this.data.arrayFallbackSignatures; + return this._data?.arrayFallbackSignatures; } set arrayFallbackSignatures(value: any) { this.data.arrayFallbackSignatures = value; } get promiseTypeOfPromiseConstructor() { - return this.data.promiseTypeOfPromiseConstructor; + return this._data?.promiseTypeOfPromiseConstructor; } set promiseTypeOfPromiseConstructor(value: any) { this.data.promiseTypeOfPromiseConstructor = value; } get promisedTypeOfPromise() { - return this.data.promisedTypeOfPromise; + return this._data?.promisedTypeOfPromise; } set promisedTypeOfPromise(value: any) { this.data.promisedTypeOfPromise = value; } get awaitedTypeOfType() { - return this.data.awaitedTypeOfType; + return this._data?.awaitedTypeOfType; } set awaitedTypeOfType(value: any) { this.data.awaitedTypeOfType = value; } get uniqueLiteralFilledInstantiation() { - return this.data.uniqueLiteralFilledInstantiation; + return this._data?.uniqueLiteralFilledInstantiation; } set uniqueLiteralFilledInstantiation(value: any) { this.data.uniqueLiteralFilledInstantiation = value; } get syntheticType() { - return this.data.syntheticType; + return this._data?.syntheticType; } set syntheticType(value: any) { this.data.syntheticType = value; } get defaultOnlyType() { - return this.data.defaultOnlyType; + return this._data?.defaultOnlyType; } set defaultOnlyType(value: any) { this.data.defaultOnlyType = value; } get constraint() { - return this.data.constraint; + return this._data?.constraint; } set constraint(value: any) { this.data.constraint = value; } get default() { - return this.data.default; + return this._data?.default; } set default(value: any) { this.data.default = value; } get isThisType() { - return this.data.isThisType; + return this._data?.isThisType; } set isThisType(value: any) { this.data.isThisType = value; } get resolvedDefaultType() { - return this.data.resolvedDefaultType; + return this._data?.resolvedDefaultType; } set resolvedDefaultType(value: any) { this.data.resolvedDefaultType = value; } get objectType() { - return this.data.objectType; + return this._data?.objectType; } set objectType(value: any) { this.data.objectType = value; } get indexType() { - return this.data.indexType; + return this._data?.indexType; } set indexType(value: any) { this.data.indexType = value; } get accessFlags() { - return this.data.accessFlags; + return this._data?.accessFlags; } set accessFlags(value: any) { this.data.accessFlags = value; } get simplifiedForReading() { - return this.data.simplifiedForReading; + return this._data?.simplifiedForReading; } set simplifiedForReading(value: any) { this.data.simplifiedForReading = value; } get simplifiedForWriting() { - return this.data.simplifiedForWriting; + return this._data?.simplifiedForWriting; } set simplifiedForWriting(value: any) { this.data.simplifiedForWriting = value; } get type() { - return this.data.type; + return this._data?.type; } set type(value: any) { this.data.type = value; } get indexFlags() { - return this.data.indexFlags; + return this._data?.indexFlags; } set indexFlags(value: any) { this.data.indexFlags = value; } get root() { - return this.data.root; + return this._data?.root; } set root(value: any) { this.data.root = value; } get checkType() { - return this.data.checkType; + return this._data?.checkType; } set checkType(value: any) { this.data.checkType = value; } get extendsType() { - return this.data.extendsType; + return this._data?.extendsType; } set extendsType(value: any) { this.data.extendsType = value; } get resolvedTrueType() { - return this.data.resolvedTrueType; + return this._data?.resolvedTrueType; } set resolvedTrueType(value: any) { this.data.resolvedTrueType = value; } get resolvedFalseType() { - return this.data.resolvedFalseType; + return this._data?.resolvedFalseType; } set resolvedFalseType(value: any) { this.data.resolvedFalseType = value; } get resolvedInferredTrueType() { - return this.data.resolvedInferredTrueType; + return this._data?.resolvedInferredTrueType; } set resolvedInferredTrueType(value: any) { this.data.resolvedInferredTrueType = value; } get resolvedDefaultConstraint() { - return this.data.resolvedDefaultConstraint; + return this._data?.resolvedDefaultConstraint; } set resolvedDefaultConstraint(value: any) { this.data.resolvedDefaultConstraint = value; } get resolvedConstraintOfDistributive() { - return this.data.resolvedConstraintOfDistributive; + return this._data?.resolvedConstraintOfDistributive; } set resolvedConstraintOfDistributive(value: any) { this.data.resolvedConstraintOfDistributive = value; } get combinedMapper() { - return this.data.combinedMapper; + return this._data?.combinedMapper; } set combinedMapper(value: any) { this.data.combinedMapper = value; } get texts() { - return this.data.texts; + return this._data?.texts; } set texts(value: any) { this.data.texts = value; } get baseType() { - return this.data.baseType; + return this._data?.baseType; } set baseType(value: any) { this.data.baseType = value; @@ -9070,56 +9072,63 @@ export class SignatureImpl { this.compositeSignatures = undefined; this.compositeKind = undefined; } - _data: any = undefined; get data() { return this._data ??= new SignatureDataImpl(); } get erasedSignatureCache() { - return this.data.erasedSignatureCache; + return this._data?.erasedSignatureCache; } set erasedSignatureCache(value: any) { this.data.erasedSignatureCache = value; } get canonicalSignatureCache() { - return this.data.canonicalSignatureCache; + return this._data?.canonicalSignatureCache; } set canonicalSignatureCache(value: any) { this.data.canonicalSignatureCache = value; } get baseSignatureCache() { - return this.data.baseSignatureCache; + return this._data?.baseSignatureCache; } set baseSignatureCache(value: any) { this.data.baseSignatureCache = value; } get optionalCallSignatureCache() { - return this.data.optionalCallSignatureCache; + return this._data?.optionalCallSignatureCache; } set optionalCallSignatureCache(value: any) { this.data.optionalCallSignatureCache = value; } get isolatedSignatureType() { - return this.data.isolatedSignatureType; + return this._data?.isolatedSignatureType; } set isolatedSignatureType(value: any) { this.data.isolatedSignatureType = value; } get instantiations() { - return this.data.instantiations; + return this._data?.instantiations; } set instantiations(value: any) { this.data.instantiations = value; } get implementationSignatureCache() { - return this.data.implementationSignatureCache; + return this._data?.implementationSignatureCache; } set implementationSignatureCache(value: any) { this.data.implementationSignatureCache = value; } } + +// export const NodeDataImplInstantiations: Partial> = {} class NodeDataImpl { + // constructor(kind: SyntaxKind) { + // NodeDataImplInstantiations[kind] = (NodeDataImplInstantiations[kind] ?? 0) + 1; + // } + // original = undefined; + // modifierFlagsCache = ModifierFlags.None } +// export const NodeImplInstantiations: Partial> = {} /** @internal */ export class NodeImpl { pos; // Node, Token, Identifier @@ -9129,1301 +9138,1321 @@ export class NodeImpl { flags = NodeFlags.None; // Node, Token, Identifier transformFlags = TransformFlags.None; // Node, Token, Identifier parent: Node = undefined!; // Node, Token, Identifier - original = undefined; // Node, Identifier emitNode = undefined; // Node, Token, Identifier + original = undefined; modifierFlagsCache = ModifierFlags.None; constructor(kind: SyntaxKind, pos: number, end: number) { this.kind = kind; this.pos = pos; this.end = end; - this.data = new NodeDataImpl(); + // NodeImplInstantiations[kind] = (NodeImplInstantiations[kind] ?? 0) + 1; + } + get data() { + return this._data ??= new NodeDataImpl(); + } + set data(value: any) { + this._data = value; } + _data: any = undefined; + // get original(): Node { + // return this._data?.original + // } + + // set original(value: Node) { + // this.data.original = value; + // } - data: any; + // get modifierFlagsCache(): ModifierFlags { + // return this._data?.modifierFlagsCache; + // } + + // set modifierFlagsCache(value: ModifierFlags) { + // this.data.modifierFlagsCache = value; + // } get sourceText() { - return this.data.sourceText; + return this._data?.sourceText; } set sourceText(value: any) { this.data.sourceText = value; } get jsDoc() { - return this.data.jsDoc; + return this._data?.jsDoc; } set jsDoc(value: any) { this.data.jsDoc = value; } get escapedText() { - return this.data.escapedText; + return this._data?.escapedText; } set escapedText(value: any) { this.data.escapedText = value; } get symbol() { - return this.data.symbol; + return this._data?.symbol; } set symbol(value: any) { this.data.symbol = value; } get localSymbol() { - return this.data.localSymbol; + return this._data?.localSymbol; } set localSymbol(value: any) { this.data.localSymbol = value; } get flowNode() { - return this.data.flowNode; + return this._data?.flowNode; } set flowNode(value: any) { this.data.flowNode = value; } get resolvedSymbol() { - return this.data.resolvedSymbol; + return this._data?.resolvedSymbol; } set resolvedSymbol(value: any) { this.data.resolvedSymbol = value; } get modifiers() { - return this.data.modifiers; + return this._data?.modifiers; } set modifiers(value: any) { this.data.modifiers = value; } get name() { - return this.data.name; + return this._data?.name; } set name(value: any) { this.data.name = value; } get constraint() { - return this.data.constraint; + return this._data?.constraint; } set constraint(value: any) { this.data.constraint = value; } get default() { - return this.data.default; + return this._data?.default; } set default(value: any) { this.data.default = value; } get expression() { - return this.data.expression; + return this._data?.expression; } set expression(value: any) { this.data.expression = value; } get typeParameters() { - return this.data.typeParameters; + return this._data?.typeParameters; } set typeParameters(value: any) { this.data.typeParameters = value; } get parameters() { - return this.data.parameters; + return this._data?.parameters; } set parameters(value: any) { this.data.parameters = value; } get type() { - return this.data.type; + return this._data?.type; } set type(value: any) { this.data.type = value; } get typeArguments() { - return this.data.typeArguments; + return this._data?.typeArguments; } set typeArguments(value: any) { this.data.typeArguments = value; } get questionToken() { - return this.data.questionToken; + return this._data?.questionToken; } set questionToken(value: any) { this.data.questionToken = value; } get locals() { - return this.data.locals; + return this._data?.locals; } set locals(value: any) { this.data.locals = value; } get nextContainer() { - return this.data.nextContainer; + return this._data?.nextContainer; } set nextContainer(value: any) { this.data.nextContainer = value; } get asteriskToken() { - return this.data.asteriskToken; + return this._data?.asteriskToken; } set asteriskToken(value: any) { this.data.asteriskToken = value; } get exclamationToken() { - return this.data.exclamationToken; + return this._data?.exclamationToken; } set exclamationToken(value: any) { this.data.exclamationToken = value; } get body() { - return this.data.body; + return this._data?.body; } set body(value: any) { this.data.body = value; } get endFlowNode() { - return this.data.endFlowNode; + return this._data?.endFlowNode; } set endFlowNode(value: any) { this.data.endFlowNode = value; } get returnFlowNode() { - return this.data.returnFlowNode; + return this._data?.returnFlowNode; } set returnFlowNode(value: any) { this.data.returnFlowNode = value; } get equalsGreaterThanToken() { - return this.data.equalsGreaterThanToken; + return this._data?.equalsGreaterThanToken; } set equalsGreaterThanToken(value: any) { this.data.equalsGreaterThanToken = value; } get initializer() { - return this.data.initializer; + return this._data?.initializer; } set initializer(value: any) { this.data.initializer = value; } get dotDotDotToken() { - return this.data.dotDotDotToken; + return this._data?.dotDotDotToken; } set dotDotDotToken(value: any) { this.data.dotDotDotToken = value; } get equalsToken() { - return this.data.equalsToken; + return this._data?.equalsToken; } set equalsToken(value: any) { this.data.equalsToken = value; } get objectAssignmentInitializer() { - return this.data.objectAssignmentInitializer; + return this._data?.objectAssignmentInitializer; } set objectAssignmentInitializer(value: any) { this.data.objectAssignmentInitializer = value; } get left() { - return this.data.left; + return this._data?.left; } set left(value: any) { this.data.left = value; } get operatorToken() { - return this.data.operatorToken; + return this._data?.operatorToken; } set operatorToken(value: any) { this.data.operatorToken = value; } get right() { - return this.data.right; + return this._data?.right; } set right(value: any) { this.data.right = value; } get multiLine() { - return this.data.multiLine; + return this._data?.multiLine; } set multiLine(value: any) { this.data.multiLine = value; } get properties() { - return this.data.properties; + return this._data?.properties; } set properties(value: any) { this.data.properties = value; } get questionDotToken() { - return this.data.questionDotToken; + return this._data?.questionDotToken; } set questionDotToken(value: any) { this.data.questionDotToken = value; } get argumentExpression() { - return this.data.argumentExpression; + return this._data?.argumentExpression; } set argumentExpression(value: any) { this.data.argumentExpression = value; } get heritageClauses() { - return this.data.heritageClauses; + return this._data?.heritageClauses; } set heritageClauses(value: any) { this.data.heritageClauses = value; } get members() { - return this.data.members; + return this._data?.members; } set members(value: any) { this.data.members = value; } get isTypeOnly() { - return this.data.isTypeOnly; + return this._data?.isTypeOnly; } set isTypeOnly(value: any) { this.data.isTypeOnly = value; } get moduleReference() { - return this.data.moduleReference; + return this._data?.moduleReference; } set moduleReference(value: any) { this.data.moduleReference = value; } get exportClause() { - return this.data.exportClause; + return this._data?.exportClause; } set exportClause(value: any) { this.data.exportClause = value; } get moduleSpecifier() { - return this.data.moduleSpecifier; + return this._data?.moduleSpecifier; } set moduleSpecifier(value: any) { this.data.moduleSpecifier = value; } get assertClause() { - return this.data.assertClause; + return this._data?.assertClause; } set assertClause(value: any) { this.data.assertClause = value; } get attributes() { - return this.data.attributes; + return this._data?.attributes; } set attributes(value: any) { this.data.attributes = value; } get isExportEquals() { - return this.data.isExportEquals; + return this._data?.isExportEquals; } set isExportEquals(value: any) { this.data.isExportEquals = value; } get statements() { - return this.data.statements; + return this._data?.statements; } set statements(value: any) { this.data.statements = value; } get declarationList() { - return this.data.declarationList; + return this._data?.declarationList; } set declarationList(value: any) { this.data.declarationList = value; } get thenStatement() { - return this.data.thenStatement; + return this._data?.thenStatement; } set thenStatement(value: any) { this.data.thenStatement = value; } get elseStatement() { - return this.data.elseStatement; + return this._data?.elseStatement; } set elseStatement(value: any) { this.data.elseStatement = value; } get statement() { - return this.data.statement; + return this._data?.statement; } set statement(value: any) { this.data.statement = value; } get condition() { - return this.data.condition; + return this._data?.condition; } set condition(value: any) { this.data.condition = value; } get incrementor() { - return this.data.incrementor; + return this._data?.incrementor; } set incrementor(value: any) { this.data.incrementor = value; } get awaitModifier() { - return this.data.awaitModifier; + return this._data?.awaitModifier; } set awaitModifier(value: any) { this.data.awaitModifier = value; } get label() { - return this.data.label; + return this._data?.label; } set label(value: any) { this.data.label = value; } get caseBlock() { - return this.data.caseBlock; + return this._data?.caseBlock; } set caseBlock(value: any) { this.data.caseBlock = value; } get possiblyExhaustive() { - return this.data.possiblyExhaustive; + return this._data?.possiblyExhaustive; } set possiblyExhaustive(value: any) { this.data.possiblyExhaustive = value; } get tryBlock() { - return this.data.tryBlock; + return this._data?.tryBlock; } set tryBlock(value: any) { this.data.tryBlock = value; } get catchClause() { - return this.data.catchClause; + return this._data?.catchClause; } set catchClause(value: any) { this.data.catchClause = value; } get finallyBlock() { - return this.data.finallyBlock; + return this._data?.finallyBlock; } set finallyBlock(value: any) { this.data.finallyBlock = value; } get importClause() { - return this.data.importClause; + return this._data?.importClause; } set importClause(value: any) { this.data.importClause = value; } get fallthroughFlowNode() { - return this.data.fallthroughFlowNode; + return this._data?.fallthroughFlowNode; } set fallthroughFlowNode(value: any) { this.data.fallthroughFlowNode = value; } get propertyName() { - return this.data.propertyName; + return this._data?.propertyName; } set propertyName(value: any) { this.data.propertyName = value; } get checkType() { - return this.data.checkType; + return this._data?.checkType; } set checkType(value: any) { this.data.checkType = value; } get extendsType() { - return this.data.extendsType; + return this._data?.extendsType; } set extendsType(value: any) { this.data.extendsType = value; } get trueType() { - return this.data.trueType; + return this._data?.trueType; } set trueType(value: any) { this.data.trueType = value; } get falseType() { - return this.data.falseType; + return this._data?.falseType; } set falseType(value: any) { this.data.falseType = value; } get readonlyToken() { - return this.data.readonlyToken; + return this._data?.readonlyToken; } set readonlyToken(value: any) { this.data.readonlyToken = value; } get typeParameter() { - return this.data.typeParameter; + return this._data?.typeParameter; } set typeParameter(value: any) { this.data.typeParameter = value; } get nameType() { - return this.data.nameType; + return this._data?.nameType; } set nameType(value: any) { this.data.nameType = value; } get clauses() { - return this.data.clauses; + return this._data?.clauses; } set clauses(value: any) { this.data.clauses = value; } get variableDeclaration() { - return this.data.variableDeclaration; + return this._data?.variableDeclaration; } set variableDeclaration(value: any) { this.data.variableDeclaration = value; } get block() { - return this.data.block; + return this._data?.block; } set block(value: any) { this.data.block = value; } get typeExpression() { - return this.data.typeExpression; + return this._data?.typeExpression; } set typeExpression(value: any) { this.data.typeExpression = value; } get tagName() { - return this.data.tagName; + return this._data?.tagName; } set tagName(value: any) { this.data.tagName = value; } get comment() { - return this.data.comment; + return this._data?.comment; } set comment(value: any) { this.data.comment = value; } get fullName() { - return this.data.fullName; + return this._data?.fullName; } set fullName(value: any) { this.data.fullName = value; } get endOfFileToken() { - return this.data.endOfFileToken; + return this._data?.endOfFileToken; } set endOfFileToken(value: any) { this.data.endOfFileToken = value; } get fileName() { - return this.data.fileName; + return this._data?.fileName; } set fileName(value: any) { this.data.fileName = value; } get path() { - return this.data.path; + return this._data?.path; } set path(value: any) { this.data.path = value; } get text() { - return this.data.text; + return this._data?.text; } set text(value: any) { this.data.text = value; } get resolvedPath() { - return this.data.resolvedPath; + return this._data?.resolvedPath; } set resolvedPath(value: any) { this.data.resolvedPath = value; } get originalFileName() { - return this.data.originalFileName; + return this._data?.originalFileName; } set originalFileName(value: any) { this.data.originalFileName = value; } get redirectInfo() { - return this.data.redirectInfo; + return this._data?.redirectInfo; } set redirectInfo(value: any) { this.data.redirectInfo = value; } get amdDependencies() { - return this.data.amdDependencies; + return this._data?.amdDependencies; } set amdDependencies(value: any) { this.data.amdDependencies = value; } get moduleName() { - return this.data.moduleName; + return this._data?.moduleName; } set moduleName(value: any) { this.data.moduleName = value; } get referencedFiles() { - return this.data.referencedFiles; + return this._data?.referencedFiles; } set referencedFiles(value: any) { this.data.referencedFiles = value; } get typeReferenceDirectives() { - return this.data.typeReferenceDirectives; + return this._data?.typeReferenceDirectives; } set typeReferenceDirectives(value: any) { this.data.typeReferenceDirectives = value; } get libReferenceDirectives() { - return this.data.libReferenceDirectives; + return this._data?.libReferenceDirectives; } set libReferenceDirectives(value: any) { this.data.libReferenceDirectives = value; } get languageVariant() { - return this.data.languageVariant; + return this._data?.languageVariant; } set languageVariant(value: any) { this.data.languageVariant = value; } get isDeclarationFile() { - return this.data.isDeclarationFile; + return this._data?.isDeclarationFile; } set isDeclarationFile(value: any) { this.data.isDeclarationFile = value; } get renamedDependencies() { - return this.data.renamedDependencies; + return this._data?.renamedDependencies; } set renamedDependencies(value: any) { this.data.renamedDependencies = value; } get hasNoDefaultLib() { - return this.data.hasNoDefaultLib; + return this._data?.hasNoDefaultLib; } set hasNoDefaultLib(value: any) { this.data.hasNoDefaultLib = value; } get languageVersion() { - return this.data.languageVersion; + return this._data?.languageVersion; } set languageVersion(value: any) { this.data.languageVersion = value; } get impliedNodeFormat() { - return this.data.impliedNodeFormat; + return this._data?.impliedNodeFormat; } set impliedNodeFormat(value: any) { this.data.impliedNodeFormat = value; } get packageJsonLocations() { - return this.data.packageJsonLocations; + return this._data?.packageJsonLocations; } set packageJsonLocations(value: any) { this.data.packageJsonLocations = value; } get packageJsonScope() { - return this.data.packageJsonScope; + return this._data?.packageJsonScope; } set packageJsonScope(value: any) { this.data.packageJsonScope = value; } get scriptKind() { - return this.data.scriptKind; + return this._data?.scriptKind; } set scriptKind(value: any) { this.data.scriptKind = value; } get externalModuleIndicator() { - return this.data.externalModuleIndicator; + return this._data?.externalModuleIndicator; } set externalModuleIndicator(value: any) { this.data.externalModuleIndicator = value; } get setExternalModuleIndicator() { - return this.data.setExternalModuleIndicator; + return this._data?.setExternalModuleIndicator; } set setExternalModuleIndicator(value: any) { this.data.setExternalModuleIndicator = value; } get commonJsModuleIndicator() { - return this.data.commonJsModuleIndicator; + return this._data?.commonJsModuleIndicator; } set commonJsModuleIndicator(value: any) { this.data.commonJsModuleIndicator = value; } get jsGlobalAugmentations() { - return this.data.jsGlobalAugmentations; + return this._data?.jsGlobalAugmentations; } set jsGlobalAugmentations(value: any) { this.data.jsGlobalAugmentations = value; } get identifiers() { - return this.data.identifiers; + return this._data?.identifiers; } set identifiers(value: any) { this.data.identifiers = value; } get nodeCount() { - return this.data.nodeCount; + return this._data?.nodeCount; } set nodeCount(value: any) { this.data.nodeCount = value; } get identifierCount() { - return this.data.identifierCount; + return this._data?.identifierCount; } set identifierCount(value: any) { this.data.identifierCount = value; } get symbolCount() { - return this.data.symbolCount; + return this._data?.symbolCount; } set symbolCount(value: any) { this.data.symbolCount = value; } get parseDiagnostics() { - return this.data.parseDiagnostics; + return this._data?.parseDiagnostics; } set parseDiagnostics(value: any) { this.data.parseDiagnostics = value; } get bindDiagnostics() { - return this.data.bindDiagnostics; + return this._data?.bindDiagnostics; } set bindDiagnostics(value: any) { this.data.bindDiagnostics = value; } get bindSuggestionDiagnostics() { - return this.data.bindSuggestionDiagnostics; + return this._data?.bindSuggestionDiagnostics; } set bindSuggestionDiagnostics(value: any) { this.data.bindSuggestionDiagnostics = value; } get jsDocDiagnostics() { - return this.data.jsDocDiagnostics; + return this._data?.jsDocDiagnostics; } set jsDocDiagnostics(value: any) { this.data.jsDocDiagnostics = value; } get additionalSyntacticDiagnostics() { - return this.data.additionalSyntacticDiagnostics; + return this._data?.additionalSyntacticDiagnostics; } set additionalSyntacticDiagnostics(value: any) { this.data.additionalSyntacticDiagnostics = value; } get lineMap() { - return this.data.lineMap; + return this._data?.lineMap; } set lineMap(value: any) { this.data.lineMap = value; } get classifiableNames() { - return this.data.classifiableNames; + return this._data?.classifiableNames; } set classifiableNames(value: any) { this.data.classifiableNames = value; } get commentDirectives() { - return this.data.commentDirectives; + return this._data?.commentDirectives; } set commentDirectives(value: any) { this.data.commentDirectives = value; } get imports() { - return this.data.imports; + return this._data?.imports; } set imports(value: any) { this.data.imports = value; } get moduleAugmentations() { - return this.data.moduleAugmentations; + return this._data?.moduleAugmentations; } set moduleAugmentations(value: any) { this.data.moduleAugmentations = value; } get patternAmbientModules() { - return this.data.patternAmbientModules; + return this._data?.patternAmbientModules; } set patternAmbientModules(value: any) { this.data.patternAmbientModules = value; } get ambientModuleNames() { - return this.data.ambientModuleNames; + return this._data?.ambientModuleNames; } set ambientModuleNames(value: any) { this.data.ambientModuleNames = value; } get checkJsDirective() { - return this.data.checkJsDirective; + return this._data?.checkJsDirective; } set checkJsDirective(value: any) { this.data.checkJsDirective = value; } get version() { - return this.data.version; + return this._data?.version; } set version(value: any) { this.data.version = value; } get pragmas() { - return this.data.pragmas; + return this._data?.pragmas; } set pragmas(value: any) { this.data.pragmas = value; } get localJsxNamespace() { - return this.data.localJsxNamespace; + return this._data?.localJsxNamespace; } set localJsxNamespace(value: any) { this.data.localJsxNamespace = value; } get localJsxFragmentNamespace() { - return this.data.localJsxFragmentNamespace; + return this._data?.localJsxFragmentNamespace; } set localJsxFragmentNamespace(value: any) { this.data.localJsxFragmentNamespace = value; } get localJsxFactory() { - return this.data.localJsxFactory; + return this._data?.localJsxFactory; } set localJsxFactory(value: any) { this.data.localJsxFactory = value; } get localJsxFragmentFactory() { - return this.data.localJsxFragmentFactory; + return this._data?.localJsxFragmentFactory; } set localJsxFragmentFactory(value: any) { this.data.localJsxFragmentFactory = value; } get jsDocParsingMode() { - return this.data.jsDocParsingMode; + return this._data?.jsDocParsingMode; } set jsDocParsingMode(value: any) { this.data.jsDocParsingMode = value; } get extendedSourceFiles() { - return this.data.extendedSourceFiles; + return this._data?.extendedSourceFiles; } set extendedSourceFiles(value: any) { this.data.extendedSourceFiles = value; } get configFileSpecs() { - return this.data.configFileSpecs; + return this._data?.configFileSpecs; } set configFileSpecs(value: any) { this.data.configFileSpecs = value; } get keywordToken() { - return this.data.keywordToken; + return this._data?.keywordToken; } set keywordToken(value: any) { this.data.keywordToken = value; } get namedBindings() { - return this.data.namedBindings; + return this._data?.namedBindings; } set namedBindings(value: any) { this.data.namedBindings = value; } get textSourceNode() { - return this.data.textSourceNode; + return this._data?.textSourceNode; } set textSourceNode(value: any) { this.data.textSourceNode = value; } get singleQuote() { - return this.data.singleQuote; + return this._data?.singleQuote; } set singleQuote(value: any) { this.data.singleQuote = value; } get isUnterminated() { - return this.data.isUnterminated; + return this._data?.isUnterminated; } set isUnterminated(value: any) { this.data.isUnterminated = value; } get hasExtendedUnicodeEscape() { - return this.data.hasExtendedUnicodeEscape; + return this._data?.hasExtendedUnicodeEscape; } set hasExtendedUnicodeEscape(value: any) { this.data.hasExtendedUnicodeEscape = value; } get templateFlags() { - return this.data.templateFlags; + return this._data?.templateFlags; } set templateFlags(value: any) { this.data.templateFlags = value; } get rawText() { - return this.data.rawText; + return this._data?.rawText; } set rawText(value: any) { this.data.rawText = value; } get numericLiteralFlags() { - return this.data.numericLiteralFlags; + return this._data?.numericLiteralFlags; } set numericLiteralFlags(value: any) { this.data.numericLiteralFlags = value; } get arguments() { - return this.data.arguments; + return this._data?.arguments; } set arguments(value: any) { this.data.arguments = value; } get isNameFirst() { - return this.data.isNameFirst; + return this._data?.isNameFirst; } set isNameFirst(value: any) { this.data.isNameFirst = value; } get isBracketed() { - return this.data.isBracketed; + return this._data?.isBracketed; } set isBracketed(value: any) { this.data.isBracketed = value; } get jsDocPropertyTags() { - return this.data.jsDocPropertyTags; + return this._data?.jsDocPropertyTags; } set jsDocPropertyTags(value: any) { this.data.jsDocPropertyTags = value; } get isArrayType() { - return this.data.isArrayType; + return this._data?.isArrayType; } set isArrayType(value: any) { this.data.isArrayType = value; } get declarations() { - return this.data.declarations; + return this._data?.declarations; } set declarations(value: any) { this.data.declarations = value; } get elements() { - return this.data.elements; + return this._data?.elements; } set elements(value: any) { this.data.elements = value; } get isTypeOf() { - return this.data.isTypeOf; + return this._data?.isTypeOf; } set isTypeOf(value: any) { this.data.isTypeOf = value; } get argument() { - return this.data.argument; + return this._data?.argument; } set argument(value: any) { this.data.argument = value; } get assertions() { - return this.data.assertions; + return this._data?.assertions; } set assertions(value: any) { this.data.assertions = value; } get qualifier() { - return this.data.qualifier; + return this._data?.qualifier; } set qualifier(value: any) { this.data.qualifier = value; } get typeName() { - return this.data.typeName; + return this._data?.typeName; } set typeName(value: any) { this.data.typeName = value; } get exprName() { - return this.data.exprName; + return this._data?.exprName; } set exprName(value: any) { this.data.exprName = value; } get assertsModifier() { - return this.data.assertsModifier; + return this._data?.assertsModifier; } set assertsModifier(value: any) { this.data.assertsModifier = value; } get parameterName() { - return this.data.parameterName; + return this._data?.parameterName; } set parameterName(value: any) { this.data.parameterName = value; } get elementType() { - return this.data.elementType; + return this._data?.elementType; } set elementType(value: any) { this.data.elementType = value; } get types() { - return this.data.types; + return this._data?.types; } set types(value: any) { this.data.types = value; } get operator() { - return this.data.operator; + return this._data?.operator; } set operator(value: any) { this.data.operator = value; } get objectType() { - return this.data.objectType; + return this._data?.objectType; } set objectType(value: any) { this.data.objectType = value; } get indexType() { - return this.data.indexType; + return this._data?.indexType; } set indexType(value: any) { this.data.indexType = value; } get literal() { - return this.data.literal; + return this._data?.literal; } set literal(value: any) { this.data.literal = value; } get head() { - return this.data.head; + return this._data?.head; } set head(value: any) { this.data.head = value; } get templateSpans() { - return this.data.templateSpans; + return this._data?.templateSpans; } set templateSpans(value: any) { this.data.templateSpans = value; } get postfix() { - return this.data.postfix; + return this._data?.postfix; } set postfix(value: any) { this.data.postfix = value; } get operand() { - return this.data.operand; + return this._data?.operand; } set operand(value: any) { this.data.operand = value; } get openingElement() { - return this.data.openingElement; + return this._data?.openingElement; } set openingElement(value: any) { this.data.openingElement = value; } get children() { - return this.data.children; + return this._data?.children; } set children(value: any) { this.data.children = value; } get closingElement() { - return this.data.closingElement; + return this._data?.closingElement; } set closingElement(value: any) { this.data.closingElement = value; } get openingFragment() { - return this.data.openingFragment; + return this._data?.openingFragment; } set openingFragment(value: any) { this.data.openingFragment = value; } get closingFragment() { - return this.data.closingFragment; + return this._data?.closingFragment; } set closingFragment(value: any) { this.data.closingFragment = value; } get tag() { - return this.data.tag; + return this._data?.tag; } set tag(value: any) { this.data.tag = value; } get template() { - return this.data.template; + return this._data?.template; } set template(value: any) { this.data.template = value; } get thisArg() { - return this.data.thisArg; + return this._data?.thisArg; } set thisArg(value: any) { this.data.thisArg = value; } get isSpread() { - return this.data.isSpread; + return this._data?.isSpread; } set isSpread(value: any) { this.data.isSpread = value; } get tupleNameSource() { - return this.data.tupleNameSource; + return this._data?.tupleNameSource; } set tupleNameSource(value: any) { this.data.tupleNameSource = value; } get whenTrue() { - return this.data.whenTrue; + return this._data?.whenTrue; } set whenTrue(value: any) { this.data.whenTrue = value; } get colonToken() { - return this.data.colonToken; + return this._data?.colonToken; } set colonToken(value: any) { this.data.colonToken = value; } get whenFalse() { - return this.data.whenFalse; + return this._data?.whenFalse; } set whenFalse(value: any) { this.data.whenFalse = value; } get containsOnlyTriviaWhiteSpaces() { - return this.data.containsOnlyTriviaWhiteSpaces; + return this._data?.containsOnlyTriviaWhiteSpaces; } set containsOnlyTriviaWhiteSpaces(value: any) { this.data.containsOnlyTriviaWhiteSpaces = value; } get namespace() { - return this.data.namespace; + return this._data?.namespace; } set namespace(value: any) { this.data.namespace = value; } get token() { - return this.data.token; + return this._data?.token; } set token(value: any) { this.data.token = value; } get value() { - return this.data.value; + return this._data?.value; } set value(value: any) { this.data.value = value; } get tags() { - return this.data.tags; + return this._data?.tags; } set tags(value: any) { this.data.tags = value; } get class() { - return this.data.class; + return this._data?.class; } set class(value: any) { this.data.class = value; } get sourceFiles() { - return this.data.sourceFiles; + return this._data?.sourceFiles; } set sourceFiles(value: any) { this.data.sourceFiles = value; } get syntheticFileReferences() { - return this.data.syntheticFileReferences; + return this._data?.syntheticFileReferences; } set syntheticFileReferences(value: any) { this.data.syntheticFileReferences = value; } get syntheticTypeReferences() { - return this.data.syntheticTypeReferences; + return this._data?.syntheticTypeReferences; } set syntheticTypeReferences(value: any) { this.data.syntheticTypeReferences = value; } get syntheticLibReferences() { - return this.data.syntheticLibReferences; + return this._data?.syntheticLibReferences; } set syntheticLibReferences(value: any) { this.data.syntheticLibReferences = value; @@ -10442,31 +10471,51 @@ export class NodeImpl { // this.original = undefined; // this.emitNode = undefined; // } +class TokenImpl { + pos; // Node, Token, Identifier + end; // Node, Token, Identifier + kind; // Node, Token, Identifier + id = 0; // Node, Token, Identifier + flags = NodeFlags.None; // Node, Token, Identifier + transformFlags = TransformFlags.None; // Node, Token, Identifier + parent: Node = undefined!; // Node, Token, Identifier + emitNode = undefined; // Node, Token, Identifier -// 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; -// } + constructor(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; + } + get data() { + return this; + } +} -// 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; -// } +class IdentifierImpl { + pos; // Node, Token, Identifier + end; // Node, Token, Identifier + kind; // Node, Token, Identifier + id = 0; // Node, Token, Identifier + flags = NodeFlags.None; // Node, Token, Identifier + transformFlags = TransformFlags.None; // Node, Token, Identifier + parent: Node = undefined!; // Node, Token, Identifier + original: Node = undefined!; // Node, Token, Identifier + emitNode = undefined; // Node, Token, Identifier + escapedText = undefined; + jsDoc = undefined; // initialized by parser (JsDocContainer) + flowNode = undefined; // initialized by binder (FlowContainer) + symbol = undefined!; // initialized by checker + constructor(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; + } + get data() { + return this; + } +} 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 @@ -10478,9 +10527,9 @@ function SourceMapSource(this: SourceMapSource, fileName: string, text: string, /** @internal */ export const objectAllocator: ObjectAllocator = { getNodeConstructor: () => NodeImpl as any, - getTokenConstructor: () => NodeImpl as any, - getIdentifierConstructor: () => NodeImpl as any, - getPrivateIdentifierConstructor: () => NodeImpl as any, + getTokenConstructor: () => TokenImpl as any, + getIdentifierConstructor: () => IdentifierImpl as any, + getPrivateIdentifierConstructor: () => IdentifierImpl as any, getSourceFileConstructor: () => NodeImpl as any, getSymbolConstructor: () => Symbol as any, getTypeConstructor: () => TypeImpl as any, diff --git a/src/harness/typeWriter.ts b/src/harness/typeWriter.ts index e09f8bd56a272..4d1ca8e8a8185 100644 --- a/src/harness/typeWriter.ts +++ b/src/harness/typeWriter.ts @@ -314,8 +314,8 @@ export class TypeWriterWalker { } count++; symbolString += ", "; - if ((declaration as any).__symbolTestOutputCache) { - symbolString += (declaration as any).__symbolTestOutputCache; + if ((declaration as any).data.__symbolTestOutputCache) { + symbolString += (declaration as any).data.__symbolTestOutputCache; continue; } const declSourceFile = declaration.getSourceFile(); @@ -324,7 +324,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; + (declaration as any).data.__symbolTestOutputCache = declText; } } symbolString += ")"; diff --git a/src/services/services.ts b/src/services/services.ts index 4b006d76a84eb..6509640507f41 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -60,6 +60,7 @@ import { EditorOptions, EditorSettings, ElementAccessExpression, + EmitNode, EmitTextWriter, emptyArray, emptyOptions, @@ -193,6 +194,7 @@ import { isTextWhiteSpaceLike, isThisTypeParameter, isTransientSymbol, + JSDoc, JsDoc, JSDocContainer, JSDocParsingMode, @@ -320,12 +322,15 @@ import { timestamp, TodoComment, TodoCommentDescriptor, + Token, toPath, tracing, + TransformFlags, Type, TypeChecker, TypeFlags, TypeImpl, + TypeNode, TypeParameter, TypeReference, typeToDisplayParts, @@ -372,16 +377,6 @@ class NodeObject extends NodeImpl implements Node { constructor(kind: TKind, pos: number, end: number) { super(kind, pos, end); } - - override get text(): string { - if (this.kind === SyntaxKind.Identifier || this.kind === SyntaxKind.PrivateIdentifier) { - return idText(this as any as Identifier); - } - return super.text; - } - override set text(value) { - super.text = value; - } 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"); @@ -519,7 +514,7 @@ class NodeObject extends NodeImpl implements Node { public update(newText: string, textChangeRange: TextChangeRange): SourceFile { Debug.assertEqual(this.kind, SyntaxKind.SourceFile); - return updateSourceFile(this as SourceFile, newText, textChangeRange); + return updateSourceFile(this as any as SourceFile, newText, textChangeRange); } public getLineAndCharacterOfPosition(position: number): LineAndCharacter { @@ -783,6 +778,98 @@ function createSyntaxList(nodes: NodeArray, parent: Node): Node { 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; + get data() { + return this; + } + + 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; @@ -917,6 +1004,37 @@ 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 = undefined!; + public original?: Node | undefined = undefined; + 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; + jsDoc = undefined; // initialized by parser (JsDocContainer) + flowNode = undefined; // initialized by binder (FlowContainer) + constructor(kind: SyntaxKind.Identifier, pos: number, end: number) { + super(kind, pos, end); + this.jsDocComments = undefined; + this.symbol = undefined!; + } + + get text(): string { + return idText(this); + } +} class TypeObject extends TypeImpl implements Type { getFlags(): TypeFlags { return this.flags; @@ -1131,12 +1249,12 @@ class SourceMapSourceObject implements SourceMapSource { function getServicesObjectAllocator(): ObjectAllocator { return { - getNodeConstructor: () => NodeObject, - getTokenConstructor: () => NodeObject, + getNodeConstructor: () => NodeObject as any, + getTokenConstructor: () => TokenObject as any, - getIdentifierConstructor: () => NodeObject, - getPrivateIdentifierConstructor: () => NodeObject, - getSourceFileConstructor: () => NodeObject, + getIdentifierConstructor: () => IdentifierObject as any, + getPrivateIdentifierConstructor: () => IdentifierObject as any, + getSourceFileConstructor: () => NodeObject as any, getSymbolConstructor: () => SymbolObject, getTypeConstructor: () => TypeObject, getSignatureConstructor: () => SignatureObject, From 7ff37c06ca022f64d7d1af6a1a964e865e357ade Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Mon, 24 Jun 2024 17:58:39 +0100 Subject: [PATCH 05/13] Ensure we only have one shape for node arrays. --- src/compiler/factory/nodeFactory.ts | 56 +++++++++++++---------------- src/compiler/utilities.ts | 10 ++++++ 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 9b51d733ed17c..8d3394e6994cd 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -56,6 +56,7 @@ import { containsObjectRestOrSpread, ContinueStatement, createBaseNodeFactory, + createEmptyObjectArray, createNodeConverters, createParenthesizerRules, createScanner, @@ -1173,10 +1174,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNodeArray(elements?: readonly T[], hasTrailingComma?: boolean): NodeArray { - if (elements === undefined || elements === emptyArray) { - elements = []; - } - else if (isNodeArray(elements)) { + let pos = -1; + let end = -1; + let transformFlags; + if (elements !== undefined && isNodeArray(elements)) { if (hasTrailingComma === undefined || elements.hasTrailingComma === hasTrailingComma) { // Ensure the transform flags have been aggregated for this NodeArray if (elements.transformFlags === undefined) { @@ -1189,25 +1190,27 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // 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; + pos = elements.pos; + end = elements.end; + transformFlags = elements.transformFlags; + elements = elements.slice(); + } + else if (elements === undefined || elements === emptyArray || elements.length === 0) { + // Ensure we have an object array + elements = createEmptyObjectArray(); } - // 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; + const array = elements as MutableNodeArray; + array.pos = pos; + array.end = end; array.hasTrailingComma = !!hasTrailingComma; - array.transformFlags = TransformFlags.None; - aggregateChildrenFlags(array); + if(transformFlags === undefined) { + array.transformFlags = TransformFlags.None; + aggregateChildrenFlags(array); + } + else { + array.transformFlags = transformFlags; + } Debug.attachNodeArrayDebugInfo(array); return array; } @@ -6533,16 +6536,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode if (isPrivateIdentifier(node)) { return clonePrivateIdentifier(node) as T & PrivateIdentifier; } - - const kind = node.kind; - const isSimpleToken = !isNodeKind(kind) - && kind !== SyntaxKind.SuperKeyword && kind !== SyntaxKind.ThisKeyword - && kind !== SyntaxKind.TemplateLiteralTypeSpan - && !isLiteralKind(kind); - - const clone = isSimpleToken ? - baseFactory.createBaseTokenNode(kind) as T : - baseFactory.createBaseNode(kind) as T; + const clone = baseFactory.createBaseNode(node.kind); (clone as unknown as NodeData).flags |= node.flags & ~NodeFlags.Synthesized; (clone as unknown as NodeData).transformFlags = node.transformFlags; @@ -6550,7 +6544,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = (node as any).data ?? node; const cloneData = (clone as any).data ?? clone; for (const key in nodeData) { - if (hasProperty(cloneData, key) || !hasProperty(nodeData, key)) { + if (hasProperty(cloneData, key) || hasProperty(clone, key) || !hasProperty(nodeData, key)) { continue; } (clone as any)[key] = nodeData[key]; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4da3dd41635e6..8bb9cd11e49d6 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -13974,3 +13974,13 @@ export function hasInferredType(node: Node): node is HasInferredType { return false; } } + +const objectArray = [{} as never]; +/** + * @internal + * Ensures V8 creates a PACKED_ELEMENTS array and not a PACKED_SMI_ELEMENTS array + **/ +export function createEmptyObjectArray(): T[] { + const elements = objectArray.slice(0,0); + return elements as T[]; +} \ No newline at end of file From 8b8d60b858911d50f92996d2cec0f81eb38b5280 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Wed, 26 Jun 2024 18:27:58 +0100 Subject: [PATCH 06/13] Reduce memory usage for Node data --- src/compiler/factory/nodeFactory.ts | 2132 +++++++++++++++------------ src/compiler/utilities.ts | 546 ++++--- src/services/services.ts | 150 +- 3 files changed, 1454 insertions(+), 1374 deletions(-) diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 8d3394e6994cd..290dc96189499 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -56,7 +56,6 @@ import { containsObjectRestOrSpread, ContinueStatement, createBaseNodeFactory, - createEmptyObjectArray, createNodeConverters, createParenthesizerRules, createScanner, @@ -179,7 +178,6 @@ import { isIndexSignatureDeclaration, isInterfaceDeclaration, isLabeledStatement, - isLiteralKind, isLocalName, isLogicalOrCoalescingAssignmentOperator, isMemberName, @@ -478,12 +476,10 @@ export const enum NodeFactoryFlags { } const nodeFactoryPatchers: ((factory: NodeFactory) => void)[] = []; -type NodeData = Readonly> & { - flags: NodeFlags; - original?: Node; - transformFlags: TransformFlags; - emitNode: EmitNode | undefined; - data: Mutable>; +type NodeData = Readonly> & + Mutable>> & +{ + data: Partial | Exclude>>> | undefined; }; /** @internal */ export function addNodeFactoryPatcher(fn: (factory: NodeFactory) => void) { @@ -1174,10 +1170,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNodeArray(elements?: readonly T[], hasTrailingComma?: boolean): NodeArray { - let pos = -1; - let end = -1; - let transformFlags; - if (elements !== undefined && isNodeArray(elements)) { + if (elements === undefined || elements === emptyArray) { + 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) { @@ -1190,47 +1186,42 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // 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` - pos = elements.pos; - end = elements.end; - transformFlags = elements.transformFlags; - elements = elements.slice(); - } - else if (elements === undefined || elements === emptyArray || elements.length === 0) { - // Ensure we have an object array - elements = createEmptyObjectArray(); - } - - const array = elements as MutableNodeArray; - array.pos = pos; - array.end = end; - array.hasTrailingComma = !!hasTrailingComma; - if(transformFlags === undefined) { - array.transformFlags = TransformFlags.None; - aggregateChildrenFlags(array); - } - else { - array.transformFlags = transformFlags; + 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 NodeData; + return baseFactory.createBaseNode(kind) as any as NodeData; } function createBaseDeclaration(kind: T["kind"]) { const node = createBaseNode(kind); - const nodeData = node.data; - nodeData.symbol = undefined!; // initialized by binder - nodeData.localSymbol = undefined; // initialized by binder return node; } function finishUpdateBaseSignatureDeclaration(updated: T, original: T) { if (updated !== original) { // copy children used for quick info - (updated as unknown as NodeData).data.typeArguments = original.typeArguments; + (updated as unknown as NodeData).data!.typeArguments = original.typeArguments!; } return update(updated, original); } @@ -1244,9 +1235,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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); - const nodeData = node.data; - nodeData.text = text; - nodeData.numericLiteralFlags = numericLiteralFlags; + node.data = { + numericLiteralFlags: numericLiteralFlags, + hasExtendedUnicodeEscape: false, + isUnterminated: false, + text: text, + // localSymbol: undefined! + } if (numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier) node.transformFlags |= TransformFlags.ContainsES2015; return node; } @@ -1254,38 +1249,49 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBigIntLiteral(value: string | PseudoBigInt): BigIntLiteral { const node = createBaseToken(SyntaxKind.BigIntLiteral); - node.data.text = typeof value === "string" ? value : pseudoBigIntToString(value) + "n"; + node.data = { + hasExtendedUnicodeEscape: false, + isUnterminated: false, + 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); - const nodeData = node.data; - nodeData.text = text; - nodeData.singleQuote = isSingleQuote; - return node; + return createBaseDeclaration(SyntaxKind.StringLiteral); } // @api function createStringLiteral(text: string, isSingleQuote?: boolean, hasExtendedUnicodeEscape?: boolean): StringLiteral { const node = createBaseStringLiteral(text, isSingleQuote); - node.data.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape; + node.data = { + hasExtendedUnicodeEscape: !!hasExtendedUnicodeEscape, + singleQuote: !!isSingleQuote, + // isUnterminated: false, + text, + // textSourceNode: undefined!, + // localSymbol: undefined!, + }; if (hasExtendedUnicodeEscape) node.transformFlags |= TransformFlags.ContainsES2015; return node; } // @api function createStringLiteralFromNode(sourceNode: PropertyNameLiteral | PrivateIdentifier): StringLiteral { - const node = createBaseStringLiteral(getTextOfIdentifierOrLiteral(sourceNode), /*isSingleQuote*/ undefined); - node.data.textSourceNode = sourceNode; + const node = createStringLiteral(getTextOfIdentifierOrLiteral(sourceNode), /*isSingleQuote*/ undefined, /*hasExtendedUnicodeEscape*/ undefined) as NodeData; + node.data!.textSourceNode = sourceNode; return node; } // @api function createRegularExpressionLiteral(text: string): RegularExpressionLiteral { - const node = createBaseNode(SyntaxKind.RegularExpressionLiteral); - node.data.text = text; + const node = createBaseToken(SyntaxKind.RegularExpressionLiteral); + node.data = { + hasExtendedUnicodeEscape: false, + isUnterminated: false, + text, + }; return node; } @@ -1314,12 +1320,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // function createBaseIdentifier(escapedText: __String) { - const node = baseFactory.createBaseIdentifierNode(SyntaxKind.Identifier) as NodeData; - const nodeData = node.data; - nodeData.escapedText = escapedText; - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) - nodeData.symbol = undefined!; // initialized by checker + const node = baseFactory.createBaseIdentifierNode(SyntaxKind.Identifier) as Mutable; + node.escapedText = escapedText; return node; } @@ -1400,7 +1402,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createBasePrivateIdentifier(escapedText: __String) { const node = baseFactory.createBasePrivateIdentifierNode(SyntaxKind.PrivateIdentifier) as NodeData; - node.data.escapedText = escapedText; + node.escapedText = escapedText; node.transformFlags |= TransformFlags.ContainsClassFields; return node; } @@ -1447,7 +1449,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // function createBaseToken(kind: T["kind"]) { - return baseFactory.createBaseTokenNode(kind) as NodeData; + return baseFactory.createBaseTokenNode(kind) as any as NodeData; } // @api @@ -1468,28 +1470,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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"); - - if (token === SyntaxKind.EndOfFileToken) { - const node = createBaseNode(token); - node.data.jsDoc = undefined; - return node; - } - if (token === SyntaxKind.ThisKeyword) { - const node = createBaseNode(token); - // 'this' indicates a lexical 'this' - node.transformFlags = TransformFlags.ContainsLexicalThis; - (node as NodeData> as NodeData).data.flowNode = undefined; // initialized by binder (FlowContainer) - return node; - } - - if (token === SyntaxKind.SuperKeyword) { - const node = createBaseNode(token); - - node.transformFlags = TransformFlags.ContainsES2015 | TransformFlags.ContainsLexicalSuper; - (node as NodeData> as NodeData).data.flowNode = undefined; // initialized by binder (FlowContainer) - return node; - } - const node = createBaseToken>(token); let transformFlags = TransformFlags.None; switch (token) { @@ -1526,12 +1506,21 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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 NodeData> as NodeData).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 NodeData> as NodeData).flowNode = undefined; // initialized by binder (FlowContainer) + break; } if (transformFlags) { node.transformFlags |= transformFlags; @@ -1605,13 +1594,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createQualifiedName(left: EntityName, right: string | Identifier) { const node = createBaseNode(SyntaxKind.QualifiedName); - const nodeData = node.data; - nodeData.left = left; - nodeData.right = asName(right); + const nodeData = node.data = { + left: left, + right: asName(right), + }; node.transformFlags |= propagateChildFlags(nodeData.left) | propagateIdentifierNameFlags(nodeData.right); - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + node.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -1626,7 +1616,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createComputedPropertyName(expression: Expression) { const node = createBaseNode(SyntaxKind.ComputedPropertyName); - node.data.expression = parenthesizerRules().parenthesizeExpressionOfComputedPropertyName(expression); + node.data = { + expression: parenthesizerRules().parenthesizeExpressionOfComputedPropertyName(expression), + }; node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsES2015 | TransformFlags.ContainsComputedPropertyName; @@ -1647,15 +1639,16 @@ 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); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.name = asName(name); - nodeData.constraint = constraint; - nodeData.default = defaultType; node.transformFlags = TransformFlags.ContainsTypeScript; - - nodeData.expression = undefined; // initialized by parser to report grammar errors - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + node.data = { + modifiers : asNodeArray(modifiers), + name : asName(name), + constraint : constraint, + default : defaultType, + expression : undefined, // initialized by parser to report grammar errors + localSymbol: undefined, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -1679,13 +1672,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode initializer?: Expression, ) { const node = createBaseDeclaration(SyntaxKind.Parameter); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.dotDotDotToken = dotDotDotToken; - nodeData.name = asName(name); - nodeData.questionToken = questionToken; - nodeData.type = type; - nodeData.initializer = asInitializer(initializer); + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + dotDotDotToken: dotDotDotToken, + name: asName(name), + questionToken: questionToken, + type: type, + initializer: asInitializer(initializer), + // localSymbol: undefined + } if (isThisIdentifier(nodeData.name)) { node.transformFlags = TransformFlags.ContainsTypeScript; @@ -1701,7 +1696,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (modifiersToFlags(nodeData.modifiers) & ModifierFlags.ParameterPropertyModifier ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None); } - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -1728,7 +1723,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createDecorator(expression: Expression) { const node = createBaseNode(SyntaxKind.Decorator); - node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); + node.data = { + expression: parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false), + }; node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsTypeScript | TransformFlags.ContainsTypeScriptClassSyntax | @@ -1755,15 +1752,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode | undefined, ) { const node = createBaseDeclaration(SyntaxKind.PropertySignature); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.name = asName(name); - nodeData.type = type; - nodeData.questionToken = questionToken; + node.data = { + modifiers: asNodeArray(modifiers), + name: asName(name), + type: type, + questionToken: questionToken, + initializer: undefined, // initialized by parser to report grammar errors + localSymbol: undefined, + }; node.transformFlags = TransformFlags.ContainsTypeScript; - nodeData.initializer = undefined; // initialized by parser to report grammar errors - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -1786,7 +1785,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function finishUpdatePropertySignature(updated: NodeData, original: PropertySignature) { if (updated !== original) { // copy children used only for error reporting - updated.data.initializer = original.initializer; + updated.data!.initializer = original.initializer; } return update(updated, original); } @@ -1800,13 +1799,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode initializer: Expression | undefined, ) { const node = createBaseDeclaration(SyntaxKind.PropertyDeclaration); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.name = asName(name); - nodeData.questionToken = questionOrExclamationToken && isQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined; - nodeData.exclamationToken = questionOrExclamationToken && isExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined; - nodeData.type = type; - nodeData.initializer = asInitializer(initializer); + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + name: asName(name), + questionToken: questionOrExclamationToken && isQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined, + exclamationToken: questionOrExclamationToken && isExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined, + type: type, + initializer: asInitializer(initializer), + } const isAmbient = node.flags & NodeFlags.Ambient || modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient; @@ -1817,7 +1817,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (isComputedPropertyName(nodeData.name) || modifiersToFlags(nodeData.modifiers) & ModifierFlags.Static && nodeData.initializer ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None) | TransformFlags.ContainsClassFields; - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -1850,19 +1850,20 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode | undefined, ) { const node = createBaseDeclaration(SyntaxKind.MethodSignature); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.name = asName(name); - nodeData.questionToken = questionToken; - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.parameters = asNodeArray(parameters); - nodeData.type = type; node.transformFlags = TransformFlags.ContainsTypeScript; - - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.typeArguments = undefined; // used in quick info + node.data = { + modifiers: asNodeArray(modifiers), + name: asName(name), + questionToken: questionToken, + typeParameters: asNodeArray(typeParameters), + parameters: asNodeArray(parameters), + type: type, + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + typeArguments: undefined, // used in quick info + localSymbol: undefined, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -1898,17 +1899,25 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode body: Block | undefined, ) { const node = createBaseDeclaration(SyntaxKind.MethodDeclaration); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.asteriskToken = asteriskToken; - nodeData.name = asName(name); - nodeData.questionToken = questionToken; - nodeData.exclamationToken = undefined; // initialized by parser for grammar errors - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.parameters = createNodeArray(parameters); - nodeData.type = type; - nodeData.body = body; - + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + asteriskToken: asteriskToken, + name: asName(name), + questionToken: questionToken, + exclamationToken: undefined, // initialized by parser for grammar errors + typeParameters: asNodeArray(typeParameters), + parameters: createNodeArray(parameters), + type: type, + body: body, + typeArguments: undefined, // used in quick inf, + locals: undefined, // initialized by binder (LocalsContainer, + nextContainer: undefined, // initialized by binder (LocalsContainer) + endFlowNode: undefined, + returnFlowNode: undefined, + localSymbol: undefined, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) if (!nodeData.body) { node.transformFlags = TransformFlags.ContainsTypeScript; } @@ -1933,13 +1942,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode TransformFlags.ContainsES2015; } - nodeData.typeArguments = undefined; // used in quick info - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) - nodeData.endFlowNode = undefined; - nodeData.returnFlowNode = undefined; return node; } @@ -1970,7 +1972,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function finishUpdateMethodDeclaration(updated: NodeData, original: MethodDeclaration) { if (updated !== original) { // copy children used only for error reporting - updated.data.exclamationToken = original.exclamationToken; + updated.data!.exclamationToken = original.exclamationToken; } return update(updated, original); } @@ -1980,16 +1982,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode body: Block, ) { const node = createBaseDeclaration(SyntaxKind.ClassStaticBlockDeclaration); - const nodeData = node.data; - nodeData.body = body; node.transformFlags = propagateChildFlags(body) | TransformFlags.ContainsClassFields; - - nodeData.modifiers = undefined; // initialized by parser for grammar errors - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.endFlowNode = undefined; - nodeData.returnFlowNode = undefined; + node.data = { + body: body, + modifiers: undefined, // initialized by parser for grammar errors + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + endFlowNode: undefined, + returnFlowNode: undefined, + name: undefined, + // localSymbol: undefined + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2006,7 +2010,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function finishUpdateClassStaticBlockDeclaration(updated: NodeData, original: ClassStaticBlockDeclaration) { if (updated !== original) { // copy children used only for error reporting - updated.data.modifiers = original.modifiers; + updated.data!.modifiers = original.modifiers; } return update(updated, original); } @@ -2018,24 +2022,30 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode body: Block | undefined, ) { const node = createBaseDeclaration(SyntaxKind.Constructor); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.parameters = createNodeArray(parameters); - nodeData.body = body; - + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + parameters: createNodeArray(parameters), + body: body, + typeParameters: undefined, // initialized by parser for grammar errors + type: undefined, // initialized by parser for grammar errors + typeArguments: undefined, // used in quick info + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + endFlowNode: undefined, + returnFlowNode: undefined, + localSymbol: undefined, + // asteriskToken: undefined, + // exclamationToken: undefined, + // name: undefined, + // questionToken: undefined, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + node.transformFlags = propagateChildrenFlags(nodeData.modifiers) | propagateChildrenFlags(nodeData.parameters) | (propagateChildFlags(nodeData.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | TransformFlags.ContainsES2015; - nodeData.typeParameters = undefined; // initialized by parser for grammar errors - nodeData.type = undefined; // initialized by parser for grammar errors - nodeData.typeArguments = undefined; // used in quick info - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.endFlowNode = undefined; - nodeData.returnFlowNode = undefined; return node; } @@ -2055,8 +2065,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function finishUpdateConstructorDeclaration(updated: NodeData, original: ConstructorDeclaration) { if (updated !== original) { - updated.data.typeParameters = original.typeParameters; - updated.data.type = original.type; + updated.data!.typeParameters = original.typeParameters; + updated.data!.type = original.type; } return finishUpdateBaseSignatureDeclaration(updated, original); } @@ -2070,12 +2080,25 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode body: Block | undefined, ) { const node = createBaseDeclaration(SyntaxKind.GetAccessor); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.name = asName(name); - nodeData.parameters = createNodeArray(parameters); - nodeData.type = type; - nodeData.body = body; + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + name: asName(name), + parameters: createNodeArray(parameters), + type: type, + body: body, + typeArguments: undefined, // used in quick info, + typeParameters: undefined, // initialized by parser for grammar errors, + locals: undefined, // initialized by binder (LocalsContainer), + nextContainer: undefined, // initialized by binder (LocalsContainer), + endFlowNode: undefined, + returnFlowNode: undefined, + // asteriskToken: undefined, + // exclamationToken: undefined, + localSymbol: undefined, + // questionToken: undefined + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) if (!nodeData.body) { node.transformFlags = TransformFlags.ContainsTypeScript; @@ -2089,14 +2112,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (nodeData.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); } - nodeData.typeArguments = undefined; // used in quick info - nodeData.typeParameters = undefined; // initialized by parser for grammar errors - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) - nodeData.endFlowNode = undefined; - nodeData.returnFlowNode = undefined; return node; } @@ -2121,7 +2136,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function finishUpdateGetAccessorDeclaration(updated: NodeData, original: GetAccessorDeclaration) { if (updated !== original) { // copy children used only for error reporting - updated.data.typeParameters = original.typeParameters; + updated.data!.typeParameters = original.typeParameters; } return finishUpdateBaseSignatureDeclaration(updated, original); } @@ -2134,12 +2149,26 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode body: Block | undefined, ) { const node = createBaseDeclaration(SyntaxKind.SetAccessor); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.name = asName(name); - nodeData.parameters = createNodeArray(parameters); - nodeData.body = body; - + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + name: asName(name), + parameters: createNodeArray(parameters), + body: body, + typeArguments: undefined, // used in quick info + typeParameters: undefined, // initialized by parser for grammar errors + type: undefined, // initialized by parser for grammar errors + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + endFlowNode: undefined, + returnFlowNode: undefined, + // asteriskToken: undefined, + // exclamationToken: undefined, + localSymbol: undefined, + // questionToken: undefined, + } + + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) if (!nodeData.body) { node.transformFlags = TransformFlags.ContainsTypeScript; } @@ -2151,15 +2180,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (nodeData.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); } - nodeData.typeArguments = undefined; // used in quick info - nodeData.typeParameters = undefined; // initialized by parser for grammar errors - nodeData.type = undefined; // initialized by parser for grammar errors - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) - nodeData.endFlowNode = undefined; - nodeData.returnFlowNode = undefined; return node; } @@ -2182,8 +2202,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function finishUpdateSetAccessorDeclaration(updated: NodeData, original: SetAccessorDeclaration) { if (updated !== original) { // copy children used only for error reporting - updated.data.typeParameters = original.typeParameters; - updated.data.type = original.type; + updated.data!.typeParameters = original.typeParameters; + updated.data!.type = original.type; } return finishUpdateBaseSignatureDeclaration(updated, original); } @@ -2195,16 +2215,20 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode | undefined, ): CallSignatureDeclaration { const node = createBaseDeclaration(SyntaxKind.CallSignature); - const nodeData = node.data; - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.parameters = asNodeArray(parameters); - nodeData.type = type; node.transformFlags = TransformFlags.ContainsTypeScript; - - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.typeArguments = undefined; // used in quick info + node.data = { + typeParameters: asNodeArray(typeParameters), + parameters: asNodeArray(parameters), + type: type, + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + typeArguments: undefined, // used in quick info + localSymbol: undefined, + // name: undefined, + // questionToken: undefined, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2229,16 +2253,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode | undefined, ): ConstructSignatureDeclaration { const node = createBaseDeclaration(SyntaxKind.ConstructSignature); - const nodeData = node.data; - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.parameters = asNodeArray(parameters); - nodeData.type = type; - node.transformFlags = TransformFlags.ContainsTypeScript; - - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.typeArguments = undefined; // used in quick info + node.transformFlags = TransformFlags.ContainsTypeScript, + node.data = { + typeParameters: asNodeArray(typeParameters), + parameters: asNodeArray(parameters), + type: type, + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + typeArguments: undefined, // used in quick info + localSymbol: undefined, + // name: undefined, + // questionToken: undefined + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2263,16 +2290,21 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode | undefined, ): IndexSignatureDeclaration { const node = createBaseDeclaration(SyntaxKind.IndexSignature); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.parameters = asNodeArray(parameters); - nodeData.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; - - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.typeArguments = undefined; // used in quick info + node.data = { + modifiers: asNodeArray(modifiers), + parameters: asNodeArray(parameters), + type: type!, // TODO(rbuckton): We mark this as required in IndexSignatureDeclaration, but it looks like the parser allows it to be elided. + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + typeArguments: undefined, // used in quick info + localSymbol: undefined, + // name: undefined, + // questionToken: undefined, + // typeParameters: undefined + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2293,10 +2325,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTemplateLiteralTypeSpan(type: TypeNode, literal: TemplateMiddle | TemplateTail) { const node = createBaseNode(SyntaxKind.TemplateLiteralTypeSpan); - const nodeData = node.data; - nodeData.type = type; - nodeData.literal = literal; node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + type: type, + literal: literal, + } return node; } @@ -2320,11 +2353,12 @@ 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); - const nodeData = node.data; - nodeData.assertsModifier = assertsModifier; - nodeData.parameterName = asName(parameterName); - nodeData.type = type; node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + assertsModifier: assertsModifier, + parameterName: asName(parameterName), + type: type, + } return node; } @@ -2340,10 +2374,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeReferenceNode(typeName: string | EntityName, typeArguments: readonly TypeNode[] | undefined) { const node = createBaseNode(SyntaxKind.TypeReference); - const nodeData = node.data; - nodeData.typeName = asName(typeName); - nodeData.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(createNodeArray(typeArguments)); node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + typeName: asName(typeName), + typeArguments: typeArguments && parenthesizerRules().parenthesizeTypeArguments(createNodeArray(typeArguments)), + }; return node; } @@ -2362,17 +2397,21 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode, ) { const node = createBaseDeclaration(SyntaxKind.FunctionType); - const nodeData = node.data; - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.parameters = asNodeArray(parameters); - nodeData.type = type; node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + typeParameters: asNodeArray(typeParameters), + parameters: asNodeArray(parameters), + type: type, + + modifiers: undefined, // initialized by parser for grammar errors + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + typeArguments: undefined, // used in quick info + localSymbol: undefined, + // name: undefined, + } - nodeData.modifiers = undefined; // initialized by parser for grammar errors - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.typeArguments = undefined; // used in quick info + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2393,7 +2432,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function finishUpdateFunctionTypeNode(updated: NodeData, original: FunctionTypeNode) { if (updated !== original) { // copy children used only for error reporting - updated.data.modifiers = original.modifiers; + updated.data!.modifiers = original.modifiers; } return finishUpdateBaseSignatureDeclaration(updated, original); } @@ -2412,17 +2451,20 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode, ): ConstructorTypeNode { const node = createBaseDeclaration(SyntaxKind.ConstructorType); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.parameters = asNodeArray(parameters); - nodeData.type = type; node.transformFlags = TransformFlags.ContainsTypeScript; - - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.typeArguments = undefined; // used in quick info + node.data = { + modifiers: asNodeArray(modifiers), + typeParameters: asNodeArray(typeParameters), + parameters: asNodeArray(parameters), + type: type, + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + typeArguments: undefined, // used in quick info + localSymbol: undefined, + // name: undefined, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2470,10 +2512,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeQueryNode(exprName: EntityName, typeArguments?: readonly TypeNode[]) { const node = createBaseNode(SyntaxKind.TypeQuery); - const nodeData = node.data; - nodeData.exprName = exprName; - nodeData.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + exprName: exprName, + typeArguments: typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments), + } return node; } @@ -2488,8 +2531,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeLiteralNode(members: readonly TypeElement[] | undefined) { const node = createBaseDeclaration(SyntaxKind.TypeLiteral); - node.data.members = createNodeArray(members); node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + members: createNodeArray(members), + localSymbol: undefined, + } return node; } @@ -2503,8 +2549,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createArrayTypeNode(elementType: TypeNode) { const node = createBaseNode(SyntaxKind.ArrayType); - node.data.elementType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(elementType); node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + elementType: parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(elementType), + } return node; } @@ -2518,8 +2566,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTupleTypeNode(elements: readonly (TypeNode | NamedTupleMember)[]) { const node = createBaseNode(SyntaxKind.TupleType); - node.data.elements = createNodeArray(parenthesizerRules().parenthesizeElementTypesOfTupleType(elements)); node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + elements: createNodeArray(parenthesizerRules().parenthesizeElementTypesOfTupleType(elements)), + } return node; } @@ -2533,14 +2583,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamedTupleMember(dotDotDotToken: DotDotDotToken | undefined, name: Identifier, questionToken: QuestionToken | undefined, type: TypeNode) { const node = createBaseDeclaration(SyntaxKind.NamedTupleMember); - const nodeData = node.data; - nodeData.dotDotDotToken = dotDotDotToken; - nodeData.name = name; - nodeData.questionToken = questionToken; - nodeData.type = type; node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + dotDotDotToken: dotDotDotToken, + name: name, + questionToken: questionToken, + type: type, + localSymbol: undefined, + }; - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2557,7 +2609,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createOptionalTypeNode(type: TypeNode) { const node = createBaseNode(SyntaxKind.OptionalType); - node.data.type = parenthesizerRules().parenthesizeTypeOfOptionalType(type); + node.data = { + type: parenthesizerRules().parenthesizeTypeOfOptionalType(type), + } node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2572,8 +2626,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createRestTypeNode(type: TypeNode) { const node = createBaseNode(SyntaxKind.RestType); - node.data.type = type; node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { type: type }; return node; } @@ -2586,8 +2640,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createUnionOrIntersectionTypeNode(kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType, types: readonly TypeNode[], parenthesize: (nodes: readonly TypeNode[]) => readonly TypeNode[]) { const node = createBaseNode(kind); - node.data.types = factory.createNodeArray(parenthesize(types)); node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + types: factory.createNodeArray(parenthesize(types)), + } return node; } @@ -2620,15 +2676,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createConditionalTypeNode(checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode) { const node = createBaseNode(SyntaxKind.ConditionalType); - const nodeData = node.data; - nodeData.checkType = parenthesizerRules().parenthesizeCheckTypeOfConditionalType(checkType); - nodeData.extendsType = parenthesizerRules().parenthesizeExtendsTypeOfConditionalType(extendsType); - nodeData.trueType = trueType; - nodeData.falseType = falseType; node.transformFlags = TransformFlags.ContainsTypeScript; - - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + node.data = { + checkType: parenthesizerRules().parenthesizeCheckTypeOfConditionalType(checkType), + extendsType: parenthesizerRules().parenthesizeExtendsTypeOfConditionalType(extendsType), + trueType: trueType, + falseType: falseType, + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + } return node; } @@ -2645,7 +2702,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createInferTypeNode(typeParameter: TypeParameterDeclaration) { const node = createBaseNode(SyntaxKind.InferType); - node.data.typeParameter = typeParameter; + node.data = { typeParameter: typeParameter } node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2660,10 +2717,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTemplateLiteralType(head: TemplateHead, templateSpans: readonly TemplateLiteralTypeSpan[]) { const node = createBaseNode(SyntaxKind.TemplateLiteralType); - const nodeData = node.data; - nodeData.head = head; - nodeData.templateSpans = createNodeArray(templateSpans); node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + head: head, + templateSpans: createNodeArray(templateSpans), + } return node; } @@ -2684,16 +2742,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode isTypeOf = false, ): ImportTypeNode { const node = createBaseNode(SyntaxKind.ImportType); - const nodeData = node.data; - nodeData.argument = argument; - nodeData.attributes = attributes; - if (nodeData.assertions && nodeData.assertions.assertClause && nodeData.attributes) { - (nodeData.assertions as NodeData).data.assertClause = nodeData.attributes; - } - nodeData.qualifier = qualifier; - nodeData.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); - nodeData.isTypeOf = isTypeOf; node.transformFlags = TransformFlags.ContainsTypeScript; + const nodeData = node.data = { + argument: argument, + attributes: attributes, + qualifier: qualifier, + typeArguments: typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments), + isTypeOf: isTypeOf, + } + + // dragomirtitian: Seems unused + // if (nodeData.assertions && nodeData.assertions.assertClause && nodeData.attributes) { + // (nodeData.assertions as NodeData).data.assertClause = nodeData.attributes; + // } return node; } @@ -2718,7 +2779,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createParenthesizedType(type: TypeNode) { const node = createBaseNode(SyntaxKind.ParenthesizedType); - node.data.type = type; + node.data = { type: type } node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2740,12 +2801,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: TypeNode): TypeOperatorNode { const node = createBaseNode(SyntaxKind.TypeOperator); - const nodeData = node.data; - nodeData.operator = operator; - nodeData.type = operator === SyntaxKind.ReadonlyKeyword ? - parenthesizerRules().parenthesizeOperandOfReadonlyTypeOperator(type) : - parenthesizerRules().parenthesizeOperandOfTypeOperator(type); node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + operator: operator, + type: operator === SyntaxKind.ReadonlyKeyword ? + parenthesizerRules().parenthesizeOperandOfReadonlyTypeOperator(type) : + parenthesizerRules().parenthesizeOperandOfTypeOperator(type), + } return node; } @@ -2759,10 +2821,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createIndexedAccessTypeNode(objectType: TypeNode, indexType: TypeNode) { const node = createBaseNode(SyntaxKind.IndexedAccessType); - const nodeData = node.data; - nodeData.objectType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(objectType); - nodeData.indexType = indexType; node.transformFlags = TransformFlags.ContainsTypeScript; + node.data = { + objectType: parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(objectType), + indexType: indexType, + } return node; } @@ -2777,17 +2840,20 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); - const nodeData = node.data; - nodeData.readonlyToken = readonlyToken; - nodeData.typeParameter = typeParameter; - nodeData.nameType = nameType; - nodeData.questionToken = questionToken; - nodeData.type = type; - nodeData.members = members && createNodeArray(members); node.transformFlags = TransformFlags.ContainsTypeScript; - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + node.data = { + readonlyToken: readonlyToken, + typeParameter: typeParameter, + nameType: nameType, + questionToken: questionToken, + type: type, + members: members && createNodeArray(members), + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + localSymbol: undefined, + } return node; } @@ -2806,7 +2872,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createLiteralTypeNode(literal: LiteralTypeNode["literal"]) { const node = createBaseNode(SyntaxKind.LiteralType); - node.data.literal = literal; + node.data = { literal: literal } node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2825,7 +2891,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createObjectBindingPattern(elements: readonly BindingElement[]) { const node = createBaseNode(SyntaxKind.ObjectBindingPattern); - node.data.elements = createNodeArray(elements); + node.data = { elements: createNodeArray(elements) } node.transformFlags |= propagateChildrenFlags(node.elements) | TransformFlags.ContainsES2015 | TransformFlags.ContainsBindingPattern; @@ -2846,7 +2912,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createArrayBindingPattern(elements: readonly ArrayBindingElement[]) { const node = createBaseNode(SyntaxKind.ArrayBindingPattern); - node.data.elements = createNodeArray(elements); + node.data = { elements: createNodeArray(elements) } node.transformFlags |= propagateChildrenFlags(node.elements) | TransformFlags.ContainsES2015 | TransformFlags.ContainsBindingPattern; @@ -2863,11 +2929,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBindingElement(dotDotDotToken: DotDotDotToken | undefined, propertyName: string | PropertyName | undefined, name: string | BindingName, initializer?: Expression) { const node = createBaseDeclaration(SyntaxKind.BindingElement); - const nodeData = node.data; - nodeData.dotDotDotToken = dotDotDotToken; - nodeData.propertyName = asName(propertyName); - nodeData.name = asName(name); - nodeData.initializer = asInitializer(initializer); + const nodeData = node.data = { + dotDotDotToken: dotDotDotToken, + propertyName: asName(propertyName), + name: asName(name), + initializer: asInitializer(initializer), + localSymbol: undefined, + } node.transformFlags |= propagateChildFlags(nodeData.dotDotDotToken) | propagateNameFlags(nodeData.propertyName) | propagateNameFlags(nodeData.name) | @@ -2875,7 +2943,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (nodeData.dotDotDotToken ? TransformFlags.ContainsRestOrSpread : TransformFlags.None) | TransformFlags.ContainsES2015; - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -2901,9 +2969,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // a trailing comma. const lastElement = elements && lastOrUndefined(elements); const elementsArray = createNodeArray(elements, lastElement && isOmittedExpression(lastElement) ? true : undefined); - const nodeData = node.data; - nodeData.elements = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(elementsArray); - nodeData.multiLine = multiLine; + const nodeData = node.data = { + elements: parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(elementsArray), + multiLine: multiLine, + }; node.transformFlags |= propagateChildrenFlags(node.elements); return node; } @@ -2918,12 +2987,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createObjectLiteralExpression(properties?: readonly ObjectLiteralElementLike[], multiLine?: boolean) { const node = createBaseDeclaration(SyntaxKind.ObjectLiteralExpression); - const nodeData = node.data; - nodeData.properties = createNodeArray(properties); - nodeData.multiLine = multiLine; + node.data = { + properties: createNodeArray(properties), + multiLine: multiLine, + localSymbol: undefined, + } node.transformFlags |= propagateChildrenFlags(node.properties); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2936,18 +3007,20 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createBasePropertyAccessExpression(expression: LeftHandSideExpression, questionDotToken: QuestionDotToken | undefined, name: MemberName) { const node = createBaseDeclaration(SyntaxKind.PropertyAccessExpression); - const nodeData = node.data; - nodeData.expression = expression; - nodeData.questionDotToken = questionDotToken; - nodeData.name = name; + const nodeData = node.data = { + expression: expression, + questionDotToken: questionDotToken, + name: name, + localSymbol: undefined, + }; node.transformFlags = propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.questionDotToken) | (isIdentifier(nodeData.name) ? propagateIdentifierNameFlags(nodeData.name) : propagateChildFlags(nodeData.name) | TransformFlags.ContainsPrivateIdentifierInExpression); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3004,16 +3077,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createBaseElementAccessExpression(expression: LeftHandSideExpression, questionDotToken: QuestionDotToken | undefined, argumentExpression: Expression) { const node = createBaseDeclaration(SyntaxKind.ElementAccessExpression); - const nodeData = node.data; - nodeData.expression = expression; - nodeData.questionDotToken = questionDotToken; - nodeData.argumentExpression = argumentExpression; + const nodeData = node.data = { + expression: expression, + questionDotToken: questionDotToken, + argumentExpression: argumentExpression, + localSymbol: undefined, + } node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.questionDotToken) | propagateChildFlags(nodeData.argumentExpression); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3070,11 +3145,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createBaseCallExpression(expression: LeftHandSideExpression, questionDotToken: QuestionDotToken | undefined, typeArguments: NodeArray | undefined, argumentsArray: NodeArray) { const node = createBaseDeclaration(SyntaxKind.CallExpression); - const nodeData = node.data; - nodeData.expression = expression; - nodeData.questionDotToken = questionDotToken; - nodeData.typeArguments = typeArguments; - nodeData.arguments = argumentsArray; + const nodeData = node.data = { + expression: expression, + questionDotToken: questionDotToken, + typeArguments: typeArguments, + arguments: argumentsArray, + localSymbol: undefined, + } + node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.questionDotToken) | propagateChildrenFlags(nodeData.typeArguments) | @@ -3141,10 +3219,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNewExpression(expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined) { const node = createBaseDeclaration(SyntaxKind.NewExpression); - const nodeData = node.data; - nodeData.expression = parenthesizerRules().parenthesizeExpressionOfNew(expression); - nodeData.typeArguments = asNodeArray(typeArguments); - nodeData.arguments = argumentsArray ? parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(argumentsArray) : undefined; + const nodeData = node.data = { + expression: parenthesizerRules().parenthesizeExpressionOfNew(expression), + typeArguments: asNodeArray(typeArguments), + arguments: argumentsArray ? parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(argumentsArray) : undefined, + localSymbol: undefined, + }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildrenFlags(nodeData.typeArguments) | propagateChildrenFlags(nodeData.arguments) | @@ -3167,10 +3247,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTaggedTemplateExpression(tag: Expression, typeArguments: readonly TypeNode[] | undefined, template: TemplateLiteral) { const node = createBaseNode(SyntaxKind.TaggedTemplateExpression); - const nodeData = node.data; - nodeData.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(tag, /*optionalChain*/ false); - nodeData.typeArguments = asNodeArray(typeArguments); - nodeData.template = template; + const nodeData = node.data = { + tag: parenthesizerRules().parenthesizeLeftSideOfAccess(tag, /*optionalChain*/ false), + typeArguments: asNodeArray(typeArguments), + template: template, + // questionDotToken: undefined, + } node.transformFlags |= propagateChildFlags(nodeData.tag) | propagateChildrenFlags(nodeData.typeArguments) | propagateChildFlags(nodeData.template) | @@ -3196,9 +3278,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeAssertion(type: TypeNode, expression: Expression) { const node = createBaseNode(SyntaxKind.TypeAssertionExpression); - const nodeData = node.data; - nodeData.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); - nodeData.type = type; + node.data = { + expression: parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression), + type: type, + }; node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.type) | TransformFlags.ContainsTypeScript; @@ -3216,11 +3299,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createParenthesizedExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.ParenthesizedExpression); - const nodeData = node.data; - nodeData.expression = expression; + node.data = { expression }; node.transformFlags = propagateChildFlags(node.expression); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -3242,14 +3324,27 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode body: Block, ) { const node = createBaseDeclaration(SyntaxKind.FunctionExpression); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.asteriskToken = asteriskToken; - nodeData.name = asName(name); - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.parameters = createNodeArray(parameters); - nodeData.type = type; - nodeData.body = body; + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + asteriskToken: asteriskToken, + name: asName(name), + typeParameters: asNodeArray(typeParameters), + parameters: createNodeArray(parameters), + type: type, + body: body, + + typeArguments: undefined, // used in quick info + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + endFlowNode: undefined, + returnFlowNode: undefined, + // exclamationToken: undefined, + localSymbol: undefined, + // questionToken: undefined, + } + + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) const isAsync = modifiersToFlags(nodeData.modifiers) & ModifierFlags.Async; const isGenerator = !!nodeData.asteriskToken; @@ -3269,13 +3364,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (nodeData.typeParameters || nodeData.type ? TransformFlags.ContainsTypeScript : TransformFlags.None) | TransformFlags.ContainsHoistedDeclarationOrCompletion; - nodeData.typeArguments = undefined; // used in quick info - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) - nodeData.endFlowNode = undefined; - nodeData.returnFlowNode = undefined; return node; } @@ -3311,13 +3399,27 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode body: ConciseBody, ) { const node = createBaseDeclaration(SyntaxKind.ArrowFunction); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.parameters = createNodeArray(parameters); - nodeData.type = type; - nodeData.equalsGreaterThanToken = equalsGreaterThanToken ?? createToken(SyntaxKind.EqualsGreaterThanToken); - nodeData.body = parenthesizerRules().parenthesizeConciseBodyOfArrowFunction(body); + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + typeParameters: asNodeArray(typeParameters), + parameters: createNodeArray(parameters), + type: type, + equalsGreaterThanToken: equalsGreaterThanToken ?? createToken(SyntaxKind.EqualsGreaterThanToken), + body: parenthesizerRules().parenthesizeConciseBodyOfArrowFunction(body), + + typeArguments: undefined, // used in quick info + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + endFlowNode: undefined, + returnFlowNode: undefined, + // asteriskToken: undefined, + // exclamationToken: undefined, + localSymbol: undefined, + // name: undefined, + // questionToken: undefined + }; + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) const isAsync = modifiersToFlags(nodeData.modifiers) & ModifierFlags.Async; @@ -3331,13 +3433,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (isAsync ? TransformFlags.ContainsES2017 | TransformFlags.ContainsLexicalThis : TransformFlags.None) | TransformFlags.ContainsES2015; - nodeData.typeArguments = undefined; // used in quick info - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) - nodeData.endFlowNode = undefined; - nodeData.returnFlowNode = undefined; return node; } @@ -3364,8 +3459,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createDeleteExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.DeleteExpression); - node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); node.transformFlags |= propagateChildFlags(node.expression); + node.data = { expression: parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression) } return node; } @@ -3379,7 +3474,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeOfExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.TypeOfExpression); - node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + node.data = { expression:parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression) }; node.transformFlags |= propagateChildFlags(node.expression); return node; } @@ -3394,7 +3489,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createVoidExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.VoidExpression); - node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + node.data = { expression: parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression) } node.transformFlags |= propagateChildFlags(node.expression); return node; } @@ -3409,7 +3504,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createAwaitExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.AwaitExpression); - node.data.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression); + node.data = { expression: parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression) }; node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsES2017 | TransformFlags.ContainsES2018 | @@ -3427,10 +3522,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createPrefixUnaryExpression(operator: PrefixUnaryOperator, operand: Expression) { const node = createBaseNode(SyntaxKind.PrefixUnaryExpression); - const nodeData = node.data; - nodeData.operator = operator; - nodeData.operand = parenthesizerRules().parenthesizeOperandOfPrefixUnary(operand); node.transformFlags |= propagateChildFlags(node.operand); + node.data = { + operator: operator, + operand: parenthesizerRules().parenthesizeOperandOfPrefixUnary(operand), + } // Only set this flag for non-generated identifiers and non-"local" names. See the // comment in `visitPreOrPostfixUnaryExpression` in module.ts if ( @@ -3454,9 +3550,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createPostfixUnaryExpression(operand: Expression, operator: PostfixUnaryOperator) { const node = createBaseNode(SyntaxKind.PostfixUnaryExpression); - const nodeData = node.data; - nodeData.operator = operator; - nodeData.operand = parenthesizerRules().parenthesizeOperandOfPostfixUnary(operand); + node.data = { + operator: operator, + 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 @@ -3482,10 +3579,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseDeclaration(SyntaxKind.BinaryExpression); const operatorToken = asToken(operator); const operatorKind = operatorToken.kind; - const nodeData = node.data; - nodeData.left = parenthesizerRules().parenthesizeLeftSideOfBinary(operatorKind, left); - nodeData.operatorToken = operatorToken; - nodeData.right = parenthesizerRules().parenthesizeRightSideOfBinary(operatorKind, node.left, right); + node.data = { + left: parenthesizerRules().parenthesizeLeftSideOfBinary(operatorKind, left), + operatorToken: operatorToken, + right: parenthesizerRules().parenthesizeRightSideOfBinary(operatorKind, node.left, right), + localSymbol: undefined, + } node.transformFlags |= propagateChildFlags(node.left) | propagateChildFlags(node.operatorToken) | propagateChildFlags(node.right); @@ -3515,7 +3614,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.transformFlags |= TransformFlags.ContainsPrivateIdentifierInExpression; } - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -3535,12 +3634,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createConditionalExpression(condition: Expression, questionToken: QuestionToken | undefined, whenTrue: Expression, colonToken: ColonToken | undefined, whenFalse: Expression) { const node = createBaseNode(SyntaxKind.ConditionalExpression); - const nodeData = node.data; - nodeData.condition = parenthesizerRules().parenthesizeConditionOfConditionalExpression(condition); - nodeData.questionToken = questionToken ?? createToken(SyntaxKind.QuestionToken); - nodeData.whenTrue = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenTrue); - nodeData.colonToken = colonToken ?? createToken(SyntaxKind.ColonToken); - nodeData.whenFalse = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenFalse); + const nodeData = node.data = { + condition: parenthesizerRules().parenthesizeConditionOfConditionalExpression(condition), + questionToken: questionToken ?? createToken(SyntaxKind.QuestionToken), + whenTrue: parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenTrue), + colonToken: colonToken ?? createToken(SyntaxKind.ColonToken), + whenFalse: parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenFalse), + } node.transformFlags |= propagateChildFlags(nodeData.condition) | propagateChildFlags(nodeData.questionToken) | propagateChildFlags(nodeData.whenTrue) | @@ -3570,9 +3670,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTemplateExpression(head: TemplateHead, templateSpans: readonly TemplateSpan[]) { const node = createBaseNode(SyntaxKind.TemplateExpression); - const nodeData = node.data; - nodeData.head = head; - nodeData.templateSpans = createNodeArray(templateSpans); + node.data = { + head: head, + templateSpans: createNodeArray(templateSpans), + } node.transformFlags |= propagateChildFlags(node.head) | propagateChildrenFlags(node.templateSpans) | TransformFlags.ContainsES2015; @@ -3622,21 +3723,27 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // 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 = createBaseNode(kind); - const nodeData = node.data; - nodeData.text = text; - nodeData.rawText = rawText; - nodeData.templateFlags = templateFlags! & TokenFlags.TemplateLiteralLikeFlags; + const node = createBaseToken(kind); + const nodeData = node.data = { + // hasExtendedUnicodeEscape: false, + // isUnterminated: false, + text: text, + rawText: rawText, + templateFlags: templateFlags! & TokenFlags.TemplateLiteralLikeFlags, + } node.transformFlags = getTransformFlagsOfTemplateLiteralLike(nodeData.templateFlags); return node; } function createTemplateLiteralLikeDeclaration(kind: SyntaxKind.NoSubstitutionTemplateLiteral, text: string, rawText: string | undefined, templateFlags: TokenFlags | undefined) { const node = createBaseDeclaration(kind); - const nodeData = node.data; - nodeData.text = text; - nodeData.rawText = rawText; - nodeData.templateFlags = templateFlags! & TokenFlags.TemplateLiteralLikeFlags; + const nodeData = node.data = { + // hasExtendedUnicodeEscape: false, + // isUnterminated: false, + text: text, + rawText: rawText, + templateFlags: templateFlags! & TokenFlags.TemplateLiteralLikeFlags, + } node.transformFlags = getTransformFlagsOfTemplateLiteralLike(nodeData.templateFlags); return node; } @@ -3677,9 +3784,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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); - const nodeData = node.data; - nodeData.expression = expression && parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); - nodeData.asteriskToken = asteriskToken; + const nodeData = node.data = { + expression: expression && parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), + asteriskToken: asteriskToken, + } node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.asteriskToken) | TransformFlags.ContainsES2015 | @@ -3699,7 +3807,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createSpreadElement(expression: Expression) { const node = createBaseNode(SyntaxKind.SpreadElement); - node.data.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + node.data = { expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression) }; node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsES2015 | TransformFlags.ContainsRestOrSpread; @@ -3722,12 +3830,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode members: readonly ClassElement[], ) { const node = createBaseDeclaration(SyntaxKind.ClassExpression); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.name = asName(name); - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.heritageClauses = asNodeArray(heritageClauses); - nodeData.members = createNodeArray(members); + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + name: asName(name), + typeParameters: asNodeArray(typeParameters), + heritageClauses: asNodeArray(heritageClauses), + members: createNodeArray(members), + // localSymbol: undefined. + } node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateNameFlags(nodeData.name) | propagateChildrenFlags(nodeData.typeParameters) | @@ -3736,7 +3846,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (nodeData.typeParameters ? TransformFlags.ContainsTypeScript : TransformFlags.None) | TransformFlags.ContainsES2015; - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -3766,9 +3876,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createExpressionWithTypeArguments(expression: Expression, typeArguments: readonly TypeNode[] | undefined) { const node = createBaseNode(SyntaxKind.ExpressionWithTypeArguments); - const nodeData = node.data; - nodeData.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); - nodeData.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments); + const nodeData = node.data = { + expression: parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false), + typeArguments: typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments), + }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildrenFlags(nodeData.typeArguments) | TransformFlags.ContainsES2015; @@ -3786,9 +3897,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createAsExpression(expression: Expression, type: TypeNode) { const node = createBaseNode(SyntaxKind.AsExpression); - const nodeData = node.data; - nodeData.expression = expression; - nodeData.type = type; + const nodeData = node.data = { + expression: expression, + type: type, + } node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.type) | TransformFlags.ContainsTypeScript; @@ -3806,7 +3918,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNonNullExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.NonNullExpression); - node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false); + node.data = { expression: parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false) }; node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsTypeScript; return node; @@ -3825,9 +3937,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createSatisfiesExpression(expression: Expression, type: TypeNode) { const node = createBaseNode(SyntaxKind.SatisfiesExpression); - const nodeData = node.data; - nodeData.expression = expression; - nodeData.type = type; + const nodeData = node.data = { + expression: expression, + type: type, + } node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.type) | TransformFlags.ContainsTypeScript; @@ -3846,7 +3959,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createNonNullChain(expression: Expression) { const node = createBaseNode(SyntaxKind.NonNullExpression); node.flags |= NodeFlags.OptionalChain; - node.data.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true); + node.data = { expression: parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true) } node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsTypeScript; return node; @@ -3863,9 +3976,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createMetaProperty(keywordToken: MetaProperty["keywordToken"], name: Identifier) { const node = createBaseNode(SyntaxKind.MetaProperty); - const nodeData = node.data; - nodeData.keywordToken = keywordToken; - nodeData.name = name; + const nodeData = node.data = { + keywordToken: keywordToken, + name: name, + } node.transformFlags |= propagateChildFlags(nodeData.name); switch (keywordToken) { case SyntaxKind.NewKeyword: @@ -3878,7 +3992,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode return Debug.assertNever(keywordToken); } - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3896,9 +4010,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTemplateSpan(expression: Expression, literal: TemplateMiddle | TemplateTail) { const node = createBaseNode(SyntaxKind.TemplateSpan); - const nodeData = node.data; - nodeData.expression = expression; - nodeData.literal = literal; + const nodeData = node.data = { + expression: expression, + literal: literal, + } node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.literal) | TransformFlags.ContainsES2015; @@ -3927,14 +4042,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBlock(statements: readonly Statement[], multiLine?: boolean): Block { const node = createBaseNode(SyntaxKind.Block); - const nodeData = node.data; - nodeData.statements = createNodeArray(statements); - nodeData.multiLine = multiLine; + const nodeData = node.data = { + statements: createNodeArray(statements), + multiLine: multiLine, + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + } + + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) node.transformFlags |= propagateChildrenFlags(nodeData.statements); - - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -3948,17 +4065,20 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createVariableStatement(modifiers: readonly ModifierLike[] | undefined, declarationList: VariableDeclarationList | readonly VariableDeclaration[]) { const node = createBaseNode(SyntaxKind.VariableStatement); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.declarationList = isArray(declarationList) ? createVariableDeclarationList(declarationList) : declarationList; + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + declarationList: isArray(declarationList) ? createVariableDeclarationList(declarationList) : declarationList, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateChildFlags(nodeData.declarationList); + if (modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; } - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3973,19 +4093,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createEmptyStatement() { const node = createBaseNode(SyntaxKind.EmptyStatement); - node.data.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.data.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } // @api function createExpressionStatement(expression: Expression): ExpressionStatement { const node = createBaseNode(SyntaxKind.ExpressionStatement); - const nodeData = node.data; - nodeData.expression = parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression); + const nodeData = node.data = { expression: parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression) } node.transformFlags |= propagateChildFlags(nodeData.expression); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3999,16 +4118,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createIfStatement(expression: Expression, thenStatement: Statement, elseStatement?: Statement) { const node = createBaseNode(SyntaxKind.IfStatement); - const nodeData = node.data; - nodeData.expression = expression; - nodeData.thenStatement = asEmbeddedStatement(thenStatement); - nodeData.elseStatement = asEmbeddedStatement(elseStatement); + const nodeData = node.data = { + expression: expression, + thenStatement: asEmbeddedStatement(thenStatement), + elseStatement: asEmbeddedStatement(elseStatement), + }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.thenStatement) | propagateChildFlags(nodeData.elseStatement); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4024,14 +4144,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createDoStatement(statement: Statement, expression: Expression) { const node = createBaseNode(SyntaxKind.DoStatement); - const nodeData = node.data; - nodeData.statement = asEmbeddedStatement(statement); - nodeData.expression = expression; + const nodeData = node.data = { + statement: asEmbeddedStatement(statement), + expression: expression, + }; node.transformFlags |= propagateChildFlags(nodeData.statement) | propagateChildFlags(nodeData.expression); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4046,14 +4167,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createWhileStatement(expression: Expression, statement: Statement) { const node = createBaseNode(SyntaxKind.WhileStatement); - const nodeData = node.data; - nodeData.expression = expression; - nodeData.statement = asEmbeddedStatement(statement); + const nodeData = node.data = { + expression: expression, + statement: asEmbeddedStatement(statement), + } node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.statement); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4068,20 +4190,21 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createForStatement(initializer: ForInitializer | undefined, condition: Expression | undefined, incrementor: Expression | undefined, statement: Statement) { const node = createBaseNode(SyntaxKind.ForStatement); - const nodeData = node.data; - nodeData.initializer = initializer; - nodeData.condition = condition; - nodeData.incrementor = incrementor; - nodeData.statement = asEmbeddedStatement(statement); + const nodeData = node.data = { + initializer: initializer, + condition: condition, + incrementor: incrementor, + statement: asEmbeddedStatement(statement), + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + node.transformFlags |= propagateChildFlags(nodeData.initializer) | propagateChildFlags(nodeData.condition) | propagateChildFlags(nodeData.incrementor) | propagateChildFlags(nodeData.statement); - - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4098,18 +4221,22 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createForInStatement(initializer: ForInitializer, expression: Expression, statement: Statement) { const node = createBaseNode(SyntaxKind.ForInStatement); - const nodeData = node.data; - nodeData.initializer = initializer; - nodeData.expression = expression; - nodeData.statement = asEmbeddedStatement(statement); + + const nodeData = node.data = { + initializer: initializer, + expression: expression, + statement: asEmbeddedStatement(statement), + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + } + + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) node.transformFlags |= propagateChildFlags(nodeData.initializer) | propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.statement); - - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + + return node; } @@ -4125,11 +4252,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createForOfStatement(awaitModifier: AwaitKeyword | undefined, initializer: ForInitializer, expression: Expression, statement: Statement) { const node = createBaseNode(SyntaxKind.ForOfStatement); - const nodeData = node.data; - nodeData.awaitModifier = awaitModifier; - nodeData.initializer = initializer; - nodeData.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); - nodeData.statement = asEmbeddedStatement(statement); + const nodeData = node.data = { + awaitModifier: awaitModifier, + initializer: initializer, + expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), + statement: asEmbeddedStatement(statement), + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + node.transformFlags |= propagateChildFlags(nodeData.awaitModifier) | propagateChildFlags(nodeData.initializer) | propagateChildFlags(nodeData.expression) | @@ -4137,10 +4271,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode TransformFlags.ContainsES2015; if (awaitModifier) node.transformFlags |= TransformFlags.ContainsES2018; - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4157,13 +4287,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createContinueStatement(label?: string | Identifier): ContinueStatement { const node = createBaseNode(SyntaxKind.ContinueStatement); - const nodeData = node.data; - nodeData.label = asName(label); + const nodeData = node.data = { label: asName(label) }; node.transformFlags |= propagateChildFlags(nodeData.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4177,13 +4306,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBreakStatement(label?: string | Identifier): BreakStatement { const node = createBaseNode(SyntaxKind.BreakStatement); - const nodeData = node.data; - nodeData.label = asName(label); + const nodeData = node.data = { label: asName(label) } node.transformFlags |= propagateChildFlags(nodeData.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4197,15 +4325,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createReturnStatement(expression?: Expression): ReturnStatement { const node = createBaseNode(SyntaxKind.ReturnStatement); - const nodeData = node.data; - nodeData.expression = expression; + const nodeData = node.data = { expression: expression }; // return in an ES2018 async generator must be awaited node.transformFlags |= propagateChildFlags(nodeData.expression) | TransformFlags.ContainsES2018 | TransformFlags.ContainsHoistedDeclarationOrCompletion; - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4219,14 +4346,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createWithStatement(expression: Expression, statement: Statement) { const node = createBaseNode(SyntaxKind.WithStatement); - const nodeData = node.data; - nodeData.expression = expression; - nodeData.statement = asEmbeddedStatement(statement); + const nodeData = node.data = { + expression: expression, + statement: asEmbeddedStatement(statement), + } node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.statement); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4241,15 +4369,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createSwitchStatement(expression: Expression, caseBlock: CaseBlock): SwitchStatement { const node = createBaseNode(SyntaxKind.SwitchStatement); - const nodeData = node.data; - nodeData.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); - nodeData.caseBlock = caseBlock; + const nodeData = node.data = { + possiblyExhaustive: false, // initialized by binder + expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), + caseBlock: caseBlock, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.caseBlock); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) - nodeData.possiblyExhaustive = false; // initialized by binder return node; } @@ -4264,14 +4393,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createLabeledStatement(label: string | Identifier, statement: Statement) { const node = createBaseNode(SyntaxKind.LabeledStatement); - const nodeData = node.data; - nodeData.label = asName(label); - nodeData.statement = asEmbeddedStatement(statement); + const nodeData = node.data = { + label: asName(label), + statement: asEmbeddedStatement(statement), + } node.transformFlags |= propagateChildFlags(nodeData.label) | propagateChildFlags(nodeData.statement); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4286,12 +4416,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createThrowStatement(expression: Expression) { const node = createBaseNode(SyntaxKind.ThrowStatement); - const nodeData = node.data; - nodeData.expression = expression; + const nodeData = node.data = { expression: expression }; node.transformFlags |= propagateChildFlags(nodeData.expression); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4305,16 +4434,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTryStatement(tryBlock: Block, catchClause: CatchClause | undefined, finallyBlock: Block | undefined) { const node = createBaseNode(SyntaxKind.TryStatement); - const nodeData = node.data; - nodeData.tryBlock = tryBlock; - nodeData.catchClause = catchClause; - nodeData.finallyBlock = finallyBlock; + const nodeData = node.data = { + tryBlock: tryBlock, + catchClause: catchClause, + finallyBlock: finallyBlock, + } node.transformFlags |= propagateChildFlags(nodeData.tryBlock) | propagateChildFlags(nodeData.catchClause) | propagateChildFlags(nodeData.finallyBlock); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4332,24 +4462,26 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseNode(SyntaxKind.DebuggerStatement); const nodeData = node.data; - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } // @api function createVariableDeclaration(name: string | BindingName, exclamationToken: ExclamationToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined) { const node = createBaseDeclaration(SyntaxKind.VariableDeclaration); - const nodeData = node.data; - nodeData.name = asName(name); - nodeData.exclamationToken = exclamationToken; - nodeData.type = type; - nodeData.initializer = asInitializer(initializer); + const nodeData = node.data = { + name: asName(name), + exclamationToken: exclamationToken, + type: type, + initializer: asInitializer(initializer), + localSymbol: undefined, + } node.transformFlags |= propagateNameFlags(nodeData.name) | propagateChildFlags(nodeData.initializer) | (nodeData.exclamationToken ?? nodeData.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4367,7 +4499,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createVariableDeclarationList(declarations: readonly VariableDeclaration[], flags = NodeFlags.None) { const node = createBaseNode(SyntaxKind.VariableDeclarationList); node.flags |= flags & NodeFlags.BlockScoped; - node.data.declarations = createNodeArray(declarations); + node.data = { declarations: createNodeArray(declarations) } node.transformFlags |= propagateChildrenFlags(node.declarations) | TransformFlags.ContainsHoistedDeclarationOrCompletion; if (flags & NodeFlags.BlockScoped) { @@ -4398,15 +4530,26 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode body: Block | undefined, ) { const node = createBaseDeclaration(SyntaxKind.FunctionDeclaration); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.asteriskToken = asteriskToken; - nodeData.name = asName(name); - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.parameters = createNodeArray(parameters); - nodeData.type = type; - nodeData.body = body; - + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + asteriskToken: asteriskToken, + name: asName(name), + typeParameters: asNodeArray(typeParameters), + parameters: createNodeArray(parameters), + type: type, + body: body, + + typeArguments: undefined, // used in quick info + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + endFlowNode: undefined, + returnFlowNode: undefined, + // exclamationToken: undefined, + localSymbol: undefined, + // questionToken: undefined, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + if (!nodeData.body || modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; } @@ -4430,12 +4573,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode TransformFlags.ContainsHoistedDeclarationOrCompletion; } - nodeData.typeArguments = undefined; // used in quick info - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.endFlowNode = undefined; - nodeData.returnFlowNode = undefined; return node; } @@ -4465,7 +4602,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode if (updated !== original) { // copy children used only for error reporting if (updated.modifiers === original.modifiers) { - updated.data.modifiers = original.modifiers; + updated.data!.modifiers = original.modifiers; } } return finishUpdateBaseSignatureDeclaration(updated, original); @@ -4480,12 +4617,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode members: readonly ClassElement[], ) { const node = createBaseDeclaration(SyntaxKind.ClassDeclaration); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.name = asName(name); - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.heritageClauses = asNodeArray(heritageClauses); - nodeData.members = createNodeArray(members); + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + name: asName(name), + typeParameters: asNodeArray(typeParameters), + heritageClauses: asNodeArray(heritageClauses), + members: createNodeArray(members), + localSymbol: undefined, + } if (modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; @@ -4503,7 +4642,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } } - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4534,15 +4673,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode members: readonly TypeElement[], ) { const node = createBaseDeclaration(SyntaxKind.InterfaceDeclaration); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.name = asName(name); - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.heritageClauses = asNodeArray(heritageClauses); - nodeData.members = createNodeArray(members); + node.data = { + modifiers: asNodeArray(modifiers), + name: asName(name), + typeParameters: asNodeArray(typeParameters), + heritageClauses: asNodeArray(heritageClauses), + members: createNodeArray(members), + localSymbol: undefined, + } node.transformFlags = TransformFlags.ContainsTypeScript; - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4572,16 +4713,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode, ) { const node = createBaseDeclaration(SyntaxKind.TypeAliasDeclaration); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.name = asName(name); - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.type = type; node.transformFlags = TransformFlags.ContainsTypeScript; - - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + node.data = { + modifiers: asNodeArray(modifiers), + name: asName(name), + typeParameters: asNodeArray(typeParameters), + type: type, + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + localSymbol: undefined, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4608,17 +4751,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode members: readonly EnumMember[], ) { const node = createBaseDeclaration(SyntaxKind.EnumDeclaration); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.name = asName(name); - nodeData.members = createNodeArray(members); + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + name: asName(name), + members: createNodeArray(members), + localSymbol: undefined, + } node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateChildFlags(nodeData.name) | propagateChildrenFlags(nodeData.members) | TransformFlags.ContainsTypeScript; node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Enum declarations cannot contain `await` - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4644,11 +4789,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode flags = NodeFlags.None, ) { const node = createBaseDeclaration(SyntaxKind.ModuleDeclaration); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); node.flags |= flags & (NodeFlags.Namespace | NodeFlags.NestedNamespace | NodeFlags.GlobalAugmentation); - nodeData.name = name; - nodeData.body = body; + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + name: name, + body: body, + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + localSymbol: undefined, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) if (modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; } @@ -4660,9 +4810,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Module declarations cannot contain `await`. - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -4683,11 +4830,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createModuleBlock(statements: readonly Statement[]) { const node = createBaseNode(SyntaxKind.ModuleBlock); - const nodeData = node.data; - nodeData.statements = createNodeArray(statements); + const nodeData = node.data = { statements: createNodeArray(statements) } node.transformFlags |= propagateChildrenFlags(nodeData.statements); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4701,12 +4847,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createCaseBlock(clauses: readonly CaseOrDefaultClause[]): CaseBlock { const node = createBaseNode(SyntaxKind.CaseBlock); - const nodeData = node.data; - nodeData.clauses = createNodeArray(clauses); + const nodeData = node.data = { + clauses: createNodeArray(clauses), + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + } + node.transformFlags |= propagateChildrenFlags(nodeData.clauses); - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -4720,13 +4869,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamespaceExportDeclaration(name: string | Identifier) { const node = createBaseDeclaration(SyntaxKind.NamespaceExportDeclaration); - const nodeData = node.data; - nodeData.name = asName(name); + const nodeData = node.data = { + name: asName(name), + modifiers: undefined, // initialized by parser to report grammar errors + localSymbol: undefined, + } node.transformFlags |= propagateIdentifierNameFlags(nodeData.name) | TransformFlags.ContainsTypeScript; - nodeData.modifiers = undefined; // initialized by parser to report grammar errors - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4740,7 +4891,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function finishUpdateNamespaceExportDeclaration(updated: NodeData, original: NamespaceExportDeclaration) { if (updated !== original) { // copy children used only for error reporting - updated.data.modifiers = original.modifiers; + updated.data!.modifiers = original.modifiers; } return update(updated, original); } @@ -4753,11 +4904,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode moduleReference: ModuleReference, ) { const node = createBaseDeclaration(SyntaxKind.ImportEqualsDeclaration); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.name = asName(name); - nodeData.isTypeOnly = isTypeOnly; - nodeData.moduleReference = moduleReference; + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + name: asName(name), + isTypeOnly: isTypeOnly, + moduleReference: moduleReference, + localSymbol: undefined, + } node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateIdentifierNameFlags(nodeData.name) | propagateChildFlags(nodeData.moduleReference); @@ -4768,7 +4921,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Import= declaration is always parsed in an Await context - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4796,16 +4949,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode attributes: ImportAttributes | undefined, ): ImportDeclaration { const node = createBaseNode(SyntaxKind.ImportDeclaration); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.importClause = importClause; - nodeData.moduleSpecifier = moduleSpecifier; - nodeData.attributes = nodeData.assertClause = attributes; + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + importClause: importClause, + moduleSpecifier: moduleSpecifier, + attributes: attributes, + assertClause: attributes, + } node.transformFlags |= propagateChildFlags(nodeData.importClause) | propagateChildFlags(nodeData.moduleSpecifier); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4828,10 +4983,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause { const node = createBaseDeclaration(SyntaxKind.ImportClause); - const nodeData = node.data; - nodeData.isTypeOnly = isTypeOnly; - nodeData.name = name; - nodeData.namedBindings = namedBindings; + const nodeData = node.data = { + isTypeOnly: isTypeOnly, + name: name, + namedBindings: namedBindings, + localSymbol: undefined, + } node.transformFlags |= propagateChildFlags(nodeData.name) | propagateChildFlags(nodeData.namedBindings); if (isTypeOnly) { @@ -4853,10 +5010,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createAssertClause(elements: readonly AssertEntry[], multiLine?: boolean): AssertClause { const node = createBaseNode(SyntaxKind.AssertClause); - const nodeData = node.data; - nodeData.elements = createNodeArray(elements); - nodeData.multiLine = multiLine; - nodeData.token = SyntaxKind.AssertKeyword; + node.data = { + elements: createNodeArray(elements), + multiLine: multiLine, + token: SyntaxKind.AssertKeyword, + } node.transformFlags |= TransformFlags.ContainsESNext; return node; } @@ -4872,9 +5030,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createAssertEntry(name: AssertionKey, value: Expression): AssertEntry { const node = createBaseNode(SyntaxKind.AssertEntry); - const nodeData = node.data; - nodeData.name = name; - nodeData.value = value; + node.data = { + name: name, + value: value, + } node.transformFlags |= TransformFlags.ContainsESNext; return node; } @@ -4890,9 +5049,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createImportTypeAssertionContainer(clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer { const node = createBaseNode(SyntaxKind.ImportTypeAssertionContainer); - const nodeData = node.data; - nodeData.assertClause = clause; - nodeData.multiLine = multiLine; + node.data = { + assertClause: clause, + multiLine: multiLine, + } return node; } @@ -4909,10 +5069,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode 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); - const nodeData = node.data; - nodeData.token = token ?? SyntaxKind.WithKeyword; - nodeData.elements = createNodeArray(elements); - nodeData.multiLine = multiLine; + node.data = { + token: token ?? SyntaxKind.WithKeyword, + elements: createNodeArray(elements), + multiLine: multiLine, + } node.transformFlags |= TransformFlags.ContainsESNext; return node; } @@ -4928,9 +5089,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createImportAttribute(name: ImportAttributeName, value: Expression): ImportAttribute { const node = createBaseNode(SyntaxKind.ImportAttribute); - const nodeData = node.data; - nodeData.name = name; - nodeData.value = value; + node.data = { + name: name, + value: value, + } node.transformFlags |= TransformFlags.ContainsESNext; return node; } @@ -4946,7 +5108,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamespaceImport(name: Identifier): NamespaceImport { const node = createBaseDeclaration(SyntaxKind.NamespaceImport); - node.data.name = name; + node.data = { + name: name, + // localSymbol: undefined + }; node.transformFlags |= propagateChildFlags(node.name); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; @@ -4962,7 +5127,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamespaceExport(name: ModuleExportName): NamespaceExport { const node = createBaseDeclaration(SyntaxKind.NamespaceExport); - node.data.name = name; + node.data = { + name: name, + // localSymbol: undefined + }; node.transformFlags |= propagateChildFlags(node.name) | TransformFlags.ContainsES2020; node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context @@ -4979,7 +5147,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamedImports(elements: readonly ImportSpecifier[]): NamedImports { const node = createBaseNode(SyntaxKind.NamedImports); - node.data.elements = createNodeArray(elements); + node.data = { elements: createNodeArray(elements) }; node.transformFlags |= propagateChildrenFlags(node.elements); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; @@ -4995,10 +5163,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createImportSpecifier(isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier) { const node = createBaseDeclaration(SyntaxKind.ImportSpecifier); - const nodeData = node.data; - nodeData.isTypeOnly = isTypeOnly; - nodeData.propertyName = propertyName; - nodeData.name = name; + const nodeData = node.data = { + isTypeOnly: isTypeOnly, + propertyName: propertyName, + name: name, + localSymbol: undefined, + } node.transformFlags |= propagateChildFlags(nodeData.propertyName) | propagateChildFlags(nodeData.name); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context @@ -5021,16 +5191,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode expression: Expression, ) { const node = createBaseDeclaration(SyntaxKind.ExportAssignment); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.isExportEquals = isExportEquals; - nodeData.expression = isExportEquals - ? parenthesizerRules().parenthesizeRightSideOfBinary(SyntaxKind.EqualsToken, /*leftSide*/ undefined, expression) - : parenthesizerRules().parenthesizeExpressionOfExportDefault(expression); + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + isExportEquals: isExportEquals, + expression: isExportEquals + ? parenthesizerRules().parenthesizeRightSideOfBinary(SyntaxKind.EqualsToken, /*leftSide*/ undefined, expression) + : parenthesizerRules().parenthesizeExpressionOfExportDefault(expression), + localSymbol: undefined, + // name: undefined, + } node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateChildFlags(nodeData.expression); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -5055,18 +5228,22 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode attributes?: ImportAttributes, ) { const node = createBaseDeclaration(SyntaxKind.ExportDeclaration); - const nodeData = node.data; - nodeData.modifiers = asNodeArray(modifiers); - nodeData.isTypeOnly = isTypeOnly; - nodeData.exportClause = exportClause; - nodeData.moduleSpecifier = moduleSpecifier; - nodeData.attributes = nodeData.assertClause = attributes; + const nodeData = node.data = { + modifiers: asNodeArray(modifiers), + isTypeOnly: isTypeOnly, + exportClause: exportClause, + moduleSpecifier: moduleSpecifier, + attributes: attributes, + assertClause: attributes, + localSymbol: undefined, + // name: undefined, + } node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateChildFlags(nodeData.exportClause) | propagateChildFlags(nodeData.moduleSpecifier); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -5092,7 +5269,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode if (updated !== original) { // copy children used only for error reporting if (updated.modifiers === original.modifiers) { - updated.data.modifiers = original.modifiers; + updated.data!.modifiers = original.modifiers; } } return update(updated, original); @@ -5101,7 +5278,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamedExports(elements: readonly ExportSpecifier[]) { const node = createBaseNode(SyntaxKind.NamedExports); - node.data.elements = createNodeArray(elements); + node.data = { elements: createNodeArray(elements) } node.transformFlags |= propagateChildrenFlags(node.elements); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; @@ -5117,15 +5294,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createExportSpecifier(isTypeOnly: boolean, propertyName: string | ModuleExportName | undefined, name: string | ModuleExportName) { const node = createBaseNode(SyntaxKind.ExportSpecifier); - const nodeData = node.data; - nodeData.isTypeOnly = isTypeOnly; - nodeData.propertyName = asName(propertyName); - nodeData.name = asName(name); + const nodeData = node.data = { + isTypeOnly: isTypeOnly, + propertyName: asName(propertyName), + name: asName(name), + localSymbol: undefined, + } node.transformFlags |= propagateChildFlags(nodeData.propertyName) | propagateChildFlags(nodeData.name); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -5142,7 +5321,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createMissingDeclaration(): MissingDeclaration { const node = createBaseDeclaration(SyntaxKind.MissingDeclaration); - node.data.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.data.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -5153,7 +5332,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createExternalModuleReference(expression: Expression) { const node = createBaseNode(SyntaxKind.ExternalModuleReference); - node.data.expression = expression; + node.data = { expression: expression }; node.transformFlags |= propagateChildFlags(node.expression); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; @@ -5185,7 +5364,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode kind, postfix ? type && parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(type) : type, ); - (node as unknown as NodeData).data.postfix = postfix; + (node as unknown as NodeData).data!.postfix = postfix; return node; } @@ -5195,7 +5374,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // createJSDocNamepathType function createJSDocUnaryTypeWorker(kind: T["kind"], type: T["type"]): T { const node = createBaseNode(kind); - node.data.type = type; + node.data = { type: type, postfix: undefined } as any; return node as unknown as T; } @@ -5221,16 +5400,20 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocFunctionType(parameters: readonly ParameterDeclaration[], type: TypeNode | undefined): JSDocFunctionType { const node = createBaseDeclaration(SyntaxKind.JSDocFunctionType); - const nodeData = node.data; - nodeData.parameters = asNodeArray(parameters); - nodeData.type = type; + const nodeData = node.data = { + parameters: asNodeArray(parameters), + type: type, + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + typeArguments: undefined, // used in quick info + localSymbol: undefined, + // name: undefined, + // typeParameters: undefined, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) node.transformFlags = propagateChildrenFlags(nodeData.parameters) | (nodeData.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.typeArguments = undefined; // used in quick info return node; } @@ -5245,9 +5428,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocTypeLiteral(propertyTags?: readonly JSDocPropertyLikeTag[], isArrayType = false): JSDocTypeLiteral { const node = createBaseDeclaration(SyntaxKind.JSDocTypeLiteral); - const nodeData = node.data; - nodeData.jsDocPropertyTags = asNodeArray(propertyTags); - nodeData.isArrayType = isArrayType; + const nodeData = node.data = { + jsDocPropertyTags: asNodeArray(propertyTags), + isArrayType: isArrayType, + } return node; } @@ -5262,7 +5446,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocTypeExpression(type: TypeNode): JSDocTypeExpression { const node = createBaseNode(SyntaxKind.JSDocTypeExpression); - node.data.type = type; + node.data = { type: type }; return node; } @@ -5276,14 +5460,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocSignature(typeParameters: readonly JSDocTemplateTag[] | undefined, parameters: readonly JSDocParameterTag[], type?: JSDocReturnTag): JSDocSignature { const node = createBaseDeclaration(SyntaxKind.JSDocSignature); - const nodeData = node.data; - nodeData.typeParameters = asNodeArray(typeParameters); - nodeData.parameters = createNodeArray(parameters); - nodeData.type = type; + node.data ={ + typeParameters: asNodeArray(typeParameters), + parameters: createNodeArray(parameters), + type: type, - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -5306,26 +5491,22 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBaseJSDocTag(kind: T["kind"], tagName: Identifier, comment: string | NodeArray | undefined) { const node = createBaseNode(kind); - const nodeData = node.data; - nodeData.tagName = tagName; - nodeData.comment = comment; - return node; - } - - function createBaseJSDocTagDeclaration(kind: T["kind"], tagName: Identifier, comment: string | NodeArray | undefined) { - const node = createBaseDeclaration(kind); - const nodeData = node.data; - nodeData.tagName = tagName; - nodeData.comment = comment; + node.data = { + tagName: tagName, + comment: comment, + } as NodeData['data'] as NodeData['data'] return 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); - const nodeData = node.data; - nodeData.constraint = constraint; - nodeData.typeParameters = createNodeArray(typeParameters); + const node = createBaseNode(SyntaxKind.JSDocTemplateTag); + node.data = { + tagName: tagName ?? createIdentifier("template"), + comment, + constraint: constraint, + typeParameters: createNodeArray(typeParameters), + } return node; } @@ -5341,14 +5522,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocTypedefTag(tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, fullName?: Identifier | JSDocNamespaceDeclaration, comment?: string | NodeArray): JSDocTypedefTag { - const node = createBaseJSDocTagDeclaration(SyntaxKind.JSDocTypedefTag, tagName ?? createIdentifier("typedef"), comment); - const nodeData = node.data; - nodeData.typeExpression = typeExpression; - nodeData.fullName = fullName; - nodeData.name = getJSDocTypeAliasName(fullName); - - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + const node = createBaseNode(SyntaxKind.JSDocTypedefTag); + node.data = { + tagName: tagName ?? createIdentifier("typedef"), + comment, + typeExpression: typeExpression, + fullName: fullName, + name: getJSDocTypeAliasName(fullName), + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + localSymbol: undefined, + } return node; } @@ -5364,12 +5549,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); - const nodeData = node.data; - nodeData.typeExpression = typeExpression; - nodeData.name = name; - nodeData.isNameFirst = !!isNameFirst; - nodeData.isBracketed = isBracketed; + const node = createBaseNode(SyntaxKind.JSDocParameterTag); + node.data = { + isNameFirst: !!isNameFirst, + isBracketed: isBracketed, + name: name, + typeExpression: typeExpression, + tagName: tagName ?? createIdentifier("param"), + comment, + localSymbol: undefined, + } return node; } @@ -5387,12 +5576,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); - const nodeData = node.data; - nodeData.typeExpression = typeExpression; - nodeData.name = name; - nodeData.isNameFirst = !!isNameFirst; - nodeData.isBracketed = isBracketed; + const node = createBaseNode(SyntaxKind.JSDocPropertyTag); + node.data = { + isBracketed: isBracketed, + isNameFirst: !!isNameFirst, + tagName: tagName ?? createIdentifier("prop"), + comment, + name: name, + typeExpression: typeExpression, + localSymbol: undefined, + } return node; } @@ -5410,14 +5603,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocCallbackTag(tagName: Identifier | undefined, typeExpression: JSDocSignature, fullName?: Identifier | JSDocNamespaceDeclaration, comment?: string | NodeArray): JSDocCallbackTag { - const node = createBaseJSDocTagDeclaration(SyntaxKind.JSDocCallbackTag, tagName ?? createIdentifier("callback"), comment); - const nodeData = node.data; - nodeData.typeExpression = typeExpression; - nodeData.fullName = fullName; - nodeData.name = getJSDocTypeAliasName(fullName); - - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + const node = createBaseNode(SyntaxKind.JSDocCallbackTag); + node.data = { + tagName: tagName ?? createIdentifier("callback"), + comment, + typeExpression: typeExpression, + fullName: fullName, + name: getJSDocTypeAliasName(fullName), + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + } return node; } @@ -5433,8 +5629,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocOverloadTag(tagName: Identifier | undefined, typeExpression: JSDocSignature, comment?: string | NodeArray): JSDocOverloadTag { - const node = createBaseJSDocTag(SyntaxKind.JSDocOverloadTag, tagName ?? createIdentifier("overload"), comment); - node.data.typeExpression = typeExpression; + const node = createBaseNode(SyntaxKind.JSDocOverloadTag); + node.data = { tagName: tagName ?? createIdentifier("overload"), comment, typeExpression: typeExpression }; return node; } @@ -5449,8 +5645,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocAugmentsTag(tagName: Identifier | undefined, className: JSDocAugmentsTag["class"], comment?: string | NodeArray): JSDocAugmentsTag { - const node = createBaseJSDocTag(SyntaxKind.JSDocAugmentsTag, tagName ?? createIdentifier("augments"), comment); - node.data.class = className; + const node = createBaseNode(SyntaxKind.JSDocAugmentsTag); + node.data = { + tagName: tagName ?? createIdentifier("augments"), + comment, + class:className, + } return node; } @@ -5465,15 +5665,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocImplementsTag(tagName: Identifier | undefined, className: JSDocImplementsTag["class"], comment?: string | NodeArray): JSDocImplementsTag { - const node = createBaseJSDocTag(SyntaxKind.JSDocImplementsTag, tagName ?? createIdentifier("implements"), comment); - node.data.class = className; + const node = createBaseNode(SyntaxKind.JSDocImplementsTag); + node.data = { tagName: tagName ?? createIdentifier("implements"), comment, class: className }; return node; } // @api function createJSDocSeeTag(tagName: Identifier | undefined, name: JSDocNameReference | undefined, comment?: string | NodeArray): JSDocSeeTag { - const node = createBaseJSDocTag(SyntaxKind.JSDocSeeTag, tagName ?? createIdentifier("see"), comment); - node.data.name = name; + const node = createBaseNode(SyntaxKind.JSDocSeeTag); + node.data = { tagName: tagName ?? createIdentifier("see"), comment, name: name }; return node; } @@ -5489,7 +5689,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocNameReference(name: EntityName | JSDocMemberName): JSDocNameReference { const node = createBaseNode(SyntaxKind.JSDocNameReference); - node.data.name = name; + node.data = { name: name }; return node; } @@ -5503,9 +5703,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocMemberName(left: EntityName | JSDocMemberName, right: Identifier) { const node = createBaseNode(SyntaxKind.JSDocMemberName); - const nodeData = node.data; - nodeData.left = left; - nodeData.right = right; + const nodeData = node.data = { + left: left, + right: right, + } node.transformFlags |= propagateChildFlags(node.left) | propagateChildFlags(node.right); return node; @@ -5522,9 +5723,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocLink(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLink { const node = createBaseNode(SyntaxKind.JSDocLink); - const nodeData = node.data; - nodeData.name = name; - nodeData.text = text; + node.data = { + name: name, + text: text, + } return node; } @@ -5538,9 +5740,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocLinkCode(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkCode { const node = createBaseNode(SyntaxKind.JSDocLinkCode); - const nodeData = node.data; - nodeData.name = name; - nodeData.text = text; + node.data = { + name: name, + text: text, + } return node; } @@ -5554,9 +5757,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocLinkPlain(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkPlain { const node = createBaseNode(SyntaxKind.JSDocLinkPlain); - const nodeData = node.data; - nodeData.name = name; - nodeData.text = text; + node.data = { + name: name, + text: text, + } return node; } @@ -5611,9 +5815,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // 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.data.typeExpression = typeExpression; - return node; + const node = createBaseNode(kind); + node.data = { + tagName: tagName ?? createIdentifier(getDefaultTagNameForKind(kind)), + comment, + typeExpression: typeExpression, + } + return node as any as T; } // @api @@ -5626,7 +5834,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode return node.tagName !== tagName || node.typeExpression !== typeExpression || node.comment !== comment - ? update(createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment), node as unknown as NodeData) + ? update(createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment), node) : node; } @@ -5646,12 +5854,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocEnumTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string | NodeArray) { - const node = createBaseJSDocTagDeclaration(SyntaxKind.JSDocEnumTag, tagName ?? createIdentifier(getDefaultTagNameForKind(SyntaxKind.JSDocEnumTag)), comment); - const nodeData = node.data; - nodeData.typeExpression = typeExpression; - - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) + const node = createBaseNode(SyntaxKind.JSDocEnumTag); + const nodeData = node.data = { + tagName: tagName ?? createIdentifier(getDefaultTagNameForKind(SyntaxKind.JSDocEnumTag)), + comment, + typeExpression: typeExpression, + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + } return node; } @@ -5666,12 +5877,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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); - const nodeData = node.data; - nodeData.importClause = importClause; - nodeData.moduleSpecifier = moduleSpecifier; - nodeData.attributes = attributes; - nodeData.comment = comment; + const node = createBaseNode(SyntaxKind.JSDocImportTag); + node.data = { + tagName: tagName ?? createIdentifier("import"), + comment, + importClause: importClause, + moduleSpecifier: moduleSpecifier, + attributes: attributes, + } return node; } @@ -5688,7 +5901,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocText(text: string): JSDocText { const node = createBaseNode(SyntaxKind.JSDocText); - node.data.text = text; + node.data = { text: text }; return node; } @@ -5702,9 +5915,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocComment(comment?: string | NodeArray | undefined, tags?: readonly JSDocTag[] | undefined) { const node = createBaseNode(SyntaxKind.JSDoc); - const nodeData = node.data; - nodeData.comment = comment; - nodeData.tags = asNodeArray(tags); + node.data = { + comment: comment, + tags: asNodeArray(tags), + } return node; } @@ -5723,10 +5937,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxElement(openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement) { const node = createBaseNode(SyntaxKind.JsxElement); - const nodeData = node.data; - nodeData.openingElement = openingElement; - nodeData.children = createNodeArray(children); - nodeData.closingElement = closingElement; + const nodeData = node.data = { + openingElement: openingElement, + children: createNodeArray(children), + closingElement: closingElement, + } node.transformFlags |= propagateChildFlags(nodeData.openingElement) | propagateChildrenFlags(nodeData.children) | propagateChildFlags(nodeData.closingElement) | @@ -5746,10 +5961,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxSelfClosingElement(tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes) { const node = createBaseNode(SyntaxKind.JsxSelfClosingElement); - const nodeData = node.data; - nodeData.tagName = tagName; - nodeData.typeArguments = asNodeArray(typeArguments); - nodeData.attributes = attributes; + const nodeData = node.data = { + tagName: tagName, + typeArguments: asNodeArray(typeArguments), + attributes: attributes, + } node.transformFlags |= propagateChildFlags(nodeData.tagName) | propagateChildrenFlags(nodeData.typeArguments) | propagateChildFlags(nodeData.attributes) | @@ -5772,10 +5988,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxOpeningElement(tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes) { const node = createBaseNode(SyntaxKind.JsxOpeningElement); - const nodeData = node.data; - nodeData.tagName = tagName; - nodeData.typeArguments = asNodeArray(typeArguments); - nodeData.attributes = attributes; + const nodeData = node.data = { + tagName: tagName, + typeArguments: asNodeArray(typeArguments), + attributes: attributes, + } node.transformFlags |= propagateChildFlags(nodeData.tagName) | propagateChildrenFlags(nodeData.typeArguments) | propagateChildFlags(nodeData.attributes) | @@ -5798,7 +6015,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxClosingElement(tagName: JsxTagNameExpression) { const node = createBaseNode(SyntaxKind.JsxClosingElement); - node.data.tagName = tagName; + node.data = { tagName: tagName } node.transformFlags |= propagateChildFlags(node.tagName) | TransformFlags.ContainsJsx; return node; @@ -5814,10 +6031,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxFragment(openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment) { const node = createBaseNode(SyntaxKind.JsxFragment); - const nodeData = node.data; - nodeData.openingFragment = openingFragment; - nodeData.children = createNodeArray(children); - nodeData.closingFragment = closingFragment; + const nodeData = node.data = { + openingFragment: openingFragment, + children: createNodeArray(children), + closingFragment: closingFragment, + } node.transformFlags |= propagateChildFlags(nodeData.openingFragment) | propagateChildrenFlags(nodeData.children) | propagateChildFlags(nodeData.closingFragment) | @@ -5837,9 +6055,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxText(text: string, containsOnlyTriviaWhiteSpaces?: boolean) { const node = createBaseNode(SyntaxKind.JsxText); - const nodeData = node.data; - nodeData.text = text; - nodeData.containsOnlyTriviaWhiteSpaces = !!containsOnlyTriviaWhiteSpaces; + node.data = { + // hasExtendedUnicodeEscape: false, + // isUnterminated: false, + text: text, + containsOnlyTriviaWhiteSpaces: !!containsOnlyTriviaWhiteSpaces, + } node.transformFlags |= TransformFlags.ContainsJsx; return node; } @@ -5869,9 +6090,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxAttribute(name: JsxAttributeName, initializer: JsxAttributeValue | undefined) { const node = createBaseDeclaration(SyntaxKind.JsxAttribute); - const nodeData = node.data; - nodeData.name = name; - nodeData.initializer = initializer; + node.data = { + name: name, + initializer: initializer, + localSymbol: undefined, + } node.transformFlags |= propagateChildFlags(node.name) | propagateChildFlags(node.initializer) | TransformFlags.ContainsJsx; @@ -5889,7 +6112,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxAttributes(properties: readonly JsxAttributeLike[]) { const node = createBaseDeclaration(SyntaxKind.JsxAttributes); - node.data.properties = createNodeArray(properties); + node.data = { properties: createNodeArray(properties) }; node.transformFlags |= propagateChildrenFlags(node.properties) | TransformFlags.ContainsJsx; return node; @@ -5905,7 +6128,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxSpreadAttribute(expression: Expression) { const node = createBaseNode(SyntaxKind.JsxSpreadAttribute); - node.data.expression = expression; + node.data = { + expression: expression, + localSymbol: undefined, + name: undefined + }; node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsJsx; return node; @@ -5921,9 +6148,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxExpression(dotDotDotToken: DotDotDotToken | undefined, expression: Expression | undefined) { const node = createBaseNode(SyntaxKind.JsxExpression); - const nodeData = node.data; - nodeData.dotDotDotToken = dotDotDotToken; - nodeData.expression = expression; + const nodeData = node.data = { + dotDotDotToken: dotDotDotToken, + expression: expression, + } node.transformFlags |= propagateChildFlags(node.dotDotDotToken) | propagateChildFlags(node.expression) | TransformFlags.ContainsJsx; @@ -5940,9 +6168,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxNamespacedName(namespace: Identifier, name: Identifier) { const node = createBaseNode(SyntaxKind.JsxNamespacedName); - const nodeData = node.data; - nodeData.namespace = namespace; - nodeData.name = name; + node.data = { + namespace: namespace, + name: name, + } node.transformFlags |= propagateChildFlags(node.namespace) | propagateChildFlags(node.name) | TransformFlags.ContainsJsx; @@ -5964,13 +6193,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createCaseClause(expression: Expression, statements: readonly Statement[]) { const node = createBaseNode(SyntaxKind.CaseClause); - const nodeData = node.data; - nodeData.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); - nodeData.statements = createNodeArray(statements); + const nodeData = node.data = { + expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), + statements: createNodeArray(statements), + // fallthroughFlowNode: undefined, + } node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildrenFlags(nodeData.statements); - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -5985,7 +6216,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createDefaultClause(statements: readonly Statement[]) { const node = createBaseNode(SyntaxKind.DefaultClause); - node.data.statements = createNodeArray(statements); + node.data = { statements: createNodeArray(statements) }; node.transformFlags = propagateChildrenFlags(node.statements); return node; } @@ -6000,9 +6231,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createHeritageClause(token: HeritageClause["token"], types: readonly ExpressionWithTypeArguments[]) { const node = createBaseNode(SyntaxKind.HeritageClause); - const nodeData = node.data; - nodeData.token = token; - nodeData.types = createNodeArray(types); + node.data = { + token: token, + types: createNodeArray(types), + } node.transformFlags |= propagateChildrenFlags(node.types); switch (token) { case SyntaxKind.ExtendsKeyword: @@ -6027,16 +6259,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createCatchClause(variableDeclaration: string | BindingName | VariableDeclaration | undefined, block: Block) { const node = createBaseNode(SyntaxKind.CatchClause); - const nodeData = node.data; - nodeData.variableDeclaration = asVariableDeclaration(variableDeclaration); - nodeData.block = block; + const nodeData = node.data = { + variableDeclaration: asVariableDeclaration(variableDeclaration), + block: block, + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + } node.transformFlags |= propagateChildFlags(nodeData.variableDeclaration) | propagateChildFlags(nodeData.block) | (!variableDeclaration ? TransformFlags.ContainsES2019 : TransformFlags.None); - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) return node; } @@ -6055,16 +6288,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createPropertyAssignment(name: string | PropertyName, initializer: Expression) { const node = createBaseDeclaration(SyntaxKind.PropertyAssignment); - const nodeData = node.data; - nodeData.name = asName(name); - nodeData.initializer = parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer); + const nodeData = node.data = { + name: asName(name), + initializer: parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer), + + modifiers: undefined ,// initialized by parser to report grammar errors + questionToken: undefined, // initialized by parser to report grammar errors + exclamationToken: undefined, // initialized by parser to report grammar errors + localSymbol: undefined, + } + node.transformFlags |= propagateNameFlags(nodeData.name) | propagateChildFlags(nodeData.initializer); - - nodeData.modifiers = undefined; // initialized by parser to report grammar errors - nodeData.questionToken = undefined; // initialized by parser to report grammar errors - nodeData.exclamationToken = undefined; // initialized by parser to report grammar errors - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -6080,9 +6316,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // copy children used only for error reporting if (updated !== original) { // copy children used only for error reporting - updated.data.modifiers = original.modifiers; - updated.data.questionToken = original.questionToken; - updated.data.exclamationToken = original.exclamationToken; + updated.data!.modifiers = original.modifiers; + updated.data!.questionToken = original.questionToken; + updated.data!.exclamationToken = original.exclamationToken; } return update(updated, original); } @@ -6090,18 +6326,22 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createShorthandPropertyAssignment(name: string | Identifier, objectAssignmentInitializer?: Expression) { const node = createBaseDeclaration(SyntaxKind.ShorthandPropertyAssignment); - const nodeData = node.data; - nodeData.name = asName(name); - nodeData.objectAssignmentInitializer = objectAssignmentInitializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(objectAssignmentInitializer); + const nodeData = node.data = { + name: asName(name), + objectAssignmentInitializer: objectAssignmentInitializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(objectAssignmentInitializer), + + equalsToken: undefined, // initialized by parser to report grammar errors + modifiers: undefined, // initialized by parser to report grammar errors + questionToken: undefined, // initialized by parser to report grammar errors + exclamationToken: undefined, // initialized by parser to report grammar errors + localSymbol: undefined, + } + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) + + node.transformFlags |= propagateIdentifierNameFlags(nodeData.name) | propagateChildFlags(nodeData.objectAssignmentInitializer) | TransformFlags.ContainsES2015; - - nodeData.equalsToken = undefined; // initialized by parser to report grammar errors - nodeData.modifiers = undefined; // initialized by parser to report grammar errors - nodeData.questionToken = undefined; // initialized by parser to report grammar errors - nodeData.exclamationToken = undefined; // initialized by parser to report grammar errors - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -6116,10 +6356,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function finishUpdateShorthandPropertyAssignment(updated: NodeData, original: ShorthandPropertyAssignment) { if (updated !== original) { // copy children used only for error reporting - updated.data.modifiers = original.modifiers; - updated.data.questionToken = original.questionToken; - updated.data.exclamationToken = original.exclamationToken; - updated.data.equalsToken = original.equalsToken; + updated.data!.modifiers = original.modifiers; + updated.data!.questionToken = original.questionToken; + updated.data!.exclamationToken = original.exclamationToken; + updated.data!.equalsToken = original.equalsToken; } return update(updated, original); } @@ -6127,13 +6367,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createSpreadAssignment(expression: Expression) { const node = createBaseDeclaration(SyntaxKind.SpreadAssignment); - const nodeData = node.data; - nodeData.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression); + node.data = { expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression) } node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsES2018 | TransformFlags.ContainsObjectRestOrSpread; - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -6151,14 +6390,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createEnumMember(name: string | PropertyName, initializer?: Expression) { const node = createBaseDeclaration(SyntaxKind.EnumMember); - const nodeData = node.data; - nodeData.name = asName(name); - nodeData.initializer = initializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer); + node.data = { + name: asName(name), + initializer: initializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer), + localSymbol: undefined, + } node.transformFlags |= propagateChildFlags(node.name) | propagateChildFlags(node.initializer) | TransformFlags.ContainsTypeScript; - nodeData.jsDoc = undefined; // initialized by parser (JsDocContainer) + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -6181,52 +6422,55 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode flags: NodeFlags, ) { const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as NodeData; - const nodeData = node.data; - nodeData.statements = createNodeArray(statements); - nodeData.endOfFileToken = endOfFileToken; - node.flags |= flags; - nodeData.text = ""; - nodeData.fileName = ""; - nodeData.path = "" as Path; - nodeData.resolvedPath = "" as Path; - nodeData.originalFileName = ""; - nodeData.languageVersion = ScriptTarget.ES5; - nodeData.languageVariant = 0; - nodeData.scriptKind = 0; - nodeData.isDeclarationFile = false; - nodeData.hasNoDefaultLib = false; - + node.flags = flags; + + const nodeData = node.data = { + statements: createNodeArray(statements), + endOfFileToken: endOfFileToken, + text: "", + fileName: "", + path: "" as Path, + resolvedPath: "" as Path, + originalFileName: "", + languageVersion: ScriptTarget.ES5, + languageVariant: 0, + scriptKind: 0, + isDeclarationFile: false, + hasNoDefaultLib: false, + + + locals: undefined, // initialized by binder (LocalsContainer) + nextContainer: undefined, // initialized by binder (LocalsContainer) + endFlowNode: undefined, + + nodeCount: 0, + identifierCount: 0, + symbolCount: 0, + parseDiagnostics: undefined!, + bindDiagnostics: undefined!, + bindSuggestionDiagnostics: undefined, + lineMap: undefined!, + externalModuleIndicator: undefined, + setExternalModuleIndicator: undefined, + pragmas: undefined!, + checkJsDirective: undefined, + referencedFiles: undefined!, + typeReferenceDirectives: undefined!, + libReferenceDirectives: undefined!, + amdDependencies: undefined!, + commentDirectives: undefined, + identifiers: undefined!, + packageJsonLocations: undefined, + packageJsonScope: undefined, + imports: undefined!, + moduleAugmentations: undefined!, + ambientModuleNames: undefined!, + classifiableNames: undefined, + impliedNodeFormat: undefined, + } + node.transformFlags |= propagateChildrenFlags(nodeData.statements) | propagateChildFlags(nodeData.endOfFileToken); - - nodeData.locals = undefined; // initialized by binder (LocalsContainer) - nodeData.nextContainer = undefined; // initialized by binder (LocalsContainer) - nodeData.endFlowNode = undefined; - - nodeData.nodeCount = 0; - nodeData.identifierCount = 0; - nodeData.symbolCount = 0; - nodeData.parseDiagnostics = undefined!; - nodeData.bindDiagnostics = undefined!; - nodeData.bindSuggestionDiagnostics = undefined; - nodeData.lineMap = undefined!; - nodeData.externalModuleIndicator = undefined; - nodeData.setExternalModuleIndicator = undefined; - nodeData.pragmas = undefined!; - nodeData.checkJsDirective = undefined; - nodeData.referencedFiles = undefined!; - nodeData.typeReferenceDirectives = undefined!; - nodeData.libReferenceDirectives = undefined!; - nodeData.amdDependencies = undefined!; - nodeData.commentDirectives = undefined; - nodeData.identifiers = undefined!; - nodeData.packageJsonLocations = undefined; - nodeData.packageJsonScope = undefined; - nodeData.imports = undefined!; - nodeData.moduleAugmentations = undefined!; - nodeData.ambientModuleNames = undefined!; - nodeData.classifiableNames = undefined; - nodeData.impliedNodeFormat = undefined; return node; } @@ -6260,7 +6504,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function cloneRedirectedSourceFile(source: SourceFile) { const node = createRedirectedSourceFile(source.redirectInfo!) as NodeData; - const nodeData = node.data; + const nodeData = node.data!; node.flags |= source.flags & ~NodeFlags.Synthesized; nodeData.fileName = source.fileName; nodeData.path = source.path; @@ -6277,8 +6521,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // work, we should consider switching explicit property assignments instead of using `for..in`. const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as NodeData; node.flags |= source.flags & ~NodeFlags.Synthesized; - const sourceData = (source as any).data ?? source; - const nodeData = (node as any).data ?? node; + const sourceData = (source as any).data; + const nodeData = (node as any).data = {}; for (const p in sourceData) { if (hasProperty(nodeData, p) || !hasProperty(sourceData, p)) { continue; @@ -6308,7 +6552,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode libReferences: readonly FileReference[], ) { const node = cloneSourceFile(source); - const nodeData = node.data; + const nodeData = node.data!; nodeData.statements = createNodeArray(statements); nodeData.isDeclarationFile = isDeclarationFile; nodeData.referencedFiles = referencedFiles; @@ -6343,12 +6587,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBundle(sourceFiles: readonly SourceFile[]) { const node = createBaseNode(SyntaxKind.Bundle); - const nodeData = node.data; - nodeData.sourceFiles = sourceFiles; - nodeData.syntheticFileReferences = undefined; - nodeData.syntheticTypeReferences = undefined; - nodeData.syntheticLibReferences = undefined; - nodeData.hasNoDefaultLib = undefined; + node.data = { + sourceFiles: sourceFiles, + syntheticFileReferences: undefined, + syntheticTypeReferences: undefined, + syntheticLibReferences: undefined, + hasNoDefaultLib: undefined, + } return node; } @@ -6366,10 +6611,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createSyntheticExpression(type: Type, isSpread = false, tupleNameSource?: ParameterDeclaration | NamedTupleMember) { const node = createBaseNode(SyntaxKind.SyntheticExpression); - const nodeData = node.data; - nodeData.type = type; - nodeData.isSpread = isSpread; - nodeData.tupleNameSource = tupleNameSource; + const nodeData = node.data = { + type: type, + isSpread: isSpread, + tupleNameSource: tupleNameSource, + } return node; } @@ -6408,8 +6654,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createPartiallyEmittedExpression(expression: Expression, original?: Node) { const node = createBaseNode(SyntaxKind.PartiallyEmittedExpression); - const nodeData = node.data; - nodeData.expression = expression; + const nodeData = node.data = { expression: expression } node.original = original; node.transformFlags |= propagateChildFlags(nodeData.expression) | TransformFlags.ContainsTypeScript; @@ -6439,7 +6684,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createCommaListExpression(elements: readonly Expression[]) { const node = createBaseNode(SyntaxKind.CommaListExpression); - node.data.elements = createNodeArray(sameFlatMap(elements, flattenCommaElements)); + node.data = { elements: createNodeArray(sameFlatMap(elements, flattenCommaElements)) } node.transformFlags |= propagateChildrenFlags(node.elements); return node; } @@ -6454,9 +6699,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createSyntheticReferenceExpression(expression: Expression, thisArg: Expression) { const node = createBaseNode(SyntaxKind.SyntheticReferenceExpression); - const nodeData = node.data; - nodeData.expression = expression; - nodeData.thisArg = thisArg; + node.data = { + expression: expression, + thisArg: thisArg, + } node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.thisArg); return node; @@ -6481,11 +6727,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function cloneIdentifier(node: Identifier): Identifier { const clone = createBaseIdentifier(node.escapedText); - const cloneData = clone.data; clone.flags |= node.flags & ~NodeFlags.Synthesized; - cloneData.jsDoc = node.jsDoc; - cloneData.flowNode = node.flowNode; - cloneData.symbol = node.symbol; + clone.jsDoc = node.jsDoc; + clone.flowNode = node.flowNode; + clone.symbol = node.symbol; clone.transformFlags = node.transformFlags; setOriginal(clone, node); @@ -6536,15 +6781,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode if (isPrivateIdentifier(node)) { return clonePrivateIdentifier(node) as T & PrivateIdentifier; } - const clone = baseFactory.createBaseNode(node.kind); - (clone as unknown as NodeData).flags |= node.flags & ~NodeFlags.Synthesized; - (clone as unknown as NodeData).transformFlags = node.transformFlags; + const clone = baseFactory.createBaseNode(node.kind) as Mutable; + + clone.flags |= node.flags & ~NodeFlags.Synthesized; + clone.transformFlags = node.transformFlags; setOriginal(clone, node); const nodeData = (node as any).data ?? node; - const cloneData = (clone as any).data ?? clone; + const cloneData = (clone as any).data = {}; for (const key in nodeData) { - if (hasProperty(cloneData, key) || hasProperty(clone, key) || !hasProperty(nodeData, key)) { + if (hasProperty(cloneData, key) || !hasProperty(nodeData, key)) { continue; } (clone as any)[key] = nodeData[key]; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8bb9cd11e49d6..9cb8f153c9381 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -107,6 +107,7 @@ import { ElementAccessExpression, EmitFlags, EmitHost, + EmitNode, EmitResolver, EmitTextWriter, emptyArray, @@ -8277,6 +8278,8 @@ function Symbol(this: Symbol, flags: SymbolFlags, name: __String) { class TypeDataImpl { } + +export const allTypes: TypeImpl[] = []; /** @internal */ export class TypeImpl { checker: TypeChecker; @@ -8291,7 +8294,9 @@ export class TypeImpl { this.flags = flags; this.symbol = undefined!; this.objectFlags = 0; + allTypes.push(this); } + get data() { return this._data ??= new TypeDataImpl(); } @@ -9072,6 +9077,7 @@ export class SignatureImpl { this.compositeSignatures = undefined; this.compositeKind = undefined; } + // get data(): any { return this; } _data: any = undefined; get data() { return this._data ??= new SignatureDataImpl(); @@ -9121,1338 +9127,1304 @@ export class SignatureImpl { } // export const NodeDataImplInstantiations: Partial> = {} -class NodeDataImpl { - // constructor(kind: SyntaxKind) { - // NodeDataImplInstantiations[kind] = (NodeDataImplInstantiations[kind] ?? 0) + 1; - // } - // original = undefined; - // modifierFlagsCache = ModifierFlags.None -} +// class NodeDataImpl { +// // constructor(kind: SyntaxKind) { +// // NodeDataImplInstantiations[kind] = (NodeDataImplInstantiations[kind] ?? 0) + 1; +// // } +// // original = undefined; +// // modifierFlagsCache = ModifierFlags.None +// } // export const NodeImplInstantiations: Partial> = {} /** @internal */ export class NodeImpl { - pos; // Node, Token, Identifier - end; // Node, Token, Identifier - kind; // Node, Token, Identifier - id = 0; // Node, Token, Identifier - flags = NodeFlags.None; // Node, Token, Identifier - transformFlags = TransformFlags.None; // Node, Token, Identifier - parent: Node = undefined!; // Node, Token, Identifier - emitNode = undefined; // Node, Token, Identifier - original = undefined; - modifierFlagsCache = ModifierFlags.None; + pos: number; + end: number; + kind: number; + id: number; + flags: NodeFlags; + transformFlags: TransformFlags; + parent: Node; + emitNode: EmitNode | undefined; + modifierFlagsCache: ModifierFlags; + original: undefined; + escapedText: undefined; + jsDoc: any; + flowNode: any; + symbol: any; constructor(kind: SyntaxKind, pos: number, end: number) { - this.kind = kind; this.pos = pos; this.end = end; - // NodeImplInstantiations[kind] = (NodeImplInstantiations[kind] ?? 0) + 1; - } - get data() { - return this._data ??= new NodeDataImpl(); - } - set data(value: any) { - this._data = value; - } - _data: any = undefined; - // get original(): Node { - // return this._data?.original - // } - - // set original(value: Node) { - // this.data.original = value; - // } - - // get modifierFlagsCache(): ModifierFlags { - // return this._data?.modifierFlagsCache; - // } + this.kind = kind; + this.id = 0; + this.flags = NodeFlags.None; + this.transformFlags = TransformFlags.None; + this.modifierFlagsCache = ModifierFlags.None; - // set modifierFlagsCache(value: ModifierFlags) { - // this.data.modifierFlagsCache = value; - // } + this.parent = undefined!; + this.emitNode = undefined; + + this.original = undefined; + this.escapedText = undefined; + this.jsDoc = undefined; + this.flowNode = undefined; + this.symbol = undefined; + } + data: any = undefined; get sourceText() { - return this._data?.sourceText; + return this.data?.sourceText; } set sourceText(value: any) { this.data.sourceText = value; } - - get jsDoc() { - return this._data?.jsDoc; - } - set jsDoc(value: any) { - this.data.jsDoc = value; - } - - get escapedText() { - return this._data?.escapedText; - } - set escapedText(value: any) { - this.data.escapedText = value; - } - - get symbol() { - return this._data?.symbol; - } - set symbol(value: any) { - this.data.symbol = value; - } - get localSymbol() { - return this._data?.localSymbol; + return this.data?.localSymbol; } set localSymbol(value: any) { this.data.localSymbol = value; } - get flowNode() { - return this._data?.flowNode; - } - set flowNode(value: any) { - this.data.flowNode = value; - } - get resolvedSymbol() { - return this._data?.resolvedSymbol; + return this.data?.resolvedSymbol; } set resolvedSymbol(value: any) { this.data.resolvedSymbol = value; } get modifiers() { - return this._data?.modifiers; + return this.data?.modifiers; } set modifiers(value: any) { this.data.modifiers = value; } get name() { - return this._data?.name; + return this.data?.name; } set name(value: any) { this.data.name = value; } get constraint() { - return this._data?.constraint; + return this.data?.constraint; } set constraint(value: any) { this.data.constraint = value; } get default() { - return this._data?.default; + return this.data?.default; } set default(value: any) { this.data.default = value; } get expression() { - return this._data?.expression; + return this.data?.expression; } set expression(value: any) { this.data.expression = value; } get typeParameters() { - return this._data?.typeParameters; + return this.data?.typeParameters; } set typeParameters(value: any) { this.data.typeParameters = value; } get parameters() { - return this._data?.parameters; + return this.data?.parameters; } set parameters(value: any) { this.data.parameters = value; } get type() { - return this._data?.type; + return this.data?.type; } set type(value: any) { this.data.type = value; } get typeArguments() { - return this._data?.typeArguments; + return this.data?.typeArguments; } set typeArguments(value: any) { this.data.typeArguments = value; } get questionToken() { - return this._data?.questionToken; + return this.data?.questionToken; } set questionToken(value: any) { this.data.questionToken = value; } get locals() { - return this._data?.locals; + return this.data?.locals; } set locals(value: any) { this.data.locals = value; } get nextContainer() { - return this._data?.nextContainer; + return this.data?.nextContainer; } set nextContainer(value: any) { this.data.nextContainer = value; } get asteriskToken() { - return this._data?.asteriskToken; + return this.data?.asteriskToken; } set asteriskToken(value: any) { this.data.asteriskToken = value; } get exclamationToken() { - return this._data?.exclamationToken; + return this.data?.exclamationToken; } set exclamationToken(value: any) { this.data.exclamationToken = value; } get body() { - return this._data?.body; + return this.data?.body; } set body(value: any) { this.data.body = value; } get endFlowNode() { - return this._data?.endFlowNode; + return this.data?.endFlowNode; } set endFlowNode(value: any) { this.data.endFlowNode = value; } get returnFlowNode() { - return this._data?.returnFlowNode; + return this.data?.returnFlowNode; } set returnFlowNode(value: any) { this.data.returnFlowNode = value; } get equalsGreaterThanToken() { - return this._data?.equalsGreaterThanToken; + return this.data?.equalsGreaterThanToken; } set equalsGreaterThanToken(value: any) { this.data.equalsGreaterThanToken = value; } get initializer() { - return this._data?.initializer; + return this.data?.initializer; } set initializer(value: any) { this.data.initializer = value; } get dotDotDotToken() { - return this._data?.dotDotDotToken; + return this.data?.dotDotDotToken; } set dotDotDotToken(value: any) { this.data.dotDotDotToken = value; } get equalsToken() { - return this._data?.equalsToken; + return this.data?.equalsToken; } set equalsToken(value: any) { this.data.equalsToken = value; } get objectAssignmentInitializer() { - return this._data?.objectAssignmentInitializer; + return this.data?.objectAssignmentInitializer; } set objectAssignmentInitializer(value: any) { this.data.objectAssignmentInitializer = value; } get left() { - return this._data?.left; + return this.data?.left; } set left(value: any) { this.data.left = value; } get operatorToken() { - return this._data?.operatorToken; + return this.data?.operatorToken; } set operatorToken(value: any) { this.data.operatorToken = value; } get right() { - return this._data?.right; + return this.data?.right; } set right(value: any) { this.data.right = value; } get multiLine() { - return this._data?.multiLine; + return this.data?.multiLine; } set multiLine(value: any) { this.data.multiLine = value; } get properties() { - return this._data?.properties; + return this.data?.properties; } set properties(value: any) { this.data.properties = value; } get questionDotToken() { - return this._data?.questionDotToken; + return this.data?.questionDotToken; } set questionDotToken(value: any) { this.data.questionDotToken = value; } get argumentExpression() { - return this._data?.argumentExpression; + return this.data?.argumentExpression; } set argumentExpression(value: any) { this.data.argumentExpression = value; } get heritageClauses() { - return this._data?.heritageClauses; + return this.data?.heritageClauses; } set heritageClauses(value: any) { this.data.heritageClauses = value; } get members() { - return this._data?.members; + return this.data?.members; } set members(value: any) { this.data.members = value; } get isTypeOnly() { - return this._data?.isTypeOnly; + return this.data?.isTypeOnly; } set isTypeOnly(value: any) { this.data.isTypeOnly = value; } get moduleReference() { - return this._data?.moduleReference; + return this.data?.moduleReference; } set moduleReference(value: any) { this.data.moduleReference = value; } get exportClause() { - return this._data?.exportClause; + return this.data?.exportClause; } set exportClause(value: any) { this.data.exportClause = value; } get moduleSpecifier() { - return this._data?.moduleSpecifier; + return this.data?.moduleSpecifier; } set moduleSpecifier(value: any) { this.data.moduleSpecifier = value; } get assertClause() { - return this._data?.assertClause; + return this.data?.assertClause; } set assertClause(value: any) { this.data.assertClause = value; } get attributes() { - return this._data?.attributes; + return this.data?.attributes; } set attributes(value: any) { this.data.attributes = value; } get isExportEquals() { - return this._data?.isExportEquals; + return this.data?.isExportEquals; } set isExportEquals(value: any) { this.data.isExportEquals = value; } get statements() { - return this._data?.statements; + return this.data?.statements; } set statements(value: any) { this.data.statements = value; } get declarationList() { - return this._data?.declarationList; + return this.data?.declarationList; } set declarationList(value: any) { this.data.declarationList = value; } get thenStatement() { - return this._data?.thenStatement; + return this.data?.thenStatement; } set thenStatement(value: any) { this.data.thenStatement = value; } get elseStatement() { - return this._data?.elseStatement; + return this.data?.elseStatement; } set elseStatement(value: any) { this.data.elseStatement = value; } get statement() { - return this._data?.statement; + return this.data?.statement; } set statement(value: any) { this.data.statement = value; } get condition() { - return this._data?.condition; + return this.data?.condition; } set condition(value: any) { this.data.condition = value; } get incrementor() { - return this._data?.incrementor; + return this.data?.incrementor; } set incrementor(value: any) { this.data.incrementor = value; } get awaitModifier() { - return this._data?.awaitModifier; + return this.data?.awaitModifier; } set awaitModifier(value: any) { this.data.awaitModifier = value; } get label() { - return this._data?.label; + return this.data?.label; } set label(value: any) { this.data.label = value; } get caseBlock() { - return this._data?.caseBlock; + return this.data?.caseBlock; } set caseBlock(value: any) { this.data.caseBlock = value; } get possiblyExhaustive() { - return this._data?.possiblyExhaustive; + return this.data?.possiblyExhaustive; } set possiblyExhaustive(value: any) { this.data.possiblyExhaustive = value; } get tryBlock() { - return this._data?.tryBlock; + return this.data?.tryBlock; } set tryBlock(value: any) { this.data.tryBlock = value; } get catchClause() { - return this._data?.catchClause; + return this.data?.catchClause; } set catchClause(value: any) { this.data.catchClause = value; } get finallyBlock() { - return this._data?.finallyBlock; + return this.data?.finallyBlock; } set finallyBlock(value: any) { this.data.finallyBlock = value; } get importClause() { - return this._data?.importClause; + return this.data?.importClause; } set importClause(value: any) { this.data.importClause = value; } get fallthroughFlowNode() { - return this._data?.fallthroughFlowNode; + return this.data?.fallthroughFlowNode; } set fallthroughFlowNode(value: any) { this.data.fallthroughFlowNode = value; } get propertyName() { - return this._data?.propertyName; + return this.data?.propertyName; } set propertyName(value: any) { this.data.propertyName = value; } get checkType() { - return this._data?.checkType; + return this.data?.checkType; } set checkType(value: any) { this.data.checkType = value; } get extendsType() { - return this._data?.extendsType; + return this.data?.extendsType; } set extendsType(value: any) { this.data.extendsType = value; } get trueType() { - return this._data?.trueType; + return this.data?.trueType; } set trueType(value: any) { this.data.trueType = value; } get falseType() { - return this._data?.falseType; + return this.data?.falseType; } set falseType(value: any) { this.data.falseType = value; } get readonlyToken() { - return this._data?.readonlyToken; + return this.data?.readonlyToken; } set readonlyToken(value: any) { this.data.readonlyToken = value; } get typeParameter() { - return this._data?.typeParameter; + return this.data?.typeParameter; } set typeParameter(value: any) { this.data.typeParameter = value; } get nameType() { - return this._data?.nameType; + return this.data?.nameType; } set nameType(value: any) { this.data.nameType = value; } get clauses() { - return this._data?.clauses; + return this.data?.clauses; } set clauses(value: any) { this.data.clauses = value; } get variableDeclaration() { - return this._data?.variableDeclaration; + return this.data?.variableDeclaration; } set variableDeclaration(value: any) { this.data.variableDeclaration = value; } get block() { - return this._data?.block; + return this.data?.block; } set block(value: any) { this.data.block = value; } get typeExpression() { - return this._data?.typeExpression; + return this.data?.typeExpression; } set typeExpression(value: any) { this.data.typeExpression = value; } get tagName() { - return this._data?.tagName; + return this.data?.tagName; } set tagName(value: any) { this.data.tagName = value; } get comment() { - return this._data?.comment; + return this.data?.comment; } set comment(value: any) { this.data.comment = value; } get fullName() { - return this._data?.fullName; + return this.data?.fullName; } set fullName(value: any) { this.data.fullName = value; } get endOfFileToken() { - return this._data?.endOfFileToken; + return this.data?.endOfFileToken; } set endOfFileToken(value: any) { this.data.endOfFileToken = value; } get fileName() { - return this._data?.fileName; + return this.data?.fileName; } set fileName(value: any) { this.data.fileName = value; } get path() { - return this._data?.path; + return this.data?.path; } set path(value: any) { this.data.path = value; } get text() { - return this._data?.text; + return this.data?.text; } set text(value: any) { this.data.text = value; } get resolvedPath() { - return this._data?.resolvedPath; + return this.data?.resolvedPath; } set resolvedPath(value: any) { this.data.resolvedPath = value; } get originalFileName() { - return this._data?.originalFileName; + return this.data?.originalFileName; } set originalFileName(value: any) { this.data.originalFileName = value; } get redirectInfo() { - return this._data?.redirectInfo; + return this.data?.redirectInfo; } set redirectInfo(value: any) { this.data.redirectInfo = value; } get amdDependencies() { - return this._data?.amdDependencies; + return this.data?.amdDependencies; } set amdDependencies(value: any) { this.data.amdDependencies = value; } get moduleName() { - return this._data?.moduleName; + return this.data?.moduleName; } set moduleName(value: any) { this.data.moduleName = value; } get referencedFiles() { - return this._data?.referencedFiles; + return this.data?.referencedFiles; } set referencedFiles(value: any) { this.data.referencedFiles = value; } get typeReferenceDirectives() { - return this._data?.typeReferenceDirectives; + return this.data?.typeReferenceDirectives; } set typeReferenceDirectives(value: any) { this.data.typeReferenceDirectives = value; } get libReferenceDirectives() { - return this._data?.libReferenceDirectives; + return this.data?.libReferenceDirectives; } set libReferenceDirectives(value: any) { this.data.libReferenceDirectives = value; } get languageVariant() { - return this._data?.languageVariant; + return this.data?.languageVariant; } set languageVariant(value: any) { this.data.languageVariant = value; } get isDeclarationFile() { - return this._data?.isDeclarationFile; + return this.data?.isDeclarationFile; } set isDeclarationFile(value: any) { this.data.isDeclarationFile = value; } get renamedDependencies() { - return this._data?.renamedDependencies; + return this.data?.renamedDependencies; } set renamedDependencies(value: any) { this.data.renamedDependencies = value; } get hasNoDefaultLib() { - return this._data?.hasNoDefaultLib; + return this.data?.hasNoDefaultLib; } set hasNoDefaultLib(value: any) { this.data.hasNoDefaultLib = value; } get languageVersion() { - return this._data?.languageVersion; + return this.data?.languageVersion; } set languageVersion(value: any) { this.data.languageVersion = value; } get impliedNodeFormat() { - return this._data?.impliedNodeFormat; + return this.data?.impliedNodeFormat; } set impliedNodeFormat(value: any) { this.data.impliedNodeFormat = value; } get packageJsonLocations() { - return this._data?.packageJsonLocations; + return this.data?.packageJsonLocations; } set packageJsonLocations(value: any) { this.data.packageJsonLocations = value; } get packageJsonScope() { - return this._data?.packageJsonScope; + return this.data?.packageJsonScope; } set packageJsonScope(value: any) { this.data.packageJsonScope = value; } get scriptKind() { - return this._data?.scriptKind; + return this.data?.scriptKind; } set scriptKind(value: any) { this.data.scriptKind = value; } get externalModuleIndicator() { - return this._data?.externalModuleIndicator; + return this.data?.externalModuleIndicator; } set externalModuleIndicator(value: any) { this.data.externalModuleIndicator = value; } get setExternalModuleIndicator() { - return this._data?.setExternalModuleIndicator; + return this.data?.setExternalModuleIndicator; } set setExternalModuleIndicator(value: any) { this.data.setExternalModuleIndicator = value; } get commonJsModuleIndicator() { - return this._data?.commonJsModuleIndicator; + return this.data?.commonJsModuleIndicator; } set commonJsModuleIndicator(value: any) { this.data.commonJsModuleIndicator = value; } get jsGlobalAugmentations() { - return this._data?.jsGlobalAugmentations; + return this.data?.jsGlobalAugmentations; } set jsGlobalAugmentations(value: any) { this.data.jsGlobalAugmentations = value; } get identifiers() { - return this._data?.identifiers; + return this.data?.identifiers; } set identifiers(value: any) { this.data.identifiers = value; } get nodeCount() { - return this._data?.nodeCount; + return this.data?.nodeCount; } set nodeCount(value: any) { this.data.nodeCount = value; } get identifierCount() { - return this._data?.identifierCount; + return this.data?.identifierCount; } set identifierCount(value: any) { this.data.identifierCount = value; } get symbolCount() { - return this._data?.symbolCount; + return this.data?.symbolCount; } set symbolCount(value: any) { this.data.symbolCount = value; } get parseDiagnostics() { - return this._data?.parseDiagnostics; + return this.data?.parseDiagnostics; } set parseDiagnostics(value: any) { this.data.parseDiagnostics = value; } get bindDiagnostics() { - return this._data?.bindDiagnostics; + return this.data?.bindDiagnostics; } set bindDiagnostics(value: any) { this.data.bindDiagnostics = value; } get bindSuggestionDiagnostics() { - return this._data?.bindSuggestionDiagnostics; + return this.data?.bindSuggestionDiagnostics; } set bindSuggestionDiagnostics(value: any) { this.data.bindSuggestionDiagnostics = value; } get jsDocDiagnostics() { - return this._data?.jsDocDiagnostics; + return this.data?.jsDocDiagnostics; } set jsDocDiagnostics(value: any) { this.data.jsDocDiagnostics = value; } get additionalSyntacticDiagnostics() { - return this._data?.additionalSyntacticDiagnostics; + return this.data?.additionalSyntacticDiagnostics; } set additionalSyntacticDiagnostics(value: any) { this.data.additionalSyntacticDiagnostics = value; } get lineMap() { - return this._data?.lineMap; + return this.data?.lineMap; } set lineMap(value: any) { this.data.lineMap = value; } get classifiableNames() { - return this._data?.classifiableNames; + return this.data?.classifiableNames; } set classifiableNames(value: any) { this.data.classifiableNames = value; } get commentDirectives() { - return this._data?.commentDirectives; + return this.data?.commentDirectives; } set commentDirectives(value: any) { this.data.commentDirectives = value; } get imports() { - return this._data?.imports; + return this.data?.imports; } set imports(value: any) { this.data.imports = value; } get moduleAugmentations() { - return this._data?.moduleAugmentations; + return this.data?.moduleAugmentations; } set moduleAugmentations(value: any) { this.data.moduleAugmentations = value; } get patternAmbientModules() { - return this._data?.patternAmbientModules; + return this.data?.patternAmbientModules; } set patternAmbientModules(value: any) { this.data.patternAmbientModules = value; } get ambientModuleNames() { - return this._data?.ambientModuleNames; + return this.data?.ambientModuleNames; } set ambientModuleNames(value: any) { this.data.ambientModuleNames = value; } get checkJsDirective() { - return this._data?.checkJsDirective; + return this.data?.checkJsDirective; } set checkJsDirective(value: any) { this.data.checkJsDirective = value; } get version() { - return this._data?.version; + return this.data?.version; } set version(value: any) { this.data.version = value; } get pragmas() { - return this._data?.pragmas; + return this.data?.pragmas; } set pragmas(value: any) { this.data.pragmas = value; } get localJsxNamespace() { - return this._data?.localJsxNamespace; + return this.data?.localJsxNamespace; } set localJsxNamespace(value: any) { this.data.localJsxNamespace = value; } get localJsxFragmentNamespace() { - return this._data?.localJsxFragmentNamespace; + return this.data?.localJsxFragmentNamespace; } set localJsxFragmentNamespace(value: any) { this.data.localJsxFragmentNamespace = value; } get localJsxFactory() { - return this._data?.localJsxFactory; + return this.data?.localJsxFactory; } set localJsxFactory(value: any) { this.data.localJsxFactory = value; } get localJsxFragmentFactory() { - return this._data?.localJsxFragmentFactory; + return this.data?.localJsxFragmentFactory; } set localJsxFragmentFactory(value: any) { this.data.localJsxFragmentFactory = value; } get jsDocParsingMode() { - return this._data?.jsDocParsingMode; + return this.data?.jsDocParsingMode; } set jsDocParsingMode(value: any) { this.data.jsDocParsingMode = value; } get extendedSourceFiles() { - return this._data?.extendedSourceFiles; + return this.data?.extendedSourceFiles; } set extendedSourceFiles(value: any) { this.data.extendedSourceFiles = value; } get configFileSpecs() { - return this._data?.configFileSpecs; + return this.data?.configFileSpecs; } set configFileSpecs(value: any) { this.data.configFileSpecs = value; } get keywordToken() { - return this._data?.keywordToken; + return this.data?.keywordToken; } set keywordToken(value: any) { this.data.keywordToken = value; } get namedBindings() { - return this._data?.namedBindings; + return this.data?.namedBindings; } set namedBindings(value: any) { this.data.namedBindings = value; } get textSourceNode() { - return this._data?.textSourceNode; + return this.data?.textSourceNode; } set textSourceNode(value: any) { this.data.textSourceNode = value; } get singleQuote() { - return this._data?.singleQuote; + return this.data?.singleQuote; } set singleQuote(value: any) { this.data.singleQuote = value; } get isUnterminated() { - return this._data?.isUnterminated; + return this.data?.isUnterminated; } set isUnterminated(value: any) { this.data.isUnterminated = value; } get hasExtendedUnicodeEscape() { - return this._data?.hasExtendedUnicodeEscape; + return this.data?.hasExtendedUnicodeEscape; } set hasExtendedUnicodeEscape(value: any) { this.data.hasExtendedUnicodeEscape = value; } get templateFlags() { - return this._data?.templateFlags; + return this.data?.templateFlags; } set templateFlags(value: any) { this.data.templateFlags = value; } get rawText() { - return this._data?.rawText; + return this.data?.rawText; } set rawText(value: any) { this.data.rawText = value; } get numericLiteralFlags() { - return this._data?.numericLiteralFlags; + return this.data?.numericLiteralFlags; } set numericLiteralFlags(value: any) { this.data.numericLiteralFlags = value; } get arguments() { - return this._data?.arguments; + return this.data?.arguments; } set arguments(value: any) { this.data.arguments = value; } get isNameFirst() { - return this._data?.isNameFirst; + return this.data?.isNameFirst; } set isNameFirst(value: any) { this.data.isNameFirst = value; } get isBracketed() { - return this._data?.isBracketed; + return this.data?.isBracketed; } set isBracketed(value: any) { this.data.isBracketed = value; } get jsDocPropertyTags() { - return this._data?.jsDocPropertyTags; + return this.data?.jsDocPropertyTags; } set jsDocPropertyTags(value: any) { this.data.jsDocPropertyTags = value; } get isArrayType() { - return this._data?.isArrayType; + return this.data?.isArrayType; } set isArrayType(value: any) { this.data.isArrayType = value; } get declarations() { - return this._data?.declarations; + return this.data?.declarations; } set declarations(value: any) { this.data.declarations = value; } get elements() { - return this._data?.elements; + return this.data?.elements; } set elements(value: any) { this.data.elements = value; } get isTypeOf() { - return this._data?.isTypeOf; + return this.data?.isTypeOf; } set isTypeOf(value: any) { this.data.isTypeOf = value; } get argument() { - return this._data?.argument; + return this.data?.argument; } set argument(value: any) { this.data.argument = value; } get assertions() { - return this._data?.assertions; + return this.data?.assertions; } set assertions(value: any) { this.data.assertions = value; } get qualifier() { - return this._data?.qualifier; + return this.data?.qualifier; } set qualifier(value: any) { this.data.qualifier = value; } get typeName() { - return this._data?.typeName; + return this.data?.typeName; } set typeName(value: any) { this.data.typeName = value; } get exprName() { - return this._data?.exprName; + return this.data?.exprName; } set exprName(value: any) { this.data.exprName = value; } get assertsModifier() { - return this._data?.assertsModifier; + return this.data?.assertsModifier; } set assertsModifier(value: any) { this.data.assertsModifier = value; } get parameterName() { - return this._data?.parameterName; + return this.data?.parameterName; } set parameterName(value: any) { this.data.parameterName = value; } get elementType() { - return this._data?.elementType; + return this.data?.elementType; } set elementType(value: any) { this.data.elementType = value; } get types() { - return this._data?.types; + return this.data?.types; } set types(value: any) { this.data.types = value; } get operator() { - return this._data?.operator; + return this.data?.operator; } set operator(value: any) { this.data.operator = value; } get objectType() { - return this._data?.objectType; + return this.data?.objectType; } set objectType(value: any) { this.data.objectType = value; } get indexType() { - return this._data?.indexType; + return this.data?.indexType; } set indexType(value: any) { this.data.indexType = value; } get literal() { - return this._data?.literal; + return this.data?.literal; } set literal(value: any) { this.data.literal = value; } get head() { - return this._data?.head; + return this.data?.head; } set head(value: any) { this.data.head = value; } get templateSpans() { - return this._data?.templateSpans; + return this.data?.templateSpans; } set templateSpans(value: any) { this.data.templateSpans = value; } get postfix() { - return this._data?.postfix; + return this.data?.postfix; } set postfix(value: any) { this.data.postfix = value; } get operand() { - return this._data?.operand; + return this.data?.operand; } set operand(value: any) { this.data.operand = value; } get openingElement() { - return this._data?.openingElement; + return this.data?.openingElement; } set openingElement(value: any) { this.data.openingElement = value; } get children() { - return this._data?.children; + return this.data?.children; } set children(value: any) { this.data.children = value; } get closingElement() { - return this._data?.closingElement; + return this.data?.closingElement; } set closingElement(value: any) { this.data.closingElement = value; } get openingFragment() { - return this._data?.openingFragment; + return this.data?.openingFragment; } set openingFragment(value: any) { this.data.openingFragment = value; } get closingFragment() { - return this._data?.closingFragment; + return this.data?.closingFragment; } set closingFragment(value: any) { this.data.closingFragment = value; } get tag() { - return this._data?.tag; + return this.data?.tag; } set tag(value: any) { this.data.tag = value; } get template() { - return this._data?.template; + return this.data?.template; } set template(value: any) { this.data.template = value; } get thisArg() { - return this._data?.thisArg; + return this.data?.thisArg; } set thisArg(value: any) { this.data.thisArg = value; } get isSpread() { - return this._data?.isSpread; + return this.data?.isSpread; } set isSpread(value: any) { this.data.isSpread = value; } get tupleNameSource() { - return this._data?.tupleNameSource; + return this.data?.tupleNameSource; } set tupleNameSource(value: any) { this.data.tupleNameSource = value; } get whenTrue() { - return this._data?.whenTrue; + return this.data?.whenTrue; } set whenTrue(value: any) { this.data.whenTrue = value; } get colonToken() { - return this._data?.colonToken; + return this.data?.colonToken; } set colonToken(value: any) { this.data.colonToken = value; } get whenFalse() { - return this._data?.whenFalse; + return this.data?.whenFalse; } set whenFalse(value: any) { this.data.whenFalse = value; } get containsOnlyTriviaWhiteSpaces() { - return this._data?.containsOnlyTriviaWhiteSpaces; + return this.data?.containsOnlyTriviaWhiteSpaces; } set containsOnlyTriviaWhiteSpaces(value: any) { this.data.containsOnlyTriviaWhiteSpaces = value; } get namespace() { - return this._data?.namespace; + return this.data?.namespace; } set namespace(value: any) { this.data.namespace = value; } get token() { - return this._data?.token; + return this.data?.token; } set token(value: any) { this.data.token = value; } get value() { - return this._data?.value; + return this.data?.value; } set value(value: any) { this.data.value = value; } get tags() { - return this._data?.tags; + return this.data?.tags; } set tags(value: any) { this.data.tags = value; } get class() { - return this._data?.class; + return this.data?.class; } set class(value: any) { this.data.class = value; } get sourceFiles() { - return this._data?.sourceFiles; + return this.data?.sourceFiles; } set sourceFiles(value: any) { this.data.sourceFiles = value; } get syntheticFileReferences() { - return this._data?.syntheticFileReferences; + return this.data?.syntheticFileReferences; } set syntheticFileReferences(value: any) { this.data.syntheticFileReferences = value; } get syntheticTypeReferences() { - return this._data?.syntheticTypeReferences; + return this.data?.syntheticTypeReferences; } set syntheticTypeReferences(value: any) { this.data.syntheticTypeReferences = value; } get syntheticLibReferences() { - return this._data?.syntheticLibReferences; + return this.data?.syntheticLibReferences; } set syntheticLibReferences(value: any) { this.data.syntheticLibReferences = value; @@ -10471,51 +10443,31 @@ export class NodeImpl { // this.original = undefined; // this.emitNode = undefined; // } -class TokenImpl { - pos; // Node, Token, Identifier - end; // Node, Token, Identifier - kind; // Node, Token, Identifier - id = 0; // Node, Token, Identifier - flags = NodeFlags.None; // Node, Token, Identifier - transformFlags = TransformFlags.None; // Node, Token, Identifier - parent: Node = undefined!; // Node, Token, Identifier - emitNode = undefined; // Node, Token, Identifier - constructor(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; - } - get data() { - return this; - } -} - -class IdentifierImpl { - pos; // Node, Token, Identifier - end; // Node, Token, Identifier - kind; // Node, Token, Identifier - id = 0; // Node, Token, Identifier - flags = NodeFlags.None; // Node, Token, Identifier - transformFlags = TransformFlags.None; // Node, Token, Identifier - parent: Node = undefined!; // Node, Token, Identifier - original: Node = undefined!; // Node, Token, Identifier - emitNode = undefined; // Node, Token, Identifier - escapedText = undefined; - jsDoc = undefined; // initialized by parser (JsDocContainer) - flowNode = undefined; // initialized by binder (FlowContainer) - symbol = undefined!; // initialized by checker - constructor(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; - } - get data() { - return this; - } -} +// 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 @@ -10527,9 +10479,9 @@ function SourceMapSource(this: SourceMapSource, fileName: string, text: string, /** @internal */ export const objectAllocator: ObjectAllocator = { getNodeConstructor: () => NodeImpl as any, - getTokenConstructor: () => TokenImpl as any, - getIdentifierConstructor: () => IdentifierImpl as any, - getPrivateIdentifierConstructor: () => IdentifierImpl as any, + getTokenConstructor: () => NodeImpl as any, + getIdentifierConstructor: () => NodeImpl as any, + getPrivateIdentifierConstructor: () => NodeImpl as any, getSourceFileConstructor: () => NodeImpl as any, getSymbolConstructor: () => Symbol as any, getTypeConstructor: () => TypeImpl as any, diff --git a/src/services/services.ts b/src/services/services.ts index 6509640507f41..fc8e54f2950a6 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -60,7 +60,6 @@ import { EditorOptions, EditorSettings, ElementAccessExpression, - EmitNode, EmitTextWriter, emptyArray, emptyOptions, @@ -194,7 +193,6 @@ import { isTextWhiteSpaceLike, isThisTypeParameter, isTransientSymbol, - JSDoc, JsDoc, JSDocContainer, JSDocParsingMode, @@ -322,15 +320,12 @@ import { timestamp, TodoComment, TodoCommentDescriptor, - Token, toPath, tracing, - TransformFlags, Type, TypeChecker, TypeFlags, TypeImpl, - TypeNode, TypeParameter, TypeReference, typeToDisplayParts, @@ -377,6 +372,16 @@ class NodeObject extends NodeImpl implements Node { constructor(kind: TKind, pos: number, end: number) { super(kind, pos, end); } + + override get text(): string { + if (this.kind === SyntaxKind.Identifier || this.kind === SyntaxKind.PrivateIdentifier) { + return idText(this as any as Identifier); + } + return super.text; + } + override set text(value) { + super.text = value; + } 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"); @@ -514,7 +519,7 @@ class NodeObject extends NodeImpl implements Node { public update(newText: string, textChangeRange: TextChangeRange): SourceFile { Debug.assertEqual(this.kind, SyntaxKind.SourceFile); - return updateSourceFile(this as any as SourceFile, newText, textChangeRange); + return updateSourceFile(this as SourceFile, newText, textChangeRange); } public getLineAndCharacterOfPosition(position: number): LineAndCharacter { @@ -778,98 +783,6 @@ function createSyntaxList(nodes: NodeArray, parent: Node): Node { 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; - get data() { - return this; - } - - 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; @@ -1004,37 +917,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 = undefined!; - public original?: Node | undefined = undefined; - 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; - jsDoc = undefined; // initialized by parser (JsDocContainer) - flowNode = undefined; // initialized by binder (FlowContainer) - constructor(kind: SyntaxKind.Identifier, pos: number, end: number) { - super(kind, pos, end); - this.jsDocComments = undefined; - this.symbol = undefined!; - } - - get text(): string { - return idText(this); - } -} class TypeObject extends TypeImpl implements Type { getFlags(): TypeFlags { return this.flags; @@ -1249,12 +1131,12 @@ class SourceMapSourceObject implements SourceMapSource { function getServicesObjectAllocator(): ObjectAllocator { return { - getNodeConstructor: () => NodeObject as any, - getTokenConstructor: () => TokenObject as any, + getNodeConstructor: () => NodeObject, + getTokenConstructor: () => NodeObject, - getIdentifierConstructor: () => IdentifierObject as any, - getPrivateIdentifierConstructor: () => IdentifierObject as any, - getSourceFileConstructor: () => NodeObject as any, + getIdentifierConstructor: () => NodeObject as any, + getPrivateIdentifierConstructor: () => NodeObject as any, + getSourceFileConstructor: () => NodeObject, getSymbolConstructor: () => SymbolObject, getTypeConstructor: () => TypeObject, getSignatureConstructor: () => SignatureObject, From b0b66c2f8ca0b51935e608bc850d2eba9183b9f3 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Wed, 26 Jun 2024 20:40:36 +0100 Subject: [PATCH 07/13] Fix tests --- src/compiler/factory/nodeFactory.ts | 870 +++++++++--------- src/compiler/utilities.ts | 26 +- src/harness/harnessUtils.ts | 6 + src/harness/typeWriter.ts | 6 +- src/services/services.ts | 4 + ...deprecated-ParseForTypeErrors-file.ts.diff | 21 +- .../deprecated-ParseForTypeInfo-file.ts.diff | 42 +- .../deprecated-ParseNone-file.js.diff | 42 +- .../deprecated-ParseNone-file.ts.diff | 42 +- .../link-ParseForTypeInfo-file.ts.diff | 22 +- .../link-ParseNone-file.js.diff | 22 +- .../link-ParseNone-file.ts.diff | 22 +- .../see-ParseForTypeInfo-file.ts.diff | 22 +- .../see-ParseNone-file.js.diff | 22 +- .../see-ParseNone-file.ts.diff | 22 +- 15 files changed, 563 insertions(+), 628 deletions(-) diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 290dc96189499..adb290952d2cc 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -186,7 +186,6 @@ import { isModuleDeclaration, isNamedDeclaration, isNodeArray, - isNodeKind, isNonNullChain, isNotEmittedStatement, isObjectLiteralExpression, @@ -327,7 +326,6 @@ import { NodeArray, NodeFactory, NodeFlags, - NodeImpl, nodeIsSynthesized, NonNullChain, NonNullExpression, @@ -476,11 +474,12 @@ export const enum NodeFactoryFlags { } const nodeFactoryPatchers: ((factory: NodeFactory) => void)[] = []; -type NodeData = Readonly> & - Mutable>> & -{ - data: Partial | Exclude>>> | undefined; -}; +type NodeData = + & Readonly> + & Mutable>> + & { + data: Partial | Exclude>>> | undefined; + }; /** @internal */ export function addNodeFactoryPatcher(fn: (factory: NodeFactory) => void) { nodeFactoryPatchers.push(fn); @@ -1236,12 +1235,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode Debug.assert(text.charCodeAt(0) !== CharacterCodes.minus, "Negative numbers should be created in combination with createPrefixUnaryExpression"); const node = createBaseDeclaration(SyntaxKind.NumericLiteral); node.data = { - numericLiteralFlags: numericLiteralFlags, + numericLiteralFlags, hasExtendedUnicodeEscape: false, isUnterminated: false, - text: text, + text, // localSymbol: undefined! - } + }; if (numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier) node.transformFlags |= TransformFlags.ContainsES2015; return node; } @@ -1258,16 +1257,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode return node; } - function createBaseStringLiteral(text: string, isSingleQuote?: boolean) { - return createBaseDeclaration(SyntaxKind.StringLiteral); - } - // @api function createStringLiteral(text: string, isSingleQuote?: boolean, hasExtendedUnicodeEscape?: boolean): StringLiteral { - const node = createBaseStringLiteral(text, isSingleQuote); + const node = createBaseNode(SyntaxKind.StringLiteral); node.data = { - hasExtendedUnicodeEscape: !!hasExtendedUnicodeEscape, - singleQuote: !!isSingleQuote, + hasExtendedUnicodeEscape, + singleQuote: isSingleQuote, // isUnterminated: false, text, // textSourceNode: undefined!, @@ -1287,7 +1282,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createRegularExpressionLiteral(text: string): RegularExpressionLiteral { const node = createBaseToken(SyntaxKind.RegularExpressionLiteral); - node.data = { + node.data = { hasExtendedUnicodeEscape: false, isUnterminated: false, text, @@ -1595,7 +1590,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createQualifiedName(left: EntityName, right: string | Identifier) { const node = createBaseNode(SyntaxKind.QualifiedName); const nodeData = node.data = { - left: left, + left, right: asName(right), }; node.transformFlags |= propagateChildFlags(nodeData.left) | @@ -1639,15 +1634,15 @@ 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.transformFlags = TransformFlags.ContainsTypeScript; node.data = { - modifiers : asNodeArray(modifiers), - name : asName(name), - constraint : constraint, - default : defaultType, - expression : undefined, // initialized by parser to report grammar errors + modifiers: asNodeArray(modifiers), + name: asName(name), + constraint, + default: defaultType, + expression: undefined, // initialized by parser to report grammar errors localSymbol: undefined, - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -1674,13 +1669,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseDeclaration(SyntaxKind.Parameter); const nodeData = node.data = { modifiers: asNodeArray(modifiers), - dotDotDotToken: dotDotDotToken, + dotDotDotToken, name: asName(name), - questionToken: questionToken, - type: type, + questionToken, + type, initializer: asInitializer(initializer), // localSymbol: undefined - } + }; if (isThisIdentifier(nodeData.name)) { node.transformFlags = TransformFlags.ContainsTypeScript; @@ -1755,8 +1750,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.data = { modifiers: asNodeArray(modifiers), name: asName(name), - type: type, - questionToken: questionToken, + type, + questionToken, initializer: undefined, // initialized by parser to report grammar errors localSymbol: undefined, }; @@ -1804,9 +1799,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: asName(name), questionToken: questionOrExclamationToken && isQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined, exclamationToken: questionOrExclamationToken && isExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined, - type: type, + type, initializer: asInitializer(initializer), - } + }; const isAmbient = node.flags & NodeFlags.Ambient || modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient; @@ -1850,19 +1845,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode | undefined, ) { const node = createBaseDeclaration(SyntaxKind.MethodSignature); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { modifiers: asNodeArray(modifiers), name: asName(name), - questionToken: questionToken, + questionToken, typeParameters: asNodeArray(typeParameters), parameters: asNodeArray(parameters), - type: type, + type, locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) typeArguments: undefined, // used in quick info localSymbol: undefined, - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -1901,21 +1896,21 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseDeclaration(SyntaxKind.MethodDeclaration); const nodeData = node.data = { modifiers: asNodeArray(modifiers), - asteriskToken: asteriskToken, + asteriskToken, name: asName(name), - questionToken: questionToken, + questionToken, exclamationToken: undefined, // initialized by parser for grammar errors typeParameters: asNodeArray(typeParameters), parameters: createNodeArray(parameters), - type: type, - body: body, + type, + body, typeArguments: undefined, // used in quick inf, locals: undefined, // initialized by binder (LocalsContainer, nextContainer: undefined, // initialized by binder (LocalsContainer) endFlowNode: undefined, returnFlowNode: undefined, localSymbol: undefined, - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) if (!nodeData.body) { @@ -1982,9 +1977,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode body: Block, ) { const node = createBaseDeclaration(SyntaxKind.ClassStaticBlockDeclaration); - node.transformFlags = propagateChildFlags(body) | TransformFlags.ContainsClassFields; node.data = { - body: body, + body, modifiers: undefined, // initialized by parser for grammar errors locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) @@ -1992,7 +1986,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode returnFlowNode: undefined, name: undefined, // localSymbol: undefined - } + }; + node.transformFlags = propagateChildFlags(body) | TransformFlags.ContainsClassFields; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2025,7 +2020,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { modifiers: asNodeArray(modifiers), parameters: createNodeArray(parameters), - body: body, + body, typeParameters: undefined, // initialized by parser for grammar errors type: undefined, // initialized by parser for grammar errors typeArguments: undefined, // used in quick info @@ -2038,9 +2033,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, // name: undefined, // questionToken: undefined, - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - + node.transformFlags = propagateChildrenFlags(nodeData.modifiers) | propagateChildrenFlags(nodeData.parameters) | (propagateChildFlags(nodeData.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) | @@ -2084,8 +2079,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode modifiers: asNodeArray(modifiers), name: asName(name), parameters: createNodeArray(parameters), - type: type, - body: body, + type, + body, typeArguments: undefined, // used in quick info, typeParameters: undefined, // initialized by parser for grammar errors, locals: undefined, // initialized by binder (LocalsContainer), @@ -2096,7 +2091,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, localSymbol: undefined, // questionToken: undefined - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -2153,7 +2148,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode modifiers: asNodeArray(modifiers), name: asName(name), parameters: createNodeArray(parameters), - body: body, + body, typeArguments: undefined, // used in quick info typeParameters: undefined, // initialized by parser for grammar errors type: undefined, // initialized by parser for grammar errors @@ -2165,8 +2160,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, localSymbol: undefined, // questionToken: undefined, - } - + }; + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) if (!nodeData.body) { @@ -2215,11 +2210,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode | undefined, ): CallSignatureDeclaration { const node = createBaseDeclaration(SyntaxKind.CallSignature); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { typeParameters: asNodeArray(typeParameters), parameters: asNodeArray(parameters), - type: type, + type, locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) @@ -2227,7 +2221,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode localSymbol: undefined, // name: undefined, // questionToken: undefined, - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2253,18 +2248,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode | undefined, ): ConstructSignatureDeclaration { const node = createBaseDeclaration(SyntaxKind.ConstructSignature); - node.transformFlags = TransformFlags.ContainsTypeScript, node.data = { typeParameters: asNodeArray(typeParameters), parameters: asNodeArray(parameters), - type: type, + type, locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) typeArguments: undefined, // used in quick info localSymbol: undefined, // name: undefined, // questionToken: undefined - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2290,7 +2285,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode | undefined, ): IndexSignatureDeclaration { const node = createBaseDeclaration(SyntaxKind.IndexSignature); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { modifiers: asNodeArray(modifiers), parameters: asNodeArray(parameters), @@ -2303,7 +2297,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // name: undefined, // questionToken: undefined, // typeParameters: undefined - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2325,11 +2320,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTemplateLiteralTypeSpan(type: TypeNode, literal: TemplateMiddle | TemplateTail) { const node = createBaseNode(SyntaxKind.TemplateLiteralTypeSpan); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { - type: type, - literal: literal, - } + type, + literal, + }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2353,12 +2348,12 @@ 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.transformFlags = TransformFlags.ContainsTypeScript; node.data = { - assertsModifier: assertsModifier, + assertsModifier, parameterName: asName(parameterName), - type: type, - } + type, + }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2374,11 +2369,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeReferenceNode(typeName: string | EntityName, typeArguments: readonly TypeNode[] | undefined) { const node = createBaseNode(SyntaxKind.TypeReference); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { typeName: asName(typeName), typeArguments: typeArguments && parenthesizerRules().parenthesizeTypeArguments(createNodeArray(typeArguments)), }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2397,11 +2392,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode, ) { const node = createBaseDeclaration(SyntaxKind.FunctionType); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { typeParameters: asNodeArray(typeParameters), parameters: asNodeArray(parameters), - type: type, + type, modifiers: undefined, // initialized by parser for grammar errors locals: undefined, // initialized by binder (LocalsContainer) @@ -2409,7 +2403,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeArguments: undefined, // used in quick info localSymbol: undefined, // name: undefined, - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; @@ -2451,19 +2446,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode, ): ConstructorTypeNode { const node = createBaseDeclaration(SyntaxKind.ConstructorType); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { modifiers: asNodeArray(modifiers), typeParameters: asNodeArray(typeParameters), parameters: asNodeArray(parameters), - type: type, + type, locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) typeArguments: undefined, // used in quick info localSymbol: undefined, // name: undefined, - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2512,11 +2507,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeQueryNode(exprName: EntityName, typeArguments?: readonly TypeNode[]) { const node = createBaseNode(SyntaxKind.TypeQuery); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { - exprName: exprName, + exprName, typeArguments: typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments), - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2531,11 +2526,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeLiteralNode(members: readonly TypeElement[] | undefined) { const node = createBaseDeclaration(SyntaxKind.TypeLiteral); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { members: createNodeArray(members), localSymbol: undefined, - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2549,10 +2544,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createArrayTypeNode(elementType: TypeNode) { const node = createBaseNode(SyntaxKind.ArrayType); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { elementType: parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(elementType), - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2566,10 +2561,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTupleTypeNode(elements: readonly (TypeNode | NamedTupleMember)[]) { const node = createBaseNode(SyntaxKind.TupleType); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { elements: createNodeArray(parenthesizerRules().parenthesizeElementTypesOfTupleType(elements)), - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2583,14 +2578,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamedTupleMember(dotDotDotToken: DotDotDotToken | undefined, name: Identifier, questionToken: QuestionToken | undefined, type: TypeNode) { const node = createBaseDeclaration(SyntaxKind.NamedTupleMember); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { - dotDotDotToken: dotDotDotToken, - name: name, - questionToken: questionToken, - type: type, + dotDotDotToken, + name, + questionToken, + type, localSymbol: undefined, }; + node.transformFlags = TransformFlags.ContainsTypeScript; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; @@ -2611,7 +2606,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseNode(SyntaxKind.OptionalType); node.data = { type: parenthesizerRules().parenthesizeTypeOfOptionalType(type), - } + }; node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2626,8 +2621,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createRestTypeNode(type: TypeNode) { const node = createBaseNode(SyntaxKind.RestType); + node.data = { type }; node.transformFlags = TransformFlags.ContainsTypeScript; - node.data = { type: type }; return node; } @@ -2640,10 +2635,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createUnionOrIntersectionTypeNode(kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType, types: readonly TypeNode[], parenthesize: (nodes: readonly TypeNode[]) => readonly TypeNode[]) { const node = createBaseNode(kind); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { types: factory.createNodeArray(parenthesize(types)), - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2676,16 +2671,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createConditionalTypeNode(checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode) { const node = createBaseNode(SyntaxKind.ConditionalType); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { checkType: parenthesizerRules().parenthesizeCheckTypeOfConditionalType(checkType), extendsType: parenthesizerRules().parenthesizeExtendsTypeOfConditionalType(extendsType), - trueType: trueType, - falseType: falseType, + trueType, + falseType, locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2702,7 +2697,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createInferTypeNode(typeParameter: TypeParameterDeclaration) { const node = createBaseNode(SyntaxKind.InferType); - node.data = { typeParameter: typeParameter } + node.data = { typeParameter }; node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2717,11 +2712,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTemplateLiteralType(head: TemplateHead, templateSpans: readonly TemplateLiteralTypeSpan[]) { const node = createBaseNode(SyntaxKind.TemplateLiteralType); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { - head: head, + head, templateSpans: createNodeArray(templateSpans), - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2742,14 +2737,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode isTypeOf = false, ): ImportTypeNode { const node = createBaseNode(SyntaxKind.ImportType); - node.transformFlags = TransformFlags.ContainsTypeScript; - const nodeData = node.data = { - argument: argument, - attributes: attributes, - qualifier: qualifier, + node.data = { + argument, + attributes, + qualifier, typeArguments: typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments), - isTypeOf: isTypeOf, - } + isTypeOf, + }; + node.transformFlags = TransformFlags.ContainsTypeScript; // dragomirtitian: Seems unused // if (nodeData.assertions && nodeData.assertions.assertClause && nodeData.attributes) { @@ -2779,7 +2774,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createParenthesizedType(type: TypeNode) { const node = createBaseNode(SyntaxKind.ParenthesizedType); - node.data = { type: type } + node.data = { type }; node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2801,13 +2796,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: TypeNode): TypeOperatorNode { const node = createBaseNode(SyntaxKind.TypeOperator); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { - operator: operator, + operator, type: operator === SyntaxKind.ReadonlyKeyword ? parenthesizerRules().parenthesizeOperandOfReadonlyTypeOperator(type) : parenthesizerRules().parenthesizeOperandOfTypeOperator(type), - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2821,11 +2816,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createIndexedAccessTypeNode(objectType: TypeNode, indexType: TypeNode) { const node = createBaseNode(SyntaxKind.IndexedAccessType); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { objectType: parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(objectType), - indexType: indexType, - } + indexType, + }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2840,20 +2835,20 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @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.transformFlags = TransformFlags.ContainsTypeScript; node.data = { - readonlyToken: readonlyToken, - typeParameter: typeParameter, - nameType: nameType, - questionToken: questionToken, - type: type, + readonlyToken, + typeParameter, + nameType, + questionToken, + type, members: members && createNodeArray(members), locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) localSymbol: undefined, - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2872,7 +2867,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createLiteralTypeNode(literal: LiteralTypeNode["literal"]) { const node = createBaseNode(SyntaxKind.LiteralType); - node.data = { literal: literal } + node.data = { literal }; node.transformFlags = TransformFlags.ContainsTypeScript; return node; } @@ -2891,7 +2886,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createObjectBindingPattern(elements: readonly BindingElement[]) { const node = createBaseNode(SyntaxKind.ObjectBindingPattern); - node.data = { elements: createNodeArray(elements) } + node.data = { elements: createNodeArray(elements) }; node.transformFlags |= propagateChildrenFlags(node.elements) | TransformFlags.ContainsES2015 | TransformFlags.ContainsBindingPattern; @@ -2912,7 +2907,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createArrayBindingPattern(elements: readonly ArrayBindingElement[]) { const node = createBaseNode(SyntaxKind.ArrayBindingPattern); - node.data = { elements: createNodeArray(elements) } + node.data = { elements: createNodeArray(elements) }; node.transformFlags |= propagateChildrenFlags(node.elements) | TransformFlags.ContainsES2015 | TransformFlags.ContainsBindingPattern; @@ -2930,12 +2925,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createBindingElement(dotDotDotToken: DotDotDotToken | undefined, propertyName: string | PropertyName | undefined, name: string | BindingName, initializer?: Expression) { const node = createBaseDeclaration(SyntaxKind.BindingElement); const nodeData = node.data = { - dotDotDotToken: dotDotDotToken, + dotDotDotToken, propertyName: asName(propertyName), name: asName(name), initializer: asInitializer(initializer), localSymbol: undefined, - } + }; node.transformFlags |= propagateChildFlags(nodeData.dotDotDotToken) | propagateNameFlags(nodeData.propertyName) | propagateNameFlags(nodeData.name) | @@ -2969,9 +2964,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // a trailing comma. const lastElement = elements && lastOrUndefined(elements); const elementsArray = createNodeArray(elements, lastElement && isOmittedExpression(lastElement) ? true : undefined); - const nodeData = node.data = { + node.data = { elements: parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(elementsArray), - multiLine: multiLine, + multiLine, }; node.transformFlags |= propagateChildrenFlags(node.elements); return node; @@ -2989,9 +2984,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseDeclaration(SyntaxKind.ObjectLiteralExpression); node.data = { properties: createNodeArray(properties), - multiLine: multiLine, + multiLine, localSymbol: undefined, - } + }; node.transformFlags |= propagateChildrenFlags(node.properties); // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -3008,9 +3003,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createBasePropertyAccessExpression(expression: LeftHandSideExpression, questionDotToken: QuestionDotToken | undefined, name: MemberName) { const node = createBaseDeclaration(SyntaxKind.PropertyAccessExpression); const nodeData = node.data = { - expression: expression, - questionDotToken: questionDotToken, - name: name, + expression, + questionDotToken, + name, localSymbol: undefined, }; node.transformFlags = propagateChildFlags(nodeData.expression) | @@ -3078,11 +3073,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createBaseElementAccessExpression(expression: LeftHandSideExpression, questionDotToken: QuestionDotToken | undefined, argumentExpression: Expression) { const node = createBaseDeclaration(SyntaxKind.ElementAccessExpression); const nodeData = node.data = { - expression: expression, - questionDotToken: questionDotToken, - argumentExpression: argumentExpression, + expression, + questionDotToken, + argumentExpression, localSymbol: undefined, - } + }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.questionDotToken) | propagateChildFlags(nodeData.argumentExpression); @@ -3146,12 +3141,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createBaseCallExpression(expression: LeftHandSideExpression, questionDotToken: QuestionDotToken | undefined, typeArguments: NodeArray | undefined, argumentsArray: NodeArray) { const node = createBaseDeclaration(SyntaxKind.CallExpression); const nodeData = node.data = { - expression: expression, - questionDotToken: questionDotToken, - typeArguments: typeArguments, + expression, + questionDotToken, + typeArguments, arguments: argumentsArray, localSymbol: undefined, - } + }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.questionDotToken) | @@ -3250,9 +3245,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { tag: parenthesizerRules().parenthesizeLeftSideOfAccess(tag, /*optionalChain*/ false), typeArguments: asNodeArray(typeArguments), - template: template, + template, // questionDotToken: undefined, - } + }; node.transformFlags |= propagateChildFlags(nodeData.tag) | propagateChildrenFlags(nodeData.typeArguments) | propagateChildFlags(nodeData.template) | @@ -3280,7 +3275,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseNode(SyntaxKind.TypeAssertionExpression); node.data = { expression: parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression), - type: type, + type, }; node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.type) | @@ -3326,13 +3321,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseDeclaration(SyntaxKind.FunctionExpression); const nodeData = node.data = { modifiers: asNodeArray(modifiers), - asteriskToken: asteriskToken, + asteriskToken, name: asName(name), typeParameters: asNodeArray(typeParameters), parameters: createNodeArray(parameters), - type: type, - body: body, - + type, + body, + typeArguments: undefined, // used in quick info locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) @@ -3341,7 +3336,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, localSymbol: undefined, // questionToken: undefined, - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -3403,7 +3398,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode modifiers: asNodeArray(modifiers), typeParameters: asNodeArray(typeParameters), parameters: createNodeArray(parameters), - type: type, + type, equalsGreaterThanToken: equalsGreaterThanToken ?? createToken(SyntaxKind.EqualsGreaterThanToken), body: parenthesizerRules().parenthesizeConciseBodyOfArrowFunction(body), @@ -3459,8 +3454,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createDeleteExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.DeleteExpression); + node.data = { expression: parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression) }; node.transformFlags |= propagateChildFlags(node.expression); - node.data = { expression: parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression) } return node; } @@ -3474,7 +3469,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createTypeOfExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.TypeOfExpression); - node.data = { expression:parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression) }; + node.data = { expression: parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression) }; node.transformFlags |= propagateChildFlags(node.expression); return node; } @@ -3489,7 +3484,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createVoidExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.VoidExpression); - node.data = { expression: parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression) } + node.data = { expression: parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression) }; node.transformFlags |= propagateChildFlags(node.expression); return node; } @@ -3522,11 +3517,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createPrefixUnaryExpression(operator: PrefixUnaryOperator, operand: Expression) { const node = createBaseNode(SyntaxKind.PrefixUnaryExpression); - node.transformFlags |= propagateChildFlags(node.operand); node.data = { - operator: operator, + operator, 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 ( @@ -3551,7 +3546,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createPostfixUnaryExpression(operand: Expression, operator: PostfixUnaryOperator) { const node = createBaseNode(SyntaxKind.PostfixUnaryExpression); node.data = { - operator: operator, + operator, operand: parenthesizerRules().parenthesizeOperandOfPostfixUnary(operand), }; node.transformFlags |= propagateChildFlags(node.operand); @@ -3581,10 +3576,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const operatorKind = operatorToken.kind; node.data = { left: parenthesizerRules().parenthesizeLeftSideOfBinary(operatorKind, left), - operatorToken: operatorToken, + operatorToken, right: parenthesizerRules().parenthesizeRightSideOfBinary(operatorKind, node.left, right), localSymbol: undefined, - } + }; node.transformFlags |= propagateChildFlags(node.left) | propagateChildFlags(node.operatorToken) | propagateChildFlags(node.right); @@ -3640,7 +3635,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode whenTrue: parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenTrue), colonToken: colonToken ?? createToken(SyntaxKind.ColonToken), whenFalse: parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenFalse), - } + }; node.transformFlags |= propagateChildFlags(nodeData.condition) | propagateChildFlags(nodeData.questionToken) | propagateChildFlags(nodeData.whenTrue) | @@ -3671,9 +3666,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createTemplateExpression(head: TemplateHead, templateSpans: readonly TemplateSpan[]) { const node = createBaseNode(SyntaxKind.TemplateExpression); node.data = { - head: head, + head, templateSpans: createNodeArray(templateSpans), - } + }; node.transformFlags |= propagateChildFlags(node.head) | propagateChildrenFlags(node.templateSpans) | TransformFlags.ContainsES2015; @@ -3727,10 +3722,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { // hasExtendedUnicodeEscape: false, // isUnterminated: false, - text: text, - rawText: rawText, + text, + rawText, templateFlags: templateFlags! & TokenFlags.TemplateLiteralLikeFlags, - } + }; node.transformFlags = getTransformFlagsOfTemplateLiteralLike(nodeData.templateFlags); return node; } @@ -3740,10 +3735,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { // hasExtendedUnicodeEscape: false, // isUnterminated: false, - text: text, - rawText: rawText, + text, + rawText, templateFlags: templateFlags! & TokenFlags.TemplateLiteralLikeFlags, - } + }; node.transformFlags = getTransformFlagsOfTemplateLiteralLike(nodeData.templateFlags); return node; } @@ -3786,8 +3781,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseNode(SyntaxKind.YieldExpression); const nodeData = node.data = { expression: expression && parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), - asteriskToken: asteriskToken, - } + asteriskToken, + }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.asteriskToken) | TransformFlags.ContainsES2015 | @@ -3837,7 +3832,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode heritageClauses: asNodeArray(heritageClauses), members: createNodeArray(members), // localSymbol: undefined. - } + }; node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateNameFlags(nodeData.name) | propagateChildrenFlags(nodeData.typeParameters) | @@ -3898,9 +3893,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createAsExpression(expression: Expression, type: TypeNode) { const node = createBaseNode(SyntaxKind.AsExpression); const nodeData = node.data = { - expression: expression, - type: type, - } + expression, + type, + }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.type) | TransformFlags.ContainsTypeScript; @@ -3918,7 +3913,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNonNullExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.NonNullExpression); - node.data = { expression: parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false) }; + node.data = { expression: parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false) }; node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsTypeScript; return node; @@ -3938,9 +3933,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createSatisfiesExpression(expression: Expression, type: TypeNode) { const node = createBaseNode(SyntaxKind.SatisfiesExpression); const nodeData = node.data = { - expression: expression, - type: type, - } + expression, + type, + }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.type) | TransformFlags.ContainsTypeScript; @@ -3959,7 +3954,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createNonNullChain(expression: Expression) { const node = createBaseNode(SyntaxKind.NonNullExpression); node.flags |= NodeFlags.OptionalChain; - node.data = { expression: parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true) } + node.data = { expression: parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ true) }; node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsTypeScript; return node; @@ -3977,9 +3972,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createMetaProperty(keywordToken: MetaProperty["keywordToken"], name: Identifier) { const node = createBaseNode(SyntaxKind.MetaProperty); const nodeData = node.data = { - keywordToken: keywordToken, - name: name, - } + keywordToken, + name, + }; node.transformFlags |= propagateChildFlags(nodeData.name); switch (keywordToken) { case SyntaxKind.NewKeyword: @@ -4011,9 +4006,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createTemplateSpan(expression: Expression, literal: TemplateMiddle | TemplateTail) { const node = createBaseNode(SyntaxKind.TemplateSpan); const nodeData = node.data = { - expression: expression, - literal: literal, - } + expression, + literal, + }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.literal) | TransformFlags.ContainsES2015; @@ -4044,12 +4039,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseNode(SyntaxKind.Block); const nodeData = node.data = { statements: createNodeArray(statements), - multiLine: multiLine, - + multiLine, + locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - } - + }; + // node.jsDoc= undefined; // initialized by parser (JsDocContainer) node.transformFlags |= propagateChildrenFlags(nodeData.statements); return node; @@ -4068,13 +4063,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { modifiers: asNodeArray(modifiers), declarationList: isArray(declarationList) ? createVariableDeclarationList(declarationList) : declarationList, - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateChildFlags(nodeData.declarationList); - + if (modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; } @@ -4100,7 +4095,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createExpressionStatement(expression: Expression): ExpressionStatement { const node = createBaseNode(SyntaxKind.ExpressionStatement); - const nodeData = node.data = { expression: parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression) } + const nodeData = node.data = { expression: parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression) }; node.transformFlags |= propagateChildFlags(nodeData.expression); // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -4119,7 +4114,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createIfStatement(expression: Expression, thenStatement: Statement, elseStatement?: Statement) { const node = createBaseNode(SyntaxKind.IfStatement); const nodeData = node.data = { - expression: expression, + expression, thenStatement: asEmbeddedStatement(thenStatement), elseStatement: asEmbeddedStatement(elseStatement), }; @@ -4146,7 +4141,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseNode(SyntaxKind.DoStatement); const nodeData = node.data = { statement: asEmbeddedStatement(statement), - expression: expression, + expression, }; node.transformFlags |= propagateChildFlags(nodeData.statement) | propagateChildFlags(nodeData.expression); @@ -4168,9 +4163,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createWhileStatement(expression: Expression, statement: Statement) { const node = createBaseNode(SyntaxKind.WhileStatement); const nodeData = node.data = { - expression: expression, + expression, statement: asEmbeddedStatement(statement), - } + }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.statement); @@ -4190,14 +4185,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createForStatement(initializer: ForInitializer | undefined, condition: Expression | undefined, incrementor: Expression | undefined, statement: Statement) { const node = createBaseNode(SyntaxKind.ForStatement); - const nodeData = node.data = { - initializer: initializer, - condition: condition, - incrementor: incrementor, + const nodeData = node.data = { + initializer, + condition, + incrementor, statement: asEmbeddedStatement(statement), locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -4221,22 +4216,21 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createForInStatement(initializer: ForInitializer, expression: Expression, statement: Statement) { const node = createBaseNode(SyntaxKind.ForInStatement); - + const nodeData = node.data = { - initializer: initializer, - expression: expression, + initializer, + expression, statement: asEmbeddedStatement(statement), locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) node.transformFlags |= propagateChildFlags(nodeData.initializer) | propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.statement); - - + return node; } @@ -4253,17 +4247,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createForOfStatement(awaitModifier: AwaitKeyword | undefined, initializer: ForInitializer, expression: Expression, statement: Statement) { const node = createBaseNode(SyntaxKind.ForOfStatement); const nodeData = node.data = { - awaitModifier: awaitModifier, - initializer: initializer, + awaitModifier, + initializer, expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), statement: asEmbeddedStatement(statement), - + locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) - + node.transformFlags |= propagateChildFlags(nodeData.awaitModifier) | propagateChildFlags(nodeData.initializer) | propagateChildFlags(nodeData.expression) | @@ -4306,7 +4300,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBreakStatement(label?: string | Identifier): BreakStatement { const node = createBaseNode(SyntaxKind.BreakStatement); - const nodeData = node.data = { label: asName(label) } + const nodeData = node.data = { label: asName(label) }; node.transformFlags |= propagateChildFlags(nodeData.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; @@ -4325,7 +4319,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createReturnStatement(expression?: Expression): ReturnStatement { const node = createBaseNode(SyntaxKind.ReturnStatement); - const nodeData = node.data = { expression: expression }; + const nodeData = node.data = { expression }; // return in an ES2018 async generator must be awaited node.transformFlags |= propagateChildFlags(nodeData.expression) | TransformFlags.ContainsES2018 | @@ -4347,9 +4341,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createWithStatement(expression: Expression, statement: Statement) { const node = createBaseNode(SyntaxKind.WithStatement); const nodeData = node.data = { - expression: expression, + expression, statement: asEmbeddedStatement(statement), - } + }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.statement); @@ -4372,8 +4366,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { possiblyExhaustive: false, // initialized by binder expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), - caseBlock: caseBlock, - } + caseBlock, + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) node.transformFlags |= propagateChildFlags(nodeData.expression) | @@ -4396,7 +4390,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { label: asName(label), statement: asEmbeddedStatement(statement), - } + }; node.transformFlags |= propagateChildFlags(nodeData.label) | propagateChildFlags(nodeData.statement); @@ -4416,7 +4410,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createThrowStatement(expression: Expression) { const node = createBaseNode(SyntaxKind.ThrowStatement); - const nodeData = node.data = { expression: expression }; + const nodeData = node.data = { expression }; node.transformFlags |= propagateChildFlags(nodeData.expression); // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -4435,10 +4429,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createTryStatement(tryBlock: Block, catchClause: CatchClause | undefined, finallyBlock: Block | undefined) { const node = createBaseNode(SyntaxKind.TryStatement); const nodeData = node.data = { - tryBlock: tryBlock, - catchClause: catchClause, - finallyBlock: finallyBlock, - } + tryBlock, + catchClause, + finallyBlock, + }; node.transformFlags |= propagateChildFlags(nodeData.tryBlock) | propagateChildFlags(nodeData.catchClause) | propagateChildFlags(nodeData.finallyBlock); @@ -4460,10 +4454,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createDebuggerStatement() { const node = createBaseNode(SyntaxKind.DebuggerStatement); - const nodeData = node.data; - - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4472,11 +4462,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseDeclaration(SyntaxKind.VariableDeclaration); const nodeData = node.data = { name: asName(name), - exclamationToken: exclamationToken, - type: type, + exclamationToken, + type, initializer: asInitializer(initializer), localSymbol: undefined, - } + }; node.transformFlags |= propagateNameFlags(nodeData.name) | propagateChildFlags(nodeData.initializer) | (nodeData.exclamationToken ?? nodeData.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); @@ -4499,7 +4489,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createVariableDeclarationList(declarations: readonly VariableDeclaration[], flags = NodeFlags.None) { const node = createBaseNode(SyntaxKind.VariableDeclarationList); node.flags |= flags & NodeFlags.BlockScoped; - node.data = { declarations: createNodeArray(declarations) } + node.data = { declarations: createNodeArray(declarations) }; node.transformFlags |= propagateChildrenFlags(node.declarations) | TransformFlags.ContainsHoistedDeclarationOrCompletion; if (flags & NodeFlags.BlockScoped) { @@ -4532,13 +4522,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseDeclaration(SyntaxKind.FunctionDeclaration); const nodeData = node.data = { modifiers: asNodeArray(modifiers), - asteriskToken: asteriskToken, + asteriskToken, name: asName(name), typeParameters: asNodeArray(typeParameters), parameters: createNodeArray(parameters), - type: type, - body: body, - + type, + body, + typeArguments: undefined, // used in quick info locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) @@ -4547,9 +4537,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, localSymbol: undefined, // questionToken: undefined, - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - + if (!nodeData.body || modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; } @@ -4624,7 +4614,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode heritageClauses: asNodeArray(heritageClauses), members: createNodeArray(members), localSymbol: undefined, - } + }; if (modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; @@ -4680,7 +4670,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode heritageClauses: asNodeArray(heritageClauses), members: createNodeArray(members), localSymbol: undefined, - } + }; node.transformFlags = TransformFlags.ContainsTypeScript; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -4713,17 +4703,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type: TypeNode, ) { const node = createBaseDeclaration(SyntaxKind.TypeAliasDeclaration); - node.transformFlags = TransformFlags.ContainsTypeScript; node.data = { modifiers: asNodeArray(modifiers), name: asName(name), typeParameters: asNodeArray(typeParameters), - type: type, + type, locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) localSymbol: undefined, - } + }; + node.transformFlags = TransformFlags.ContainsTypeScript; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4756,7 +4746,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: asName(name), members: createNodeArray(members), localSymbol: undefined, - } + }; node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateChildFlags(nodeData.name) | propagateChildrenFlags(nodeData.members) | @@ -4792,12 +4782,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.flags |= flags & (NodeFlags.Namespace | NodeFlags.NestedNamespace | NodeFlags.GlobalAugmentation); const nodeData = node.data = { modifiers: asNodeArray(modifiers), - name: name, - body: body, + name, + body, locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) localSymbol: undefined, - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) if (modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; @@ -4830,7 +4820,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createModuleBlock(statements: readonly Statement[]) { const node = createBaseNode(SyntaxKind.ModuleBlock); - const nodeData = node.data = { statements: createNodeArray(statements) } + const nodeData = node.data = { statements: createNodeArray(statements) }; node.transformFlags |= propagateChildrenFlags(nodeData.statements); // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -4849,10 +4839,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseNode(SyntaxKind.CaseBlock); const nodeData = node.data = { clauses: createNodeArray(clauses), - + locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - } + }; node.transformFlags |= propagateChildrenFlags(nodeData.clauses); @@ -4873,7 +4863,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: asName(name), modifiers: undefined, // initialized by parser to report grammar errors localSymbol: undefined, - } + }; node.transformFlags |= propagateIdentifierNameFlags(nodeData.name) | TransformFlags.ContainsTypeScript; @@ -4907,10 +4897,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { modifiers: asNodeArray(modifiers), name: asName(name), - isTypeOnly: isTypeOnly, - moduleReference: moduleReference, + isTypeOnly, + moduleReference, localSymbol: undefined, - } + }; node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateIdentifierNameFlags(nodeData.name) | propagateChildFlags(nodeData.moduleReference); @@ -4951,11 +4941,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseNode(SyntaxKind.ImportDeclaration); const nodeData = node.data = { modifiers: asNodeArray(modifiers), - importClause: importClause, - moduleSpecifier: moduleSpecifier, - attributes: attributes, + importClause, + moduleSpecifier, + attributes, assertClause: attributes, - } + }; node.transformFlags |= propagateChildFlags(nodeData.importClause) | propagateChildFlags(nodeData.moduleSpecifier); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context @@ -4984,11 +4974,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause { const node = createBaseDeclaration(SyntaxKind.ImportClause); const nodeData = node.data = { - isTypeOnly: isTypeOnly, - name: name, - namedBindings: namedBindings, + isTypeOnly, + name, + namedBindings, localSymbol: undefined, - } + }; node.transformFlags |= propagateChildFlags(nodeData.name) | propagateChildFlags(nodeData.namedBindings); if (isTypeOnly) { @@ -5012,9 +5002,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseNode(SyntaxKind.AssertClause); node.data = { elements: createNodeArray(elements), - multiLine: multiLine, + multiLine, token: SyntaxKind.AssertKeyword, - } + }; node.transformFlags |= TransformFlags.ContainsESNext; return node; } @@ -5031,9 +5021,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createAssertEntry(name: AssertionKey, value: Expression): AssertEntry { const node = createBaseNode(SyntaxKind.AssertEntry); node.data = { - name: name, - value: value, - } + name, + value, + }; node.transformFlags |= TransformFlags.ContainsESNext; return node; } @@ -5051,8 +5041,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseNode(SyntaxKind.ImportTypeAssertionContainer); node.data = { assertClause: clause, - multiLine: multiLine, - } + multiLine, + }; return node; } @@ -5072,8 +5062,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.data = { token: token ?? SyntaxKind.WithKeyword, elements: createNodeArray(elements), - multiLine: multiLine, - } + multiLine, + }; node.transformFlags |= TransformFlags.ContainsESNext; return node; } @@ -5090,9 +5080,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createImportAttribute(name: ImportAttributeName, value: Expression): ImportAttribute { const node = createBaseNode(SyntaxKind.ImportAttribute); node.data = { - name: name, - value: value, - } + name, + value, + }; node.transformFlags |= TransformFlags.ContainsESNext; return node; } @@ -5108,8 +5098,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamespaceImport(name: Identifier): NamespaceImport { const node = createBaseDeclaration(SyntaxKind.NamespaceImport); - node.data = { - name: name, + node.data = { + name, // localSymbol: undefined }; node.transformFlags |= propagateChildFlags(node.name); @@ -5127,8 +5117,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamespaceExport(name: ModuleExportName): NamespaceExport { const node = createBaseDeclaration(SyntaxKind.NamespaceExport); - node.data = { - name: name, + node.data = { + name, // localSymbol: undefined }; node.transformFlags |= propagateChildFlags(node.name) | @@ -5164,11 +5154,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createImportSpecifier(isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier) { const node = createBaseDeclaration(SyntaxKind.ImportSpecifier); const nodeData = node.data = { - isTypeOnly: isTypeOnly, - propertyName: propertyName, - name: name, + isTypeOnly, + propertyName, + name, localSymbol: undefined, - } + }; node.transformFlags |= propagateChildFlags(nodeData.propertyName) | propagateChildFlags(nodeData.name); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context @@ -5193,13 +5183,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseDeclaration(SyntaxKind.ExportAssignment); const nodeData = node.data = { modifiers: asNodeArray(modifiers), - isExportEquals: isExportEquals, + isExportEquals, expression: isExportEquals ? parenthesizerRules().parenthesizeRightSideOfBinary(SyntaxKind.EqualsToken, /*leftSide*/ undefined, expression) : parenthesizerRules().parenthesizeExpressionOfExportDefault(expression), localSymbol: undefined, // name: undefined, - } + }; node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateChildFlags(nodeData.expression); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context @@ -5230,14 +5220,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseDeclaration(SyntaxKind.ExportDeclaration); const nodeData = node.data = { modifiers: asNodeArray(modifiers), - isTypeOnly: isTypeOnly, - exportClause: exportClause, - moduleSpecifier: moduleSpecifier, - attributes: attributes, + isTypeOnly, + exportClause, + moduleSpecifier, + attributes, assertClause: attributes, localSymbol: undefined, // name: undefined, - } + }; node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateChildFlags(nodeData.exportClause) | propagateChildFlags(nodeData.moduleSpecifier); @@ -5278,7 +5268,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createNamedExports(elements: readonly ExportSpecifier[]) { const node = createBaseNode(SyntaxKind.NamedExports); - node.data = { elements: createNodeArray(elements) } + node.data = { elements: createNodeArray(elements) }; node.transformFlags |= propagateChildrenFlags(node.elements); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; @@ -5295,11 +5285,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createExportSpecifier(isTypeOnly: boolean, propertyName: string | ModuleExportName | undefined, name: string | ModuleExportName) { const node = createBaseNode(SyntaxKind.ExportSpecifier); const nodeData = node.data = { - isTypeOnly: isTypeOnly, + isTypeOnly, propertyName: asName(propertyName), name: asName(name), localSymbol: undefined, - } + }; node.transformFlags |= propagateChildFlags(nodeData.propertyName) | propagateChildFlags(nodeData.name); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context @@ -5320,7 +5310,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createMissingDeclaration(): MissingDeclaration { const node = createBaseDeclaration(SyntaxKind.MissingDeclaration); - + node.data = {}; // Bag for others to add what they need, we don't know what that will be // node.data.jsDoc = undefined; // initialized by parser (JsDocContainer) return node; } @@ -5332,7 +5322,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createExternalModuleReference(expression: Expression) { const node = createBaseNode(SyntaxKind.ExternalModuleReference); - node.data = { expression: expression }; + node.data = { expression }; node.transformFlags |= propagateChildFlags(node.expression); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; @@ -5374,7 +5364,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // createJSDocNamepathType function createJSDocUnaryTypeWorker(kind: T["kind"], type: T["type"]): T { const node = createBaseNode(kind); - node.data = { type: type, postfix: undefined } as any; + node.data = { type, postfix: undefined } as any; return node as unknown as T; } @@ -5402,14 +5392,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseDeclaration(SyntaxKind.JSDocFunctionType); const nodeData = node.data = { parameters: asNodeArray(parameters), - type: type, + type, locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) typeArguments: undefined, // used in quick info localSymbol: undefined, // name: undefined, // typeParameters: undefined, - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) node.transformFlags = propagateChildrenFlags(nodeData.parameters) | (nodeData.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); @@ -5428,10 +5418,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocTypeLiteral(propertyTags?: readonly JSDocPropertyLikeTag[], isArrayType = false): JSDocTypeLiteral { const node = createBaseDeclaration(SyntaxKind.JSDocTypeLiteral); - const nodeData = node.data = { + node.data = { jsDocPropertyTags: asNodeArray(propertyTags), - isArrayType: isArrayType, - } + isArrayType, + }; return node; } @@ -5446,7 +5436,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocTypeExpression(type: TypeNode): JSDocTypeExpression { const node = createBaseNode(SyntaxKind.JSDocTypeExpression); - node.data = { type: type }; + node.data = { type }; return node; } @@ -5460,14 +5450,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocSignature(typeParameters: readonly JSDocTemplateTag[] | undefined, parameters: readonly JSDocParameterTag[], type?: JSDocReturnTag): JSDocSignature { const node = createBaseDeclaration(SyntaxKind.JSDocSignature); - node.data ={ + node.data = { typeParameters: asNodeArray(typeParameters), parameters: createNodeArray(parameters), - type: type, + type, locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -5492,9 +5482,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createBaseJSDocTag(kind: T["kind"], tagName: Identifier, comment: string | NodeArray | undefined) { const node = createBaseNode(kind); node.data = { - tagName: tagName, - comment: comment, - } as NodeData['data'] as NodeData['data'] + tagName, + comment, + } as NodeData["data"] as NodeData["data"]; return node; } @@ -5502,11 +5492,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJSDocTemplateTag(tagName: Identifier | undefined, constraint: JSDocTypeExpression | undefined, typeParameters: readonly TypeParameterDeclaration[], comment?: string | NodeArray): JSDocTemplateTag { const node = createBaseNode(SyntaxKind.JSDocTemplateTag); node.data = { - tagName: tagName ?? createIdentifier("template"), + tagName: tagName ?? createIdentifier("template"), comment, - constraint: constraint, + constraint, typeParameters: createNodeArray(typeParameters), - } + }; return node; } @@ -5526,14 +5516,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.data = { tagName: tagName ?? createIdentifier("typedef"), comment, - typeExpression: typeExpression, - fullName: fullName, + typeExpression, + fullName, name: getJSDocTypeAliasName(fullName), locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) localSymbol: undefined, - } + }; return node; } @@ -5551,14 +5541,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJSDocParameterTag(tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression?: JSDocTypeExpression, isNameFirst?: boolean, comment?: string | NodeArray): JSDocParameterTag { const node = createBaseNode(SyntaxKind.JSDocParameterTag); node.data = { - isNameFirst: !!isNameFirst, - isBracketed: isBracketed, - name: name, - typeExpression: typeExpression, - tagName: tagName ?? createIdentifier("param"), + tagName: tagName ?? createIdentifier("param"), comment, + typeExpression, + name, localSymbol: undefined, - } + isNameFirst: !!isNameFirst, + isBracketed, + }; return node; } @@ -5578,14 +5568,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJSDocPropertyTag(tagName: Identifier | undefined, name: EntityName, isBracketed: boolean, typeExpression?: JSDocTypeExpression, isNameFirst?: boolean, comment?: string | NodeArray): JSDocPropertyTag { const node = createBaseNode(SyntaxKind.JSDocPropertyTag); node.data = { - isBracketed: isBracketed, - isNameFirst: !!isNameFirst, - tagName: tagName ?? createIdentifier("prop"), + tagName: tagName ?? createIdentifier("prop"), comment, - name: name, - typeExpression: typeExpression, + typeExpression, + name, + isNameFirst: !!isNameFirst, + isBracketed, localSymbol: undefined, - } + }; return node; } @@ -5605,15 +5595,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJSDocCallbackTag(tagName: Identifier | undefined, typeExpression: JSDocSignature, fullName?: Identifier | JSDocNamespaceDeclaration, comment?: string | NodeArray): JSDocCallbackTag { const node = createBaseNode(SyntaxKind.JSDocCallbackTag); node.data = { - tagName: tagName ?? createIdentifier("callback"), + tagName: tagName ?? createIdentifier("callback"), comment, - typeExpression: typeExpression, - fullName: fullName, + typeExpression, + fullName, name: getJSDocTypeAliasName(fullName), locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - } + }; return node; } @@ -5630,7 +5620,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocOverloadTag(tagName: Identifier | undefined, typeExpression: JSDocSignature, comment?: string | NodeArray): JSDocOverloadTag { const node = createBaseNode(SyntaxKind.JSDocOverloadTag); - node.data = { tagName: tagName ?? createIdentifier("overload"), comment, typeExpression: typeExpression }; + node.data = { tagName: tagName ?? createIdentifier("overload"), comment, typeExpression }; return node; } @@ -5649,8 +5639,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.data = { tagName: tagName ?? createIdentifier("augments"), comment, - class:className, - } + class: className, + }; return node; } @@ -5673,7 +5663,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocSeeTag(tagName: Identifier | undefined, name: JSDocNameReference | undefined, comment?: string | NodeArray): JSDocSeeTag { const node = createBaseNode(SyntaxKind.JSDocSeeTag); - node.data = { tagName: tagName ?? createIdentifier("see"), comment, name: name }; + node.data = { tagName: tagName ?? createIdentifier("see"), comment, name }; return node; } @@ -5689,7 +5679,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocNameReference(name: EntityName | JSDocMemberName): JSDocNameReference { const node = createBaseNode(SyntaxKind.JSDocNameReference); - node.data = { name: name }; + node.data = { name }; return node; } @@ -5703,10 +5693,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocMemberName(left: EntityName | JSDocMemberName, right: Identifier) { const node = createBaseNode(SyntaxKind.JSDocMemberName); - const nodeData = node.data = { - left: left, - right: right, - } + node.data = { + left, + right, + }; node.transformFlags |= propagateChildFlags(node.left) | propagateChildFlags(node.right); return node; @@ -5724,9 +5714,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJSDocLink(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLink { const node = createBaseNode(SyntaxKind.JSDocLink); node.data = { - name: name, - text: text, - } + name, + text, + }; return node; } @@ -5740,10 +5730,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocLinkCode(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkCode { const node = createBaseNode(SyntaxKind.JSDocLinkCode); - node.data = { - name: name, - text: text, - } + node.data = { + name, + text, + }; return node; } @@ -5757,10 +5747,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocLinkPlain(name: EntityName | JSDocMemberName | undefined, text: string): JSDocLinkPlain { const node = createBaseNode(SyntaxKind.JSDocLinkPlain); - node.data = { - name: name, - text: text, - } + node.data = { + name, + text, + }; return node; } @@ -5819,8 +5809,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.data = { tagName: tagName ?? createIdentifier(getDefaultTagNameForKind(kind)), comment, - typeExpression: typeExpression, - } + typeExpression, + }; return node as any as T; } @@ -5855,14 +5845,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocEnumTag(tagName: Identifier | undefined, typeExpression: JSDocTypeExpression, comment?: string | NodeArray) { const node = createBaseNode(SyntaxKind.JSDocEnumTag); - const nodeData = node.data = { - tagName: tagName ?? createIdentifier(getDefaultTagNameForKind(SyntaxKind.JSDocEnumTag)), + node.data = { + tagName: tagName ?? createIdentifier(getDefaultTagNameForKind(SyntaxKind.JSDocEnumTag)), comment, - typeExpression: typeExpression, + typeExpression, locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - } + }; return node; } @@ -5879,12 +5869,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJSDocImportTag(tagName: Identifier | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes?: ImportAttributes, comment?: string | NodeArray): JSDocImportTag { const node = createBaseNode(SyntaxKind.JSDocImportTag); node.data = { - tagName: tagName ?? createIdentifier("import"), + tagName: tagName ?? createIdentifier("import"), comment, - importClause: importClause, - moduleSpecifier: moduleSpecifier, - attributes: attributes, - } + importClause, + moduleSpecifier, + attributes, + }; return node; } @@ -5901,7 +5891,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJSDocText(text: string): JSDocText { const node = createBaseNode(SyntaxKind.JSDocText); - node.data = { text: text }; + node.data = { text }; return node; } @@ -5916,9 +5906,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJSDocComment(comment?: string | NodeArray | undefined, tags?: readonly JSDocTag[] | undefined) { const node = createBaseNode(SyntaxKind.JSDoc); node.data = { - comment: comment, + comment, tags: asNodeArray(tags), - } + }; return node; } @@ -5938,10 +5928,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJsxElement(openingElement: JsxOpeningElement, children: readonly JsxChild[], closingElement: JsxClosingElement) { const node = createBaseNode(SyntaxKind.JsxElement); const nodeData = node.data = { - openingElement: openingElement, + openingElement, children: createNodeArray(children), - closingElement: closingElement, - } + closingElement, + }; node.transformFlags |= propagateChildFlags(nodeData.openingElement) | propagateChildrenFlags(nodeData.children) | propagateChildFlags(nodeData.closingElement) | @@ -5962,10 +5952,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJsxSelfClosingElement(tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes) { const node = createBaseNode(SyntaxKind.JsxSelfClosingElement); const nodeData = node.data = { - tagName: tagName, + tagName, typeArguments: asNodeArray(typeArguments), - attributes: attributes, - } + attributes, + }; node.transformFlags |= propagateChildFlags(nodeData.tagName) | propagateChildrenFlags(nodeData.typeArguments) | propagateChildFlags(nodeData.attributes) | @@ -5989,10 +5979,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJsxOpeningElement(tagName: JsxTagNameExpression, typeArguments: readonly TypeNode[] | undefined, attributes: JsxAttributes) { const node = createBaseNode(SyntaxKind.JsxOpeningElement); const nodeData = node.data = { - tagName: tagName, + tagName, typeArguments: asNodeArray(typeArguments), - attributes: attributes, - } + attributes, + }; node.transformFlags |= propagateChildFlags(nodeData.tagName) | propagateChildrenFlags(nodeData.typeArguments) | propagateChildFlags(nodeData.attributes) | @@ -6015,7 +6005,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxClosingElement(tagName: JsxTagNameExpression) { const node = createBaseNode(SyntaxKind.JsxClosingElement); - node.data = { tagName: tagName } + node.data = { tagName }; node.transformFlags |= propagateChildFlags(node.tagName) | TransformFlags.ContainsJsx; return node; @@ -6032,10 +6022,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJsxFragment(openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment) { const node = createBaseNode(SyntaxKind.JsxFragment); const nodeData = node.data = { - openingFragment: openingFragment, + openingFragment, children: createNodeArray(children), - closingFragment: closingFragment, - } + closingFragment, + }; node.transformFlags |= propagateChildFlags(nodeData.openingFragment) | propagateChildrenFlags(nodeData.children) | propagateChildFlags(nodeData.closingFragment) | @@ -6058,9 +6048,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.data = { // hasExtendedUnicodeEscape: false, // isUnterminated: false, - text: text, + text, containsOnlyTriviaWhiteSpaces: !!containsOnlyTriviaWhiteSpaces, - } + }; node.transformFlags |= TransformFlags.ContainsJsx; return node; } @@ -6091,10 +6081,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJsxAttribute(name: JsxAttributeName, initializer: JsxAttributeValue | undefined) { const node = createBaseDeclaration(SyntaxKind.JsxAttribute); node.data = { - name: name, - initializer: initializer, + name, + initializer, localSymbol: undefined, - } + }; node.transformFlags |= propagateChildFlags(node.name) | propagateChildFlags(node.initializer) | TransformFlags.ContainsJsx; @@ -6128,10 +6118,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxSpreadAttribute(expression: Expression) { const node = createBaseNode(SyntaxKind.JsxSpreadAttribute); - node.data = { - expression: expression, + node.data = { + expression, localSymbol: undefined, - name: undefined + name: undefined, }; node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsJsx; @@ -6148,10 +6138,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createJsxExpression(dotDotDotToken: DotDotDotToken | undefined, expression: Expression | undefined) { const node = createBaseNode(SyntaxKind.JsxExpression); - const nodeData = node.data = { - dotDotDotToken: dotDotDotToken, - expression: expression, - } + node.data = { + dotDotDotToken, + expression, + }; node.transformFlags |= propagateChildFlags(node.dotDotDotToken) | propagateChildFlags(node.expression) | TransformFlags.ContainsJsx; @@ -6169,9 +6159,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createJsxNamespacedName(namespace: Identifier, name: Identifier) { const node = createBaseNode(SyntaxKind.JsxNamespacedName); node.data = { - namespace: namespace, - name: name, - } + namespace, + name, + }; node.transformFlags |= propagateChildFlags(node.namespace) | propagateChildFlags(node.name) | TransformFlags.ContainsJsx; @@ -6193,11 +6183,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createCaseClause(expression: Expression, statements: readonly Statement[]) { const node = createBaseNode(SyntaxKind.CaseClause); - const nodeData = node.data = { + const nodeData = node.data = { expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), statements: createNodeArray(statements), // fallthroughFlowNode: undefined, - } + }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildrenFlags(nodeData.statements); @@ -6232,9 +6222,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createHeritageClause(token: HeritageClause["token"], types: readonly ExpressionWithTypeArguments[]) { const node = createBaseNode(SyntaxKind.HeritageClause); node.data = { - token: token, + token, types: createNodeArray(types), - } + }; node.transformFlags |= propagateChildrenFlags(node.types); switch (token) { case SyntaxKind.ExtendsKeyword: @@ -6261,10 +6251,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseNode(SyntaxKind.CatchClause); const nodeData = node.data = { variableDeclaration: asVariableDeclaration(variableDeclaration), - block: block, + block, locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - } + }; node.transformFlags |= propagateChildFlags(nodeData.variableDeclaration) | propagateChildFlags(nodeData.block) | @@ -6292,11 +6282,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: asName(name), initializer: parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer), - modifiers: undefined ,// initialized by parser to report grammar errors + modifiers: undefined, // initialized by parser to report grammar errors questionToken: undefined, // initialized by parser to report grammar errors exclamationToken: undefined, // initialized by parser to report grammar errors localSymbol: undefined, - } + }; node.transformFlags |= propagateNameFlags(nodeData.name) | propagateChildFlags(nodeData.initializer); @@ -6335,10 +6325,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionToken: undefined, // initialized by parser to report grammar errors exclamationToken: undefined, // initialized by parser to report grammar errors localSymbol: undefined, - } + }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - node.transformFlags |= propagateIdentifierNameFlags(nodeData.name) | propagateChildFlags(nodeData.objectAssignmentInitializer) | TransformFlags.ContainsES2015; @@ -6367,7 +6356,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createSpreadAssignment(expression: Expression) { const node = createBaseDeclaration(SyntaxKind.SpreadAssignment); - node.data = { expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression) } + node.data = { expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression) }; node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsES2018 | TransformFlags.ContainsObjectRestOrSpread; @@ -6394,7 +6383,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: asName(name), initializer: initializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer), localSymbol: undefined, - } + }; node.transformFlags |= propagateChildFlags(node.name) | propagateChildFlags(node.initializer) | TransformFlags.ContainsTypeScript; @@ -6426,7 +6415,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { statements: createNodeArray(statements), - endOfFileToken: endOfFileToken, + endOfFileToken, text: "", fileName: "", path: "" as Path, @@ -6438,7 +6427,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode isDeclarationFile: false, hasNoDefaultLib: false, - locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) endFlowNode: undefined, @@ -6467,16 +6455,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode ambientModuleNames: undefined!, classifiableNames: undefined, impliedNodeFormat: undefined, - } - + }; + node.transformFlags |= propagateChildrenFlags(nodeData.statements) | propagateChildFlags(nodeData.endOfFileToken); return node; } function createRedirectedSourceFile(redirectInfo: RedirectInfo) { - const nodeData: any = Object.create((redirectInfo.redirectTarget as any as NodeImpl).data); - Object.defineProperties(nodeData, { + const node: SourceFile = Object.create(redirectInfo.redirectTarget); + Object.defineProperties(node, { id: { get(this: SourceFile) { return this.redirectInfo!.redirectTarget.id; @@ -6493,13 +6481,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode this.redirectInfo!.redirectTarget.symbol = value; }, }, - redirectInfo: { - value: redirectInfo, - }, }); - const sourceFile = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile); - (sourceFile as NodeImpl).data = nodeData; - return sourceFile as SourceFile; + (node as any).data = Object.create((redirectInfo.redirectTarget as any).data); + node.redirectInfo = redirectInfo; + return node; } function cloneRedirectedSourceFile(source: SourceFile) { @@ -6521,6 +6506,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // work, we should consider switching explicit property assignments instead of using `for..in`. const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as NodeData; node.flags |= source.flags & ~NodeFlags.Synthesized; + node.symbol = source.symbol; + const sourceData = (source as any).data; const nodeData = (node as any).data = {}; for (const p in sourceData) { @@ -6588,12 +6575,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createBundle(sourceFiles: readonly SourceFile[]) { const node = createBaseNode(SyntaxKind.Bundle); node.data = { - sourceFiles: sourceFiles, + sourceFiles, syntheticFileReferences: undefined, syntheticTypeReferences: undefined, syntheticLibReferences: undefined, hasNoDefaultLib: undefined, - } + }; return node; } @@ -6611,11 +6598,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createSyntheticExpression(type: Type, isSpread = false, tupleNameSource?: ParameterDeclaration | NamedTupleMember) { const node = createBaseNode(SyntaxKind.SyntheticExpression); - const nodeData = node.data = { - type: type, - isSpread: isSpread, - tupleNameSource: tupleNameSource, - } + node.data = { + type, + isSpread, + tupleNameSource, + }; return node; } @@ -6654,7 +6641,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createPartiallyEmittedExpression(expression: Expression, original?: Node) { const node = createBaseNode(SyntaxKind.PartiallyEmittedExpression); - const nodeData = node.data = { expression: expression } + const nodeData = node.data = { expression }; node.original = original; node.transformFlags |= propagateChildFlags(nodeData.expression) | TransformFlags.ContainsTypeScript; @@ -6684,7 +6671,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createCommaListExpression(elements: readonly Expression[]) { const node = createBaseNode(SyntaxKind.CommaListExpression); - node.data = { elements: createNodeArray(sameFlatMap(elements, flattenCommaElements)) } + node.data = { elements: createNodeArray(sameFlatMap(elements, flattenCommaElements)) }; node.transformFlags |= propagateChildrenFlags(node.elements); return node; } @@ -6700,9 +6687,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function createSyntheticReferenceExpression(expression: Expression, thisArg: Expression) { const node = createBaseNode(SyntaxKind.SyntheticReferenceExpression); node.data = { - expression: expression, - thisArg: thisArg, - } + expression, + thisArg, + }; node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.thisArg); return node; @@ -6782,18 +6769,23 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode return clonePrivateIdentifier(node) as T & PrivateIdentifier; } - const clone = baseFactory.createBaseNode(node.kind) as Mutable; + const clone = baseFactory.createBaseNode(node.kind) as Mutable; clone.flags |= node.flags & ~NodeFlags.Synthesized; - clone.transformFlags = node.transformFlags; + clone.jsDoc = (node as any).jsDoc; + clone.flowNode = (node as any).flowNode; + clone.symbol = (node as any).symbol; + setOriginal(clone, node); - const nodeData = (node as any).data ?? node; - const cloneData = (clone as any).data = {}; - for (const key in nodeData) { - if (hasProperty(cloneData, key) || !hasProperty(nodeData, key)) { - continue; + const nodeData = (node as any).data; + if (nodeData) { + const cloneData = (clone as any).data = {}; + for (const key in nodeData) { + if (hasProperty(cloneData, key) || !hasProperty(nodeData, key)) { + continue; + } + (clone as any)[key] = nodeData[key]; } - (clone as any)[key] = nodeData[key]; } return clone; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9cb8f153c9381..be22cabcaaf3d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -546,6 +546,7 @@ import { TokenFlags, tokenToString, toPath, + tracing, TransformFlags, TransientSymbol, TriviaSyntaxKind, @@ -8279,10 +8280,10 @@ function Symbol(this: Symbol, flags: SymbolFlags, name: __String) { class TypeDataImpl { } -export const allTypes: TypeImpl[] = []; +// export const allTypes: TypeImpl[] = []; /** @internal */ export class TypeImpl { - checker: TypeChecker; + checker!: TypeChecker; flags: TypeFlags; symbol: Symbol; _data: any = undefined; @@ -8290,11 +8291,13 @@ export class TypeImpl { objectFlags: number; constructor(checker: TypeChecker, flags: TypeFlags) { this.id = 0; - this.checker = checker; + if (Debug.isDebugging || tracing) { + this.checker = checker; + } this.flags = flags; this.symbol = undefined!; this.objectFlags = 0; - allTypes.push(this); + // allTypes.push(this); } get data() { @@ -9151,6 +9154,7 @@ export class NodeImpl { jsDoc: any; flowNode: any; symbol: any; + __symbolTestOutputCache?: any; // For tests only constructor(kind: SyntaxKind, pos: number, end: number) { this.pos = pos; this.end = end; @@ -9162,12 +9166,16 @@ export class NodeImpl { this.parent = undefined!; this.emitNode = undefined; - + this.original = undefined; this.escapedText = undefined; this.jsDoc = undefined; this.flowNode = undefined; this.symbol = undefined; + + if (Debug.isDebugging || tracing) { + this.__symbolTestOutputCache = undefined; + } } data: any = undefined; @@ -13928,11 +13936,11 @@ export function hasInferredType(node: Node): node is HasInferredType { } const objectArray = [{} as never]; -/** +/** * @internal * Ensures V8 creates a PACKED_ELEMENTS array and not a PACKED_SMI_ELEMENTS array - **/ + */ export function createEmptyObjectArray(): T[] { - const elements = objectArray.slice(0,0); + const elements = objectArray.slice(0, 0); return elements as T[]; -} \ No newline at end of file +} diff --git a/src/harness/harnessUtils.ts b/src/harness/harnessUtils.ts index 66de3bcec4b5a..e58ee6043f62d 100644 --- a/src/harness/harnessUtils.ts +++ b/src/harness/harnessUtils.ts @@ -207,6 +207,12 @@ export function sourceFileToJSON(file: ts.Node): string { o.modifierFlagsCache = n.modifierFlagsCache; } o.transformFlags = n.transformFlags; + if (n.kind === ts.SyntaxKind.Identifier) { + o.escapedText = n.escapedText; + } + if (n.jsDoc) { + o.jsDoc = n.jsDoc; + } } else { nodeData = n; diff --git a/src/harness/typeWriter.ts b/src/harness/typeWriter.ts index 4d1ca8e8a8185..e09f8bd56a272 100644 --- a/src/harness/typeWriter.ts +++ b/src/harness/typeWriter.ts @@ -314,8 +314,8 @@ export class TypeWriterWalker { } count++; symbolString += ", "; - if ((declaration as any).data.__symbolTestOutputCache) { - symbolString += (declaration as any).data.__symbolTestOutputCache; + if ((declaration as any).__symbolTestOutputCache) { + symbolString += (declaration as any).__symbolTestOutputCache; continue; } const declSourceFile = declaration.getSourceFile(); @@ -324,7 +324,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).data.__symbolTestOutputCache = declText; + (declaration as any).__symbolTestOutputCache = declText; } } symbolString += ")"; diff --git a/src/services/services.ts b/src/services/services.ts index fc8e54f2950a6..7de202a59f489 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -918,6 +918,10 @@ class SymbolObject implements Symbol { } class TypeObject extends TypeImpl implements Type { + constructor(checker: TypeChecker, flags: TypeFlags) { + super(checker, flags); + this.checker = checker; + } getFlags(): TypeFlags { return this.flags; } diff --git a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeErrors-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeErrors-file.ts.diff index c50da716b91b9..943b25dcb2fb8 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 @@ +@@ -8,44 +8,10 @@ "0": { "kind": "FunctionDeclaration", "pos": 0, @@ -9,14 +9,6 @@ - "flags": "Deprecated", "modifierFlagsCache": 0, "transformFlags": 4194304, - "name": { - "kind": "Identifier", -@@ -39,42 +38,9 @@ - "hasTrailingComma": false, - "transformFlags": 0 - }, - "multiLine": false -- }, - "jsDoc": [ - { - "kind": "JSDoc", @@ -49,12 +41,11 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "1": { - "kind": "ExpressionStatement", - "pos": 46, +- ], + "name": { + "kind": "Identifier", + "pos": 28, + "end": 41, @@ -230,6 +196,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], diff --git a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeInfo-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseForTypeInfo-file.ts.diff index f63d4526fd75c..cd158dbfbc1be 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 @@ +@@ -8,44 +8,10 @@ "0": { "kind": "FunctionDeclaration", "pos": 0, @@ -9,14 +9,6 @@ - "flags": "Deprecated", "modifierFlagsCache": 0, "transformFlags": 4194304, - "name": { - "kind": "Identifier", -@@ -39,42 +38,9 @@ - "hasTrailingComma": false, - "transformFlags": 0 - }, - "multiLine": false -- }, - "jsDoc": [ - { - "kind": "JSDoc", @@ -49,13 +41,12 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "1": { - "kind": "ExpressionStatement", - "pos": 46, -@@ -106,9 +72,8 @@ +- ], + "name": { + "kind": "Identifier", + "pos": 28, + "end": 41, +@@ -106,45 +72,10 @@ "2": { "kind": "FunctionDeclaration", "pos": 61, @@ -63,14 +54,6 @@ - "flags": "Deprecated", "modifierFlagsCache": 0, "transformFlags": 4194304, - "name": { - "kind": "Identifier", -@@ -137,43 +102,9 @@ - "hasTrailingComma": false, - "transformFlags": 0 - }, - "multiLine": false -- }, - "jsDoc": [ - { - "kind": "JSDoc", @@ -104,12 +87,11 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "3": { - "kind": "ExpressionStatement", - "pos": 135, +- ], + "name": { + "kind": "Identifier", + "pos": 116, + "end": 130, @@ -230,6 +161,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], diff --git a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseNone-file.js.diff b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseNone-file.js.diff index 567ff8973d13a..d123442d7230d 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 @@ +@@ -8,44 +8,10 @@ "0": { "kind": "FunctionDeclaration", "pos": 0, @@ -9,14 +9,6 @@ - "flags": "Deprecated", "modifierFlagsCache": 0, "transformFlags": 4194304, - "name": { - "kind": "Identifier", -@@ -39,42 +38,9 @@ - "hasTrailingComma": false, - "transformFlags": 0 - }, - "multiLine": false -- }, - "jsDoc": [ - { - "kind": "JSDoc", @@ -49,13 +41,12 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "1": { - "kind": "ExpressionStatement", - "pos": 46, -@@ -106,9 +72,8 @@ +- ], + "name": { + "kind": "Identifier", + "pos": 28, + "end": 41, +@@ -106,45 +72,10 @@ "2": { "kind": "FunctionDeclaration", "pos": 61, @@ -63,14 +54,6 @@ - "flags": "Deprecated", "modifierFlagsCache": 0, "transformFlags": 4194304, - "name": { - "kind": "Identifier", -@@ -137,43 +102,9 @@ - "hasTrailingComma": false, - "transformFlags": 0 - }, - "multiLine": false -- }, - "jsDoc": [ - { - "kind": "JSDoc", @@ -104,12 +87,11 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "3": { - "kind": "ExpressionStatement", - "pos": 135, +- ], + "name": { + "kind": "Identifier", + "pos": 116, + "end": 130, @@ -230,7 +161,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], diff --git a/tests/baselines/reference/skipJSDocParsing/deprecated-ParseNone-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/deprecated-ParseNone-file.ts.diff index 852412d8420f3..80ff7ac9429be 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 @@ +@@ -8,44 +8,10 @@ "0": { "kind": "FunctionDeclaration", "pos": 0, @@ -9,14 +9,6 @@ - "flags": "Deprecated", "modifierFlagsCache": 0, "transformFlags": 4194304, - "name": { - "kind": "Identifier", -@@ -39,42 +38,9 @@ - "hasTrailingComma": false, - "transformFlags": 0 - }, - "multiLine": false -- }, - "jsDoc": [ - { - "kind": "JSDoc", @@ -49,13 +41,12 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "1": { - "kind": "ExpressionStatement", - "pos": 46, -@@ -106,9 +72,8 @@ +- ], + "name": { + "kind": "Identifier", + "pos": 28, + "end": 41, +@@ -106,45 +72,10 @@ "2": { "kind": "FunctionDeclaration", "pos": 61, @@ -63,14 +54,6 @@ - "flags": "Deprecated", "modifierFlagsCache": 0, "transformFlags": 4194304, - "name": { - "kind": "Identifier", -@@ -137,43 +102,9 @@ - "hasTrailingComma": false, - "transformFlags": 0 - }, - "multiLine": false -- }, - "jsDoc": [ - { - "kind": "JSDoc", @@ -104,12 +87,11 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "3": { - "kind": "ExpressionStatement", - "pos": 135, +- ], + "name": { + "kind": "Identifier", + "pos": 116, + "end": 130, @@ -230,6 +161,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff index 0c2bff5a4677e..b527b2d016da9 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff @@ -1,12 +1,11 @@ =================================================================== --- default +++ ParseForTypeInfo -@@ -88,52 +88,9 @@ - "pos": 69, - "end": 69, - "hasTrailingComma": false, - "transformFlags": 0 -- }, +@@ -62,51 +62,8 @@ + "pos": 30, + "end": 70, + "modifierFlagsCache": 0, + "transformFlags": 1, - "jsDoc": [ - { - "kind": "JSDoc", @@ -49,12 +48,11 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "length": 2, - "pos": 0, - "end": 70, +- ], + "modifiers": { + "0": { + "kind": "ExportKeyword", + "pos": 30, @@ -214,6 +171,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff index 3a1028bb08254..a6e9f5f2ded40 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff @@ -1,12 +1,11 @@ =================================================================== --- default +++ ParseNone -@@ -88,52 +88,9 @@ - "pos": 69, - "end": 69, - "hasTrailingComma": false, - "transformFlags": 0 -- }, +@@ -62,51 +62,8 @@ + "pos": 30, + "end": 70, + "modifierFlagsCache": 0, + "transformFlags": 1, - "jsDoc": [ - { - "kind": "JSDoc", @@ -49,12 +48,11 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "length": 2, - "pos": 0, - "end": 70, +- ], + "modifiers": { + "0": { + "kind": "ExportKeyword", + "pos": 30, @@ -214,7 +171,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff index 41135dc2495ba..38b49375f3292 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff @@ -1,12 +1,11 @@ =================================================================== --- default +++ ParseNone -@@ -88,52 +88,9 @@ - "pos": 69, - "end": 69, - "hasTrailingComma": false, - "transformFlags": 0 -- }, +@@ -62,51 +62,8 @@ + "pos": 30, + "end": 70, + "modifierFlagsCache": 0, + "transformFlags": 1, - "jsDoc": [ - { - "kind": "JSDoc", @@ -49,12 +48,11 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "length": 2, - "pos": 0, - "end": 70, +- ], + "modifiers": { + "0": { + "kind": "ExportKeyword", + "pos": 30, @@ -214,6 +171,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], diff --git a/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.ts.diff index 277a3fbe56a55..710ad9ae82741 100644 --- a/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/see-ParseForTypeInfo-file.ts.diff @@ -1,12 +1,11 @@ =================================================================== --- default +++ ParseForTypeInfo -@@ -38,235 +38,9 @@ - "end": 108, - "hasTrailingComma": false, - "transformFlags": 0 - } -- }, +@@ -10,234 +10,8 @@ + "pos": 0, + "end": 109, + "modifierFlagsCache": 0, + "transformFlags": 4457472, - "jsDoc": [ - { - "kind": "JSDoc", @@ -232,12 +231,11 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "length": 1, - "pos": 0, - "end": 109, +- ], + "declarationList": { + "kind": "VariableDeclarationList", + "pos": 0, + "end": 108, @@ -295,6 +69,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], diff --git a/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.js.diff b/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.js.diff index cae5537d772c6..e15e60dfa305d 100644 --- a/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.js.diff @@ -1,12 +1,11 @@ =================================================================== --- default +++ ParseNone -@@ -38,235 +38,9 @@ - "end": 108, - "hasTrailingComma": false, - "transformFlags": 0 - } -- }, +@@ -10,234 +10,8 @@ + "pos": 0, + "end": 109, + "modifierFlagsCache": 0, + "transformFlags": 4457472, - "jsDoc": [ - { - "kind": "JSDoc", @@ -232,12 +231,11 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "length": 1, - "pos": 0, - "end": 109, +- ], + "declarationList": { + "kind": "VariableDeclarationList", + "pos": 0, + "end": 108, @@ -295,7 +69,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], diff --git a/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.ts.diff index d89f8511e680a..0c60572516f2d 100644 --- a/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/see-ParseNone-file.ts.diff @@ -1,12 +1,11 @@ =================================================================== --- default +++ ParseNone -@@ -38,235 +38,9 @@ - "end": 108, - "hasTrailingComma": false, - "transformFlags": 0 - } -- }, +@@ -10,234 +10,8 @@ + "pos": 0, + "end": 109, + "modifierFlagsCache": 0, + "transformFlags": 4457472, - "jsDoc": [ - { - "kind": "JSDoc", @@ -232,12 +231,11 @@ - "transformFlags": 0 - } - } -- ] -+ } - }, - "length": 1, - "pos": 0, - "end": 109, +- ], + "declarationList": { + "kind": "VariableDeclarationList", + "pos": 0, + "end": 108, @@ -295,6 +69,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], From 51d635c26667ee34577bc52c1580cbe9b83a265f Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Fri, 28 Jun 2024 14:43:31 +0100 Subject: [PATCH 08/13] Make node slightly smaller by removing original and emit node and moving them to data --- src/compiler/factory/nodeFactory.ts | 58 ++++++++++++++++++++++------- src/compiler/utilities.ts | 36 ++++++++++++++---- 2 files changed, 73 insertions(+), 21 deletions(-) diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index adb290952d2cc..2aaec104d5f41 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -478,7 +478,7 @@ type NodeData = & Readonly> & Mutable>> & { - data: Partial | Exclude>>> | undefined; + data: Partial | Exclude>>> | undefined; }; /** @internal */ export function addNodeFactoryPatcher(fn: (factory: NodeFactory) => void) { @@ -1910,6 +1910,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode endFlowNode: undefined, returnFlowNode: undefined, localSymbol: undefined, + flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -2091,6 +2092,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, localSymbol: undefined, // questionToken: undefined + flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -2160,6 +2162,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, localSymbol: undefined, // questionToken: undefined, + flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -2938,7 +2941,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (nodeData.dotDotDotToken ? TransformFlags.ContainsRestOrSpread : TransformFlags.None) | TransformFlags.ContainsES2015; - // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3007,6 +3010,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionDotToken, name, localSymbol: undefined, + flowNode: undefined, }; node.transformFlags = propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.questionDotToken) | @@ -3083,7 +3087,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode propagateChildFlags(nodeData.argumentExpression); // // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3339,7 +3343,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) const isAsync = modifiersToFlags(nodeData.modifiers) & ModifierFlags.Async; const isGenerator = !!nodeData.asteriskToken; @@ -3412,6 +3416,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode localSymbol: undefined, // name: undefined, // questionToken: undefined + flowNode: undefined, }; // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -3974,6 +3979,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { keywordToken, name, + flowNode: undefined, }; node.transformFlags |= propagateChildFlags(nodeData.name); switch (keywordToken) { @@ -4063,6 +4069,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { modifiers: asNodeArray(modifiers), declarationList: isArray(declarationList) ? createVariableDeclarationList(declarationList) : declarationList, + flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -4095,7 +4102,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createExpressionStatement(expression: Expression): ExpressionStatement { const node = createBaseNode(SyntaxKind.ExpressionStatement); - const nodeData = node.data = { expression: parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression) }; + const nodeData = node.data = { + expression: parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression), + flowNode: undefined, + }; node.transformFlags |= propagateChildFlags(nodeData.expression); // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -4123,7 +4133,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode propagateChildFlags(nodeData.elseStatement); // // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4142,6 +4152,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { statement: asEmbeddedStatement(statement), expression, + flowNode: undefined, }; node.transformFlags |= propagateChildFlags(nodeData.statement) | propagateChildFlags(nodeData.expression); @@ -4165,6 +4176,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { expression, statement: asEmbeddedStatement(statement), + flowNode: undefined, }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.statement); @@ -4192,6 +4204,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode statement: asEmbeddedStatement(statement), locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) + flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -4223,6 +4236,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode statement: asEmbeddedStatement(statement), locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) + flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -4254,6 +4268,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) + flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -4281,12 +4296,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createContinueStatement(label?: string | Identifier): ContinueStatement { const node = createBaseNode(SyntaxKind.ContinueStatement); - const nodeData = node.data = { label: asName(label) }; + const nodeData = node.data = { label: asName(label), + flowNode: undefined, + }; node.transformFlags |= propagateChildFlags(nodeData.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4300,7 +4317,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBreakStatement(label?: string | Identifier): BreakStatement { const node = createBaseNode(SyntaxKind.BreakStatement); - const nodeData = node.data = { label: asName(label) }; + const nodeData = node.data = { + label: asName(label), + flowNode: undefined, + }; node.transformFlags |= propagateChildFlags(nodeData.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; @@ -4319,14 +4339,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createReturnStatement(expression?: Expression): ReturnStatement { const node = createBaseNode(SyntaxKind.ReturnStatement); - const nodeData = node.data = { expression }; + const nodeData = node.data = { + expression, + flowNode: undefined, + }; // return in an ES2018 async generator must be awaited node.transformFlags |= propagateChildFlags(nodeData.expression) | TransformFlags.ContainsES2018 | TransformFlags.ContainsHoistedDeclarationOrCompletion; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4343,6 +4366,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { expression, statement: asEmbeddedStatement(statement), + flowNode: undefined, }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.statement); @@ -4367,6 +4391,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode possiblyExhaustive: false, // initialized by binder expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), caseBlock, + flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -4390,6 +4415,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { label: asName(label), statement: asEmbeddedStatement(statement), + flowNode: undefined, }; node.transformFlags |= propagateChildFlags(nodeData.label) | propagateChildFlags(nodeData.statement); @@ -4410,7 +4436,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createThrowStatement(expression: Expression) { const node = createBaseNode(SyntaxKind.ThrowStatement); - const nodeData = node.data = { expression }; + const nodeData = node.data = { + expression, + flowNode: undefined, + }; node.transformFlags |= propagateChildFlags(nodeData.expression); // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -4432,6 +4461,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode tryBlock, catchClause, finallyBlock, + flowNode: undefined, }; node.transformFlags |= propagateChildFlags(nodeData.tryBlock) | propagateChildFlags(nodeData.catchClause) | @@ -6776,10 +6806,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode clone.flowNode = (node as any).flowNode; clone.symbol = (node as any).symbol; - setOriginal(clone, node); const nodeData = (node as any).data; + const cloneData = (clone as any).data = {}; if (nodeData) { - const cloneData = (clone as any).data = {}; for (const key in nodeData) { if (hasProperty(cloneData, key) || !hasProperty(nodeData, key)) { continue; @@ -6787,6 +6816,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (clone as any)[key] = nodeData[key]; } } + setOriginal(clone, node); return clone; } // compound nodes diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index be22cabcaaf3d..fb784ad038992 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -9147,9 +9147,9 @@ export class NodeImpl { flags: NodeFlags; transformFlags: TransformFlags; parent: Node; - emitNode: EmitNode | undefined; + // emitNode: EmitNode | undefined; modifierFlagsCache: ModifierFlags; - original: undefined; + // original: undefined; escapedText: undefined; jsDoc: any; flowNode: any; @@ -9165,19 +9165,41 @@ export class NodeImpl { this.modifierFlagsCache = ModifierFlags.None; this.parent = undefined!; - this.emitNode = undefined; + // this.emitNode = undefined; - this.original = undefined; + // this.original = undefined; this.escapedText = undefined; this.jsDoc = undefined; this.flowNode = undefined; this.symbol = undefined; - if (Debug.isDebugging || tracing) { - this.__symbolTestOutputCache = undefined; - } + // if (Debug.isDebugging || tracing) { + // this.__symbolTestOutputCache = undefined; + // } } data: any = undefined; + + get emitNode() { + return this.data?.emitNode; + } + set emitNode(value: any) { + if(!this.data) { + this.data = { emitNode: value}; + } else { + this.data.emitNode = value; + } + } + + get original() { + return this.data?.original; + } + set original(value: any) { + if(!this.data) { + this.data = { original: value}; + } else { + this.data.original = value; + } + } get sourceText() { return this.data?.sourceText; From 8bb31a0a48f272d9058407f6c5a5af4f93bb6698 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Fri, 28 Jun 2024 14:57:27 +0100 Subject: [PATCH 09/13] Fix leftover debug code. --- src/compiler/factory/nodeFactory.ts | 54 +++++++---------------------- src/compiler/utilities.ts | 18 +++++----- 2 files changed, 22 insertions(+), 50 deletions(-) diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 2aaec104d5f41..0de5796a35cc3 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -478,7 +478,7 @@ type NodeData = & Readonly> & Mutable>> & { - data: Partial | Exclude>>> | undefined; + data: Partial | Exclude>>> | undefined; }; /** @internal */ export function addNodeFactoryPatcher(fn: (factory: NodeFactory) => void) { @@ -1910,7 +1910,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode endFlowNode: undefined, returnFlowNode: undefined, localSymbol: undefined, - flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -2092,7 +2091,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, localSymbol: undefined, // questionToken: undefined - flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -2162,7 +2160,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, localSymbol: undefined, // questionToken: undefined, - flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -2941,7 +2938,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (nodeData.dotDotDotToken ? TransformFlags.ContainsRestOrSpread : TransformFlags.None) | TransformFlags.ContainsES2015; - // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3010,7 +3007,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionDotToken, name, localSymbol: undefined, - flowNode: undefined, }; node.transformFlags = propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.questionDotToken) | @@ -3087,7 +3083,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode propagateChildFlags(nodeData.argumentExpression); // // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3343,7 +3339,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) const isAsync = modifiersToFlags(nodeData.modifiers) & ModifierFlags.Async; const isGenerator = !!nodeData.asteriskToken; @@ -3416,7 +3412,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode localSymbol: undefined, // name: undefined, // questionToken: undefined - flowNode: undefined, }; // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -3979,7 +3974,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { keywordToken, name, - flowNode: undefined, }; node.transformFlags |= propagateChildFlags(nodeData.name); switch (keywordToken) { @@ -4069,7 +4063,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { modifiers: asNodeArray(modifiers), declarationList: isArray(declarationList) ? createVariableDeclarationList(declarationList) : declarationList, - flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -4102,10 +4095,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createExpressionStatement(expression: Expression): ExpressionStatement { const node = createBaseNode(SyntaxKind.ExpressionStatement); - const nodeData = node.data = { - expression: parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression), - flowNode: undefined, - }; + const nodeData = node.data = { expression: parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression) }; node.transformFlags |= propagateChildFlags(nodeData.expression); // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -4133,7 +4123,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode propagateChildFlags(nodeData.elseStatement); // // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4152,7 +4142,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { statement: asEmbeddedStatement(statement), expression, - flowNode: undefined, }; node.transformFlags |= propagateChildFlags(nodeData.statement) | propagateChildFlags(nodeData.expression); @@ -4176,7 +4165,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { expression, statement: asEmbeddedStatement(statement), - flowNode: undefined, }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.statement); @@ -4204,7 +4192,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode statement: asEmbeddedStatement(statement), locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -4236,7 +4223,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode statement: asEmbeddedStatement(statement), locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -4268,7 +4254,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) - flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -4296,14 +4281,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createContinueStatement(label?: string | Identifier): ContinueStatement { const node = createBaseNode(SyntaxKind.ContinueStatement); - const nodeData = node.data = { label: asName(label), - flowNode: undefined, - }; + const nodeData = node.data = { label: asName(label) }; node.transformFlags |= propagateChildFlags(nodeData.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4317,10 +4300,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBreakStatement(label?: string | Identifier): BreakStatement { const node = createBaseNode(SyntaxKind.BreakStatement); - const nodeData = node.data = { - label: asName(label), - flowNode: undefined, - }; + const nodeData = node.data = { label: asName(label) }; node.transformFlags |= propagateChildFlags(nodeData.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; @@ -4339,17 +4319,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createReturnStatement(expression?: Expression): ReturnStatement { const node = createBaseNode(SyntaxKind.ReturnStatement); - const nodeData = node.data = { - expression, - flowNode: undefined, - }; + const nodeData = node.data = { expression }; // return in an ES2018 async generator must be awaited node.transformFlags |= propagateChildFlags(nodeData.expression) | TransformFlags.ContainsES2018 | TransformFlags.ContainsHoistedDeclarationOrCompletion; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) - nodeData.flowNode = undefined; // initialized by binder (FlowContainer) + // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4366,7 +4343,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { expression, statement: asEmbeddedStatement(statement), - flowNode: undefined, }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.statement); @@ -4391,7 +4367,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode possiblyExhaustive: false, // initialized by binder expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), caseBlock, - flowNode: undefined, }; // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) @@ -4415,7 +4390,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { label: asName(label), statement: asEmbeddedStatement(statement), - flowNode: undefined, }; node.transformFlags |= propagateChildFlags(nodeData.label) | propagateChildFlags(nodeData.statement); @@ -4436,10 +4410,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createThrowStatement(expression: Expression) { const node = createBaseNode(SyntaxKind.ThrowStatement); - const nodeData = node.data = { - expression, - flowNode: undefined, - }; + const nodeData = node.data = { expression }; node.transformFlags |= propagateChildFlags(nodeData.expression); // node.jsDoc= undefined; // initialized by parser (JsDocContainer) @@ -4461,7 +4432,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode tryBlock, catchClause, finallyBlock, - flowNode: undefined, }; node.transformFlags |= propagateChildFlags(nodeData.tryBlock) | propagateChildFlags(nodeData.catchClause) | diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index fb784ad038992..d276320c01590 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -9178,14 +9178,15 @@ export class NodeImpl { // } } data: any = undefined; - + get emitNode() { return this.data?.emitNode; } - set emitNode(value: any) { - if(!this.data) { - this.data = { emitNode: value}; - } else { + set emitNode(value: EmitNode) { + if (!this.data) { + this.data = { emitNode: value }; + } + else { this.data.emitNode = value; } } @@ -9194,9 +9195,10 @@ export class NodeImpl { return this.data?.original; } set original(value: any) { - if(!this.data) { - this.data = { original: value}; - } else { + if (!this.data) { + this.data = { original: value }; + } + else { this.data.original = value; } } From da811f477d6869a2322382ddb5f41deaf1307eca Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Fri, 28 Jun 2024 17:28:41 +0100 Subject: [PATCH 10/13] Fix merge issue. --- src/compiler/factory/nodeFactory.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index c1514dd008303..53857f36a47fd 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -474,18 +474,13 @@ export const enum NodeFactoryFlags { } const nodeFactoryPatchers: ((factory: NodeFactory) => void)[] = []; -<<<<<<< experiment-monomorphic-node type NodeData = & Readonly> & Mutable>> & { data: Partial | Exclude>>> | undefined; }; -/** @internal */ -======= - /** @internal @knipignore */ ->>>>>>> main export function addNodeFactoryPatcher(fn: (factory: NodeFactory) => void) { nodeFactoryPatchers.push(fn); } From 2766a8090fcf2bfd3bc9d4f4047637e695165ed1 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Fri, 28 Jun 2024 19:03:08 +0100 Subject: [PATCH 11/13] Fix tests --- src/compiler/factory/nodeFactory.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 53857f36a47fd..6432c0e48c9f2 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -6777,7 +6777,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode clone.symbol = (node as any).symbol; const nodeData = (node as any).data; - const cloneData = (clone as any).data = {}; + const cloneData: any = (clone as any).data = {}; if (nodeData) { for (const key in nodeData) { if (hasProperty(cloneData, key) || !hasProperty(nodeData, key)) { @@ -6785,6 +6785,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } (clone as any)[key] = nodeData[key]; } + if(cloneData.emitNode) { + cloneData.emitNode = undefined; + } } setOriginal(clone, node); return clone; From 76074de0e0251ef3b096f311b9d6865ea3a0915e Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Mon, 1 Jul 2024 11:32:03 +0100 Subject: [PATCH 12/13] Tweaking shape of Node to reduce memory consumption. --- src/compiler/factory/nodeFactory.ts | 210 +++++++++++----------- src/compiler/utilities.ts | 260 +++++++++++++++------------- 2 files changed, 247 insertions(+), 223 deletions(-) diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 6432c0e48c9f2..e47c549072008 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -478,7 +478,7 @@ type NodeData = & Readonly> & Mutable>> & { - data: Partial | Exclude>>> | undefined; + data: Partial | Exclude>>> | undefined; }; /** @internal @knipignore */ export function addNodeFactoryPatcher(fn: (factory: NodeFactory) => void) { @@ -1239,7 +1239,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode hasExtendedUnicodeEscape: false, isUnterminated: false, text, - // localSymbol: undefined! + localSymbol: undefined, }; if (numericLiteralFlags & TokenFlags.BinaryOrOctalSpecifier) node.transformFlags |= TransformFlags.ContainsES2015; return node; @@ -1266,7 +1266,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // isUnterminated: false, text, // textSourceNode: undefined!, - // localSymbol: undefined!, + localSymbol: undefined, }; if (hasExtendedUnicodeEscape) node.transformFlags |= TransformFlags.ContainsES2015; return node; @@ -1641,9 +1641,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode default: defaultType, expression: undefined, // initialized by parser to report grammar errors localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -1674,7 +1674,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionToken, type, initializer: asInitializer(initializer), - // localSymbol: undefined + localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; if (isThisIdentifier(nodeData.name)) { @@ -1691,7 +1692,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (modifiersToFlags(nodeData.modifiers) & ModifierFlags.ParameterPropertyModifier ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None); } - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -1754,10 +1754,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionToken, initializer: undefined, // initialized by parser to report grammar errors localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -1801,6 +1801,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode exclamationToken: questionOrExclamationToken && isExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : undefined, type, initializer: asInitializer(initializer), + jsDoc: undefined, // initialized by parser (JsDocContainer) }; const isAmbient = node.flags & NodeFlags.Ambient || modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient; @@ -1812,7 +1813,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (isComputedPropertyName(nodeData.name) || modifiersToFlags(nodeData.modifiers) & ModifierFlags.Static && nodeData.initializer ? TransformFlags.ContainsTypeScriptClassSyntax : TransformFlags.None) | TransformFlags.ContainsClassFields; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -1856,9 +1856,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode nextContainer: undefined, // initialized by binder (LocalsContainer) typeArguments: undefined, // used in quick info localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -1910,8 +1910,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode endFlowNode: undefined, returnFlowNode: undefined, localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) if (!nodeData.body) { node.transformFlags = TransformFlags.ContainsTypeScript; @@ -1985,10 +1985,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode endFlowNode: undefined, returnFlowNode: undefined, name: undefined, - // localSymbol: undefined + localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = propagateChildFlags(body) | TransformFlags.ContainsClassFields; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2033,8 +2033,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, // name: undefined, // questionToken: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) node.transformFlags = propagateChildrenFlags(nodeData.modifiers) | propagateChildrenFlags(nodeData.parameters) | @@ -2091,8 +2091,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, localSymbol: undefined, // questionToken: undefined + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) if (!nodeData.body) { @@ -2160,9 +2160,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, localSymbol: undefined, // questionToken: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) if (!nodeData.body) { node.transformFlags = TransformFlags.ContainsTypeScript; @@ -2221,9 +2221,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode localSymbol: undefined, // name: undefined, // questionToken: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2258,9 +2258,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode localSymbol: undefined, // name: undefined, // questionToken: undefined + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2297,9 +2297,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // name: undefined, // questionToken: undefined, // typeParameters: undefined + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2403,10 +2403,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeArguments: undefined, // used in quick info localSymbol: undefined, // name: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2457,9 +2457,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeArguments: undefined, // used in quick info localSymbol: undefined, // name: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2584,10 +2584,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionToken, type, localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -2986,10 +2986,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode properties: createNodeArray(properties), multiLine, localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildrenFlags(node.properties); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -3007,6 +3007,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionDotToken, name, localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.questionDotToken) | @@ -3014,7 +3015,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode propagateIdentifierNameFlags(nodeData.name) : propagateChildFlags(nodeData.name) | TransformFlags.ContainsPrivateIdentifierInExpression); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3077,12 +3077,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionDotToken, argumentExpression, localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.questionDotToken) | propagateChildFlags(nodeData.argumentExpression); - // // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -3294,10 +3294,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createParenthesizedExpression(expression: Expression) { const node = createBaseNode(SyntaxKind.ParenthesizedExpression); - node.data = { expression }; + node.data = { + expression, + jsDoc: undefined, // initialized by parser (JsDocContainer) + }; node.transformFlags = propagateChildFlags(node.expression); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -3336,9 +3338,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, localSymbol: undefined, // questionToken: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) const isAsync = modifiersToFlags(nodeData.modifiers) & ModifierFlags.Async; @@ -3412,9 +3414,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode localSymbol: undefined, // name: undefined, // questionToken: undefined + jsDoc: undefined, // initialized by parser (JsDocContainer) }; // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) const isAsync = modifiersToFlags(nodeData.modifiers) & ModifierFlags.Async; @@ -3579,6 +3581,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode operatorToken, right: parenthesizerRules().parenthesizeRightSideOfBinary(operatorKind, node.left, right), localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildFlags(node.left) | propagateChildFlags(node.operatorToken) | @@ -3609,7 +3612,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.transformFlags |= TransformFlags.ContainsPrivateIdentifierInExpression; } - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -3831,7 +3833,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode typeParameters: asNodeArray(typeParameters), heritageClauses: asNodeArray(heritageClauses), members: createNodeArray(members), - // localSymbol: undefined. + localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateNameFlags(nodeData.name) | @@ -3841,7 +3844,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode (nodeData.typeParameters ? TransformFlags.ContainsTypeScript : TransformFlags.None) | TransformFlags.ContainsES2015; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4043,9 +4045,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) node.transformFlags |= propagateChildrenFlags(nodeData.statements); return node; } @@ -4063,8 +4065,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { modifiers: asNodeArray(modifiers), declarationList: isArray(declarationList) ? createVariableDeclarationList(declarationList) : declarationList, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | @@ -4088,17 +4090,19 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createEmptyStatement() { const node = createBaseNode(SyntaxKind.EmptyStatement); - // node.data.jsDoc = undefined; // initialized by parser (JsDocContainer) + node.data = { jsDoc: undefined }; // initialized by parser (JsDocContainer) return node; } // @api function createExpressionStatement(expression: Expression): ExpressionStatement { const node = createBaseNode(SyntaxKind.ExpressionStatement); - const nodeData = node.data = { expression: parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression) }; + const nodeData = node.data = { + expression: parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression), + jsDoc: undefined, // initialized by parser (JsDocContainer) + }; node.transformFlags |= propagateChildFlags(nodeData.expression); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4117,12 +4121,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode expression, thenStatement: asEmbeddedStatement(thenStatement), elseStatement: asEmbeddedStatement(elseStatement), + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.thenStatement) | propagateChildFlags(nodeData.elseStatement); - // // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4142,11 +4146,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { statement: asEmbeddedStatement(statement), expression, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildFlags(nodeData.statement) | propagateChildFlags(nodeData.expression); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4165,11 +4169,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { expression, statement: asEmbeddedStatement(statement), + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.statement); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4192,8 +4196,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode statement: asEmbeddedStatement(statement), locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) node.transformFlags |= propagateChildFlags(nodeData.initializer) | @@ -4223,9 +4227,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode statement: asEmbeddedStatement(statement), locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) node.transformFlags |= propagateChildFlags(nodeData.initializer) | propagateChildFlags(nodeData.expression) | @@ -4254,8 +4258,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) node.transformFlags |= propagateChildFlags(nodeData.awaitModifier) | @@ -4281,11 +4285,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createContinueStatement(label?: string | Identifier): ContinueStatement { const node = createBaseNode(SyntaxKind.ContinueStatement); - const nodeData = node.data = { label: asName(label) }; + const nodeData = node.data = { + label: asName(label), + jsDoc: undefined, // initialized by parser (JsDocContainer) + }; node.transformFlags |= propagateChildFlags(nodeData.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4300,11 +4306,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createBreakStatement(label?: string | Identifier): BreakStatement { const node = createBaseNode(SyntaxKind.BreakStatement); - const nodeData = node.data = { label: asName(label) }; + const nodeData = node.data = { + label: asName(label), + jsDoc: undefined, // initialized by parser (JsDocContainer) + }; node.transformFlags |= propagateChildFlags(nodeData.label) | TransformFlags.ContainsHoistedDeclarationOrCompletion; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4319,13 +4327,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createReturnStatement(expression?: Expression): ReturnStatement { const node = createBaseNode(SyntaxKind.ReturnStatement); - const nodeData = node.data = { expression }; + const nodeData = node.data = { + expression, + jsDoc: undefined, // initialized by parser (JsDocContainer) + }; // return in an ES2018 async generator must be awaited node.transformFlags |= propagateChildFlags(nodeData.expression) | TransformFlags.ContainsES2018 | TransformFlags.ContainsHoistedDeclarationOrCompletion; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4343,11 +4353,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { expression, statement: asEmbeddedStatement(statement), + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.statement); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4367,8 +4377,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode possiblyExhaustive: false, // initialized by binder expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), caseBlock, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildFlags(nodeData.caseBlock); @@ -4390,11 +4400,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const nodeData = node.data = { label: asName(label), statement: asEmbeddedStatement(statement), + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildFlags(nodeData.label) | propagateChildFlags(nodeData.statement); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4410,10 +4420,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createThrowStatement(expression: Expression) { const node = createBaseNode(SyntaxKind.ThrowStatement); - const nodeData = node.data = { expression }; + const nodeData = node.data = { + expression, + jsDoc: undefined, // initialized by parser (JsDocContainer) + }; node.transformFlags |= propagateChildFlags(nodeData.expression); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4432,12 +4444,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode tryBlock, catchClause, finallyBlock, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildFlags(nodeData.tryBlock) | propagateChildFlags(nodeData.catchClause) | propagateChildFlags(nodeData.finallyBlock); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) // nodeData.flowNode = undefined; // initialized by binder (FlowContainer) return node; } @@ -4466,12 +4478,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode type, initializer: asInitializer(initializer), localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateNameFlags(nodeData.name) | propagateChildFlags(nodeData.initializer) | (nodeData.exclamationToken ?? nodeData.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4537,8 +4549,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // exclamationToken: undefined, localSymbol: undefined, // questionToken: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) if (!nodeData.body || modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; @@ -4614,6 +4626,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode heritageClauses: asNodeArray(heritageClauses), members: createNodeArray(members), localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; if (modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { @@ -4632,7 +4645,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } } - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4670,10 +4682,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode heritageClauses: asNodeArray(heritageClauses), members: createNodeArray(members), localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4712,9 +4724,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags = TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4746,6 +4758,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: asName(name), members: createNodeArray(members), localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateChildFlags(nodeData.name) | @@ -4753,7 +4766,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode TransformFlags.ContainsTypeScript; node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Enum declarations cannot contain `await` - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4787,8 +4799,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) if (modifiersToFlags(nodeData.modifiers) & ModifierFlags.Ambient) { node.transformFlags = TransformFlags.ContainsTypeScript; } @@ -4820,10 +4832,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createModuleBlock(statements: readonly Statement[]) { const node = createBaseNode(SyntaxKind.ModuleBlock); - const nodeData = node.data = { statements: createNodeArray(statements) }; + const nodeData = node.data = { + statements: createNodeArray(statements), + jsDoc: undefined, // initialized by parser (JsDocContainer) + }; node.transformFlags |= propagateChildrenFlags(nodeData.statements); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4863,11 +4877,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: asName(name), modifiers: undefined, // initialized by parser to report grammar errors localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateIdentifierNameFlags(nodeData.name) | TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4900,6 +4914,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode isTypeOnly, moduleReference, localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateIdentifierNameFlags(nodeData.name) | @@ -4911,7 +4926,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Import= declaration is always parsed in an Await context - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -4945,12 +4959,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode moduleSpecifier, attributes, assertClause: attributes, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildFlags(nodeData.importClause) | propagateChildFlags(nodeData.moduleSpecifier); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -5100,7 +5114,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseDeclaration(SyntaxKind.NamespaceImport); node.data = { name, - // localSymbol: undefined + localSymbol: undefined, }; node.transformFlags |= propagateChildFlags(node.name); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context @@ -5119,7 +5133,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const node = createBaseDeclaration(SyntaxKind.NamespaceExport); node.data = { name, - // localSymbol: undefined + localSymbol: undefined, }; node.transformFlags |= propagateChildFlags(node.name) | TransformFlags.ContainsES2020; @@ -5189,11 +5203,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode : parenthesizerRules().parenthesizeExpressionOfExportDefault(expression), localSymbol: undefined, // name: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateChildFlags(nodeData.expression); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -5227,13 +5241,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode assertClause: attributes, localSymbol: undefined, // name: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildrenFlags(nodeData.modifiers) | propagateChildFlags(nodeData.exportClause) | propagateChildFlags(nodeData.moduleSpecifier); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -5289,12 +5303,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode propertyName: asName(propertyName), name: asName(name), localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildFlags(nodeData.propertyName) | propagateChildFlags(nodeData.name); node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -5310,8 +5324,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createMissingDeclaration(): MissingDeclaration { const node = createBaseDeclaration(SyntaxKind.MissingDeclaration); - node.data = {}; // Bag for others to add what they need, we don't know what that will be - // node.data.jsDoc = undefined; // initialized by parser (JsDocContainer) + node.data = { + jsDoc: undefined, // initialized by parser (JsDocContainer) + }; return node; } @@ -5399,8 +5414,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode localSymbol: undefined, // name: undefined, // typeParameters: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) node.transformFlags = propagateChildrenFlags(nodeData.parameters) | (nodeData.type ? TransformFlags.ContainsTypeScript : TransformFlags.None); @@ -5457,8 +5472,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode locals: undefined, // initialized by binder (LocalsContainer) nextContainer: undefined, // initialized by binder (LocalsContainer) + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -6187,11 +6202,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), statements: createNodeArray(statements), // fallthroughFlowNode: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildFlags(nodeData.expression) | propagateChildrenFlags(nodeData.statements); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -6286,11 +6301,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionToken: undefined, // initialized by parser to report grammar errors exclamationToken: undefined, // initialized by parser to report grammar errors localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateNameFlags(nodeData.name) | propagateChildFlags(nodeData.initializer); - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -6325,8 +6340,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode questionToken: undefined, // initialized by parser to report grammar errors exclamationToken: undefined, // initialized by parser to report grammar errors localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) node.transformFlags |= propagateIdentifierNameFlags(nodeData.name) | propagateChildFlags(nodeData.objectAssignmentInitializer) | @@ -6356,12 +6371,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode // @api function createSpreadAssignment(expression: Expression) { const node = createBaseDeclaration(SyntaxKind.SpreadAssignment); - node.data = { expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression) }; + node.data = { + expression: parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression), + jsDoc: undefined, // initialized by parser (JsDocContainer) + }; node.transformFlags |= propagateChildFlags(node.expression) | TransformFlags.ContainsES2018 | TransformFlags.ContainsObjectRestOrSpread; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -6383,12 +6400,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode name: asName(name), initializer: initializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer), localSymbol: undefined, + jsDoc: undefined, // initialized by parser (JsDocContainer) }; node.transformFlags |= propagateChildFlags(node.name) | propagateChildFlags(node.initializer) | TransformFlags.ContainsTypeScript; - // node.jsDoc= undefined; // initialized by parser (JsDocContainer) return node; } @@ -6509,16 +6526,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode node.symbol = source.symbol; const sourceData = (source as any).data; - const nodeData = (node as any).data = {}; + const nodeData: any = (node as any).data = {}; for (const p in sourceData) { - if (hasProperty(nodeData, p) || !hasProperty(sourceData, p)) { - continue; - } - if (p === "emitNode") { - node.emitNode = undefined; - continue; - } - (node as any)[p] = sourceData[p]; + if (p === "emitNode") continue; + const value = sourceData[p]; + if (value === undefined) continue; + nodeData[p] = sourceData[p]; } return node; } @@ -6715,7 +6728,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode function cloneIdentifier(node: Identifier): Identifier { const clone = createBaseIdentifier(node.escapedText); clone.flags |= node.flags & ~NodeFlags.Synthesized; - clone.jsDoc = node.jsDoc; + if (node.jsDoc) { + clone.jsDoc = node.jsDoc; + } clone.flowNode = node.flowNode; clone.symbol = node.symbol; clone.transformFlags = node.transformFlags; @@ -6772,7 +6787,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const clone = baseFactory.createBaseNode(node.kind) as Mutable; clone.flags |= node.flags & ~NodeFlags.Synthesized; - clone.jsDoc = (node as any).jsDoc; + // clone.jsDoc = (node as any).jsDoc; clone.flowNode = (node as any).flowNode; clone.symbol = (node as any).symbol; @@ -6780,13 +6795,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode const cloneData: any = (clone as any).data = {}; if (nodeData) { for (const key in nodeData) { - if (hasProperty(cloneData, key) || !hasProperty(nodeData, key)) { - continue; - } - (clone as any)[key] = nodeData[key]; - } - if(cloneData.emitNode) { - cloneData.emitNode = undefined; + if (key === "emitNode") continue; + const value = nodeData[key]; + if (value === undefined) continue; + cloneData[key] = nodeData[key]; } } setOriginal(clone, node); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ca5056066394b..8e28f585cc12f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -8212,7 +8212,7 @@ export class TypeImpl { checker!: TypeChecker; flags: TypeFlags; symbol: Symbol; - _data: any = undefined; + data: any; id: number; objectFlags: number; constructor(checker: TypeChecker, flags: TypeFlags) { @@ -8221,741 +8221,738 @@ export class TypeImpl { this.checker = checker; } this.flags = flags; - this.symbol = undefined!; this.objectFlags = 0; + this.symbol = undefined!; + this.data = new TypeDataImpl(); // allTypes.push(this); } - get data() { - return this._data ??= new TypeDataImpl(); - } - get pattern() { - return this._data?.pattern; + return this.data.pattern; } set pattern(value: any) { this.data.pattern = value; } get aliasSymbol() { - return this._data?.aliasSymbol; + return this.data.aliasSymbol; } set aliasSymbol(value: any) { this.data.aliasSymbol = value; } get aliasTypeArguments() { - return this._data?.aliasTypeArguments; + return this.data.aliasTypeArguments; } set aliasTypeArguments(value: any) { this.data.aliasTypeArguments = value; } get permissiveInstantiation() { - return this._data?.permissiveInstantiation; + return this.data.permissiveInstantiation; } set permissiveInstantiation(value: any) { this.data.permissiveInstantiation = value; } get restrictiveInstantiation() { - return this._data?.restrictiveInstantiation; + return this.data.restrictiveInstantiation; } set restrictiveInstantiation(value: any) { this.data.restrictiveInstantiation = value; } get immediateBaseConstraint() { - return this._data?.immediateBaseConstraint; + return this.data.immediateBaseConstraint; } set immediateBaseConstraint(value: any) { this.data.immediateBaseConstraint = value; } get widened() { - return this._data?.widened; + return this.data.widened; } set widened(value: any) { this.data.widened = value; } get intrinsicName() { - return this._data?.intrinsicName; + return this.data.intrinsicName; } set intrinsicName(value: any) { this.data.intrinsicName = value; } get debugIntrinsicName() { - return this._data?.debugIntrinsicName; + return this.data.debugIntrinsicName; } set debugIntrinsicName(value: any) { this.data.debugIntrinsicName = value; } - // get objectFlags() { return this._data?.objectFlags; } + // get objectFlags() { return this.data.objectFlags; } // set objectFlags(value: any) { this.data.objectFlags = value } get freshType() { - return this._data?.freshType; + return this.data.freshType; } set freshType(value: any) { this.data.freshType = value; } get regularType() { - return this._data?.regularType; + return this.data.regularType; } set regularType(value: any) { this.data.regularType = value; } get value() { - return this._data?.value; + return this.data.value; } set value(value: any) { this.data.value = value; } get escapedName() { - return this._data?.escapedName; + return this.data.escapedName; } set escapedName(value: any) { this.data.escapedName = value; } get members() { - return this._data?.members; + return this.data.members; } set members(value: any) { this.data.members = value; } get properties() { - return this._data?.properties; + return this.data.properties; } set properties(value: any) { this.data.properties = value; } get callSignatures() { - return this._data?.callSignatures; + return this.data.callSignatures; } set callSignatures(value: any) { this.data.callSignatures = value; } get constructSignatures() { - return this._data?.constructSignatures; + return this.data.constructSignatures; } set constructSignatures(value: any) { this.data.constructSignatures = value; } get indexInfos() { - return this._data?.indexInfos; + return this.data.indexInfos; } set indexInfos(value: any) { this.data.indexInfos = value; } get objectTypeWithoutAbstractConstructSignatures() { - return this._data?.objectTypeWithoutAbstractConstructSignatures; + return this.data.objectTypeWithoutAbstractConstructSignatures; } set objectTypeWithoutAbstractConstructSignatures(value: any) { this.data.objectTypeWithoutAbstractConstructSignatures = value; } get typeParameters() { - return this._data?.typeParameters; + return this.data.typeParameters; } set typeParameters(value: any) { this.data.typeParameters = value; } get outerTypeParameters() { - return this._data?.outerTypeParameters; + return this.data.outerTypeParameters; } set outerTypeParameters(value: any) { this.data.outerTypeParameters = value; } get localTypeParameters() { - return this._data?.localTypeParameters; + return this.data.localTypeParameters; } set localTypeParameters(value: any) { this.data.localTypeParameters = value; } get thisType() { - return this._data?.thisType; + return this.data.thisType; } set thisType(value: any) { this.data.thisType = value; } get resolvedBaseConstructorType() { - return this._data?.resolvedBaseConstructorType; + return this.data.resolvedBaseConstructorType; } set resolvedBaseConstructorType(value: any) { this.data.resolvedBaseConstructorType = value; } get resolvedBaseTypes() { - return this._data?.resolvedBaseTypes; + return this.data.resolvedBaseTypes; } set resolvedBaseTypes(value: any) { this.data.resolvedBaseTypes = value; } get baseTypesResolved() { - return this._data?.baseTypesResolved; + return this.data.baseTypesResolved; } set baseTypesResolved(value: any) { this.data.baseTypesResolved = value; } get declaredProperties() { - return this._data?.declaredProperties; + return this.data.declaredProperties; } set declaredProperties(value: any) { this.data.declaredProperties = value; } get declaredCallSignatures() { - return this._data?.declaredCallSignatures; + return this.data.declaredCallSignatures; } set declaredCallSignatures(value: any) { this.data.declaredCallSignatures = value; } get declaredConstructSignatures() { - return this._data?.declaredConstructSignatures; + return this.data.declaredConstructSignatures; } set declaredConstructSignatures(value: any) { this.data.declaredConstructSignatures = value; } get declaredIndexInfos() { - return this._data?.declaredIndexInfos; + return this.data.declaredIndexInfos; } set declaredIndexInfos(value: any) { this.data.declaredIndexInfos = value; } get instantiations() { - return this._data?.instantiations; + return this.data.instantiations; } set instantiations(value: any) { this.data.instantiations = value; } get variances() { - return this._data?.variances; + return this.data.variances; } set variances(value: any) { this.data.variances = value; } get target() { - return this._data?.target; + return this.data.target; } set target(value: any) { this.data.target = value; } get node() { - return this._data?.node; + return this.data.node; } set node(value: any) { this.data.node = value; } get mapper() { - return this._data?.mapper; + return this.data.mapper; } set mapper(value: any) { this.data.mapper = value; } get resolvedTypeArguments() { - return this._data?.resolvedTypeArguments; + return this.data.resolvedTypeArguments; } set resolvedTypeArguments(value: any) { this.data.resolvedTypeArguments = value; } get literalType() { - return this._data?.literalType; + return this.data.literalType; } set literalType(value: any) { this.data.literalType = value; } get cachedEquivalentBaseType() { - return this._data?.cachedEquivalentBaseType; + return this.data.cachedEquivalentBaseType; } set cachedEquivalentBaseType(value: any) { this.data.cachedEquivalentBaseType = value; } get elementFlags() { - return this._data?.elementFlags; + return this.data.elementFlags; } set elementFlags(value: any) { this.data.elementFlags = value; } get minLength() { - return this._data?.minLength; + return this.data.minLength; } set minLength(value: any) { this.data.minLength = value; } get fixedLength() { - return this._data?.fixedLength; + return this.data.fixedLength; } set fixedLength(value: any) { this.data.fixedLength = value; } get hasRestElement() { - return this._data?.hasRestElement; + return this.data.hasRestElement; } set hasRestElement(value: any) { this.data.hasRestElement = value; } get combinedFlags() { - return this._data?.combinedFlags; + return this.data.combinedFlags; } set combinedFlags(value: any) { this.data.combinedFlags = value; } get readonly() { - return this._data?.readonly; + return this.data.readonly; } set readonly(value: any) { this.data.readonly = value; } get labeledElementDeclarations() { - return this._data?.labeledElementDeclarations; + return this.data.labeledElementDeclarations; } set labeledElementDeclarations(value: any) { this.data.labeledElementDeclarations = value; } get declaration() { - return this._data?.declaration; + return this.data.declaration; } set declaration(value: any) { this.data.declaration = value; } get typeParameter() { - return this._data?.typeParameter; + return this.data.typeParameter; } set typeParameter(value: any) { this.data.typeParameter = value; } get constraintType() { - return this._data?.constraintType; + return this.data.constraintType; } set constraintType(value: any) { this.data.constraintType = value; } get nameType() { - return this._data?.nameType; + return this.data.nameType; } set nameType(value: any) { this.data.nameType = value; } get templateType() { - return this._data?.templateType; + return this.data.templateType; } set templateType(value: any) { this.data.templateType = value; } get modifiersType() { - return this._data?.modifiersType; + return this.data.modifiersType; } set modifiersType(value: any) { this.data.modifiersType = value; } get resolvedApparentType() { - return this._data?.resolvedApparentType; + return this.data.resolvedApparentType; } set resolvedApparentType(value: any) { this.data.resolvedApparentType = value; } get containsError() { - return this._data?.containsError; + return this.data.containsError; } set containsError(value: any) { this.data.containsError = value; } get elementType() { - return this._data?.elementType; + return this.data.elementType; } set elementType(value: any) { this.data.elementType = value; } get finalArrayType() { - return this._data?.finalArrayType; + return this.data.finalArrayType; } set finalArrayType(value: any) { this.data.finalArrayType = value; } get source() { - return this._data?.source; + return this.data.source; } set source(value: any) { this.data.source = value; } get mappedType() { - return this._data?.mappedType; + return this.data.mappedType; } set mappedType(value: any) { this.data.mappedType = value; } get types() { - return this._data?.types; + return this.data.types; } set types(value: any) { this.data.types = value; } get propertyCache() { - return this._data?.propertyCache; + return this.data.propertyCache; } set propertyCache(value: any) { this.data.propertyCache = value; } get propertyCacheWithoutObjectFunctionPropertyAugment() { - return this._data?.propertyCacheWithoutObjectFunctionPropertyAugment; + return this.data.propertyCacheWithoutObjectFunctionPropertyAugment; } set propertyCacheWithoutObjectFunctionPropertyAugment(value: any) { this.data.propertyCacheWithoutObjectFunctionPropertyAugment = value; } get resolvedProperties() { - return this._data?.resolvedProperties; + return this.data.resolvedProperties; } set resolvedProperties(value: any) { this.data.resolvedProperties = value; } get resolvedIndexType() { - return this._data?.resolvedIndexType; + return this.data.resolvedIndexType; } set resolvedIndexType(value: any) { this.data.resolvedIndexType = value; } get resolvedStringIndexType() { - return this._data?.resolvedStringIndexType; + return this.data.resolvedStringIndexType; } set resolvedStringIndexType(value: any) { this.data.resolvedStringIndexType = value; } get resolvedBaseConstraint() { - return this._data?.resolvedBaseConstraint; + return this.data.resolvedBaseConstraint; } set resolvedBaseConstraint(value: any) { this.data.resolvedBaseConstraint = value; } get iterationTypesOfGeneratorReturnType() { - return this._data?.iterationTypesOfGeneratorReturnType; + return this.data.iterationTypesOfGeneratorReturnType; } set iterationTypesOfGeneratorReturnType(value: any) { this.data.iterationTypesOfGeneratorReturnType = value; } get iterationTypesOfAsyncGeneratorReturnType() { - return this._data?.iterationTypesOfAsyncGeneratorReturnType; + return this.data.iterationTypesOfAsyncGeneratorReturnType; } set iterationTypesOfAsyncGeneratorReturnType(value: any) { this.data.iterationTypesOfAsyncGeneratorReturnType = value; } get iterationTypesOfIterable() { - return this._data?.iterationTypesOfIterable; + return this.data.iterationTypesOfIterable; } set iterationTypesOfIterable(value: any) { this.data.iterationTypesOfIterable = value; } get iterationTypesOfIterator() { - return this._data?.iterationTypesOfIterator; + return this.data.iterationTypesOfIterator; } set iterationTypesOfIterator(value: any) { this.data.iterationTypesOfIterator = value; } get iterationTypesOfAsyncIterable() { - return this._data?.iterationTypesOfAsyncIterable; + return this.data.iterationTypesOfAsyncIterable; } set iterationTypesOfAsyncIterable(value: any) { this.data.iterationTypesOfAsyncIterable = value; } get iterationTypesOfAsyncIterator() { - return this._data?.iterationTypesOfAsyncIterator; + return this.data.iterationTypesOfAsyncIterator; } set iterationTypesOfAsyncIterator(value: any) { this.data.iterationTypesOfAsyncIterator = value; } get iterationTypesOfIteratorResult() { - return this._data?.iterationTypesOfIteratorResult; + return this.data.iterationTypesOfIteratorResult; } set iterationTypesOfIteratorResult(value: any) { this.data.iterationTypesOfIteratorResult = value; } get resolvedReducedType() { - return this._data?.resolvedReducedType; + return this.data.resolvedReducedType; } set resolvedReducedType(value: any) { this.data.resolvedReducedType = value; } get origin() { - return this._data?.origin; + return this.data.origin; } set origin(value: any) { this.data.origin = value; } get keyPropertyName() { - return this._data?.keyPropertyName; + return this.data.keyPropertyName; } set keyPropertyName(value: any) { this.data.keyPropertyName = value; } get constituentMap() { - return this._data?.constituentMap; + return this.data.constituentMap; } set constituentMap(value: any) { this.data.constituentMap = value; } get arrayFallbackSignatures() { - return this._data?.arrayFallbackSignatures; + return this.data.arrayFallbackSignatures; } set arrayFallbackSignatures(value: any) { this.data.arrayFallbackSignatures = value; } get promiseTypeOfPromiseConstructor() { - return this._data?.promiseTypeOfPromiseConstructor; + return this.data.promiseTypeOfPromiseConstructor; } set promiseTypeOfPromiseConstructor(value: any) { this.data.promiseTypeOfPromiseConstructor = value; } get promisedTypeOfPromise() { - return this._data?.promisedTypeOfPromise; + return this.data.promisedTypeOfPromise; } set promisedTypeOfPromise(value: any) { this.data.promisedTypeOfPromise = value; } get awaitedTypeOfType() { - return this._data?.awaitedTypeOfType; + return this.data.awaitedTypeOfType; } set awaitedTypeOfType(value: any) { this.data.awaitedTypeOfType = value; } get uniqueLiteralFilledInstantiation() { - return this._data?.uniqueLiteralFilledInstantiation; + return this.data.uniqueLiteralFilledInstantiation; } set uniqueLiteralFilledInstantiation(value: any) { this.data.uniqueLiteralFilledInstantiation = value; } get syntheticType() { - return this._data?.syntheticType; + return this.data.syntheticType; } set syntheticType(value: any) { this.data.syntheticType = value; } get defaultOnlyType() { - return this._data?.defaultOnlyType; + return this.data.defaultOnlyType; } set defaultOnlyType(value: any) { this.data.defaultOnlyType = value; } get constraint() { - return this._data?.constraint; + return this.data.constraint; } set constraint(value: any) { this.data.constraint = value; } get default() { - return this._data?.default; + return this.data.default; } set default(value: any) { this.data.default = value; } get isThisType() { - return this._data?.isThisType; + return this.data.isThisType; } set isThisType(value: any) { this.data.isThisType = value; } get resolvedDefaultType() { - return this._data?.resolvedDefaultType; + return this.data.resolvedDefaultType; } set resolvedDefaultType(value: any) { this.data.resolvedDefaultType = value; } get objectType() { - return this._data?.objectType; + return this.data.objectType; } set objectType(value: any) { this.data.objectType = value; } get indexType() { - return this._data?.indexType; + return this.data.indexType; } set indexType(value: any) { this.data.indexType = value; } get accessFlags() { - return this._data?.accessFlags; + return this.data.accessFlags; } set accessFlags(value: any) { this.data.accessFlags = value; } get simplifiedForReading() { - return this._data?.simplifiedForReading; + return this.data.simplifiedForReading; } set simplifiedForReading(value: any) { this.data.simplifiedForReading = value; } get simplifiedForWriting() { - return this._data?.simplifiedForWriting; + return this.data.simplifiedForWriting; } set simplifiedForWriting(value: any) { this.data.simplifiedForWriting = value; } get type() { - return this._data?.type; + return this.data.type; } set type(value: any) { this.data.type = value; } get indexFlags() { - return this._data?.indexFlags; + return this.data.indexFlags; } set indexFlags(value: any) { this.data.indexFlags = value; } get root() { - return this._data?.root; + return this.data.root; } set root(value: any) { this.data.root = value; } get checkType() { - return this._data?.checkType; + return this.data.checkType; } set checkType(value: any) { this.data.checkType = value; } get extendsType() { - return this._data?.extendsType; + return this.data.extendsType; } set extendsType(value: any) { this.data.extendsType = value; } get resolvedTrueType() { - return this._data?.resolvedTrueType; + return this.data.resolvedTrueType; } set resolvedTrueType(value: any) { this.data.resolvedTrueType = value; } get resolvedFalseType() { - return this._data?.resolvedFalseType; + return this.data.resolvedFalseType; } set resolvedFalseType(value: any) { this.data.resolvedFalseType = value; } get resolvedInferredTrueType() { - return this._data?.resolvedInferredTrueType; + return this.data.resolvedInferredTrueType; } set resolvedInferredTrueType(value: any) { this.data.resolvedInferredTrueType = value; } get resolvedDefaultConstraint() { - return this._data?.resolvedDefaultConstraint; + return this.data.resolvedDefaultConstraint; } set resolvedDefaultConstraint(value: any) { this.data.resolvedDefaultConstraint = value; } get resolvedConstraintOfDistributive() { - return this._data?.resolvedConstraintOfDistributive; + return this.data.resolvedConstraintOfDistributive; } set resolvedConstraintOfDistributive(value: any) { this.data.resolvedConstraintOfDistributive = value; } get combinedMapper() { - return this._data?.combinedMapper; + return this.data.combinedMapper; } set combinedMapper(value: any) { this.data.combinedMapper = value; } get texts() { - return this._data?.texts; + return this.data.texts; } set texts(value: any) { this.data.texts = value; } get baseType() { - return this._data?.baseType; + return this.data.baseType; } set baseType(value: any) { this.data.baseType = value; @@ -9005,50 +9002,51 @@ export class SignatureImpl { this.mapper = undefined; this.compositeSignatures = undefined; this.compositeKind = undefined; + this._data = undefined; } // get data(): any { return this; } - _data: any = undefined; + _data: any; get data() { return this._data ??= new SignatureDataImpl(); } get erasedSignatureCache() { - return this._data?.erasedSignatureCache; + return this.data.erasedSignatureCache; } set erasedSignatureCache(value: any) { this.data.erasedSignatureCache = value; } get canonicalSignatureCache() { - return this._data?.canonicalSignatureCache; + return this.data.canonicalSignatureCache; } set canonicalSignatureCache(value: any) { this.data.canonicalSignatureCache = value; } get baseSignatureCache() { - return this._data?.baseSignatureCache; + return this.data.baseSignatureCache; } set baseSignatureCache(value: any) { this.data.baseSignatureCache = value; } get optionalCallSignatureCache() { - return this._data?.optionalCallSignatureCache; + return this.data.optionalCallSignatureCache; } set optionalCallSignatureCache(value: any) { this.data.optionalCallSignatureCache = value; } get isolatedSignatureType() { - return this._data?.isolatedSignatureType; + return this.data.isolatedSignatureType; } set isolatedSignatureType(value: any) { this.data.isolatedSignatureType = value; } get instantiations() { - return this._data?.instantiations; + return this.data.instantiations; } set instantiations(value: any) { this.data.instantiations = value; } get implementationSignatureCache() { - return this._data?.implementationSignatureCache; + return this.data.implementationSignatureCache; } set implementationSignatureCache(value: any) { this.data.implementationSignatureCache = value; @@ -9064,6 +9062,8 @@ export class SignatureImpl { // // modifierFlagsCache = ModifierFlags.None // } // export const NodeImplInstantiations: Partial> = {} + +// export const allNodes = new Set(); /** @internal */ export class NodeImpl { pos: number; @@ -9077,7 +9077,7 @@ export class NodeImpl { modifierFlagsCache: ModifierFlags; // original: undefined; escapedText: undefined; - jsDoc: any; + // jsDoc: any; flowNode: any; symbol: any; __symbolTestOutputCache?: any; // For tests only @@ -9095,16 +9095,28 @@ export class NodeImpl { // this.original = undefined; this.escapedText = undefined; - this.jsDoc = undefined; + // this.jsDoc = undefined; this.flowNode = undefined; this.symbol = undefined; + // allNodes.add(this); - // if (Debug.isDebugging || tracing) { - // this.__symbolTestOutputCache = undefined; - // } + if (Debug.isDebugging || tracing) { + this.__symbolTestOutputCache = undefined; + } } data: any = undefined; + get jsDoc() { + return this.data?.jsDoc; + } + set jsDoc(value: any) { + if (!this.data) { + this.data = { jsDoc: value }; + } + else { + this.data.jsDoc = value; + } + } get emitNode() { return this.data?.emitNode; } From 570e42dd500f4722867d1c0c17b0b31ce34b194b Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Mon, 1 Jul 2024 11:35:04 +0100 Subject: [PATCH 13/13] Fix lint. --- src/compiler/factory/nodeFactory.ts | 1 - src/compiler/utilities.ts | 10 ---------- 2 files changed, 11 deletions(-) diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index e47c549072008..34fcb235a7042 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -120,7 +120,6 @@ import { HasDecorators, hasInvalidEscape, HasModifiers, - hasProperty, hasSyntacticModifier, HeritageClause, Identifier, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8e28f585cc12f..e9e9cab9f3e8c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -13868,13 +13868,3 @@ export function hasInferredType(node: Node): node is HasInferredType { return false; } } - -const objectArray = [{} as never]; -/** - * @internal - * Ensures V8 creates a PACKED_ELEMENTS array and not a PACKED_SMI_ELEMENTS array - */ -export function createEmptyObjectArray(): T[] { - const elements = objectArray.slice(0, 0); - return elements as T[]; -}