mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Make most Node properties read-only
This commit is contained in:
@@ -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<T extends Node>(node: T): T {
|
||||
|
||||
@@ -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<Node>, 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<ModuleDeclaration | SourceFile>) {
|
||||
// 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)) {
|
||||
|
||||
+185
-101
@@ -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 = <MethodSignature>signatureToSignatureDeclarationHelper(signature, SyntaxKind.MethodSignature, context);
|
||||
methodDeclaration.name = propertyName;
|
||||
methodDeclaration.questionToken = optionalToken;
|
||||
const methodDeclaration = <MethodSignature>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) {
|
||||
(<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<HasModifiers, Statement>);
|
||||
}
|
||||
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<HasModifiers, Statement> {
|
||||
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<HasModifiers, Statement>) {
|
||||
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;
|
||||
|
||||
+10
-2
@@ -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<T>(array: readonly T[], equalityComparer: EqualityComparer<T>, comparer: Comparer<T>) {
|
||||
// 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<T>(array: readonly T[], comparer: Comparer<T>): SortedReadonlyArray<T> {
|
||||
const indices = array.map((_, i) => i);
|
||||
const indices = indicesOf(array);
|
||||
stableSortIndices(array, indices, comparer);
|
||||
return indices.map(i => array[i]) as SortedArray<T> as SortedReadonlyArray<T>;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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<T extends Node>(kind: T["kind"]): T {
|
||||
return createNode(kind) as T;
|
||||
function createBaseNode<T extends Node>(kind: T["kind"]) {
|
||||
return createNode(kind) as Mutable<T>;
|
||||
}
|
||||
|
||||
function createBaseDeclaration<T extends Declaration | VariableStatement | ImportDeclaration>(
|
||||
@@ -619,7 +612,8 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
function updateBaseSignatureDeclaration<T extends SignatureDeclarationBase>(updated: T, original: T) {
|
||||
function updateBaseSignatureDeclaration<T extends SignatureDeclarationBase>(updated: Mutable<T>, 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<T extends FunctionLikeDeclaration>(updated: T, original: T) {
|
||||
function updateBaseFunctionLikeDeclaration<T extends FunctionLikeDeclaration>(updated: Mutable<T>, 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<Identifier>;
|
||||
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<GeneratedIdentifier>;
|
||||
node.autoGenerateFlags = autoGenerateFlags;
|
||||
node.autoGenerateId = nextAutoGenerateId;
|
||||
nextAutoGenerateId++;
|
||||
@@ -902,6 +897,10 @@ namespace ts {
|
||||
// Punctuation
|
||||
//
|
||||
|
||||
function createBaseToken<T extends Node>(kind: T["kind"]) {
|
||||
return createTokenNode(kind) as Mutable<T>;
|
||||
}
|
||||
|
||||
// @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<TKind>;
|
||||
const node = createBaseToken<Token<TKind>>(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<ImportTypeNode>(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<TemplateLiteralLikeNode>(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<PropertyAssignment>, 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<ShorthandPropertyAssignment>, 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<SourceFile>;
|
||||
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<T extends UnparsedNode>(kind: T["kind"], data?: string): T {
|
||||
const node = createBaseNode<T>(kind);
|
||||
function createBaseUnparsedNode<T extends UnparsedNode>(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<T>).flags |= (node.flags & ~NodeFlags.Synthesized);
|
||||
(clone as Mutable<T>).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<Node>).transformFlags |= propagateChildFlags(child);
|
||||
}
|
||||
}
|
||||
|
||||
function setChildrenWorker(parent: Node, children: NodeArray<Node> | undefined): void {
|
||||
if (!skipTransformationFlags && children) {
|
||||
parent.transformFlags |= propagateChildrenFlags(children);
|
||||
(parent as Mutable<Node>).transformFlags |= propagateChildrenFlags(children);
|
||||
}
|
||||
}
|
||||
|
||||
function finishWorker<T extends Node>(node: T) {
|
||||
if (!skipTransformationFlags) {
|
||||
node.transformFlags |= TransformFlags.HasComputedFlags;
|
||||
(node as Mutable<T>).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 <Statement>singleOrUndefined(nodes) || factory.createBlock(<readonly Statement[]>nodes);
|
||||
}
|
||||
|
||||
function updateModifiers<T extends HasModifiers>(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>) => { node.transformFlags = transformFlags; } :
|
||||
(node: Mutable<Node>) => { node.transformFlags |= transformFlags; };
|
||||
}
|
||||
|
||||
function observeArguments<T>(action: <U extends T>(arg1: U, arg2: U) => U, observer: ((arg1: T, arg2: T) => void) | undefined): <U extends T>(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<Node>).flags |= NodeFlags.Synthesized
|
||||
});
|
||||
|
||||
export function createUnparsedSourceFile(text: string): UnparsedSource;
|
||||
@@ -5976,4 +6015,3 @@ namespace ts {
|
||||
return destRanges;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Identifier>;
|
||||
right.escapedText = jsxFactory.right.escapedText;
|
||||
return factory.createPropertyAccess(left, right);
|
||||
}
|
||||
@@ -780,4 +780,31 @@ namespace ts {
|
||||
return <readonly BindingOrAssignmentElement[]>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;
|
||||
}
|
||||
}
|
||||
+19
-19
@@ -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<SourceFile>).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<EndOfFileToken>());
|
||||
|
||||
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<T> 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<T>).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<T>).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<Node>).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<Node>).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<ShorthandPropertyAssignment | PropertyAssignment>;
|
||||
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<Node>).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<Statement>(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected);
|
||||
const missing = createMissingNode<MissingDeclaration>(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<Node>).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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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!;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<LiteralExpression>[][] | 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(<Identifier>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
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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[];
|
||||
}
|
||||
|
||||
+818
-633
File diff suppressed because it is too large
Load Diff
@@ -298,13 +298,13 @@ namespace ts {
|
||||
|
||||
// If so, mark ourselves accordingly.
|
||||
if (thisNodeOrAnySubNodesHasError) {
|
||||
node.flags |= NodeFlags.ThisNodeOrAnySubNodesHasError;
|
||||
(node as Mutable<Node>).flags |= NodeFlags.ThisNodeOrAnySubNodesHasError;
|
||||
}
|
||||
|
||||
// Also mark that we've propagated the child information to this node. This way we can
|
||||
// always consult the bit directly on this node without needing to check its children
|
||||
// again.
|
||||
node.flags |= NodeFlags.HasAggregatedChildData;
|
||||
(node as Mutable<Node>).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<Node>, kind: SyntaxKind, pos: number, end: number) {
|
||||
this.pos = pos;
|
||||
this.end = end;
|
||||
this.kind = kind;
|
||||
|
||||
+235
-227
@@ -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<T extends Node>(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray<Node>) => T): T;
|
||||
|
||||
export function visitNode<T extends Node>(node: T, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray<Node>) => 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<T extends Node>(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray<Node>) => T): T | undefined;
|
||||
|
||||
export function visitNode<T extends Node>(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: NodeArray<Node>) => 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<T extends Node>(nodes: NodeArray<T> | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T>;
|
||||
|
||||
export function visitNodes<T extends Node>(nodes: NodeArray<T>, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T>;
|
||||
/**
|
||||
* 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<T extends Node>(nodes: NodeArray<T> | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T> | undefined;
|
||||
|
||||
export function visitNodes<T extends Node>(nodes: NodeArray<T> | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T> | 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<T extends Node>(nodes: NodeArray<T> | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T> | undefined {
|
||||
export function visitNodes<T extends Node>(nodes: NodeArray<T> | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T> | 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<Statement>, visitor: Visitor, context: TransformationContext, start?: number, ensureUseStrict?: boolean) {
|
||||
export function visitLexicalEnvironment(statements: NodeArray<Statement>, 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<ParameterDeclaration>, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray<ParameterDeclaration>;
|
||||
/**
|
||||
* Starts a new lexical environment and visits a parameter list, suspending the lexical
|
||||
* environment upon completion.
|
||||
*/
|
||||
export function visitParameterList(nodes: NodeArray<ParameterDeclaration> | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray<ParameterDeclaration> | undefined;
|
||||
export function visitParameterList(nodes: NodeArray<ParameterDeclaration> | 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<T extends Node>(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<T extends Node>(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<T extends Node>(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor, tokenVisitor?: Visitor): T | undefined;
|
||||
/* @internal */
|
||||
export function visitEachChild<T extends Node>(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(<Identifier>node, nodesVisitor((<Identifier>node).typeArguments, visitor, isTypeNodeOrTypeParameterDeclaration));
|
||||
return factory.updateIdentifier(<Identifier>node,
|
||||
nodesVisitor((<Identifier>node).typeArguments, visitor, isTypeNodeOrTypeParameterDeclaration));
|
||||
|
||||
case SyntaxKind.QualifiedName:
|
||||
return factory.updateQualifiedName(<QualifiedName>node,
|
||||
visitNode((<QualifiedName>node).left, visitor, isEntityName),
|
||||
visitNode((<QualifiedName>node).right, visitor, isIdentifier));
|
||||
nodeVisitor((<QualifiedName>node).left, visitor, isEntityName),
|
||||
nodeVisitor((<QualifiedName>node).right, visitor, isIdentifier));
|
||||
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
return factory.updateComputedPropertyName(<ComputedPropertyName>node,
|
||||
visitNode((<ComputedPropertyName>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<ComputedPropertyName>node).expression, visitor, isExpression));
|
||||
|
||||
// Signature elements
|
||||
case SyntaxKind.TypeParameter:
|
||||
return factory.updateTypeParameterDeclaration(<TypeParameterDeclaration>node,
|
||||
visitNode((<TypeParameterDeclaration>node).name, visitor, isIdentifier),
|
||||
visitNode((<TypeParameterDeclaration>node).constraint, visitor, isTypeNode),
|
||||
visitNode((<TypeParameterDeclaration>node).default, visitor, isTypeNode));
|
||||
nodeVisitor((<TypeParameterDeclaration>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<TypeParameterDeclaration>node).constraint, visitor, isTypeNode),
|
||||
nodeVisitor((<TypeParameterDeclaration>node).default, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.Parameter:
|
||||
return factory.updateParameterDeclaration(<ParameterDeclaration>node,
|
||||
nodesVisitor((<ParameterDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<ParameterDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<ParameterDeclaration>node).dotDotDotToken, tokenVisitor, isToken),
|
||||
visitNode((<ParameterDeclaration>node).name, visitor, isBindingName),
|
||||
visitNode((<ParameterDeclaration>node).questionToken, tokenVisitor, isToken),
|
||||
visitNode((<ParameterDeclaration>node).type, visitor, isTypeNode),
|
||||
visitNode((<ParameterDeclaration>node).initializer, visitor, isExpression));
|
||||
nodeVisitor((<ParameterDeclaration>node).dotDotDotToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<ParameterDeclaration>node).name, visitor, isBindingName),
|
||||
nodeVisitor((<ParameterDeclaration>node).questionToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<ParameterDeclaration>node).type, visitor, isTypeNode),
|
||||
nodeVisitor((<ParameterDeclaration>node).initializer, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.Decorator:
|
||||
return factory.updateDecorator(<Decorator>node,
|
||||
visitNode((<Decorator>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<Decorator>node).expression, visitor, isExpression));
|
||||
|
||||
// Type elements
|
||||
case SyntaxKind.PropertySignature:
|
||||
return factory.updatePropertySignature((<PropertySignature>node),
|
||||
nodesVisitor((<PropertySignature>node).modifiers, visitor, isToken),
|
||||
visitNode((<PropertySignature>node).name, visitor, isPropertyName),
|
||||
visitNode((<PropertySignature>node).questionToken, tokenVisitor, isToken),
|
||||
visitNode((<PropertySignature>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<PropertySignature>node).name, visitor, isPropertyName),
|
||||
nodeVisitor((<PropertySignature>node).questionToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<PropertySignature>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
return factory.updatePropertyDeclaration(<PropertyDeclaration>node,
|
||||
nodesVisitor((<PropertyDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<PropertyDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<PropertyDeclaration>node).name, visitor, isPropertyName),
|
||||
nodeVisitor((<PropertyDeclaration>node).name, visitor, isPropertyName),
|
||||
// QuestionToken and ExclamationToken is uniqued in Property Declaration and the signature of 'updateProperty' is that too
|
||||
visitNode((<PropertyDeclaration>node).questionToken || (<PropertyDeclaration>node).exclamationToken, tokenVisitor, isToken),
|
||||
visitNode((<PropertyDeclaration>node).type, visitor, isTypeNode),
|
||||
visitNode((<PropertyDeclaration>node).initializer, visitor, isExpression));
|
||||
nodeVisitor((<PropertyDeclaration>node).questionToken || (<PropertyDeclaration>node).exclamationToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<PropertyDeclaration>node).type, visitor, isTypeNode),
|
||||
nodeVisitor((<PropertyDeclaration>node).initializer, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.MethodSignature:
|
||||
return factory.updateMethodSignature(<MethodSignature>node,
|
||||
nodesVisitor((<ParameterDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<MethodSignature>node).name, visitor, isPropertyName),
|
||||
visitNode((<MethodSignature>node).questionToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<MethodSignature>node).name, visitor, isPropertyName),
|
||||
nodeVisitor((<MethodSignature>node).questionToken, tokenVisitor, isToken),
|
||||
nodesVisitor((<MethodSignature>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
nodesVisitor((<MethodSignature>node).parameters, visitor, isParameterDeclaration),
|
||||
visitNode((<MethodSignature>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<MethodSignature>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
return factory.updateMethodDeclaration(<MethodDeclaration>node,
|
||||
nodesVisitor((<MethodDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<MethodDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<MethodDeclaration>node).asteriskToken, tokenVisitor, isToken),
|
||||
visitNode((<MethodDeclaration>node).name, visitor, isPropertyName),
|
||||
visitNode((<MethodDeclaration>node).questionToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<MethodDeclaration>node).asteriskToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<MethodDeclaration>node).name, visitor, isPropertyName),
|
||||
nodeVisitor((<MethodDeclaration>node).questionToken, tokenVisitor, isToken),
|
||||
nodesVisitor((<MethodDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
visitParameterList((<MethodDeclaration>node).parameters, visitor, context, nodesVisitor),
|
||||
visitNode((<MethodDeclaration>node).type, visitor, isTypeNode),
|
||||
visitFunctionBody((<MethodDeclaration>node).body!, visitor, context));
|
||||
nodeVisitor((<MethodDeclaration>node).type, visitor, isTypeNode),
|
||||
visitFunctionBody((<MethodDeclaration>node).body!, visitor, context, nodeVisitor));
|
||||
|
||||
case SyntaxKind.Constructor:
|
||||
return factory.updateConstructorDeclaration(<ConstructorDeclaration>node,
|
||||
nodesVisitor((<ConstructorDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<ConstructorDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitParameterList((<ConstructorDeclaration>node).parameters, visitor, context, nodesVisitor),
|
||||
visitFunctionBody((<ConstructorDeclaration>node).body!, visitor, context));
|
||||
visitFunctionBody((<ConstructorDeclaration>node).body, visitor, context, nodeVisitor));
|
||||
|
||||
case SyntaxKind.GetAccessor:
|
||||
return factory.updateGetAccessorDeclaration(<GetAccessorDeclaration>node,
|
||||
nodesVisitor((<GetAccessorDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<GetAccessorDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<GetAccessorDeclaration>node).name, visitor, isPropertyName),
|
||||
nodeVisitor((<GetAccessorDeclaration>node).name, visitor, isPropertyName),
|
||||
visitParameterList((<GetAccessorDeclaration>node).parameters, visitor, context, nodesVisitor),
|
||||
visitNode((<GetAccessorDeclaration>node).type, visitor, isTypeNode),
|
||||
visitFunctionBody((<GetAccessorDeclaration>node).body!, visitor, context));
|
||||
nodeVisitor((<GetAccessorDeclaration>node).type, visitor, isTypeNode),
|
||||
visitFunctionBody((<GetAccessorDeclaration>node).body, visitor, context, nodeVisitor));
|
||||
|
||||
case SyntaxKind.SetAccessor:
|
||||
return factory.updateSetAccessorDeclaration(<SetAccessorDeclaration>node,
|
||||
nodesVisitor((<SetAccessorDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<SetAccessorDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<SetAccessorDeclaration>node).name, visitor, isPropertyName),
|
||||
nodeVisitor((<SetAccessorDeclaration>node).name, visitor, isPropertyName),
|
||||
visitParameterList((<SetAccessorDeclaration>node).parameters, visitor, context, nodesVisitor),
|
||||
visitFunctionBody((<SetAccessorDeclaration>node).body!, visitor, context));
|
||||
visitFunctionBody((<SetAccessorDeclaration>node).body, visitor, context, nodeVisitor));
|
||||
|
||||
case SyntaxKind.CallSignature:
|
||||
return factory.updateCallSignature(<CallSignatureDeclaration>node,
|
||||
nodesVisitor((<CallSignatureDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
nodesVisitor((<CallSignatureDeclaration>node).parameters, visitor, isParameterDeclaration),
|
||||
visitNode((<CallSignatureDeclaration>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<CallSignatureDeclaration>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.ConstructSignature:
|
||||
return factory.updateConstructSignature(<ConstructSignatureDeclaration>node,
|
||||
nodesVisitor((<ConstructSignatureDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
nodesVisitor((<ConstructSignatureDeclaration>node).parameters, visitor, isParameterDeclaration),
|
||||
visitNode((<ConstructSignatureDeclaration>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<ConstructSignatureDeclaration>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.IndexSignature:
|
||||
return factory.updateIndexSignature(<IndexSignatureDeclaration>node,
|
||||
nodesVisitor((<IndexSignatureDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<IndexSignatureDeclaration>node).modifiers, visitor, isModifier),
|
||||
nodesVisitor((<IndexSignatureDeclaration>node).parameters, visitor, isParameterDeclaration),
|
||||
visitNode((<IndexSignatureDeclaration>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<IndexSignatureDeclaration>node).type, visitor, isTypeNode));
|
||||
|
||||
// Types
|
||||
case SyntaxKind.TypePredicate:
|
||||
return factory.updateTypePredicateNode(<TypePredicateNode>node,
|
||||
visitNode((<TypePredicateNode>node).assertsModifier, visitor),
|
||||
visitNode((<TypePredicateNode>node).parameterName, visitor),
|
||||
visitNode((<TypePredicateNode>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<TypePredicateNode>node).assertsModifier, visitor),
|
||||
nodeVisitor((<TypePredicateNode>node).parameterName, visitor),
|
||||
nodeVisitor((<TypePredicateNode>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.TypeReference:
|
||||
return factory.updateTypeReferenceNode(<TypeReferenceNode>node,
|
||||
visitNode((<TypeReferenceNode>node).typeName, visitor, isEntityName),
|
||||
nodeVisitor((<TypeReferenceNode>node).typeName, visitor, isEntityName),
|
||||
nodesVisitor((<TypeReferenceNode>node).typeArguments, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.FunctionType:
|
||||
return factory.updateFunctionTypeNode(<FunctionTypeNode>node,
|
||||
nodesVisitor((<FunctionTypeNode>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
nodesVisitor((<FunctionTypeNode>node).parameters, visitor, isParameterDeclaration),
|
||||
visitNode((<FunctionTypeNode>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<FunctionTypeNode>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.ConstructorType:
|
||||
return factory.updateConstructorTypeNode(<ConstructorTypeNode>node,
|
||||
nodesVisitor((<ConstructorTypeNode>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
nodesVisitor((<ConstructorTypeNode>node).parameters, visitor, isParameterDeclaration),
|
||||
visitNode((<ConstructorTypeNode>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<ConstructorTypeNode>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.TypeQuery:
|
||||
return factory.updateTypeQueryNode((<TypeQueryNode>node),
|
||||
visitNode((<TypeQueryNode>node).exprName, visitor, isEntityName));
|
||||
nodeVisitor((<TypeQueryNode>node).exprName, visitor, isEntityName));
|
||||
|
||||
case SyntaxKind.TypeLiteral:
|
||||
return factory.updateTypeLiteralNode((<TypeLiteralNode>node),
|
||||
@@ -375,7 +384,7 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.ArrayType:
|
||||
return factory.updateArrayTypeNode(<ArrayTypeNode>node,
|
||||
visitNode((<ArrayTypeNode>node).elementType, visitor, isTypeNode));
|
||||
nodeVisitor((<ArrayTypeNode>node).elementType, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.TupleType:
|
||||
return factory.updateTupleTypeNode((<TupleTypeNode>node),
|
||||
@@ -383,11 +392,11 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.OptionalType:
|
||||
return factory.updateOptionalTypeNode((<OptionalTypeNode>node),
|
||||
visitNode((<OptionalTypeNode>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<OptionalTypeNode>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.RestType:
|
||||
return factory.updateRestTypeNode((<RestTypeNode>node),
|
||||
visitNode((<RestTypeNode>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<RestTypeNode>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.UnionType:
|
||||
return factory.updateUnionTypeNode(<UnionTypeNode>node,
|
||||
@@ -399,46 +408,45 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.ConditionalType:
|
||||
return factory.updateConditionalTypeNode(<ConditionalTypeNode>node,
|
||||
visitNode((<ConditionalTypeNode>node).checkType, visitor, isTypeNode),
|
||||
visitNode((<ConditionalTypeNode>node).extendsType, visitor, isTypeNode),
|
||||
visitNode((<ConditionalTypeNode>node).trueType, visitor, isTypeNode),
|
||||
visitNode((<ConditionalTypeNode>node).falseType, visitor, isTypeNode));
|
||||
nodeVisitor((<ConditionalTypeNode>node).checkType, visitor, isTypeNode),
|
||||
nodeVisitor((<ConditionalTypeNode>node).extendsType, visitor, isTypeNode),
|
||||
nodeVisitor((<ConditionalTypeNode>node).trueType, visitor, isTypeNode),
|
||||
nodeVisitor((<ConditionalTypeNode>node).falseType, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.InferType:
|
||||
return factory.updateInferTypeNode(<InferTypeNode>node,
|
||||
visitNode((<InferTypeNode>node).typeParameter, visitor, isTypeParameterDeclaration));
|
||||
nodeVisitor((<InferTypeNode>node).typeParameter, visitor, isTypeParameterDeclaration));
|
||||
|
||||
case SyntaxKind.ImportType:
|
||||
return factory.updateImportTypeNode(<ImportTypeNode>node,
|
||||
visitNode((<ImportTypeNode>node).argument, visitor, isTypeNode),
|
||||
visitNode((<ImportTypeNode>node).qualifier, visitor, isEntityName),
|
||||
visitNodes((<ImportTypeNode>node).typeArguments, visitor, isTypeNode),
|
||||
(<ImportTypeNode>node).isTypeOf
|
||||
);
|
||||
nodeVisitor((<ImportTypeNode>node).argument, visitor, isTypeNode),
|
||||
nodeVisitor((<ImportTypeNode>node).qualifier, visitor, isEntityName),
|
||||
nodesVisitor((<ImportTypeNode>node).typeArguments, visitor, isTypeNode),
|
||||
(<ImportTypeNode>node).isTypeOf);
|
||||
|
||||
case SyntaxKind.ParenthesizedType:
|
||||
return factory.updateParenthesizedType(<ParenthesizedTypeNode>node,
|
||||
visitNode((<ParenthesizedTypeNode>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<ParenthesizedTypeNode>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.TypeOperator:
|
||||
return factory.updateTypeOperatorNode(<TypeOperatorNode>node,
|
||||
visitNode((<TypeOperatorNode>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<TypeOperatorNode>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.IndexedAccessType:
|
||||
return factory.updateIndexedAccessTypeNode((<IndexedAccessTypeNode>node),
|
||||
visitNode((<IndexedAccessTypeNode>node).objectType, visitor, isTypeNode),
|
||||
visitNode((<IndexedAccessTypeNode>node).indexType, visitor, isTypeNode));
|
||||
nodeVisitor((<IndexedAccessTypeNode>node).objectType, visitor, isTypeNode),
|
||||
nodeVisitor((<IndexedAccessTypeNode>node).indexType, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.MappedType:
|
||||
return factory.updateMappedTypeNode((<MappedTypeNode>node),
|
||||
visitNode((<MappedTypeNode>node).readonlyToken, tokenVisitor, isToken),
|
||||
visitNode((<MappedTypeNode>node).typeParameter, visitor, isTypeParameterDeclaration),
|
||||
visitNode((<MappedTypeNode>node).questionToken, tokenVisitor, isToken),
|
||||
visitNode((<MappedTypeNode>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<MappedTypeNode>node).readonlyToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<MappedTypeNode>node).typeParameter, visitor, isTypeParameterDeclaration),
|
||||
nodeVisitor((<MappedTypeNode>node).questionToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<MappedTypeNode>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.LiteralType:
|
||||
return factory.updateLiteralTypeNode(<LiteralTypeNode>node,
|
||||
visitNode((<LiteralTypeNode>node).literal, visitor, isExpression));
|
||||
nodeVisitor((<LiteralTypeNode>node).literal, visitor, isExpression));
|
||||
|
||||
// Binding patterns
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
@@ -451,10 +459,10 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.BindingElement:
|
||||
return factory.updateBindingElement(<BindingElement>node,
|
||||
visitNode((<BindingElement>node).dotDotDotToken, tokenVisitor, isToken),
|
||||
visitNode((<BindingElement>node).propertyName, visitor, isPropertyName),
|
||||
visitNode((<BindingElement>node).name, visitor, isBindingName),
|
||||
visitNode((<BindingElement>node).initializer, visitor, isExpression));
|
||||
nodeVisitor((<BindingElement>node).dotDotDotToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<BindingElement>node).propertyName, visitor, isPropertyName),
|
||||
nodeVisitor((<BindingElement>node).name, visitor, isBindingName),
|
||||
nodeVisitor((<BindingElement>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(<PropertyAccessChain>node,
|
||||
visitNode((<PropertyAccessChain>node).expression, visitor, isExpression),
|
||||
visitNode((<PropertyAccessChain>node).questionDotToken, visitor, isToken),
|
||||
visitNode((<PropertyAccessChain>node).name, visitor, isIdentifier));
|
||||
nodeVisitor((<PropertyAccessChain>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<PropertyAccessChain>node).questionDotToken, visitor, isToken),
|
||||
nodeVisitor((<PropertyAccessChain>node).name, visitor, isIdentifier));
|
||||
}
|
||||
return factory.updatePropertyAccess(<PropertyAccessExpression>node,
|
||||
visitNode((<PropertyAccessExpression>node).expression, visitor, isExpression),
|
||||
visitNode((<PropertyAccessExpression>node).name, visitor, isIdentifier));
|
||||
nodeVisitor((<PropertyAccessExpression>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<PropertyAccessExpression>node).name, visitor, isIdentifier));
|
||||
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
if (node.flags & NodeFlags.OptionalChain) {
|
||||
return factory.updateElementAccessChain(<ElementAccessChain>node,
|
||||
visitNode((<ElementAccessChain>node).expression, visitor, isExpression),
|
||||
visitNode((<ElementAccessChain>node).questionDotToken, visitor, isToken),
|
||||
visitNode((<ElementAccessChain>node).argumentExpression, visitor, isExpression));
|
||||
nodeVisitor((<ElementAccessChain>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<ElementAccessChain>node).questionDotToken, visitor, isToken),
|
||||
nodeVisitor((<ElementAccessChain>node).argumentExpression, visitor, isExpression));
|
||||
}
|
||||
return factory.updateElementAccess(<ElementAccessExpression>node,
|
||||
visitNode((<ElementAccessExpression>node).expression, visitor, isExpression),
|
||||
visitNode((<ElementAccessExpression>node).argumentExpression, visitor, isExpression));
|
||||
nodeVisitor((<ElementAccessExpression>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<ElementAccessExpression>node).argumentExpression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.CallExpression:
|
||||
if (node.flags & NodeFlags.OptionalChain) {
|
||||
return factory.updateCallChain(<CallChain>node,
|
||||
visitNode((<CallChain>node).expression, visitor, isExpression),
|
||||
visitNode((<CallChain>node).questionDotToken, visitor, isToken),
|
||||
nodeVisitor((<CallChain>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<CallChain>node).questionDotToken, visitor, isToken),
|
||||
nodesVisitor((<CallChain>node).typeArguments, visitor, isTypeNode),
|
||||
nodesVisitor((<CallChain>node).arguments, visitor, isExpression));
|
||||
}
|
||||
return factory.updateCall(<CallExpression>node,
|
||||
visitNode((<CallExpression>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<CallExpression>node).expression, visitor, isExpression),
|
||||
nodesVisitor((<CallExpression>node).typeArguments, visitor, isTypeNode),
|
||||
nodesVisitor((<CallExpression>node).arguments, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.NewExpression:
|
||||
return factory.updateNew(<NewExpression>node,
|
||||
visitNode((<NewExpression>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<NewExpression>node).expression, visitor, isExpression),
|
||||
nodesVisitor((<NewExpression>node).typeArguments, visitor, isTypeNode),
|
||||
nodesVisitor((<NewExpression>node).arguments, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
return factory.updateTaggedTemplate(<TaggedTemplateExpression>node,
|
||||
visitNode((<TaggedTemplateExpression>node).tag, visitor, isExpression),
|
||||
visitNodes((<TaggedTemplateExpression>node).typeArguments, visitor, isExpression),
|
||||
visitNode((<TaggedTemplateExpression>node).template, visitor, isTemplateLiteral));
|
||||
nodeVisitor((<TaggedTemplateExpression>node).tag, visitor, isExpression),
|
||||
nodesVisitor((<TaggedTemplateExpression>node).typeArguments, visitor, isExpression),
|
||||
nodeVisitor((<TaggedTemplateExpression>node).template, visitor, isTemplateLiteral));
|
||||
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
return factory.updateTypeAssertion(<TypeAssertion>node,
|
||||
visitNode((<TypeAssertion>node).type, visitor, isTypeNode),
|
||||
visitNode((<TypeAssertion>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<TypeAssertion>node).type, visitor, isTypeNode),
|
||||
nodeVisitor((<TypeAssertion>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
return factory.updateParen(<ParenthesizedExpression>node,
|
||||
visitNode((<ParenthesizedExpression>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<ParenthesizedExpression>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return factory.updateFunctionExpression(<FunctionExpression>node,
|
||||
nodesVisitor((<FunctionExpression>node).modifiers, visitor, isModifier),
|
||||
visitNode((<FunctionExpression>node).asteriskToken, tokenVisitor, isToken),
|
||||
visitNode((<FunctionExpression>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<FunctionExpression>node).asteriskToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<FunctionExpression>node).name, visitor, isIdentifier),
|
||||
nodesVisitor((<FunctionExpression>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
visitParameterList((<FunctionExpression>node).parameters, visitor, context, nodesVisitor),
|
||||
visitNode((<FunctionExpression>node).type, visitor, isTypeNode),
|
||||
visitFunctionBody((<FunctionExpression>node).body, visitor, context));
|
||||
nodeVisitor((<FunctionExpression>node).type, visitor, isTypeNode),
|
||||
visitFunctionBody((<FunctionExpression>node).body, visitor, context, nodeVisitor));
|
||||
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return factory.updateArrowFunction(<ArrowFunction>node,
|
||||
nodesVisitor((<ArrowFunction>node).modifiers, visitor, isModifier),
|
||||
nodesVisitor((<ArrowFunction>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
visitParameterList((<ArrowFunction>node).parameters, visitor, context, nodesVisitor),
|
||||
visitNode((<ArrowFunction>node).type, visitor, isTypeNode),
|
||||
visitNode((<ArrowFunction>node).equalsGreaterThanToken, visitor, isToken),
|
||||
visitFunctionBody((<ArrowFunction>node).body, visitor, context));
|
||||
nodeVisitor((<ArrowFunction>node).type, visitor, isTypeNode),
|
||||
nodeVisitor((<ArrowFunction>node).equalsGreaterThanToken, visitor, isToken),
|
||||
visitFunctionBody((<ArrowFunction>node).body, visitor, context, nodeVisitor));
|
||||
|
||||
case SyntaxKind.DeleteExpression:
|
||||
return factory.updateDelete(<DeleteExpression>node,
|
||||
visitNode((<DeleteExpression>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<DeleteExpression>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.TypeOfExpression:
|
||||
return factory.updateTypeOf(<TypeOfExpression>node,
|
||||
visitNode((<TypeOfExpression>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<TypeOfExpression>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.VoidExpression:
|
||||
return factory.updateVoid(<VoidExpression>node,
|
||||
visitNode((<VoidExpression>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<VoidExpression>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.AwaitExpression:
|
||||
return factory.updateAwait(<AwaitExpression>node,
|
||||
visitNode((<AwaitExpression>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<AwaitExpression>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.PrefixUnaryExpression:
|
||||
return factory.updatePrefix(<PrefixUnaryExpression>node,
|
||||
visitNode((<PrefixUnaryExpression>node).operand, visitor, isExpression));
|
||||
nodeVisitor((<PrefixUnaryExpression>node).operand, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.PostfixUnaryExpression:
|
||||
return factory.updatePostfix(<PostfixUnaryExpression>node,
|
||||
visitNode((<PostfixUnaryExpression>node).operand, visitor, isExpression));
|
||||
nodeVisitor((<PostfixUnaryExpression>node).operand, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.BinaryExpression:
|
||||
return factory.updateBinary(<BinaryExpression>node,
|
||||
visitNode((<BinaryExpression>node).left, visitor, isExpression),
|
||||
visitNode((<BinaryExpression>node).right, visitor, isExpression),
|
||||
visitNode((<BinaryExpression>node).operatorToken, visitor, isToken));
|
||||
nodeVisitor((<BinaryExpression>node).left, visitor, isExpression),
|
||||
nodeVisitor((<BinaryExpression>node).right, visitor, isExpression),
|
||||
nodeVisitor((<BinaryExpression>node).operatorToken, visitor, isToken));
|
||||
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
return factory.updateConditional(<ConditionalExpression>node,
|
||||
visitNode((<ConditionalExpression>node).condition, visitor, isExpression),
|
||||
visitNode((<ConditionalExpression>node).questionToken, visitor, isToken),
|
||||
visitNode((<ConditionalExpression>node).whenTrue, visitor, isExpression),
|
||||
visitNode((<ConditionalExpression>node).colonToken, visitor, isToken),
|
||||
visitNode((<ConditionalExpression>node).whenFalse, visitor, isExpression));
|
||||
nodeVisitor((<ConditionalExpression>node).condition, visitor, isExpression),
|
||||
nodeVisitor((<ConditionalExpression>node).questionToken, visitor, isToken),
|
||||
nodeVisitor((<ConditionalExpression>node).whenTrue, visitor, isExpression),
|
||||
nodeVisitor((<ConditionalExpression>node).colonToken, visitor, isToken),
|
||||
nodeVisitor((<ConditionalExpression>node).whenFalse, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.TemplateExpression:
|
||||
return factory.updateTemplateExpression(<TemplateExpression>node,
|
||||
visitNode((<TemplateExpression>node).head, visitor, isTemplateHead),
|
||||
nodeVisitor((<TemplateExpression>node).head, visitor, isTemplateHead),
|
||||
nodesVisitor((<TemplateExpression>node).templateSpans, visitor, isTemplateSpan));
|
||||
|
||||
case SyntaxKind.YieldExpression:
|
||||
return factory.updateYield(<YieldExpression>node,
|
||||
visitNode((<YieldExpression>node).asteriskToken, tokenVisitor, isToken),
|
||||
visitNode((<YieldExpression>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<YieldExpression>node).asteriskToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<YieldExpression>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.SpreadElement:
|
||||
return factory.updateSpread(<SpreadElement>node,
|
||||
visitNode((<SpreadElement>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<SpreadElement>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.ClassExpression:
|
||||
return factory.updateClassExpression(<ClassExpression>node,
|
||||
nodesVisitor((<IndexSignatureDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<IndexSignatureDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<ClassExpression>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<ClassExpression>node).name, visitor, isIdentifier),
|
||||
nodesVisitor((<ClassExpression>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
nodesVisitor((<ClassExpression>node).heritageClauses, visitor, isHeritageClause),
|
||||
nodesVisitor((<ClassExpression>node).members, visitor, isClassElement));
|
||||
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return factory.updateExpressionWithTypeArguments(<ExpressionWithTypeArguments>node,
|
||||
visitNode((<ExpressionWithTypeArguments>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<ExpressionWithTypeArguments>node).expression, visitor, isExpression),
|
||||
nodesVisitor((<ExpressionWithTypeArguments>node).typeArguments, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.AsExpression:
|
||||
return factory.updateAsExpression(<AsExpression>node,
|
||||
visitNode((<AsExpression>node).expression, visitor, isExpression),
|
||||
visitNode((<AsExpression>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<AsExpression>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<AsExpression>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.NonNullExpression:
|
||||
return factory.updateNonNullExpression(<NonNullExpression>node,
|
||||
visitNode((<NonNullExpression>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<NonNullExpression>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.MetaProperty:
|
||||
return factory.updateMetaProperty(<MetaProperty>node,
|
||||
visitNode((<MetaProperty>node).name, visitor, isIdentifier));
|
||||
nodeVisitor((<MetaProperty>node).name, visitor, isIdentifier));
|
||||
|
||||
// Misc
|
||||
case SyntaxKind.TemplateSpan:
|
||||
return factory.updateTemplateSpan(<TemplateSpan>node,
|
||||
visitNode((<TemplateSpan>node).expression, visitor, isExpression),
|
||||
visitNode((<TemplateSpan>node).literal, visitor, isTemplateMiddleOrTemplateTail));
|
||||
nodeVisitor((<TemplateSpan>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<TemplateSpan>node).literal, visitor, isTemplateMiddleOrTemplateTail));
|
||||
|
||||
// Element
|
||||
case SyntaxKind.Block:
|
||||
@@ -633,91 +641,91 @@ namespace ts {
|
||||
case SyntaxKind.VariableStatement:
|
||||
return factory.updateVariableStatement(<VariableStatement>node,
|
||||
nodesVisitor((<VariableStatement>node).modifiers, visitor, isModifier),
|
||||
visitNode((<VariableStatement>node).declarationList, visitor, isVariableDeclarationList));
|
||||
nodeVisitor((<VariableStatement>node).declarationList, visitor, isVariableDeclarationList));
|
||||
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
return factory.updateExpressionStatement(<ExpressionStatement>node,
|
||||
visitNode((<ExpressionStatement>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<ExpressionStatement>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.IfStatement:
|
||||
return factory.updateIf(<IfStatement>node,
|
||||
visitNode((<IfStatement>node).expression, visitor, isExpression),
|
||||
visitNode((<IfStatement>node).thenStatement, visitor, isStatement, factory.liftToBlock),
|
||||
visitNode((<IfStatement>node).elseStatement, visitor, isStatement, factory.liftToBlock));
|
||||
nodeVisitor((<IfStatement>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<IfStatement>node).thenStatement, visitor, isStatement, factory.liftToBlock),
|
||||
nodeVisitor((<IfStatement>node).elseStatement, visitor, isStatement, factory.liftToBlock));
|
||||
|
||||
case SyntaxKind.DoStatement:
|
||||
return factory.updateDo(<DoStatement>node,
|
||||
visitNode((<DoStatement>node).statement, visitor, isStatement, factory.liftToBlock),
|
||||
visitNode((<DoStatement>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<DoStatement>node).statement, visitor, isStatement, factory.liftToBlock),
|
||||
nodeVisitor((<DoStatement>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.WhileStatement:
|
||||
return factory.updateWhile(<WhileStatement>node,
|
||||
visitNode((<WhileStatement>node).expression, visitor, isExpression),
|
||||
visitNode((<WhileStatement>node).statement, visitor, isStatement, factory.liftToBlock));
|
||||
nodeVisitor((<WhileStatement>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<WhileStatement>node).statement, visitor, isStatement, factory.liftToBlock));
|
||||
|
||||
case SyntaxKind.ForStatement:
|
||||
return factory.updateFor(<ForStatement>node,
|
||||
visitNode((<ForStatement>node).initializer, visitor, isForInitializer),
|
||||
visitNode((<ForStatement>node).condition, visitor, isExpression),
|
||||
visitNode((<ForStatement>node).incrementor, visitor, isExpression),
|
||||
visitNode((<ForStatement>node).statement, visitor, isStatement, factory.liftToBlock));
|
||||
nodeVisitor((<ForStatement>node).initializer, visitor, isForInitializer),
|
||||
nodeVisitor((<ForStatement>node).condition, visitor, isExpression),
|
||||
nodeVisitor((<ForStatement>node).incrementor, visitor, isExpression),
|
||||
nodeVisitor((<ForStatement>node).statement, visitor, isStatement, factory.liftToBlock));
|
||||
|
||||
case SyntaxKind.ForInStatement:
|
||||
return factory.updateForIn(<ForInStatement>node,
|
||||
visitNode((<ForInStatement>node).initializer, visitor, isForInitializer),
|
||||
visitNode((<ForInStatement>node).expression, visitor, isExpression),
|
||||
visitNode((<ForInStatement>node).statement, visitor, isStatement, factory.liftToBlock));
|
||||
nodeVisitor((<ForInStatement>node).initializer, visitor, isForInitializer),
|
||||
nodeVisitor((<ForInStatement>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<ForInStatement>node).statement, visitor, isStatement, factory.liftToBlock));
|
||||
|
||||
case SyntaxKind.ForOfStatement:
|
||||
return factory.updateForOf(<ForOfStatement>node,
|
||||
visitNode((<ForOfStatement>node).awaitModifier, visitor, isToken),
|
||||
visitNode((<ForOfStatement>node).initializer, visitor, isForInitializer),
|
||||
visitNode((<ForOfStatement>node).expression, visitor, isExpression),
|
||||
visitNode((<ForOfStatement>node).statement, visitor, isStatement, factory.liftToBlock));
|
||||
nodeVisitor((<ForOfStatement>node).awaitModifier, visitor, isToken),
|
||||
nodeVisitor((<ForOfStatement>node).initializer, visitor, isForInitializer),
|
||||
nodeVisitor((<ForOfStatement>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<ForOfStatement>node).statement, visitor, isStatement, factory.liftToBlock));
|
||||
|
||||
case SyntaxKind.ContinueStatement:
|
||||
return factory.updateContinue(<ContinueStatement>node,
|
||||
visitNode((<ContinueStatement>node).label, visitor, isIdentifier));
|
||||
nodeVisitor((<ContinueStatement>node).label, visitor, isIdentifier));
|
||||
|
||||
case SyntaxKind.BreakStatement:
|
||||
return factory.updateBreak(<BreakStatement>node,
|
||||
visitNode((<BreakStatement>node).label, visitor, isIdentifier));
|
||||
nodeVisitor((<BreakStatement>node).label, visitor, isIdentifier));
|
||||
|
||||
case SyntaxKind.ReturnStatement:
|
||||
return factory.updateReturn(<ReturnStatement>node,
|
||||
visitNode((<ReturnStatement>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<ReturnStatement>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.WithStatement:
|
||||
return factory.updateWith(<WithStatement>node,
|
||||
visitNode((<WithStatement>node).expression, visitor, isExpression),
|
||||
visitNode((<WithStatement>node).statement, visitor, isStatement, factory.liftToBlock));
|
||||
nodeVisitor((<WithStatement>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<WithStatement>node).statement, visitor, isStatement, factory.liftToBlock));
|
||||
|
||||
case SyntaxKind.SwitchStatement:
|
||||
return factory.updateSwitch(<SwitchStatement>node,
|
||||
visitNode((<SwitchStatement>node).expression, visitor, isExpression),
|
||||
visitNode((<SwitchStatement>node).caseBlock, visitor, isCaseBlock));
|
||||
nodeVisitor((<SwitchStatement>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<SwitchStatement>node).caseBlock, visitor, isCaseBlock));
|
||||
|
||||
case SyntaxKind.LabeledStatement:
|
||||
return factory.updateLabel(<LabeledStatement>node,
|
||||
visitNode((<LabeledStatement>node).label, visitor, isIdentifier),
|
||||
visitNode((<LabeledStatement>node).statement, visitor, isStatement, factory.liftToBlock));
|
||||
nodeVisitor((<LabeledStatement>node).label, visitor, isIdentifier),
|
||||
nodeVisitor((<LabeledStatement>node).statement, visitor, isStatement, factory.liftToBlock));
|
||||
|
||||
case SyntaxKind.ThrowStatement:
|
||||
return factory.updateThrow(<ThrowStatement>node,
|
||||
visitNode((<ThrowStatement>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<ThrowStatement>node).expression!, visitor, isExpression)); // expression could be `undefined` due to invalid parse.
|
||||
|
||||
case SyntaxKind.TryStatement:
|
||||
return factory.updateTry(<TryStatement>node,
|
||||
visitNode((<TryStatement>node).tryBlock, visitor, isBlock),
|
||||
visitNode((<TryStatement>node).catchClause, visitor, isCatchClause),
|
||||
visitNode((<TryStatement>node).finallyBlock, visitor, isBlock));
|
||||
nodeVisitor((<TryStatement>node).tryBlock, visitor, isBlock),
|
||||
nodeVisitor((<TryStatement>node).catchClause, visitor, isCatchClause),
|
||||
nodeVisitor((<TryStatement>node).finallyBlock, visitor, isBlock));
|
||||
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return factory.updateVariableDeclaration(<VariableDeclaration>node,
|
||||
visitNode((<VariableDeclaration>node).name, visitor, isBindingName),
|
||||
visitNode((<VariableDeclaration>node).exclamationToken, visitor, isToken),
|
||||
visitNode((<VariableDeclaration>node).type, visitor, isTypeNode),
|
||||
visitNode((<VariableDeclaration>node).initializer, visitor, isExpression));
|
||||
nodeVisitor((<VariableDeclaration>node).name, visitor, isBindingName),
|
||||
nodeVisitor((<VariableDeclaration>node).exclamationToken, visitor, isToken),
|
||||
nodeVisitor((<VariableDeclaration>node).type, visitor, isTypeNode),
|
||||
nodeVisitor((<VariableDeclaration>node).initializer, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.VariableDeclarationList:
|
||||
return factory.updateVariableDeclarationList(<VariableDeclarationList>node,
|
||||
@@ -727,18 +735,18 @@ namespace ts {
|
||||
return factory.updateFunctionDeclaration(<FunctionDeclaration>node,
|
||||
nodesVisitor((<FunctionDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<FunctionDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<FunctionDeclaration>node).asteriskToken, tokenVisitor, isToken),
|
||||
visitNode((<FunctionDeclaration>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<FunctionDeclaration>node).asteriskToken, tokenVisitor, isToken),
|
||||
nodeVisitor((<FunctionDeclaration>node).name, visitor, isIdentifier),
|
||||
nodesVisitor((<FunctionDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
visitParameterList((<FunctionDeclaration>node).parameters, visitor, context, nodesVisitor),
|
||||
visitNode((<FunctionDeclaration>node).type, visitor, isTypeNode),
|
||||
visitFunctionBody((<FunctionExpression>node).body, visitor, context));
|
||||
nodeVisitor((<FunctionDeclaration>node).type, visitor, isTypeNode),
|
||||
visitFunctionBody((<FunctionExpression>node).body, visitor, context, nodeVisitor));
|
||||
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
return factory.updateClassDeclaration(<ClassDeclaration>node,
|
||||
nodesVisitor((<ClassDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<ClassDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<ClassDeclaration>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<ClassDeclaration>node).name, visitor, isIdentifier),
|
||||
nodesVisitor((<ClassDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
nodesVisitor((<ClassDeclaration>node).heritageClauses, visitor, isHeritageClause),
|
||||
nodesVisitor((<ClassDeclaration>node).members, visitor, isClassElement));
|
||||
@@ -747,7 +755,7 @@ namespace ts {
|
||||
return factory.updateInterfaceDeclaration(<InterfaceDeclaration>node,
|
||||
nodesVisitor((<InterfaceDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<InterfaceDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<InterfaceDeclaration>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<InterfaceDeclaration>node).name, visitor, isIdentifier),
|
||||
nodesVisitor((<InterfaceDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
nodesVisitor((<InterfaceDeclaration>node).heritageClauses, visitor, isHeritageClause),
|
||||
nodesVisitor((<InterfaceDeclaration>node).members, visitor, isTypeElement));
|
||||
@@ -756,23 +764,23 @@ namespace ts {
|
||||
return factory.updateTypeAliasDeclaration(<TypeAliasDeclaration>node,
|
||||
nodesVisitor((<TypeAliasDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<TypeAliasDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<TypeAliasDeclaration>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<TypeAliasDeclaration>node).name, visitor, isIdentifier),
|
||||
nodesVisitor((<TypeAliasDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration),
|
||||
visitNode((<TypeAliasDeclaration>node).type, visitor, isTypeNode));
|
||||
nodeVisitor((<TypeAliasDeclaration>node).type, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
return factory.updateEnumDeclaration(<EnumDeclaration>node,
|
||||
nodesVisitor((<EnumDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<EnumDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<EnumDeclaration>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<EnumDeclaration>node).name, visitor, isIdentifier),
|
||||
nodesVisitor((<EnumDeclaration>node).members, visitor, isEnumMember));
|
||||
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
return factory.updateModuleDeclaration(<ModuleDeclaration>node,
|
||||
nodesVisitor((<ModuleDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<ModuleDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<ModuleDeclaration>node).name, visitor, isIdentifier),
|
||||
visitNode((<ModuleDeclaration>node).body, visitor, isModuleBody));
|
||||
nodeVisitor((<ModuleDeclaration>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<ModuleDeclaration>node).body, visitor, isModuleBody));
|
||||
|
||||
case SyntaxKind.ModuleBlock:
|
||||
return factory.updateModuleBlock(<ModuleBlock>node,
|
||||
@@ -784,30 +792,30 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.NamespaceExportDeclaration:
|
||||
return factory.updateNamespaceExportDeclaration(<NamespaceExportDeclaration>node,
|
||||
visitNode((<NamespaceExportDeclaration>node).name, visitor, isIdentifier));
|
||||
nodeVisitor((<NamespaceExportDeclaration>node).name, visitor, isIdentifier));
|
||||
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
return factory.updateImportEqualsDeclaration(<ImportEqualsDeclaration>node,
|
||||
nodesVisitor((<ImportEqualsDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<ImportEqualsDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<ImportEqualsDeclaration>node).name, visitor, isIdentifier),
|
||||
visitNode((<ImportEqualsDeclaration>node).moduleReference, visitor, isModuleReference));
|
||||
nodeVisitor((<ImportEqualsDeclaration>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<ImportEqualsDeclaration>node).moduleReference, visitor, isModuleReference));
|
||||
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
return factory.updateImportDeclaration(<ImportDeclaration>node,
|
||||
nodesVisitor((<ImportDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<ImportDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<ImportDeclaration>node).importClause, visitor, isImportClause),
|
||||
visitNode((<ImportDeclaration>node).moduleSpecifier, visitor, isExpression));
|
||||
nodeVisitor((<ImportDeclaration>node).importClause, visitor, isImportClause),
|
||||
nodeVisitor((<ImportDeclaration>node).moduleSpecifier, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.ImportClause:
|
||||
return factory.updateImportClause(<ImportClause>node,
|
||||
visitNode((<ImportClause>node).name, visitor, isIdentifier),
|
||||
visitNode((<ImportClause>node).namedBindings, visitor, isNamedImportBindings));
|
||||
nodeVisitor((<ImportClause>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<ImportClause>node).namedBindings, visitor, isNamedImportBindings));
|
||||
|
||||
case SyntaxKind.NamespaceImport:
|
||||
return factory.updateNamespaceImport(<NamespaceImport>node,
|
||||
visitNode((<NamespaceImport>node).name, visitor, isIdentifier));
|
||||
nodeVisitor((<NamespaceImport>node).name, visitor, isIdentifier));
|
||||
|
||||
case SyntaxKind.NamedImports:
|
||||
return factory.updateNamedImports(<NamedImports>node,
|
||||
@@ -815,21 +823,21 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
return factory.updateImportSpecifier(<ImportSpecifier>node,
|
||||
visitNode((<ImportSpecifier>node).propertyName, visitor, isIdentifier),
|
||||
visitNode((<ImportSpecifier>node).name, visitor, isIdentifier));
|
||||
nodeVisitor((<ImportSpecifier>node).propertyName, visitor, isIdentifier),
|
||||
nodeVisitor((<ImportSpecifier>node).name, visitor, isIdentifier));
|
||||
|
||||
case SyntaxKind.ExportAssignment:
|
||||
return factory.updateExportAssignment(<ExportAssignment>node,
|
||||
nodesVisitor((<ExportAssignment>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<ExportAssignment>node).modifiers, visitor, isModifier),
|
||||
visitNode((<ExportAssignment>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<ExportAssignment>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
return factory.updateExportDeclaration(<ExportDeclaration>node,
|
||||
nodesVisitor((<ExportDeclaration>node).decorators, visitor, isDecorator),
|
||||
nodesVisitor((<ExportDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<ExportDeclaration>node).exportClause, visitor, isNamedExports),
|
||||
visitNode((<ExportDeclaration>node).moduleSpecifier, visitor, isExpression));
|
||||
nodeVisitor((<ExportDeclaration>node).exportClause, visitor, isNamedExports),
|
||||
nodeVisitor((<ExportDeclaration>node).moduleSpecifier, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.NamedExports:
|
||||
return factory.updateNamedExports(<NamedExports>node,
|
||||
@@ -837,47 +845,47 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
return factory.updateExportSpecifier(<ExportSpecifier>node,
|
||||
visitNode((<ExportSpecifier>node).propertyName, visitor, isIdentifier),
|
||||
visitNode((<ExportSpecifier>node).name, visitor, isIdentifier));
|
||||
nodeVisitor((<ExportSpecifier>node).propertyName, visitor, isIdentifier),
|
||||
nodeVisitor((<ExportSpecifier>node).name, visitor, isIdentifier));
|
||||
|
||||
// Module references
|
||||
case SyntaxKind.ExternalModuleReference:
|
||||
return factory.updateExternalModuleReference(<ExternalModuleReference>node,
|
||||
visitNode((<ExternalModuleReference>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<ExternalModuleReference>node).expression, visitor, isExpression));
|
||||
|
||||
// JSX
|
||||
case SyntaxKind.JsxElement:
|
||||
return factory.updateJsxElement(<JsxElement>node,
|
||||
visitNode((<JsxElement>node).openingElement, visitor, isJsxOpeningElement),
|
||||
nodeVisitor((<JsxElement>node).openingElement, visitor, isJsxOpeningElement),
|
||||
nodesVisitor((<JsxElement>node).children, visitor, isJsxChild),
|
||||
visitNode((<JsxElement>node).closingElement, visitor, isJsxClosingElement));
|
||||
nodeVisitor((<JsxElement>node).closingElement, visitor, isJsxClosingElement));
|
||||
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
return factory.updateJsxSelfClosingElement(<JsxSelfClosingElement>node,
|
||||
visitNode((<JsxSelfClosingElement>node).tagName, visitor, isJsxTagNameExpression),
|
||||
nodeVisitor((<JsxSelfClosingElement>node).tagName, visitor, isJsxTagNameExpression),
|
||||
nodesVisitor((<JsxSelfClosingElement>node).typeArguments, visitor, isTypeNode),
|
||||
visitNode((<JsxSelfClosingElement>node).attributes, visitor, isJsxAttributes));
|
||||
nodeVisitor((<JsxSelfClosingElement>node).attributes, visitor, isJsxAttributes));
|
||||
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
return factory.updateJsxOpeningElement(<JsxOpeningElement>node,
|
||||
visitNode((<JsxOpeningElement>node).tagName, visitor, isJsxTagNameExpression),
|
||||
nodeVisitor((<JsxOpeningElement>node).tagName, visitor, isJsxTagNameExpression),
|
||||
nodesVisitor((<JsxSelfClosingElement>node).typeArguments, visitor, isTypeNode),
|
||||
visitNode((<JsxOpeningElement>node).attributes, visitor, isJsxAttributes));
|
||||
nodeVisitor((<JsxOpeningElement>node).attributes, visitor, isJsxAttributes));
|
||||
|
||||
case SyntaxKind.JsxClosingElement:
|
||||
return factory.updateJsxClosingElement(<JsxClosingElement>node,
|
||||
visitNode((<JsxClosingElement>node).tagName, visitor, isJsxTagNameExpression));
|
||||
nodeVisitor((<JsxClosingElement>node).tagName, visitor, isJsxTagNameExpression));
|
||||
|
||||
case SyntaxKind.JsxFragment:
|
||||
return factory.updateJsxFragment(<JsxFragment>node,
|
||||
visitNode((<JsxFragment>node).openingFragment, visitor, isJsxOpeningFragment),
|
||||
nodeVisitor((<JsxFragment>node).openingFragment, visitor, isJsxOpeningFragment),
|
||||
nodesVisitor((<JsxFragment>node).children, visitor, isJsxChild),
|
||||
visitNode((<JsxFragment>node).closingFragment, visitor, isJsxClosingFragment));
|
||||
nodeVisitor((<JsxFragment>node).closingFragment, visitor, isJsxClosingFragment));
|
||||
|
||||
case SyntaxKind.JsxAttribute:
|
||||
return factory.updateJsxAttribute(<JsxAttribute>node,
|
||||
visitNode((<JsxAttribute>node).name, visitor, isIdentifier),
|
||||
visitNode((<JsxAttribute>node).initializer, visitor, isStringLiteralOrJsxExpression));
|
||||
nodeVisitor((<JsxAttribute>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<JsxAttribute>node).initializer, visitor, isStringLiteralOrJsxExpression));
|
||||
|
||||
case SyntaxKind.JsxAttributes:
|
||||
return factory.updateJsxAttributes(<JsxAttributes>node,
|
||||
@@ -885,16 +893,16 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.JsxSpreadAttribute:
|
||||
return factory.updateJsxSpreadAttribute(<JsxSpreadAttribute>node,
|
||||
visitNode((<JsxSpreadAttribute>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<JsxSpreadAttribute>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.JsxExpression:
|
||||
return factory.updateJsxExpression(<JsxExpression>node,
|
||||
visitNode((<JsxExpression>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<JsxExpression>node).expression, visitor, isExpression));
|
||||
|
||||
// Clauses
|
||||
case SyntaxKind.CaseClause:
|
||||
return factory.updateCaseClause(<CaseClause>node,
|
||||
visitNode((<CaseClause>node).expression, visitor, isExpression),
|
||||
nodeVisitor((<CaseClause>node).expression, visitor, isExpression),
|
||||
nodesVisitor((<CaseClause>node).statements, visitor, isStatement));
|
||||
|
||||
case SyntaxKind.DefaultClause:
|
||||
@@ -907,29 +915,29 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.CatchClause:
|
||||
return factory.updateCatchClause(<CatchClause>node,
|
||||
visitNode((<CatchClause>node).variableDeclaration, visitor, isVariableDeclaration),
|
||||
visitNode((<CatchClause>node).block, visitor, isBlock));
|
||||
nodeVisitor((<CatchClause>node).variableDeclaration, visitor, isVariableDeclaration),
|
||||
nodeVisitor((<CatchClause>node).block, visitor, isBlock));
|
||||
|
||||
// Property assignments
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return factory.updatePropertyAssignment(<PropertyAssignment>node,
|
||||
visitNode((<PropertyAssignment>node).name, visitor, isPropertyName),
|
||||
visitNode((<PropertyAssignment>node).initializer, visitor, isExpression));
|
||||
nodeVisitor((<PropertyAssignment>node).name, visitor, isPropertyName),
|
||||
nodeVisitor((<PropertyAssignment>node).initializer, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
return factory.updateShorthandPropertyAssignment(<ShorthandPropertyAssignment>node,
|
||||
visitNode((<ShorthandPropertyAssignment>node).name, visitor, isIdentifier),
|
||||
visitNode((<ShorthandPropertyAssignment>node).objectAssignmentInitializer, visitor, isExpression));
|
||||
nodeVisitor((<ShorthandPropertyAssignment>node).name, visitor, isIdentifier),
|
||||
nodeVisitor((<ShorthandPropertyAssignment>node).objectAssignmentInitializer, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
return factory.updateSpreadAssignment(<SpreadAssignment>node,
|
||||
visitNode((<SpreadAssignment>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<SpreadAssignment>node).expression, visitor, isExpression));
|
||||
|
||||
// Enum
|
||||
case SyntaxKind.EnumMember:
|
||||
return factory.updateEnumMember(<EnumMember>node,
|
||||
visitNode((<EnumMember>node).name, visitor, isPropertyName),
|
||||
visitNode((<EnumMember>node).initializer, visitor, isExpression));
|
||||
nodeVisitor((<EnumMember>node).name, visitor, isPropertyName),
|
||||
nodeVisitor((<EnumMember>node).initializer, visitor, isExpression));
|
||||
|
||||
// Top-level nodes
|
||||
case SyntaxKind.SourceFile:
|
||||
@@ -939,7 +947,7 @@ namespace ts {
|
||||
// Transformation nodes
|
||||
case SyntaxKind.PartiallyEmittedExpression:
|
||||
return factory.updatePartiallyEmittedExpression(<PartiallyEmittedExpression>node,
|
||||
visitNode((<PartiallyEmittedExpression>node).expression, visitor, isExpression));
|
||||
nodeVisitor((<PartiallyEmittedExpression>node).expression, visitor, isExpression));
|
||||
|
||||
case SyntaxKind.CommaListExpression:
|
||||
return factory.updateCommaList(<CommaListExpression>node,
|
||||
|
||||
@@ -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 = <EndOfFileToken>{ kind: SyntaxKind.EndOfFileToken };
|
||||
}
|
||||
const configFileErrors = result.parseDiagnostics as Diagnostic[];
|
||||
const parsedCommandLine = parseJsonSourceFileConfigFileContent(
|
||||
result,
|
||||
|
||||
@@ -155,17 +155,23 @@ namespace ts.codefix {
|
||||
body: Block | undefined,
|
||||
): MethodDeclaration | undefined {
|
||||
const program = context.program;
|
||||
const signatureDeclaration = <MethodDeclaration>program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation | NodeBuilderFlags.SuppressAnyReturnType, getNoopSymbolTrackerWithResolver(context));
|
||||
if (!signatureDeclaration) {
|
||||
const node = <MethodDeclaration>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(
|
||||
|
||||
@@ -1262,13 +1262,13 @@ namespace ts.refactor.extractSymbol {
|
||||
}
|
||||
|
||||
function visitor(node: Node): VisitResult<Node> {
|
||||
if (!ignoreReturns && node.kind === SyntaxKind.ReturnStatement && hasWritesOrVariableDeclarations) {
|
||||
if (!ignoreReturns && isReturnStatement(node) && hasWritesOrVariableDeclarations) {
|
||||
const assignments: ObjectLiteralElementLike[] = getPropertyAssignmentsForWritesAndVariableDeclarations(exposedVariableDeclarations, writes);
|
||||
if ((<ReturnStatement>node).expression) {
|
||||
if (node.expression) {
|
||||
if (!returnValueProperty) {
|
||||
returnValueProperty = "__return";
|
||||
}
|
||||
assignments.unshift(factory.createPropertyAssignment(returnValueProperty, visitNode((<ReturnStatement>node).expression, visitor)));
|
||||
assignments.unshift(factory.createPropertyAssignment(returnValueProperty, visitNode(node.expression, visitor)));
|
||||
}
|
||||
if (assignments.length === 1) {
|
||||
return factory.createReturn(assignments[0].name as Expression);
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
+546
-527
File diff suppressed because it is too large
Load Diff
+546
-527
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user