diff --git a/src/compat/deprecations.ts b/src/compat/deprecations.ts index 16cf1fe41e610..940f290e67913 100644 --- a/src/compat/deprecations.ts +++ b/src/compat/deprecations.ts @@ -1928,7 +1928,11 @@ namespace ts { }); /** - * Creates a shallow, memberwise clone of a node for mutation. + * Creates a shallow, memberwise clone of a node ~for mutation~ with its `pos`, `end`, and `parent` set. + * + * NOTE: It is unsafe to change any properties of a `Node` that relate to its AST children, as those changes won't be + * captured with respect to transformations. + * * @deprecated Use `factory.cloneNode` instead and set `pos`, `end`, and `parent` as needed. */ export function getMutableClone(node: T): T { diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 639b3f9ba3d40..f688ab4673d91 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -584,7 +584,7 @@ namespace ts { // All container nodes are kept on a linked list in declaration order. This list is used by // the getLocalNameOfContainer function in the type checker to validate that the local name // used for a container is unique. - function bindContainer(node: Node, containerFlags: ContainerFlags) { + function bindContainer(node: Mutable, containerFlags: ContainerFlags) { // Before we recurse into a node's children, we first save the existing parent, container // and block-container. Then after we pop out of processing the children, we restore // these saved values. @@ -1757,7 +1757,7 @@ namespace ts { return !!body && body.statements.some(s => isExportDeclaration(s) || isExportAssignment(s)); } - function setExportContextFlag(node: ModuleDeclaration | SourceFile) { + function setExportContextFlag(node: Mutable) { // A declaration source file or ambient module declaration that contains no export declarations (but possibly regular // declarations with export modifiers) is an export context in which declarations are implicitly exported. if (node.flags & NodeFlags.Ambient && !hasExportDeclarations(node)) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4bb181f506ef9..4450d7b15a174 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3683,7 +3683,7 @@ namespace ts { typeToTypeNode: (type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => typeToTypeNodeHelper(type, context)), indexInfoToIndexSignatureDeclaration: (indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => - withContext(enclosingDeclaration, flags, tracker, context => indexInfoToIndexSignatureDeclarationHelper(indexInfo, kind, context)), + withContext(enclosingDeclaration, flags, tracker, context => indexInfoToIndexSignatureDeclarationHelper(indexInfo, kind, context, /*typeNode*/ undefined)), signatureToSignatureDeclaration: (signature: Signature, kind: SignatureDeclaration["kind"], enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => signatureToSignatureDeclarationHelper(signature, kind, context)), symbolToEntityName: (symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => @@ -4141,29 +4141,53 @@ namespace ts { function appendReferenceToType(root: TypeReferenceNode | ImportTypeNode, ref: TypeReferenceNode): TypeReferenceNode | ImportTypeNode { if (isImportTypeNode(root)) { // first shift type arguments - const innerParams = root.typeArguments; - if (root.qualifier) { - (isIdentifier(root.qualifier) ? root.qualifier : root.qualifier.right).typeArguments = innerParams; + let typeArguments = root.typeArguments; + let qualifier = root.qualifier; + if (qualifier) { + if (isIdentifier(qualifier)) { + qualifier = factory.updateIdentifier(qualifier, typeArguments); + } + else { + qualifier = factory.updateQualifiedName(qualifier, + qualifier.left, + factory.updateIdentifier(qualifier.right, typeArguments)); + } } - root.typeArguments = ref.typeArguments; + typeArguments = ref.typeArguments; // then move qualifiers const ids = getAccessStack(ref); for (const id of ids) { - root.qualifier = root.qualifier ? factory.createQualifiedName(root.qualifier, id) : id; + qualifier = qualifier ? factory.createQualifiedName(qualifier, id) : id; } - return root; + return factory.updateImportTypeNode( + root, + root.argument, + qualifier, + typeArguments, + root.isTypeOf); } else { // first shift type arguments - const innerParams = root.typeArguments; - (isIdentifier(root.typeName) ? root.typeName : root.typeName.right).typeArguments = innerParams; - root.typeArguments = ref.typeArguments; + let typeArguments = root.typeArguments; + let typeName = root.typeName; + if (isIdentifier(typeName)) { + typeName = factory.updateIdentifier(typeName, typeArguments); + } + else { + typeName = factory.updateQualifiedName(typeName, + typeName.left, + factory.updateIdentifier(typeName.right, typeArguments)); + } + typeArguments = ref.typeArguments; // then move qualifiers const ids = getAccessStack(ref); for (const id of ids) { - root.typeName = factory.createQualifiedName(root.typeName, id); + typeName = factory.createQualifiedName(typeName, id); } - return root; + return factory.updateTypeReferenceNode( + root, + typeName, + typeArguments); } } @@ -4192,16 +4216,19 @@ namespace ts { if (resolvedType.stringIndexInfo) { let indexSignature: IndexSignatureDeclaration; if (resolvedType.objectFlags & ObjectFlags.ReverseMapped) { - indexSignature = indexInfoToIndexSignatureDeclarationHelper(createIndexInfo(anyType, resolvedType.stringIndexInfo.isReadonly, resolvedType.stringIndexInfo.declaration), IndexKind.String, context); - indexSignature.type = createElidedInformationPlaceholder(context); + indexSignature = indexInfoToIndexSignatureDeclarationHelper( + createIndexInfo(anyType, resolvedType.stringIndexInfo.isReadonly, resolvedType.stringIndexInfo.declaration), + IndexKind.String, + context, + createElidedInformationPlaceholder(context)); } else { - indexSignature = indexInfoToIndexSignatureDeclarationHelper(resolvedType.stringIndexInfo, IndexKind.String, context); + indexSignature = indexInfoToIndexSignatureDeclarationHelper(resolvedType.stringIndexInfo, IndexKind.String, context, /*typeNode*/ undefined); } typeElements.push(indexSignature); } if (resolvedType.numberIndexInfo) { - typeElements.push(indexInfoToIndexSignatureDeclarationHelper(resolvedType.numberIndexInfo, IndexKind.Number, context)); + typeElements.push(indexInfoToIndexSignatureDeclarationHelper(resolvedType.numberIndexInfo, IndexKind.Number, context, /*typeNode*/ undefined)); } const properties = resolvedType.properties; @@ -4267,9 +4294,7 @@ namespace ts { if (propertySymbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(propertyType).length && !isReadonlySymbol(propertySymbol)) { const signatures = getSignaturesOfType(filterType(propertyType, t => !(t.flags & TypeFlags.Undefined)), SignatureKind.Call); for (const signature of signatures) { - const methodDeclaration = signatureToSignatureDeclarationHelper(signature, SyntaxKind.MethodSignature, context); - methodDeclaration.name = propertyName; - methodDeclaration.questionToken = optionalToken; + const methodDeclaration = signatureToSignatureDeclarationHelper(signature, SyntaxKind.MethodSignature, context, { name: propertyName, questionToken: optionalToken }); typeElements.push(preserveCommentsOn(methodDeclaration)); } } @@ -4351,7 +4376,7 @@ namespace ts { } } - function indexInfoToIndexSignatureDeclarationHelper(indexInfo: IndexInfo, kind: IndexKind, context: NodeBuilderContext): IndexSignatureDeclaration { + function indexInfoToIndexSignatureDeclarationHelper(indexInfo: IndexInfo, kind: IndexKind, context: NodeBuilderContext, typeNode: TypeNode | undefined): IndexSignatureDeclaration { const name = getNameFromIndexInfo(indexInfo) || "x"; const indexerTypeNode = factory.createKeywordTypeNode(kind === IndexKind.String ? SyntaxKind.StringKeyword : SyntaxKind.NumberKeyword); @@ -4363,7 +4388,9 @@ namespace ts { /*questionToken*/ undefined, indexerTypeNode, /*initializer*/ undefined); - const typeNode = typeToTypeNodeHelper(indexInfo.type || anyType, context); + if (!typeNode) { + typeNode = typeToTypeNodeHelper(indexInfo.type || anyType, context); + } if (!indexInfo.type && !(context.flags & NodeBuilderFlags.AllowEmptyIndexInfoType)) { context.encounteredError = true; } @@ -4375,7 +4402,14 @@ namespace ts { typeNode); } - function signatureToSignatureDeclarationHelper(signature: Signature, kind: SignatureDeclaration["kind"], context: NodeBuilderContext): SignatureDeclaration { + interface SignatureToSignatureDeclarationOptions { + modifiers?: readonly Modifier[]; + name?: PropertyName; + questionToken?: QuestionToken; + + } + + function signatureToSignatureDeclarationHelper(signature: Signature, kind: SignatureDeclaration["kind"], context: NodeBuilderContext, options?: SignatureToSignatureDeclarationOptions): SignatureDeclaration { let typeParameters: TypeParameterDeclaration[] | undefined; let typeArguments: TypeNode[] | undefined; if (context.flags & NodeBuilderFlags.WriteTypeArgumentsOfSignature && signature.target && signature.mapper && signature.target.typeParameters) { @@ -4416,10 +4450,28 @@ namespace ts { returnTypeNode = factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); } context.approximateLength += 3; // Usually a signature contributes a few more characters than this, but 3 is the minimum - const node = factory.createSignatureDeclaration(kind, typeParameters, parameters, returnTypeNode); + + const node = + kind === SyntaxKind.CallSignature ? factory.createCallSignature(typeParameters, parameters, returnTypeNode) : + kind === SyntaxKind.ConstructSignature ? factory.createConstructSignature(typeParameters, parameters, returnTypeNode) : + kind === SyntaxKind.MethodSignature ? factory.createMethodSignature(options?.modifiers, options?.name ?? factory.createIdentifier(""), options?.questionToken, typeParameters, parameters, returnTypeNode) : + kind === SyntaxKind.MethodDeclaration ? factory.createMethodDeclaration(/*decorators*/ undefined, options?.modifiers, /*asteriskToken*/ undefined, options?.name ?? factory.createIdentifier(""), /*questionToken*/ undefined, typeParameters, parameters, returnTypeNode, /*body*/ undefined) : + kind === SyntaxKind.Constructor ? factory.createConstructorDeclaration(/*decorators*/ undefined, options?.modifiers, parameters, /*body*/ undefined) : + kind === SyntaxKind.GetAccessor ? factory.createGetAccessorDeclaration(/*decorators*/ undefined, options?.modifiers, options?.name ?? factory.createIdentifier(""), parameters, returnTypeNode, /*body*/ undefined) : + kind === SyntaxKind.SetAccessor ? factory.createSetAccessorDeclaration(/*decorators*/ undefined, options?.modifiers, options?.name ?? factory.createIdentifier(""), parameters, /*body*/ undefined) : + kind === SyntaxKind.IndexSignature ? factory.createIndexSignature(/*decorators*/ undefined, options?.modifiers, parameters, returnTypeNode) : + kind === SyntaxKind.JSDocFunctionType ? factory.createJSDocFunctionType(parameters, returnTypeNode) : + kind === SyntaxKind.FunctionType ? factory.createFunctionTypeNode(typeParameters, parameters, returnTypeNode) : + kind === SyntaxKind.ConstructorType ? factory.createConstructorTypeNode(typeParameters, parameters, returnTypeNode) : + kind === SyntaxKind.FunctionDeclaration ? factory.createFunctionDeclaration(/*decorators*/ undefined, options?.modifiers, /*asteriskToken*/ undefined, options?.name ? cast(options.name, isIdentifier) : factory.createIdentifier(""), typeParameters, parameters, returnTypeNode, /*body*/ undefined) : + kind === SyntaxKind.FunctionExpression ? factory.createFunctionExpression(options?.modifiers, /*asteriskToken*/ undefined, options?.name ? cast(options.name, isIdentifier) : factory.createIdentifier(""), typeParameters, parameters, returnTypeNode, factory.createBlock([])) : + kind === SyntaxKind.ArrowFunction ? factory.createArrowFunction(options?.modifiers, typeParameters, parameters, returnTypeNode, /*equalsGreaterThanToken*/ undefined, factory.createBlock([])) : + Debug.assertNever(kind); + if (typeArguments) { node.typeArguments = factory.createNodeArray(typeArguments); } + return node; } @@ -4478,12 +4530,19 @@ namespace ts { if (context.tracker.trackSymbol && isComputedPropertyName(node) && isLateBindableName(node)) { trackComputedName(node.expression, context.enclosingDeclaration, context); } - const visited = visitEachChild(node, elideInitializerAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!; - const clone = nodeIsSynthesized(visited) ? visited : factory.cloneNode(visited); - if (clone.kind === SyntaxKind.BindingElement) { - (clone).initializer = undefined; + let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!; + if (isBindingElement(visited)) { + visited = factory.updateBindingElement( + visited, + visited.dotDotDotToken, + visited.propertyName, + visited.name, + /*initializer*/ undefined); } - return setEmitFlags(clone, EmitFlags.SingleLine | EmitFlags.NoAsciiEscaping); + if (!nodeIsSynthesized(visited)) { + visited = factory.cloneNode(visited); + } + return setEmitFlags(visited, EmitFlags.SingleLine | EmitFlags.NoAsciiEscaping); } } } @@ -4882,8 +4941,11 @@ namespace ts { } let expression: Expression | undefined; if (isSingleOrDoubleQuote(firstChar)) { - expression = factory.createStringLiteral(symbolName.substring(1, symbolName.length - 1).replace(/\\./g, s => s.substring(1))); - (expression as StringLiteral).singleQuote = firstChar === CharacterCodes.singleQuote; + expression = factory.createStringLiteral( + symbolName + .substring(1, symbolName.length - 1) + .replace(/\\./g, s => s.substring(1)), + firstChar === CharacterCodes.singleQuote); } else if (("" + +symbolName) === symbolName) { expression = factory.createNumericLiteral(+symbolName); @@ -5042,27 +5104,39 @@ namespace ts { function flattenExportAssignedNamespace(statements: Statement[]) { const exportAssignment = find(statements, isExportAssignment); - const ns = find(statements, isModuleDeclaration); + const nsIndex = findIndex(statements, isModuleDeclaration); + let ns = nsIndex !== -1 ? statements[nsIndex] as ModuleDeclaration : undefined; if (ns && exportAssignment && exportAssignment.isExportEquals && isIdentifier(exportAssignment.expression) && isIdentifier(ns.name) && idText(ns.name) === idText(exportAssignment.expression) && ns.body && isModuleBlock(ns.body)) { // Pass 0: Correct situations where a module has both an `export = ns` and multiple top-level exports by stripping the export modifiers from // the top-level exports and exporting them in the targeted ns, as can occur when a js file has both typedefs and `module.export` assignments const excessExports = filter(statements, s => !!(getModifierFlags(s) & ModifierFlags.Export)); + const name = ns.name; + let body = ns.body; if (length(excessExports)) { - ns.body.statements = factory.createNodeArray([...ns.body.statements, factory.createExportDeclaration( - /*decorators*/ undefined, - /*modifiers*/ undefined, - factory.createNamedExports(map(flatMap(excessExports, e => getNamesOfDeclaration(e)), id => factory.createExportSpecifier(/*alias*/ undefined, id))), - /*moduleSpecifier*/ undefined - )]); + ns = factory.updateModuleDeclaration( + ns, + ns.decorators, + ns.modifiers, + ns.name, + body = factory.updateModuleBlock( + body, + factory.createNodeArray([...ns.body.statements, factory.createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + factory.createNamedExports(map(flatMap(excessExports, e => getNamesOfDeclaration(e)), id => factory.createExportSpecifier(/*alias*/ undefined, id))), + /*moduleSpecifier*/ undefined + )]) + ) + ); + statements = [...statements.slice(0, nsIndex), ns, ...statements.slice(nsIndex + 1)]; } - // Pass 1: Flatten `export namespace _exports {} export = _exports;` so long as the `export=` only points at a single namespace declaration - if (!find(statements, s => s !== ns && nodeHasName(s, ns.name as Identifier))) { + if (!find(statements, s => s !== ns && nodeHasName(s, name))) { results = []; - forEach(ns.body.statements, s => { + forEach(body.statements, s => { addResult(s, ModifierFlags.None); // Recalculates the ambient (and export, if applicable from above) flag }); statements = [...filter(statements, s => s !== ns && s !== exportAssignment), ...results]; @@ -5109,27 +5183,39 @@ namespace ts { function inlineExportModifiers(statements: Statement[]) { // Pass 3: Move all `export {}`'s to `export` modifiers where possible - const exportDecl = find(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause) as ExportDeclaration | undefined; - if (exportDecl) { - const replacements = mapDefined(exportDecl.exportClause!.elements, e => { + const index = findIndex(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause); + if (index >= 0) { + const exportDecl = statements[index] as ExportDeclaration & { readonly exportClause: NamedExports }; + const replacements = mapDefined(exportDecl.exportClause.elements, e => { if (!e.propertyName) { // export {name} - look thru `statements` for `name`, and if all results can take an `export` modifier, do so and filter it - const associated = filter(statements, s => nodeHasName(s, e.name)); - if (length(associated) && every(associated, canHaveExportModifier)) { - forEach(associated, addExportModifier); + const indices = indicesOf(statements); + const associatedIndices = filter(indices, i => nodeHasName(statements[i], e.name)); + if (length(associatedIndices) && every(associatedIndices, i => canHaveExportModifier(statements[i]))) { + for (const index of associatedIndices) { + statements[index] = addExportModifier(statements[index] as Extract); + } return undefined; } } return e; }); if (!length(replacements)) { - // all clauses removed, filter the export declaration - statements = filter(statements, s => s !== exportDecl); + // all clauses removed, remove the export declaration + orderedRemoveItemAt(statements, index); } else { // some items filtered, others not - update the export declaration - // (mutating because why not, we're building a whole new tree here anyway) - exportDecl.exportClause!.elements = factory.createNodeArray(replacements); + statements[index] = factory.updateExportDeclaration( + exportDecl, + exportDecl.decorators, + exportDecl.modifiers, + factory.updateNamedExports( + exportDecl.exportClause, + replacements + ), + exportDecl.moduleSpecifier + ); } } return statements; @@ -5150,7 +5236,7 @@ namespace ts { return statements; } - function canHaveExportModifier(node: Statement) { + function canHaveExportModifier(node: Statement): node is Extract { return isEnumDeclaration(node) || isVariableStatement(node) || isFunctionDeclaration(node) || @@ -5160,10 +5246,9 @@ namespace ts { isTypeDeclaration(node); } - function addExportModifier(statement: Statement) { - const flags = (getModifierFlags(statement) | ModifierFlags.Export) & ~ModifierFlags.Ambient; - statement.modifiers = factory.createNodeArray(factory.createModifiersFromModifierFlags(flags)); - statement.modifierFlagsCache = 0; + function addExportModifier(node: Extract) { + const flags = (getModifierFlags(node) | ModifierFlags.Export) & ~ModifierFlags.Ambient; + return factory.updateModifiers(node, flags); } function visitSymbolTable(symbolTable: SymbolTable, suppressNewPrivateContext?: boolean, propertyAsAlias?: boolean) { @@ -5302,29 +5387,29 @@ namespace ts { } // Prepends a `declare` and/or `export` modifier if the context requires it, and then adds `node` to `result` and returns `node` - // Note: This _mutates_ `node` without using `updateNode` - the assumption being that all nodes should be manufactured fresh by the node builder function addResult(node: Statement, additionalModifierFlags: ModifierFlags) { - let newModifierFlags: ModifierFlags = ModifierFlags.None; - if (additionalModifierFlags & ModifierFlags.Export && - enclosingDeclaration && - isExportingScope(enclosingDeclaration) && - canHaveExportModifier(node) - ) { - // Classes, namespaces, variables, functions, interfaces, and types should all be `export`ed in a module context if not private - newModifierFlags |= ModifierFlags.Export; - } - if (addingDeclare && !(newModifierFlags & ModifierFlags.Export) && - (!enclosingDeclaration || !(enclosingDeclaration.flags & NodeFlags.Ambient)) && - (isEnumDeclaration(node) || isVariableStatement(node) || isFunctionDeclaration(node) || isClassDeclaration(node) || isModuleDeclaration(node))) { - // Classes, namespaces, variables, enums, and functions all need `declare` modifiers to be valid in a declaration file top-level scope - newModifierFlags |= ModifierFlags.Ambient; - } - if ((additionalModifierFlags & ModifierFlags.Default) && (isClassDeclaration(node) || isInterfaceDeclaration(node) || isFunctionDeclaration(node))) { - newModifierFlags |= ModifierFlags.Default; - } - if (newModifierFlags) { - node.modifiers = factory.createNodeArray(factory.createModifiersFromModifierFlags(newModifierFlags | getModifierFlags(node))); - node.modifierFlagsCache = 0; // Reset computed flags cache + if (canHaveModifiers(node)) { + let newModifierFlags: ModifierFlags = ModifierFlags.None; + if (additionalModifierFlags & ModifierFlags.Export && + enclosingDeclaration && + isExportingScope(enclosingDeclaration) && + canHaveExportModifier(node) + ) { + // Classes, namespaces, variables, functions, interfaces, and types should all be `export`ed in a module context if not private + newModifierFlags |= ModifierFlags.Export; + } + if (addingDeclare && !(newModifierFlags & ModifierFlags.Export) && + (!enclosingDeclaration || !(enclosingDeclaration.flags & NodeFlags.Ambient)) && + (isEnumDeclaration(node) || isVariableStatement(node) || isFunctionDeclaration(node) || isClassDeclaration(node) || isModuleDeclaration(node))) { + // Classes, namespaces, variables, enums, and functions all need `declare` modifiers to be valid in a declaration file top-level scope + newModifierFlags |= ModifierFlags.Ambient; + } + if ((additionalModifierFlags & ModifierFlags.Default) && (isClassDeclaration(node) || isInterfaceDeclaration(node) || isFunctionDeclaration(node))) { + newModifierFlags |= ModifierFlags.Default; + } + if (newModifierFlags) { + node = factory.updateModifiers(node, newModifierFlags | getModifierFlags(node)); + } } results.push(node); } @@ -5495,8 +5580,7 @@ namespace ts { const signatures = getSignaturesOfType(type, SignatureKind.Call); for (const sig of signatures) { // Each overload becomes a separate function declaration, in order - const decl = signatureToSignatureDeclarationHelper(sig, SyntaxKind.FunctionDeclaration, context) as FunctionDeclaration; - decl.name = factory.createIdentifier(localName); + const decl = signatureToSignatureDeclarationHelper(sig, SyntaxKind.FunctionDeclaration, context, { name: factory.createIdentifier(localName) }) as FunctionDeclaration; addResult(setTextRange(decl, sig.declaration), modifierFlags); } // Module symbol emit will take care of module-y members, provided it has exports @@ -5530,11 +5614,12 @@ namespace ts { // emit akin to the above would be needed. // Add a namespace - const fakespace = factory.createModuleDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, factory.createIdentifier(localName), factory.createModuleBlock([]), NodeFlags.Namespace); - fakespace.flags ^= NodeFlags.Synthesized; // unset synthesized so it is usable as an enclosing declaration + // Create namespace as non-synthetic so it is usable as an enclosing declaration + let fakespace = parseNodeFactory.createModuleDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, factory.createIdentifier(localName), factory.createModuleBlock([]), NodeFlags.Namespace); fakespace.parent = enclosingDeclaration as SourceFile | NamespaceDeclaration; fakespace.locals = createSymbolTable(props); fakespace.symbol = props[0].parent!; + const oldResults = results; results = []; const oldAddingDeclare = addingDeclare; @@ -5548,11 +5633,14 @@ namespace ts { addingDeclare = oldAddingDeclare; const declarations = results; results = oldResults; - fakespace.flags ^= NodeFlags.Synthesized; // reset synthesized - fakespace.parent = undefined!; - fakespace.locals = undefined!; - fakespace.symbol = undefined!; - fakespace.body = factory.createModuleBlock(declarations); + + // replace namespace with synthetic version + fakespace = factory.updateModuleDeclaration( + fakespace, + fakespace.decorators, + fakespace.modifiers, + fakespace.name, + factory.createModuleBlock(declarations)); addResult(fakespace, modifierFlags); // namespaces can never be default exported } } @@ -5574,12 +5662,6 @@ namespace ts { p => !(p.flags & SymbolFlags.Prototype) && p.escapedName !== "prototype" ), p => serializePropertySymbolForClass(p, /*isStatic*/ true, staticBaseType)); const constructors = serializeSignatures(SignatureKind.Construct, staticType, baseTypes[0], SyntaxKind.Constructor) as ConstructorDeclaration[]; - for (const c of constructors) { - // A constructor's return type and type parameters are supposed to be controlled by the enclosing class declaration - // `signatureToSignatureDeclarationHelper` appends them regardless, so for now we delete them here - c.type = undefined; - c.typeParameters = undefined; - } const indexSignatures = serializeIndexSignatures(classType, baseTypes[0]); addResult(setTextRange(factory.createClassDeclaration( /*decorators*/ undefined, @@ -5900,14 +5982,16 @@ namespace ts { const results = []; for (const sig of signatures) { // Each overload becomes a separate method declaration, in order - const decl = signatureToSignatureDeclarationHelper(sig, methodKind, context) as MethodDeclaration; - decl.name = name; // TODO: Clone - if (staticFlag) { - decl.modifiers = factory.createNodeArray(factory.createModifiersFromModifierFlags(staticFlag)); - } - if (p.flags & SymbolFlags.Optional) { - decl.questionToken = factory.createToken(SyntaxKind.QuestionToken); - } + const decl = signatureToSignatureDeclarationHelper( + sig, + methodKind, + context, + { + name, + questionToken: p.flags & SymbolFlags.Optional ? factory.createToken(SyntaxKind.QuestionToken) : undefined, + modifiers: staticFlag ? factory.createModifiersFromModifierFlags(staticFlag) : undefined + } + ); results.push(setTextRange(decl, sig.declaration)); } return results as unknown as T[]; @@ -6115,7 +6199,7 @@ namespace ts { } } } - results.push(indexInfoToIndexSignatureDeclarationHelper(info, type, context)); + results.push(indexInfoToIndexSignatureDeclarationHelper(info, type, context, /*typeNode*/ undefined)); } } return results; diff --git a/src/compiler/core.ts b/src/compiler/core.ts index c8d561f190872..ad6d68f80dbab 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -719,10 +719,18 @@ namespace ts { return [...array1, ...array2]; } + function selectIndex(_: unknown, i: number) { + return i; + } + + export function indicesOf(array: readonly unknown[]): number[] { + return array.map(selectIndex); + } + function deduplicateRelational(array: readonly T[], equalityComparer: EqualityComparer, comparer: Comparer) { // Perform a stable sort of the array. This ensures the first entry in a list of // duplicates remains the first entry in the result. - const indices = array.map((_, i) => i); + const indices = indicesOf(array); stableSortIndices(array, indices, comparer); let last = array[indices[0]]; @@ -1028,7 +1036,7 @@ namespace ts { * Stable sort of an array. Elements equal to each other maintain their relative position in the array. */ export function stableSort(array: readonly T[], comparer: Comparer): SortedReadonlyArray { - const indices = array.map((_, i) => i); + const indices = indicesOf(array); stableSortIndices(array, indices, comparer); return indices.map(i => array[i]) as SortedArray as SortedReadonlyArray; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ce7a7c9488d64..0a221f220ca0d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -685,7 +685,7 @@ namespace ts { return statement; }); const eofToken = factory.createToken(SyntaxKind.EndOfFileToken); - const sourceFile = factory.createSourceFile(statements ?? [], eofToken); + const sourceFile = factory.createSourceFile(statements ?? [], eofToken, NodeFlags.None); sourceFile.fileName = getRelativePathFromDirectory( host.getCurrentDirectory(), getNormalizedAbsolutePath(fileName, buildInfoDirectory), diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 39dee3a7cea7d..6e4743448e6a9 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -199,21 +199,13 @@ namespace ts { updateArrayLiteral: updateArrayLiteralExpression, createObjectLiteral: createObjectLiteralExpression, updateObjectLiteral: updateObjectLiteralExpression, - createPropertyAccess: (expression, name) => { - const node = createPropertyAccessExpression(expression, name); - if (flags & NodeFactoryFlags.NoIndentationOnFreshPropertyAccess) { - setEmitFlags(node, EmitFlags.NoIndentation); - } - return node; - }, + createPropertyAccess: flags & NodeFactoryFlags.NoIndentationOnFreshPropertyAccess ? + (expression, name) => setEmitFlags(createPropertyAccessExpression(expression, name), EmitFlags.NoIndentation) : + createPropertyAccessExpression, updatePropertyAccess: updatePropertyAccessExpression, - createPropertyAccessChain: (expression, questionDotToken, name) => { - const node = createPropertyAccessChain(expression, questionDotToken, name); - if (flags & NodeFactoryFlags.NoIndentationOnFreshPropertyAccess) { - setEmitFlags(node, EmitFlags.NoIndentation); - } - return node; - }, + createPropertyAccessChain: flags & NodeFactoryFlags.NoIndentationOnFreshPropertyAccess ? + (expression, questionDotToken, name) => setEmitFlags(createPropertyAccessChain(expression, questionDotToken, name), EmitFlags.NoIndentation) : + createPropertyAccessChain, updatePropertyAccessChain, createElementAccess: createElementAccessExpression, updateElementAccess: updateElementAccessExpression, @@ -508,6 +500,7 @@ namespace ts { get copyCustomPrologue() { return lazyFactory().copyCustomPrologue; }, get ensureUseStrict() { return lazyFactory().ensureUseStrict; }, get liftToBlock() { return lazyFactory().liftToBlock; }, + get updateModifiers() { return lazyFactory().updateModifiers; }, }; return factory; @@ -543,8 +536,8 @@ namespace ts { return array; } - function createBaseNode(kind: T["kind"]): T { - return createNode(kind) as T; + function createBaseNode(kind: T["kind"]) { + return createNode(kind) as Mutable; } function createBaseDeclaration( @@ -619,7 +612,8 @@ namespace ts { return node; } - function updateBaseSignatureDeclaration(updated: T, original: T) { + function updateBaseSignatureDeclaration(updated: Mutable, original: T) { + // copy children used only for error reporting if (original.typeArguments) updated.typeArguments = original.typeArguments; return update(updated, original); } @@ -650,7 +644,8 @@ namespace ts { return node; } - function updateBaseFunctionLikeDeclaration(updated: T, original: T) { + function updateBaseFunctionLikeDeclaration(updated: Mutable, original: T) { + // copy children used only for error reporting if (original.exclamationToken) updated.exclamationToken = original.exclamationToken; if (original.typeArguments) updated.typeArguments = original.typeArguments; return updateBaseSignatureDeclaration(updated, original); @@ -743,7 +738,7 @@ namespace ts { kind: T["kind"], text: string ) { - const node = createTokenNode(kind) as T; + const node = createBaseToken(kind); node.text = text; node.hasExtendedUnicodeEscape = undefined; node.isUnterminated = undefined; @@ -815,21 +810,21 @@ namespace ts { // Identifiers // - function createBaseIdentifier(text: string, originalKeywordKind: SyntaxKind | undefined): Identifier { + function createBaseIdentifier(text: string, originalKeywordKind: SyntaxKind | undefined) { if (originalKeywordKind === undefined && text) { originalKeywordKind = stringToToken(text); } if (originalKeywordKind === SyntaxKind.Identifier) { originalKeywordKind = undefined; } - const node = createIdentifierNode(SyntaxKind.Identifier) as Identifier; + const node = createIdentifierNode(SyntaxKind.Identifier) as Mutable; node.originalKeywordKind = originalKeywordKind; node.escapedText = escapeLeadingUnderscores(text); return node; } function createBaseGeneratedIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags) { - const node = createBaseIdentifier(text, /*originalKeywordKind*/ undefined) as GeneratedIdentifier; + const node = createBaseIdentifier(text, /*originalKeywordKind*/ undefined) as Mutable; node.autoGenerateFlags = autoGenerateFlags; node.autoGenerateId = nextAutoGenerateId; nextAutoGenerateId++; @@ -902,6 +897,10 @@ namespace ts { // Punctuation // + function createBaseToken(kind: T["kind"]) { + return createTokenNode(kind) as Mutable; + } + // @api function createToken(token: SyntaxKind.SuperKeyword): SuperExpression; function createToken(token: SyntaxKind.ThisKeyword): ThisExpression; @@ -919,7 +918,7 @@ namespace ts { Debug.assert(token <= SyntaxKind.FirstTemplateToken || token >= SyntaxKind.LastTemplateToken, "Invalid token. Use 'createTemplateLiteralLikeNode' to create template literals."); Debug.assert(token <= SyntaxKind.FirstLiteralToken || token >= SyntaxKind.LastLiteralToken, "Invalid token. Use 'createLiteralLikeNode' to create literals."); Debug.assert(token !== SyntaxKind.Identifier, "Invalid token. Use 'createIdentifier' to create identifiers"); - const node = createTokenNode(token) as Token; + const node = createBaseToken>(token); if (!skipTransformationFlags) { switch (token) { case SyntaxKind.AsyncKeyword: @@ -1889,7 +1888,7 @@ namespace ts { } // @api - function createImportTypeNode(argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean) { + function createImportTypeNode(argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf = false) { const node = createBaseNode(SyntaxKind.ImportType); setChild(node, node.argument = argument); setChild(node, node.qualifier = qualifier); @@ -1902,7 +1901,7 @@ namespace ts { } // @api - function updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean) { + function updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf = node.isTypeOf) { return node.argument !== argument || node.qualifier !== qualifier || node.typeArguments !== typeArguments @@ -2676,7 +2675,7 @@ namespace ts { // @api function createTemplateLiteralLikeNode(kind: TemplateLiteralToken["kind"], text: string, rawText: string | undefined) { - const node = createTokenNode(kind) as TemplateLiteralLikeNode; + const node = createBaseToken(kind); node.text = text; node.rawText = rawText; if (!skipTransformationFlags) { @@ -4361,7 +4360,8 @@ namespace ts { return finish(node); } - function finishUpdatePropertyAssignment(updated: PropertyAssignment, original: PropertyAssignment) { + function finishUpdatePropertyAssignment(updated: Mutable, original: PropertyAssignment) { + // copy children used only for error reporting if (original.decorators) updated.decorators = original.decorators; if (original.modifiers) updated.modifiers = original.modifiers; if (original.questionToken) updated.questionToken = original.questionToken; @@ -4394,7 +4394,8 @@ namespace ts { return finish(node); } - function finishUpdateShorthandPropertyAssignment(updated: ShorthandPropertyAssignment, original: ShorthandPropertyAssignment) { + function finishUpdateShorthandPropertyAssignment(updated: Mutable, original: ShorthandPropertyAssignment) { + // copy children used only for error reporting if (original.decorators) updated.decorators = original.decorators; if (original.modifiers) updated.modifiers = original.modifiers; if (original.equalsToken) updated.equalsToken = original.equalsToken; @@ -4460,10 +4461,12 @@ namespace ts { function createSourceFile( statements: readonly Statement[], endOfFileToken: EndOfFileToken, + flags: NodeFlags ) { - const node = createSourceFileNode(SyntaxKind.SourceFile) as SourceFile; + const node = createSourceFileNode(SyntaxKind.SourceFile) as Mutable; setChildren(node, node.statements = createNodeArray(statements)); setChild(node, node.endOfFileToken = endOfFileToken); + node.flags |= flags; node.fileName = ""; node.text = ""; node.languageVersion = 0; @@ -4556,8 +4559,8 @@ namespace ts { return node; } - function createBaseUnparsedNode(kind: T["kind"], data?: string): T { - const node = createBaseNode(kind); + function createBaseUnparsedNode(kind: T["kind"], data?: string) { + const node = createBaseNode(kind); node.data = data; return node; } @@ -4743,12 +4746,14 @@ namespace ts { return node; } - const clone = node.kind === SyntaxKind.SourceFile ? createSourceFileNode(node.kind) as T: + const clone = + node.kind === SyntaxKind.SourceFile ? createSourceFileNode(node.kind) as T: node.kind === SyntaxKind.Identifier ? createIdentifierNode(node.kind) as T: !isNodeKind(node.kind) ? createTokenNode(node.kind) as T: createBaseNode(node.kind) as T; - clone.flags |= node.flags; + (clone as Mutable).flags |= (node.flags & ~NodeFlags.Synthesized); + (clone as Mutable).transformFlags = node.transformFlags; setOriginalNode(clone, node); for (const key in node) { @@ -4792,19 +4797,19 @@ namespace ts { function setChildWorker(parent: Node, child: Node | undefined): void { if (!skipTransformationFlags && child) { - parent.transformFlags |= propagateChildFlags(child); + (parent as Mutable).transformFlags |= propagateChildFlags(child); } } function setChildrenWorker(parent: Node, children: NodeArray | undefined): void { if (!skipTransformationFlags && children) { - parent.transformFlags |= propagateChildrenFlags(children); + (parent as Mutable).transformFlags |= propagateChildrenFlags(children); } } function finishWorker(node: T) { if (!skipTransformationFlags) { - node.transformFlags |= TransformFlags.HasComputedFlags; + (node as Mutable).transformFlags |= TransformFlags.HasComputedFlags; } return node; } @@ -4897,6 +4902,7 @@ namespace ts { copyCustomPrologue, ensureUseStrict, liftToBlock, + updateModifiers, }; function getBinaryFactory(operator: BinaryOperator) { @@ -5445,6 +5451,38 @@ namespace ts { Debug.assert(every(nodes, isStatementOrBlock), "Cannot lift nodes to a Block."); return singleOrUndefined(nodes) || factory.createBlock(nodes); } + + function updateModifiers(node: T, modifiers: readonly Modifier[] | ModifierFlags): T; + function updateModifiers(node: HasModifiers, modifiers: readonly Modifier[] | ModifierFlags) { + if (typeof modifiers === "number") { + modifiers = factory.createModifiersFromModifierFlags(modifiers); + } + + return node.kind === SyntaxKind.Parameter ? factory.updateParameterDeclaration(node, node.decorators, modifiers, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) : + node.kind === SyntaxKind.PropertySignature ? factory.updatePropertySignature(node, modifiers, node.name, node.questionToken, node.type) : + node.kind === SyntaxKind.PropertyDeclaration ? factory.updatePropertyDeclaration(node, node.decorators, modifiers, node.name, node.questionToken ?? node.exclamationToken, node.type, node.initializer) : + node.kind === SyntaxKind.MethodSignature ? factory.updateMethodSignature(node, modifiers, node.name, node.questionToken, node.typeParameters, node.parameters, node.type) : + node.kind === SyntaxKind.MethodDeclaration ? factory.updateMethodDeclaration(node, node.decorators, modifiers, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body) : + node.kind === SyntaxKind.Constructor ? factory.updateConstructorDeclaration(node, node.decorators, modifiers, node.parameters, node.body) : + node.kind === SyntaxKind.GetAccessor ? factory.updateGetAccessorDeclaration(node, node.decorators, modifiers, node.name, node.parameters, node.type, node.body) : + node.kind === SyntaxKind.SetAccessor ? factory.updateSetAccessorDeclaration(node, node.decorators, modifiers, node.name, node.parameters, node.body) : + node.kind === SyntaxKind.IndexSignature ? factory.updateIndexSignature(node, node.decorators, modifiers, node.parameters, node.type!) : + node.kind === SyntaxKind.FunctionExpression ? factory.updateFunctionExpression(node, modifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) : + node.kind === SyntaxKind.ArrowFunction ? factory.updateArrowFunction(node, modifiers, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, node.body) : + node.kind === SyntaxKind.ClassExpression ? factory.updateClassExpression(node, node.decorators, modifiers, node.name, node.typeParameters, node.heritageClauses, node.members) : + node.kind === SyntaxKind.VariableStatement ? factory.updateVariableStatement(node, modifiers, node.declarationList) : + node.kind === SyntaxKind.FunctionDeclaration ? factory.updateFunctionDeclaration(node, node.decorators, modifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) : + node.kind === SyntaxKind.ClassDeclaration ? factory.updateClassDeclaration(node, node.decorators, modifiers, node.name, node.typeParameters, node.heritageClauses, node.members) : + node.kind === SyntaxKind.InterfaceDeclaration ? factory.updateInterfaceDeclaration(node, node.decorators, modifiers, node.name, node.typeParameters, node.heritageClauses, node.members) : + node.kind === SyntaxKind.TypeAliasDeclaration ? factory.updateTypeAliasDeclaration(node, node.decorators, modifiers, node.name, node.typeParameters, node.type) : + node.kind === SyntaxKind.EnumDeclaration ? factory.updateEnumDeclaration(node, node.decorators, modifiers, node.name, node.members) : + node.kind === SyntaxKind.ModuleDeclaration ? factory.updateModuleDeclaration(node, node.decorators, modifiers, node.name, node.body) : + node.kind === SyntaxKind.ImportEqualsDeclaration ? factory.updateImportEqualsDeclaration(node, node.decorators, modifiers, node.name, node.moduleReference) : + node.kind === SyntaxKind.ImportDeclaration ? factory.updateImportDeclaration(node, node.decorators, modifiers, node.importClause, node.moduleSpecifier) : + node.kind === SyntaxKind.ExportAssignment ? factory.updateExportAssignment(node, node.decorators, modifiers, node.expression) : + node.kind === SyntaxKind.ExportDeclaration ? factory.updateExportDeclaration(node, node.decorators, modifiers, node.exportClause, node.moduleSpecifier) : + Debug.assertNever(node); + } } // Language-edition and feature specific node markers @@ -5472,8 +5510,9 @@ namespace ts { const markJsx = createFlagMarker(TransformFlags.ContainsJsx); function createFlagMarker(transformFlags: TransformFlags, excludeSubtree?: boolean) { - return excludeSubtree ? (node: Node) => { node.transformFlags = transformFlags; } : - (node: Node) => { node.transformFlags |= transformFlags; }; + return excludeSubtree ? + (node: Mutable) => { node.transformFlags = transformFlags; } : + (node: Mutable) => { node.transformFlags |= transformFlags; }; } function observeArguments(action: (arg1: U, arg2: U) => U, observer: ((arg1: T, arg2: T) => void) | undefined): (arg1: U, arg2: U) => U; @@ -5649,7 +5688,7 @@ namespace ts { const baseFactory = createBaseNodeFactory(); export const factory = createNodeFactory(NodeFactoryFlags.NoIndentationOnFreshPropertyAccess, baseFactory, { - onCreateNode: node => node.flags |= NodeFlags.Synthesized + onCreateNode: node => (node as Mutable).flags |= NodeFlags.Synthesized }); export function createUnparsedSourceFile(text: string): UnparsedSource; @@ -5976,4 +6015,3 @@ namespace ts { return destRanges; } } - diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index 154ed896d5c13..f0acbf8b22ed9 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -37,7 +37,7 @@ namespace ts { function createJsxFactoryExpressionFromEntityName(factory: NodeFactory, jsxFactory: EntityName, parent: JsxOpeningLikeElement | JsxOpeningFragment): Expression { if (isQualifiedName(jsxFactory)) { const left = createJsxFactoryExpressionFromEntityName(factory, jsxFactory.left, parent); - const right = factory.createIdentifier(idText(jsxFactory.right)); + const right = factory.createIdentifier(idText(jsxFactory.right)) as Mutable; right.escapedText = jsxFactory.right.escapedText; return factory.createPropertyAccess(left, right); } @@ -780,4 +780,31 @@ namespace ts { return name.properties; } } + + export function canHaveModifiers(node: Node): node is HasModifiers { + const kind = node.kind; + return kind === SyntaxKind.Parameter + || kind === SyntaxKind.PropertySignature + || kind === SyntaxKind.PropertyDeclaration + || kind === SyntaxKind.MethodSignature + || kind === SyntaxKind.MethodDeclaration + || kind === SyntaxKind.Constructor + || kind === SyntaxKind.GetAccessor + || kind === SyntaxKind.SetAccessor + || kind === SyntaxKind.IndexSignature + || kind === SyntaxKind.FunctionExpression + || kind === SyntaxKind.ArrowFunction + || kind === SyntaxKind.ClassExpression + || kind === SyntaxKind.VariableStatement + || kind === SyntaxKind.FunctionDeclaration + || kind === SyntaxKind.ClassDeclaration + || kind === SyntaxKind.InterfaceDeclaration + || kind === SyntaxKind.TypeAliasDeclaration + || kind === SyntaxKind.EnumDeclaration + || kind === SyntaxKind.ModuleDeclaration + || kind === SyntaxKind.ImportEqualsDeclaration + || kind === SyntaxKind.ImportDeclaration + || kind === SyntaxKind.ExportAssignment + || kind === SyntaxKind.ExportDeclaration; + } } \ No newline at end of file diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 136dd8c07733f..92b71adb1e70e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -568,7 +568,7 @@ namespace ts { const newSourceFile = IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); // Because new source file node is created, it may not have the flag PossiblyContainDynamicImport. This is the case if there is no new edit to add dynamic import. // We will manually port the flag to the new source file. - newSourceFile.flags |= (sourceFile.flags & NodeFlags.PermanentlySetIncrementalFlags); + (newSourceFile as Mutable).flags |= (sourceFile.flags & NodeFlags.PermanentlySetIncrementalFlags); return newSourceFile; } @@ -824,8 +824,7 @@ namespace ts { } // Set source file so that errors will be reported with this file name - const sourceFile = createSourceFile(fileName, ScriptTarget.ES2015, ScriptKind.JSON, /*isDeclaration*/ false, statements, endOfFileToken); - sourceFile.flags |= sourceFlags; + const sourceFile = createSourceFile(fileName, ScriptTarget.ES2015, ScriptKind.JSON, /*isDeclaration*/ false, statements, endOfFileToken, sourceFlags); if (setParentNodes) { fixupParentReferences(sourceFile); @@ -923,8 +922,7 @@ namespace ts { Debug.assert(token() === SyntaxKind.EndOfFileToken); const endOfFileToken = addJSDocComment(parseTokenNode()); - const sourceFile = createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken); - sourceFile.flags |= sourceFlags; + const sourceFile = createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, sourceFlags); // A member of ReadonlyArray isn't assignable to a member of T[] (and prevents a direct cast) - but this is where we set up those members so they can be readonly in the future processCommentPragmas(sourceFile as {} as PragmaContext, sourceText); @@ -994,10 +992,10 @@ namespace ts { } } - function createSourceFile(fileName: string, languageVersion: ScriptTarget, scriptKind: ScriptKind, isDeclarationFile: boolean, statements: readonly Statement[], endOfFileToken: EndOfFileToken): SourceFile { + function createSourceFile(fileName: string, languageVersion: ScriptTarget, scriptKind: ScriptKind, isDeclarationFile: boolean, statements: readonly Statement[], endOfFileToken: EndOfFileToken, flags: NodeFlags): SourceFile { // code from createNode is inlined here so createNode won't have to deal with special case of creating source files // this is quite rare comparing to other nodes and createNode should be as fast as possible - const sourceFile = factory.createSourceFile(statements, endOfFileToken); + const sourceFile = factory.createSourceFile(statements, endOfFileToken, flags); sourceFile.pos = 0; sourceFile.end = sourceText.length; sourceFile.text = sourceText; @@ -1411,7 +1409,7 @@ namespace ts { node.end = end === undefined ? scanner.getStartPos() : end; if (contextFlags) { - node.flags |= contextFlags; + (node as Mutable).flags |= contextFlags; } // Keep track on the node if we encountered an error while parsing it. If we did, then @@ -1419,7 +1417,7 @@ namespace ts { // flag so that we don't mark any subsequent nodes. if (parseErrorBeforeNextFinishedNode) { parseErrorBeforeNextFinishedNode = false; - node.flags |= NodeFlags.ThisNodeHasError; + (node as Mutable).flags |= NodeFlags.ThisNodeHasError; } return node; @@ -3040,7 +3038,7 @@ namespace ts { const node = factory.createOptionalTypeNode(type.type); node.pos = type.pos; node.end = type.end; - node.flags = type.flags; + (node as Mutable).flags = type.flags; return node; } return type; @@ -4783,7 +4781,7 @@ namespace ts { parseTemplateExpression() ); if (questionDotToken || tag.flags & NodeFlags.OptionalChain) { - tagExpression.flags |= NodeFlags.OptionalChain; + (tagExpression as Mutable).flags |= NodeFlags.OptionalChain; } factory.trackExtraneousChildNode(tagExpression, tagExpression.questionDotToken = questionDotToken); return finishNode(tagExpression, pos); @@ -5019,7 +5017,7 @@ namespace ts { // CoverInitializedName[Yield] : // IdentifierReference[?Yield] Initializer[In, ?Yield] // this is necessary because ObjectLiteral productions are also used to cover grammar for ObjectAssignmentPattern - let node: ShorthandPropertyAssignment | PropertyAssignment; + let node: Mutable; const isShorthandPropertyAssignment = tokenIsIdentifier && (token() !== SyntaxKind.ColonToken); if (isShorthandPropertyAssignment) { const equalsToken = parseOptionalToken(SyntaxKind.EqualsToken); @@ -5323,13 +5321,15 @@ namespace ts { // ThrowStatement[Yield] : // throw [no LineTerminator here]Expression[In, ?Yield]; + const pos = getNodePos(); + parseExpected(SyntaxKind.ThrowKeyword); + // Because of automatic semicolon insertion, we need to report error if this // throw could be terminated with a semicolon. Note: we can't call 'parseExpression' // directly as that might consume an expression on the following line. // We just return 'undefined' in that case. The actual error will be reported in the // grammar walker. - const pos = getNodePos(); - parseExpected(SyntaxKind.ThrowKeyword); + // TODO(rbuckton): Should we use `createMissingNode` here instead? const expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression); parseSemicolon(); return finishNode(factory.createThrow(expression!), pos); @@ -5667,7 +5667,7 @@ namespace ts { const modifiers = parseModifiers(); if (isAmbient) { for (const m of modifiers!) { - m.flags |= NodeFlags.Ambient; + (m as Mutable).flags |= NodeFlags.Ambient; } return doInsideOfContext(NodeFlags.Ambient, () => parseDeclarationWorker(pos, hasJSDoc, decorators, modifiers)); } @@ -5722,7 +5722,7 @@ namespace ts { if (decorators || modifiers) { // We reached this point because we encountered decorators and/or modifiers and assumed a declaration // would follow. For recovery and error reporting purposes, return an incomplete declaration. - const missing = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); + const missing = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); missing.pos = pos; missing.decorators = decorators; missing.modifiers = modifiers; @@ -6004,7 +6004,7 @@ namespace ts { : factory.createSetAccessorDeclaration(decorators, modifiers, name, parameters, body); // Keep track of `typeParameters` (for both) and `type` (for setters) if they were parsed those indicate grammar errors if (typeParameters) factory.trackExtraneousChildNodes(node, node.typeParameters = typeParameters); - if (type && kind === SyntaxKind.SetAccessor) factory.trackExtraneousChildNode(node, node.type = type); + if (type && node.kind === SyntaxKind.SetAccessor) factory.trackExtraneousChildNode(node, node.type = type); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6182,7 +6182,7 @@ namespace ts { const isAmbient = some(modifiers, isDeclareModifier); if (isAmbient) { for (const m of modifiers!) { - m.flags |= NodeFlags.Ambient; + (m as Mutable).flags |= NodeFlags.Ambient; } return doInsideOfContext(NodeFlags.Ambient, () => parsePropertyOrMethodDeclaration(pos, hasJSDoc, decorators, modifiers)); } @@ -6690,7 +6690,7 @@ namespace ts { currentToken = scanner.scan(); const jsDocTypeExpression = parseJSDocTypeExpression(); - const sourceFile = createSourceFile("file.js", ScriptTarget.Latest, ScriptKind.JS, /*isDeclarationFile*/ false, [], factory.createToken(SyntaxKind.EndOfFileToken)); + const sourceFile = createSourceFile("file.js", ScriptTarget.Latest, ScriptKind.JS, /*isDeclarationFile*/ false, [], factory.createToken(SyntaxKind.EndOfFileToken), NodeFlags.None); const diagnostics = attachFileToDiagnostics(parseDiagnostics, sourceFile); if (jsDocDiagnostics) { sourceFile.jsDocDiagnostics = attachFileToDiagnostics(jsDocDiagnostics, sourceFile); diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 2378297d71aa6..fcd945e7b5927 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -285,7 +285,7 @@ namespace ts { factory.createConstructorDeclaration( /*decorators*/ undefined, /*modifiers*/ undefined, - parameters, + parameters ?? [], body ), constructor || node @@ -423,7 +423,7 @@ namespace ts { ? factory.updateComputedPropertyName(property.name, factory.getGeneratedNameForNode(property.name)) : property.name; - const initializer = property.initializer || emitAssignment ? visitNode(property.initializer, visitor, isExpression) : factory.createVoidZero(); + const initializer = visitNode(property.initializer, visitor, isExpression) ?? factory.createVoidZero(); if (emitAssignment) { const memberAccess = createMemberAccessForPropertyName(factory, receiver, propertyName, /*location*/ propertyName); return factory.createAssignment(memberAccess, initializer); diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 12e619cf613dd..13cfc21db5154 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -1050,16 +1050,14 @@ namespace ts { } function stripExportModifiers(statement: Statement): Statement { - if (isImportEqualsDeclaration(statement) || hasModifier(statement, ModifierFlags.Default)) { + if (isImportEqualsDeclaration(statement) || hasModifier(statement, ModifierFlags.Default) || !canHaveModifiers(statement)) { // `export import` statements should remain as-is, as imports are _not_ implicitly exported in an ambient namespace // Likewise, `export default` classes and the like and just be `default`, so we preserve their `export` modifiers, too return statement; } - // TODO(rbuckton): Does this need to be parented? - const clone = setParent(setTextRange(factory.cloneNode(statement), statement), statement.parent); + const modifiers = factory.createModifiersFromModifierFlags(getModifierFlags(statement) & (ModifierFlags.All ^ ModifierFlags.Export)); - clone.modifiers = modifiers.length ? factory.createNodeArray(modifiers) : undefined; - return clone; + return factory.updateModifiers(statement, modifiers); } function transformTopLevelDeclaration(input: LateVisibilityPaintedStatement) { @@ -1126,8 +1124,8 @@ namespace ts { )); if (clean && resolver.isExpandoFunctionDeclaration(input)) { const props = resolver.getPropertiesOfContainerFunction(input); - const fakespace = factory.createModuleDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, clean.name || factory.createIdentifier("_default"), factory.createModuleBlock([]), NodeFlags.Namespace); - fakespace.flags ^= NodeFlags.Synthesized; // unset synthesized so it is usable as an enclosing declaration + // Use parseNodeFactory so it is usable as an enclosing declaration + const fakespace = parseNodeFactory.createModuleDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, clean.name || factory.createIdentifier("_default"), factory.createModuleBlock([]), NodeFlags.Namespace); fakespace.parent = enclosingDeclaration as SourceFile | NamespaceDeclaration; fakespace.locals = createSymbolTable(props); fakespace.symbol = props[0].parent!; diff --git a/src/compiler/transformers/destructuring.ts b/src/compiler/transformers/destructuring.ts index 367dec7662951..ba288c777b63c 100644 --- a/src/compiler/transformers/destructuring.ts +++ b/src/compiler/transformers/destructuring.ts @@ -467,7 +467,6 @@ namespace ts { } else if (isStringOrNumericLiteralLike(propertyName)) { const argumentExpression = factory.cloneNode(propertyName); - argumentExpression.text = argumentExpression.text; return flattenContext.context.factory.createElementAccess(value, argumentExpression); } else { diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index ca6557c553e36..72e3466ef9fe7 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -3085,11 +3085,19 @@ namespace ts { // we only evaluate the incrementor on subsequent evaluations. currentState.conditionVariable = factory.createUniqueName("inc"); - statements.push(factory.createIf( - currentState.conditionVariable, - factory.createExpressionStatement(visitNode(node.incrementor, visitor, isExpression)), - factory.createExpressionStatement(factory.createAssignment(currentState.conditionVariable, factory.createTrue())) - )); + if (node.incrementor) { + statements.push(factory.createIf( + currentState.conditionVariable, + factory.createExpressionStatement(visitNode(node.incrementor, visitor, isExpression)), + factory.createExpressionStatement(factory.createAssignment(currentState.conditionVariable, factory.createTrue())) + )); + } + else { + statements.push(factory.createIf( + factory.createLogicalNot(currentState.conditionVariable), + factory.createExpressionStatement(factory.createAssignment(currentState.conditionVariable, factory.createTrue())) + )); + } if (shouldConvertConditionOfForStatement(node)) { statements.push(factory.createIf( diff --git a/src/compiler/transformers/es2018.ts b/src/compiler/transformers/es2018.ts index 6702fbe719447..48e8fd294f2e4 100644 --- a/src/compiler/transformers/es2018.ts +++ b/src/compiler/transformers/es2018.ts @@ -163,7 +163,7 @@ namespace ts { function visitYieldExpression(node: YieldExpression) { if (enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator) { if (node.asteriskToken) { - const expression = visitNode(node.expression, visitor, isExpression); + const expression = visitNode(Debug.assertDefined(node.expression), visitor, isExpression); return setOriginalNode( setTextRange( @@ -822,7 +822,7 @@ namespace ts { resumeLexicalEnvironment(); let statementOffset = 0; const statements: Statement[] = []; - const body = visitNode(node.body, visitor, isConciseBody); + const body = visitNode(node.body, visitor, isConciseBody) ?? factory.createBlock([]); if (isBlock(body)) { statementOffset = factory.copyPrologue(body.statements, statements, /*ensureUseStrict*/ false, visitor); } diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index dd4fb33db72b4..57ef46595129d 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -265,7 +265,7 @@ namespace ts { // allocating objects to store the same information to avoid GC overhead. // let labelOffsets: number[] | undefined; // The operation offset at which the label is defined. - let labelExpressions: LiteralExpression[][] | undefined; // The NumericLiteral nodes bound to each label. + let labelExpressions: Mutable[][] | undefined; // The NumericLiteral nodes bound to each label. let nextLabelId = 1; // The next label id to use. // Operations store information about generated code for the function body. This @@ -939,8 +939,9 @@ namespace ts { const resumeLabel = defineLabel(); const expression = visitNode(node.expression, visitor, isExpression); if (node.asteriskToken) { + // NOTE: `expression` must be defined for `yield*`. const iterator = (getEmitFlags(node.expression!) & EmitFlags.Iterator) === 0 - ? setTextRange(emitHelpers().createValuesHelper(expression), node) + ? setTextRange(emitHelpers().createValuesHelper(expression!), node) : expression; emitYieldStar(iterator, /*location*/ node); } @@ -1282,7 +1283,7 @@ namespace ts { return undefined; } - function transformInitializedVariable(node: VariableDeclaration) { + function transformInitializedVariable(node: InitializedVariableDeclaration) { return setSourceMapRange( factory.createAssignment( setSourceMapRange(factory.cloneNode(node.name), node.name), @@ -1870,8 +1871,9 @@ namespace ts { } function transformAndEmitThrowStatement(node: ThrowStatement): void { + // TODO(rbuckton): `expression` should be required on `throw`. emitThrow( - visitNode(node.expression, visitor, isExpression), + visitNode(node.expression ?? factory.createVoidZero(), visitor, isExpression), /*location*/ node ); } diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index ff31b29bb369e..c266c7ae51a9d 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -180,7 +180,7 @@ namespace ts { if (node.expression === undefined) { return factory.createTrue(); } - return visitJsxExpression(node); + return visitNode(node.expression, visitor, isExpression); } else { return Debug.failBadSyntaxKind(node); diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 33fa62ebfcc11..7f4b4720b718f 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -607,7 +607,7 @@ namespace ts { case ModuleKind.AMD: return createImportCallExpressionAMD(argument, containsLexicalThis); case ModuleKind.UMD: - return createImportCallExpressionUMD(argument, containsLexicalThis); + return createImportCallExpressionUMD(argument ?? factory.createVoidZero(), containsLexicalThis); case ModuleKind.CommonJS: default: return createImportCallExpressionCommonJS(argument, containsLexicalThis); @@ -1166,7 +1166,7 @@ namespace ts { variables = append(variables, variable); } else if (variable.initializer) { - expressions = append(expressions, transformInitializedVariable(variable)); + expressions = append(expressions, transformInitializedVariable(variable as InitializedVariableDeclaration)); } } @@ -1215,7 +1215,7 @@ namespace ts { * * @param node The node to transform. */ - function transformInitializedVariable(node: VariableDeclaration): Expression { + function transformInitializedVariable(node: InitializedVariableDeclaration): Expression { if (isBindingPattern(node.name)) { return flattenDestructuringAssignment( visitNode(node, moduleExpressionElementVisitor), diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index cae2cba07be1c..c2e6025739f32 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -1737,12 +1737,9 @@ namespace ts { case SyntaxKind.Identifier: // Create a clone of the name with a new parent, and treat it as if it were // a source tree node for the purposes of the checker. - // TODO(rbuckton): Does this need to be parented? - const name = setParent(setTextRange(factory.cloneNode(node), node), node.parent); - name.flags &= ~NodeFlags.Synthesized; + const name = setParent(setTextRange(parseNodeFactory.cloneNode(node), node), node.parent); name.original = undefined; name.parent = getParseTreeNode(currentLexicalScope)!; // ensure the parent is set to a parse tree node. - return name; case SyntaxKind.QualifiedName: @@ -2174,7 +2171,7 @@ namespace ts { } } - function transformInitializedVariable(node: VariableDeclaration): Expression { + function transformInitializedVariable(node: InitializedVariableDeclaration): Expression { const name = node.name; if (isBindingPattern(name)) { return flattenDestructuringAssignment( diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index 70caf79c7f451..8e1e62e627ce4 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -285,6 +285,8 @@ namespace ts { * @param node The class node. * @param isStatic A value indicating whether to get properties from the static or instance side of the class. */ + export function getProperties(node: ClassExpression | ClassDeclaration, requireInitializer: true, isStatic: boolean): readonly InitializedPropertyDeclaration[]; + export function getProperties(node: ClassExpression | ClassDeclaration, requireInitializer: boolean, isStatic: boolean): readonly PropertyDeclaration[]; export function getProperties(node: ClassExpression | ClassDeclaration, requireInitializer: boolean, isStatic: boolean): readonly PropertyDeclaration[] { return filter(node.members, m => isInitializedOrStaticProperty(m, requireInitializer, isStatic)) as PropertyDeclaration[]; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4facdfa017c49..3816aed3b9d30 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -797,12 +797,12 @@ namespace ts { } export interface Node extends TextRange { - kind: SyntaxKind; - flags: NodeFlags; + readonly kind: SyntaxKind; + readonly flags: NodeFlags; /* @internal */ modifierFlagsCache: ModifierFlags; - /* @internal */ transformFlags: TransformFlags; // Flags for transforms, possibly undefined - decorators?: NodeArray; // Array of decorators (in document order) - modifiers?: ModifiersArray; // Array of modifiers + /* @internal */ readonly transformFlags: TransformFlags; // Flags for transforms + readonly decorators?: NodeArray; // Array of decorators (in document order) + readonly modifiers?: ModifiersArray; // Array of modifiers /* @internal */ id?: number; // Unique id (used to look up NodeLinks) parent: Node; // Parent node (initialized by binding) /* @internal */ original?: Node; // The original node if this is an updated node. @@ -818,7 +818,7 @@ namespace ts { export interface JSDocContainer { /* @internal */ jsDoc?: JSDoc[]; // JSDoc that directly precedes this node - /* @internal */ jsDocCache?: readonly JSDocTag[]; // Cache for getJSDocTags + /* @internal */ jsDocCache?: readonly JSDocTag[]; // Cache for getJSDocTags } export type HasJSDoc = @@ -896,6 +896,34 @@ namespace ts { | EnumMember ; + // NOTE: Changing this list requires changes to `canHaveModifiers` in factory/utilities.ts and `updateModifiers` in factory/nodeFactory.ts + /* @internal */ + export type HasModifiers = + | ParameterDeclaration + | PropertySignature + | PropertyDeclaration + | MethodSignature + | MethodDeclaration + | ConstructorDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration + | IndexSignatureDeclaration + | FunctionExpression + | ArrowFunction + | ClassExpression + | VariableStatement + | FunctionDeclaration + | ClassDeclaration + | InterfaceDeclaration + | TypeAliasDeclaration + | EnumDeclaration + | ModuleDeclaration + | ImportEqualsDeclaration + | ImportDeclaration + | ExportAssignment + | ExportDeclaration + ; + /* @internal */ export type MutableNodeArray = NodeArray & T[]; @@ -906,7 +934,7 @@ namespace ts { // TODO(rbuckton): Constraint 'TKind' to 'TokenSyntaxKind' export interface Token extends Node { - kind: TKind; + readonly kind: TKind; } export type EndOfFileToken = Token & JSDocContainer; @@ -1008,15 +1036,15 @@ namespace ts { } export interface Identifier extends PrimaryExpression, Declaration { - kind: SyntaxKind.Identifier; + readonly kind: SyntaxKind.Identifier; /** * Prefer to use `id.unescapedText`. (Note: This is available only in services, not internally to the TypeScript compiler.) * Text of identifier, but if the identifier begins with two underscores, this will begin with three. */ - escapedText: __String; - originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later - /*@internal*/ autoGenerateFlags?: GeneratedIdentifierFlags; // Specifies whether to auto-generate the text for an identifier. - /*@internal*/ autoGenerateId?: number; // Ensures unique generated identifiers get unique names, but clones get the same name. + readonly escapedText: __String; + readonly originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later + /*@internal*/ readonly autoGenerateFlags?: GeneratedIdentifierFlags; // Specifies whether to auto-generate the text for an identifier. + /*@internal*/ readonly autoGenerateId?: number; // Ensures unique generated identifiers get unique names, but clones get the same name. isInJSDocNamespace?: boolean; // if the node is a member in a JSDoc namespace /*@internal*/ typeArguments?: NodeArray; // Only defined on synthesized nodes. Though not syntactically valid, used in emitting diagnostics, quickinfo, and signature help. /*@internal*/ jsdocDotPos?: number; // Identifier occurs in JSDoc-style generic: Id. @@ -1033,9 +1061,9 @@ namespace ts { } export interface QualifiedName extends Node { - kind: SyntaxKind.QualifiedName; - left: EntityName; - right: Identifier; + readonly kind: SyntaxKind.QualifiedName; + readonly left: EntityName; + readonly right: Identifier; /*@internal*/ jsdocDotPos?: number; // QualifiedName occurs in JSDoc-style generic: Id1.Id2. } @@ -1057,75 +1085,75 @@ namespace ts { } export interface NamedDeclaration extends Declaration { - name?: DeclarationName; + readonly name?: DeclarationName; } /* @internal */ export interface DynamicNamedDeclaration extends NamedDeclaration { - name: ComputedPropertyName; + readonly name: ComputedPropertyName; } /* @internal */ export interface DynamicNamedBinaryExpression extends BinaryExpression { - left: ElementAccessExpression; + readonly left: ElementAccessExpression; } /* @internal */ // A declaration that supports late-binding (used in checker) export interface LateBoundDeclaration extends DynamicNamedDeclaration { - name: LateBoundName; + readonly name: LateBoundName; } /* @internal */ export interface LateBoundBinaryExpressionDeclaration extends DynamicNamedBinaryExpression { - left: LateBoundElementAccessExpression; + readonly left: LateBoundElementAccessExpression; } /* @internal */ export interface LateBoundElementAccessExpression extends ElementAccessExpression { - argumentExpression: EntityNameExpression; + readonly argumentExpression: EntityNameExpression; } export interface DeclarationStatement extends NamedDeclaration, Statement { - name?: Identifier | StringLiteral | NumericLiteral; + readonly name?: Identifier | StringLiteral | NumericLiteral; } export interface ComputedPropertyName extends Node { parent: Declaration; - kind: SyntaxKind.ComputedPropertyName; - expression: Expression; + readonly kind: SyntaxKind.ComputedPropertyName; + readonly expression: Expression; } /* @internal */ // A name that supports late-binding (used in checker) export interface LateBoundName extends ComputedPropertyName { - expression: EntityNameExpression; + readonly expression: EntityNameExpression; } export interface Decorator extends Node { - kind: SyntaxKind.Decorator; - parent: NamedDeclaration; - expression: LeftHandSideExpression; + readonly kind: SyntaxKind.Decorator; + readonly parent: NamedDeclaration; + readonly expression: LeftHandSideExpression; } export interface TypeParameterDeclaration extends NamedDeclaration { - kind: SyntaxKind.TypeParameter; - parent: DeclarationWithTypeParameterChildren | InferTypeNode; - name: Identifier; + readonly kind: SyntaxKind.TypeParameter; + readonly parent: DeclarationWithTypeParameterChildren | InferTypeNode; + readonly name: Identifier; /** Note: Consider calling `getEffectiveConstraintOfTypeParameter` */ - constraint?: TypeNode; - default?: TypeNode; + readonly constraint?: TypeNode; + readonly default?: TypeNode; // For error recovery purposes. expression?: Expression; } export interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { - kind: SignatureDeclaration["kind"]; - name?: PropertyName; - typeParameters?: NodeArray; - parameters: NodeArray; - type?: TypeNode; + readonly kind: SignatureDeclaration["kind"]; + readonly name?: PropertyName; + readonly typeParameters?: NodeArray; + readonly parameters: NodeArray; + readonly type?: TypeNode; /* @internal */ typeArguments?: NodeArray; // Used for quick info, replaces typeParameters for instantiated signatures } @@ -1145,73 +1173,79 @@ namespace ts { | ArrowFunction; export interface CallSignatureDeclaration extends SignatureDeclarationBase, TypeElement { - kind: SyntaxKind.CallSignature; + readonly kind: SyntaxKind.CallSignature; } export interface ConstructSignatureDeclaration extends SignatureDeclarationBase, TypeElement { - kind: SyntaxKind.ConstructSignature; + readonly kind: SyntaxKind.ConstructSignature; } export type BindingName = Identifier | BindingPattern; export interface VariableDeclaration extends NamedDeclaration { - kind: SyntaxKind.VariableDeclaration; - parent: VariableDeclarationList | CatchClause; - name: BindingName; // Declared variable name - exclamationToken?: ExclamationToken; // Optional definite assignment assertion - type?: TypeNode; // Optional type annotation - initializer?: Expression; // Optional initializer + readonly kind: SyntaxKind.VariableDeclaration; + readonly parent: VariableDeclarationList | CatchClause; + readonly name: BindingName; // Declared variable name + readonly exclamationToken?: ExclamationToken; // Optional definite assignment assertion + readonly type?: TypeNode; // Optional type annotation + readonly initializer?: Expression; // Optional initializer } + /* @internal */ + export type InitializedVariableDeclaration = VariableDeclaration & { readonly initializer: Expression }; + export interface VariableDeclarationList extends Node { - kind: SyntaxKind.VariableDeclarationList; - parent: VariableStatement | ForStatement | ForOfStatement | ForInStatement; - declarations: NodeArray; + readonly kind: SyntaxKind.VariableDeclarationList; + readonly parent: VariableStatement | ForStatement | ForOfStatement | ForInStatement; + readonly declarations: NodeArray; } export interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { - kind: SyntaxKind.Parameter; - parent: SignatureDeclaration; - dotDotDotToken?: DotDotDotToken; // Present on rest parameter - name: BindingName; // Declared parameter name. - questionToken?: QuestionToken; // Present on optional parameter - type?: TypeNode; // Optional type annotation - initializer?: Expression; // Optional initializer + readonly kind: SyntaxKind.Parameter; + readonly parent: SignatureDeclaration; + readonly dotDotDotToken?: DotDotDotToken; // Present on rest parameter + readonly name: BindingName; // Declared parameter name. + readonly questionToken?: QuestionToken; // Present on optional parameter + readonly type?: TypeNode; // Optional type annotation + readonly initializer?: Expression; // Optional initializer } export interface BindingElement extends NamedDeclaration { - kind: SyntaxKind.BindingElement; - parent: BindingPattern; - propertyName?: PropertyName; // Binding property name (in object binding pattern) - dotDotDotToken?: DotDotDotToken; // Present on rest element (in object binding pattern) - name: BindingName; // Declared binding element name - initializer?: Expression; // Optional initializer + readonly kind: SyntaxKind.BindingElement; + readonly parent: BindingPattern; + readonly propertyName?: PropertyName; // Binding property name (in object binding pattern) + readonly dotDotDotToken?: DotDotDotToken; // Present on rest element (in object binding pattern) + readonly name: BindingName; // Declared binding element name + readonly initializer?: Expression; // Optional initializer } /*@internal*/ export type BindingElementGrandparent = BindingElement["parent"]["parent"]; export interface PropertySignature extends TypeElement, JSDocContainer { - kind: SyntaxKind.PropertySignature; - name: PropertyName; // Declared property name - questionToken?: QuestionToken; // Present on optional property - type?: TypeNode; // Optional type annotation - initializer?: Expression; // Optional initializer + readonly kind: SyntaxKind.PropertySignature; + readonly name: PropertyName; // Declared property name + readonly questionToken?: QuestionToken; // Present on optional property + readonly type?: TypeNode; // Optional type annotation + initializer?: Expression; // Present for use with reporting a grammar error } export interface PropertyDeclaration extends ClassElement, JSDocContainer { - kind: SyntaxKind.PropertyDeclaration; - parent: ClassLikeDeclaration; - name: PropertyName; - questionToken?: QuestionToken; // Present for use with reporting a grammar error - exclamationToken?: ExclamationToken; - type?: TypeNode; - initializer?: Expression; // Optional initializer + readonly kind: SyntaxKind.PropertyDeclaration; + readonly parent: ClassLikeDeclaration; + readonly name: PropertyName; + readonly questionToken?: QuestionToken; // Present for use with reporting a grammar error + readonly exclamationToken?: ExclamationToken; + readonly type?: TypeNode; + readonly initializer?: Expression; // Optional initializer } + /* @internal */ + export type InitializedPropertyDeclaration = PropertyDeclaration & { readonly initializer: Expression }; + export interface ObjectLiteralElement extends NamedDeclaration { _objectLiteralBrand: any; - name?: PropertyName; + readonly name?: PropertyName; } /** Unlike ObjectLiteralElement, excludes JSXAttribute and JSXSpreadAttribute. */ @@ -1225,29 +1259,29 @@ namespace ts { export interface PropertyAssignment extends ObjectLiteralElement, JSDocContainer { parent: ObjectLiteralExpression; - kind: SyntaxKind.PropertyAssignment; - name: PropertyName; - questionToken?: QuestionToken; // Present for use with reporting a grammar error - exclamationToken?: ExclamationToken; // Present for use with reporting a grammar error - initializer: Expression; + readonly kind: SyntaxKind.PropertyAssignment; + readonly name: PropertyName; + readonly questionToken?: QuestionToken; // Present for use with reporting a grammar error + readonly exclamationToken?: ExclamationToken; // Present for use with reporting a grammar error + readonly initializer: Expression; } export interface ShorthandPropertyAssignment extends ObjectLiteralElement, JSDocContainer { parent: ObjectLiteralExpression; - kind: SyntaxKind.ShorthandPropertyAssignment; - name: Identifier; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; + readonly kind: SyntaxKind.ShorthandPropertyAssignment; + readonly name: Identifier; + readonly questionToken?: QuestionToken; + readonly exclamationToken?: ExclamationToken; // used when ObjectLiteralExpression is used in ObjectAssignmentPattern - // it is grammar error to appear in actual object initializer - equalsToken?: Token; - objectAssignmentInitializer?: Expression; + // it is a grammar error to appear in actual object initializer: + readonly equalsToken?: EqualsToken; + readonly objectAssignmentInitializer?: Expression; } export interface SpreadAssignment extends ObjectLiteralElement, JSDocContainer { parent: ObjectLiteralExpression; - kind: SyntaxKind.SpreadAssignment; - expression: Expression; + readonly kind: SyntaxKind.SpreadAssignment; + readonly expression: Expression; } export type VariableLikeDeclaration = @@ -1264,19 +1298,19 @@ namespace ts { | JSDocParameterTag; export interface PropertyLikeDeclaration extends NamedDeclaration { - name: PropertyName; + readonly name: PropertyName; } export interface ObjectBindingPattern extends Node { - kind: SyntaxKind.ObjectBindingPattern; parent: VariableDeclaration | ParameterDeclaration | BindingElement; - elements: NodeArray; + readonly kind: SyntaxKind.ObjectBindingPattern; + readonly elements: NodeArray; } export interface ArrayBindingPattern extends Node { - kind: SyntaxKind.ArrayBindingPattern; parent: VariableDeclaration | ParameterDeclaration | BindingElement; - elements: NodeArray; + readonly kind: SyntaxKind.ArrayBindingPattern; + readonly elements: NodeArray; } export type BindingPattern = ObjectBindingPattern | ArrayBindingPattern; @@ -1294,10 +1328,10 @@ namespace ts { export interface FunctionLikeDeclarationBase extends SignatureDeclarationBase { _functionLikeDeclarationBrand: any; - asteriskToken?: AsteriskToken; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; - body?: Block | Expression; + readonly asteriskToken?: AsteriskToken; + readonly questionToken?: QuestionToken; + readonly exclamationToken?: ExclamationToken; + readonly body?: Block | Expression; /* @internal */ endFlowNode?: FlowNode; } @@ -1313,15 +1347,15 @@ namespace ts { export type FunctionLike = SignatureDeclaration; export interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement { - kind: SyntaxKind.FunctionDeclaration; - name?: Identifier; - body?: FunctionBody; + readonly kind: SyntaxKind.FunctionDeclaration; + readonly name?: Identifier; + readonly body?: FunctionBody; } export interface MethodSignature extends SignatureDeclarationBase, TypeElement { - kind: SyntaxKind.MethodSignature; parent: ObjectTypeDeclaration; - name: PropertyName; + readonly kind: SyntaxKind.MethodSignature; + readonly name: PropertyName; } // Note that a MethodDeclaration is considered both a ClassElement and an ObjectLiteralElement. @@ -1334,48 +1368,55 @@ namespace ts { // at later stages of the compiler pipeline. In that case, you can either check the parent kind // of the method, or use helpers like isObjectLiteralMethodDeclaration export interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { - kind: SyntaxKind.MethodDeclaration; parent: ClassLikeDeclaration | ObjectLiteralExpression; - name: PropertyName; - body?: FunctionBody; + readonly kind: SyntaxKind.MethodDeclaration; + readonly name: PropertyName; + readonly body?: FunctionBody; + /* @internal*/ exclamationToken?: ExclamationToken; // Present for use with reporting a grammar error } export interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElement, JSDocContainer { - kind: SyntaxKind.Constructor; parent: ClassLikeDeclaration; - body?: FunctionBody; + readonly kind: SyntaxKind.Constructor; + readonly body?: FunctionBody; /* @internal */ returnFlowNode?: FlowNode; + /* @internal */ typeParameters?: NodeArray; // Present for use with reporting a grammar error + /* @internal */ type?: TypeNode; // Present for use with reporting a grammar error } /** For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. */ export interface SemicolonClassElement extends ClassElement { - kind: SyntaxKind.SemicolonClassElement; parent: ClassLikeDeclaration; + readonly kind: SyntaxKind.SemicolonClassElement; } // See the comment on MethodDeclaration for the intuition behind GetAccessorDeclaration being a // ClassElement and an ObjectLiteralElement. export interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { - kind: SyntaxKind.GetAccessor; parent: ClassLikeDeclaration | ObjectLiteralExpression; - name: PropertyName; - body?: FunctionBody; + readonly kind: SyntaxKind.GetAccessor; + readonly name: PropertyName; + readonly body?: FunctionBody; + /* @internal */ typeParameters?: NodeArray; // Present for use with reporting a grammar error } // See the comment on MethodDeclaration for the intuition behind SetAccessorDeclaration being a // ClassElement and an ObjectLiteralElement. export interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { - kind: SyntaxKind.SetAccessor; parent: ClassLikeDeclaration | ObjectLiteralExpression; - name: PropertyName; - body?: FunctionBody; + readonly kind: SyntaxKind.SetAccessor; + readonly name: PropertyName; + readonly body?: FunctionBody; + /* @internal */ typeParameters?: NodeArray; // Present for use with reporting a grammar error + /* @internal */ type?: TypeNode; // Present for use with reporting a grammar error } export type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; export interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement { - kind: SyntaxKind.IndexSignature; parent: ObjectTypeDeclaration; + readonly kind: SyntaxKind.IndexSignature; + readonly type: TypeNode; } export interface TypeNode extends Node { @@ -1384,157 +1425,157 @@ namespace ts { /* @internal */ export interface TypeNode extends Node { - kind: TypeNodeSyntaxKind; + readonly kind: TypeNodeSyntaxKind; } export interface KeywordTypeNode extends KeywordToken, TypeNode { - kind: TKind; + readonly kind: TKind; } export interface ImportTypeNode extends NodeWithTypeArguments { - kind: SyntaxKind.ImportType; - isTypeOf?: boolean; - argument: TypeNode; - qualifier?: EntityName; + readonly kind: SyntaxKind.ImportType; + readonly isTypeOf: boolean; + readonly argument: TypeNode; + readonly qualifier?: EntityName; } /* @internal */ - export type LiteralImportTypeNode = ImportTypeNode & { argument: LiteralTypeNode & { literal: StringLiteral } }; + export type LiteralImportTypeNode = ImportTypeNode & { readonly argument: LiteralTypeNode & { readonly literal: StringLiteral } }; export interface ThisTypeNode extends TypeNode { - kind: SyntaxKind.ThisType; + readonly kind: SyntaxKind.ThisType; } export type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; export interface FunctionOrConstructorTypeNodeBase extends TypeNode, SignatureDeclarationBase { - kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType; - type: TypeNode; + readonly kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType; + readonly type: TypeNode; } export interface FunctionTypeNode extends FunctionOrConstructorTypeNodeBase { - kind: SyntaxKind.FunctionType; + readonly kind: SyntaxKind.FunctionType; } export interface ConstructorTypeNode extends FunctionOrConstructorTypeNodeBase { - kind: SyntaxKind.ConstructorType; + readonly kind: SyntaxKind.ConstructorType; } export interface NodeWithTypeArguments extends TypeNode { - typeArguments?: NodeArray; + readonly typeArguments?: NodeArray; } export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; export interface TypeReferenceNode extends NodeWithTypeArguments { - kind: SyntaxKind.TypeReference; - typeName: EntityName; + readonly kind: SyntaxKind.TypeReference; + readonly typeName: EntityName; } export interface TypePredicateNode extends TypeNode { - kind: SyntaxKind.TypePredicate; - parent: SignatureDeclaration | JSDocTypeExpression; - assertsModifier?: AssertsToken; - parameterName: Identifier | ThisTypeNode; - type?: TypeNode; + readonly kind: SyntaxKind.TypePredicate; + readonly parent: SignatureDeclaration | JSDocTypeExpression; + readonly assertsModifier?: AssertsToken; + readonly parameterName: Identifier | ThisTypeNode; + readonly type?: TypeNode; } export interface TypeQueryNode extends TypeNode { - kind: SyntaxKind.TypeQuery; - exprName: EntityName; + readonly kind: SyntaxKind.TypeQuery; + readonly exprName: EntityName; } // A TypeLiteral is the declaration node for an anonymous symbol. export interface TypeLiteralNode extends TypeNode, Declaration { - kind: SyntaxKind.TypeLiteral; - members: NodeArray; + readonly kind: SyntaxKind.TypeLiteral; + readonly members: NodeArray; } export interface ArrayTypeNode extends TypeNode { - kind: SyntaxKind.ArrayType; - elementType: TypeNode; + readonly kind: SyntaxKind.ArrayType; + readonly elementType: TypeNode; } export interface TupleTypeNode extends TypeNode { - kind: SyntaxKind.TupleType; - elementTypes: NodeArray; + readonly kind: SyntaxKind.TupleType; + readonly elementTypes: NodeArray; } export interface OptionalTypeNode extends TypeNode { - kind: SyntaxKind.OptionalType; - type: TypeNode; + readonly kind: SyntaxKind.OptionalType; + readonly type: TypeNode; } export interface RestTypeNode extends TypeNode { - kind: SyntaxKind.RestType; - type: TypeNode; + readonly kind: SyntaxKind.RestType; + readonly type: TypeNode; } export type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; export interface UnionTypeNode extends TypeNode { - kind: SyntaxKind.UnionType; - types: NodeArray; + readonly kind: SyntaxKind.UnionType; + readonly types: NodeArray; } export interface IntersectionTypeNode extends TypeNode { - kind: SyntaxKind.IntersectionType; - types: NodeArray; + readonly kind: SyntaxKind.IntersectionType; + readonly types: NodeArray; } export interface ConditionalTypeNode extends TypeNode { - kind: SyntaxKind.ConditionalType; - checkType: TypeNode; - extendsType: TypeNode; - trueType: TypeNode; - falseType: TypeNode; + readonly kind: SyntaxKind.ConditionalType; + readonly checkType: TypeNode; + readonly extendsType: TypeNode; + readonly trueType: TypeNode; + readonly falseType: TypeNode; } export interface InferTypeNode extends TypeNode { - kind: SyntaxKind.InferType; - typeParameter: TypeParameterDeclaration; + readonly kind: SyntaxKind.InferType; + readonly typeParameter: TypeParameterDeclaration; } export interface ParenthesizedTypeNode extends TypeNode { - kind: SyntaxKind.ParenthesizedType; - type: TypeNode; + readonly kind: SyntaxKind.ParenthesizedType; + readonly type: TypeNode; } export interface TypeOperatorNode extends TypeNode { - kind: SyntaxKind.TypeOperator; - operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; - type: TypeNode; + readonly kind: SyntaxKind.TypeOperator; + readonly operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; + readonly type: TypeNode; } /* @internal */ export interface UniqueTypeOperatorNode extends TypeOperatorNode { - operator: SyntaxKind.UniqueKeyword; + readonly operator: SyntaxKind.UniqueKeyword; } export interface IndexedAccessTypeNode extends TypeNode { - kind: SyntaxKind.IndexedAccessType; - objectType: TypeNode; - indexType: TypeNode; + readonly kind: SyntaxKind.IndexedAccessType; + readonly objectType: TypeNode; + readonly indexType: TypeNode; } export interface MappedTypeNode extends TypeNode, Declaration { - kind: SyntaxKind.MappedType; - readonlyToken?: ReadonlyToken | PlusToken | MinusToken; - typeParameter: TypeParameterDeclaration; - questionToken?: QuestionToken | PlusToken | MinusToken; - type?: TypeNode; + readonly kind: SyntaxKind.MappedType; + readonly readonlyToken?: ReadonlyToken | PlusToken | MinusToken; + readonly typeParameter: TypeParameterDeclaration; + readonly questionToken?: QuestionToken | PlusToken | MinusToken; + readonly type?: TypeNode; } export interface LiteralTypeNode extends TypeNode { - kind: SyntaxKind.LiteralType; - literal: NullLiteral | BooleanLiteral | LiteralExpression | PrefixUnaryExpression; + readonly kind: SyntaxKind.LiteralType; + readonly literal: NullLiteral | BooleanLiteral | LiteralExpression | PrefixUnaryExpression; } export interface StringLiteral extends LiteralExpression, Declaration { - kind: SyntaxKind.StringLiteral; - /* @internal */ textSourceNode?: Identifier | StringLiteralLike | NumericLiteral; // Allows a StringLiteral to get its text from another node (used by transforms). + readonly kind: SyntaxKind.StringLiteral; + /* @internal */ readonly textSourceNode?: Identifier | StringLiteralLike | NumericLiteral; // Allows a StringLiteral to get its text from another node (used by transforms). /** Note: this is only set when synthesizing a node, not during parsing. */ - /* @internal */ singleQuote?: boolean; + /* @internal */ readonly singleQuote?: boolean; } export type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral; @@ -1552,14 +1593,14 @@ namespace ts { } export interface OmittedExpression extends Expression { - kind: SyntaxKind.OmittedExpression; + readonly kind: SyntaxKind.OmittedExpression; } // Represents an expression that is elided as part of a transformation to emit comments on a // not-emitted node. The 'expression' property of a PartiallyEmittedExpression should be emitted. export interface PartiallyEmittedExpression extends LeftHandSideExpression { - kind: SyntaxKind.PartiallyEmittedExpression; - expression: Expression; + readonly kind: SyntaxKind.PartiallyEmittedExpression; + readonly expression: Expression; } export interface UnaryExpression extends Expression { @@ -1583,9 +1624,9 @@ namespace ts { | SyntaxKind.ExclamationToken; export interface PrefixUnaryExpression extends UpdateExpression { - kind: SyntaxKind.PrefixUnaryExpression; - operator: PrefixUnaryOperator; - operand: UnaryExpression; + readonly kind: SyntaxKind.PrefixUnaryExpression; + readonly operator: PrefixUnaryOperator; + readonly operand: UnaryExpression; } // see: https://tc39.github.io/ecma262/#prod-UpdateExpression @@ -1595,9 +1636,9 @@ namespace ts { ; export interface PostfixUnaryExpression extends UpdateExpression { - kind: SyntaxKind.PostfixUnaryExpression; - operand: LeftHandSideExpression; - operator: PostfixUnaryOperator; + readonly kind: SyntaxKind.PostfixUnaryExpression; + readonly operand: LeftHandSideExpression; + readonly operator: PostfixUnaryOperator; } export interface LeftHandSideExpression extends UpdateExpression { @@ -1613,109 +1654,109 @@ namespace ts { } export interface NullLiteral extends PrimaryExpression { - kind: SyntaxKind.NullKeyword; + readonly kind: SyntaxKind.NullKeyword; } export interface TrueLiteral extends PrimaryExpression { - kind: SyntaxKind.TrueKeyword; + readonly kind: SyntaxKind.TrueKeyword; } export interface FalseLiteral extends PrimaryExpression { - kind: SyntaxKind.FalseKeyword; + readonly kind: SyntaxKind.FalseKeyword; } export type BooleanLiteral = TrueLiteral | FalseLiteral; export interface ThisExpression extends PrimaryExpression { - kind: SyntaxKind.ThisKeyword; + readonly kind: SyntaxKind.ThisKeyword; } export interface SuperExpression extends PrimaryExpression { - kind: SyntaxKind.SuperKeyword; + readonly kind: SyntaxKind.SuperKeyword; } export interface ImportExpression extends PrimaryExpression { - kind: SyntaxKind.ImportKeyword; + readonly kind: SyntaxKind.ImportKeyword; } export interface DeleteExpression extends UnaryExpression { - kind: SyntaxKind.DeleteExpression; - expression: UnaryExpression; + readonly kind: SyntaxKind.DeleteExpression; + readonly expression: UnaryExpression; } export interface TypeOfExpression extends UnaryExpression { - kind: SyntaxKind.TypeOfExpression; - expression: UnaryExpression; + readonly kind: SyntaxKind.TypeOfExpression; + readonly expression: UnaryExpression; } export interface VoidExpression extends UnaryExpression { - kind: SyntaxKind.VoidExpression; - expression: UnaryExpression; + readonly kind: SyntaxKind.VoidExpression; + readonly expression: UnaryExpression; } export interface AwaitExpression extends UnaryExpression { - kind: SyntaxKind.AwaitExpression; - expression: UnaryExpression; + readonly kind: SyntaxKind.AwaitExpression; + readonly expression: UnaryExpression; } export interface YieldExpression extends Expression { - kind: SyntaxKind.YieldExpression; - asteriskToken?: AsteriskToken; - expression?: Expression; + readonly kind: SyntaxKind.YieldExpression; + readonly asteriskToken?: AsteriskToken; + readonly expression?: Expression; } export interface SyntheticExpression extends Expression { - kind: SyntaxKind.SyntheticExpression; - isSpread: boolean; - type: Type; + readonly kind: SyntaxKind.SyntheticExpression; + readonly isSpread: boolean; + readonly type: Type; } // see: https://tc39.github.io/ecma262/#prod-ExponentiationExpression - export type ExponentiationOperator - = SyntaxKind.AsteriskAsteriskToken + export type ExponentiationOperator = + | SyntaxKind.AsteriskAsteriskToken ; // see: https://tc39.github.io/ecma262/#prod-MultiplicativeOperator - export type MultiplicativeOperator - = SyntaxKind.AsteriskToken + export type MultiplicativeOperator = + | SyntaxKind.AsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken ; // see: https://tc39.github.io/ecma262/#prod-MultiplicativeExpression - export type MultiplicativeOperatorOrHigher - = ExponentiationOperator + export type MultiplicativeOperatorOrHigher = + | ExponentiationOperator | MultiplicativeOperator ; // see: https://tc39.github.io/ecma262/#prod-AdditiveExpression - export type AdditiveOperator - = SyntaxKind.PlusToken + export type AdditiveOperator = + | SyntaxKind.PlusToken | SyntaxKind.MinusToken ; // see: https://tc39.github.io/ecma262/#prod-AdditiveExpression - export type AdditiveOperatorOrHigher - = MultiplicativeOperatorOrHigher + export type AdditiveOperatorOrHigher = + | MultiplicativeOperatorOrHigher | AdditiveOperator ; // see: https://tc39.github.io/ecma262/#prod-ShiftExpression - export type ShiftOperator - = SyntaxKind.LessThanLessThanToken + export type ShiftOperator = + | SyntaxKind.LessThanLessThanToken | SyntaxKind.GreaterThanGreaterThanToken | SyntaxKind.GreaterThanGreaterThanGreaterThanToken ; // see: https://tc39.github.io/ecma262/#prod-ShiftExpression - export type ShiftOperatorOrHigher - = AdditiveOperatorOrHigher + export type ShiftOperatorOrHigher = + | AdditiveOperatorOrHigher | ShiftOperator ; // see: https://tc39.github.io/ecma262/#prod-RelationalExpression - export type RelationalOperator - = SyntaxKind.LessThanToken + export type RelationalOperator = + | SyntaxKind.LessThanToken | SyntaxKind.LessThanEqualsToken | SyntaxKind.GreaterThanToken | SyntaxKind.GreaterThanEqualsToken @@ -1724,29 +1765,29 @@ namespace ts { ; // see: https://tc39.github.io/ecma262/#prod-RelationalExpression - export type RelationalOperatorOrHigher - = ShiftOperatorOrHigher + export type RelationalOperatorOrHigher = + | ShiftOperatorOrHigher | RelationalOperator ; // see: https://tc39.github.io/ecma262/#prod-EqualityExpression - export type EqualityOperator - = SyntaxKind.EqualsEqualsToken + export type EqualityOperator = + | SyntaxKind.EqualsEqualsToken | SyntaxKind.EqualsEqualsEqualsToken | SyntaxKind.ExclamationEqualsEqualsToken | SyntaxKind.ExclamationEqualsToken ; // see: https://tc39.github.io/ecma262/#prod-EqualityExpression - export type EqualityOperatorOrHigher - = RelationalOperatorOrHigher + export type EqualityOperatorOrHigher = + | RelationalOperatorOrHigher | EqualityOperator; // see: https://tc39.github.io/ecma262/#prod-BitwiseANDExpression // see: https://tc39.github.io/ecma262/#prod-BitwiseXORExpression // see: https://tc39.github.io/ecma262/#prod-BitwiseORExpression - export type BitwiseOperator - = SyntaxKind.AmpersandToken + export type BitwiseOperator = + | SyntaxKind.AmpersandToken | SyntaxKind.BarToken | SyntaxKind.CaretToken ; @@ -1754,28 +1795,28 @@ namespace ts { // see: https://tc39.github.io/ecma262/#prod-BitwiseANDExpression // see: https://tc39.github.io/ecma262/#prod-BitwiseXORExpression // see: https://tc39.github.io/ecma262/#prod-BitwiseORExpression - export type BitwiseOperatorOrHigher - = EqualityOperatorOrHigher + export type BitwiseOperatorOrHigher = + | EqualityOperatorOrHigher | BitwiseOperator ; // see: https://tc39.github.io/ecma262/#prod-LogicalANDExpression // see: https://tc39.github.io/ecma262/#prod-LogicalORExpression - export type LogicalOperator - = SyntaxKind.AmpersandAmpersandToken + export type LogicalOperator = + | SyntaxKind.AmpersandAmpersandToken | SyntaxKind.BarBarToken ; // see: https://tc39.github.io/ecma262/#prod-LogicalANDExpression // see: https://tc39.github.io/ecma262/#prod-LogicalORExpression - export type LogicalOperatorOrHigher - = BitwiseOperatorOrHigher + export type LogicalOperatorOrHigher = + | BitwiseOperatorOrHigher | LogicalOperator ; // see: https://tc39.github.io/ecma262/#prod-AssignmentOperator - export type CompoundAssignmentOperator - = SyntaxKind.PlusEqualsToken + export type CompoundAssignmentOperator = + | SyntaxKind.PlusEqualsToken | SyntaxKind.MinusEqualsToken | SyntaxKind.AsteriskAsteriskEqualsToken | SyntaxKind.AsteriskEqualsToken @@ -1790,55 +1831,55 @@ namespace ts { ; // see: https://tc39.github.io/ecma262/#prod-AssignmentExpression - export type AssignmentOperator - = SyntaxKind.EqualsToken + export type AssignmentOperator = + | SyntaxKind.EqualsToken | CompoundAssignmentOperator ; // see: https://tc39.github.io/ecma262/#prod-AssignmentExpression - export type AssignmentOperatorOrHigher - = SyntaxKind.QuestionQuestionToken + export type AssignmentOperatorOrHigher = + | SyntaxKind.QuestionQuestionToken | LogicalOperatorOrHigher | AssignmentOperator ; // see: https://tc39.github.io/ecma262/#prod-Expression - export type BinaryOperator - = AssignmentOperatorOrHigher + export type BinaryOperator = + | AssignmentOperatorOrHigher | SyntaxKind.CommaToken ; export type BinaryOperatorToken = Token; export interface BinaryExpression extends Expression, Declaration { - kind: SyntaxKind.BinaryExpression; - left: Expression; - operatorToken: BinaryOperatorToken; - right: Expression; + readonly kind: SyntaxKind.BinaryExpression; + readonly left: Expression; + readonly operatorToken: BinaryOperatorToken; + readonly right: Expression; } export type AssignmentOperatorToken = Token; export interface AssignmentExpression extends BinaryExpression { - left: LeftHandSideExpression; - operatorToken: TOperator; + readonly left: LeftHandSideExpression; + readonly operatorToken: TOperator; } export interface ObjectDestructuringAssignment extends AssignmentExpression { - left: ObjectLiteralExpression; + readonly left: ObjectLiteralExpression; } export interface ArrayDestructuringAssignment extends AssignmentExpression { - left: ArrayLiteralExpression; + readonly left: ArrayLiteralExpression; } - export type DestructuringAssignment - = ObjectDestructuringAssignment + export type DestructuringAssignment = + | ObjectDestructuringAssignment | ArrayDestructuringAssignment ; - export type BindingOrAssignmentElement - = VariableDeclaration + export type BindingOrAssignmentElement = + | VariableDeclaration | ParameterDeclaration | ObjectBindingOrAssignmentElement | ArrayBindingOrAssignmentElement @@ -1863,8 +1904,8 @@ namespace ts { | ElementAccessExpression // DestructuringAssignmentTarget ; - export type BindingOrAssignmentElementRestIndicator - = DotDotDotToken // from BindingElement + export type BindingOrAssignmentElementRestIndicator = + | DotDotDotToken // from BindingElement | SpreadElement // AssignmentRestElement | SpreadAssignment // AssignmentRestProperty ; @@ -1876,13 +1917,13 @@ namespace ts { | ElementAccessExpression | OmittedExpression; - export type ObjectBindingOrAssignmentPattern - = ObjectBindingPattern + export type ObjectBindingOrAssignmentPattern = + | ObjectBindingPattern | ObjectLiteralExpression // ObjectAssignmentPattern ; - export type ArrayBindingOrAssignmentPattern - = ArrayBindingPattern + export type ArrayBindingOrAssignmentPattern = + | ArrayBindingPattern | ArrayLiteralExpression // ArrayAssignmentPattern ; @@ -1891,28 +1932,28 @@ namespace ts { export type BindingOrAssignmentPattern = ObjectBindingOrAssignmentPattern | ArrayBindingOrAssignmentPattern; export interface ConditionalExpression extends Expression { - kind: SyntaxKind.ConditionalExpression; - condition: Expression; - questionToken: QuestionToken; - whenTrue: Expression; - colonToken: ColonToken; - whenFalse: Expression; + readonly kind: SyntaxKind.ConditionalExpression; + readonly condition: Expression; + readonly questionToken: QuestionToken; + readonly whenTrue: Expression; + readonly colonToken: ColonToken; + readonly whenFalse: Expression; } export type FunctionBody = Block; export type ConciseBody = FunctionBody | Expression; export interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer { - kind: SyntaxKind.FunctionExpression; - name?: Identifier; - body: FunctionBody; // Required, whereas the member inherited from FunctionDeclaration is optional + readonly kind: SyntaxKind.FunctionExpression; + readonly name?: Identifier; + readonly body: FunctionBody; // Required, whereas the member inherited from FunctionDeclaration is optional } export interface ArrowFunction extends Expression, FunctionLikeDeclarationBase, JSDocContainer { - kind: SyntaxKind.ArrowFunction; - equalsGreaterThanToken: EqualsGreaterThanToken; - body: ConciseBody; - name: never; + readonly kind: SyntaxKind.ArrowFunction; + readonly equalsGreaterThanToken: EqualsGreaterThanToken; + readonly body: ConciseBody; + readonly name: never; } // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, @@ -1936,11 +1977,11 @@ namespace ts { } export interface RegularExpressionLiteral extends LiteralExpression { - kind: SyntaxKind.RegularExpressionLiteral; + readonly kind: SyntaxKind.RegularExpressionLiteral; } export interface NoSubstitutionTemplateLiteral extends LiteralExpression, TemplateLiteralLikeNode, Declaration { - kind: SyntaxKind.NoSubstitutionTemplateLiteral; + readonly kind: SyntaxKind.NoSubstitutionTemplateLiteral; } export const enum TokenFlags { @@ -1969,13 +2010,13 @@ namespace ts { } export interface NumericLiteral extends LiteralExpression, Declaration { - kind: SyntaxKind.NumericLiteral; + readonly kind: SyntaxKind.NumericLiteral; /* @internal */ - numericLiteralFlags: TokenFlags; + readonly numericLiteralFlags: TokenFlags; } export interface BigIntLiteral extends LiteralExpression { - kind: SyntaxKind.BigIntLiteral; + readonly kind: SyntaxKind.BigIntLiteral; } export type LiteralToken = @@ -1988,17 +2029,17 @@ namespace ts { ; export interface TemplateHead extends TemplateLiteralLikeNode { - kind: SyntaxKind.TemplateHead; + readonly kind: SyntaxKind.TemplateHead; parent: TemplateExpression; } export interface TemplateMiddle extends TemplateLiteralLikeNode { - kind: SyntaxKind.TemplateMiddle; + readonly kind: SyntaxKind.TemplateMiddle; parent: TemplateSpan; } export interface TemplateTail extends TemplateLiteralLikeNode { - kind: SyntaxKind.TemplateTail; + readonly kind: SyntaxKind.TemplateTail; parent: TemplateSpan; } @@ -2014,9 +2055,9 @@ namespace ts { ; export interface TemplateExpression extends PrimaryExpression { - kind: SyntaxKind.TemplateExpression; - head: TemplateHead; - templateSpans: NodeArray; + readonly kind: SyntaxKind.TemplateExpression; + readonly head: TemplateHead; + readonly templateSpans: NodeArray; } export type TemplateLiteral = @@ -2027,28 +2068,28 @@ namespace ts { // Each of these corresponds to a substitution expression and a template literal, in that order. // The template literal must have kind TemplateMiddleLiteral or TemplateTailLiteral. export interface TemplateSpan extends Node { - kind: SyntaxKind.TemplateSpan; parent: TemplateExpression; - expression: Expression; - literal: TemplateMiddle | TemplateTail; + readonly kind: SyntaxKind.TemplateSpan; + readonly expression: Expression; + readonly literal: TemplateMiddle | TemplateTail; } export interface ParenthesizedExpression extends PrimaryExpression, JSDocContainer { - kind: SyntaxKind.ParenthesizedExpression; - expression: Expression; + readonly kind: SyntaxKind.ParenthesizedExpression; + readonly expression: Expression; } export interface ArrayLiteralExpression extends PrimaryExpression { - kind: SyntaxKind.ArrayLiteralExpression; - elements: NodeArray; + readonly kind: SyntaxKind.ArrayLiteralExpression; + readonly elements: NodeArray; /* @internal */ multiLine?: boolean; } export interface SpreadElement extends Expression { - kind: SyntaxKind.SpreadElement; parent: ArrayLiteralExpression | CallExpression | NewExpression; - expression: Expression; + readonly kind: SyntaxKind.SpreadElement; + readonly expression: Expression; } /** @@ -2058,12 +2099,12 @@ namespace ts { * ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.) */ export interface ObjectLiteralExpressionBase extends PrimaryExpression, Declaration { - properties: NodeArray; + readonly properties: NodeArray; } // An ObjectLiteralExpression is the declaration node for an anonymous symbol. export interface ObjectLiteralExpression extends ObjectLiteralExpressionBase { - kind: SyntaxKind.ObjectLiteralExpression; + readonly kind: SyntaxKind.ObjectLiteralExpression; /* @internal */ multiLine?: boolean; } @@ -2075,10 +2116,10 @@ namespace ts { export type AccessExpression = PropertyAccessExpression | ElementAccessExpression; export interface PropertyAccessExpression extends MemberExpression, NamedDeclaration { - kind: SyntaxKind.PropertyAccessExpression; - expression: LeftHandSideExpression; - questionDotToken?: QuestionDotToken; - name: Identifier; + readonly kind: SyntaxKind.PropertyAccessExpression; + readonly expression: LeftHandSideExpression; + readonly questionDotToken?: QuestionDotToken; + readonly name: Identifier; } export interface PropertyAccessChain extends PropertyAccessExpression { @@ -2087,24 +2128,24 @@ namespace ts { /* @internal */ export interface PropertyAccessChainRoot extends PropertyAccessChain { - questionDotToken: QuestionDotToken; + readonly questionDotToken: QuestionDotToken; } export interface SuperPropertyAccessExpression extends PropertyAccessExpression { - expression: SuperExpression; + readonly expression: SuperExpression; } /** Brand for a PropertyAccessExpression which, like a QualifiedName, consists of a sequence of identifiers separated by dots. */ export interface PropertyAccessEntityNameExpression extends PropertyAccessExpression { _propertyAccessExpressionLikeQualifiedNameBrand?: any; - expression: EntityNameExpression; + readonly expression: EntityNameExpression; } export interface ElementAccessExpression extends MemberExpression { - kind: SyntaxKind.ElementAccessExpression; - expression: LeftHandSideExpression; - questionDotToken?: QuestionDotToken; - argumentExpression: Expression; + readonly kind: SyntaxKind.ElementAccessExpression; + readonly expression: LeftHandSideExpression; + readonly questionDotToken?: QuestionDotToken; + readonly argumentExpression: Expression; } export interface ElementAccessChain extends ElementAccessExpression { @@ -2113,22 +2154,22 @@ namespace ts { /* @internal */ export interface ElementAccessChainRoot extends ElementAccessChain { - questionDotToken: QuestionDotToken; + readonly questionDotToken: QuestionDotToken; } export interface SuperElementAccessExpression extends ElementAccessExpression { - expression: SuperExpression; + readonly expression: SuperExpression; } // see: https://tc39.github.io/ecma262/#prod-SuperProperty export type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; export interface CallExpression extends LeftHandSideExpression, Declaration { - kind: SyntaxKind.CallExpression; - expression: LeftHandSideExpression; - questionDotToken?: QuestionDotToken; - typeArguments?: NodeArray; - arguments: NodeArray; + readonly kind: SyntaxKind.CallExpression; + readonly expression: LeftHandSideExpression; + readonly questionDotToken?: QuestionDotToken; + readonly typeArguments?: NodeArray; + readonly arguments: NodeArray; } export interface CallChain extends CallExpression { @@ -2137,7 +2178,7 @@ namespace ts { /* @internal */ export interface CallChainRoot extends CallChain { - questionDotToken: QuestionDotToken; + readonly questionDotToken: QuestionDotToken; } export type OptionalChain = @@ -2155,197 +2196,242 @@ namespace ts { /** @internal */ export interface WellKnownSymbolExpression extends PropertyAccessExpression { - expression: Identifier & { escapedText: "Symbol" }; + readonly expression: Identifier & { readonly escapedText: __String & "Symbol" }; } + /** @internal */ - export type BindableObjectDefinePropertyCall = CallExpression & { arguments: { 0: BindableStaticNameExpression, 1: StringLiteralLike | NumericLiteral, 2: ObjectLiteralExpression } }; + export type BindableObjectDefinePropertyCall = CallExpression & { + readonly arguments: readonly [BindableStaticNameExpression, StringLiteralLike | NumericLiteral, ObjectLiteralExpression] & Readonly; + }; + /** @internal */ - export type BindableStaticNameExpression = EntityNameExpression | BindableStaticElementAccessExpression; + export type BindableStaticNameExpression = + | EntityNameExpression + | BindableStaticElementAccessExpression + ; + /** @internal */ export type LiteralLikeElementAccessExpression = ElementAccessExpression & Declaration & { - argumentExpression: StringLiteralLike | NumericLiteral | WellKnownSymbolExpression; + readonly argumentExpression: StringLiteralLike | NumericLiteral | WellKnownSymbolExpression; }; + /** @internal */ export type BindableStaticElementAccessExpression = LiteralLikeElementAccessExpression & { - expression: BindableStaticNameExpression; + readonly expression: BindableStaticNameExpression; }; + /** @internal */ export type BindableElementAccessExpression = ElementAccessExpression & { - expression: BindableStaticNameExpression; + readonly expression: BindableStaticNameExpression; }; + /** @internal */ - export type BindableStaticAccessExpression = PropertyAccessEntityNameExpression | BindableStaticElementAccessExpression; + export type BindableStaticAccessExpression = + | PropertyAccessEntityNameExpression + | BindableStaticElementAccessExpression + ; + /** @internal */ - export type BindableAccessExpression = PropertyAccessEntityNameExpression | BindableElementAccessExpression; + export type BindableAccessExpression = + | PropertyAccessEntityNameExpression + | BindableElementAccessExpression + ; + /** @internal */ export interface BindableStaticPropertyAssignmentExpression extends BinaryExpression { - left: BindableStaticAccessExpression; + readonly left: BindableStaticAccessExpression; } + /** @internal */ export interface BindablePropertyAssignmentExpression extends BinaryExpression { - left: BindableAccessExpression; + readonly left: BindableAccessExpression; } // see: https://tc39.github.io/ecma262/#prod-SuperCall export interface SuperCall extends CallExpression { - expression: SuperExpression; + readonly expression: SuperExpression; } export interface ImportCall extends CallExpression { - expression: ImportExpression; + readonly expression: ImportExpression; } export interface ExpressionWithTypeArguments extends NodeWithTypeArguments { - kind: SyntaxKind.ExpressionWithTypeArguments; parent: HeritageClause | JSDocAugmentsTag; - expression: LeftHandSideExpression; + readonly kind: SyntaxKind.ExpressionWithTypeArguments; + readonly expression: LeftHandSideExpression; } export interface NewExpression extends PrimaryExpression, Declaration { - kind: SyntaxKind.NewExpression; - expression: LeftHandSideExpression; - typeArguments?: NodeArray; - arguments?: NodeArray; + readonly kind: SyntaxKind.NewExpression; + readonly expression: LeftHandSideExpression; + readonly typeArguments?: NodeArray; + readonly arguments?: NodeArray; } export interface TaggedTemplateExpression extends MemberExpression { - kind: SyntaxKind.TaggedTemplateExpression; - tag: LeftHandSideExpression; - typeArguments?: NodeArray; - template: TemplateLiteral; + readonly kind: SyntaxKind.TaggedTemplateExpression; + readonly tag: LeftHandSideExpression; + readonly typeArguments?: NodeArray; + readonly template: TemplateLiteral; /*@internal*/ questionDotToken?: QuestionDotToken; // NOTE: Invalid syntax, only used to report a grammar error. } - export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator | JsxOpeningLikeElement; + export type CallLikeExpression = + | CallExpression + | NewExpression + | TaggedTemplateExpression + | Decorator + | JsxOpeningLikeElement + ; export interface AsExpression extends Expression { - kind: SyntaxKind.AsExpression; - expression: Expression; - type: TypeNode; + readonly kind: SyntaxKind.AsExpression; + readonly expression: Expression; + readonly type: TypeNode; } export interface TypeAssertion extends UnaryExpression { - kind: SyntaxKind.TypeAssertionExpression; - type: TypeNode; - expression: UnaryExpression; + readonly kind: SyntaxKind.TypeAssertionExpression; + readonly type: TypeNode; + readonly expression: UnaryExpression; } - export type AssertionExpression = TypeAssertion | AsExpression; + export type AssertionExpression = + | TypeAssertion + | AsExpression + ; export interface NonNullExpression extends LeftHandSideExpression { - kind: SyntaxKind.NonNullExpression; - expression: Expression; + readonly kind: SyntaxKind.NonNullExpression; + readonly expression: Expression; } // NOTE: MetaProperty is really a MemberExpression, but we consider it a PrimaryExpression // for the same reasons we treat NewExpression as a PrimaryExpression. export interface MetaProperty extends PrimaryExpression { - kind: SyntaxKind.MetaProperty; - keywordToken: SyntaxKind.NewKeyword | SyntaxKind.ImportKeyword; - name: Identifier; + readonly kind: SyntaxKind.MetaProperty; + readonly keywordToken: SyntaxKind.NewKeyword | SyntaxKind.ImportKeyword; + readonly name: Identifier; } /* @internal */ export interface ImportMetaProperty extends MetaProperty { - keywordToken: SyntaxKind.ImportKeyword; - name: Identifier & { escapedText: __String & "meta" }; + readonly keywordToken: SyntaxKind.ImportKeyword; + readonly name: Identifier & { readonly escapedText: __String & "meta" }; } /// A JSX expression of the form ... export interface JsxElement extends PrimaryExpression { - kind: SyntaxKind.JsxElement; - openingElement: JsxOpeningElement; - children: NodeArray; - closingElement: JsxClosingElement; + readonly kind: SyntaxKind.JsxElement; + readonly openingElement: JsxOpeningElement; + readonly children: NodeArray; + readonly closingElement: JsxClosingElement; } /// Either the opening tag in a ... pair or the lone in a self-closing form - export type JsxOpeningLikeElement = JsxSelfClosingElement | JsxOpeningElement; + export type JsxOpeningLikeElement = + | JsxSelfClosingElement + | JsxOpeningElement + ; - export type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute; + export type JsxAttributeLike = + | JsxAttribute + | JsxSpreadAttribute + ; - export type JsxTagNameExpression = Identifier | ThisExpression | JsxTagNamePropertyAccess; + export type JsxTagNameExpression = + | Identifier + | ThisExpression + | JsxTagNamePropertyAccess + ; export interface JsxTagNamePropertyAccess extends PropertyAccessExpression { - expression: JsxTagNameExpression; + readonly expression: JsxTagNameExpression; } export interface JsxAttributes extends ObjectLiteralExpressionBase { - kind: SyntaxKind.JsxAttributes; parent: JsxOpeningLikeElement; + readonly kind: SyntaxKind.JsxAttributes; } /// The opening element of a ... JsxElement export interface JsxOpeningElement extends Expression { - kind: SyntaxKind.JsxOpeningElement; parent: JsxElement; - tagName: JsxTagNameExpression; - typeArguments?: NodeArray; - attributes: JsxAttributes; + readonly kind: SyntaxKind.JsxOpeningElement; + readonly tagName: JsxTagNameExpression; + readonly typeArguments?: NodeArray; + readonly attributes: JsxAttributes; } /// A JSX expression of the form export interface JsxSelfClosingElement extends PrimaryExpression { - kind: SyntaxKind.JsxSelfClosingElement; - tagName: JsxTagNameExpression; - typeArguments?: NodeArray; - attributes: JsxAttributes; + readonly kind: SyntaxKind.JsxSelfClosingElement; + readonly tagName: JsxTagNameExpression; + readonly typeArguments?: NodeArray; + readonly attributes: JsxAttributes; } /// A JSX expression of the form <>... export interface JsxFragment extends PrimaryExpression { - kind: SyntaxKind.JsxFragment; - openingFragment: JsxOpeningFragment; - children: NodeArray; - closingFragment: JsxClosingFragment; + readonly kind: SyntaxKind.JsxFragment; + readonly openingFragment: JsxOpeningFragment; + readonly children: NodeArray; + readonly closingFragment: JsxClosingFragment; } /// The opening element of a <>... JsxFragment export interface JsxOpeningFragment extends Expression { - kind: SyntaxKind.JsxOpeningFragment; parent: JsxFragment; + readonly kind: SyntaxKind.JsxOpeningFragment; } /// The closing element of a <>... JsxFragment export interface JsxClosingFragment extends Expression { - kind: SyntaxKind.JsxClosingFragment; parent: JsxFragment; + readonly kind: SyntaxKind.JsxClosingFragment; } export interface JsxAttribute extends ObjectLiteralElement { - kind: SyntaxKind.JsxAttribute; parent: JsxAttributes; - name: Identifier; + readonly kind: SyntaxKind.JsxAttribute; + readonly name: Identifier; /// JSX attribute initializers are optional; is sugar for - initializer?: StringLiteral | JsxExpression; + readonly initializer?: StringLiteral | JsxExpression; } export interface JsxSpreadAttribute extends ObjectLiteralElement { - kind: SyntaxKind.JsxSpreadAttribute; parent: JsxAttributes; - expression: Expression; + readonly kind: SyntaxKind.JsxSpreadAttribute; + readonly expression: Expression; } export interface JsxClosingElement extends Node { - kind: SyntaxKind.JsxClosingElement; parent: JsxElement; - tagName: JsxTagNameExpression; + readonly kind: SyntaxKind.JsxClosingElement; + readonly tagName: JsxTagNameExpression; } export interface JsxExpression extends Expression { - kind: SyntaxKind.JsxExpression; parent: JsxElement | JsxAttributeLike; - dotDotDotToken?: Token; - expression?: Expression; + readonly kind: SyntaxKind.JsxExpression; + readonly dotDotDotToken?: Token; + readonly expression?: Expression; } export interface JsxText extends LiteralLikeNode { - kind: SyntaxKind.JsxText; - containsOnlyTriviaWhiteSpaces: boolean; parent: JsxElement; + readonly kind: SyntaxKind.JsxText; + readonly containsOnlyTriviaWhiteSpaces: boolean; } - export type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment; + export type JsxChild = + | JsxText + | JsxExpression + | JsxElement + | JsxSelfClosingElement + | JsxFragment + ; export interface Statement extends Node { _statementBrand: any; @@ -2354,7 +2440,7 @@ namespace ts { // Represents a statement that is elided as part of a transformation to emit comments on a // not-emitted node. export interface NotEmittedStatement extends Statement { - kind: SyntaxKind.NotEmittedStatement; + readonly kind: SyntaxKind.NotEmittedStatement; } /** @@ -2362,15 +2448,15 @@ namespace ts { */ /* @internal */ export interface EndOfDeclarationMarker extends Statement { - kind: SyntaxKind.EndOfDeclarationMarker; + readonly kind: SyntaxKind.EndOfDeclarationMarker; } /** * A list of comma-separated expressions. This node is only created by transformations. */ export interface CommaListExpression extends Expression { - kind: SyntaxKind.CommaListExpression; - elements: NodeArray; + readonly kind: SyntaxKind.CommaListExpression; + readonly elements: NodeArray; } /** @@ -2378,283 +2464,339 @@ namespace ts { */ /* @internal */ export interface MergeDeclarationMarker extends Statement { - kind: SyntaxKind.MergeDeclarationMarker; + readonly kind: SyntaxKind.MergeDeclarationMarker; } /* @internal */ export interface SyntheticReferenceExpression extends LeftHandSideExpression { - kind: SyntaxKind.SyntheticReferenceExpression; - expression: Expression; - thisArg: Expression; + readonly kind: SyntaxKind.SyntheticReferenceExpression; + readonly expression: Expression; + readonly thisArg: Expression; } export interface EmptyStatement extends Statement { - kind: SyntaxKind.EmptyStatement; + readonly kind: SyntaxKind.EmptyStatement; } export interface DebuggerStatement extends Statement { - kind: SyntaxKind.DebuggerStatement; + readonly kind: SyntaxKind.DebuggerStatement; } export interface MissingDeclaration extends DeclarationStatement { - kind: SyntaxKind.MissingDeclaration; - name?: Identifier; + /*@internal*/ decorators?: NodeArray; // Present for use with reporting a grammar error + /*@internal*/ modifiers?: ModifiersArray; // Present for use with reporting a grammar error + readonly kind: SyntaxKind.MissingDeclaration; + readonly name?: Identifier; } - export type BlockLike = SourceFile | Block | ModuleBlock | CaseOrDefaultClause; + export type BlockLike = + | SourceFile + | Block + | ModuleBlock + | CaseOrDefaultClause + ; export interface Block extends Statement { - kind: SyntaxKind.Block; - statements: NodeArray; + readonly kind: SyntaxKind.Block; + readonly statements: NodeArray; /*@internal*/ multiLine?: boolean; } export interface VariableStatement extends Statement, JSDocContainer { - kind: SyntaxKind.VariableStatement; - declarationList: VariableDeclarationList; + /* @internal*/ decorators?: NodeArray; // Present for use with reporting a grammar error + readonly kind: SyntaxKind.VariableStatement; + readonly declarationList: VariableDeclarationList; } export interface ExpressionStatement extends Statement, JSDocContainer { - kind: SyntaxKind.ExpressionStatement; - expression: Expression; + readonly kind: SyntaxKind.ExpressionStatement; + readonly expression: Expression; } /* @internal */ export interface PrologueDirective extends ExpressionStatement { - expression: StringLiteral; + readonly expression: StringLiteral; } export interface IfStatement extends Statement { - kind: SyntaxKind.IfStatement; - expression: Expression; - thenStatement: Statement; - elseStatement?: Statement; + readonly kind: SyntaxKind.IfStatement; + readonly expression: Expression; + readonly thenStatement: Statement; + readonly elseStatement?: Statement; } export interface IterationStatement extends Statement { - statement: Statement; + readonly statement: Statement; } export interface DoStatement extends IterationStatement { - kind: SyntaxKind.DoStatement; - expression: Expression; + readonly kind: SyntaxKind.DoStatement; + readonly expression: Expression; } export interface WhileStatement extends IterationStatement { - kind: SyntaxKind.WhileStatement; - expression: Expression; + readonly kind: SyntaxKind.WhileStatement; + readonly expression: Expression; } - export type ForInitializer = VariableDeclarationList | Expression; + export type ForInitializer = + | VariableDeclarationList + | Expression + ; export interface ForStatement extends IterationStatement { - kind: SyntaxKind.ForStatement; - initializer?: ForInitializer; - condition?: Expression; - incrementor?: Expression; + readonly kind: SyntaxKind.ForStatement; + readonly initializer?: ForInitializer; + readonly condition?: Expression; + readonly incrementor?: Expression; } - export type ForInOrOfStatement = ForInStatement | ForOfStatement; + export type ForInOrOfStatement = + | ForInStatement + | ForOfStatement + ; export interface ForInStatement extends IterationStatement { - kind: SyntaxKind.ForInStatement; - initializer: ForInitializer; - expression: Expression; + readonly kind: SyntaxKind.ForInStatement; + readonly initializer: ForInitializer; + readonly expression: Expression; } export interface ForOfStatement extends IterationStatement { - kind: SyntaxKind.ForOfStatement; - awaitModifier?: AwaitKeywordToken; - initializer: ForInitializer; - expression: Expression; + readonly kind: SyntaxKind.ForOfStatement; + readonly awaitModifier?: AwaitKeywordToken; + readonly initializer: ForInitializer; + readonly expression: Expression; } export interface BreakStatement extends Statement { - kind: SyntaxKind.BreakStatement; - label?: Identifier; + readonly kind: SyntaxKind.BreakStatement; + readonly label?: Identifier; } export interface ContinueStatement extends Statement { - kind: SyntaxKind.ContinueStatement; - label?: Identifier; + readonly kind: SyntaxKind.ContinueStatement; + readonly label?: Identifier; } - export type BreakOrContinueStatement = BreakStatement | ContinueStatement; + export type BreakOrContinueStatement = + | BreakStatement + | ContinueStatement + ; export interface ReturnStatement extends Statement { - kind: SyntaxKind.ReturnStatement; - expression?: Expression; + readonly kind: SyntaxKind.ReturnStatement; + readonly expression?: Expression; } export interface WithStatement extends Statement { - kind: SyntaxKind.WithStatement; - expression: Expression; - statement: Statement; + readonly kind: SyntaxKind.WithStatement; + readonly expression: Expression; + readonly statement: Statement; } export interface SwitchStatement extends Statement { - kind: SyntaxKind.SwitchStatement; - expression: Expression; - caseBlock: CaseBlock; + readonly kind: SyntaxKind.SwitchStatement; + readonly expression: Expression; + readonly caseBlock: CaseBlock; possiblyExhaustive?: boolean; } export interface CaseBlock extends Node { - kind: SyntaxKind.CaseBlock; parent: SwitchStatement; - clauses: NodeArray; + readonly kind: SyntaxKind.CaseBlock; + readonly clauses: NodeArray; } export interface CaseClause extends Node { - kind: SyntaxKind.CaseClause; parent: CaseBlock; - expression: Expression; - statements: NodeArray; + readonly kind: SyntaxKind.CaseClause; + readonly expression: Expression; + readonly statements: NodeArray; /* @internal */ fallthroughFlowNode?: FlowNode; } export interface DefaultClause extends Node { - kind: SyntaxKind.DefaultClause; parent: CaseBlock; - statements: NodeArray; + readonly kind: SyntaxKind.DefaultClause; + readonly statements: NodeArray; /* @internal */ fallthroughFlowNode?: FlowNode; } - export type CaseOrDefaultClause = CaseClause | DefaultClause; + export type CaseOrDefaultClause = + | CaseClause + | DefaultClause + ; export interface LabeledStatement extends Statement, JSDocContainer { - kind: SyntaxKind.LabeledStatement; - label: Identifier; - statement: Statement; + readonly kind: SyntaxKind.LabeledStatement; + readonly label: Identifier; + readonly statement: Statement; } export interface ThrowStatement extends Statement { - kind: SyntaxKind.ThrowStatement; - expression?: Expression; + readonly kind: SyntaxKind.ThrowStatement; + readonly expression?: Expression; } export interface TryStatement extends Statement { - kind: SyntaxKind.TryStatement; - tryBlock: Block; - catchClause?: CatchClause; - finallyBlock?: Block; + readonly kind: SyntaxKind.TryStatement; + readonly tryBlock: Block; + readonly catchClause?: CatchClause; + readonly finallyBlock?: Block; } export interface CatchClause extends Node { - kind: SyntaxKind.CatchClause; parent: TryStatement; - variableDeclaration?: VariableDeclaration; - block: Block; + readonly kind: SyntaxKind.CatchClause; + readonly variableDeclaration?: VariableDeclaration; + readonly block: Block; } - export type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode; + export type ObjectTypeDeclaration = + | ClassLikeDeclaration + | InterfaceDeclaration + | TypeLiteralNode + ; - export type DeclarationWithTypeParameters = DeclarationWithTypeParameterChildren | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; - export type DeclarationWithTypeParameterChildren = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; + export type DeclarationWithTypeParameters = + | DeclarationWithTypeParameterChildren + | JSDocTypedefTag + | JSDocCallbackTag + | JSDocSignature + ; + + export type DeclarationWithTypeParameterChildren = + | SignatureDeclaration + | ClassLikeDeclaration + | InterfaceDeclaration + | TypeAliasDeclaration + | JSDocTemplateTag + ; export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { - kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; - name?: Identifier; - typeParameters?: NodeArray; - heritageClauses?: NodeArray; - members: NodeArray; + readonly kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; + readonly name?: Identifier; + readonly typeParameters?: NodeArray; + readonly heritageClauses?: NodeArray; + readonly members: NodeArray; } export interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatement { - kind: SyntaxKind.ClassDeclaration; + readonly kind: SyntaxKind.ClassDeclaration; /** May be undefined in `export default class { ... }`. */ - name?: Identifier; + readonly name?: Identifier; } export interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpression { - kind: SyntaxKind.ClassExpression; + readonly kind: SyntaxKind.ClassExpression; } - export type ClassLikeDeclaration = ClassDeclaration | ClassExpression; + export type ClassLikeDeclaration = + | ClassDeclaration + | ClassExpression + ; export interface ClassElement extends NamedDeclaration { _classElementBrand: any; - name?: PropertyName; + readonly name?: PropertyName; } export interface TypeElement extends NamedDeclaration { _typeElementBrand: any; - name?: PropertyName; - questionToken?: QuestionToken; + readonly name?: PropertyName; + readonly questionToken?: QuestionToken; } export interface InterfaceDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.InterfaceDeclaration; - name: Identifier; - typeParameters?: NodeArray; - heritageClauses?: NodeArray; - members: NodeArray; + readonly kind: SyntaxKind.InterfaceDeclaration; + readonly name: Identifier; + readonly typeParameters?: NodeArray; + readonly heritageClauses?: NodeArray; + readonly members: NodeArray; } export interface HeritageClause extends Node { - kind: SyntaxKind.HeritageClause; parent: InterfaceDeclaration | ClassLikeDeclaration; - token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; - types: NodeArray; + readonly kind: SyntaxKind.HeritageClause; + readonly token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; + readonly types: NodeArray; } export interface TypeAliasDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.TypeAliasDeclaration; - name: Identifier; - typeParameters?: NodeArray; - type: TypeNode; + readonly kind: SyntaxKind.TypeAliasDeclaration; + readonly name: Identifier; + readonly typeParameters?: NodeArray; + readonly type: TypeNode; } export interface EnumMember extends NamedDeclaration, JSDocContainer { - kind: SyntaxKind.EnumMember; parent: EnumDeclaration; + readonly kind: SyntaxKind.EnumMember; // This does include ComputedPropertyName, but the parser will give an error // if it parses a ComputedPropertyName in an EnumMember - name: PropertyName; - initializer?: Expression; + readonly name: PropertyName; + readonly initializer?: Expression; } export interface EnumDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.EnumDeclaration; - name: Identifier; - members: NodeArray; + readonly kind: SyntaxKind.EnumDeclaration; + readonly name: Identifier; + readonly members: NodeArray; } - export type ModuleName = Identifier | StringLiteral; + export type ModuleName = + | Identifier + | StringLiteral + ; - export type ModuleBody = NamespaceBody | JSDocNamespaceBody; + export type ModuleBody = + | NamespaceBody + | JSDocNamespaceBody + ; /* @internal */ - export interface AmbientModuleDeclaration extends ModuleDeclaration { body?: ModuleBlock; } + export interface AmbientModuleDeclaration extends ModuleDeclaration { + readonly body?: ModuleBlock; + } export interface ModuleDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ModuleDeclaration; parent: ModuleBody | SourceFile; - name: ModuleName; - body?: ModuleBody | JSDocNamespaceDeclaration; + readonly kind: SyntaxKind.ModuleDeclaration; + readonly name: ModuleName; + readonly body?: ModuleBody | JSDocNamespaceDeclaration; } - export type NamespaceBody = ModuleBlock | NamespaceDeclaration; + export type NamespaceBody = + | ModuleBlock + | NamespaceDeclaration + ; export interface NamespaceDeclaration extends ModuleDeclaration { - name: Identifier; - body: NamespaceBody; + readonly name: Identifier; + readonly body: NamespaceBody; } - export type JSDocNamespaceBody = Identifier | JSDocNamespaceDeclaration; + export type JSDocNamespaceBody = + | Identifier + | JSDocNamespaceDeclaration + ; export interface JSDocNamespaceDeclaration extends ModuleDeclaration { - name: Identifier; - body?: JSDocNamespaceBody; + readonly name: Identifier; + readonly body?: JSDocNamespaceBody; } export interface ModuleBlock extends Node, Statement { - kind: SyntaxKind.ModuleBlock; parent: ModuleDeclaration; - statements: NodeArray; + readonly kind: SyntaxKind.ModuleBlock; + readonly statements: NodeArray; } - export type ModuleReference = EntityName | ExternalModuleReference; + export type ModuleReference = + | EntityName + | ExternalModuleReference + ; /** * One of: @@ -2662,19 +2804,19 @@ namespace ts { * - import x = M.x; */ export interface ImportEqualsDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ImportEqualsDeclaration; parent: SourceFile | ModuleBlock; - name: Identifier; + readonly kind: SyntaxKind.ImportEqualsDeclaration; + readonly name: Identifier; // 'EntityName' for an internal module reference, 'ExternalModuleReference' for an external // module reference. - moduleReference: ModuleReference; + readonly moduleReference: ModuleReference; } export interface ExternalModuleReference extends Node { - kind: SyntaxKind.ExternalModuleReference; parent: ImportEqualsDeclaration; - expression: Expression; + readonly kind: SyntaxKind.ExternalModuleReference; + readonly expression: Expression; } // In case of: @@ -2682,14 +2824,17 @@ namespace ts { // In rest of the cases, module specifier is string literal corresponding to module // ImportClause information is shown at its declaration below. export interface ImportDeclaration extends Statement, JSDocContainer { - kind: SyntaxKind.ImportDeclaration; parent: SourceFile | ModuleBlock; - importClause?: ImportClause; + readonly kind: SyntaxKind.ImportDeclaration; + readonly importClause?: ImportClause; /** If this is not a StringLiteral it will be a grammar error. */ - moduleSpecifier: Expression; + readonly moduleSpecifier: Expression; } - export type NamedImportBindings = NamespaceImport | NamedImports; + export type NamedImportBindings = + | NamespaceImport + | NamedImports + ; // In case of: // import d from "mod" => name = d, namedBinding = undefined @@ -2698,71 +2843,76 @@ namespace ts { // import { a, b as x } from "mod" => name = undefined, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} // import d, { a, b as x } from "mod" => name = d, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} export interface ImportClause extends NamedDeclaration { - kind: SyntaxKind.ImportClause; parent: ImportDeclaration; - name?: Identifier; // Default binding - namedBindings?: NamedImportBindings; + readonly kind: SyntaxKind.ImportClause; + readonly name?: Identifier; // Default binding + readonly namedBindings?: NamedImportBindings; } export interface NamespaceImport extends NamedDeclaration { - kind: SyntaxKind.NamespaceImport; parent: ImportClause; - name: Identifier; + readonly kind: SyntaxKind.NamespaceImport; + readonly name: Identifier; } export interface NamespaceExportDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.NamespaceExportDeclaration; - name: Identifier; + readonly kind: SyntaxKind.NamespaceExportDeclaration; + readonly name: Identifier; + /* @internal */ decorators?: NodeArray; // Present for use with reporting a grammar error + /* @internal */ modifiers?: ModifiersArray; // Present for use with reporting a grammar error } export interface ExportDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ExportDeclaration; parent: SourceFile | ModuleBlock; + readonly kind: SyntaxKind.ExportDeclaration; /** Will not be assigned in the case of `export * from "foo";` */ - exportClause?: NamedExports; + readonly exportClause?: NamedExports; /** If this is not a StringLiteral it will be a grammar error. */ - moduleSpecifier?: Expression; + readonly moduleSpecifier?: Expression; } export interface NamedImports extends Node { - kind: SyntaxKind.NamedImports; parent: ImportClause; - elements: NodeArray; + readonly kind: SyntaxKind.NamedImports; + readonly elements: NodeArray; } export interface NamedExports extends Node { - kind: SyntaxKind.NamedExports; parent: ExportDeclaration; - elements: NodeArray; + readonly kind: SyntaxKind.NamedExports; + readonly elements: NodeArray; } export type NamedImportsOrExports = NamedImports | NamedExports; export interface ImportSpecifier extends NamedDeclaration { - kind: SyntaxKind.ImportSpecifier; parent: NamedImports; - propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) - name: Identifier; // Declared name + readonly kind: SyntaxKind.ImportSpecifier; + readonly propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) + readonly name: Identifier; // Declared name } export interface ExportSpecifier extends NamedDeclaration { - kind: SyntaxKind.ExportSpecifier; parent: NamedExports; - propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) - name: Identifier; // Declared name + readonly kind: SyntaxKind.ExportSpecifier; + readonly propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) + readonly name: Identifier; // Declared name } - export type ImportOrExportSpecifier = ImportSpecifier | ExportSpecifier; + export type ImportOrExportSpecifier = + | ImportSpecifier + | ExportSpecifier + ; /** * This is either an `export =` or an `export default` declaration. * Unless `isExportEquals` is set, this node was parsed as an `export default`. */ export interface ExportAssignment extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ExportAssignment; parent: SourceFile; - isExportEquals?: boolean; - expression: Expression; + readonly kind: SyntaxKind.ExportAssignment; + readonly isExportEquals?: boolean; + readonly expression: Expression; } export interface FileReference extends TextRange { @@ -2788,8 +2938,8 @@ namespace ts { // represents a top level: { type } expression in a JSDoc comment. export interface JSDocTypeExpression extends TypeNode { - kind: SyntaxKind.JSDocTypeExpression; - type: TypeNode; + readonly kind: SyntaxKind.JSDocTypeExpression; + readonly type: TypeNode; } export interface JSDocType extends TypeNode { @@ -2797,59 +2947,64 @@ namespace ts { } export interface JSDocAllType extends JSDocType { - kind: SyntaxKind.JSDocAllType; + readonly kind: SyntaxKind.JSDocAllType; } export interface JSDocUnknownType extends JSDocType { - kind: SyntaxKind.JSDocUnknownType; + readonly kind: SyntaxKind.JSDocUnknownType; } export interface JSDocNonNullableType extends JSDocType { - kind: SyntaxKind.JSDocNonNullableType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocNonNullableType; + readonly type: TypeNode; } export interface JSDocNullableType extends JSDocType { - kind: SyntaxKind.JSDocNullableType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocNullableType; + readonly type: TypeNode; } export interface JSDocOptionalType extends JSDocType { - kind: SyntaxKind.JSDocOptionalType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocOptionalType; + readonly type: TypeNode; } export interface JSDocFunctionType extends JSDocType, SignatureDeclarationBase { - kind: SyntaxKind.JSDocFunctionType; + readonly kind: SyntaxKind.JSDocFunctionType; } export interface JSDocVariadicType extends JSDocType { - kind: SyntaxKind.JSDocVariadicType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocVariadicType; + readonly type: TypeNode; } export interface JSDocNamepathType extends JSDocType { - kind: SyntaxKind.JSDocNamepathType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocNamepathType; + readonly type: TypeNode; } - export type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; + export type JSDocTypeReferencingNode = + | JSDocVariadicType + | JSDocOptionalType + | JSDocNullableType + | JSDocNonNullableType + ; export interface JSDoc extends Node { - kind: SyntaxKind.JSDocComment; parent: HasJSDoc; - tags?: NodeArray; + readonly kind: SyntaxKind.JSDocComment; + readonly tags?: NodeArray; comment?: string; } export interface JSDocTag extends Node { parent: JSDoc | JSDocTypeLiteral; - tagName: Identifier; + readonly tagName: Identifier; comment?: string; } export interface JSDocUnknownTag extends JSDocTag { - kind: SyntaxKind.JSDocTag; + readonly kind: SyntaxKind.JSDocTag; } /** @@ -2857,90 +3012,90 @@ namespace ts { * Both tags are represented by this interface. */ export interface JSDocAugmentsTag extends JSDocTag { - kind: SyntaxKind.JSDocAugmentsTag; - class: ExpressionWithTypeArguments & { expression: Identifier | PropertyAccessEntityNameExpression }; + readonly kind: SyntaxKind.JSDocAugmentsTag; + readonly class: ExpressionWithTypeArguments & { readonly expression: Identifier | PropertyAccessEntityNameExpression }; } export interface JSDocAuthorTag extends JSDocTag { - kind: SyntaxKind.JSDocAuthorTag; + readonly kind: SyntaxKind.JSDocAuthorTag; } export interface JSDocClassTag extends JSDocTag { - kind: SyntaxKind.JSDocClassTag; + readonly kind: SyntaxKind.JSDocClassTag; } export interface JSDocEnumTag extends JSDocTag, Declaration { parent: JSDoc; - kind: SyntaxKind.JSDocEnumTag; - typeExpression?: JSDocTypeExpression; + readonly kind: SyntaxKind.JSDocEnumTag; + readonly typeExpression?: JSDocTypeExpression; } export interface JSDocThisTag extends JSDocTag { - kind: SyntaxKind.JSDocThisTag; - typeExpression?: JSDocTypeExpression; + readonly kind: SyntaxKind.JSDocThisTag; + readonly typeExpression?: JSDocTypeExpression; } export interface JSDocTemplateTag extends JSDocTag { - kind: SyntaxKind.JSDocTemplateTag; - constraint: JSDocTypeExpression | undefined; - typeParameters: NodeArray; + readonly kind: SyntaxKind.JSDocTemplateTag; + readonly constraint: JSDocTypeExpression | undefined; + readonly typeParameters: NodeArray; } export interface JSDocReturnTag extends JSDocTag { - kind: SyntaxKind.JSDocReturnTag; - typeExpression?: JSDocTypeExpression; + readonly kind: SyntaxKind.JSDocReturnTag; + readonly typeExpression?: JSDocTypeExpression; } export interface JSDocTypeTag extends JSDocTag { - kind: SyntaxKind.JSDocTypeTag; - typeExpression: JSDocTypeExpression; + readonly kind: SyntaxKind.JSDocTypeTag; + readonly typeExpression: JSDocTypeExpression; } export interface JSDocTypedefTag extends JSDocTag, NamedDeclaration { parent: JSDoc; - kind: SyntaxKind.JSDocTypedefTag; - fullName?: JSDocNamespaceDeclaration | Identifier; - name?: Identifier; - typeExpression?: JSDocTypeExpression | JSDocTypeLiteral; + readonly kind: SyntaxKind.JSDocTypedefTag; + readonly fullName?: JSDocNamespaceDeclaration | Identifier; + readonly name?: Identifier; + readonly typeExpression?: JSDocTypeExpression | JSDocTypeLiteral; } export interface JSDocCallbackTag extends JSDocTag, NamedDeclaration { parent: JSDoc; - kind: SyntaxKind.JSDocCallbackTag; - fullName?: JSDocNamespaceDeclaration | Identifier; - name?: Identifier; - typeExpression: JSDocSignature; + readonly kind: SyntaxKind.JSDocCallbackTag; + readonly fullName?: JSDocNamespaceDeclaration | Identifier; + readonly name?: Identifier; + readonly typeExpression: JSDocSignature; } export interface JSDocSignature extends JSDocType, Declaration { - kind: SyntaxKind.JSDocSignature; - typeParameters?: readonly JSDocTemplateTag[]; - parameters: readonly JSDocParameterTag[]; - type: JSDocReturnTag | undefined; + readonly kind: SyntaxKind.JSDocSignature; + readonly typeParameters?: readonly JSDocTemplateTag[]; + readonly parameters: readonly JSDocParameterTag[]; + readonly type: JSDocReturnTag | undefined; } export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { parent: JSDoc; - name: EntityName; - typeExpression?: JSDocTypeExpression; + readonly name: EntityName; + readonly typeExpression?: JSDocTypeExpression; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ - isNameFirst: boolean; - isBracketed: boolean; + readonly isNameFirst: boolean; + readonly isBracketed: boolean; } export interface JSDocPropertyTag extends JSDocPropertyLikeTag { - kind: SyntaxKind.JSDocPropertyTag; + readonly kind: SyntaxKind.JSDocPropertyTag; } export interface JSDocParameterTag extends JSDocPropertyLikeTag { - kind: SyntaxKind.JSDocParameterTag; + readonly kind: SyntaxKind.JSDocParameterTag; } export interface JSDocTypeLiteral extends JSDocType { - kind: SyntaxKind.JSDocTypeLiteral; - jsDocPropertyTags?: readonly JSDocPropertyLikeTag[]; + readonly kind: SyntaxKind.JSDocTypeLiteral; + readonly jsDocPropertyTags?: readonly JSDocPropertyLikeTag[]; /** If true, then this type literal represents an *array* of its type. */ - isArrayType?: boolean; + readonly isArrayType?: boolean; } // NOTE: Ensure this is up-to-date with src/debug/debug.ts @@ -3080,9 +3235,9 @@ namespace ts { // Source files are declarations when they are external modules. export interface SourceFile extends Declaration { - kind: SyntaxKind.SourceFile; - statements: NodeArray; - endOfFileToken: Token; + readonly kind: SyntaxKind.SourceFile; + readonly statements: NodeArray; + readonly endOfFileToken: Token; fileName: string; /* @internal */ path: Path; @@ -3182,16 +3337,16 @@ namespace ts { /* @internal */ localJsxNamespace?: __String; /* @internal */ localJsxFactory?: EntityName; - /*@internal*/ exportedModulesFromDeclarationEmit?: ExportedModulesFromDeclarationEmit; + /* @internal */ exportedModulesFromDeclarationEmit?: ExportedModulesFromDeclarationEmit; } /*@internal*/ export type ExportedModulesFromDeclarationEmit = readonly Symbol[]; export interface Bundle extends Node { - kind: SyntaxKind.Bundle; - prepends: readonly (InputFiles | UnparsedSource)[]; - sourceFiles: readonly SourceFile[]; + readonly kind: SyntaxKind.Bundle; + readonly prepends: readonly (InputFiles | UnparsedSource)[]; + readonly sourceFiles: readonly SourceFile[]; /* @internal */ syntheticFileReferences?: readonly FileReference[]; /* @internal */ syntheticTypeReferences?: readonly FileReference[]; /* @internal */ syntheticLibReferences?: readonly FileReference[]; @@ -3199,7 +3354,7 @@ namespace ts { } export interface InputFiles extends Node { - kind: SyntaxKind.InputFiles; + readonly kind: SyntaxKind.InputFiles; javascriptPath?: string; javascriptText: string; javascriptMapPath?: string; @@ -3214,10 +3369,10 @@ namespace ts { } export interface UnparsedSource extends Node { - kind: SyntaxKind.UnparsedSource; + readonly kind: SyntaxKind.UnparsedSource; fileName: string; text: string; - prologues: readonly UnparsedPrologue[]; + readonly prologues: readonly UnparsedPrologue[]; helpers: readonly UnscopedEmitHelper[] | undefined; // References and noDefaultLibAre Dts only @@ -3228,8 +3383,8 @@ namespace ts { sourceMapPath?: string; sourceMapText?: string; - syntheticReferences?: readonly UnparsedSyntheticReference[]; - texts: readonly UnparsedSourceText[]; + readonly syntheticReferences?: readonly UnparsedSyntheticReference[]; + readonly texts: readonly UnparsedSourceText[]; /*@internal*/ oldFileOfCurrentEmit?: boolean; /*@internal*/ parsedSourceMap?: RawSourceMap | false | undefined; // Adding this to satisfy services, fix later @@ -3237,41 +3392,49 @@ namespace ts { getLineAndCharacterOfPosition(pos: number): LineAndCharacter; } - export type UnparsedSourceText = UnparsedPrepend | UnparsedTextLike; - export type UnparsedNode = UnparsedPrologue | UnparsedSourceText | UnparsedSyntheticReference; + export type UnparsedSourceText = + | UnparsedPrepend + | UnparsedTextLike + ; + + export type UnparsedNode = + | UnparsedPrologue + | UnparsedSourceText + | UnparsedSyntheticReference + ; export interface UnparsedSection extends Node { - kind: SyntaxKind; - data?: string; parent: UnparsedSource; + readonly kind: SyntaxKind; + readonly data?: string; } export interface UnparsedPrologue extends UnparsedSection { - kind: SyntaxKind.UnparsedPrologue; - data: string; parent: UnparsedSource; + readonly kind: SyntaxKind.UnparsedPrologue; + readonly data: string; } export interface UnparsedPrepend extends UnparsedSection { - kind: SyntaxKind.UnparsedPrepend; - data: string; parent: UnparsedSource; - texts: readonly UnparsedTextLike[]; + readonly kind: SyntaxKind.UnparsedPrepend; + readonly data: string; + readonly texts: readonly UnparsedTextLike[]; } export interface UnparsedTextLike extends UnparsedSection { - kind: SyntaxKind.UnparsedText | SyntaxKind.UnparsedInternalText; parent: UnparsedSource; + readonly kind: SyntaxKind.UnparsedText | SyntaxKind.UnparsedInternalText; } export interface UnparsedSyntheticReference extends UnparsedSection { - kind: SyntaxKind.UnparsedSyntheticReference; parent: UnparsedSource; - /*@internal*/ section: BundleFileHasNoDefaultLib | BundleFileReference; + readonly kind: SyntaxKind.UnparsedSyntheticReference; + /*@internal*/ readonly section: BundleFileHasNoDefaultLib | BundleFileReference; } export interface JsonSourceFile extends SourceFile { - statements: NodeArray; + readonly statements: NodeArray; } export interface TsConfigSourceFile extends JsonSourceFile { @@ -3279,13 +3442,23 @@ namespace ts { } export interface JsonMinusNumericLiteral extends PrefixUnaryExpression { - kind: SyntaxKind.PrefixUnaryExpression; - operator: SyntaxKind.MinusToken; - operand: NumericLiteral; + readonly kind: SyntaxKind.PrefixUnaryExpression; + readonly operator: SyntaxKind.MinusToken; + readonly operand: NumericLiteral; } + export type JsonObjectExpression = + | ObjectLiteralExpression + | ArrayLiteralExpression + | JsonMinusNumericLiteral + | NumericLiteral + | StringLiteral + | BooleanLiteral + | NullLiteral + ; + export interface JsonObjectExpressionStatement extends ExpressionStatement { - expression: ObjectLiteralExpression | ArrayLiteralExpression | JsonMinusNumericLiteral | NumericLiteral | StringLiteral | BooleanLiteral | NullLiteral; + readonly expression: JsonObjectExpression; } export interface ScriptReferenceHost { @@ -6245,7 +6418,7 @@ namespace ts { createInferTypeNode(typeParameter: TypeParameterDeclaration): InferTypeNode; updateInferTypeNode(node: InferTypeNode, typeParameter: TypeParameterDeclaration): InferTypeNode; createImportTypeNode(argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; - updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; + updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode; createParenthesizedType(type: TypeNode): ParenthesizedTypeNode; updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode; createThisTypeNode(): ThisTypeNode; @@ -6538,7 +6711,7 @@ namespace ts { // Top-level nodes // - createSourceFile(statements: readonly Statement[], endOfFileToken: EndOfFileToken): SourceFile; + createSourceFile(statements: readonly Statement[], endOfFileToken: EndOfFileToken, flags: NodeFlags): SourceFile; updateSourceFile(node: SourceFile, statements: readonly Statement[], isDeclarationFile?: boolean, referencedFiles?: readonly FileReference[], typeReferences?: readonly FileReference[], hasNoDefaultLib?: boolean, libReferences?: readonly FileReference[]): SourceFile; /* @internal */ createUnparsedSource(prologues: readonly UnparsedPrologue[], syntheticReferences: readonly UnparsedSyntheticReference[] | undefined, texts: readonly UnparsedSourceText[]): UnparsedSource; @@ -6736,8 +6909,10 @@ namespace ts { * Creates a shallow, memberwise clone of a node. * - The result will have its `original` pointer set to `node`. * - The result will have its `pos` and `end` set to `-1`. + * - *DO NOT USE THIS* if a more appropriate function is available. */ /* @internal */ cloneNode(node: T): T; + /* @internal */ updateModifiers(node: T, modifiers: readonly Modifier[] | ModifierFlags): T; } export interface CoreTransformationContext { @@ -6861,6 +7036,16 @@ namespace ts { */ export type Visitor = (node: Node) => VisitResult; + export interface NodeVisitor { + (nodes: T, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T; + (nodes: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T | undefined; + } + + export interface NodesVisitor { + (nodes: NodeArray, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; + (nodes: NodeArray | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; + } + export type VisitResult = T | T[] | undefined; export interface Printer { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 26bda84dc2c6e..e6f9dbd6f0759 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -298,13 +298,13 @@ namespace ts { // If so, mark ourselves accordingly. if (thisNodeOrAnySubNodesHasError) { - node.flags |= NodeFlags.ThisNodeOrAnySubNodesHasError; + (node as Mutable).flags |= NodeFlags.ThisNodeOrAnySubNodesHasError; } // Also mark that we've propagated the child information to this node. This way we can // always consult the bit directly on this node without needing to check its children // again. - node.flags |= NodeFlags.HasAggregatedChildData; + (node as Mutable).flags |= NodeFlags.HasAggregatedChildData; } } @@ -4792,7 +4792,7 @@ namespace ts { return filter(node.declarations, isInitializedVariable); } - function isInitializedVariable(node: VariableDeclaration) { + function isInitializedVariable(node: VariableDeclaration): node is InitializedVariableDeclaration { return node.initializer !== undefined; } @@ -7114,7 +7114,7 @@ namespace ts { } } - function Node(this: Node, kind: SyntaxKind, pos: number, end: number) { + function Node(this: Mutable, kind: SyntaxKind, pos: number, end: number) { this.pos = pos; this.end = end; this.kind = kind; diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 44e1c56e3e42f..396ce5c92816c 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -9,8 +9,7 @@ namespace ts { * @param test A callback to execute to verify the Node is valid. * @param lift An optional callback to execute to lift a NodeArray into a valid Node. */ - export function visitNode(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T; - + export function visitNode(node: T, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T; /** * Visits a Node using the supplied visitor, possibly returning a new Node in its place. * @@ -20,7 +19,6 @@ namespace ts { * @param lift An optional callback to execute to lift a NodeArray into a valid Node. */ export function visitNode(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T | undefined; - export function visitNode(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T | undefined { if (node === undefined || visitor === undefined) { return node; @@ -55,8 +53,7 @@ namespace ts { * @param start An optional value indicating the starting offset at which to start visiting. * @param count An optional value indicating the maximum number of nodes to visit. */ - export function visitNodes(nodes: NodeArray | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; - + export function visitNodes(nodes: NodeArray, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; /** * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. * @@ -66,8 +63,7 @@ namespace ts { * @param start An optional value indicating the starting offset at which to start visiting. * @param count An optional value indicating the maximum number of nodes to visit. */ - export function visitNodes(nodes: NodeArray | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; - + export function visitNodes(nodes: NodeArray | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; /** * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. * @@ -77,7 +73,7 @@ namespace ts { * @param start An optional value indicating the starting offset at which to start visiting. * @param count An optional value indicating the maximum number of nodes to visit. */ - export function visitNodes(nodes: NodeArray | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined { + export function visitNodes(nodes: NodeArray | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined { if (nodes === undefined || visitor === undefined) { return nodes; } @@ -147,9 +143,9 @@ namespace ts { * Starts a new lexical environment and visits a statement list, ending the lexical environment * and merging hoisted declarations upon completion. */ - export function visitLexicalEnvironment(statements: NodeArray, visitor: Visitor, context: TransformationContext, start?: number, ensureUseStrict?: boolean) { + export function visitLexicalEnvironment(statements: NodeArray, visitor: Visitor, context: TransformationContext, start?: number, ensureUseStrict?: boolean, nodesVisitor: NodesVisitor = visitNodes) { context.startLexicalEnvironment(); - statements = visitNodes(statements, visitor, isStatement, start); + statements = nodesVisitor(statements, visitor, isStatement, start); if (ensureUseStrict) statements = context.factory.ensureUseStrict(statements); return mergeLexicalEnvironment(statements, context.endLexicalEnvironment(), context.factory); } @@ -158,6 +154,12 @@ namespace ts { * Starts a new lexical environment and visits a parameter list, suspending the lexical * environment upon completion. */ + export function visitParameterList(nodes: NodeArray, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray; + /** + * Starts a new lexical environment and visits a parameter list, suspending the lexical + * environment upon completion. + */ + export function visitParameterList(nodes: NodeArray | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray | undefined; export function visitParameterList(nodes: NodeArray | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor = visitNodes) { context.startLexicalEnvironment(); const updated = nodesVisitor(nodes, visitor, isParameterDeclaration); @@ -180,11 +182,17 @@ namespace ts { * environment and merging hoisted declarations upon completion. */ export function visitFunctionBody(node: ConciseBody, visitor: Visitor, context: TransformationContext): ConciseBody; - export function visitFunctionBody(node: ConciseBody | undefined, visitor: Visitor, context: TransformationContext): ConciseBody | undefined { + /* @internal*/ export function visitFunctionBody(node: FunctionBody, visitor: Visitor, context: TransformationContext, nodeVisitor?: NodeVisitor): FunctionBody; // eslint-disable-line @typescript-eslint/unified-signatures + /* @internal*/ export function visitFunctionBody(node: FunctionBody | undefined, visitor: Visitor, context: TransformationContext, nodeVisitor?: NodeVisitor): FunctionBody | undefined; // eslint-disable-line @typescript-eslint/unified-signatures + /* @internal*/ export function visitFunctionBody(node: ConciseBody, visitor: Visitor, context: TransformationContext, nodeVisitor?: NodeVisitor): ConciseBody; // eslint-disable-line @typescript-eslint/unified-signatures + export function visitFunctionBody(node: ConciseBody | undefined, visitor: Visitor, context: TransformationContext, nodeVisitor: NodeVisitor = visitNode): ConciseBody | undefined { context.resumeLexicalEnvironment(); - const updated = visitNode(node, visitor, isConciseBody); + const updated = nodeVisitor(node, visitor, isConciseBody); const declarations = context.endLexicalEnvironment(); if (some(declarations)) { + if (!updated) { + return context.factory.createBlock(declarations); + } const block = context.factory.converters.convertToFunctionBlock(updated); const statements = mergeLexicalEnvironment(block.statements, declarations); return context.factory.updateBlock(block, statements); @@ -200,7 +208,6 @@ namespace ts { * @param context A lexical environment context for the visitor. */ export function visitEachChild(node: T, visitor: Visitor, context: TransformationContext): T; - /** * Visits each child of a Node using the supplied visitor, possibly returning a new Node of the same kind in its place. * @@ -208,9 +215,10 @@ namespace ts { * @param visitor The callback used to visit each child. * @param context A lexical environment context for the visitor. */ - export function visitEachChild(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined; - - export function visitEachChild(node: Node | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor = visitNodes, tokenVisitor?: Visitor): Node | undefined { + export function visitEachChild(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor, tokenVisitor?: Visitor): T | undefined; + /* @internal */ + export function visitEachChild(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor, tokenVisitor?: Visitor, nodeVisitor?: NodeVisitor): T | undefined; // eslint-disable-line @typescript-eslint/unified-signatures + export function visitEachChild(node: Node | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor: NodesVisitor = visitNodes, tokenVisitor?: Visitor, nodeVisitor: NodeVisitor = visitNode): Node | undefined { if (node === undefined) { return undefined; } @@ -227,147 +235,148 @@ namespace ts { // Names case SyntaxKind.Identifier: - return factory.updateIdentifier(node, nodesVisitor((node).typeArguments, visitor, isTypeNodeOrTypeParameterDeclaration)); + return factory.updateIdentifier(node, + nodesVisitor((node).typeArguments, visitor, isTypeNodeOrTypeParameterDeclaration)); case SyntaxKind.QualifiedName: return factory.updateQualifiedName(node, - visitNode((node).left, visitor, isEntityName), - visitNode((node).right, visitor, isIdentifier)); + nodeVisitor((node).left, visitor, isEntityName), + nodeVisitor((node).right, visitor, isIdentifier)); case SyntaxKind.ComputedPropertyName: return factory.updateComputedPropertyName(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); // Signature elements case SyntaxKind.TypeParameter: return factory.updateTypeParameterDeclaration(node, - visitNode((node).name, visitor, isIdentifier), - visitNode((node).constraint, visitor, isTypeNode), - visitNode((node).default, visitor, isTypeNode)); + nodeVisitor((node).name, visitor, isIdentifier), + nodeVisitor((node).constraint, visitor, isTypeNode), + nodeVisitor((node).default, visitor, isTypeNode)); case SyntaxKind.Parameter: return factory.updateParameterDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).dotDotDotToken, tokenVisitor, isToken), - visitNode((node).name, visitor, isBindingName), - visitNode((node).questionToken, tokenVisitor, isToken), - visitNode((node).type, visitor, isTypeNode), - visitNode((node).initializer, visitor, isExpression)); + nodeVisitor((node).dotDotDotToken, tokenVisitor, isToken), + nodeVisitor((node).name, visitor, isBindingName), + nodeVisitor((node).questionToken, tokenVisitor, isToken), + nodeVisitor((node).type, visitor, isTypeNode), + nodeVisitor((node).initializer, visitor, isExpression)); case SyntaxKind.Decorator: return factory.updateDecorator(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); // Type elements case SyntaxKind.PropertySignature: return factory.updatePropertySignature((node), nodesVisitor((node).modifiers, visitor, isToken), - visitNode((node).name, visitor, isPropertyName), - visitNode((node).questionToken, tokenVisitor, isToken), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).name, visitor, isPropertyName), + nodeVisitor((node).questionToken, tokenVisitor, isToken), + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.PropertyDeclaration: return factory.updatePropertyDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).name, visitor, isPropertyName), + nodeVisitor((node).name, visitor, isPropertyName), // QuestionToken and ExclamationToken is uniqued in Property Declaration and the signature of 'updateProperty' is that too - visitNode((node).questionToken || (node).exclamationToken, tokenVisitor, isToken), - visitNode((node).type, visitor, isTypeNode), - visitNode((node).initializer, visitor, isExpression)); + nodeVisitor((node).questionToken || (node).exclamationToken, tokenVisitor, isToken), + nodeVisitor((node).type, visitor, isTypeNode), + nodeVisitor((node).initializer, visitor, isExpression)); case SyntaxKind.MethodSignature: return factory.updateMethodSignature(node, nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).name, visitor, isPropertyName), - visitNode((node).questionToken, tokenVisitor, isToken), + nodeVisitor((node).name, visitor, isPropertyName), + nodeVisitor((node).questionToken, tokenVisitor, isToken), nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).parameters, visitor, isParameterDeclaration), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.MethodDeclaration: return factory.updateMethodDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).asteriskToken, tokenVisitor, isToken), - visitNode((node).name, visitor, isPropertyName), - visitNode((node).questionToken, tokenVisitor, isToken), + nodeVisitor((node).asteriskToken, tokenVisitor, isToken), + nodeVisitor((node).name, visitor, isPropertyName), + nodeVisitor((node).questionToken, tokenVisitor, isToken), nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), visitParameterList((node).parameters, visitor, context, nodesVisitor), - visitNode((node).type, visitor, isTypeNode), - visitFunctionBody((node).body!, visitor, context)); + nodeVisitor((node).type, visitor, isTypeNode), + visitFunctionBody((node).body!, visitor, context, nodeVisitor)); case SyntaxKind.Constructor: return factory.updateConstructorDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), visitParameterList((node).parameters, visitor, context, nodesVisitor), - visitFunctionBody((node).body!, visitor, context)); + visitFunctionBody((node).body, visitor, context, nodeVisitor)); case SyntaxKind.GetAccessor: return factory.updateGetAccessorDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).name, visitor, isPropertyName), + nodeVisitor((node).name, visitor, isPropertyName), visitParameterList((node).parameters, visitor, context, nodesVisitor), - visitNode((node).type, visitor, isTypeNode), - visitFunctionBody((node).body!, visitor, context)); + nodeVisitor((node).type, visitor, isTypeNode), + visitFunctionBody((node).body, visitor, context, nodeVisitor)); case SyntaxKind.SetAccessor: return factory.updateSetAccessorDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).name, visitor, isPropertyName), + nodeVisitor((node).name, visitor, isPropertyName), visitParameterList((node).parameters, visitor, context, nodesVisitor), - visitFunctionBody((node).body!, visitor, context)); + visitFunctionBody((node).body, visitor, context, nodeVisitor)); case SyntaxKind.CallSignature: return factory.updateCallSignature(node, nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).parameters, visitor, isParameterDeclaration), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.ConstructSignature: return factory.updateConstructSignature(node, nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).parameters, visitor, isParameterDeclaration), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.IndexSignature: return factory.updateIndexSignature(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), nodesVisitor((node).parameters, visitor, isParameterDeclaration), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).type, visitor, isTypeNode)); // Types case SyntaxKind.TypePredicate: return factory.updateTypePredicateNode(node, - visitNode((node).assertsModifier, visitor), - visitNode((node).parameterName, visitor), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).assertsModifier, visitor), + nodeVisitor((node).parameterName, visitor), + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.TypeReference: return factory.updateTypeReferenceNode(node, - visitNode((node).typeName, visitor, isEntityName), + nodeVisitor((node).typeName, visitor, isEntityName), nodesVisitor((node).typeArguments, visitor, isTypeNode)); case SyntaxKind.FunctionType: return factory.updateFunctionTypeNode(node, nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).parameters, visitor, isParameterDeclaration), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.ConstructorType: return factory.updateConstructorTypeNode(node, nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).parameters, visitor, isParameterDeclaration), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.TypeQuery: return factory.updateTypeQueryNode((node), - visitNode((node).exprName, visitor, isEntityName)); + nodeVisitor((node).exprName, visitor, isEntityName)); case SyntaxKind.TypeLiteral: return factory.updateTypeLiteralNode((node), @@ -375,7 +384,7 @@ namespace ts { case SyntaxKind.ArrayType: return factory.updateArrayTypeNode(node, - visitNode((node).elementType, visitor, isTypeNode)); + nodeVisitor((node).elementType, visitor, isTypeNode)); case SyntaxKind.TupleType: return factory.updateTupleTypeNode((node), @@ -383,11 +392,11 @@ namespace ts { case SyntaxKind.OptionalType: return factory.updateOptionalTypeNode((node), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.RestType: return factory.updateRestTypeNode((node), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.UnionType: return factory.updateUnionTypeNode(node, @@ -399,46 +408,45 @@ namespace ts { case SyntaxKind.ConditionalType: return factory.updateConditionalTypeNode(node, - visitNode((node).checkType, visitor, isTypeNode), - visitNode((node).extendsType, visitor, isTypeNode), - visitNode((node).trueType, visitor, isTypeNode), - visitNode((node).falseType, visitor, isTypeNode)); + nodeVisitor((node).checkType, visitor, isTypeNode), + nodeVisitor((node).extendsType, visitor, isTypeNode), + nodeVisitor((node).trueType, visitor, isTypeNode), + nodeVisitor((node).falseType, visitor, isTypeNode)); case SyntaxKind.InferType: return factory.updateInferTypeNode(node, - visitNode((node).typeParameter, visitor, isTypeParameterDeclaration)); + nodeVisitor((node).typeParameter, visitor, isTypeParameterDeclaration)); case SyntaxKind.ImportType: return factory.updateImportTypeNode(node, - visitNode((node).argument, visitor, isTypeNode), - visitNode((node).qualifier, visitor, isEntityName), - visitNodes((node).typeArguments, visitor, isTypeNode), - (node).isTypeOf - ); + nodeVisitor((node).argument, visitor, isTypeNode), + nodeVisitor((node).qualifier, visitor, isEntityName), + nodesVisitor((node).typeArguments, visitor, isTypeNode), + (node).isTypeOf); case SyntaxKind.ParenthesizedType: return factory.updateParenthesizedType(node, - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.TypeOperator: return factory.updateTypeOperatorNode(node, - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.IndexedAccessType: return factory.updateIndexedAccessTypeNode((node), - visitNode((node).objectType, visitor, isTypeNode), - visitNode((node).indexType, visitor, isTypeNode)); + nodeVisitor((node).objectType, visitor, isTypeNode), + nodeVisitor((node).indexType, visitor, isTypeNode)); case SyntaxKind.MappedType: return factory.updateMappedTypeNode((node), - visitNode((node).readonlyToken, tokenVisitor, isToken), - visitNode((node).typeParameter, visitor, isTypeParameterDeclaration), - visitNode((node).questionToken, tokenVisitor, isToken), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).readonlyToken, tokenVisitor, isToken), + nodeVisitor((node).typeParameter, visitor, isTypeParameterDeclaration), + nodeVisitor((node).questionToken, tokenVisitor, isToken), + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.LiteralType: return factory.updateLiteralTypeNode(node, - visitNode((node).literal, visitor, isExpression)); + nodeVisitor((node).literal, visitor, isExpression)); // Binding patterns case SyntaxKind.ObjectBindingPattern: @@ -451,10 +459,10 @@ namespace ts { case SyntaxKind.BindingElement: return factory.updateBindingElement(node, - visitNode((node).dotDotDotToken, tokenVisitor, isToken), - visitNode((node).propertyName, visitor, isPropertyName), - visitNode((node).name, visitor, isBindingName), - visitNode((node).initializer, visitor, isExpression)); + nodeVisitor((node).dotDotDotToken, tokenVisitor, isToken), + nodeVisitor((node).propertyName, visitor, isPropertyName), + nodeVisitor((node).name, visitor, isBindingName), + nodeVisitor((node).initializer, visitor, isExpression)); // Expression case SyntaxKind.ArrayLiteralExpression: @@ -468,162 +476,162 @@ namespace ts { case SyntaxKind.PropertyAccessExpression: if (node.flags & NodeFlags.OptionalChain) { return factory.updatePropertyAccessChain(node, - visitNode((node).expression, visitor, isExpression), - visitNode((node).questionDotToken, visitor, isToken), - visitNode((node).name, visitor, isIdentifier)); + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).questionDotToken, visitor, isToken), + nodeVisitor((node).name, visitor, isIdentifier)); } return factory.updatePropertyAccess(node, - visitNode((node).expression, visitor, isExpression), - visitNode((node).name, visitor, isIdentifier)); + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).name, visitor, isIdentifier)); case SyntaxKind.ElementAccessExpression: if (node.flags & NodeFlags.OptionalChain) { return factory.updateElementAccessChain(node, - visitNode((node).expression, visitor, isExpression), - visitNode((node).questionDotToken, visitor, isToken), - visitNode((node).argumentExpression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).questionDotToken, visitor, isToken), + nodeVisitor((node).argumentExpression, visitor, isExpression)); } return factory.updateElementAccess(node, - visitNode((node).expression, visitor, isExpression), - visitNode((node).argumentExpression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).argumentExpression, visitor, isExpression)); case SyntaxKind.CallExpression: if (node.flags & NodeFlags.OptionalChain) { return factory.updateCallChain(node, - visitNode((node).expression, visitor, isExpression), - visitNode((node).questionDotToken, visitor, isToken), + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).questionDotToken, visitor, isToken), nodesVisitor((node).typeArguments, visitor, isTypeNode), nodesVisitor((node).arguments, visitor, isExpression)); } return factory.updateCall(node, - visitNode((node).expression, visitor, isExpression), + nodeVisitor((node).expression, visitor, isExpression), nodesVisitor((node).typeArguments, visitor, isTypeNode), nodesVisitor((node).arguments, visitor, isExpression)); case SyntaxKind.NewExpression: return factory.updateNew(node, - visitNode((node).expression, visitor, isExpression), + nodeVisitor((node).expression, visitor, isExpression), nodesVisitor((node).typeArguments, visitor, isTypeNode), nodesVisitor((node).arguments, visitor, isExpression)); case SyntaxKind.TaggedTemplateExpression: return factory.updateTaggedTemplate(node, - visitNode((node).tag, visitor, isExpression), - visitNodes((node).typeArguments, visitor, isExpression), - visitNode((node).template, visitor, isTemplateLiteral)); + nodeVisitor((node).tag, visitor, isExpression), + nodesVisitor((node).typeArguments, visitor, isExpression), + nodeVisitor((node).template, visitor, isTemplateLiteral)); case SyntaxKind.TypeAssertionExpression: return factory.updateTypeAssertion(node, - visitNode((node).type, visitor, isTypeNode), - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).type, visitor, isTypeNode), + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.ParenthesizedExpression: return factory.updateParen(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.FunctionExpression: return factory.updateFunctionExpression(node, nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).asteriskToken, tokenVisitor, isToken), - visitNode((node).name, visitor, isIdentifier), + nodeVisitor((node).asteriskToken, tokenVisitor, isToken), + nodeVisitor((node).name, visitor, isIdentifier), nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), visitParameterList((node).parameters, visitor, context, nodesVisitor), - visitNode((node).type, visitor, isTypeNode), - visitFunctionBody((node).body, visitor, context)); + nodeVisitor((node).type, visitor, isTypeNode), + visitFunctionBody((node).body, visitor, context, nodeVisitor)); case SyntaxKind.ArrowFunction: return factory.updateArrowFunction(node, nodesVisitor((node).modifiers, visitor, isModifier), nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), visitParameterList((node).parameters, visitor, context, nodesVisitor), - visitNode((node).type, visitor, isTypeNode), - visitNode((node).equalsGreaterThanToken, visitor, isToken), - visitFunctionBody((node).body, visitor, context)); + nodeVisitor((node).type, visitor, isTypeNode), + nodeVisitor((node).equalsGreaterThanToken, visitor, isToken), + visitFunctionBody((node).body, visitor, context, nodeVisitor)); case SyntaxKind.DeleteExpression: return factory.updateDelete(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.TypeOfExpression: return factory.updateTypeOf(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.VoidExpression: return factory.updateVoid(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.AwaitExpression: return factory.updateAwait(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.PrefixUnaryExpression: return factory.updatePrefix(node, - visitNode((node).operand, visitor, isExpression)); + nodeVisitor((node).operand, visitor, isExpression)); case SyntaxKind.PostfixUnaryExpression: return factory.updatePostfix(node, - visitNode((node).operand, visitor, isExpression)); + nodeVisitor((node).operand, visitor, isExpression)); case SyntaxKind.BinaryExpression: return factory.updateBinary(node, - visitNode((node).left, visitor, isExpression), - visitNode((node).right, visitor, isExpression), - visitNode((node).operatorToken, visitor, isToken)); + nodeVisitor((node).left, visitor, isExpression), + nodeVisitor((node).right, visitor, isExpression), + nodeVisitor((node).operatorToken, visitor, isToken)); case SyntaxKind.ConditionalExpression: return factory.updateConditional(node, - visitNode((node).condition, visitor, isExpression), - visitNode((node).questionToken, visitor, isToken), - visitNode((node).whenTrue, visitor, isExpression), - visitNode((node).colonToken, visitor, isToken), - visitNode((node).whenFalse, visitor, isExpression)); + nodeVisitor((node).condition, visitor, isExpression), + nodeVisitor((node).questionToken, visitor, isToken), + nodeVisitor((node).whenTrue, visitor, isExpression), + nodeVisitor((node).colonToken, visitor, isToken), + nodeVisitor((node).whenFalse, visitor, isExpression)); case SyntaxKind.TemplateExpression: return factory.updateTemplateExpression(node, - visitNode((node).head, visitor, isTemplateHead), + nodeVisitor((node).head, visitor, isTemplateHead), nodesVisitor((node).templateSpans, visitor, isTemplateSpan)); case SyntaxKind.YieldExpression: return factory.updateYield(node, - visitNode((node).asteriskToken, tokenVisitor, isToken), - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).asteriskToken, tokenVisitor, isToken), + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.SpreadElement: return factory.updateSpread(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.ClassExpression: return factory.updateClassExpression(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).name, visitor, isIdentifier), + nodeVisitor((node).name, visitor, isIdentifier), nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).heritageClauses, visitor, isHeritageClause), nodesVisitor((node).members, visitor, isClassElement)); case SyntaxKind.ExpressionWithTypeArguments: return factory.updateExpressionWithTypeArguments(node, - visitNode((node).expression, visitor, isExpression), + nodeVisitor((node).expression, visitor, isExpression), nodesVisitor((node).typeArguments, visitor, isTypeNode)); case SyntaxKind.AsExpression: return factory.updateAsExpression(node, - visitNode((node).expression, visitor, isExpression), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.NonNullExpression: return factory.updateNonNullExpression(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.MetaProperty: return factory.updateMetaProperty(node, - visitNode((node).name, visitor, isIdentifier)); + nodeVisitor((node).name, visitor, isIdentifier)); // Misc case SyntaxKind.TemplateSpan: return factory.updateTemplateSpan(node, - visitNode((node).expression, visitor, isExpression), - visitNode((node).literal, visitor, isTemplateMiddleOrTemplateTail)); + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).literal, visitor, isTemplateMiddleOrTemplateTail)); // Element case SyntaxKind.Block: @@ -633,91 +641,91 @@ namespace ts { case SyntaxKind.VariableStatement: return factory.updateVariableStatement(node, nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).declarationList, visitor, isVariableDeclarationList)); + nodeVisitor((node).declarationList, visitor, isVariableDeclarationList)); case SyntaxKind.ExpressionStatement: return factory.updateExpressionStatement(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.IfStatement: return factory.updateIf(node, - visitNode((node).expression, visitor, isExpression), - visitNode((node).thenStatement, visitor, isStatement, factory.liftToBlock), - visitNode((node).elseStatement, visitor, isStatement, factory.liftToBlock)); + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).thenStatement, visitor, isStatement, factory.liftToBlock), + nodeVisitor((node).elseStatement, visitor, isStatement, factory.liftToBlock)); case SyntaxKind.DoStatement: return factory.updateDo(node, - visitNode((node).statement, visitor, isStatement, factory.liftToBlock), - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).statement, visitor, isStatement, factory.liftToBlock), + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.WhileStatement: return factory.updateWhile(node, - visitNode((node).expression, visitor, isExpression), - visitNode((node).statement, visitor, isStatement, factory.liftToBlock)); + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).statement, visitor, isStatement, factory.liftToBlock)); case SyntaxKind.ForStatement: return factory.updateFor(node, - visitNode((node).initializer, visitor, isForInitializer), - visitNode((node).condition, visitor, isExpression), - visitNode((node).incrementor, visitor, isExpression), - visitNode((node).statement, visitor, isStatement, factory.liftToBlock)); + nodeVisitor((node).initializer, visitor, isForInitializer), + nodeVisitor((node).condition, visitor, isExpression), + nodeVisitor((node).incrementor, visitor, isExpression), + nodeVisitor((node).statement, visitor, isStatement, factory.liftToBlock)); case SyntaxKind.ForInStatement: return factory.updateForIn(node, - visitNode((node).initializer, visitor, isForInitializer), - visitNode((node).expression, visitor, isExpression), - visitNode((node).statement, visitor, isStatement, factory.liftToBlock)); + nodeVisitor((node).initializer, visitor, isForInitializer), + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).statement, visitor, isStatement, factory.liftToBlock)); case SyntaxKind.ForOfStatement: return factory.updateForOf(node, - visitNode((node).awaitModifier, visitor, isToken), - visitNode((node).initializer, visitor, isForInitializer), - visitNode((node).expression, visitor, isExpression), - visitNode((node).statement, visitor, isStatement, factory.liftToBlock)); + nodeVisitor((node).awaitModifier, visitor, isToken), + nodeVisitor((node).initializer, visitor, isForInitializer), + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).statement, visitor, isStatement, factory.liftToBlock)); case SyntaxKind.ContinueStatement: return factory.updateContinue(node, - visitNode((node).label, visitor, isIdentifier)); + nodeVisitor((node).label, visitor, isIdentifier)); case SyntaxKind.BreakStatement: return factory.updateBreak(node, - visitNode((node).label, visitor, isIdentifier)); + nodeVisitor((node).label, visitor, isIdentifier)); case SyntaxKind.ReturnStatement: return factory.updateReturn(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.WithStatement: return factory.updateWith(node, - visitNode((node).expression, visitor, isExpression), - visitNode((node).statement, visitor, isStatement, factory.liftToBlock)); + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).statement, visitor, isStatement, factory.liftToBlock)); case SyntaxKind.SwitchStatement: return factory.updateSwitch(node, - visitNode((node).expression, visitor, isExpression), - visitNode((node).caseBlock, visitor, isCaseBlock)); + nodeVisitor((node).expression, visitor, isExpression), + nodeVisitor((node).caseBlock, visitor, isCaseBlock)); case SyntaxKind.LabeledStatement: return factory.updateLabel(node, - visitNode((node).label, visitor, isIdentifier), - visitNode((node).statement, visitor, isStatement, factory.liftToBlock)); + nodeVisitor((node).label, visitor, isIdentifier), + nodeVisitor((node).statement, visitor, isStatement, factory.liftToBlock)); case SyntaxKind.ThrowStatement: return factory.updateThrow(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression!, visitor, isExpression)); // expression could be `undefined` due to invalid parse. case SyntaxKind.TryStatement: return factory.updateTry(node, - visitNode((node).tryBlock, visitor, isBlock), - visitNode((node).catchClause, visitor, isCatchClause), - visitNode((node).finallyBlock, visitor, isBlock)); + nodeVisitor((node).tryBlock, visitor, isBlock), + nodeVisitor((node).catchClause, visitor, isCatchClause), + nodeVisitor((node).finallyBlock, visitor, isBlock)); case SyntaxKind.VariableDeclaration: return factory.updateVariableDeclaration(node, - visitNode((node).name, visitor, isBindingName), - visitNode((node).exclamationToken, visitor, isToken), - visitNode((node).type, visitor, isTypeNode), - visitNode((node).initializer, visitor, isExpression)); + nodeVisitor((node).name, visitor, isBindingName), + nodeVisitor((node).exclamationToken, visitor, isToken), + nodeVisitor((node).type, visitor, isTypeNode), + nodeVisitor((node).initializer, visitor, isExpression)); case SyntaxKind.VariableDeclarationList: return factory.updateVariableDeclarationList(node, @@ -727,18 +735,18 @@ namespace ts { return factory.updateFunctionDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).asteriskToken, tokenVisitor, isToken), - visitNode((node).name, visitor, isIdentifier), + nodeVisitor((node).asteriskToken, tokenVisitor, isToken), + nodeVisitor((node).name, visitor, isIdentifier), nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), visitParameterList((node).parameters, visitor, context, nodesVisitor), - visitNode((node).type, visitor, isTypeNode), - visitFunctionBody((node).body, visitor, context)); + nodeVisitor((node).type, visitor, isTypeNode), + visitFunctionBody((node).body, visitor, context, nodeVisitor)); case SyntaxKind.ClassDeclaration: return factory.updateClassDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).name, visitor, isIdentifier), + nodeVisitor((node).name, visitor, isIdentifier), nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).heritageClauses, visitor, isHeritageClause), nodesVisitor((node).members, visitor, isClassElement)); @@ -747,7 +755,7 @@ namespace ts { return factory.updateInterfaceDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).name, visitor, isIdentifier), + nodeVisitor((node).name, visitor, isIdentifier), nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).heritageClauses, visitor, isHeritageClause), nodesVisitor((node).members, visitor, isTypeElement)); @@ -756,23 +764,23 @@ namespace ts { return factory.updateTypeAliasDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).name, visitor, isIdentifier), + nodeVisitor((node).name, visitor, isIdentifier), nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), - visitNode((node).type, visitor, isTypeNode)); + nodeVisitor((node).type, visitor, isTypeNode)); case SyntaxKind.EnumDeclaration: return factory.updateEnumDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).name, visitor, isIdentifier), + nodeVisitor((node).name, visitor, isIdentifier), nodesVisitor((node).members, visitor, isEnumMember)); case SyntaxKind.ModuleDeclaration: return factory.updateModuleDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).name, visitor, isIdentifier), - visitNode((node).body, visitor, isModuleBody)); + nodeVisitor((node).name, visitor, isIdentifier), + nodeVisitor((node).body, visitor, isModuleBody)); case SyntaxKind.ModuleBlock: return factory.updateModuleBlock(node, @@ -784,30 +792,30 @@ namespace ts { case SyntaxKind.NamespaceExportDeclaration: return factory.updateNamespaceExportDeclaration(node, - visitNode((node).name, visitor, isIdentifier)); + nodeVisitor((node).name, visitor, isIdentifier)); case SyntaxKind.ImportEqualsDeclaration: return factory.updateImportEqualsDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).name, visitor, isIdentifier), - visitNode((node).moduleReference, visitor, isModuleReference)); + nodeVisitor((node).name, visitor, isIdentifier), + nodeVisitor((node).moduleReference, visitor, isModuleReference)); case SyntaxKind.ImportDeclaration: return factory.updateImportDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).importClause, visitor, isImportClause), - visitNode((node).moduleSpecifier, visitor, isExpression)); + nodeVisitor((node).importClause, visitor, isImportClause), + nodeVisitor((node).moduleSpecifier, visitor, isExpression)); case SyntaxKind.ImportClause: return factory.updateImportClause(node, - visitNode((node).name, visitor, isIdentifier), - visitNode((node).namedBindings, visitor, isNamedImportBindings)); + nodeVisitor((node).name, visitor, isIdentifier), + nodeVisitor((node).namedBindings, visitor, isNamedImportBindings)); case SyntaxKind.NamespaceImport: return factory.updateNamespaceImport(node, - visitNode((node).name, visitor, isIdentifier)); + nodeVisitor((node).name, visitor, isIdentifier)); case SyntaxKind.NamedImports: return factory.updateNamedImports(node, @@ -815,21 +823,21 @@ namespace ts { case SyntaxKind.ImportSpecifier: return factory.updateImportSpecifier(node, - visitNode((node).propertyName, visitor, isIdentifier), - visitNode((node).name, visitor, isIdentifier)); + nodeVisitor((node).propertyName, visitor, isIdentifier), + nodeVisitor((node).name, visitor, isIdentifier)); case SyntaxKind.ExportAssignment: return factory.updateExportAssignment(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.ExportDeclaration: return factory.updateExportDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).exportClause, visitor, isNamedExports), - visitNode((node).moduleSpecifier, visitor, isExpression)); + nodeVisitor((node).exportClause, visitor, isNamedExports), + nodeVisitor((node).moduleSpecifier, visitor, isExpression)); case SyntaxKind.NamedExports: return factory.updateNamedExports(node, @@ -837,47 +845,47 @@ namespace ts { case SyntaxKind.ExportSpecifier: return factory.updateExportSpecifier(node, - visitNode((node).propertyName, visitor, isIdentifier), - visitNode((node).name, visitor, isIdentifier)); + nodeVisitor((node).propertyName, visitor, isIdentifier), + nodeVisitor((node).name, visitor, isIdentifier)); // Module references case SyntaxKind.ExternalModuleReference: return factory.updateExternalModuleReference(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); // JSX case SyntaxKind.JsxElement: return factory.updateJsxElement(node, - visitNode((node).openingElement, visitor, isJsxOpeningElement), + nodeVisitor((node).openingElement, visitor, isJsxOpeningElement), nodesVisitor((node).children, visitor, isJsxChild), - visitNode((node).closingElement, visitor, isJsxClosingElement)); + nodeVisitor((node).closingElement, visitor, isJsxClosingElement)); case SyntaxKind.JsxSelfClosingElement: return factory.updateJsxSelfClosingElement(node, - visitNode((node).tagName, visitor, isJsxTagNameExpression), + nodeVisitor((node).tagName, visitor, isJsxTagNameExpression), nodesVisitor((node).typeArguments, visitor, isTypeNode), - visitNode((node).attributes, visitor, isJsxAttributes)); + nodeVisitor((node).attributes, visitor, isJsxAttributes)); case SyntaxKind.JsxOpeningElement: return factory.updateJsxOpeningElement(node, - visitNode((node).tagName, visitor, isJsxTagNameExpression), + nodeVisitor((node).tagName, visitor, isJsxTagNameExpression), nodesVisitor((node).typeArguments, visitor, isTypeNode), - visitNode((node).attributes, visitor, isJsxAttributes)); + nodeVisitor((node).attributes, visitor, isJsxAttributes)); case SyntaxKind.JsxClosingElement: return factory.updateJsxClosingElement(node, - visitNode((node).tagName, visitor, isJsxTagNameExpression)); + nodeVisitor((node).tagName, visitor, isJsxTagNameExpression)); case SyntaxKind.JsxFragment: return factory.updateJsxFragment(node, - visitNode((node).openingFragment, visitor, isJsxOpeningFragment), + nodeVisitor((node).openingFragment, visitor, isJsxOpeningFragment), nodesVisitor((node).children, visitor, isJsxChild), - visitNode((node).closingFragment, visitor, isJsxClosingFragment)); + nodeVisitor((node).closingFragment, visitor, isJsxClosingFragment)); case SyntaxKind.JsxAttribute: return factory.updateJsxAttribute(node, - visitNode((node).name, visitor, isIdentifier), - visitNode((node).initializer, visitor, isStringLiteralOrJsxExpression)); + nodeVisitor((node).name, visitor, isIdentifier), + nodeVisitor((node).initializer, visitor, isStringLiteralOrJsxExpression)); case SyntaxKind.JsxAttributes: return factory.updateJsxAttributes(node, @@ -885,16 +893,16 @@ namespace ts { case SyntaxKind.JsxSpreadAttribute: return factory.updateJsxSpreadAttribute(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.JsxExpression: return factory.updateJsxExpression(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); // Clauses case SyntaxKind.CaseClause: return factory.updateCaseClause(node, - visitNode((node).expression, visitor, isExpression), + nodeVisitor((node).expression, visitor, isExpression), nodesVisitor((node).statements, visitor, isStatement)); case SyntaxKind.DefaultClause: @@ -907,29 +915,29 @@ namespace ts { case SyntaxKind.CatchClause: return factory.updateCatchClause(node, - visitNode((node).variableDeclaration, visitor, isVariableDeclaration), - visitNode((node).block, visitor, isBlock)); + nodeVisitor((node).variableDeclaration, visitor, isVariableDeclaration), + nodeVisitor((node).block, visitor, isBlock)); // Property assignments case SyntaxKind.PropertyAssignment: return factory.updatePropertyAssignment(node, - visitNode((node).name, visitor, isPropertyName), - visitNode((node).initializer, visitor, isExpression)); + nodeVisitor((node).name, visitor, isPropertyName), + nodeVisitor((node).initializer, visitor, isExpression)); case SyntaxKind.ShorthandPropertyAssignment: return factory.updateShorthandPropertyAssignment(node, - visitNode((node).name, visitor, isIdentifier), - visitNode((node).objectAssignmentInitializer, visitor, isExpression)); + nodeVisitor((node).name, visitor, isIdentifier), + nodeVisitor((node).objectAssignmentInitializer, visitor, isExpression)); case SyntaxKind.SpreadAssignment: return factory.updateSpreadAssignment(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); // Enum case SyntaxKind.EnumMember: return factory.updateEnumMember(node, - visitNode((node).name, visitor, isPropertyName), - visitNode((node).initializer, visitor, isExpression)); + nodeVisitor((node).name, visitor, isPropertyName), + nodeVisitor((node).initializer, visitor, isExpression)); // Top-level nodes case SyntaxKind.SourceFile: @@ -939,7 +947,7 @@ namespace ts { // Transformation nodes case SyntaxKind.PartiallyEmittedExpression: return factory.updatePartiallyEmittedExpression(node, - visitNode((node).expression, visitor, isExpression)); + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.CommaListExpression: return factory.updateCommaList(node, diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 00f9f4a73e29b..a48aaebcc84d8 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1777,9 +1777,6 @@ namespace ts.server { const configFileContent = this.host.readFile(configFilename)!; // TODO: GH#18217 const result = parseJsonText(configFilename, configFileContent); - if (!result.endOfFileToken) { - result.endOfFileToken = { kind: SyntaxKind.EndOfFileToken }; - } const configFileErrors = result.parseDiagnostics as Diagnostic[]; const parsedCommandLine = parseJsonSourceFileConfigFileContent( result, diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index cc58db24a7c01..4006ba00be2e6 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -155,17 +155,23 @@ namespace ts.codefix { body: Block | undefined, ): MethodDeclaration | undefined { const program = context.program; - const signatureDeclaration = program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation | NodeBuilderFlags.SuppressAnyReturnType, getNoopSymbolTrackerWithResolver(context)); - if (!signatureDeclaration) { + const node = program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation | NodeBuilderFlags.SuppressAnyReturnType, getNoopSymbolTrackerWithResolver(context)); + if (!node) { return undefined; } - signatureDeclaration.decorators = undefined; - signatureDeclaration.modifiers = modifiers; - signatureDeclaration.name = name; - signatureDeclaration.questionToken = optional ? factory.createToken(SyntaxKind.QuestionToken) : undefined; - signatureDeclaration.body = body; - return signatureDeclaration; + return factory.updateMethodDeclaration( + node, + /*decorators*/ undefined, + modifiers, + node.asteriskToken, + name, + optional ? factory.createToken(SyntaxKind.QuestionToken) : undefined, + node.typeParameters, + node.parameters, + node.type, + body + ); } export function createMethodFromCallExpression( diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 5534624135bf0..cc94e17b35112 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -1262,13 +1262,13 @@ namespace ts.refactor.extractSymbol { } function visitor(node: Node): VisitResult { - if (!ignoreReturns && node.kind === SyntaxKind.ReturnStatement && hasWritesOrVariableDeclarations) { + if (!ignoreReturns && isReturnStatement(node) && hasWritesOrVariableDeclarations) { const assignments: ObjectLiteralElementLike[] = getPropertyAssignmentsForWritesAndVariableDeclarations(exposedVariableDeclarations, writes); - if ((node).expression) { + if (node.expression) { if (!returnValueProperty) { returnValueProperty = "__return"; } - assignments.unshift(factory.createPropertyAssignment(returnValueProperty, visitNode((node).expression, visitor))); + assignments.unshift(factory.createPropertyAssignment(returnValueProperty, visitNode(node.expression, visitor))); } if (assignments.length === 1) { return factory.createReturn(assignments[0].name as Expression); diff --git a/src/services/refactors/extractType.ts b/src/services/refactors/extractType.ts index 4da7d6db9ce43..2e39d6480fb59 100644 --- a/src/services/refactors/extractType.ts +++ b/src/services/refactors/extractType.ts @@ -185,7 +185,6 @@ namespace ts.refactor { factory.createIdentifier("typedef"), factory.createJSDocTypeExpression(selection), factory.createIdentifier(name)); - node.name = node.name as Identifier; const templates: JSDocTemplateTag[] = []; forEach(typeParameters, typeParameter => { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 84fdbe766df2b..00346fa6659ee 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1787,13 +1787,10 @@ namespace ts { if (visited === node) { // This only happens for leaf nodes - internal nodes always see their children change. - const clone = factory.cloneNode(node); - if (isStringLiteral(clone)) { - clone.textSourceNode = node as any; - } - else if (isNumericLiteral(clone)) { - clone.numericLiteralFlags = (node as any).numericLiteralFlags; - } + const clone = + isStringLiteral(node) ? setOriginalNode(factory.createStringLiteralFromNode(node), node) as Node as T : + isNumericLiteral(node) ? setOriginalNode(factory.createNumericLiteral(node.text, node.numericLiteralFlags), node) as Node as T : + factory.cloneNode(node); return setTextRange(clone, node); } diff --git a/src/testRunner/unittests/transform.ts b/src/testRunner/unittests/transform.ts index d1ae3d9b295ce..758b2d7f3ffb8 100644 --- a/src/testRunner/unittests/transform.ts +++ b/src/testRunner/unittests/transform.ts @@ -175,11 +175,13 @@ namespace ts { function replaceWithClassAndNamespace() { return (sourceFile: SourceFile) => { // TODO(rbuckton): Does this need to be parented? - const result = setParent(setTextRange(factory.cloneNode(sourceFile), sourceFile), sourceFile.parent); - result.statements = factory.createNodeArray([ - factory.createClassDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, "Foo", /*typeParameters*/ undefined, /*heritageClauses*/ undefined, /*members*/ undefined!), // TODO: GH#18217 - factory.createModuleDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, factory.createIdentifier("Foo"), factory.createModuleBlock([factory.createEmptyStatement()])) - ]); + const result = factory.updateSourceFile( + sourceFile, + factory.createNodeArray([ + factory.createClassDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, "Foo", /*typeParameters*/ undefined, /*heritageClauses*/ undefined, /*members*/ undefined!), // TODO: GH#18217 + factory.createModuleDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, factory.createIdentifier("Foo"), factory.createModuleBlock([factory.createEmptyStatement()])) + ]) + ); return result; }; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index b76d6e9025d10..8c12a77a05d80 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -501,10 +501,10 @@ declare namespace ts { IntrinsicElement = 3 } export interface Node extends TextRange { - kind: SyntaxKind; - flags: NodeFlags; - decorators?: NodeArray; - modifiers?: ModifiersArray; + readonly kind: SyntaxKind; + readonly flags: NodeFlags; + readonly decorators?: NodeArray; + readonly modifiers?: ModifiersArray; parent: Node; } export interface JSDocContainer { @@ -517,7 +517,7 @@ declare namespace ts { hasTrailingComma?: boolean; } export interface Token extends Node { - kind: TKind; + readonly kind: TKind; } export type EndOfFileToken = Token & JSDocContainer; export interface PunctuationToken extends Token { @@ -562,22 +562,22 @@ declare namespace ts { export type ClassMemberModifier = AccessibilityModifier | ReadonlyKeyword | StaticKeyword; export type ModifiersArray = NodeArray; export interface Identifier extends PrimaryExpression, Declaration { - kind: SyntaxKind.Identifier; + readonly kind: SyntaxKind.Identifier; /** * Prefer to use `id.unescapedText`. (Note: This is available only in services, not internally to the TypeScript compiler.) * Text of identifier, but if the identifier begins with two underscores, this will begin with three. */ - escapedText: __String; - originalKeywordKind?: SyntaxKind; + readonly escapedText: __String; + readonly originalKeywordKind?: SyntaxKind; isInJSDocNamespace?: boolean; } export interface TransientIdentifier extends Identifier { resolvedSymbol: Symbol; } export interface QualifiedName extends Node { - kind: SyntaxKind.QualifiedName; - left: EntityName; - right: Identifier; + readonly kind: SyntaxKind.QualifiedName; + readonly left: EntityName; + readonly right: Identifier; } export type EntityName = Identifier | QualifiedName; export type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName; @@ -586,132 +586,132 @@ declare namespace ts { _declarationBrand: any; } export interface NamedDeclaration extends Declaration { - name?: DeclarationName; + readonly name?: DeclarationName; } export interface DeclarationStatement extends NamedDeclaration, Statement { - name?: Identifier | StringLiteral | NumericLiteral; + readonly name?: Identifier | StringLiteral | NumericLiteral; } export interface ComputedPropertyName extends Node { parent: Declaration; - kind: SyntaxKind.ComputedPropertyName; - expression: Expression; + readonly kind: SyntaxKind.ComputedPropertyName; + readonly expression: Expression; } export interface Decorator extends Node { - kind: SyntaxKind.Decorator; - parent: NamedDeclaration; - expression: LeftHandSideExpression; + readonly kind: SyntaxKind.Decorator; + readonly parent: NamedDeclaration; + readonly expression: LeftHandSideExpression; } export interface TypeParameterDeclaration extends NamedDeclaration { - kind: SyntaxKind.TypeParameter; - parent: DeclarationWithTypeParameterChildren | InferTypeNode; - name: Identifier; + readonly kind: SyntaxKind.TypeParameter; + readonly parent: DeclarationWithTypeParameterChildren | InferTypeNode; + readonly name: Identifier; /** Note: Consider calling `getEffectiveConstraintOfTypeParameter` */ - constraint?: TypeNode; - default?: TypeNode; + readonly constraint?: TypeNode; + readonly default?: TypeNode; expression?: Expression; } export interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { - kind: SignatureDeclaration["kind"]; - name?: PropertyName; - typeParameters?: NodeArray; - parameters: NodeArray; - type?: TypeNode; + readonly kind: SignatureDeclaration["kind"]; + readonly name?: PropertyName; + readonly typeParameters?: NodeArray; + readonly parameters: NodeArray; + readonly type?: TypeNode; } export type SignatureDeclaration = CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | AccessorDeclaration | FunctionExpression | ArrowFunction; export interface CallSignatureDeclaration extends SignatureDeclarationBase, TypeElement { - kind: SyntaxKind.CallSignature; + readonly kind: SyntaxKind.CallSignature; } export interface ConstructSignatureDeclaration extends SignatureDeclarationBase, TypeElement { - kind: SyntaxKind.ConstructSignature; + readonly kind: SyntaxKind.ConstructSignature; } export type BindingName = Identifier | BindingPattern; export interface VariableDeclaration extends NamedDeclaration { - kind: SyntaxKind.VariableDeclaration; - parent: VariableDeclarationList | CatchClause; - name: BindingName; - exclamationToken?: ExclamationToken; - type?: TypeNode; - initializer?: Expression; + readonly kind: SyntaxKind.VariableDeclaration; + readonly parent: VariableDeclarationList | CatchClause; + readonly name: BindingName; + readonly exclamationToken?: ExclamationToken; + readonly type?: TypeNode; + readonly initializer?: Expression; } export interface VariableDeclarationList extends Node { - kind: SyntaxKind.VariableDeclarationList; - parent: VariableStatement | ForStatement | ForOfStatement | ForInStatement; - declarations: NodeArray; + readonly kind: SyntaxKind.VariableDeclarationList; + readonly parent: VariableStatement | ForStatement | ForOfStatement | ForInStatement; + readonly declarations: NodeArray; } export interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { - kind: SyntaxKind.Parameter; - parent: SignatureDeclaration; - dotDotDotToken?: DotDotDotToken; - name: BindingName; - questionToken?: QuestionToken; - type?: TypeNode; - initializer?: Expression; + readonly kind: SyntaxKind.Parameter; + readonly parent: SignatureDeclaration; + readonly dotDotDotToken?: DotDotDotToken; + readonly name: BindingName; + readonly questionToken?: QuestionToken; + readonly type?: TypeNode; + readonly initializer?: Expression; } export interface BindingElement extends NamedDeclaration { - kind: SyntaxKind.BindingElement; - parent: BindingPattern; - propertyName?: PropertyName; - dotDotDotToken?: DotDotDotToken; - name: BindingName; - initializer?: Expression; + readonly kind: SyntaxKind.BindingElement; + readonly parent: BindingPattern; + readonly propertyName?: PropertyName; + readonly dotDotDotToken?: DotDotDotToken; + readonly name: BindingName; + readonly initializer?: Expression; } export interface PropertySignature extends TypeElement, JSDocContainer { - kind: SyntaxKind.PropertySignature; - name: PropertyName; - questionToken?: QuestionToken; - type?: TypeNode; + readonly kind: SyntaxKind.PropertySignature; + readonly name: PropertyName; + readonly questionToken?: QuestionToken; + readonly type?: TypeNode; initializer?: Expression; } export interface PropertyDeclaration extends ClassElement, JSDocContainer { - kind: SyntaxKind.PropertyDeclaration; - parent: ClassLikeDeclaration; - name: PropertyName; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; - type?: TypeNode; - initializer?: Expression; + readonly kind: SyntaxKind.PropertyDeclaration; + readonly parent: ClassLikeDeclaration; + readonly name: PropertyName; + readonly questionToken?: QuestionToken; + readonly exclamationToken?: ExclamationToken; + readonly type?: TypeNode; + readonly initializer?: Expression; } export interface ObjectLiteralElement extends NamedDeclaration { _objectLiteralBrand: any; - name?: PropertyName; + readonly name?: PropertyName; } /** Unlike ObjectLiteralElement, excludes JSXAttribute and JSXSpreadAttribute. */ export type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment | MethodDeclaration | AccessorDeclaration; export interface PropertyAssignment extends ObjectLiteralElement, JSDocContainer { parent: ObjectLiteralExpression; - kind: SyntaxKind.PropertyAssignment; - name: PropertyName; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; - initializer: Expression; + readonly kind: SyntaxKind.PropertyAssignment; + readonly name: PropertyName; + readonly questionToken?: QuestionToken; + readonly exclamationToken?: ExclamationToken; + readonly initializer: Expression; } export interface ShorthandPropertyAssignment extends ObjectLiteralElement, JSDocContainer { parent: ObjectLiteralExpression; - kind: SyntaxKind.ShorthandPropertyAssignment; - name: Identifier; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; - equalsToken?: Token; - objectAssignmentInitializer?: Expression; + readonly kind: SyntaxKind.ShorthandPropertyAssignment; + readonly name: Identifier; + readonly questionToken?: QuestionToken; + readonly exclamationToken?: ExclamationToken; + readonly equalsToken?: EqualsToken; + readonly objectAssignmentInitializer?: Expression; } export interface SpreadAssignment extends ObjectLiteralElement, JSDocContainer { parent: ObjectLiteralExpression; - kind: SyntaxKind.SpreadAssignment; - expression: Expression; + readonly kind: SyntaxKind.SpreadAssignment; + readonly expression: Expression; } export type VariableLikeDeclaration = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | PropertySignature | JsxAttribute | ShorthandPropertyAssignment | EnumMember | JSDocPropertyTag | JSDocParameterTag; export interface PropertyLikeDeclaration extends NamedDeclaration { - name: PropertyName; + readonly name: PropertyName; } export interface ObjectBindingPattern extends Node { - kind: SyntaxKind.ObjectBindingPattern; parent: VariableDeclaration | ParameterDeclaration | BindingElement; - elements: NodeArray; + readonly kind: SyntaxKind.ObjectBindingPattern; + readonly elements: NodeArray; } export interface ArrayBindingPattern extends Node { - kind: SyntaxKind.ArrayBindingPattern; parent: VariableDeclaration | ParameterDeclaration | BindingElement; - elements: NodeArray; + readonly kind: SyntaxKind.ArrayBindingPattern; + readonly elements: NodeArray; } export type BindingPattern = ObjectBindingPattern | ArrayBindingPattern; export type ArrayBindingElement = BindingElement | OmittedExpression; @@ -725,169 +725,170 @@ declare namespace ts { */ export interface FunctionLikeDeclarationBase extends SignatureDeclarationBase { _functionLikeDeclarationBrand: any; - asteriskToken?: AsteriskToken; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; - body?: Block | Expression; + readonly asteriskToken?: AsteriskToken; + readonly questionToken?: QuestionToken; + readonly exclamationToken?: ExclamationToken; + readonly body?: Block | Expression; } export type FunctionLikeDeclaration = FunctionDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ConstructorDeclaration | FunctionExpression | ArrowFunction; /** @deprecated Use SignatureDeclaration */ export type FunctionLike = SignatureDeclaration; export interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement { - kind: SyntaxKind.FunctionDeclaration; - name?: Identifier; - body?: FunctionBody; + readonly kind: SyntaxKind.FunctionDeclaration; + readonly name?: Identifier; + readonly body?: FunctionBody; } export interface MethodSignature extends SignatureDeclarationBase, TypeElement { - kind: SyntaxKind.MethodSignature; parent: ObjectTypeDeclaration; - name: PropertyName; + readonly kind: SyntaxKind.MethodSignature; + readonly name: PropertyName; } export interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { - kind: SyntaxKind.MethodDeclaration; parent: ClassLikeDeclaration | ObjectLiteralExpression; - name: PropertyName; - body?: FunctionBody; + readonly kind: SyntaxKind.MethodDeclaration; + readonly name: PropertyName; + readonly body?: FunctionBody; } export interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElement, JSDocContainer { - kind: SyntaxKind.Constructor; parent: ClassLikeDeclaration; - body?: FunctionBody; + readonly kind: SyntaxKind.Constructor; + readonly body?: FunctionBody; } /** For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. */ export interface SemicolonClassElement extends ClassElement { - kind: SyntaxKind.SemicolonClassElement; parent: ClassLikeDeclaration; + readonly kind: SyntaxKind.SemicolonClassElement; } export interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { - kind: SyntaxKind.GetAccessor; parent: ClassLikeDeclaration | ObjectLiteralExpression; - name: PropertyName; - body?: FunctionBody; + readonly kind: SyntaxKind.GetAccessor; + readonly name: PropertyName; + readonly body?: FunctionBody; } export interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { - kind: SyntaxKind.SetAccessor; parent: ClassLikeDeclaration | ObjectLiteralExpression; - name: PropertyName; - body?: FunctionBody; + readonly kind: SyntaxKind.SetAccessor; + readonly name: PropertyName; + readonly body?: FunctionBody; } export type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; export interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement { - kind: SyntaxKind.IndexSignature; parent: ObjectTypeDeclaration; + readonly kind: SyntaxKind.IndexSignature; + readonly type: TypeNode; } export interface TypeNode extends Node { _typeNodeBrand: any; } export interface KeywordTypeNode extends KeywordToken, TypeNode { - kind: TKind; + readonly kind: TKind; } export interface ImportTypeNode extends NodeWithTypeArguments { - kind: SyntaxKind.ImportType; - isTypeOf?: boolean; - argument: TypeNode; - qualifier?: EntityName; + readonly kind: SyntaxKind.ImportType; + readonly isTypeOf: boolean; + readonly argument: TypeNode; + readonly qualifier?: EntityName; } export interface ThisTypeNode extends TypeNode { - kind: SyntaxKind.ThisType; + readonly kind: SyntaxKind.ThisType; } export type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; export interface FunctionOrConstructorTypeNodeBase extends TypeNode, SignatureDeclarationBase { - kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType; - type: TypeNode; + readonly kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType; + readonly type: TypeNode; } export interface FunctionTypeNode extends FunctionOrConstructorTypeNodeBase { - kind: SyntaxKind.FunctionType; + readonly kind: SyntaxKind.FunctionType; } export interface ConstructorTypeNode extends FunctionOrConstructorTypeNodeBase { - kind: SyntaxKind.ConstructorType; + readonly kind: SyntaxKind.ConstructorType; } export interface NodeWithTypeArguments extends TypeNode { - typeArguments?: NodeArray; + readonly typeArguments?: NodeArray; } export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; export interface TypeReferenceNode extends NodeWithTypeArguments { - kind: SyntaxKind.TypeReference; - typeName: EntityName; + readonly kind: SyntaxKind.TypeReference; + readonly typeName: EntityName; } export interface TypePredicateNode extends TypeNode { - kind: SyntaxKind.TypePredicate; - parent: SignatureDeclaration | JSDocTypeExpression; - assertsModifier?: AssertsToken; - parameterName: Identifier | ThisTypeNode; - type?: TypeNode; + readonly kind: SyntaxKind.TypePredicate; + readonly parent: SignatureDeclaration | JSDocTypeExpression; + readonly assertsModifier?: AssertsToken; + readonly parameterName: Identifier | ThisTypeNode; + readonly type?: TypeNode; } export interface TypeQueryNode extends TypeNode { - kind: SyntaxKind.TypeQuery; - exprName: EntityName; + readonly kind: SyntaxKind.TypeQuery; + readonly exprName: EntityName; } export interface TypeLiteralNode extends TypeNode, Declaration { - kind: SyntaxKind.TypeLiteral; - members: NodeArray; + readonly kind: SyntaxKind.TypeLiteral; + readonly members: NodeArray; } export interface ArrayTypeNode extends TypeNode { - kind: SyntaxKind.ArrayType; - elementType: TypeNode; + readonly kind: SyntaxKind.ArrayType; + readonly elementType: TypeNode; } export interface TupleTypeNode extends TypeNode { - kind: SyntaxKind.TupleType; - elementTypes: NodeArray; + readonly kind: SyntaxKind.TupleType; + readonly elementTypes: NodeArray; } export interface OptionalTypeNode extends TypeNode { - kind: SyntaxKind.OptionalType; - type: TypeNode; + readonly kind: SyntaxKind.OptionalType; + readonly type: TypeNode; } export interface RestTypeNode extends TypeNode { - kind: SyntaxKind.RestType; - type: TypeNode; + readonly kind: SyntaxKind.RestType; + readonly type: TypeNode; } export type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; export interface UnionTypeNode extends TypeNode { - kind: SyntaxKind.UnionType; - types: NodeArray; + readonly kind: SyntaxKind.UnionType; + readonly types: NodeArray; } export interface IntersectionTypeNode extends TypeNode { - kind: SyntaxKind.IntersectionType; - types: NodeArray; + readonly kind: SyntaxKind.IntersectionType; + readonly types: NodeArray; } export interface ConditionalTypeNode extends TypeNode { - kind: SyntaxKind.ConditionalType; - checkType: TypeNode; - extendsType: TypeNode; - trueType: TypeNode; - falseType: TypeNode; + readonly kind: SyntaxKind.ConditionalType; + readonly checkType: TypeNode; + readonly extendsType: TypeNode; + readonly trueType: TypeNode; + readonly falseType: TypeNode; } export interface InferTypeNode extends TypeNode { - kind: SyntaxKind.InferType; - typeParameter: TypeParameterDeclaration; + readonly kind: SyntaxKind.InferType; + readonly typeParameter: TypeParameterDeclaration; } export interface ParenthesizedTypeNode extends TypeNode { - kind: SyntaxKind.ParenthesizedType; - type: TypeNode; + readonly kind: SyntaxKind.ParenthesizedType; + readonly type: TypeNode; } export interface TypeOperatorNode extends TypeNode { - kind: SyntaxKind.TypeOperator; - operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; - type: TypeNode; + readonly kind: SyntaxKind.TypeOperator; + readonly operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; + readonly type: TypeNode; } export interface IndexedAccessTypeNode extends TypeNode { - kind: SyntaxKind.IndexedAccessType; - objectType: TypeNode; - indexType: TypeNode; + readonly kind: SyntaxKind.IndexedAccessType; + readonly objectType: TypeNode; + readonly indexType: TypeNode; } export interface MappedTypeNode extends TypeNode, Declaration { - kind: SyntaxKind.MappedType; - readonlyToken?: ReadonlyToken | PlusToken | MinusToken; - typeParameter: TypeParameterDeclaration; - questionToken?: QuestionToken | PlusToken | MinusToken; - type?: TypeNode; + readonly kind: SyntaxKind.MappedType; + readonly readonlyToken?: ReadonlyToken | PlusToken | MinusToken; + readonly typeParameter: TypeParameterDeclaration; + readonly questionToken?: QuestionToken | PlusToken | MinusToken; + readonly type?: TypeNode; } export interface LiteralTypeNode extends TypeNode { - kind: SyntaxKind.LiteralType; - literal: NullLiteral | BooleanLiteral | LiteralExpression | PrefixUnaryExpression; + readonly kind: SyntaxKind.LiteralType; + readonly literal: NullLiteral | BooleanLiteral | LiteralExpression | PrefixUnaryExpression; } export interface StringLiteral extends LiteralExpression, Declaration { - kind: SyntaxKind.StringLiteral; + readonly kind: SyntaxKind.StringLiteral; } export type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral; export type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral; @@ -895,11 +896,11 @@ declare namespace ts { _expressionBrand: any; } export interface OmittedExpression extends Expression { - kind: SyntaxKind.OmittedExpression; + readonly kind: SyntaxKind.OmittedExpression; } export interface PartiallyEmittedExpression extends LeftHandSideExpression { - kind: SyntaxKind.PartiallyEmittedExpression; - expression: Expression; + readonly kind: SyntaxKind.PartiallyEmittedExpression; + readonly expression: Expression; } export interface UnaryExpression extends Expression { _unaryExpressionBrand: any; @@ -911,15 +912,15 @@ declare namespace ts { } export type PrefixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.TildeToken | SyntaxKind.ExclamationToken; export interface PrefixUnaryExpression extends UpdateExpression { - kind: SyntaxKind.PrefixUnaryExpression; - operator: PrefixUnaryOperator; - operand: UnaryExpression; + readonly kind: SyntaxKind.PrefixUnaryExpression; + readonly operator: PrefixUnaryOperator; + readonly operand: UnaryExpression; } export type PostfixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken; export interface PostfixUnaryExpression extends UpdateExpression { - kind: SyntaxKind.PostfixUnaryExpression; - operand: LeftHandSideExpression; - operator: PostfixUnaryOperator; + readonly kind: SyntaxKind.PostfixUnaryExpression; + readonly operand: LeftHandSideExpression; + readonly operator: PostfixUnaryOperator; } export interface LeftHandSideExpression extends UpdateExpression { _leftHandSideExpressionBrand: any; @@ -931,49 +932,49 @@ declare namespace ts { _primaryExpressionBrand: any; } export interface NullLiteral extends PrimaryExpression { - kind: SyntaxKind.NullKeyword; + readonly kind: SyntaxKind.NullKeyword; } export interface TrueLiteral extends PrimaryExpression { - kind: SyntaxKind.TrueKeyword; + readonly kind: SyntaxKind.TrueKeyword; } export interface FalseLiteral extends PrimaryExpression { - kind: SyntaxKind.FalseKeyword; + readonly kind: SyntaxKind.FalseKeyword; } export type BooleanLiteral = TrueLiteral | FalseLiteral; export interface ThisExpression extends PrimaryExpression { - kind: SyntaxKind.ThisKeyword; + readonly kind: SyntaxKind.ThisKeyword; } export interface SuperExpression extends PrimaryExpression { - kind: SyntaxKind.SuperKeyword; + readonly kind: SyntaxKind.SuperKeyword; } export interface ImportExpression extends PrimaryExpression { - kind: SyntaxKind.ImportKeyword; + readonly kind: SyntaxKind.ImportKeyword; } export interface DeleteExpression extends UnaryExpression { - kind: SyntaxKind.DeleteExpression; - expression: UnaryExpression; + readonly kind: SyntaxKind.DeleteExpression; + readonly expression: UnaryExpression; } export interface TypeOfExpression extends UnaryExpression { - kind: SyntaxKind.TypeOfExpression; - expression: UnaryExpression; + readonly kind: SyntaxKind.TypeOfExpression; + readonly expression: UnaryExpression; } export interface VoidExpression extends UnaryExpression { - kind: SyntaxKind.VoidExpression; - expression: UnaryExpression; + readonly kind: SyntaxKind.VoidExpression; + readonly expression: UnaryExpression; } export interface AwaitExpression extends UnaryExpression { - kind: SyntaxKind.AwaitExpression; - expression: UnaryExpression; + readonly kind: SyntaxKind.AwaitExpression; + readonly expression: UnaryExpression; } export interface YieldExpression extends Expression { - kind: SyntaxKind.YieldExpression; - asteriskToken?: AsteriskToken; - expression?: Expression; + readonly kind: SyntaxKind.YieldExpression; + readonly asteriskToken?: AsteriskToken; + readonly expression?: Expression; } export interface SyntheticExpression extends Expression { - kind: SyntaxKind.SyntheticExpression; - isSpread: boolean; - type: Type; + readonly kind: SyntaxKind.SyntheticExpression; + readonly isSpread: boolean; + readonly type: Type; } export type ExponentiationOperator = SyntaxKind.AsteriskAsteriskToken; export type MultiplicativeOperator = SyntaxKind.AsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken; @@ -996,21 +997,21 @@ declare namespace ts { export type BinaryOperator = AssignmentOperatorOrHigher | SyntaxKind.CommaToken; export type BinaryOperatorToken = Token; export interface BinaryExpression extends Expression, Declaration { - kind: SyntaxKind.BinaryExpression; - left: Expression; - operatorToken: BinaryOperatorToken; - right: Expression; + readonly kind: SyntaxKind.BinaryExpression; + readonly left: Expression; + readonly operatorToken: BinaryOperatorToken; + readonly right: Expression; } export type AssignmentOperatorToken = Token; export interface AssignmentExpression extends BinaryExpression { - left: LeftHandSideExpression; - operatorToken: TOperator; + readonly left: LeftHandSideExpression; + readonly operatorToken: TOperator; } export interface ObjectDestructuringAssignment extends AssignmentExpression { - left: ObjectLiteralExpression; + readonly left: ObjectLiteralExpression; } export interface ArrayDestructuringAssignment extends AssignmentExpression { - left: ArrayLiteralExpression; + readonly left: ArrayLiteralExpression; } export type DestructuringAssignment = ObjectDestructuringAssignment | ArrayDestructuringAssignment; export type BindingOrAssignmentElement = VariableDeclaration | ParameterDeclaration | ObjectBindingOrAssignmentElement | ArrayBindingOrAssignmentElement; @@ -1023,25 +1024,25 @@ declare namespace ts { export type AssignmentPattern = ObjectLiteralExpression | ArrayLiteralExpression; export type BindingOrAssignmentPattern = ObjectBindingOrAssignmentPattern | ArrayBindingOrAssignmentPattern; export interface ConditionalExpression extends Expression { - kind: SyntaxKind.ConditionalExpression; - condition: Expression; - questionToken: QuestionToken; - whenTrue: Expression; - colonToken: ColonToken; - whenFalse: Expression; + readonly kind: SyntaxKind.ConditionalExpression; + readonly condition: Expression; + readonly questionToken: QuestionToken; + readonly whenTrue: Expression; + readonly colonToken: ColonToken; + readonly whenFalse: Expression; } export type FunctionBody = Block; export type ConciseBody = FunctionBody | Expression; export interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer { - kind: SyntaxKind.FunctionExpression; - name?: Identifier; - body: FunctionBody; + readonly kind: SyntaxKind.FunctionExpression; + readonly name?: Identifier; + readonly body: FunctionBody; } export interface ArrowFunction extends Expression, FunctionLikeDeclarationBase, JSDocContainer { - kind: SyntaxKind.ArrowFunction; - equalsGreaterThanToken: EqualsGreaterThanToken; - body: ConciseBody; - name: never; + readonly kind: SyntaxKind.ArrowFunction; + readonly equalsGreaterThanToken: EqualsGreaterThanToken; + readonly body: ConciseBody; + readonly name: never; } export interface LiteralLikeNode extends Node { text: string; @@ -1055,10 +1056,10 @@ declare namespace ts { _literalExpressionBrand: any; } export interface RegularExpressionLiteral extends LiteralExpression { - kind: SyntaxKind.RegularExpressionLiteral; + readonly kind: SyntaxKind.RegularExpressionLiteral; } export interface NoSubstitutionTemplateLiteral extends LiteralExpression, TemplateLiteralLikeNode, Declaration { - kind: SyntaxKind.NoSubstitutionTemplateLiteral; + readonly kind: SyntaxKind.NoSubstitutionTemplateLiteral; } export enum TokenFlags { None = 0, @@ -1069,50 +1070,50 @@ declare namespace ts { OctalSpecifier = 256, } export interface NumericLiteral extends LiteralExpression, Declaration { - kind: SyntaxKind.NumericLiteral; + readonly kind: SyntaxKind.NumericLiteral; } export interface BigIntLiteral extends LiteralExpression { - kind: SyntaxKind.BigIntLiteral; + readonly kind: SyntaxKind.BigIntLiteral; } export type LiteralToken = NumericLiteral | BigIntLiteral | StringLiteral | JsxText | RegularExpressionLiteral | NoSubstitutionTemplateLiteral; export interface TemplateHead extends TemplateLiteralLikeNode { - kind: SyntaxKind.TemplateHead; + readonly kind: SyntaxKind.TemplateHead; parent: TemplateExpression; } export interface TemplateMiddle extends TemplateLiteralLikeNode { - kind: SyntaxKind.TemplateMiddle; + readonly kind: SyntaxKind.TemplateMiddle; parent: TemplateSpan; } export interface TemplateTail extends TemplateLiteralLikeNode { - kind: SyntaxKind.TemplateTail; + readonly kind: SyntaxKind.TemplateTail; parent: TemplateSpan; } export type PseudoLiteralToken = TemplateHead | TemplateMiddle | TemplateTail; export type TemplateLiteralToken = NoSubstitutionTemplateLiteral | PseudoLiteralToken; export interface TemplateExpression extends PrimaryExpression { - kind: SyntaxKind.TemplateExpression; - head: TemplateHead; - templateSpans: NodeArray; + readonly kind: SyntaxKind.TemplateExpression; + readonly head: TemplateHead; + readonly templateSpans: NodeArray; } export type TemplateLiteral = TemplateExpression | NoSubstitutionTemplateLiteral; export interface TemplateSpan extends Node { - kind: SyntaxKind.TemplateSpan; parent: TemplateExpression; - expression: Expression; - literal: TemplateMiddle | TemplateTail; + readonly kind: SyntaxKind.TemplateSpan; + readonly expression: Expression; + readonly literal: TemplateMiddle | TemplateTail; } export interface ParenthesizedExpression extends PrimaryExpression, JSDocContainer { - kind: SyntaxKind.ParenthesizedExpression; - expression: Expression; + readonly kind: SyntaxKind.ParenthesizedExpression; + readonly expression: Expression; } export interface ArrayLiteralExpression extends PrimaryExpression { - kind: SyntaxKind.ArrayLiteralExpression; - elements: NodeArray; + readonly kind: SyntaxKind.ArrayLiteralExpression; + readonly elements: NodeArray; } export interface SpreadElement extends Expression { - kind: SyntaxKind.SpreadElement; parent: ArrayLiteralExpression | CallExpression | NewExpression; - expression: Expression; + readonly kind: SyntaxKind.SpreadElement; + readonly expression: Expression; } /** * This interface is a base interface for ObjectLiteralExpression and JSXAttributes to extend from. JSXAttributes is similar to @@ -1121,383 +1122,383 @@ declare namespace ts { * ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.) */ export interface ObjectLiteralExpressionBase extends PrimaryExpression, Declaration { - properties: NodeArray; + readonly properties: NodeArray; } export interface ObjectLiteralExpression extends ObjectLiteralExpressionBase { - kind: SyntaxKind.ObjectLiteralExpression; + readonly kind: SyntaxKind.ObjectLiteralExpression; } export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression; export type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression; export interface PropertyAccessExpression extends MemberExpression, NamedDeclaration { - kind: SyntaxKind.PropertyAccessExpression; - expression: LeftHandSideExpression; - questionDotToken?: QuestionDotToken; - name: Identifier; + readonly kind: SyntaxKind.PropertyAccessExpression; + readonly expression: LeftHandSideExpression; + readonly questionDotToken?: QuestionDotToken; + readonly name: Identifier; } export interface PropertyAccessChain extends PropertyAccessExpression { _optionalChainBrand: any; } export interface SuperPropertyAccessExpression extends PropertyAccessExpression { - expression: SuperExpression; + readonly expression: SuperExpression; } /** Brand for a PropertyAccessExpression which, like a QualifiedName, consists of a sequence of identifiers separated by dots. */ export interface PropertyAccessEntityNameExpression extends PropertyAccessExpression { _propertyAccessExpressionLikeQualifiedNameBrand?: any; - expression: EntityNameExpression; + readonly expression: EntityNameExpression; } export interface ElementAccessExpression extends MemberExpression { - kind: SyntaxKind.ElementAccessExpression; - expression: LeftHandSideExpression; - questionDotToken?: QuestionDotToken; - argumentExpression: Expression; + readonly kind: SyntaxKind.ElementAccessExpression; + readonly expression: LeftHandSideExpression; + readonly questionDotToken?: QuestionDotToken; + readonly argumentExpression: Expression; } export interface ElementAccessChain extends ElementAccessExpression { _optionalChainBrand: any; } export interface SuperElementAccessExpression extends ElementAccessExpression { - expression: SuperExpression; + readonly expression: SuperExpression; } export type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; export interface CallExpression extends LeftHandSideExpression, Declaration { - kind: SyntaxKind.CallExpression; - expression: LeftHandSideExpression; - questionDotToken?: QuestionDotToken; - typeArguments?: NodeArray; - arguments: NodeArray; + readonly kind: SyntaxKind.CallExpression; + readonly expression: LeftHandSideExpression; + readonly questionDotToken?: QuestionDotToken; + readonly typeArguments?: NodeArray; + readonly arguments: NodeArray; } export interface CallChain extends CallExpression { _optionalChainBrand: any; } export type OptionalChain = PropertyAccessChain | ElementAccessChain | CallChain; export interface SuperCall extends CallExpression { - expression: SuperExpression; + readonly expression: SuperExpression; } export interface ImportCall extends CallExpression { - expression: ImportExpression; + readonly expression: ImportExpression; } export interface ExpressionWithTypeArguments extends NodeWithTypeArguments { - kind: SyntaxKind.ExpressionWithTypeArguments; parent: HeritageClause | JSDocAugmentsTag; - expression: LeftHandSideExpression; + readonly kind: SyntaxKind.ExpressionWithTypeArguments; + readonly expression: LeftHandSideExpression; } export interface NewExpression extends PrimaryExpression, Declaration { - kind: SyntaxKind.NewExpression; - expression: LeftHandSideExpression; - typeArguments?: NodeArray; - arguments?: NodeArray; + readonly kind: SyntaxKind.NewExpression; + readonly expression: LeftHandSideExpression; + readonly typeArguments?: NodeArray; + readonly arguments?: NodeArray; } export interface TaggedTemplateExpression extends MemberExpression { - kind: SyntaxKind.TaggedTemplateExpression; - tag: LeftHandSideExpression; - typeArguments?: NodeArray; - template: TemplateLiteral; + readonly kind: SyntaxKind.TaggedTemplateExpression; + readonly tag: LeftHandSideExpression; + readonly typeArguments?: NodeArray; + readonly template: TemplateLiteral; } export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator | JsxOpeningLikeElement; export interface AsExpression extends Expression { - kind: SyntaxKind.AsExpression; - expression: Expression; - type: TypeNode; + readonly kind: SyntaxKind.AsExpression; + readonly expression: Expression; + readonly type: TypeNode; } export interface TypeAssertion extends UnaryExpression { - kind: SyntaxKind.TypeAssertionExpression; - type: TypeNode; - expression: UnaryExpression; + readonly kind: SyntaxKind.TypeAssertionExpression; + readonly type: TypeNode; + readonly expression: UnaryExpression; } export type AssertionExpression = TypeAssertion | AsExpression; export interface NonNullExpression extends LeftHandSideExpression { - kind: SyntaxKind.NonNullExpression; - expression: Expression; + readonly kind: SyntaxKind.NonNullExpression; + readonly expression: Expression; } export interface MetaProperty extends PrimaryExpression { - kind: SyntaxKind.MetaProperty; - keywordToken: SyntaxKind.NewKeyword | SyntaxKind.ImportKeyword; - name: Identifier; + readonly kind: SyntaxKind.MetaProperty; + readonly keywordToken: SyntaxKind.NewKeyword | SyntaxKind.ImportKeyword; + readonly name: Identifier; } export interface JsxElement extends PrimaryExpression { - kind: SyntaxKind.JsxElement; - openingElement: JsxOpeningElement; - children: NodeArray; - closingElement: JsxClosingElement; + readonly kind: SyntaxKind.JsxElement; + readonly openingElement: JsxOpeningElement; + readonly children: NodeArray; + readonly closingElement: JsxClosingElement; } export type JsxOpeningLikeElement = JsxSelfClosingElement | JsxOpeningElement; export type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute; export type JsxTagNameExpression = Identifier | ThisExpression | JsxTagNamePropertyAccess; export interface JsxTagNamePropertyAccess extends PropertyAccessExpression { - expression: JsxTagNameExpression; + readonly expression: JsxTagNameExpression; } export interface JsxAttributes extends ObjectLiteralExpressionBase { - kind: SyntaxKind.JsxAttributes; parent: JsxOpeningLikeElement; + readonly kind: SyntaxKind.JsxAttributes; } export interface JsxOpeningElement extends Expression { - kind: SyntaxKind.JsxOpeningElement; parent: JsxElement; - tagName: JsxTagNameExpression; - typeArguments?: NodeArray; - attributes: JsxAttributes; + readonly kind: SyntaxKind.JsxOpeningElement; + readonly tagName: JsxTagNameExpression; + readonly typeArguments?: NodeArray; + readonly attributes: JsxAttributes; } export interface JsxSelfClosingElement extends PrimaryExpression { - kind: SyntaxKind.JsxSelfClosingElement; - tagName: JsxTagNameExpression; - typeArguments?: NodeArray; - attributes: JsxAttributes; + readonly kind: SyntaxKind.JsxSelfClosingElement; + readonly tagName: JsxTagNameExpression; + readonly typeArguments?: NodeArray; + readonly attributes: JsxAttributes; } export interface JsxFragment extends PrimaryExpression { - kind: SyntaxKind.JsxFragment; - openingFragment: JsxOpeningFragment; - children: NodeArray; - closingFragment: JsxClosingFragment; + readonly kind: SyntaxKind.JsxFragment; + readonly openingFragment: JsxOpeningFragment; + readonly children: NodeArray; + readonly closingFragment: JsxClosingFragment; } export interface JsxOpeningFragment extends Expression { - kind: SyntaxKind.JsxOpeningFragment; parent: JsxFragment; + readonly kind: SyntaxKind.JsxOpeningFragment; } export interface JsxClosingFragment extends Expression { - kind: SyntaxKind.JsxClosingFragment; parent: JsxFragment; + readonly kind: SyntaxKind.JsxClosingFragment; } export interface JsxAttribute extends ObjectLiteralElement { - kind: SyntaxKind.JsxAttribute; parent: JsxAttributes; - name: Identifier; - initializer?: StringLiteral | JsxExpression; + readonly kind: SyntaxKind.JsxAttribute; + readonly name: Identifier; + readonly initializer?: StringLiteral | JsxExpression; } export interface JsxSpreadAttribute extends ObjectLiteralElement { - kind: SyntaxKind.JsxSpreadAttribute; parent: JsxAttributes; - expression: Expression; + readonly kind: SyntaxKind.JsxSpreadAttribute; + readonly expression: Expression; } export interface JsxClosingElement extends Node { - kind: SyntaxKind.JsxClosingElement; parent: JsxElement; - tagName: JsxTagNameExpression; + readonly kind: SyntaxKind.JsxClosingElement; + readonly tagName: JsxTagNameExpression; } export interface JsxExpression extends Expression { - kind: SyntaxKind.JsxExpression; parent: JsxElement | JsxAttributeLike; - dotDotDotToken?: Token; - expression?: Expression; + readonly kind: SyntaxKind.JsxExpression; + readonly dotDotDotToken?: Token; + readonly expression?: Expression; } export interface JsxText extends LiteralLikeNode { - kind: SyntaxKind.JsxText; - containsOnlyTriviaWhiteSpaces: boolean; parent: JsxElement; + readonly kind: SyntaxKind.JsxText; + readonly containsOnlyTriviaWhiteSpaces: boolean; } export type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment; export interface Statement extends Node { _statementBrand: any; } export interface NotEmittedStatement extends Statement { - kind: SyntaxKind.NotEmittedStatement; + readonly kind: SyntaxKind.NotEmittedStatement; } /** * A list of comma-separated expressions. This node is only created by transformations. */ export interface CommaListExpression extends Expression { - kind: SyntaxKind.CommaListExpression; - elements: NodeArray; + readonly kind: SyntaxKind.CommaListExpression; + readonly elements: NodeArray; } export interface EmptyStatement extends Statement { - kind: SyntaxKind.EmptyStatement; + readonly kind: SyntaxKind.EmptyStatement; } export interface DebuggerStatement extends Statement { - kind: SyntaxKind.DebuggerStatement; + readonly kind: SyntaxKind.DebuggerStatement; } export interface MissingDeclaration extends DeclarationStatement { - kind: SyntaxKind.MissingDeclaration; - name?: Identifier; + readonly kind: SyntaxKind.MissingDeclaration; + readonly name?: Identifier; } export type BlockLike = SourceFile | Block | ModuleBlock | CaseOrDefaultClause; export interface Block extends Statement { - kind: SyntaxKind.Block; - statements: NodeArray; + readonly kind: SyntaxKind.Block; + readonly statements: NodeArray; } export interface VariableStatement extends Statement, JSDocContainer { - kind: SyntaxKind.VariableStatement; - declarationList: VariableDeclarationList; + readonly kind: SyntaxKind.VariableStatement; + readonly declarationList: VariableDeclarationList; } export interface ExpressionStatement extends Statement, JSDocContainer { - kind: SyntaxKind.ExpressionStatement; - expression: Expression; + readonly kind: SyntaxKind.ExpressionStatement; + readonly expression: Expression; } export interface IfStatement extends Statement { - kind: SyntaxKind.IfStatement; - expression: Expression; - thenStatement: Statement; - elseStatement?: Statement; + readonly kind: SyntaxKind.IfStatement; + readonly expression: Expression; + readonly thenStatement: Statement; + readonly elseStatement?: Statement; } export interface IterationStatement extends Statement { - statement: Statement; + readonly statement: Statement; } export interface DoStatement extends IterationStatement { - kind: SyntaxKind.DoStatement; - expression: Expression; + readonly kind: SyntaxKind.DoStatement; + readonly expression: Expression; } export interface WhileStatement extends IterationStatement { - kind: SyntaxKind.WhileStatement; - expression: Expression; + readonly kind: SyntaxKind.WhileStatement; + readonly expression: Expression; } export type ForInitializer = VariableDeclarationList | Expression; export interface ForStatement extends IterationStatement { - kind: SyntaxKind.ForStatement; - initializer?: ForInitializer; - condition?: Expression; - incrementor?: Expression; + readonly kind: SyntaxKind.ForStatement; + readonly initializer?: ForInitializer; + readonly condition?: Expression; + readonly incrementor?: Expression; } export type ForInOrOfStatement = ForInStatement | ForOfStatement; export interface ForInStatement extends IterationStatement { - kind: SyntaxKind.ForInStatement; - initializer: ForInitializer; - expression: Expression; + readonly kind: SyntaxKind.ForInStatement; + readonly initializer: ForInitializer; + readonly expression: Expression; } export interface ForOfStatement extends IterationStatement { - kind: SyntaxKind.ForOfStatement; - awaitModifier?: AwaitKeywordToken; - initializer: ForInitializer; - expression: Expression; + readonly kind: SyntaxKind.ForOfStatement; + readonly awaitModifier?: AwaitKeywordToken; + readonly initializer: ForInitializer; + readonly expression: Expression; } export interface BreakStatement extends Statement { - kind: SyntaxKind.BreakStatement; - label?: Identifier; + readonly kind: SyntaxKind.BreakStatement; + readonly label?: Identifier; } export interface ContinueStatement extends Statement { - kind: SyntaxKind.ContinueStatement; - label?: Identifier; + readonly kind: SyntaxKind.ContinueStatement; + readonly label?: Identifier; } export type BreakOrContinueStatement = BreakStatement | ContinueStatement; export interface ReturnStatement extends Statement { - kind: SyntaxKind.ReturnStatement; - expression?: Expression; + readonly kind: SyntaxKind.ReturnStatement; + readonly expression?: Expression; } export interface WithStatement extends Statement { - kind: SyntaxKind.WithStatement; - expression: Expression; - statement: Statement; + readonly kind: SyntaxKind.WithStatement; + readonly expression: Expression; + readonly statement: Statement; } export interface SwitchStatement extends Statement { - kind: SyntaxKind.SwitchStatement; - expression: Expression; - caseBlock: CaseBlock; + readonly kind: SyntaxKind.SwitchStatement; + readonly expression: Expression; + readonly caseBlock: CaseBlock; possiblyExhaustive?: boolean; } export interface CaseBlock extends Node { - kind: SyntaxKind.CaseBlock; parent: SwitchStatement; - clauses: NodeArray; + readonly kind: SyntaxKind.CaseBlock; + readonly clauses: NodeArray; } export interface CaseClause extends Node { - kind: SyntaxKind.CaseClause; parent: CaseBlock; - expression: Expression; - statements: NodeArray; + readonly kind: SyntaxKind.CaseClause; + readonly expression: Expression; + readonly statements: NodeArray; } export interface DefaultClause extends Node { - kind: SyntaxKind.DefaultClause; parent: CaseBlock; - statements: NodeArray; + readonly kind: SyntaxKind.DefaultClause; + readonly statements: NodeArray; } export type CaseOrDefaultClause = CaseClause | DefaultClause; export interface LabeledStatement extends Statement, JSDocContainer { - kind: SyntaxKind.LabeledStatement; - label: Identifier; - statement: Statement; + readonly kind: SyntaxKind.LabeledStatement; + readonly label: Identifier; + readonly statement: Statement; } export interface ThrowStatement extends Statement { - kind: SyntaxKind.ThrowStatement; - expression?: Expression; + readonly kind: SyntaxKind.ThrowStatement; + readonly expression?: Expression; } export interface TryStatement extends Statement { - kind: SyntaxKind.TryStatement; - tryBlock: Block; - catchClause?: CatchClause; - finallyBlock?: Block; + readonly kind: SyntaxKind.TryStatement; + readonly tryBlock: Block; + readonly catchClause?: CatchClause; + readonly finallyBlock?: Block; } export interface CatchClause extends Node { - kind: SyntaxKind.CatchClause; parent: TryStatement; - variableDeclaration?: VariableDeclaration; - block: Block; + readonly kind: SyntaxKind.CatchClause; + readonly variableDeclaration?: VariableDeclaration; + readonly block: Block; } export type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode; export type DeclarationWithTypeParameters = DeclarationWithTypeParameterChildren | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; export type DeclarationWithTypeParameterChildren = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { - kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; - name?: Identifier; - typeParameters?: NodeArray; - heritageClauses?: NodeArray; - members: NodeArray; + readonly kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; + readonly name?: Identifier; + readonly typeParameters?: NodeArray; + readonly heritageClauses?: NodeArray; + readonly members: NodeArray; } export interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatement { - kind: SyntaxKind.ClassDeclaration; + readonly kind: SyntaxKind.ClassDeclaration; /** May be undefined in `export default class { ... }`. */ - name?: Identifier; + readonly name?: Identifier; } export interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpression { - kind: SyntaxKind.ClassExpression; + readonly kind: SyntaxKind.ClassExpression; } export type ClassLikeDeclaration = ClassDeclaration | ClassExpression; export interface ClassElement extends NamedDeclaration { _classElementBrand: any; - name?: PropertyName; + readonly name?: PropertyName; } export interface TypeElement extends NamedDeclaration { _typeElementBrand: any; - name?: PropertyName; - questionToken?: QuestionToken; + readonly name?: PropertyName; + readonly questionToken?: QuestionToken; } export interface InterfaceDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.InterfaceDeclaration; - name: Identifier; - typeParameters?: NodeArray; - heritageClauses?: NodeArray; - members: NodeArray; + readonly kind: SyntaxKind.InterfaceDeclaration; + readonly name: Identifier; + readonly typeParameters?: NodeArray; + readonly heritageClauses?: NodeArray; + readonly members: NodeArray; } export interface HeritageClause extends Node { - kind: SyntaxKind.HeritageClause; parent: InterfaceDeclaration | ClassLikeDeclaration; - token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; - types: NodeArray; + readonly kind: SyntaxKind.HeritageClause; + readonly token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; + readonly types: NodeArray; } export interface TypeAliasDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.TypeAliasDeclaration; - name: Identifier; - typeParameters?: NodeArray; - type: TypeNode; + readonly kind: SyntaxKind.TypeAliasDeclaration; + readonly name: Identifier; + readonly typeParameters?: NodeArray; + readonly type: TypeNode; } export interface EnumMember extends NamedDeclaration, JSDocContainer { - kind: SyntaxKind.EnumMember; parent: EnumDeclaration; - name: PropertyName; - initializer?: Expression; + readonly kind: SyntaxKind.EnumMember; + readonly name: PropertyName; + readonly initializer?: Expression; } export interface EnumDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.EnumDeclaration; - name: Identifier; - members: NodeArray; + readonly kind: SyntaxKind.EnumDeclaration; + readonly name: Identifier; + readonly members: NodeArray; } export type ModuleName = Identifier | StringLiteral; export type ModuleBody = NamespaceBody | JSDocNamespaceBody; export interface ModuleDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ModuleDeclaration; parent: ModuleBody | SourceFile; - name: ModuleName; - body?: ModuleBody | JSDocNamespaceDeclaration; + readonly kind: SyntaxKind.ModuleDeclaration; + readonly name: ModuleName; + readonly body?: ModuleBody | JSDocNamespaceDeclaration; } export type NamespaceBody = ModuleBlock | NamespaceDeclaration; export interface NamespaceDeclaration extends ModuleDeclaration { - name: Identifier; - body: NamespaceBody; + readonly name: Identifier; + readonly body: NamespaceBody; } export type JSDocNamespaceBody = Identifier | JSDocNamespaceDeclaration; export interface JSDocNamespaceDeclaration extends ModuleDeclaration { - name: Identifier; - body?: JSDocNamespaceBody; + readonly name: Identifier; + readonly body?: JSDocNamespaceBody; } export interface ModuleBlock extends Node, Statement { - kind: SyntaxKind.ModuleBlock; parent: ModuleDeclaration; - statements: NodeArray; + readonly kind: SyntaxKind.ModuleBlock; + readonly statements: NodeArray; } export type ModuleReference = EntityName | ExternalModuleReference; /** @@ -1506,69 +1507,69 @@ declare namespace ts { * - import x = M.x; */ export interface ImportEqualsDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ImportEqualsDeclaration; parent: SourceFile | ModuleBlock; - name: Identifier; - moduleReference: ModuleReference; + readonly kind: SyntaxKind.ImportEqualsDeclaration; + readonly name: Identifier; + readonly moduleReference: ModuleReference; } export interface ExternalModuleReference extends Node { - kind: SyntaxKind.ExternalModuleReference; parent: ImportEqualsDeclaration; - expression: Expression; + readonly kind: SyntaxKind.ExternalModuleReference; + readonly expression: Expression; } export interface ImportDeclaration extends Statement, JSDocContainer { - kind: SyntaxKind.ImportDeclaration; parent: SourceFile | ModuleBlock; - importClause?: ImportClause; + readonly kind: SyntaxKind.ImportDeclaration; + readonly importClause?: ImportClause; /** If this is not a StringLiteral it will be a grammar error. */ - moduleSpecifier: Expression; + readonly moduleSpecifier: Expression; } export type NamedImportBindings = NamespaceImport | NamedImports; export interface ImportClause extends NamedDeclaration { - kind: SyntaxKind.ImportClause; parent: ImportDeclaration; - name?: Identifier; - namedBindings?: NamedImportBindings; + readonly kind: SyntaxKind.ImportClause; + readonly name?: Identifier; + readonly namedBindings?: NamedImportBindings; } export interface NamespaceImport extends NamedDeclaration { - kind: SyntaxKind.NamespaceImport; parent: ImportClause; - name: Identifier; + readonly kind: SyntaxKind.NamespaceImport; + readonly name: Identifier; } export interface NamespaceExportDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.NamespaceExportDeclaration; - name: Identifier; + readonly kind: SyntaxKind.NamespaceExportDeclaration; + readonly name: Identifier; } export interface ExportDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ExportDeclaration; parent: SourceFile | ModuleBlock; + readonly kind: SyntaxKind.ExportDeclaration; /** Will not be assigned in the case of `export * from "foo";` */ - exportClause?: NamedExports; + readonly exportClause?: NamedExports; /** If this is not a StringLiteral it will be a grammar error. */ - moduleSpecifier?: Expression; + readonly moduleSpecifier?: Expression; } export interface NamedImports extends Node { - kind: SyntaxKind.NamedImports; parent: ImportClause; - elements: NodeArray; + readonly kind: SyntaxKind.NamedImports; + readonly elements: NodeArray; } export interface NamedExports extends Node { - kind: SyntaxKind.NamedExports; parent: ExportDeclaration; - elements: NodeArray; + readonly kind: SyntaxKind.NamedExports; + readonly elements: NodeArray; } export type NamedImportsOrExports = NamedImports | NamedExports; export interface ImportSpecifier extends NamedDeclaration { - kind: SyntaxKind.ImportSpecifier; parent: NamedImports; - propertyName?: Identifier; - name: Identifier; + readonly kind: SyntaxKind.ImportSpecifier; + readonly propertyName?: Identifier; + readonly name: Identifier; } export interface ExportSpecifier extends NamedDeclaration { - kind: SyntaxKind.ExportSpecifier; parent: NamedExports; - propertyName?: Identifier; - name: Identifier; + readonly kind: SyntaxKind.ExportSpecifier; + readonly propertyName?: Identifier; + readonly name: Identifier; } export type ImportOrExportSpecifier = ImportSpecifier | ExportSpecifier; /** @@ -1576,10 +1577,10 @@ declare namespace ts { * Unless `isExportEquals` is set, this node was parsed as an `export default`. */ export interface ExportAssignment extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ExportAssignment; parent: SourceFile; - isExportEquals?: boolean; - expression: Expression; + readonly kind: SyntaxKind.ExportAssignment; + readonly isExportEquals?: boolean; + readonly expression: Expression; } export interface FileReference extends TextRange { fileName: string; @@ -1598,133 +1599,133 @@ declare namespace ts { end: -1; } export interface JSDocTypeExpression extends TypeNode { - kind: SyntaxKind.JSDocTypeExpression; - type: TypeNode; + readonly kind: SyntaxKind.JSDocTypeExpression; + readonly type: TypeNode; } export interface JSDocType extends TypeNode { _jsDocTypeBrand: any; } export interface JSDocAllType extends JSDocType { - kind: SyntaxKind.JSDocAllType; + readonly kind: SyntaxKind.JSDocAllType; } export interface JSDocUnknownType extends JSDocType { - kind: SyntaxKind.JSDocUnknownType; + readonly kind: SyntaxKind.JSDocUnknownType; } export interface JSDocNonNullableType extends JSDocType { - kind: SyntaxKind.JSDocNonNullableType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocNonNullableType; + readonly type: TypeNode; } export interface JSDocNullableType extends JSDocType { - kind: SyntaxKind.JSDocNullableType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocNullableType; + readonly type: TypeNode; } export interface JSDocOptionalType extends JSDocType { - kind: SyntaxKind.JSDocOptionalType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocOptionalType; + readonly type: TypeNode; } export interface JSDocFunctionType extends JSDocType, SignatureDeclarationBase { - kind: SyntaxKind.JSDocFunctionType; + readonly kind: SyntaxKind.JSDocFunctionType; } export interface JSDocVariadicType extends JSDocType { - kind: SyntaxKind.JSDocVariadicType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocVariadicType; + readonly type: TypeNode; } export interface JSDocNamepathType extends JSDocType { - kind: SyntaxKind.JSDocNamepathType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocNamepathType; + readonly type: TypeNode; } export type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; export interface JSDoc extends Node { - kind: SyntaxKind.JSDocComment; parent: HasJSDoc; - tags?: NodeArray; + readonly kind: SyntaxKind.JSDocComment; + readonly tags?: NodeArray; comment?: string; } export interface JSDocTag extends Node { parent: JSDoc | JSDocTypeLiteral; - tagName: Identifier; + readonly tagName: Identifier; comment?: string; } export interface JSDocUnknownTag extends JSDocTag { - kind: SyntaxKind.JSDocTag; + readonly kind: SyntaxKind.JSDocTag; } /** * Note that `@extends` is a synonym of `@augments`. * Both tags are represented by this interface. */ export interface JSDocAugmentsTag extends JSDocTag { - kind: SyntaxKind.JSDocAugmentsTag; - class: ExpressionWithTypeArguments & { - expression: Identifier | PropertyAccessEntityNameExpression; + readonly kind: SyntaxKind.JSDocAugmentsTag; + readonly class: ExpressionWithTypeArguments & { + readonly expression: Identifier | PropertyAccessEntityNameExpression; }; } export interface JSDocAuthorTag extends JSDocTag { - kind: SyntaxKind.JSDocAuthorTag; + readonly kind: SyntaxKind.JSDocAuthorTag; } export interface JSDocClassTag extends JSDocTag { - kind: SyntaxKind.JSDocClassTag; + readonly kind: SyntaxKind.JSDocClassTag; } export interface JSDocEnumTag extends JSDocTag, Declaration { parent: JSDoc; - kind: SyntaxKind.JSDocEnumTag; - typeExpression?: JSDocTypeExpression; + readonly kind: SyntaxKind.JSDocEnumTag; + readonly typeExpression?: JSDocTypeExpression; } export interface JSDocThisTag extends JSDocTag { - kind: SyntaxKind.JSDocThisTag; - typeExpression?: JSDocTypeExpression; + readonly kind: SyntaxKind.JSDocThisTag; + readonly typeExpression?: JSDocTypeExpression; } export interface JSDocTemplateTag extends JSDocTag { - kind: SyntaxKind.JSDocTemplateTag; - constraint: JSDocTypeExpression | undefined; - typeParameters: NodeArray; + readonly kind: SyntaxKind.JSDocTemplateTag; + readonly constraint: JSDocTypeExpression | undefined; + readonly typeParameters: NodeArray; } export interface JSDocReturnTag extends JSDocTag { - kind: SyntaxKind.JSDocReturnTag; - typeExpression?: JSDocTypeExpression; + readonly kind: SyntaxKind.JSDocReturnTag; + readonly typeExpression?: JSDocTypeExpression; } export interface JSDocTypeTag extends JSDocTag { - kind: SyntaxKind.JSDocTypeTag; - typeExpression: JSDocTypeExpression; + readonly kind: SyntaxKind.JSDocTypeTag; + readonly typeExpression: JSDocTypeExpression; } export interface JSDocTypedefTag extends JSDocTag, NamedDeclaration { parent: JSDoc; - kind: SyntaxKind.JSDocTypedefTag; - fullName?: JSDocNamespaceDeclaration | Identifier; - name?: Identifier; - typeExpression?: JSDocTypeExpression | JSDocTypeLiteral; + readonly kind: SyntaxKind.JSDocTypedefTag; + readonly fullName?: JSDocNamespaceDeclaration | Identifier; + readonly name?: Identifier; + readonly typeExpression?: JSDocTypeExpression | JSDocTypeLiteral; } export interface JSDocCallbackTag extends JSDocTag, NamedDeclaration { parent: JSDoc; - kind: SyntaxKind.JSDocCallbackTag; - fullName?: JSDocNamespaceDeclaration | Identifier; - name?: Identifier; - typeExpression: JSDocSignature; + readonly kind: SyntaxKind.JSDocCallbackTag; + readonly fullName?: JSDocNamespaceDeclaration | Identifier; + readonly name?: Identifier; + readonly typeExpression: JSDocSignature; } export interface JSDocSignature extends JSDocType, Declaration { - kind: SyntaxKind.JSDocSignature; - typeParameters?: readonly JSDocTemplateTag[]; - parameters: readonly JSDocParameterTag[]; - type: JSDocReturnTag | undefined; + readonly kind: SyntaxKind.JSDocSignature; + readonly typeParameters?: readonly JSDocTemplateTag[]; + readonly parameters: readonly JSDocParameterTag[]; + readonly type: JSDocReturnTag | undefined; } export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { parent: JSDoc; - name: EntityName; - typeExpression?: JSDocTypeExpression; + readonly name: EntityName; + readonly typeExpression?: JSDocTypeExpression; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ - isNameFirst: boolean; - isBracketed: boolean; + readonly isNameFirst: boolean; + readonly isBracketed: boolean; } export interface JSDocPropertyTag extends JSDocPropertyLikeTag { - kind: SyntaxKind.JSDocPropertyTag; + readonly kind: SyntaxKind.JSDocPropertyTag; } export interface JSDocParameterTag extends JSDocPropertyLikeTag { - kind: SyntaxKind.JSDocParameterTag; + readonly kind: SyntaxKind.JSDocParameterTag; } export interface JSDocTypeLiteral extends JSDocType { - kind: SyntaxKind.JSDocTypeLiteral; - jsDocPropertyTags?: readonly JSDocPropertyLikeTag[]; + readonly kind: SyntaxKind.JSDocTypeLiteral; + readonly jsDocPropertyTags?: readonly JSDocPropertyLikeTag[]; /** If true, then this type literal represents an *array* of its type. */ - isArrayType?: boolean; + readonly isArrayType?: boolean; } export enum FlowFlags { Unreachable = 1, @@ -1797,9 +1798,9 @@ declare namespace ts { name?: string; } export interface SourceFile extends Declaration { - kind: SyntaxKind.SourceFile; - statements: NodeArray; - endOfFileToken: Token; + readonly kind: SyntaxKind.SourceFile; + readonly statements: NodeArray; + readonly endOfFileToken: Token; fileName: string; text: string; amdDependencies: readonly AmdDependency[]; @@ -1821,12 +1822,12 @@ declare namespace ts { languageVersion: ScriptTarget; } export interface Bundle extends Node { - kind: SyntaxKind.Bundle; - prepends: readonly (InputFiles | UnparsedSource)[]; - sourceFiles: readonly SourceFile[]; + readonly kind: SyntaxKind.Bundle; + readonly prepends: readonly (InputFiles | UnparsedSource)[]; + readonly sourceFiles: readonly SourceFile[]; } export interface InputFiles extends Node { - kind: SyntaxKind.InputFiles; + readonly kind: SyntaxKind.InputFiles; javascriptPath?: string; javascriptText: string; javascriptMapPath?: string; @@ -1837,10 +1838,10 @@ declare namespace ts { declarationMapText?: string; } export interface UnparsedSource extends Node { - kind: SyntaxKind.UnparsedSource; + readonly kind: SyntaxKind.UnparsedSource; fileName: string; text: string; - prologues: readonly UnparsedPrologue[]; + readonly prologues: readonly UnparsedPrologue[]; helpers: readonly UnscopedEmitHelper[] | undefined; referencedFiles: readonly FileReference[]; typeReferenceDirectives: readonly string[] | undefined; @@ -1848,48 +1849,49 @@ declare namespace ts { hasNoDefaultLib?: boolean; sourceMapPath?: string; sourceMapText?: string; - syntheticReferences?: readonly UnparsedSyntheticReference[]; - texts: readonly UnparsedSourceText[]; + readonly syntheticReferences?: readonly UnparsedSyntheticReference[]; + readonly texts: readonly UnparsedSourceText[]; } export type UnparsedSourceText = UnparsedPrepend | UnparsedTextLike; export type UnparsedNode = UnparsedPrologue | UnparsedSourceText | UnparsedSyntheticReference; export interface UnparsedSection extends Node { - kind: SyntaxKind; - data?: string; parent: UnparsedSource; + readonly kind: SyntaxKind; + readonly data?: string; } export interface UnparsedPrologue extends UnparsedSection { - kind: SyntaxKind.UnparsedPrologue; - data: string; parent: UnparsedSource; + readonly kind: SyntaxKind.UnparsedPrologue; + readonly data: string; } export interface UnparsedPrepend extends UnparsedSection { - kind: SyntaxKind.UnparsedPrepend; - data: string; parent: UnparsedSource; - texts: readonly UnparsedTextLike[]; + readonly kind: SyntaxKind.UnparsedPrepend; + readonly data: string; + readonly texts: readonly UnparsedTextLike[]; } export interface UnparsedTextLike extends UnparsedSection { - kind: SyntaxKind.UnparsedText | SyntaxKind.UnparsedInternalText; parent: UnparsedSource; + readonly kind: SyntaxKind.UnparsedText | SyntaxKind.UnparsedInternalText; } export interface UnparsedSyntheticReference extends UnparsedSection { - kind: SyntaxKind.UnparsedSyntheticReference; parent: UnparsedSource; + readonly kind: SyntaxKind.UnparsedSyntheticReference; } export interface JsonSourceFile extends SourceFile { - statements: NodeArray; + readonly statements: NodeArray; } export interface TsConfigSourceFile extends JsonSourceFile { extendedSourceFiles?: string[]; } export interface JsonMinusNumericLiteral extends PrefixUnaryExpression { - kind: SyntaxKind.PrefixUnaryExpression; - operator: SyntaxKind.MinusToken; - operand: NumericLiteral; + readonly kind: SyntaxKind.PrefixUnaryExpression; + readonly operator: SyntaxKind.MinusToken; + readonly operand: NumericLiteral; } + export type JsonObjectExpression = ObjectLiteralExpression | ArrayLiteralExpression | JsonMinusNumericLiteral | NumericLiteral | StringLiteral | BooleanLiteral | NullLiteral; export interface JsonObjectExpressionStatement extends ExpressionStatement { - expression: ObjectLiteralExpression | ArrayLiteralExpression | JsonMinusNumericLiteral | NumericLiteral | StringLiteral | BooleanLiteral | NullLiteral; + readonly expression: JsonObjectExpression; } export interface ScriptReferenceHost { getCompilerOptions(): CompilerOptions; @@ -3062,7 +3064,7 @@ declare namespace ts { createInferTypeNode(typeParameter: TypeParameterDeclaration): InferTypeNode; updateInferTypeNode(node: InferTypeNode, typeParameter: TypeParameterDeclaration): InferTypeNode; createImportTypeNode(argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; - updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; + updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode; createParenthesizedType(type: TypeNode): ParenthesizedTypeNode; updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode; createThisTypeNode(): ThisTypeNode; @@ -3271,7 +3273,7 @@ declare namespace ts { updateSpreadAssignment(node: SpreadAssignment, expression: Expression): SpreadAssignment; createEnumMember(name: string | PropertyName, initializer?: Expression): EnumMember; updateEnumMember(node: EnumMember, name: PropertyName, initializer: Expression | undefined): EnumMember; - createSourceFile(statements: readonly Statement[], endOfFileToken: EndOfFileToken): SourceFile; + createSourceFile(statements: readonly Statement[], endOfFileToken: EndOfFileToken, flags: NodeFlags): SourceFile; updateSourceFile(node: SourceFile, statements: readonly Statement[], isDeclarationFile?: boolean, referencedFiles?: readonly FileReference[], typeReferences?: readonly FileReference[], hasNoDefaultLib?: boolean, libReferences?: readonly FileReference[]): SourceFile; createNotEmittedStatement(original: Node): NotEmittedStatement; createPartiallyEmittedExpression(expression: Expression, original?: Node): PartiallyEmittedExpression; @@ -3413,6 +3415,14 @@ declare namespace ts { * A function that accepts and possibly transforms a node. */ export type Visitor = (node: Node) => VisitResult; + export interface NodeVisitor { + (nodes: T, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T; + (nodes: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T | undefined; + } + export interface NodesVisitor { + (nodes: NodeArray, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; + (nodes: NodeArray | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; + } export type VisitResult = T | T[] | undefined; export interface Printer { /** @@ -4366,7 +4376,7 @@ declare namespace ts { * @param test A callback to execute to verify the Node is valid. * @param lift An optional callback to execute to lift a NodeArray into a valid Node. */ - function visitNode(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T; + function visitNode(node: T, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T; /** * Visits a Node using the supplied visitor, possibly returning a new Node in its place. * @@ -4385,7 +4395,7 @@ declare namespace ts { * @param start An optional value indicating the starting offset at which to start visiting. * @param count An optional value indicating the maximum number of nodes to visit. */ - function visitNodes(nodes: NodeArray | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; + function visitNodes(nodes: NodeArray, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; /** * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. * @@ -4395,17 +4405,22 @@ declare namespace ts { * @param start An optional value indicating the starting offset at which to start visiting. * @param count An optional value indicating the maximum number of nodes to visit. */ - function visitNodes(nodes: NodeArray | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; + function visitNodes(nodes: NodeArray | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; /** * Starts a new lexical environment and visits a statement list, ending the lexical environment * and merging hoisted declarations upon completion. */ - function visitLexicalEnvironment(statements: NodeArray, visitor: Visitor, context: TransformationContext, start?: number, ensureUseStrict?: boolean): NodeArray; + function visitLexicalEnvironment(statements: NodeArray, visitor: Visitor, context: TransformationContext, start?: number, ensureUseStrict?: boolean, nodesVisitor?: NodesVisitor): NodeArray; + /** + * Starts a new lexical environment and visits a parameter list, suspending the lexical + * environment upon completion. + */ + function visitParameterList(nodes: NodeArray, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray; /** * Starts a new lexical environment and visits a parameter list, suspending the lexical * environment upon completion. */ - function visitParameterList(nodes: NodeArray | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes): NodeArray; + function visitParameterList(nodes: NodeArray | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray | undefined; /** * Resumes a suspended lexical environment and visits a function body, ending the lexical * environment and merging hoisted declarations upon completion. @@ -4436,7 +4451,7 @@ declare namespace ts { * @param visitor The callback used to visit each child. * @param context A lexical environment context for the visitor. */ - function visitEachChild(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined; + function visitEachChild(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor, tokenVisitor?: Visitor): T | undefined; } declare namespace ts { function getTsBuildInfoEmitOutputFilePath(options: CompilerOptions): string | undefined; @@ -9665,7 +9680,7 @@ declare namespace ts { /** * @deprecated Use `factory.updateImportTypeNode` or the factory supplied by your transformation context instead. */ - updateImportTypeNode: (node: ImportTypeNode, argument: TypeNode, qualifier?: Identifier | QualifiedName | undefined, typeArguments?: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined) => ImportTypeNode, + updateImportTypeNode: (node: ImportTypeNode, argument: TypeNode, qualifier: Identifier | QualifiedName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined) => ImportTypeNode, /** * @deprecated Use `factory.createParenthesizedType` or the factory supplied by your transformation context instead. */ @@ -10709,7 +10724,11 @@ declare namespace ts { */ function createLogicalNot(operand: Expression): PrefixUnaryExpression; /** - * Creates a shallow, memberwise clone of a node for mutation. + * Creates a shallow, memberwise clone of a node ~for mutation~ with its `pos`, `end`, and `parent` set. + * + * NOTE: It is unsafe to change any properties of a `Node` that relate to its AST children, as those changes won't be + * captured with respect to transformations. + * * @deprecated Use `factory.cloneNode` instead and set `pos`, `end`, and `parent` as needed. */ function getMutableClone(node: T): T; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index b0e8f2bb85c78..7b69bbdb735bb 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -501,10 +501,10 @@ declare namespace ts { IntrinsicElement = 3 } export interface Node extends TextRange { - kind: SyntaxKind; - flags: NodeFlags; - decorators?: NodeArray; - modifiers?: ModifiersArray; + readonly kind: SyntaxKind; + readonly flags: NodeFlags; + readonly decorators?: NodeArray; + readonly modifiers?: ModifiersArray; parent: Node; } export interface JSDocContainer { @@ -517,7 +517,7 @@ declare namespace ts { hasTrailingComma?: boolean; } export interface Token extends Node { - kind: TKind; + readonly kind: TKind; } export type EndOfFileToken = Token & JSDocContainer; export interface PunctuationToken extends Token { @@ -562,22 +562,22 @@ declare namespace ts { export type ClassMemberModifier = AccessibilityModifier | ReadonlyKeyword | StaticKeyword; export type ModifiersArray = NodeArray; export interface Identifier extends PrimaryExpression, Declaration { - kind: SyntaxKind.Identifier; + readonly kind: SyntaxKind.Identifier; /** * Prefer to use `id.unescapedText`. (Note: This is available only in services, not internally to the TypeScript compiler.) * Text of identifier, but if the identifier begins with two underscores, this will begin with three. */ - escapedText: __String; - originalKeywordKind?: SyntaxKind; + readonly escapedText: __String; + readonly originalKeywordKind?: SyntaxKind; isInJSDocNamespace?: boolean; } export interface TransientIdentifier extends Identifier { resolvedSymbol: Symbol; } export interface QualifiedName extends Node { - kind: SyntaxKind.QualifiedName; - left: EntityName; - right: Identifier; + readonly kind: SyntaxKind.QualifiedName; + readonly left: EntityName; + readonly right: Identifier; } export type EntityName = Identifier | QualifiedName; export type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName; @@ -586,132 +586,132 @@ declare namespace ts { _declarationBrand: any; } export interface NamedDeclaration extends Declaration { - name?: DeclarationName; + readonly name?: DeclarationName; } export interface DeclarationStatement extends NamedDeclaration, Statement { - name?: Identifier | StringLiteral | NumericLiteral; + readonly name?: Identifier | StringLiteral | NumericLiteral; } export interface ComputedPropertyName extends Node { parent: Declaration; - kind: SyntaxKind.ComputedPropertyName; - expression: Expression; + readonly kind: SyntaxKind.ComputedPropertyName; + readonly expression: Expression; } export interface Decorator extends Node { - kind: SyntaxKind.Decorator; - parent: NamedDeclaration; - expression: LeftHandSideExpression; + readonly kind: SyntaxKind.Decorator; + readonly parent: NamedDeclaration; + readonly expression: LeftHandSideExpression; } export interface TypeParameterDeclaration extends NamedDeclaration { - kind: SyntaxKind.TypeParameter; - parent: DeclarationWithTypeParameterChildren | InferTypeNode; - name: Identifier; + readonly kind: SyntaxKind.TypeParameter; + readonly parent: DeclarationWithTypeParameterChildren | InferTypeNode; + readonly name: Identifier; /** Note: Consider calling `getEffectiveConstraintOfTypeParameter` */ - constraint?: TypeNode; - default?: TypeNode; + readonly constraint?: TypeNode; + readonly default?: TypeNode; expression?: Expression; } export interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { - kind: SignatureDeclaration["kind"]; - name?: PropertyName; - typeParameters?: NodeArray; - parameters: NodeArray; - type?: TypeNode; + readonly kind: SignatureDeclaration["kind"]; + readonly name?: PropertyName; + readonly typeParameters?: NodeArray; + readonly parameters: NodeArray; + readonly type?: TypeNode; } export type SignatureDeclaration = CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | AccessorDeclaration | FunctionExpression | ArrowFunction; export interface CallSignatureDeclaration extends SignatureDeclarationBase, TypeElement { - kind: SyntaxKind.CallSignature; + readonly kind: SyntaxKind.CallSignature; } export interface ConstructSignatureDeclaration extends SignatureDeclarationBase, TypeElement { - kind: SyntaxKind.ConstructSignature; + readonly kind: SyntaxKind.ConstructSignature; } export type BindingName = Identifier | BindingPattern; export interface VariableDeclaration extends NamedDeclaration { - kind: SyntaxKind.VariableDeclaration; - parent: VariableDeclarationList | CatchClause; - name: BindingName; - exclamationToken?: ExclamationToken; - type?: TypeNode; - initializer?: Expression; + readonly kind: SyntaxKind.VariableDeclaration; + readonly parent: VariableDeclarationList | CatchClause; + readonly name: BindingName; + readonly exclamationToken?: ExclamationToken; + readonly type?: TypeNode; + readonly initializer?: Expression; } export interface VariableDeclarationList extends Node { - kind: SyntaxKind.VariableDeclarationList; - parent: VariableStatement | ForStatement | ForOfStatement | ForInStatement; - declarations: NodeArray; + readonly kind: SyntaxKind.VariableDeclarationList; + readonly parent: VariableStatement | ForStatement | ForOfStatement | ForInStatement; + readonly declarations: NodeArray; } export interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { - kind: SyntaxKind.Parameter; - parent: SignatureDeclaration; - dotDotDotToken?: DotDotDotToken; - name: BindingName; - questionToken?: QuestionToken; - type?: TypeNode; - initializer?: Expression; + readonly kind: SyntaxKind.Parameter; + readonly parent: SignatureDeclaration; + readonly dotDotDotToken?: DotDotDotToken; + readonly name: BindingName; + readonly questionToken?: QuestionToken; + readonly type?: TypeNode; + readonly initializer?: Expression; } export interface BindingElement extends NamedDeclaration { - kind: SyntaxKind.BindingElement; - parent: BindingPattern; - propertyName?: PropertyName; - dotDotDotToken?: DotDotDotToken; - name: BindingName; - initializer?: Expression; + readonly kind: SyntaxKind.BindingElement; + readonly parent: BindingPattern; + readonly propertyName?: PropertyName; + readonly dotDotDotToken?: DotDotDotToken; + readonly name: BindingName; + readonly initializer?: Expression; } export interface PropertySignature extends TypeElement, JSDocContainer { - kind: SyntaxKind.PropertySignature; - name: PropertyName; - questionToken?: QuestionToken; - type?: TypeNode; + readonly kind: SyntaxKind.PropertySignature; + readonly name: PropertyName; + readonly questionToken?: QuestionToken; + readonly type?: TypeNode; initializer?: Expression; } export interface PropertyDeclaration extends ClassElement, JSDocContainer { - kind: SyntaxKind.PropertyDeclaration; - parent: ClassLikeDeclaration; - name: PropertyName; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; - type?: TypeNode; - initializer?: Expression; + readonly kind: SyntaxKind.PropertyDeclaration; + readonly parent: ClassLikeDeclaration; + readonly name: PropertyName; + readonly questionToken?: QuestionToken; + readonly exclamationToken?: ExclamationToken; + readonly type?: TypeNode; + readonly initializer?: Expression; } export interface ObjectLiteralElement extends NamedDeclaration { _objectLiteralBrand: any; - name?: PropertyName; + readonly name?: PropertyName; } /** Unlike ObjectLiteralElement, excludes JSXAttribute and JSXSpreadAttribute. */ export type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment | MethodDeclaration | AccessorDeclaration; export interface PropertyAssignment extends ObjectLiteralElement, JSDocContainer { parent: ObjectLiteralExpression; - kind: SyntaxKind.PropertyAssignment; - name: PropertyName; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; - initializer: Expression; + readonly kind: SyntaxKind.PropertyAssignment; + readonly name: PropertyName; + readonly questionToken?: QuestionToken; + readonly exclamationToken?: ExclamationToken; + readonly initializer: Expression; } export interface ShorthandPropertyAssignment extends ObjectLiteralElement, JSDocContainer { parent: ObjectLiteralExpression; - kind: SyntaxKind.ShorthandPropertyAssignment; - name: Identifier; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; - equalsToken?: Token; - objectAssignmentInitializer?: Expression; + readonly kind: SyntaxKind.ShorthandPropertyAssignment; + readonly name: Identifier; + readonly questionToken?: QuestionToken; + readonly exclamationToken?: ExclamationToken; + readonly equalsToken?: EqualsToken; + readonly objectAssignmentInitializer?: Expression; } export interface SpreadAssignment extends ObjectLiteralElement, JSDocContainer { parent: ObjectLiteralExpression; - kind: SyntaxKind.SpreadAssignment; - expression: Expression; + readonly kind: SyntaxKind.SpreadAssignment; + readonly expression: Expression; } export type VariableLikeDeclaration = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | PropertySignature | JsxAttribute | ShorthandPropertyAssignment | EnumMember | JSDocPropertyTag | JSDocParameterTag; export interface PropertyLikeDeclaration extends NamedDeclaration { - name: PropertyName; + readonly name: PropertyName; } export interface ObjectBindingPattern extends Node { - kind: SyntaxKind.ObjectBindingPattern; parent: VariableDeclaration | ParameterDeclaration | BindingElement; - elements: NodeArray; + readonly kind: SyntaxKind.ObjectBindingPattern; + readonly elements: NodeArray; } export interface ArrayBindingPattern extends Node { - kind: SyntaxKind.ArrayBindingPattern; parent: VariableDeclaration | ParameterDeclaration | BindingElement; - elements: NodeArray; + readonly kind: SyntaxKind.ArrayBindingPattern; + readonly elements: NodeArray; } export type BindingPattern = ObjectBindingPattern | ArrayBindingPattern; export type ArrayBindingElement = BindingElement | OmittedExpression; @@ -725,169 +725,170 @@ declare namespace ts { */ export interface FunctionLikeDeclarationBase extends SignatureDeclarationBase { _functionLikeDeclarationBrand: any; - asteriskToken?: AsteriskToken; - questionToken?: QuestionToken; - exclamationToken?: ExclamationToken; - body?: Block | Expression; + readonly asteriskToken?: AsteriskToken; + readonly questionToken?: QuestionToken; + readonly exclamationToken?: ExclamationToken; + readonly body?: Block | Expression; } export type FunctionLikeDeclaration = FunctionDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ConstructorDeclaration | FunctionExpression | ArrowFunction; /** @deprecated Use SignatureDeclaration */ export type FunctionLike = SignatureDeclaration; export interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement { - kind: SyntaxKind.FunctionDeclaration; - name?: Identifier; - body?: FunctionBody; + readonly kind: SyntaxKind.FunctionDeclaration; + readonly name?: Identifier; + readonly body?: FunctionBody; } export interface MethodSignature extends SignatureDeclarationBase, TypeElement { - kind: SyntaxKind.MethodSignature; parent: ObjectTypeDeclaration; - name: PropertyName; + readonly kind: SyntaxKind.MethodSignature; + readonly name: PropertyName; } export interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { - kind: SyntaxKind.MethodDeclaration; parent: ClassLikeDeclaration | ObjectLiteralExpression; - name: PropertyName; - body?: FunctionBody; + readonly kind: SyntaxKind.MethodDeclaration; + readonly name: PropertyName; + readonly body?: FunctionBody; } export interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElement, JSDocContainer { - kind: SyntaxKind.Constructor; parent: ClassLikeDeclaration; - body?: FunctionBody; + readonly kind: SyntaxKind.Constructor; + readonly body?: FunctionBody; } /** For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. */ export interface SemicolonClassElement extends ClassElement { - kind: SyntaxKind.SemicolonClassElement; parent: ClassLikeDeclaration; + readonly kind: SyntaxKind.SemicolonClassElement; } export interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { - kind: SyntaxKind.GetAccessor; parent: ClassLikeDeclaration | ObjectLiteralExpression; - name: PropertyName; - body?: FunctionBody; + readonly kind: SyntaxKind.GetAccessor; + readonly name: PropertyName; + readonly body?: FunctionBody; } export interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { - kind: SyntaxKind.SetAccessor; parent: ClassLikeDeclaration | ObjectLiteralExpression; - name: PropertyName; - body?: FunctionBody; + readonly kind: SyntaxKind.SetAccessor; + readonly name: PropertyName; + readonly body?: FunctionBody; } export type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; export interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement { - kind: SyntaxKind.IndexSignature; parent: ObjectTypeDeclaration; + readonly kind: SyntaxKind.IndexSignature; + readonly type: TypeNode; } export interface TypeNode extends Node { _typeNodeBrand: any; } export interface KeywordTypeNode extends KeywordToken, TypeNode { - kind: TKind; + readonly kind: TKind; } export interface ImportTypeNode extends NodeWithTypeArguments { - kind: SyntaxKind.ImportType; - isTypeOf?: boolean; - argument: TypeNode; - qualifier?: EntityName; + readonly kind: SyntaxKind.ImportType; + readonly isTypeOf: boolean; + readonly argument: TypeNode; + readonly qualifier?: EntityName; } export interface ThisTypeNode extends TypeNode { - kind: SyntaxKind.ThisType; + readonly kind: SyntaxKind.ThisType; } export type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; export interface FunctionOrConstructorTypeNodeBase extends TypeNode, SignatureDeclarationBase { - kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType; - type: TypeNode; + readonly kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType; + readonly type: TypeNode; } export interface FunctionTypeNode extends FunctionOrConstructorTypeNodeBase { - kind: SyntaxKind.FunctionType; + readonly kind: SyntaxKind.FunctionType; } export interface ConstructorTypeNode extends FunctionOrConstructorTypeNodeBase { - kind: SyntaxKind.ConstructorType; + readonly kind: SyntaxKind.ConstructorType; } export interface NodeWithTypeArguments extends TypeNode { - typeArguments?: NodeArray; + readonly typeArguments?: NodeArray; } export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; export interface TypeReferenceNode extends NodeWithTypeArguments { - kind: SyntaxKind.TypeReference; - typeName: EntityName; + readonly kind: SyntaxKind.TypeReference; + readonly typeName: EntityName; } export interface TypePredicateNode extends TypeNode { - kind: SyntaxKind.TypePredicate; - parent: SignatureDeclaration | JSDocTypeExpression; - assertsModifier?: AssertsToken; - parameterName: Identifier | ThisTypeNode; - type?: TypeNode; + readonly kind: SyntaxKind.TypePredicate; + readonly parent: SignatureDeclaration | JSDocTypeExpression; + readonly assertsModifier?: AssertsToken; + readonly parameterName: Identifier | ThisTypeNode; + readonly type?: TypeNode; } export interface TypeQueryNode extends TypeNode { - kind: SyntaxKind.TypeQuery; - exprName: EntityName; + readonly kind: SyntaxKind.TypeQuery; + readonly exprName: EntityName; } export interface TypeLiteralNode extends TypeNode, Declaration { - kind: SyntaxKind.TypeLiteral; - members: NodeArray; + readonly kind: SyntaxKind.TypeLiteral; + readonly members: NodeArray; } export interface ArrayTypeNode extends TypeNode { - kind: SyntaxKind.ArrayType; - elementType: TypeNode; + readonly kind: SyntaxKind.ArrayType; + readonly elementType: TypeNode; } export interface TupleTypeNode extends TypeNode { - kind: SyntaxKind.TupleType; - elementTypes: NodeArray; + readonly kind: SyntaxKind.TupleType; + readonly elementTypes: NodeArray; } export interface OptionalTypeNode extends TypeNode { - kind: SyntaxKind.OptionalType; - type: TypeNode; + readonly kind: SyntaxKind.OptionalType; + readonly type: TypeNode; } export interface RestTypeNode extends TypeNode { - kind: SyntaxKind.RestType; - type: TypeNode; + readonly kind: SyntaxKind.RestType; + readonly type: TypeNode; } export type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; export interface UnionTypeNode extends TypeNode { - kind: SyntaxKind.UnionType; - types: NodeArray; + readonly kind: SyntaxKind.UnionType; + readonly types: NodeArray; } export interface IntersectionTypeNode extends TypeNode { - kind: SyntaxKind.IntersectionType; - types: NodeArray; + readonly kind: SyntaxKind.IntersectionType; + readonly types: NodeArray; } export interface ConditionalTypeNode extends TypeNode { - kind: SyntaxKind.ConditionalType; - checkType: TypeNode; - extendsType: TypeNode; - trueType: TypeNode; - falseType: TypeNode; + readonly kind: SyntaxKind.ConditionalType; + readonly checkType: TypeNode; + readonly extendsType: TypeNode; + readonly trueType: TypeNode; + readonly falseType: TypeNode; } export interface InferTypeNode extends TypeNode { - kind: SyntaxKind.InferType; - typeParameter: TypeParameterDeclaration; + readonly kind: SyntaxKind.InferType; + readonly typeParameter: TypeParameterDeclaration; } export interface ParenthesizedTypeNode extends TypeNode { - kind: SyntaxKind.ParenthesizedType; - type: TypeNode; + readonly kind: SyntaxKind.ParenthesizedType; + readonly type: TypeNode; } export interface TypeOperatorNode extends TypeNode { - kind: SyntaxKind.TypeOperator; - operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; - type: TypeNode; + readonly kind: SyntaxKind.TypeOperator; + readonly operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; + readonly type: TypeNode; } export interface IndexedAccessTypeNode extends TypeNode { - kind: SyntaxKind.IndexedAccessType; - objectType: TypeNode; - indexType: TypeNode; + readonly kind: SyntaxKind.IndexedAccessType; + readonly objectType: TypeNode; + readonly indexType: TypeNode; } export interface MappedTypeNode extends TypeNode, Declaration { - kind: SyntaxKind.MappedType; - readonlyToken?: ReadonlyToken | PlusToken | MinusToken; - typeParameter: TypeParameterDeclaration; - questionToken?: QuestionToken | PlusToken | MinusToken; - type?: TypeNode; + readonly kind: SyntaxKind.MappedType; + readonly readonlyToken?: ReadonlyToken | PlusToken | MinusToken; + readonly typeParameter: TypeParameterDeclaration; + readonly questionToken?: QuestionToken | PlusToken | MinusToken; + readonly type?: TypeNode; } export interface LiteralTypeNode extends TypeNode { - kind: SyntaxKind.LiteralType; - literal: NullLiteral | BooleanLiteral | LiteralExpression | PrefixUnaryExpression; + readonly kind: SyntaxKind.LiteralType; + readonly literal: NullLiteral | BooleanLiteral | LiteralExpression | PrefixUnaryExpression; } export interface StringLiteral extends LiteralExpression, Declaration { - kind: SyntaxKind.StringLiteral; + readonly kind: SyntaxKind.StringLiteral; } export type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral; export type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral; @@ -895,11 +896,11 @@ declare namespace ts { _expressionBrand: any; } export interface OmittedExpression extends Expression { - kind: SyntaxKind.OmittedExpression; + readonly kind: SyntaxKind.OmittedExpression; } export interface PartiallyEmittedExpression extends LeftHandSideExpression { - kind: SyntaxKind.PartiallyEmittedExpression; - expression: Expression; + readonly kind: SyntaxKind.PartiallyEmittedExpression; + readonly expression: Expression; } export interface UnaryExpression extends Expression { _unaryExpressionBrand: any; @@ -911,15 +912,15 @@ declare namespace ts { } export type PrefixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.TildeToken | SyntaxKind.ExclamationToken; export interface PrefixUnaryExpression extends UpdateExpression { - kind: SyntaxKind.PrefixUnaryExpression; - operator: PrefixUnaryOperator; - operand: UnaryExpression; + readonly kind: SyntaxKind.PrefixUnaryExpression; + readonly operator: PrefixUnaryOperator; + readonly operand: UnaryExpression; } export type PostfixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken; export interface PostfixUnaryExpression extends UpdateExpression { - kind: SyntaxKind.PostfixUnaryExpression; - operand: LeftHandSideExpression; - operator: PostfixUnaryOperator; + readonly kind: SyntaxKind.PostfixUnaryExpression; + readonly operand: LeftHandSideExpression; + readonly operator: PostfixUnaryOperator; } export interface LeftHandSideExpression extends UpdateExpression { _leftHandSideExpressionBrand: any; @@ -931,49 +932,49 @@ declare namespace ts { _primaryExpressionBrand: any; } export interface NullLiteral extends PrimaryExpression { - kind: SyntaxKind.NullKeyword; + readonly kind: SyntaxKind.NullKeyword; } export interface TrueLiteral extends PrimaryExpression { - kind: SyntaxKind.TrueKeyword; + readonly kind: SyntaxKind.TrueKeyword; } export interface FalseLiteral extends PrimaryExpression { - kind: SyntaxKind.FalseKeyword; + readonly kind: SyntaxKind.FalseKeyword; } export type BooleanLiteral = TrueLiteral | FalseLiteral; export interface ThisExpression extends PrimaryExpression { - kind: SyntaxKind.ThisKeyword; + readonly kind: SyntaxKind.ThisKeyword; } export interface SuperExpression extends PrimaryExpression { - kind: SyntaxKind.SuperKeyword; + readonly kind: SyntaxKind.SuperKeyword; } export interface ImportExpression extends PrimaryExpression { - kind: SyntaxKind.ImportKeyword; + readonly kind: SyntaxKind.ImportKeyword; } export interface DeleteExpression extends UnaryExpression { - kind: SyntaxKind.DeleteExpression; - expression: UnaryExpression; + readonly kind: SyntaxKind.DeleteExpression; + readonly expression: UnaryExpression; } export interface TypeOfExpression extends UnaryExpression { - kind: SyntaxKind.TypeOfExpression; - expression: UnaryExpression; + readonly kind: SyntaxKind.TypeOfExpression; + readonly expression: UnaryExpression; } export interface VoidExpression extends UnaryExpression { - kind: SyntaxKind.VoidExpression; - expression: UnaryExpression; + readonly kind: SyntaxKind.VoidExpression; + readonly expression: UnaryExpression; } export interface AwaitExpression extends UnaryExpression { - kind: SyntaxKind.AwaitExpression; - expression: UnaryExpression; + readonly kind: SyntaxKind.AwaitExpression; + readonly expression: UnaryExpression; } export interface YieldExpression extends Expression { - kind: SyntaxKind.YieldExpression; - asteriskToken?: AsteriskToken; - expression?: Expression; + readonly kind: SyntaxKind.YieldExpression; + readonly asteriskToken?: AsteriskToken; + readonly expression?: Expression; } export interface SyntheticExpression extends Expression { - kind: SyntaxKind.SyntheticExpression; - isSpread: boolean; - type: Type; + readonly kind: SyntaxKind.SyntheticExpression; + readonly isSpread: boolean; + readonly type: Type; } export type ExponentiationOperator = SyntaxKind.AsteriskAsteriskToken; export type MultiplicativeOperator = SyntaxKind.AsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken; @@ -996,21 +997,21 @@ declare namespace ts { export type BinaryOperator = AssignmentOperatorOrHigher | SyntaxKind.CommaToken; export type BinaryOperatorToken = Token; export interface BinaryExpression extends Expression, Declaration { - kind: SyntaxKind.BinaryExpression; - left: Expression; - operatorToken: BinaryOperatorToken; - right: Expression; + readonly kind: SyntaxKind.BinaryExpression; + readonly left: Expression; + readonly operatorToken: BinaryOperatorToken; + readonly right: Expression; } export type AssignmentOperatorToken = Token; export interface AssignmentExpression extends BinaryExpression { - left: LeftHandSideExpression; - operatorToken: TOperator; + readonly left: LeftHandSideExpression; + readonly operatorToken: TOperator; } export interface ObjectDestructuringAssignment extends AssignmentExpression { - left: ObjectLiteralExpression; + readonly left: ObjectLiteralExpression; } export interface ArrayDestructuringAssignment extends AssignmentExpression { - left: ArrayLiteralExpression; + readonly left: ArrayLiteralExpression; } export type DestructuringAssignment = ObjectDestructuringAssignment | ArrayDestructuringAssignment; export type BindingOrAssignmentElement = VariableDeclaration | ParameterDeclaration | ObjectBindingOrAssignmentElement | ArrayBindingOrAssignmentElement; @@ -1023,25 +1024,25 @@ declare namespace ts { export type AssignmentPattern = ObjectLiteralExpression | ArrayLiteralExpression; export type BindingOrAssignmentPattern = ObjectBindingOrAssignmentPattern | ArrayBindingOrAssignmentPattern; export interface ConditionalExpression extends Expression { - kind: SyntaxKind.ConditionalExpression; - condition: Expression; - questionToken: QuestionToken; - whenTrue: Expression; - colonToken: ColonToken; - whenFalse: Expression; + readonly kind: SyntaxKind.ConditionalExpression; + readonly condition: Expression; + readonly questionToken: QuestionToken; + readonly whenTrue: Expression; + readonly colonToken: ColonToken; + readonly whenFalse: Expression; } export type FunctionBody = Block; export type ConciseBody = FunctionBody | Expression; export interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer { - kind: SyntaxKind.FunctionExpression; - name?: Identifier; - body: FunctionBody; + readonly kind: SyntaxKind.FunctionExpression; + readonly name?: Identifier; + readonly body: FunctionBody; } export interface ArrowFunction extends Expression, FunctionLikeDeclarationBase, JSDocContainer { - kind: SyntaxKind.ArrowFunction; - equalsGreaterThanToken: EqualsGreaterThanToken; - body: ConciseBody; - name: never; + readonly kind: SyntaxKind.ArrowFunction; + readonly equalsGreaterThanToken: EqualsGreaterThanToken; + readonly body: ConciseBody; + readonly name: never; } export interface LiteralLikeNode extends Node { text: string; @@ -1055,10 +1056,10 @@ declare namespace ts { _literalExpressionBrand: any; } export interface RegularExpressionLiteral extends LiteralExpression { - kind: SyntaxKind.RegularExpressionLiteral; + readonly kind: SyntaxKind.RegularExpressionLiteral; } export interface NoSubstitutionTemplateLiteral extends LiteralExpression, TemplateLiteralLikeNode, Declaration { - kind: SyntaxKind.NoSubstitutionTemplateLiteral; + readonly kind: SyntaxKind.NoSubstitutionTemplateLiteral; } export enum TokenFlags { None = 0, @@ -1069,50 +1070,50 @@ declare namespace ts { OctalSpecifier = 256, } export interface NumericLiteral extends LiteralExpression, Declaration { - kind: SyntaxKind.NumericLiteral; + readonly kind: SyntaxKind.NumericLiteral; } export interface BigIntLiteral extends LiteralExpression { - kind: SyntaxKind.BigIntLiteral; + readonly kind: SyntaxKind.BigIntLiteral; } export type LiteralToken = NumericLiteral | BigIntLiteral | StringLiteral | JsxText | RegularExpressionLiteral | NoSubstitutionTemplateLiteral; export interface TemplateHead extends TemplateLiteralLikeNode { - kind: SyntaxKind.TemplateHead; + readonly kind: SyntaxKind.TemplateHead; parent: TemplateExpression; } export interface TemplateMiddle extends TemplateLiteralLikeNode { - kind: SyntaxKind.TemplateMiddle; + readonly kind: SyntaxKind.TemplateMiddle; parent: TemplateSpan; } export interface TemplateTail extends TemplateLiteralLikeNode { - kind: SyntaxKind.TemplateTail; + readonly kind: SyntaxKind.TemplateTail; parent: TemplateSpan; } export type PseudoLiteralToken = TemplateHead | TemplateMiddle | TemplateTail; export type TemplateLiteralToken = NoSubstitutionTemplateLiteral | PseudoLiteralToken; export interface TemplateExpression extends PrimaryExpression { - kind: SyntaxKind.TemplateExpression; - head: TemplateHead; - templateSpans: NodeArray; + readonly kind: SyntaxKind.TemplateExpression; + readonly head: TemplateHead; + readonly templateSpans: NodeArray; } export type TemplateLiteral = TemplateExpression | NoSubstitutionTemplateLiteral; export interface TemplateSpan extends Node { - kind: SyntaxKind.TemplateSpan; parent: TemplateExpression; - expression: Expression; - literal: TemplateMiddle | TemplateTail; + readonly kind: SyntaxKind.TemplateSpan; + readonly expression: Expression; + readonly literal: TemplateMiddle | TemplateTail; } export interface ParenthesizedExpression extends PrimaryExpression, JSDocContainer { - kind: SyntaxKind.ParenthesizedExpression; - expression: Expression; + readonly kind: SyntaxKind.ParenthesizedExpression; + readonly expression: Expression; } export interface ArrayLiteralExpression extends PrimaryExpression { - kind: SyntaxKind.ArrayLiteralExpression; - elements: NodeArray; + readonly kind: SyntaxKind.ArrayLiteralExpression; + readonly elements: NodeArray; } export interface SpreadElement extends Expression { - kind: SyntaxKind.SpreadElement; parent: ArrayLiteralExpression | CallExpression | NewExpression; - expression: Expression; + readonly kind: SyntaxKind.SpreadElement; + readonly expression: Expression; } /** * This interface is a base interface for ObjectLiteralExpression and JSXAttributes to extend from. JSXAttributes is similar to @@ -1121,383 +1122,383 @@ declare namespace ts { * ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.) */ export interface ObjectLiteralExpressionBase extends PrimaryExpression, Declaration { - properties: NodeArray; + readonly properties: NodeArray; } export interface ObjectLiteralExpression extends ObjectLiteralExpressionBase { - kind: SyntaxKind.ObjectLiteralExpression; + readonly kind: SyntaxKind.ObjectLiteralExpression; } export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression; export type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression; export interface PropertyAccessExpression extends MemberExpression, NamedDeclaration { - kind: SyntaxKind.PropertyAccessExpression; - expression: LeftHandSideExpression; - questionDotToken?: QuestionDotToken; - name: Identifier; + readonly kind: SyntaxKind.PropertyAccessExpression; + readonly expression: LeftHandSideExpression; + readonly questionDotToken?: QuestionDotToken; + readonly name: Identifier; } export interface PropertyAccessChain extends PropertyAccessExpression { _optionalChainBrand: any; } export interface SuperPropertyAccessExpression extends PropertyAccessExpression { - expression: SuperExpression; + readonly expression: SuperExpression; } /** Brand for a PropertyAccessExpression which, like a QualifiedName, consists of a sequence of identifiers separated by dots. */ export interface PropertyAccessEntityNameExpression extends PropertyAccessExpression { _propertyAccessExpressionLikeQualifiedNameBrand?: any; - expression: EntityNameExpression; + readonly expression: EntityNameExpression; } export interface ElementAccessExpression extends MemberExpression { - kind: SyntaxKind.ElementAccessExpression; - expression: LeftHandSideExpression; - questionDotToken?: QuestionDotToken; - argumentExpression: Expression; + readonly kind: SyntaxKind.ElementAccessExpression; + readonly expression: LeftHandSideExpression; + readonly questionDotToken?: QuestionDotToken; + readonly argumentExpression: Expression; } export interface ElementAccessChain extends ElementAccessExpression { _optionalChainBrand: any; } export interface SuperElementAccessExpression extends ElementAccessExpression { - expression: SuperExpression; + readonly expression: SuperExpression; } export type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; export interface CallExpression extends LeftHandSideExpression, Declaration { - kind: SyntaxKind.CallExpression; - expression: LeftHandSideExpression; - questionDotToken?: QuestionDotToken; - typeArguments?: NodeArray; - arguments: NodeArray; + readonly kind: SyntaxKind.CallExpression; + readonly expression: LeftHandSideExpression; + readonly questionDotToken?: QuestionDotToken; + readonly typeArguments?: NodeArray; + readonly arguments: NodeArray; } export interface CallChain extends CallExpression { _optionalChainBrand: any; } export type OptionalChain = PropertyAccessChain | ElementAccessChain | CallChain; export interface SuperCall extends CallExpression { - expression: SuperExpression; + readonly expression: SuperExpression; } export interface ImportCall extends CallExpression { - expression: ImportExpression; + readonly expression: ImportExpression; } export interface ExpressionWithTypeArguments extends NodeWithTypeArguments { - kind: SyntaxKind.ExpressionWithTypeArguments; parent: HeritageClause | JSDocAugmentsTag; - expression: LeftHandSideExpression; + readonly kind: SyntaxKind.ExpressionWithTypeArguments; + readonly expression: LeftHandSideExpression; } export interface NewExpression extends PrimaryExpression, Declaration { - kind: SyntaxKind.NewExpression; - expression: LeftHandSideExpression; - typeArguments?: NodeArray; - arguments?: NodeArray; + readonly kind: SyntaxKind.NewExpression; + readonly expression: LeftHandSideExpression; + readonly typeArguments?: NodeArray; + readonly arguments?: NodeArray; } export interface TaggedTemplateExpression extends MemberExpression { - kind: SyntaxKind.TaggedTemplateExpression; - tag: LeftHandSideExpression; - typeArguments?: NodeArray; - template: TemplateLiteral; + readonly kind: SyntaxKind.TaggedTemplateExpression; + readonly tag: LeftHandSideExpression; + readonly typeArguments?: NodeArray; + readonly template: TemplateLiteral; } export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator | JsxOpeningLikeElement; export interface AsExpression extends Expression { - kind: SyntaxKind.AsExpression; - expression: Expression; - type: TypeNode; + readonly kind: SyntaxKind.AsExpression; + readonly expression: Expression; + readonly type: TypeNode; } export interface TypeAssertion extends UnaryExpression { - kind: SyntaxKind.TypeAssertionExpression; - type: TypeNode; - expression: UnaryExpression; + readonly kind: SyntaxKind.TypeAssertionExpression; + readonly type: TypeNode; + readonly expression: UnaryExpression; } export type AssertionExpression = TypeAssertion | AsExpression; export interface NonNullExpression extends LeftHandSideExpression { - kind: SyntaxKind.NonNullExpression; - expression: Expression; + readonly kind: SyntaxKind.NonNullExpression; + readonly expression: Expression; } export interface MetaProperty extends PrimaryExpression { - kind: SyntaxKind.MetaProperty; - keywordToken: SyntaxKind.NewKeyword | SyntaxKind.ImportKeyword; - name: Identifier; + readonly kind: SyntaxKind.MetaProperty; + readonly keywordToken: SyntaxKind.NewKeyword | SyntaxKind.ImportKeyword; + readonly name: Identifier; } export interface JsxElement extends PrimaryExpression { - kind: SyntaxKind.JsxElement; - openingElement: JsxOpeningElement; - children: NodeArray; - closingElement: JsxClosingElement; + readonly kind: SyntaxKind.JsxElement; + readonly openingElement: JsxOpeningElement; + readonly children: NodeArray; + readonly closingElement: JsxClosingElement; } export type JsxOpeningLikeElement = JsxSelfClosingElement | JsxOpeningElement; export type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute; export type JsxTagNameExpression = Identifier | ThisExpression | JsxTagNamePropertyAccess; export interface JsxTagNamePropertyAccess extends PropertyAccessExpression { - expression: JsxTagNameExpression; + readonly expression: JsxTagNameExpression; } export interface JsxAttributes extends ObjectLiteralExpressionBase { - kind: SyntaxKind.JsxAttributes; parent: JsxOpeningLikeElement; + readonly kind: SyntaxKind.JsxAttributes; } export interface JsxOpeningElement extends Expression { - kind: SyntaxKind.JsxOpeningElement; parent: JsxElement; - tagName: JsxTagNameExpression; - typeArguments?: NodeArray; - attributes: JsxAttributes; + readonly kind: SyntaxKind.JsxOpeningElement; + readonly tagName: JsxTagNameExpression; + readonly typeArguments?: NodeArray; + readonly attributes: JsxAttributes; } export interface JsxSelfClosingElement extends PrimaryExpression { - kind: SyntaxKind.JsxSelfClosingElement; - tagName: JsxTagNameExpression; - typeArguments?: NodeArray; - attributes: JsxAttributes; + readonly kind: SyntaxKind.JsxSelfClosingElement; + readonly tagName: JsxTagNameExpression; + readonly typeArguments?: NodeArray; + readonly attributes: JsxAttributes; } export interface JsxFragment extends PrimaryExpression { - kind: SyntaxKind.JsxFragment; - openingFragment: JsxOpeningFragment; - children: NodeArray; - closingFragment: JsxClosingFragment; + readonly kind: SyntaxKind.JsxFragment; + readonly openingFragment: JsxOpeningFragment; + readonly children: NodeArray; + readonly closingFragment: JsxClosingFragment; } export interface JsxOpeningFragment extends Expression { - kind: SyntaxKind.JsxOpeningFragment; parent: JsxFragment; + readonly kind: SyntaxKind.JsxOpeningFragment; } export interface JsxClosingFragment extends Expression { - kind: SyntaxKind.JsxClosingFragment; parent: JsxFragment; + readonly kind: SyntaxKind.JsxClosingFragment; } export interface JsxAttribute extends ObjectLiteralElement { - kind: SyntaxKind.JsxAttribute; parent: JsxAttributes; - name: Identifier; - initializer?: StringLiteral | JsxExpression; + readonly kind: SyntaxKind.JsxAttribute; + readonly name: Identifier; + readonly initializer?: StringLiteral | JsxExpression; } export interface JsxSpreadAttribute extends ObjectLiteralElement { - kind: SyntaxKind.JsxSpreadAttribute; parent: JsxAttributes; - expression: Expression; + readonly kind: SyntaxKind.JsxSpreadAttribute; + readonly expression: Expression; } export interface JsxClosingElement extends Node { - kind: SyntaxKind.JsxClosingElement; parent: JsxElement; - tagName: JsxTagNameExpression; + readonly kind: SyntaxKind.JsxClosingElement; + readonly tagName: JsxTagNameExpression; } export interface JsxExpression extends Expression { - kind: SyntaxKind.JsxExpression; parent: JsxElement | JsxAttributeLike; - dotDotDotToken?: Token; - expression?: Expression; + readonly kind: SyntaxKind.JsxExpression; + readonly dotDotDotToken?: Token; + readonly expression?: Expression; } export interface JsxText extends LiteralLikeNode { - kind: SyntaxKind.JsxText; - containsOnlyTriviaWhiteSpaces: boolean; parent: JsxElement; + readonly kind: SyntaxKind.JsxText; + readonly containsOnlyTriviaWhiteSpaces: boolean; } export type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment; export interface Statement extends Node { _statementBrand: any; } export interface NotEmittedStatement extends Statement { - kind: SyntaxKind.NotEmittedStatement; + readonly kind: SyntaxKind.NotEmittedStatement; } /** * A list of comma-separated expressions. This node is only created by transformations. */ export interface CommaListExpression extends Expression { - kind: SyntaxKind.CommaListExpression; - elements: NodeArray; + readonly kind: SyntaxKind.CommaListExpression; + readonly elements: NodeArray; } export interface EmptyStatement extends Statement { - kind: SyntaxKind.EmptyStatement; + readonly kind: SyntaxKind.EmptyStatement; } export interface DebuggerStatement extends Statement { - kind: SyntaxKind.DebuggerStatement; + readonly kind: SyntaxKind.DebuggerStatement; } export interface MissingDeclaration extends DeclarationStatement { - kind: SyntaxKind.MissingDeclaration; - name?: Identifier; + readonly kind: SyntaxKind.MissingDeclaration; + readonly name?: Identifier; } export type BlockLike = SourceFile | Block | ModuleBlock | CaseOrDefaultClause; export interface Block extends Statement { - kind: SyntaxKind.Block; - statements: NodeArray; + readonly kind: SyntaxKind.Block; + readonly statements: NodeArray; } export interface VariableStatement extends Statement, JSDocContainer { - kind: SyntaxKind.VariableStatement; - declarationList: VariableDeclarationList; + readonly kind: SyntaxKind.VariableStatement; + readonly declarationList: VariableDeclarationList; } export interface ExpressionStatement extends Statement, JSDocContainer { - kind: SyntaxKind.ExpressionStatement; - expression: Expression; + readonly kind: SyntaxKind.ExpressionStatement; + readonly expression: Expression; } export interface IfStatement extends Statement { - kind: SyntaxKind.IfStatement; - expression: Expression; - thenStatement: Statement; - elseStatement?: Statement; + readonly kind: SyntaxKind.IfStatement; + readonly expression: Expression; + readonly thenStatement: Statement; + readonly elseStatement?: Statement; } export interface IterationStatement extends Statement { - statement: Statement; + readonly statement: Statement; } export interface DoStatement extends IterationStatement { - kind: SyntaxKind.DoStatement; - expression: Expression; + readonly kind: SyntaxKind.DoStatement; + readonly expression: Expression; } export interface WhileStatement extends IterationStatement { - kind: SyntaxKind.WhileStatement; - expression: Expression; + readonly kind: SyntaxKind.WhileStatement; + readonly expression: Expression; } export type ForInitializer = VariableDeclarationList | Expression; export interface ForStatement extends IterationStatement { - kind: SyntaxKind.ForStatement; - initializer?: ForInitializer; - condition?: Expression; - incrementor?: Expression; + readonly kind: SyntaxKind.ForStatement; + readonly initializer?: ForInitializer; + readonly condition?: Expression; + readonly incrementor?: Expression; } export type ForInOrOfStatement = ForInStatement | ForOfStatement; export interface ForInStatement extends IterationStatement { - kind: SyntaxKind.ForInStatement; - initializer: ForInitializer; - expression: Expression; + readonly kind: SyntaxKind.ForInStatement; + readonly initializer: ForInitializer; + readonly expression: Expression; } export interface ForOfStatement extends IterationStatement { - kind: SyntaxKind.ForOfStatement; - awaitModifier?: AwaitKeywordToken; - initializer: ForInitializer; - expression: Expression; + readonly kind: SyntaxKind.ForOfStatement; + readonly awaitModifier?: AwaitKeywordToken; + readonly initializer: ForInitializer; + readonly expression: Expression; } export interface BreakStatement extends Statement { - kind: SyntaxKind.BreakStatement; - label?: Identifier; + readonly kind: SyntaxKind.BreakStatement; + readonly label?: Identifier; } export interface ContinueStatement extends Statement { - kind: SyntaxKind.ContinueStatement; - label?: Identifier; + readonly kind: SyntaxKind.ContinueStatement; + readonly label?: Identifier; } export type BreakOrContinueStatement = BreakStatement | ContinueStatement; export interface ReturnStatement extends Statement { - kind: SyntaxKind.ReturnStatement; - expression?: Expression; + readonly kind: SyntaxKind.ReturnStatement; + readonly expression?: Expression; } export interface WithStatement extends Statement { - kind: SyntaxKind.WithStatement; - expression: Expression; - statement: Statement; + readonly kind: SyntaxKind.WithStatement; + readonly expression: Expression; + readonly statement: Statement; } export interface SwitchStatement extends Statement { - kind: SyntaxKind.SwitchStatement; - expression: Expression; - caseBlock: CaseBlock; + readonly kind: SyntaxKind.SwitchStatement; + readonly expression: Expression; + readonly caseBlock: CaseBlock; possiblyExhaustive?: boolean; } export interface CaseBlock extends Node { - kind: SyntaxKind.CaseBlock; parent: SwitchStatement; - clauses: NodeArray; + readonly kind: SyntaxKind.CaseBlock; + readonly clauses: NodeArray; } export interface CaseClause extends Node { - kind: SyntaxKind.CaseClause; parent: CaseBlock; - expression: Expression; - statements: NodeArray; + readonly kind: SyntaxKind.CaseClause; + readonly expression: Expression; + readonly statements: NodeArray; } export interface DefaultClause extends Node { - kind: SyntaxKind.DefaultClause; parent: CaseBlock; - statements: NodeArray; + readonly kind: SyntaxKind.DefaultClause; + readonly statements: NodeArray; } export type CaseOrDefaultClause = CaseClause | DefaultClause; export interface LabeledStatement extends Statement, JSDocContainer { - kind: SyntaxKind.LabeledStatement; - label: Identifier; - statement: Statement; + readonly kind: SyntaxKind.LabeledStatement; + readonly label: Identifier; + readonly statement: Statement; } export interface ThrowStatement extends Statement { - kind: SyntaxKind.ThrowStatement; - expression?: Expression; + readonly kind: SyntaxKind.ThrowStatement; + readonly expression?: Expression; } export interface TryStatement extends Statement { - kind: SyntaxKind.TryStatement; - tryBlock: Block; - catchClause?: CatchClause; - finallyBlock?: Block; + readonly kind: SyntaxKind.TryStatement; + readonly tryBlock: Block; + readonly catchClause?: CatchClause; + readonly finallyBlock?: Block; } export interface CatchClause extends Node { - kind: SyntaxKind.CatchClause; parent: TryStatement; - variableDeclaration?: VariableDeclaration; - block: Block; + readonly kind: SyntaxKind.CatchClause; + readonly variableDeclaration?: VariableDeclaration; + readonly block: Block; } export type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode; export type DeclarationWithTypeParameters = DeclarationWithTypeParameterChildren | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; export type DeclarationWithTypeParameterChildren = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { - kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; - name?: Identifier; - typeParameters?: NodeArray; - heritageClauses?: NodeArray; - members: NodeArray; + readonly kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; + readonly name?: Identifier; + readonly typeParameters?: NodeArray; + readonly heritageClauses?: NodeArray; + readonly members: NodeArray; } export interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatement { - kind: SyntaxKind.ClassDeclaration; + readonly kind: SyntaxKind.ClassDeclaration; /** May be undefined in `export default class { ... }`. */ - name?: Identifier; + readonly name?: Identifier; } export interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpression { - kind: SyntaxKind.ClassExpression; + readonly kind: SyntaxKind.ClassExpression; } export type ClassLikeDeclaration = ClassDeclaration | ClassExpression; export interface ClassElement extends NamedDeclaration { _classElementBrand: any; - name?: PropertyName; + readonly name?: PropertyName; } export interface TypeElement extends NamedDeclaration { _typeElementBrand: any; - name?: PropertyName; - questionToken?: QuestionToken; + readonly name?: PropertyName; + readonly questionToken?: QuestionToken; } export interface InterfaceDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.InterfaceDeclaration; - name: Identifier; - typeParameters?: NodeArray; - heritageClauses?: NodeArray; - members: NodeArray; + readonly kind: SyntaxKind.InterfaceDeclaration; + readonly name: Identifier; + readonly typeParameters?: NodeArray; + readonly heritageClauses?: NodeArray; + readonly members: NodeArray; } export interface HeritageClause extends Node { - kind: SyntaxKind.HeritageClause; parent: InterfaceDeclaration | ClassLikeDeclaration; - token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; - types: NodeArray; + readonly kind: SyntaxKind.HeritageClause; + readonly token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; + readonly types: NodeArray; } export interface TypeAliasDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.TypeAliasDeclaration; - name: Identifier; - typeParameters?: NodeArray; - type: TypeNode; + readonly kind: SyntaxKind.TypeAliasDeclaration; + readonly name: Identifier; + readonly typeParameters?: NodeArray; + readonly type: TypeNode; } export interface EnumMember extends NamedDeclaration, JSDocContainer { - kind: SyntaxKind.EnumMember; parent: EnumDeclaration; - name: PropertyName; - initializer?: Expression; + readonly kind: SyntaxKind.EnumMember; + readonly name: PropertyName; + readonly initializer?: Expression; } export interface EnumDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.EnumDeclaration; - name: Identifier; - members: NodeArray; + readonly kind: SyntaxKind.EnumDeclaration; + readonly name: Identifier; + readonly members: NodeArray; } export type ModuleName = Identifier | StringLiteral; export type ModuleBody = NamespaceBody | JSDocNamespaceBody; export interface ModuleDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ModuleDeclaration; parent: ModuleBody | SourceFile; - name: ModuleName; - body?: ModuleBody | JSDocNamespaceDeclaration; + readonly kind: SyntaxKind.ModuleDeclaration; + readonly name: ModuleName; + readonly body?: ModuleBody | JSDocNamespaceDeclaration; } export type NamespaceBody = ModuleBlock | NamespaceDeclaration; export interface NamespaceDeclaration extends ModuleDeclaration { - name: Identifier; - body: NamespaceBody; + readonly name: Identifier; + readonly body: NamespaceBody; } export type JSDocNamespaceBody = Identifier | JSDocNamespaceDeclaration; export interface JSDocNamespaceDeclaration extends ModuleDeclaration { - name: Identifier; - body?: JSDocNamespaceBody; + readonly name: Identifier; + readonly body?: JSDocNamespaceBody; } export interface ModuleBlock extends Node, Statement { - kind: SyntaxKind.ModuleBlock; parent: ModuleDeclaration; - statements: NodeArray; + readonly kind: SyntaxKind.ModuleBlock; + readonly statements: NodeArray; } export type ModuleReference = EntityName | ExternalModuleReference; /** @@ -1506,69 +1507,69 @@ declare namespace ts { * - import x = M.x; */ export interface ImportEqualsDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ImportEqualsDeclaration; parent: SourceFile | ModuleBlock; - name: Identifier; - moduleReference: ModuleReference; + readonly kind: SyntaxKind.ImportEqualsDeclaration; + readonly name: Identifier; + readonly moduleReference: ModuleReference; } export interface ExternalModuleReference extends Node { - kind: SyntaxKind.ExternalModuleReference; parent: ImportEqualsDeclaration; - expression: Expression; + readonly kind: SyntaxKind.ExternalModuleReference; + readonly expression: Expression; } export interface ImportDeclaration extends Statement, JSDocContainer { - kind: SyntaxKind.ImportDeclaration; parent: SourceFile | ModuleBlock; - importClause?: ImportClause; + readonly kind: SyntaxKind.ImportDeclaration; + readonly importClause?: ImportClause; /** If this is not a StringLiteral it will be a grammar error. */ - moduleSpecifier: Expression; + readonly moduleSpecifier: Expression; } export type NamedImportBindings = NamespaceImport | NamedImports; export interface ImportClause extends NamedDeclaration { - kind: SyntaxKind.ImportClause; parent: ImportDeclaration; - name?: Identifier; - namedBindings?: NamedImportBindings; + readonly kind: SyntaxKind.ImportClause; + readonly name?: Identifier; + readonly namedBindings?: NamedImportBindings; } export interface NamespaceImport extends NamedDeclaration { - kind: SyntaxKind.NamespaceImport; parent: ImportClause; - name: Identifier; + readonly kind: SyntaxKind.NamespaceImport; + readonly name: Identifier; } export interface NamespaceExportDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.NamespaceExportDeclaration; - name: Identifier; + readonly kind: SyntaxKind.NamespaceExportDeclaration; + readonly name: Identifier; } export interface ExportDeclaration extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ExportDeclaration; parent: SourceFile | ModuleBlock; + readonly kind: SyntaxKind.ExportDeclaration; /** Will not be assigned in the case of `export * from "foo";` */ - exportClause?: NamedExports; + readonly exportClause?: NamedExports; /** If this is not a StringLiteral it will be a grammar error. */ - moduleSpecifier?: Expression; + readonly moduleSpecifier?: Expression; } export interface NamedImports extends Node { - kind: SyntaxKind.NamedImports; parent: ImportClause; - elements: NodeArray; + readonly kind: SyntaxKind.NamedImports; + readonly elements: NodeArray; } export interface NamedExports extends Node { - kind: SyntaxKind.NamedExports; parent: ExportDeclaration; - elements: NodeArray; + readonly kind: SyntaxKind.NamedExports; + readonly elements: NodeArray; } export type NamedImportsOrExports = NamedImports | NamedExports; export interface ImportSpecifier extends NamedDeclaration { - kind: SyntaxKind.ImportSpecifier; parent: NamedImports; - propertyName?: Identifier; - name: Identifier; + readonly kind: SyntaxKind.ImportSpecifier; + readonly propertyName?: Identifier; + readonly name: Identifier; } export interface ExportSpecifier extends NamedDeclaration { - kind: SyntaxKind.ExportSpecifier; parent: NamedExports; - propertyName?: Identifier; - name: Identifier; + readonly kind: SyntaxKind.ExportSpecifier; + readonly propertyName?: Identifier; + readonly name: Identifier; } export type ImportOrExportSpecifier = ImportSpecifier | ExportSpecifier; /** @@ -1576,10 +1577,10 @@ declare namespace ts { * Unless `isExportEquals` is set, this node was parsed as an `export default`. */ export interface ExportAssignment extends DeclarationStatement, JSDocContainer { - kind: SyntaxKind.ExportAssignment; parent: SourceFile; - isExportEquals?: boolean; - expression: Expression; + readonly kind: SyntaxKind.ExportAssignment; + readonly isExportEquals?: boolean; + readonly expression: Expression; } export interface FileReference extends TextRange { fileName: string; @@ -1598,133 +1599,133 @@ declare namespace ts { end: -1; } export interface JSDocTypeExpression extends TypeNode { - kind: SyntaxKind.JSDocTypeExpression; - type: TypeNode; + readonly kind: SyntaxKind.JSDocTypeExpression; + readonly type: TypeNode; } export interface JSDocType extends TypeNode { _jsDocTypeBrand: any; } export interface JSDocAllType extends JSDocType { - kind: SyntaxKind.JSDocAllType; + readonly kind: SyntaxKind.JSDocAllType; } export interface JSDocUnknownType extends JSDocType { - kind: SyntaxKind.JSDocUnknownType; + readonly kind: SyntaxKind.JSDocUnknownType; } export interface JSDocNonNullableType extends JSDocType { - kind: SyntaxKind.JSDocNonNullableType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocNonNullableType; + readonly type: TypeNode; } export interface JSDocNullableType extends JSDocType { - kind: SyntaxKind.JSDocNullableType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocNullableType; + readonly type: TypeNode; } export interface JSDocOptionalType extends JSDocType { - kind: SyntaxKind.JSDocOptionalType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocOptionalType; + readonly type: TypeNode; } export interface JSDocFunctionType extends JSDocType, SignatureDeclarationBase { - kind: SyntaxKind.JSDocFunctionType; + readonly kind: SyntaxKind.JSDocFunctionType; } export interface JSDocVariadicType extends JSDocType { - kind: SyntaxKind.JSDocVariadicType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocVariadicType; + readonly type: TypeNode; } export interface JSDocNamepathType extends JSDocType { - kind: SyntaxKind.JSDocNamepathType; - type: TypeNode; + readonly kind: SyntaxKind.JSDocNamepathType; + readonly type: TypeNode; } export type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; export interface JSDoc extends Node { - kind: SyntaxKind.JSDocComment; parent: HasJSDoc; - tags?: NodeArray; + readonly kind: SyntaxKind.JSDocComment; + readonly tags?: NodeArray; comment?: string; } export interface JSDocTag extends Node { parent: JSDoc | JSDocTypeLiteral; - tagName: Identifier; + readonly tagName: Identifier; comment?: string; } export interface JSDocUnknownTag extends JSDocTag { - kind: SyntaxKind.JSDocTag; + readonly kind: SyntaxKind.JSDocTag; } /** * Note that `@extends` is a synonym of `@augments`. * Both tags are represented by this interface. */ export interface JSDocAugmentsTag extends JSDocTag { - kind: SyntaxKind.JSDocAugmentsTag; - class: ExpressionWithTypeArguments & { - expression: Identifier | PropertyAccessEntityNameExpression; + readonly kind: SyntaxKind.JSDocAugmentsTag; + readonly class: ExpressionWithTypeArguments & { + readonly expression: Identifier | PropertyAccessEntityNameExpression; }; } export interface JSDocAuthorTag extends JSDocTag { - kind: SyntaxKind.JSDocAuthorTag; + readonly kind: SyntaxKind.JSDocAuthorTag; } export interface JSDocClassTag extends JSDocTag { - kind: SyntaxKind.JSDocClassTag; + readonly kind: SyntaxKind.JSDocClassTag; } export interface JSDocEnumTag extends JSDocTag, Declaration { parent: JSDoc; - kind: SyntaxKind.JSDocEnumTag; - typeExpression?: JSDocTypeExpression; + readonly kind: SyntaxKind.JSDocEnumTag; + readonly typeExpression?: JSDocTypeExpression; } export interface JSDocThisTag extends JSDocTag { - kind: SyntaxKind.JSDocThisTag; - typeExpression?: JSDocTypeExpression; + readonly kind: SyntaxKind.JSDocThisTag; + readonly typeExpression?: JSDocTypeExpression; } export interface JSDocTemplateTag extends JSDocTag { - kind: SyntaxKind.JSDocTemplateTag; - constraint: JSDocTypeExpression | undefined; - typeParameters: NodeArray; + readonly kind: SyntaxKind.JSDocTemplateTag; + readonly constraint: JSDocTypeExpression | undefined; + readonly typeParameters: NodeArray; } export interface JSDocReturnTag extends JSDocTag { - kind: SyntaxKind.JSDocReturnTag; - typeExpression?: JSDocTypeExpression; + readonly kind: SyntaxKind.JSDocReturnTag; + readonly typeExpression?: JSDocTypeExpression; } export interface JSDocTypeTag extends JSDocTag { - kind: SyntaxKind.JSDocTypeTag; - typeExpression: JSDocTypeExpression; + readonly kind: SyntaxKind.JSDocTypeTag; + readonly typeExpression: JSDocTypeExpression; } export interface JSDocTypedefTag extends JSDocTag, NamedDeclaration { parent: JSDoc; - kind: SyntaxKind.JSDocTypedefTag; - fullName?: JSDocNamespaceDeclaration | Identifier; - name?: Identifier; - typeExpression?: JSDocTypeExpression | JSDocTypeLiteral; + readonly kind: SyntaxKind.JSDocTypedefTag; + readonly fullName?: JSDocNamespaceDeclaration | Identifier; + readonly name?: Identifier; + readonly typeExpression?: JSDocTypeExpression | JSDocTypeLiteral; } export interface JSDocCallbackTag extends JSDocTag, NamedDeclaration { parent: JSDoc; - kind: SyntaxKind.JSDocCallbackTag; - fullName?: JSDocNamespaceDeclaration | Identifier; - name?: Identifier; - typeExpression: JSDocSignature; + readonly kind: SyntaxKind.JSDocCallbackTag; + readonly fullName?: JSDocNamespaceDeclaration | Identifier; + readonly name?: Identifier; + readonly typeExpression: JSDocSignature; } export interface JSDocSignature extends JSDocType, Declaration { - kind: SyntaxKind.JSDocSignature; - typeParameters?: readonly JSDocTemplateTag[]; - parameters: readonly JSDocParameterTag[]; - type: JSDocReturnTag | undefined; + readonly kind: SyntaxKind.JSDocSignature; + readonly typeParameters?: readonly JSDocTemplateTag[]; + readonly parameters: readonly JSDocParameterTag[]; + readonly type: JSDocReturnTag | undefined; } export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { parent: JSDoc; - name: EntityName; - typeExpression?: JSDocTypeExpression; + readonly name: EntityName; + readonly typeExpression?: JSDocTypeExpression; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ - isNameFirst: boolean; - isBracketed: boolean; + readonly isNameFirst: boolean; + readonly isBracketed: boolean; } export interface JSDocPropertyTag extends JSDocPropertyLikeTag { - kind: SyntaxKind.JSDocPropertyTag; + readonly kind: SyntaxKind.JSDocPropertyTag; } export interface JSDocParameterTag extends JSDocPropertyLikeTag { - kind: SyntaxKind.JSDocParameterTag; + readonly kind: SyntaxKind.JSDocParameterTag; } export interface JSDocTypeLiteral extends JSDocType { - kind: SyntaxKind.JSDocTypeLiteral; - jsDocPropertyTags?: readonly JSDocPropertyLikeTag[]; + readonly kind: SyntaxKind.JSDocTypeLiteral; + readonly jsDocPropertyTags?: readonly JSDocPropertyLikeTag[]; /** If true, then this type literal represents an *array* of its type. */ - isArrayType?: boolean; + readonly isArrayType?: boolean; } export enum FlowFlags { Unreachable = 1, @@ -1797,9 +1798,9 @@ declare namespace ts { name?: string; } export interface SourceFile extends Declaration { - kind: SyntaxKind.SourceFile; - statements: NodeArray; - endOfFileToken: Token; + readonly kind: SyntaxKind.SourceFile; + readonly statements: NodeArray; + readonly endOfFileToken: Token; fileName: string; text: string; amdDependencies: readonly AmdDependency[]; @@ -1821,12 +1822,12 @@ declare namespace ts { languageVersion: ScriptTarget; } export interface Bundle extends Node { - kind: SyntaxKind.Bundle; - prepends: readonly (InputFiles | UnparsedSource)[]; - sourceFiles: readonly SourceFile[]; + readonly kind: SyntaxKind.Bundle; + readonly prepends: readonly (InputFiles | UnparsedSource)[]; + readonly sourceFiles: readonly SourceFile[]; } export interface InputFiles extends Node { - kind: SyntaxKind.InputFiles; + readonly kind: SyntaxKind.InputFiles; javascriptPath?: string; javascriptText: string; javascriptMapPath?: string; @@ -1837,10 +1838,10 @@ declare namespace ts { declarationMapText?: string; } export interface UnparsedSource extends Node { - kind: SyntaxKind.UnparsedSource; + readonly kind: SyntaxKind.UnparsedSource; fileName: string; text: string; - prologues: readonly UnparsedPrologue[]; + readonly prologues: readonly UnparsedPrologue[]; helpers: readonly UnscopedEmitHelper[] | undefined; referencedFiles: readonly FileReference[]; typeReferenceDirectives: readonly string[] | undefined; @@ -1848,48 +1849,49 @@ declare namespace ts { hasNoDefaultLib?: boolean; sourceMapPath?: string; sourceMapText?: string; - syntheticReferences?: readonly UnparsedSyntheticReference[]; - texts: readonly UnparsedSourceText[]; + readonly syntheticReferences?: readonly UnparsedSyntheticReference[]; + readonly texts: readonly UnparsedSourceText[]; } export type UnparsedSourceText = UnparsedPrepend | UnparsedTextLike; export type UnparsedNode = UnparsedPrologue | UnparsedSourceText | UnparsedSyntheticReference; export interface UnparsedSection extends Node { - kind: SyntaxKind; - data?: string; parent: UnparsedSource; + readonly kind: SyntaxKind; + readonly data?: string; } export interface UnparsedPrologue extends UnparsedSection { - kind: SyntaxKind.UnparsedPrologue; - data: string; parent: UnparsedSource; + readonly kind: SyntaxKind.UnparsedPrologue; + readonly data: string; } export interface UnparsedPrepend extends UnparsedSection { - kind: SyntaxKind.UnparsedPrepend; - data: string; parent: UnparsedSource; - texts: readonly UnparsedTextLike[]; + readonly kind: SyntaxKind.UnparsedPrepend; + readonly data: string; + readonly texts: readonly UnparsedTextLike[]; } export interface UnparsedTextLike extends UnparsedSection { - kind: SyntaxKind.UnparsedText | SyntaxKind.UnparsedInternalText; parent: UnparsedSource; + readonly kind: SyntaxKind.UnparsedText | SyntaxKind.UnparsedInternalText; } export interface UnparsedSyntheticReference extends UnparsedSection { - kind: SyntaxKind.UnparsedSyntheticReference; parent: UnparsedSource; + readonly kind: SyntaxKind.UnparsedSyntheticReference; } export interface JsonSourceFile extends SourceFile { - statements: NodeArray; + readonly statements: NodeArray; } export interface TsConfigSourceFile extends JsonSourceFile { extendedSourceFiles?: string[]; } export interface JsonMinusNumericLiteral extends PrefixUnaryExpression { - kind: SyntaxKind.PrefixUnaryExpression; - operator: SyntaxKind.MinusToken; - operand: NumericLiteral; + readonly kind: SyntaxKind.PrefixUnaryExpression; + readonly operator: SyntaxKind.MinusToken; + readonly operand: NumericLiteral; } + export type JsonObjectExpression = ObjectLiteralExpression | ArrayLiteralExpression | JsonMinusNumericLiteral | NumericLiteral | StringLiteral | BooleanLiteral | NullLiteral; export interface JsonObjectExpressionStatement extends ExpressionStatement { - expression: ObjectLiteralExpression | ArrayLiteralExpression | JsonMinusNumericLiteral | NumericLiteral | StringLiteral | BooleanLiteral | NullLiteral; + readonly expression: JsonObjectExpression; } export interface ScriptReferenceHost { getCompilerOptions(): CompilerOptions; @@ -3062,7 +3064,7 @@ declare namespace ts { createInferTypeNode(typeParameter: TypeParameterDeclaration): InferTypeNode; updateInferTypeNode(node: InferTypeNode, typeParameter: TypeParameterDeclaration): InferTypeNode; createImportTypeNode(argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; - updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode; + updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode; createParenthesizedType(type: TypeNode): ParenthesizedTypeNode; updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode; createThisTypeNode(): ThisTypeNode; @@ -3271,7 +3273,7 @@ declare namespace ts { updateSpreadAssignment(node: SpreadAssignment, expression: Expression): SpreadAssignment; createEnumMember(name: string | PropertyName, initializer?: Expression): EnumMember; updateEnumMember(node: EnumMember, name: PropertyName, initializer: Expression | undefined): EnumMember; - createSourceFile(statements: readonly Statement[], endOfFileToken: EndOfFileToken): SourceFile; + createSourceFile(statements: readonly Statement[], endOfFileToken: EndOfFileToken, flags: NodeFlags): SourceFile; updateSourceFile(node: SourceFile, statements: readonly Statement[], isDeclarationFile?: boolean, referencedFiles?: readonly FileReference[], typeReferences?: readonly FileReference[], hasNoDefaultLib?: boolean, libReferences?: readonly FileReference[]): SourceFile; createNotEmittedStatement(original: Node): NotEmittedStatement; createPartiallyEmittedExpression(expression: Expression, original?: Node): PartiallyEmittedExpression; @@ -3413,6 +3415,14 @@ declare namespace ts { * A function that accepts and possibly transforms a node. */ export type Visitor = (node: Node) => VisitResult; + export interface NodeVisitor { + (nodes: T, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T; + (nodes: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T | undefined; + } + export interface NodesVisitor { + (nodes: NodeArray, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; + (nodes: NodeArray | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; + } export type VisitResult = T | T[] | undefined; export interface Printer { /** @@ -4366,7 +4376,7 @@ declare namespace ts { * @param test A callback to execute to verify the Node is valid. * @param lift An optional callback to execute to lift a NodeArray into a valid Node. */ - function visitNode(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T; + function visitNode(node: T, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray) => T): T; /** * Visits a Node using the supplied visitor, possibly returning a new Node in its place. * @@ -4385,7 +4395,7 @@ declare namespace ts { * @param start An optional value indicating the starting offset at which to start visiting. * @param count An optional value indicating the maximum number of nodes to visit. */ - function visitNodes(nodes: NodeArray | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; + function visitNodes(nodes: NodeArray, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; /** * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. * @@ -4395,17 +4405,22 @@ declare namespace ts { * @param start An optional value indicating the starting offset at which to start visiting. * @param count An optional value indicating the maximum number of nodes to visit. */ - function visitNodes(nodes: NodeArray | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; + function visitNodes(nodes: NodeArray | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; /** * Starts a new lexical environment and visits a statement list, ending the lexical environment * and merging hoisted declarations upon completion. */ - function visitLexicalEnvironment(statements: NodeArray, visitor: Visitor, context: TransformationContext, start?: number, ensureUseStrict?: boolean): NodeArray; + function visitLexicalEnvironment(statements: NodeArray, visitor: Visitor, context: TransformationContext, start?: number, ensureUseStrict?: boolean, nodesVisitor?: NodesVisitor): NodeArray; + /** + * Starts a new lexical environment and visits a parameter list, suspending the lexical + * environment upon completion. + */ + function visitParameterList(nodes: NodeArray, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray; /** * Starts a new lexical environment and visits a parameter list, suspending the lexical * environment upon completion. */ - function visitParameterList(nodes: NodeArray | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes): NodeArray; + function visitParameterList(nodes: NodeArray | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray | undefined; /** * Resumes a suspended lexical environment and visits a function body, ending the lexical * environment and merging hoisted declarations upon completion. @@ -4436,7 +4451,7 @@ declare namespace ts { * @param visitor The callback used to visit each child. * @param context A lexical environment context for the visitor. */ - function visitEachChild(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined; + function visitEachChild(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor, tokenVisitor?: Visitor): T | undefined; } declare namespace ts { function getTsBuildInfoEmitOutputFilePath(options: CompilerOptions): string | undefined; @@ -6208,7 +6223,7 @@ declare namespace ts { /** * @deprecated Use `factory.updateImportTypeNode` or the factory supplied by your transformation context instead. */ - updateImportTypeNode: (node: ImportTypeNode, argument: TypeNode, qualifier?: Identifier | QualifiedName | undefined, typeArguments?: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined) => ImportTypeNode, + updateImportTypeNode: (node: ImportTypeNode, argument: TypeNode, qualifier: Identifier | QualifiedName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean | undefined) => ImportTypeNode, /** * @deprecated Use `factory.createParenthesizedType` or the factory supplied by your transformation context instead. */ @@ -7252,7 +7267,11 @@ declare namespace ts { */ function createLogicalNot(operand: Expression): PrefixUnaryExpression; /** - * Creates a shallow, memberwise clone of a node for mutation. + * Creates a shallow, memberwise clone of a node ~for mutation~ with its `pos`, `end`, and `parent` set. + * + * NOTE: It is unsafe to change any properties of a `Node` that relate to its AST children, as those changes won't be + * captured with respect to transformations. + * * @deprecated Use `factory.cloneNode` instead and set `pos`, `end`, and `parent` as needed. */ function getMutableClone(node: T): T;