Skip to content

Commit 1389b76

Browse files
committed
Perf investigation
1 parent 6ab6d5f commit 1389b76

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/compiler/parser.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -682,14 +682,19 @@ namespace ts {
682682
let SourceFileConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
683683
// tslint:enable variable-name
684684

685+
function countNode(node: Node) {
686+
nodeCount++;
687+
return node;
688+
}
689+
685690
// Rather than using `createBaseNodeFactory` here, we establish a `BaseNodeFactory` that closes over the
686691
// constructors above, which are reset each time `initializeState` is called.
687692
const baseNodeFactory: BaseNodeFactory = {
688-
createBaseSourceFileNode: kind => new SourceFileConstructor(kind, /*pos*/ 0, /*end*/ 0),
689-
createBaseIdentifierNode: kind => new IdentifierConstructor(kind, /*pos*/ 0, /*end*/ 0),
690-
createBasePrivateIdentifierNode: kind => new PrivateIdentifierConstructor(kind, /*pos*/ 0, /*end*/ 0),
691-
createBaseTokenNode: kind => new TokenConstructor(kind, /*pos*/ 0, /*end*/ 0),
692-
createBaseNode: kind => new NodeConstructor(kind, /*pos*/ 0, /*end*/ 0)
693+
createBaseSourceFileNode: kind => countNode(new SourceFileConstructor(kind, /*pos*/ 0, /*end*/ 0)),
694+
createBaseIdentifierNode: kind => countNode(new IdentifierConstructor(kind, /*pos*/ 0, /*end*/ 0)),
695+
createBasePrivateIdentifierNode: kind => countNode(new PrivateIdentifierConstructor(kind, /*pos*/ 0, /*end*/ 0)),
696+
createBaseTokenNode: kind => countNode(new TokenConstructor(kind, /*pos*/ 0, /*end*/ 0)),
697+
createBaseNode: kind => countNode(new NodeConstructor(kind, /*pos*/ 0, /*end*/ 0))
693698
};
694699

695700
const factory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules | NodeFactoryFlags.NoNodeConverters, baseNodeFactory, {
@@ -704,14 +709,9 @@ namespace ts {
704709
}
705710
},
706711
onFinishNode(node) {
707-
if (setParentNodes) {
708-
if (hasJSDocNodes(node)) {
709-
setEachParent(node.jsDoc, node);
710-
}
712+
if (setParentNodes && hasJSDocNodes(node)) {
713+
setEachParent(node.jsDoc, node);
711714
}
712-
},
713-
onCreateNode(_) {
714-
nodeCount++;
715715
}
716716
});
717717

0 commit comments

Comments
 (0)