From b94b82a8963b67ac8d6f436dfed5bc242f015057 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 9 Aug 2022 22:06:21 +0000 Subject: [PATCH] Grab function directly to avoid possible `.call` overhead from downlevel emit. --- src/compiler/parser.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5df3b91b96b..3f2934fdfed 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -97,9 +97,8 @@ namespace ts { type ForEachChildFunction = (node: any, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray) => T | undefined) => T | undefined; - const forEachChildTable: ForEachChildFunction[] = []; - const forEachChildNoOpFn: ForEachChildFunction = (_node, _cbNode, _cbNodes) => undefined; - for (let i = 0; i < SyntaxKind.Count; i++) forEachChildTable.push(forEachChildNoOpFn); + const forEachChildTable: (ForEachChildFunction | undefined)[] = []; + for (let i = 0; i < SyntaxKind.Count; i++) forEachChildTable.push(undefined); forEachChildTable[SyntaxKind.QualifiedName] = forEachChildInQualifiedName; forEachChildTable[SyntaxKind.TypeParameter] = forEachChildInTypeParameter; forEachChildTable[SyntaxKind.ShorthandPropertyAssignment] = forEachChildInShorthandPropertyAssignment; @@ -1088,7 +1087,8 @@ namespace ts { return; } - return forEachChildTable[node.kind](node, cbNode, cbNodes); + const fn = forEachChildTable[node.kind]; + return fn === undefined ? undefined : fn(node, cbNode, cbNodes); } /** @internal */