Skip to content

Commit 6f5a23d

Browse files
committed
Adds streamlined child visitors for frequently visited nodes.
1 parent e64724e commit 6f5a23d

11 files changed

Lines changed: 914 additions & 132 deletions

File tree

src/compiler/comments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ namespace ts {
329329

330330
function setSourceFile(sourceFile: SourceFile) {
331331
currentSourceFile = sourceFile;
332-
currentText = sourceFile.text;
333-
currentLineMap = getLineStarts(sourceFile);
332+
currentText = currentSourceFile.text;
333+
currentLineMap = getLineStarts(currentSourceFile);
334334
detachedCommentsInfo = undefined;
335335
consumedCommentRanges = {};
336336
leadingCommentRangePositions = {};

src/compiler/factory.ts

Lines changed: 319 additions & 71 deletions
Large diffs are not rendered by default.

src/compiler/sourcemap.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ namespace ts {
701701
*/
702702
function setSourceFile(sourceFile: SourceFile) {
703703
currentSourceFile = sourceFile;
704-
currentSourceText = sourceFile.text;
704+
currentSourceText = currentSourceFile.text;
705705

706706
// Add the file to tsFilePaths
707707
// If sourceroot option: Use the relative path corresponding to the common directory path
@@ -720,10 +720,10 @@ namespace ts {
720720
sourceMapData.sourceMapSources.push(source);
721721

722722
// The one that can be used from program to get the actual source file
723-
sourceMapData.inputSourceFileNames.push(sourceFile.fileName);
723+
sourceMapData.inputSourceFileNames.push(currentSourceFile.fileName);
724724

725725
if (compilerOptions.inlineSources) {
726-
sourceMapData.sourceMapSourcesContent.push(sourceFile.text);
726+
sourceMapData.sourceMapSourcesContent.push(currentSourceFile.text);
727727
}
728728
}
729729
}

src/compiler/transformers/destructuring.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace ts {
9898
return declarations;
9999

100100
function emitAssignment(name: Identifier, value: Expression, location: TextRange) {
101-
const declaration = createVariableDeclaration(name, value, location);
101+
const declaration = createVariableDeclaration(name, /*type*/ undefined, value, location);
102102

103103
// NOTE: this completely disables source maps, but aligns with the behavior of
104104
// `emitAssignment` in the old emitter.
@@ -134,7 +134,7 @@ namespace ts {
134134
return declarations;
135135

136136
function emitAssignment(name: Identifier, value: Expression, location: TextRange, original: Node) {
137-
const declaration = createVariableDeclaration(name, value, location);
137+
const declaration = createVariableDeclaration(name, /*type*/ undefined, value, location);
138138
declaration.original = original;
139139

140140
// NOTE: this completely disables source maps, but aligns with the behavior of

src/compiler/transformers/es6.ts

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ namespace ts {
554554
createVariableDeclarationList([
555555
createVariableDeclaration(
556556
getDeclarationName(node, /*allowComments*/ true),
557+
/*type*/ undefined,
557558
transformClassLikeDeclarationToExpression(node)
558559
)
559560
]),
@@ -621,7 +622,9 @@ namespace ts {
621622
const classFunction = createFunctionExpression(
622623
/*asteriskToken*/ undefined,
623624
/*name*/ undefined,
625+
/*typeParameters*/ undefined,
624626
extendsClauseElement ? [createParameter("_super")] : [],
627+
/*type*/ undefined,
625628
transformClassBody(node, extendsClauseElement)
626629
);
627630

@@ -645,6 +648,7 @@ namespace ts {
645648
return createParen(
646649
createCall(
647650
outer,
651+
/*typeArguments*/ undefined,
648652
extendsClauseElement
649653
? [visitNode(extendsClauseElement.expression, visitor, isExpression)]
650654
: []
@@ -717,10 +721,13 @@ namespace ts {
717721
const hasSynthesizedSuper = hasSynthesizedDefaultSuperCall(constructor, extendsClauseElement !== undefined);
718722
statements.push(
719723
createFunctionDeclaration(
724+
/*decorators*/ undefined,
720725
/*modifiers*/ undefined,
721726
/*asteriskToken*/ undefined,
722727
getDeclarationName(node),
728+
/*typeParameters*/ undefined,
723729
transformConstructorParameters(constructor, hasSynthesizedSuper),
730+
/*type*/ undefined,
724731
transformConstructorBody(constructor, node, extendsClauseElement, hasSynthesizedSuper),
725732
/*location*/ constructor || node
726733
)
@@ -967,10 +974,9 @@ namespace ts {
967974
NodeEmitFlags.SingleLine | NodeEmitFlags.NoTrailingSourceMap | NodeEmitFlags.NoTokenSourceMaps
968975
),
969976
/*elseStatement*/ undefined,
970-
/*location*/ parameter,
971-
{ startOnNewLine: true }
977+
/*location*/ parameter
972978
);
973-
979+
statement.startsOnNewLine = true;
974980
setNodeEmitFlags(statement, NodeEmitFlags.NoTokenSourceMaps | NodeEmitFlags.NoTrailingSourceMap);
975981
statements.push(statement);
976982
}
@@ -1018,6 +1024,7 @@ namespace ts {
10181024
createVariableDeclarationList([
10191025
createVariableDeclaration(
10201026
declarationName,
1027+
/*type*/ undefined,
10211028
createArrayLiteral([])
10221029
)
10231030
]),
@@ -1030,7 +1037,7 @@ namespace ts {
10301037
// }
10311038
const forStatement = createFor(
10321039
createVariableDeclarationList([
1033-
createVariableDeclaration(temp, createLiteral(restIndex))
1040+
createVariableDeclaration(temp, /*type*/ undefined, createLiteral(restIndex))
10341041
], /*location*/ parameter),
10351042
createLessThan(
10361043
temp,
@@ -1073,6 +1080,7 @@ namespace ts {
10731080
createVariableDeclarationList([
10741081
createVariableDeclaration(
10751082
"_this",
1083+
/*type*/ undefined,
10761084
createThis()
10771085
)
10781086
])
@@ -1228,6 +1236,7 @@ namespace ts {
12281236

12291237
return createCall(
12301238
createPropertyAccess(createIdentifier("Object"), "defineProperty"),
1239+
/*typeArguments*/ undefined,
12311240
[
12321241
target,
12331242
propertyName,
@@ -1271,15 +1280,19 @@ namespace ts {
12711280
* @param node a FunctionDeclaration node.
12721281
*/
12731282
function visitFunctionDeclaration(node: FunctionDeclaration): FunctionDeclaration {
1274-
return createFunctionDeclaration(
1275-
/*modifiers*/ undefined,
1276-
node.asteriskToken,
1277-
node.name,
1278-
visitNodes(node.parameters, visitor, isParameter),
1279-
transformFunctionBody(node),
1280-
/*location*/ node,
1281-
/*original*/ node
1282-
);
1283+
return setOriginalNode(
1284+
createFunctionDeclaration(
1285+
/*decorators*/ undefined,
1286+
/*modifiers*/ undefined,
1287+
node.asteriskToken,
1288+
node.name,
1289+
/*typeParameters*/ undefined,
1290+
visitNodes(node.parameters, visitor, isParameter),
1291+
/*type*/ undefined,
1292+
transformFunctionBody(node),
1293+
/*location*/ node
1294+
),
1295+
/*original*/ node);
12831296
}
12841297

12851298
/**
@@ -1295,12 +1308,16 @@ namespace ts {
12951308
containingNonArrowFunction = node;
12961309
}
12971310

1298-
const expression = createFunctionExpression(
1299-
node.asteriskToken,
1300-
name,
1301-
visitNodes(node.parameters, visitor, isParameter),
1302-
saveStateAndInvoke(node, transformFunctionBody),
1303-
location,
1311+
const expression = setOriginalNode(
1312+
createFunctionExpression(
1313+
node.asteriskToken,
1314+
name,
1315+
/*typeParameters*/ undefined,
1316+
visitNodes(node.parameters, visitor, isParameter),
1317+
/*type*/ undefined,
1318+
saveStateAndInvoke(node, transformFunctionBody),
1319+
location
1320+
),
13041321
/*original*/ node
13051322
);
13061323

@@ -1755,6 +1772,7 @@ namespace ts {
17551772
createVariableDeclarationList([
17561773
createVariableDeclaration(
17571774
firstOriginalDeclaration ? firstOriginalDeclaration.name : createTempVariable(/*recordTempVariable*/ undefined),
1775+
/*type*/ undefined,
17581776
createElementAccess(rhsReference, counter)
17591777
)
17601778
], /*location*/ moveRangePos(initializer, -1)),
@@ -1818,8 +1836,8 @@ namespace ts {
18181836

18191837
const forStatement = createFor(
18201838
createVariableDeclarationList([
1821-
createVariableDeclaration(counter, createLiteral(0), /*location*/ moveRangePos(node.expression, -1)),
1822-
createVariableDeclaration(rhsReference, expression, /*location*/ node.expression)
1839+
createVariableDeclaration(counter, /*type*/ undefined, createLiteral(0), /*location*/ moveRangePos(node.expression, -1)),
1840+
createVariableDeclaration(rhsReference, /*type*/ undefined, expression, /*location*/ node.expression)
18231841
], /*location*/ node.expression),
18241842
createLessThan(
18251843
counter,
@@ -1996,11 +2014,14 @@ namespace ts {
19962014
[
19972015
createVariableDeclaration(
19982016
functionName,
2017+
/*type*/ undefined,
19992018
setNodeEmitFlags(
20002019
createFunctionExpression(
20012020
/*asteriskToken*/ undefined,
20022021
/*name*/ undefined,
2022+
/*typeParameters*/ undefined,
20032023
loopParameters,
2024+
/*type*/ undefined,
20042025
<Block>loopBody
20052026
),
20062027
currentState.containsLexicalThis
@@ -2027,6 +2048,7 @@ namespace ts {
20272048
(extraVariableDeclarations || (extraVariableDeclarations = [])).push(
20282049
createVariableDeclaration(
20292050
currentState.argumentsName,
2051+
/*type*/ undefined,
20302052
createIdentifier("arguments")
20312053
)
20322054
);
@@ -2047,8 +2069,9 @@ namespace ts {
20472069
(extraVariableDeclarations || (extraVariableDeclarations = [])).push(
20482070
createVariableDeclaration(
20492071
currentState.thisName,
2072+
/*type*/ undefined,
20502073
createIdentifier("this")
2051-
)
2074+
)
20522075
);
20532076
}
20542077
}
@@ -2140,7 +2163,7 @@ namespace ts {
21402163
!state.labeledNonLocalBreaks &&
21412164
!state.labeledNonLocalContinues;
21422165

2143-
const call = createCall(loopFunctionExpressionName, map(parameters, p => <Identifier>p.name));
2166+
const call = createCall(loopFunctionExpressionName, /*typeArguments*/ undefined, map(parameters, p => <Identifier>p.name));
21442167
if (isSimpleLoop) {
21452168
statements.push(createStatement(call));
21462169
copyOutParameters(state.loopOutParameters, CopyDirection.ToOriginal, statements);
@@ -2150,7 +2173,7 @@ namespace ts {
21502173
const stateVariable = createVariableStatement(
21512174
/*modifiers*/ undefined,
21522175
createVariableDeclarationList(
2153-
[createVariableDeclaration(loopResultName, call)]
2176+
[createVariableDeclaration(loopResultName, /*type*/ undefined, call)]
21542177
)
21552178
);
21562179
statements.push(stateVariable);
@@ -2474,6 +2497,7 @@ namespace ts {
24742497
thisArg,
24752498
transformAndSpreadElements(createNodeArray([createVoidZero(), ...node.arguments]), /*needsUniqueCopy*/ false, /*multiLine*/ false, /*hasTrailingComma*/ false)
24762499
),
2500+
/*typeArguments*/ undefined,
24772501
[]
24782502
);
24792503
}
@@ -2586,7 +2610,7 @@ namespace ts {
25862610
inlineExpressions([
25872611
createAssignment(temp, createArrayLiteral(cookedStrings)),
25882612
createAssignment(createPropertyAccess(temp, "raw"), createArrayLiteral(rawStrings)),
2589-
createCall(tag, templateArguments)
2613+
createCall(tag, /*typeArguments*/ undefined, templateArguments)
25902614
])
25912615
);
25922616
}

src/compiler/transformers/module/module.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ namespace ts {
147147
createStatement(
148148
createCall(
149149
define,
150+
/*typeArguments*/ undefined,
150151
[
151152
// Add the module name (if provided).
152153
...(moduleName ? [moduleName] : []),
@@ -167,11 +168,13 @@ namespace ts {
167168
createFunctionExpression(
168169
/*asteriskToken*/ undefined,
169170
/*name*/ undefined,
171+
/*typeParameters*/ undefined,
170172
[
171173
createParameter("require"),
172174
createParameter("exports"),
173175
...importAliasNames
174176
],
177+
/*type*/ undefined,
175178
transformAsynchronousModuleBody(node)
176179
)
177180
]
@@ -307,6 +310,7 @@ namespace ts {
307310
variables.push(
308311
createVariableDeclaration(
309312
getSynthesizedClone(namespaceDeclaration.name),
313+
/*type*/ undefined,
310314
createRequireCall(node)
311315
)
312316
);
@@ -319,6 +323,7 @@ namespace ts {
319323
variables.push(
320324
createVariableDeclaration(
321325
getGeneratedNameForNode(node),
326+
/*type*/ undefined,
322327
createRequireCall(node)
323328
)
324329
);
@@ -327,6 +332,7 @@ namespace ts {
327332
variables.push(
328333
createVariableDeclaration(
329334
getSynthesizedClone(namespaceDeclaration.name),
335+
/*type*/ undefined,
330336
getGeneratedNameForNode(node)
331337
)
332338
);
@@ -350,6 +356,7 @@ namespace ts {
350356
createVariableDeclarationList([
351357
createVariableDeclaration(
352358
getSynthesizedClone(namespaceDeclaration.name),
359+
/*type*/ undefined,
353360
getGeneratedNameForNode(node),
354361
/*location*/ node
355362
)
@@ -390,6 +397,7 @@ namespace ts {
390397
createVariableDeclarationList([
391398
createVariableDeclaration(
392399
getSynthesizedClone(node.name),
400+
/*type*/ undefined,
393401
createRequireCall(node)
394402
)
395403
],
@@ -431,6 +439,7 @@ namespace ts {
431439
createVariableDeclarationList([
432440
createVariableDeclaration(
433441
generatedName,
442+
/*type*/ undefined,
434443
createRequireCall(node)
435444
)
436445
]),
@@ -460,6 +469,7 @@ namespace ts {
460469
return createStatement(
461470
createCall(
462471
createIdentifier("__export"),
472+
/*typeArguments*/ undefined,
463473
[
464474
moduleKind !== ModuleKind.AMD
465475
? createRequireCall(node)
@@ -517,6 +527,7 @@ namespace ts {
517527
createStatement(
518528
createCall(
519529
createPropertyAccess(createIdentifier("Object"), "defineProperty"),
530+
/*typeArguments*/ undefined,
520531
[
521532
createIdentifier("exports"),
522533
createLiteral("__esModule"),
@@ -671,10 +682,13 @@ namespace ts {
671682
statements.push(
672683
setOriginalNode(
673684
createFunctionDeclaration(
685+
/*decorators*/ undefined,
674686
/*modifiers*/ undefined,
675687
/*asteriskToken*/ undefined,
676688
name,
689+
/*typeParameters*/ undefined,
677690
node.parameters,
691+
/*type*/ undefined,
678692
node.body,
679693
/*location*/ node
680694
),
@@ -775,6 +789,7 @@ namespace ts {
775789
/*modifiers*/ undefined,
776790
[createVariableDeclaration(
777791
getDeclarationName(node),
792+
/*type*/ undefined,
778793
createPropertyAccess(createIdentifier("exports"), getDeclarationName(node))
779794
)],
780795
/*location*/ node
@@ -910,7 +925,7 @@ namespace ts {
910925
args.push(moduleName);
911926
}
912927

913-
return createCall(createIdentifier("require"), args);
928+
return createCall(createIdentifier("require"), /*typeArguments*/ undefined, args);
914929
}
915930

916931
function createExportStatement(name: Identifier, value: Expression, location?: TextRange) {

0 commit comments

Comments
 (0)