1namespace ts { 2 const isTypeNodeOrTypeParameterDeclaration = or(isTypeNode, isTypeParameterDeclaration); 3 4 /** 5 * Visits a Node using the supplied visitor, possibly returning a new Node in its place. 6 * 7 * @param node The Node to visit. 8 * @param visitor The callback used to visit the Node. 9 * @param test A callback to execute to verify the Node is valid. 10 * @param lift An optional callback to execute to lift a NodeArray into a valid Node. 11 */ 12 export function visitNode<T extends Node>(node: T, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: readonly Node[]) => T): T; 13 14 /** 15 * Visits a Node using the supplied visitor, possibly returning a new Node in its place. 16 * 17 * @param node The Node to visit. 18 * @param visitor The callback used to visit the Node. 19 * @param test A callback to execute to verify the Node is valid. 20 * @param lift An optional callback to execute to lift a NodeArray into a valid Node. 21 */ 22 export function visitNode<T extends Node>(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: readonly Node[]) => T): T | undefined; 23 24 export function visitNode<T extends Node>(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: readonly Node[]) => T): T | undefined { 25 if (node === undefined || visitor === undefined) { 26 return node; 27 } 28 29 const visited = visitor(node); 30 if (visited === node) { 31 return node; 32 } 33 34 let visitedNode: Node | undefined; 35 if (visited === undefined) { 36 return undefined; 37 } 38 else if (isArray(visited)) { 39 visitedNode = (lift || extractSingleNode)(visited); 40 } 41 else { 42 visitedNode = visited; 43 } 44 45 Debug.assertNode(visitedNode, test); 46 return <T>visitedNode; 47 } 48 49 /** 50 * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. 51 * 52 * @param nodes The NodeArray to visit. 53 * @param visitor The callback used to visit a Node. 54 * @param test A node test to execute for each node. 55 * @param start An optional value indicating the starting offset at which to start visiting. 56 * @param count An optional value indicating the maximum number of nodes to visit. 57 */ 58 export function visitNodes<T extends Node>(nodes: NodeArray<T>, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T>; 59 60 /** 61 * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. 62 * 63 * @param nodes The NodeArray to visit. 64 * @param visitor The callback used to visit a Node. 65 * @param test A node test to execute for each node. 66 * @param start An optional value indicating the starting offset at which to start visiting. 67 * @param count An optional value indicating the maximum number of nodes to visit. 68 */ 69 export function visitNodes<T extends Node>(nodes: NodeArray<T> | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T> | undefined; 70 71 /** 72 * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. 73 * 74 * @param nodes The NodeArray to visit. 75 * @param visitor The callback used to visit a Node. 76 * @param test A node test to execute for each node. 77 * @param start An optional value indicating the starting offset at which to start visiting. 78 * @param count An optional value indicating the maximum number of nodes to visit. 79 */ 80 export function visitNodes<T extends Node>(nodes: NodeArray<T> | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T> | undefined { 81 if (nodes === undefined || visitor === undefined) { 82 return nodes; 83 } 84 85 let updated: T[] | undefined; 86 87 // Ensure start and count have valid values 88 const length = nodes.length; 89 if (start === undefined || start < 0) { 90 start = 0; 91 } 92 93 if (count === undefined || count > length - start) { 94 count = length - start; 95 } 96 97 let hasTrailingComma: boolean | undefined; 98 let pos = -1; 99 let end = -1; 100 if (start > 0 || count < length) { 101 // If we are not visiting all of the original nodes, we must always create a new array. 102 // Since this is a fragment of a node array, we do not copy over the previous location 103 // and will only copy over `hasTrailingComma` if we are including the last element. 104 updated = []; 105 hasTrailingComma = nodes.hasTrailingComma && start + count === length; 106 } 107 108 // Visit each original node. 109 for (let i = 0; i < count; i++) { 110 const node: T = nodes[i + start]; 111 const visited = node !== undefined ? visitor(node) : undefined; 112 if (updated !== undefined || visited === undefined || visited !== node) { 113 if (updated === undefined) { 114 // Ensure we have a copy of `nodes`, up to the current index. 115 updated = nodes.slice(0, i); 116 hasTrailingComma = nodes.hasTrailingComma; 117 pos = nodes.pos; 118 end = nodes.end; 119 } 120 if (visited) { 121 if (isArray(visited)) { 122 for (const visitedNode of visited) { 123 void Debug.assertNode(visitedNode, test); 124 updated.push(<T>visitedNode); 125 } 126 } 127 else { 128 void Debug.assertNode(visited, test); 129 updated.push(<T>visited); 130 } 131 } 132 } 133 } 134 135 if (updated) { 136 // TODO(rbuckton): Remove dependency on `ts.factory` in favor of a provided factory. 137 const updatedArray = factory.createNodeArray(updated, hasTrailingComma); 138 setTextRangePosEnd(updatedArray, pos, end); 139 return updatedArray; 140 } 141 142 return nodes; 143 } 144 145 /** 146 * Starts a new lexical environment and visits a statement list, ending the lexical environment 147 * and merging hoisted declarations upon completion. 148 */ 149 export function visitLexicalEnvironment(statements: NodeArray<Statement>, visitor: Visitor, context: TransformationContext, start?: number, ensureUseStrict?: boolean, nodesVisitor: NodesVisitor = visitNodes) { 150 context.startLexicalEnvironment(); 151 statements = nodesVisitor(statements, visitor, isStatement, start); 152 if (ensureUseStrict) statements = context.factory.ensureUseStrict(statements); 153 return factory.mergeLexicalEnvironment(statements, context.endLexicalEnvironment()); 154 } 155 156 /** 157 * Starts a new lexical environment and visits a parameter list, suspending the lexical 158 * environment upon completion. 159 */ 160 export function visitParameterList(nodes: NodeArray<ParameterDeclaration>, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray<ParameterDeclaration>; 161 export function visitParameterList(nodes: NodeArray<ParameterDeclaration> | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor): NodeArray<ParameterDeclaration> | undefined; 162 export function visitParameterList(nodes: NodeArray<ParameterDeclaration> | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor = visitNodes) { 163 let updated: NodeArray<ParameterDeclaration> | undefined; 164 context.startLexicalEnvironment(); 165 if (nodes) { 166 context.setLexicalEnvironmentFlags(LexicalEnvironmentFlags.InParameters, true); 167 updated = nodesVisitor(nodes, visitor, isParameterDeclaration); 168 169 // As of ES2015, any runtime execution of that occurs in for a parameter (such as evaluating an 170 // initializer or a binding pattern), occurs in its own lexical scope. As a result, any expression 171 // that we might transform that introduces a temporary variable would fail as the temporary variable 172 // exists in a different lexical scope. To address this, we move any binding patterns and initializers 173 // in a parameter list to the body if we detect a variable being hoisted while visiting a parameter list 174 // when the emit target is greater than ES2015. 175 if (context.getLexicalEnvironmentFlags() & LexicalEnvironmentFlags.VariablesHoistedInParameters && 176 getEmitScriptTarget(context.getCompilerOptions()) >= ScriptTarget.ES2015) { 177 updated = addDefaultValueAssignmentsIfNeeded(updated, context); 178 } 179 context.setLexicalEnvironmentFlags(LexicalEnvironmentFlags.InParameters, false); 180 } 181 context.suspendLexicalEnvironment(); 182 return updated; 183 } 184 185 function addDefaultValueAssignmentsIfNeeded(parameters: NodeArray<ParameterDeclaration>, context: TransformationContext) { 186 let result: ParameterDeclaration[] | undefined; 187 for (let i = 0; i < parameters.length; i++) { 188 const parameter = parameters[i]; 189 const updated = addDefaultValueAssignmentIfNeeded(parameter, context); 190 if (result || updated !== parameter) { 191 if (!result) result = parameters.slice(0, i); 192 result[i] = updated; 193 } 194 } 195 if (result) { 196 return setTextRange(context.factory.createNodeArray(result, parameters.hasTrailingComma), parameters); 197 } 198 return parameters; 199 } 200 201 function addDefaultValueAssignmentIfNeeded(parameter: ParameterDeclaration, context: TransformationContext) { 202 // A rest parameter cannot have a binding pattern or an initializer, 203 // so let's just ignore it. 204 return parameter.dotDotDotToken ? parameter : 205 isBindingPattern(parameter.name) ? addDefaultValueAssignmentForBindingPattern(parameter, context) : 206 parameter.initializer ? addDefaultValueAssignmentForInitializer(parameter, parameter.name, parameter.initializer, context) : 207 parameter; 208 } 209 210 function addDefaultValueAssignmentForBindingPattern(parameter: ParameterDeclaration, context: TransformationContext) { 211 const { factory } = context; 212 context.addInitializationStatement( 213 factory.createVariableStatement( 214 /*modifiers*/ undefined, 215 factory.createVariableDeclarationList([ 216 factory.createVariableDeclaration( 217 parameter.name, 218 /*exclamationToken*/ undefined, 219 parameter.type, 220 parameter.initializer ? 221 factory.createConditionalExpression( 222 factory.createStrictEquality( 223 factory.getGeneratedNameForNode(parameter), 224 factory.createVoidZero() 225 ), 226 /*questionToken*/ undefined, 227 parameter.initializer, 228 /*colonToken*/ undefined, 229 factory.getGeneratedNameForNode(parameter) 230 ) : 231 factory.getGeneratedNameForNode(parameter) 232 ), 233 ]) 234 ) 235 ); 236 return factory.updateParameterDeclaration(parameter, 237 parameter.decorators, 238 parameter.modifiers, 239 parameter.dotDotDotToken, 240 factory.getGeneratedNameForNode(parameter), 241 parameter.questionToken, 242 parameter.type, 243 /*initializer*/ undefined); 244 } 245 246 function addDefaultValueAssignmentForInitializer(parameter: ParameterDeclaration, name: Identifier, initializer: Expression, context: TransformationContext) { 247 const factory = context.factory; 248 context.addInitializationStatement( 249 factory.createIfStatement( 250 factory.createTypeCheck(factory.cloneNode(name), "undefined"), 251 setEmitFlags( 252 setTextRange( 253 factory.createBlock([ 254 factory.createExpressionStatement( 255 setEmitFlags( 256 setTextRange( 257 factory.createAssignment( 258 setEmitFlags(factory.cloneNode(name), EmitFlags.NoSourceMap), 259 setEmitFlags(initializer, EmitFlags.NoSourceMap | getEmitFlags(initializer) | EmitFlags.NoComments) 260 ), 261 parameter 262 ), 263 EmitFlags.NoComments 264 ) 265 ) 266 ]), 267 parameter 268 ), 269 EmitFlags.SingleLine | EmitFlags.NoTrailingSourceMap | EmitFlags.NoTokenSourceMaps | EmitFlags.NoComments 270 ) 271 ) 272 ); 273 return factory.updateParameterDeclaration(parameter, 274 parameter.decorators, 275 parameter.modifiers, 276 parameter.dotDotDotToken, 277 parameter.name, 278 parameter.questionToken, 279 parameter.type, 280 /*initializer*/ undefined); 281 } 282 283 /** 284 * Resumes a suspended lexical environment and visits a function body, ending the lexical 285 * environment and merging hoisted declarations upon completion. 286 */ 287 export function visitFunctionBody(node: FunctionBody, visitor: Visitor, context: TransformationContext): FunctionBody; 288 /** 289 * Resumes a suspended lexical environment and visits a function body, ending the lexical 290 * environment and merging hoisted declarations upon completion. 291 */ 292 export function visitFunctionBody(node: FunctionBody | undefined, visitor: Visitor, context: TransformationContext): FunctionBody | undefined; 293 /** 294 * Resumes a suspended lexical environment and visits a concise body, ending the lexical 295 * environment and merging hoisted declarations upon completion. 296 */ 297 export function visitFunctionBody(node: ConciseBody, visitor: Visitor, context: TransformationContext): ConciseBody; 298 /* @internal*/ export function visitFunctionBody(node: FunctionBody, visitor: Visitor, context: TransformationContext, nodeVisitor?: NodeVisitor): FunctionBody; // eslint-disable-line @typescript-eslint/unified-signatures 299 /* @internal*/ export function visitFunctionBody(node: FunctionBody | undefined, visitor: Visitor, context: TransformationContext, nodeVisitor?: NodeVisitor): FunctionBody | undefined; // eslint-disable-line @typescript-eslint/unified-signatures 300 /* @internal*/ export function visitFunctionBody(node: ConciseBody, visitor: Visitor, context: TransformationContext, nodeVisitor?: NodeVisitor): ConciseBody; // eslint-disable-line @typescript-eslint/unified-signatures 301 export function visitFunctionBody(node: ConciseBody | undefined, visitor: Visitor, context: TransformationContext, nodeVisitor: NodeVisitor = visitNode): ConciseBody | undefined { 302 context.resumeLexicalEnvironment(); 303 const updated = nodeVisitor(node, visitor, isConciseBody); 304 const declarations = context.endLexicalEnvironment(); 305 if (some(declarations)) { 306 if (!updated) { 307 return context.factory.createBlock(declarations); 308 } 309 const block = context.factory.converters.convertToFunctionBlock(updated); 310 const statements = factory.mergeLexicalEnvironment(block.statements, declarations); 311 return context.factory.updateBlock(block, statements); 312 } 313 return updated; 314 } 315 316 /** 317 * Visits each child of a Node using the supplied visitor, possibly returning a new Node of the same kind in its place. 318 * 319 * @param node The Node whose children will be visited. 320 * @param visitor The callback used to visit each child. 321 * @param context A lexical environment context for the visitor. 322 */ 323 export function visitEachChild<T extends Node>(node: T, visitor: Visitor, context: TransformationContext): T; 324 /* @internal */ 325 export function visitEachChild<T extends Node>(node: T, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor, tokenVisitor?: Visitor, nodeVisitor?: NodeVisitor): T; // eslint-disable-line @typescript-eslint/unified-signatures 326 /** 327 * Visits each child of a Node using the supplied visitor, possibly returning a new Node of the same kind in its place. 328 * 329 * @param node The Node whose children will be visited. 330 * @param visitor The callback used to visit each child. 331 * @param context A lexical environment context for the visitor. 332 */ 333 export function visitEachChild<T extends Node>(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined; 334 /* @internal */ 335 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 336 export function visitEachChild(node: Node | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor = visitNodes, tokenVisitor?: Visitor, nodeVisitor: NodeVisitor = visitNode): Node | undefined { 337 if (node === undefined) { 338 return undefined; 339 } 340 341 const kind = node.kind; 342 343 // No need to visit nodes with no children. 344 if ((kind > SyntaxKind.FirstToken && kind <= SyntaxKind.LastToken) || kind === SyntaxKind.ThisType) { 345 return node; 346 } 347 348 const factory = context.factory; 349 switch (kind) { 350 // Names 351 352 case SyntaxKind.Identifier: 353 return factory.updateIdentifier(<Identifier>node, 354 nodesVisitor((<Identifier>node).typeArguments, visitor, isTypeNodeOrTypeParameterDeclaration)); 355 356 case SyntaxKind.QualifiedName: 357 return factory.updateQualifiedName(<QualifiedName>node, 358 nodeVisitor((<QualifiedName>node).left, visitor, isEntityName), 359 nodeVisitor((<QualifiedName>node).right, visitor, isIdentifier)); 360 361 case SyntaxKind.ComputedPropertyName: 362 return factory.updateComputedPropertyName(<ComputedPropertyName>node, 363 nodeVisitor((<ComputedPropertyName>node).expression, visitor, isExpression)); 364 365 // Signature elements 366 case SyntaxKind.TypeParameter: 367 return factory.updateTypeParameterDeclaration(<TypeParameterDeclaration>node, 368 nodeVisitor((<TypeParameterDeclaration>node).name, visitor, isIdentifier), 369 nodeVisitor((<TypeParameterDeclaration>node).constraint, visitor, isTypeNode), 370 nodeVisitor((<TypeParameterDeclaration>node).default, visitor, isTypeNode)); 371 372 case SyntaxKind.Parameter: 373 return factory.updateParameterDeclaration(<ParameterDeclaration>node, 374 nodesVisitor((<ParameterDeclaration>node).decorators, visitor, isDecorator), 375 nodesVisitor((<ParameterDeclaration>node).modifiers, visitor, isModifier), 376 nodeVisitor((<ParameterDeclaration>node).dotDotDotToken, tokenVisitor, isToken), 377 nodeVisitor((<ParameterDeclaration>node).name, visitor, isBindingName), 378 nodeVisitor((<ParameterDeclaration>node).questionToken, tokenVisitor, isToken), 379 nodeVisitor((<ParameterDeclaration>node).type, visitor, isTypeNode), 380 nodeVisitor((<ParameterDeclaration>node).initializer, visitor, isExpression)); 381 382 case SyntaxKind.Decorator: 383 return factory.updateDecorator(<Decorator>node, 384 nodeVisitor((<Decorator>node).expression, visitor, isExpression)); 385 386 // Type elements 387 case SyntaxKind.PropertySignature: 388 return factory.updatePropertySignature((<PropertySignature>node), 389 nodesVisitor((<PropertySignature>node).modifiers, visitor, isToken), 390 nodeVisitor((<PropertySignature>node).name, visitor, isPropertyName), 391 nodeVisitor((<PropertySignature>node).questionToken, tokenVisitor, isToken), 392 nodeVisitor((<PropertySignature>node).type, visitor, isTypeNode)); 393 394 case SyntaxKind.PropertyDeclaration: 395 return factory.updatePropertyDeclaration(<PropertyDeclaration>node, 396 nodesVisitor((<PropertyDeclaration>node).decorators, visitor, isDecorator), 397 nodesVisitor((<PropertyDeclaration>node).modifiers, visitor, isModifier), 398 nodeVisitor((<PropertyDeclaration>node).name, visitor, isPropertyName), 399 // QuestionToken and ExclamationToken is uniqued in Property Declaration and the signature of 'updateProperty' is that too 400 nodeVisitor((<PropertyDeclaration>node).questionToken || (<PropertyDeclaration>node).exclamationToken, tokenVisitor, isToken), 401 nodeVisitor((<PropertyDeclaration>node).type, visitor, isTypeNode), 402 nodeVisitor((<PropertyDeclaration>node).initializer, visitor, isExpression)); 403 404 case SyntaxKind.MethodSignature: 405 return factory.updateMethodSignature(<MethodSignature>node, 406 nodesVisitor((<ParameterDeclaration>node).modifiers, visitor, isModifier), 407 nodeVisitor((<MethodSignature>node).name, visitor, isPropertyName), 408 nodeVisitor((<MethodSignature>node).questionToken, tokenVisitor, isToken), 409 nodesVisitor((<MethodSignature>node).typeParameters, visitor, isTypeParameterDeclaration), 410 nodesVisitor((<MethodSignature>node).parameters, visitor, isParameterDeclaration), 411 nodeVisitor((<MethodSignature>node).type, visitor, isTypeNode)); 412 413 case SyntaxKind.MethodDeclaration: 414 return factory.updateMethodDeclaration(<MethodDeclaration>node, 415 nodesVisitor((<MethodDeclaration>node).decorators, visitor, isDecorator), 416 nodesVisitor((<MethodDeclaration>node).modifiers, visitor, isModifier), 417 nodeVisitor((<MethodDeclaration>node).asteriskToken, tokenVisitor, isToken), 418 nodeVisitor((<MethodDeclaration>node).name, visitor, isPropertyName), 419 nodeVisitor((<MethodDeclaration>node).questionToken, tokenVisitor, isToken), 420 nodesVisitor((<MethodDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration), 421 visitParameterList((<MethodDeclaration>node).parameters, visitor, context, nodesVisitor), 422 nodeVisitor((<MethodDeclaration>node).type, visitor, isTypeNode), 423 visitFunctionBody((<MethodDeclaration>node).body!, visitor, context, nodeVisitor)); 424 425 case SyntaxKind.Constructor: 426 return factory.updateConstructorDeclaration(<ConstructorDeclaration>node, 427 nodesVisitor((<ConstructorDeclaration>node).decorators, visitor, isDecorator), 428 nodesVisitor((<ConstructorDeclaration>node).modifiers, visitor, isModifier), 429 visitParameterList((<ConstructorDeclaration>node).parameters, visitor, context, nodesVisitor), 430 visitFunctionBody((<ConstructorDeclaration>node).body!, visitor, context, nodeVisitor)); 431 432 case SyntaxKind.GetAccessor: 433 return factory.updateGetAccessorDeclaration(<GetAccessorDeclaration>node, 434 nodesVisitor((<GetAccessorDeclaration>node).decorators, visitor, isDecorator), 435 nodesVisitor((<GetAccessorDeclaration>node).modifiers, visitor, isModifier), 436 nodeVisitor((<GetAccessorDeclaration>node).name, visitor, isPropertyName), 437 visitParameterList((<GetAccessorDeclaration>node).parameters, visitor, context, nodesVisitor), 438 nodeVisitor((<GetAccessorDeclaration>node).type, visitor, isTypeNode), 439 visitFunctionBody((<GetAccessorDeclaration>node).body!, visitor, context, nodeVisitor)); 440 441 case SyntaxKind.SetAccessor: 442 return factory.updateSetAccessorDeclaration(<SetAccessorDeclaration>node, 443 nodesVisitor((<SetAccessorDeclaration>node).decorators, visitor, isDecorator), 444 nodesVisitor((<SetAccessorDeclaration>node).modifiers, visitor, isModifier), 445 nodeVisitor((<SetAccessorDeclaration>node).name, visitor, isPropertyName), 446 visitParameterList((<SetAccessorDeclaration>node).parameters, visitor, context, nodesVisitor), 447 visitFunctionBody((<SetAccessorDeclaration>node).body!, visitor, context, nodeVisitor)); 448 449 case SyntaxKind.CallSignature: 450 return factory.updateCallSignature(<CallSignatureDeclaration>node, 451 nodesVisitor((<CallSignatureDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration), 452 nodesVisitor((<CallSignatureDeclaration>node).parameters, visitor, isParameterDeclaration), 453 nodeVisitor((<CallSignatureDeclaration>node).type, visitor, isTypeNode)); 454 455 case SyntaxKind.ConstructSignature: 456 return factory.updateConstructSignature(<ConstructSignatureDeclaration>node, 457 nodesVisitor((<ConstructSignatureDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration), 458 nodesVisitor((<ConstructSignatureDeclaration>node).parameters, visitor, isParameterDeclaration), 459 nodeVisitor((<ConstructSignatureDeclaration>node).type, visitor, isTypeNode)); 460 461 case SyntaxKind.IndexSignature: 462 return factory.updateIndexSignature(<IndexSignatureDeclaration>node, 463 nodesVisitor((<IndexSignatureDeclaration>node).decorators, visitor, isDecorator), 464 nodesVisitor((<IndexSignatureDeclaration>node).modifiers, visitor, isModifier), 465 nodesVisitor((<IndexSignatureDeclaration>node).parameters, visitor, isParameterDeclaration), 466 nodeVisitor((<IndexSignatureDeclaration>node).type, visitor, isTypeNode)); 467 468 // Types 469 case SyntaxKind.TypePredicate: 470 return factory.updateTypePredicateNode(<TypePredicateNode>node, 471 nodeVisitor((<TypePredicateNode>node).assertsModifier, visitor), 472 nodeVisitor((<TypePredicateNode>node).parameterName, visitor), 473 nodeVisitor((<TypePredicateNode>node).type, visitor, isTypeNode)); 474 475 case SyntaxKind.TypeReference: 476 return factory.updateTypeReferenceNode(<TypeReferenceNode>node, 477 nodeVisitor((<TypeReferenceNode>node).typeName, visitor, isEntityName), 478 nodesVisitor((<TypeReferenceNode>node).typeArguments, visitor, isTypeNode)); 479 480 case SyntaxKind.FunctionType: 481 return factory.updateFunctionTypeNode(<FunctionTypeNode>node, 482 nodesVisitor((<FunctionTypeNode>node).typeParameters, visitor, isTypeParameterDeclaration), 483 nodesVisitor((<FunctionTypeNode>node).parameters, visitor, isParameterDeclaration), 484 nodeVisitor((<FunctionTypeNode>node).type, visitor, isTypeNode)); 485 486 case SyntaxKind.ConstructorType: 487 return factory.updateConstructorTypeNode(<ConstructorTypeNode>node, 488 nodesVisitor((<ConstructorTypeNode>node).modifiers, visitor, isModifier), 489 nodesVisitor((<ConstructorTypeNode>node).typeParameters, visitor, isTypeParameterDeclaration), 490 nodesVisitor((<ConstructorTypeNode>node).parameters, visitor, isParameterDeclaration), 491 nodeVisitor((<ConstructorTypeNode>node).type, visitor, isTypeNode)); 492 493 case SyntaxKind.TypeQuery: 494 return factory.updateTypeQueryNode((<TypeQueryNode>node), 495 nodeVisitor((<TypeQueryNode>node).exprName, visitor, isEntityName)); 496 497 case SyntaxKind.TypeLiteral: 498 return factory.updateTypeLiteralNode((<TypeLiteralNode>node), 499 nodesVisitor((<TypeLiteralNode>node).members, visitor, isTypeElement)); 500 501 case SyntaxKind.ArrayType: 502 return factory.updateArrayTypeNode(<ArrayTypeNode>node, 503 nodeVisitor((<ArrayTypeNode>node).elementType, visitor, isTypeNode)); 504 505 case SyntaxKind.TupleType: 506 return factory.updateTupleTypeNode((<TupleTypeNode>node), 507 nodesVisitor((<TupleTypeNode>node).elements, visitor, isTypeNode)); 508 509 case SyntaxKind.OptionalType: 510 return factory.updateOptionalTypeNode((<OptionalTypeNode>node), 511 nodeVisitor((<OptionalTypeNode>node).type, visitor, isTypeNode)); 512 513 case SyntaxKind.RestType: 514 return factory.updateRestTypeNode((<RestTypeNode>node), 515 nodeVisitor((<RestTypeNode>node).type, visitor, isTypeNode)); 516 517 case SyntaxKind.UnionType: 518 return factory.updateUnionTypeNode(<UnionTypeNode>node, 519 nodesVisitor((<UnionTypeNode>node).types, visitor, isTypeNode)); 520 521 case SyntaxKind.IntersectionType: 522 return factory.updateIntersectionTypeNode(<IntersectionTypeNode>node, 523 nodesVisitor((<IntersectionTypeNode>node).types, visitor, isTypeNode)); 524 525 case SyntaxKind.ConditionalType: 526 return factory.updateConditionalTypeNode(<ConditionalTypeNode>node, 527 nodeVisitor((<ConditionalTypeNode>node).checkType, visitor, isTypeNode), 528 nodeVisitor((<ConditionalTypeNode>node).extendsType, visitor, isTypeNode), 529 nodeVisitor((<ConditionalTypeNode>node).trueType, visitor, isTypeNode), 530 nodeVisitor((<ConditionalTypeNode>node).falseType, visitor, isTypeNode)); 531 532 case SyntaxKind.InferType: 533 return factory.updateInferTypeNode(<InferTypeNode>node, 534 nodeVisitor((<InferTypeNode>node).typeParameter, visitor, isTypeParameterDeclaration)); 535 536 case SyntaxKind.ImportType: 537 return factory.updateImportTypeNode(<ImportTypeNode>node, 538 nodeVisitor((<ImportTypeNode>node).argument, visitor, isTypeNode), 539 nodeVisitor((<ImportTypeNode>node).qualifier, visitor, isEntityName), 540 visitNodes((<ImportTypeNode>node).typeArguments, visitor, isTypeNode), 541 (<ImportTypeNode>node).isTypeOf 542 ); 543 544 case SyntaxKind.NamedTupleMember: 545 return factory.updateNamedTupleMember(<NamedTupleMember>node, 546 visitNode((<NamedTupleMember>node).dotDotDotToken, visitor, isToken), 547 visitNode((<NamedTupleMember>node).name, visitor, isIdentifier), 548 visitNode((<NamedTupleMember>node).questionToken, visitor, isToken), 549 visitNode((<NamedTupleMember>node).type, visitor, isTypeNode), 550 ); 551 552 case SyntaxKind.ParenthesizedType: 553 return factory.updateParenthesizedType(<ParenthesizedTypeNode>node, 554 nodeVisitor((<ParenthesizedTypeNode>node).type, visitor, isTypeNode)); 555 556 case SyntaxKind.TypeOperator: 557 return factory.updateTypeOperatorNode(<TypeOperatorNode>node, 558 nodeVisitor((<TypeOperatorNode>node).type, visitor, isTypeNode)); 559 560 case SyntaxKind.IndexedAccessType: 561 return factory.updateIndexedAccessTypeNode((<IndexedAccessTypeNode>node), 562 nodeVisitor((<IndexedAccessTypeNode>node).objectType, visitor, isTypeNode), 563 nodeVisitor((<IndexedAccessTypeNode>node).indexType, visitor, isTypeNode)); 564 565 case SyntaxKind.MappedType: 566 return factory.updateMappedTypeNode((<MappedTypeNode>node), 567 nodeVisitor((<MappedTypeNode>node).readonlyToken, tokenVisitor, isToken), 568 nodeVisitor((<MappedTypeNode>node).typeParameter, visitor, isTypeParameterDeclaration), 569 nodeVisitor((<MappedTypeNode>node).nameType, visitor, isTypeNode), 570 nodeVisitor((<MappedTypeNode>node).questionToken, tokenVisitor, isToken), 571 nodeVisitor((<MappedTypeNode>node).type, visitor, isTypeNode)); 572 573 case SyntaxKind.LiteralType: 574 return factory.updateLiteralTypeNode(<LiteralTypeNode>node, 575 nodeVisitor((<LiteralTypeNode>node).literal, visitor, isExpression)); 576 577 case SyntaxKind.TemplateLiteralType: 578 return factory.updateTemplateLiteralType(<TemplateLiteralTypeNode>node, 579 nodeVisitor((<TemplateLiteralTypeNode>node).head, visitor, isTemplateHead), 580 nodesVisitor((<TemplateLiteralTypeNode>node).templateSpans, visitor, isTemplateLiteralTypeSpan)); 581 582 case SyntaxKind.TemplateLiteralTypeSpan: 583 return factory.updateTemplateLiteralTypeSpan(<TemplateLiteralTypeSpan>node, 584 nodeVisitor((<TemplateLiteralTypeSpan>node).type, visitor, isTypeNode), 585 nodeVisitor((<TemplateLiteralTypeSpan>node).literal, visitor, isTemplateMiddleOrTemplateTail)); 586 587 // Binding patterns 588 case SyntaxKind.ObjectBindingPattern: 589 return factory.updateObjectBindingPattern(<ObjectBindingPattern>node, 590 nodesVisitor((<ObjectBindingPattern>node).elements, visitor, isBindingElement)); 591 592 case SyntaxKind.ArrayBindingPattern: 593 return factory.updateArrayBindingPattern(<ArrayBindingPattern>node, 594 nodesVisitor((<ArrayBindingPattern>node).elements, visitor, isArrayBindingElement)); 595 596 case SyntaxKind.BindingElement: 597 return factory.updateBindingElement(<BindingElement>node, 598 nodeVisitor((<BindingElement>node).dotDotDotToken, tokenVisitor, isToken), 599 nodeVisitor((<BindingElement>node).propertyName, visitor, isPropertyName), 600 nodeVisitor((<BindingElement>node).name, visitor, isBindingName), 601 nodeVisitor((<BindingElement>node).initializer, visitor, isExpression)); 602 603 // Expression 604 case SyntaxKind.ArrayLiteralExpression: 605 return factory.updateArrayLiteralExpression(<ArrayLiteralExpression>node, 606 nodesVisitor((<ArrayLiteralExpression>node).elements, visitor, isExpression)); 607 608 case SyntaxKind.ObjectLiteralExpression: 609 return factory.updateObjectLiteralExpression(<ObjectLiteralExpression>node, 610 nodesVisitor((<ObjectLiteralExpression>node).properties, visitor, isObjectLiteralElementLike)); 611 612 case SyntaxKind.PropertyAccessExpression: 613 if (node.flags & NodeFlags.OptionalChain) { 614 return factory.updatePropertyAccessChain(<PropertyAccessChain>node, 615 nodeVisitor((<PropertyAccessChain>node).expression, visitor, isExpression), 616 nodeVisitor((<PropertyAccessChain>node).questionDotToken, tokenVisitor, isToken), 617 nodeVisitor((<PropertyAccessChain>node).name, visitor, isIdentifier)); 618 } 619 return factory.updatePropertyAccessExpression(<PropertyAccessExpression>node, 620 nodeVisitor((<PropertyAccessExpression>node).expression, visitor, isExpression), 621 nodeVisitor((<PropertyAccessExpression>node).name, visitor, isIdentifierOrPrivateIdentifier)); 622 623 case SyntaxKind.ElementAccessExpression: 624 if (node.flags & NodeFlags.OptionalChain) { 625 return factory.updateElementAccessChain(<ElementAccessChain>node, 626 nodeVisitor((<ElementAccessChain>node).expression, visitor, isExpression), 627 nodeVisitor((<ElementAccessChain>node).questionDotToken, tokenVisitor, isToken), 628 nodeVisitor((<ElementAccessChain>node).argumentExpression, visitor, isExpression)); 629 } 630 return factory.updateElementAccessExpression(<ElementAccessExpression>node, 631 nodeVisitor((<ElementAccessExpression>node).expression, visitor, isExpression), 632 nodeVisitor((<ElementAccessExpression>node).argumentExpression, visitor, isExpression)); 633 634 case SyntaxKind.CallExpression: 635 if (node.flags & NodeFlags.OptionalChain) { 636 return factory.updateCallChain(<CallChain>node, 637 nodeVisitor((<CallChain>node).expression, visitor, isExpression), 638 nodeVisitor((<CallChain>node).questionDotToken, tokenVisitor, isToken), 639 nodesVisitor((<CallChain>node).typeArguments, visitor, isTypeNode), 640 nodesVisitor((<CallChain>node).arguments, visitor, isExpression)); 641 } 642 return factory.updateCallExpression(<CallExpression>node, 643 nodeVisitor((<CallExpression>node).expression, visitor, isExpression), 644 nodesVisitor((<CallExpression>node).typeArguments, visitor, isTypeNode), 645 nodesVisitor((<CallExpression>node).arguments, visitor, isExpression)); 646 647 case SyntaxKind.NewExpression: 648 return factory.updateNewExpression(<NewExpression>node, 649 nodeVisitor((<NewExpression>node).expression, visitor, isExpression), 650 nodesVisitor((<NewExpression>node).typeArguments, visitor, isTypeNode), 651 nodesVisitor((<NewExpression>node).arguments, visitor, isExpression)); 652 653 case SyntaxKind.TaggedTemplateExpression: 654 return factory.updateTaggedTemplateExpression(<TaggedTemplateExpression>node, 655 nodeVisitor((<TaggedTemplateExpression>node).tag, visitor, isExpression), 656 visitNodes((<TaggedTemplateExpression>node).typeArguments, visitor, isExpression), 657 nodeVisitor((<TaggedTemplateExpression>node).template, visitor, isTemplateLiteral)); 658 659 case SyntaxKind.TypeAssertionExpression: 660 return factory.updateTypeAssertion(<TypeAssertion>node, 661 nodeVisitor((<TypeAssertion>node).type, visitor, isTypeNode), 662 nodeVisitor((<TypeAssertion>node).expression, visitor, isExpression)); 663 664 case SyntaxKind.ParenthesizedExpression: 665 return factory.updateParenthesizedExpression(<ParenthesizedExpression>node, 666 nodeVisitor((<ParenthesizedExpression>node).expression, visitor, isExpression)); 667 668 case SyntaxKind.FunctionExpression: 669 return factory.updateFunctionExpression(<FunctionExpression>node, 670 nodesVisitor((<FunctionExpression>node).modifiers, visitor, isModifier), 671 nodeVisitor((<FunctionExpression>node).asteriskToken, tokenVisitor, isToken), 672 nodeVisitor((<FunctionExpression>node).name, visitor, isIdentifier), 673 nodesVisitor((<FunctionExpression>node).typeParameters, visitor, isTypeParameterDeclaration), 674 visitParameterList((<FunctionExpression>node).parameters, visitor, context, nodesVisitor), 675 nodeVisitor((<FunctionExpression>node).type, visitor, isTypeNode), 676 visitFunctionBody((<FunctionExpression>node).body, visitor, context, nodeVisitor)); 677 678 case SyntaxKind.ArrowFunction: 679 return factory.updateArrowFunction(<ArrowFunction>node, 680 nodesVisitor((<ArrowFunction>node).modifiers, visitor, isModifier), 681 nodesVisitor((<ArrowFunction>node).typeParameters, visitor, isTypeParameterDeclaration), 682 visitParameterList((<ArrowFunction>node).parameters, visitor, context, nodesVisitor), 683 nodeVisitor((<ArrowFunction>node).type, visitor, isTypeNode), 684 nodeVisitor((<ArrowFunction>node).equalsGreaterThanToken, tokenVisitor, isToken), 685 visitFunctionBody((<ArrowFunction>node).body, visitor, context, nodeVisitor)); 686 687 case SyntaxKind.DeleteExpression: 688 return factory.updateDeleteExpression(<DeleteExpression>node, 689 nodeVisitor((<DeleteExpression>node).expression, visitor, isExpression)); 690 691 case SyntaxKind.TypeOfExpression: 692 return factory.updateTypeOfExpression(<TypeOfExpression>node, 693 nodeVisitor((<TypeOfExpression>node).expression, visitor, isExpression)); 694 695 case SyntaxKind.VoidExpression: 696 return factory.updateVoidExpression(<VoidExpression>node, 697 nodeVisitor((<VoidExpression>node).expression, visitor, isExpression)); 698 699 case SyntaxKind.AwaitExpression: 700 return factory.updateAwaitExpression(<AwaitExpression>node, 701 nodeVisitor((<AwaitExpression>node).expression, visitor, isExpression)); 702 703 case SyntaxKind.PrefixUnaryExpression: 704 return factory.updatePrefixUnaryExpression(<PrefixUnaryExpression>node, 705 nodeVisitor((<PrefixUnaryExpression>node).operand, visitor, isExpression)); 706 707 case SyntaxKind.PostfixUnaryExpression: 708 return factory.updatePostfixUnaryExpression(<PostfixUnaryExpression>node, 709 nodeVisitor((<PostfixUnaryExpression>node).operand, visitor, isExpression)); 710 711 case SyntaxKind.BinaryExpression: 712 return factory.updateBinaryExpression(<BinaryExpression>node, 713 nodeVisitor((<BinaryExpression>node).left, visitor, isExpression), 714 nodeVisitor((<BinaryExpression>node).operatorToken, tokenVisitor, isToken), 715 nodeVisitor((<BinaryExpression>node).right, visitor, isExpression)); 716 717 case SyntaxKind.ConditionalExpression: 718 return factory.updateConditionalExpression(<ConditionalExpression>node, 719 nodeVisitor((<ConditionalExpression>node).condition, visitor, isExpression), 720 nodeVisitor((<ConditionalExpression>node).questionToken, tokenVisitor, isToken), 721 nodeVisitor((<ConditionalExpression>node).whenTrue, visitor, isExpression), 722 nodeVisitor((<ConditionalExpression>node).colonToken, tokenVisitor, isToken), 723 nodeVisitor((<ConditionalExpression>node).whenFalse, visitor, isExpression)); 724 725 case SyntaxKind.TemplateExpression: 726 return factory.updateTemplateExpression(<TemplateExpression>node, 727 nodeVisitor((<TemplateExpression>node).head, visitor, isTemplateHead), 728 nodesVisitor((<TemplateExpression>node).templateSpans, visitor, isTemplateSpan)); 729 730 case SyntaxKind.YieldExpression: 731 return factory.updateYieldExpression(<YieldExpression>node, 732 nodeVisitor((<YieldExpression>node).asteriskToken, tokenVisitor, isToken), 733 nodeVisitor((<YieldExpression>node).expression, visitor, isExpression)); 734 735 case SyntaxKind.SpreadElement: 736 return factory.updateSpreadElement(<SpreadElement>node, 737 nodeVisitor((<SpreadElement>node).expression, visitor, isExpression)); 738 739 case SyntaxKind.ClassExpression: 740 return factory.updateClassExpression(<ClassExpression>node, 741 nodesVisitor((<ClassExpression>node).decorators, visitor, isDecorator), 742 nodesVisitor((<ClassExpression>node).modifiers, visitor, isModifier), 743 nodeVisitor((<ClassExpression>node).name, visitor, isIdentifier), 744 nodesVisitor((<ClassExpression>node).typeParameters, visitor, isTypeParameterDeclaration), 745 nodesVisitor((<ClassExpression>node).heritageClauses, visitor, isHeritageClause), 746 nodesVisitor((<ClassExpression>node).members, visitor, isClassElement)); 747 748 case SyntaxKind.ExpressionWithTypeArguments: 749 return factory.updateExpressionWithTypeArguments(<ExpressionWithTypeArguments>node, 750 nodeVisitor((<ExpressionWithTypeArguments>node).expression, visitor, isExpression), 751 nodesVisitor((<ExpressionWithTypeArguments>node).typeArguments, visitor, isTypeNode)); 752 753 case SyntaxKind.AsExpression: 754 return factory.updateAsExpression(<AsExpression>node, 755 nodeVisitor((<AsExpression>node).expression, visitor, isExpression), 756 nodeVisitor((<AsExpression>node).type, visitor, isTypeNode)); 757 758 case SyntaxKind.NonNullExpression: 759 if (node.flags & NodeFlags.OptionalChain) { 760 return factory.updateNonNullChain(<NonNullChain>node, 761 nodeVisitor((<NonNullChain>node).expression, visitor, isExpression)); 762 } 763 return factory.updateNonNullExpression(<NonNullExpression>node, 764 nodeVisitor((<NonNullExpression>node).expression, visitor, isExpression)); 765 766 case SyntaxKind.MetaProperty: 767 return factory.updateMetaProperty(<MetaProperty>node, 768 nodeVisitor((<MetaProperty>node).name, visitor, isIdentifier)); 769 770 // Misc 771 case SyntaxKind.TemplateSpan: 772 return factory.updateTemplateSpan(<TemplateSpan>node, 773 nodeVisitor((<TemplateSpan>node).expression, visitor, isExpression), 774 nodeVisitor((<TemplateSpan>node).literal, visitor, isTemplateMiddleOrTemplateTail)); 775 776 // Element 777 case SyntaxKind.Block: 778 return factory.updateBlock(<Block>node, 779 nodesVisitor((<Block>node).statements, visitor, isStatement)); 780 781 case SyntaxKind.VariableStatement: 782 return factory.updateVariableStatement(<VariableStatement>node, 783 nodesVisitor((<VariableStatement>node).modifiers, visitor, isModifier), 784 nodeVisitor((<VariableStatement>node).declarationList, visitor, isVariableDeclarationList)); 785 786 case SyntaxKind.ExpressionStatement: 787 return factory.updateExpressionStatement(<ExpressionStatement>node, 788 nodeVisitor((<ExpressionStatement>node).expression, visitor, isExpression)); 789 790 case SyntaxKind.IfStatement: 791 return factory.updateIfStatement(<IfStatement>node, 792 nodeVisitor((<IfStatement>node).expression, visitor, isExpression), 793 nodeVisitor((<IfStatement>node).thenStatement, visitor, isStatement, factory.liftToBlock), 794 nodeVisitor((<IfStatement>node).elseStatement, visitor, isStatement, factory.liftToBlock)); 795 796 case SyntaxKind.DoStatement: 797 return factory.updateDoStatement(<DoStatement>node, 798 nodeVisitor((<DoStatement>node).statement, visitor, isStatement, factory.liftToBlock), 799 nodeVisitor((<DoStatement>node).expression, visitor, isExpression)); 800 801 case SyntaxKind.WhileStatement: 802 return factory.updateWhileStatement(<WhileStatement>node, 803 nodeVisitor((<WhileStatement>node).expression, visitor, isExpression), 804 nodeVisitor((<WhileStatement>node).statement, visitor, isStatement, factory.liftToBlock)); 805 806 case SyntaxKind.ForStatement: 807 return factory.updateForStatement(<ForStatement>node, 808 nodeVisitor((<ForStatement>node).initializer, visitor, isForInitializer), 809 nodeVisitor((<ForStatement>node).condition, visitor, isExpression), 810 nodeVisitor((<ForStatement>node).incrementor, visitor, isExpression), 811 nodeVisitor((<ForStatement>node).statement, visitor, isStatement, factory.liftToBlock)); 812 813 case SyntaxKind.ForInStatement: 814 return factory.updateForInStatement(<ForInStatement>node, 815 nodeVisitor((<ForInStatement>node).initializer, visitor, isForInitializer), 816 nodeVisitor((<ForInStatement>node).expression, visitor, isExpression), 817 nodeVisitor((<ForInStatement>node).statement, visitor, isStatement, factory.liftToBlock)); 818 819 case SyntaxKind.ForOfStatement: 820 return factory.updateForOfStatement(<ForOfStatement>node, 821 nodeVisitor((<ForOfStatement>node).awaitModifier, tokenVisitor, isToken), 822 nodeVisitor((<ForOfStatement>node).initializer, visitor, isForInitializer), 823 nodeVisitor((<ForOfStatement>node).expression, visitor, isExpression), 824 nodeVisitor((<ForOfStatement>node).statement, visitor, isStatement, factory.liftToBlock)); 825 826 case SyntaxKind.ContinueStatement: 827 return factory.updateContinueStatement(<ContinueStatement>node, 828 nodeVisitor((<ContinueStatement>node).label, visitor, isIdentifier)); 829 830 case SyntaxKind.BreakStatement: 831 return factory.updateBreakStatement(<BreakStatement>node, 832 nodeVisitor((<BreakStatement>node).label, visitor, isIdentifier)); 833 834 case SyntaxKind.ReturnStatement: 835 return factory.updateReturnStatement(<ReturnStatement>node, 836 nodeVisitor((<ReturnStatement>node).expression, visitor, isExpression)); 837 838 case SyntaxKind.WithStatement: 839 return factory.updateWithStatement(<WithStatement>node, 840 nodeVisitor((<WithStatement>node).expression, visitor, isExpression), 841 nodeVisitor((<WithStatement>node).statement, visitor, isStatement, factory.liftToBlock)); 842 843 case SyntaxKind.SwitchStatement: 844 return factory.updateSwitchStatement(<SwitchStatement>node, 845 nodeVisitor((<SwitchStatement>node).expression, visitor, isExpression), 846 nodeVisitor((<SwitchStatement>node).caseBlock, visitor, isCaseBlock)); 847 848 case SyntaxKind.LabeledStatement: 849 return factory.updateLabeledStatement(<LabeledStatement>node, 850 nodeVisitor((<LabeledStatement>node).label, visitor, isIdentifier), 851 nodeVisitor((<LabeledStatement>node).statement, visitor, isStatement, factory.liftToBlock)); 852 853 case SyntaxKind.ThrowStatement: 854 return factory.updateThrowStatement(<ThrowStatement>node, 855 nodeVisitor((<ThrowStatement>node).expression, visitor, isExpression)); 856 857 case SyntaxKind.TryStatement: 858 return factory.updateTryStatement(<TryStatement>node, 859 nodeVisitor((<TryStatement>node).tryBlock, visitor, isBlock), 860 nodeVisitor((<TryStatement>node).catchClause, visitor, isCatchClause), 861 nodeVisitor((<TryStatement>node).finallyBlock, visitor, isBlock)); 862 863 case SyntaxKind.VariableDeclaration: 864 return factory.updateVariableDeclaration(<VariableDeclaration>node, 865 nodeVisitor((<VariableDeclaration>node).name, visitor, isBindingName), 866 nodeVisitor((<VariableDeclaration>node).exclamationToken, tokenVisitor, isToken), 867 nodeVisitor((<VariableDeclaration>node).type, visitor, isTypeNode), 868 nodeVisitor((<VariableDeclaration>node).initializer, visitor, isExpression)); 869 870 case SyntaxKind.VariableDeclarationList: 871 return factory.updateVariableDeclarationList(<VariableDeclarationList>node, 872 nodesVisitor((<VariableDeclarationList>node).declarations, visitor, isVariableDeclaration)); 873 874 case SyntaxKind.FunctionDeclaration: 875 return factory.updateFunctionDeclaration(<FunctionDeclaration>node, 876 nodesVisitor((<FunctionDeclaration>node).decorators, visitor, isDecorator), 877 nodesVisitor((<FunctionDeclaration>node).modifiers, visitor, isModifier), 878 nodeVisitor((<FunctionDeclaration>node).asteriskToken, tokenVisitor, isToken), 879 nodeVisitor((<FunctionDeclaration>node).name, visitor, isIdentifier), 880 nodesVisitor((<FunctionDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration), 881 visitParameterList((<FunctionDeclaration>node).parameters, visitor, context, nodesVisitor), 882 nodeVisitor((<FunctionDeclaration>node).type, visitor, isTypeNode), 883 visitFunctionBody((<FunctionExpression>node).body, visitor, context, nodeVisitor)); 884 885 case SyntaxKind.ClassDeclaration: 886 return factory.updateClassDeclaration(<ClassDeclaration>node, 887 nodesVisitor((<ClassDeclaration>node).decorators, visitor, isDecorator), 888 nodesVisitor((<ClassDeclaration>node).modifiers, visitor, isModifier), 889 nodeVisitor((<ClassDeclaration>node).name, visitor, isIdentifier), 890 nodesVisitor((<ClassDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration), 891 nodesVisitor((<ClassDeclaration>node).heritageClauses, visitor, isHeritageClause), 892 nodesVisitor((<ClassDeclaration>node).members, visitor, isClassElement)); 893 894 case SyntaxKind.StructDeclaration: 895 return factory.updateStructDeclaration(<StructDeclaration>node, 896 nodesVisitor((<StructDeclaration>node).decorators, visitor, isDecorator), 897 nodesVisitor((<StructDeclaration>node).modifiers, visitor, isModifier), 898 nodeVisitor((<StructDeclaration>node).name, visitor, isIdentifier), 899 nodesVisitor((<StructDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration), 900 nodesVisitor((<StructDeclaration>node).heritageClauses, visitor, isHeritageClause), 901 nodesVisitor((<StructDeclaration>node).members, visitor, isClassElement)); 902 903 case SyntaxKind.InterfaceDeclaration: 904 return factory.updateInterfaceDeclaration(<InterfaceDeclaration>node, 905 nodesVisitor((<InterfaceDeclaration>node).decorators, visitor, isDecorator), 906 nodesVisitor((<InterfaceDeclaration>node).modifiers, visitor, isModifier), 907 nodeVisitor((<InterfaceDeclaration>node).name, visitor, isIdentifier), 908 nodesVisitor((<InterfaceDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration), 909 nodesVisitor((<InterfaceDeclaration>node).heritageClauses, visitor, isHeritageClause), 910 nodesVisitor((<InterfaceDeclaration>node).members, visitor, isTypeElement)); 911 912 case SyntaxKind.TypeAliasDeclaration: 913 return factory.updateTypeAliasDeclaration(<TypeAliasDeclaration>node, 914 nodesVisitor((<TypeAliasDeclaration>node).decorators, visitor, isDecorator), 915 nodesVisitor((<TypeAliasDeclaration>node).modifiers, visitor, isModifier), 916 nodeVisitor((<TypeAliasDeclaration>node).name, visitor, isIdentifier), 917 nodesVisitor((<TypeAliasDeclaration>node).typeParameters, visitor, isTypeParameterDeclaration), 918 nodeVisitor((<TypeAliasDeclaration>node).type, visitor, isTypeNode)); 919 920 case SyntaxKind.EnumDeclaration: 921 return factory.updateEnumDeclaration(<EnumDeclaration>node, 922 nodesVisitor((<EnumDeclaration>node).decorators, visitor, isDecorator), 923 nodesVisitor((<EnumDeclaration>node).modifiers, visitor, isModifier), 924 nodeVisitor((<EnumDeclaration>node).name, visitor, isIdentifier), 925 nodesVisitor((<EnumDeclaration>node).members, visitor, isEnumMember)); 926 927 case SyntaxKind.ModuleDeclaration: 928 return factory.updateModuleDeclaration(<ModuleDeclaration>node, 929 nodesVisitor((<ModuleDeclaration>node).decorators, visitor, isDecorator), 930 nodesVisitor((<ModuleDeclaration>node).modifiers, visitor, isModifier), 931 nodeVisitor((<ModuleDeclaration>node).name, visitor, isIdentifier), 932 nodeVisitor((<ModuleDeclaration>node).body, visitor, isModuleBody)); 933 934 case SyntaxKind.ModuleBlock: 935 return factory.updateModuleBlock(<ModuleBlock>node, 936 nodesVisitor((<ModuleBlock>node).statements, visitor, isStatement)); 937 938 case SyntaxKind.CaseBlock: 939 return factory.updateCaseBlock(<CaseBlock>node, 940 nodesVisitor((<CaseBlock>node).clauses, visitor, isCaseOrDefaultClause)); 941 942 case SyntaxKind.NamespaceExportDeclaration: 943 return factory.updateNamespaceExportDeclaration(<NamespaceExportDeclaration>node, 944 nodeVisitor((<NamespaceExportDeclaration>node).name, visitor, isIdentifier)); 945 946 case SyntaxKind.ImportEqualsDeclaration: 947 return factory.updateImportEqualsDeclaration(<ImportEqualsDeclaration>node, 948 nodesVisitor((<ImportEqualsDeclaration>node).decorators, visitor, isDecorator), 949 nodesVisitor((<ImportEqualsDeclaration>node).modifiers, visitor, isModifier), 950 (<ImportEqualsDeclaration>node).isTypeOnly, 951 nodeVisitor((<ImportEqualsDeclaration>node).name, visitor, isIdentifier), 952 nodeVisitor((<ImportEqualsDeclaration>node).moduleReference, visitor, isModuleReference)); 953 954 case SyntaxKind.ImportDeclaration: 955 return factory.updateImportDeclaration(<ImportDeclaration>node, 956 nodesVisitor((<ImportDeclaration>node).decorators, visitor, isDecorator), 957 nodesVisitor((<ImportDeclaration>node).modifiers, visitor, isModifier), 958 nodeVisitor((<ImportDeclaration>node).importClause, visitor, isImportClause), 959 nodeVisitor((<ImportDeclaration>node).moduleSpecifier, visitor, isExpression)); 960 961 case SyntaxKind.ImportClause: 962 return factory.updateImportClause(<ImportClause>node, 963 (<ImportClause>node).isTypeOnly, 964 nodeVisitor((<ImportClause>node).name, visitor, isIdentifier), 965 nodeVisitor((<ImportClause>node).namedBindings, visitor, isNamedImportBindings)); 966 967 case SyntaxKind.NamespaceImport: 968 return factory.updateNamespaceImport(<NamespaceImport>node, 969 nodeVisitor((<NamespaceImport>node).name, visitor, isIdentifier)); 970 971 case SyntaxKind.NamespaceExport: 972 return factory.updateNamespaceExport(<NamespaceExport>node, 973 nodeVisitor((<NamespaceExport>node).name, visitor, isIdentifier)); 974 975 case SyntaxKind.NamedImports: 976 return factory.updateNamedImports(<NamedImports>node, 977 nodesVisitor((<NamedImports>node).elements, visitor, isImportSpecifier)); 978 979 case SyntaxKind.ImportSpecifier: 980 return factory.updateImportSpecifier(<ImportSpecifier>node, 981 nodeVisitor((<ImportSpecifier>node).propertyName, visitor, isIdentifier), 982 nodeVisitor((<ImportSpecifier>node).name, visitor, isIdentifier)); 983 984 case SyntaxKind.ExportAssignment: 985 return factory.updateExportAssignment(<ExportAssignment>node, 986 nodesVisitor((<ExportAssignment>node).decorators, visitor, isDecorator), 987 nodesVisitor((<ExportAssignment>node).modifiers, visitor, isModifier), 988 nodeVisitor((<ExportAssignment>node).expression, visitor, isExpression)); 989 990 case SyntaxKind.ExportDeclaration: 991 return factory.updateExportDeclaration(<ExportDeclaration>node, 992 nodesVisitor((<ExportDeclaration>node).decorators, visitor, isDecorator), 993 nodesVisitor((<ExportDeclaration>node).modifiers, visitor, isModifier), 994 (<ExportDeclaration>node).isTypeOnly, 995 nodeVisitor((<ExportDeclaration>node).exportClause, visitor, isNamedExportBindings), 996 nodeVisitor((<ExportDeclaration>node).moduleSpecifier, visitor, isExpression)); 997 998 case SyntaxKind.NamedExports: 999 return factory.updateNamedExports(<NamedExports>node, 1000 nodesVisitor((<NamedExports>node).elements, visitor, isExportSpecifier)); 1001 1002 case SyntaxKind.ExportSpecifier: 1003 return factory.updateExportSpecifier(<ExportSpecifier>node, 1004 nodeVisitor((<ExportSpecifier>node).propertyName, visitor, isIdentifier), 1005 nodeVisitor((<ExportSpecifier>node).name, visitor, isIdentifier)); 1006 1007 // Module references 1008 case SyntaxKind.ExternalModuleReference: 1009 return factory.updateExternalModuleReference(<ExternalModuleReference>node, 1010 nodeVisitor((<ExternalModuleReference>node).expression, visitor, isExpression)); 1011 1012 // JSX 1013 case SyntaxKind.JsxElement: 1014 return factory.updateJsxElement(<JsxElement>node, 1015 nodeVisitor((<JsxElement>node).openingElement, visitor, isJsxOpeningElement), 1016 nodesVisitor((<JsxElement>node).children, visitor, isJsxChild), 1017 nodeVisitor((<JsxElement>node).closingElement, visitor, isJsxClosingElement)); 1018 1019 case SyntaxKind.JsxSelfClosingElement: 1020 return factory.updateJsxSelfClosingElement(<JsxSelfClosingElement>node, 1021 nodeVisitor((<JsxSelfClosingElement>node).tagName, visitor, isJsxTagNameExpression), 1022 nodesVisitor((<JsxSelfClosingElement>node).typeArguments, visitor, isTypeNode), 1023 nodeVisitor((<JsxSelfClosingElement>node).attributes, visitor, isJsxAttributes)); 1024 1025 case SyntaxKind.JsxOpeningElement: 1026 return factory.updateJsxOpeningElement(<JsxOpeningElement>node, 1027 nodeVisitor((<JsxOpeningElement>node).tagName, visitor, isJsxTagNameExpression), 1028 nodesVisitor((<JsxSelfClosingElement>node).typeArguments, visitor, isTypeNode), 1029 nodeVisitor((<JsxOpeningElement>node).attributes, visitor, isJsxAttributes)); 1030 1031 case SyntaxKind.JsxClosingElement: 1032 return factory.updateJsxClosingElement(<JsxClosingElement>node, 1033 nodeVisitor((<JsxClosingElement>node).tagName, visitor, isJsxTagNameExpression)); 1034 1035 case SyntaxKind.JsxFragment: 1036 return factory.updateJsxFragment(<JsxFragment>node, 1037 nodeVisitor((<JsxFragment>node).openingFragment, visitor, isJsxOpeningFragment), 1038 nodesVisitor((<JsxFragment>node).children, visitor, isJsxChild), 1039 nodeVisitor((<JsxFragment>node).closingFragment, visitor, isJsxClosingFragment)); 1040 1041 case SyntaxKind.JsxAttribute: 1042 return factory.updateJsxAttribute(<JsxAttribute>node, 1043 nodeVisitor((<JsxAttribute>node).name, visitor, isIdentifier), 1044 nodeVisitor((<JsxAttribute>node).initializer, visitor, isStringLiteralOrJsxExpression)); 1045 1046 case SyntaxKind.JsxAttributes: 1047 return factory.updateJsxAttributes(<JsxAttributes>node, 1048 nodesVisitor((<JsxAttributes>node).properties, visitor, isJsxAttributeLike)); 1049 1050 case SyntaxKind.JsxSpreadAttribute: 1051 return factory.updateJsxSpreadAttribute(<JsxSpreadAttribute>node, 1052 nodeVisitor((<JsxSpreadAttribute>node).expression, visitor, isExpression)); 1053 1054 case SyntaxKind.JsxExpression: 1055 return factory.updateJsxExpression(<JsxExpression>node, 1056 nodeVisitor((<JsxExpression>node).expression, visitor, isExpression)); 1057 1058 // Clauses 1059 case SyntaxKind.CaseClause: 1060 return factory.updateCaseClause(<CaseClause>node, 1061 nodeVisitor((<CaseClause>node).expression, visitor, isExpression), 1062 nodesVisitor((<CaseClause>node).statements, visitor, isStatement)); 1063 1064 case SyntaxKind.DefaultClause: 1065 return factory.updateDefaultClause(<DefaultClause>node, 1066 nodesVisitor((<DefaultClause>node).statements, visitor, isStatement)); 1067 1068 case SyntaxKind.HeritageClause: 1069 return factory.updateHeritageClause(<HeritageClause>node, 1070 nodesVisitor((<HeritageClause>node).types, visitor, isExpressionWithTypeArguments)); 1071 1072 case SyntaxKind.CatchClause: 1073 return factory.updateCatchClause(<CatchClause>node, 1074 nodeVisitor((<CatchClause>node).variableDeclaration, visitor, isVariableDeclaration), 1075 nodeVisitor((<CatchClause>node).block, visitor, isBlock)); 1076 1077 // Property assignments 1078 case SyntaxKind.PropertyAssignment: 1079 return factory.updatePropertyAssignment(<PropertyAssignment>node, 1080 nodeVisitor((<PropertyAssignment>node).name, visitor, isPropertyName), 1081 nodeVisitor((<PropertyAssignment>node).initializer, visitor, isExpression)); 1082 1083 case SyntaxKind.ShorthandPropertyAssignment: 1084 return factory.updateShorthandPropertyAssignment(<ShorthandPropertyAssignment>node, 1085 nodeVisitor((<ShorthandPropertyAssignment>node).name, visitor, isIdentifier), 1086 nodeVisitor((<ShorthandPropertyAssignment>node).objectAssignmentInitializer, visitor, isExpression)); 1087 1088 case SyntaxKind.SpreadAssignment: 1089 return factory.updateSpreadAssignment(<SpreadAssignment>node, 1090 nodeVisitor((<SpreadAssignment>node).expression, visitor, isExpression)); 1091 1092 // Enum 1093 case SyntaxKind.EnumMember: 1094 return factory.updateEnumMember(<EnumMember>node, 1095 nodeVisitor((<EnumMember>node).name, visitor, isPropertyName), 1096 nodeVisitor((<EnumMember>node).initializer, visitor, isExpression)); 1097 1098 // Top-level nodes 1099 case SyntaxKind.SourceFile: 1100 return factory.updateSourceFile(<SourceFile>node, 1101 visitLexicalEnvironment((<SourceFile>node).statements, visitor, context)); 1102 1103 // Transformation nodes 1104 case SyntaxKind.PartiallyEmittedExpression: 1105 return factory.updatePartiallyEmittedExpression(<PartiallyEmittedExpression>node, 1106 nodeVisitor((<PartiallyEmittedExpression>node).expression, visitor, isExpression)); 1107 1108 case SyntaxKind.CommaListExpression: 1109 return factory.updateCommaListExpression(<CommaListExpression>node, 1110 nodesVisitor((<CommaListExpression>node).elements, visitor, isExpression)); 1111 1112 default: 1113 // No need to visit nodes with no children. 1114 return node; 1115 } 1116 1117 } 1118 1119 /** 1120 * Extracts the single node from a NodeArray. 1121 * 1122 * @param nodes The NodeArray. 1123 */ 1124 function extractSingleNode(nodes: readonly Node[]): Node | undefined { 1125 Debug.assert(nodes.length <= 1, "Too many nodes written to output."); 1126 return singleOrUndefined(nodes); 1127 } 1128} 1129