Skip to content

Commit 23a64fe

Browse files
author
Andy
authored
Remove redundant call to checkNodeDeferred (#22516)
* Remove redundant call to `checkNodeDeferred` * Use a set to speed up `contains` checks
1 parent e41feab commit 23a64fe

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/compiler/checker.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ namespace ts {
422422

423423
let deferredNodes: Node[];
424424
let deferredUnusedIdentifierNodes: Node[];
425+
const seenDeferredUnusedIdentifiers = createMap<true>(); // For assertion that we don't defer the same identifier twice
425426

426427
let flowLoopStart = 0;
427428
let flowLoopCount = 0;
@@ -18674,7 +18675,6 @@ namespace ts {
1867418675

1867518676
// The identityMapper object is used to indicate that function expressions are wildcards
1867618677
if (checkMode === CheckMode.SkipContextSensitive && isContextSensitive(node)) {
18677-
checkNodeDeferred(node);
1867818678
return anyFunctionType;
1867918679
}
1868018680

@@ -21564,6 +21564,7 @@ namespace ts {
2156421564

2156521565
function registerForUnusedIdentifiersCheck(node: Node) {
2156621566
if (deferredUnusedIdentifierNodes) {
21567+
Debug.assert(addToSeen(seenDeferredUnusedIdentifiers, getNodeId(node)), "Deferring unused identifier check twice");
2156721568
deferredUnusedIdentifierNodes.push(node);
2156821569
}
2156921570
}
@@ -24573,6 +24574,7 @@ namespace ts {
2457324574
}
2457424575

2457524576
deferredNodes = undefined;
24577+
seenDeferredUnusedIdentifiers.clear();
2457624578
deferredUnusedIdentifierNodes = undefined;
2457724579

2457824580
if (isExternalOrCommonJsModule(node)) {

src/compiler/utilities.ts

+10
Original file line numberDiff line numberDiff line change
@@ -3839,6 +3839,16 @@ namespace ts {
38393839
export function showModuleSpecifier({ moduleSpecifier }: ImportDeclaration): string {
38403840
return isStringLiteral(moduleSpecifier) ? moduleSpecifier.text : getTextOfNode(moduleSpecifier);
38413841
}
3842+
3843+
/** Add a value to a set, and return true if it wasn't already present. */
3844+
export function addToSeen(seen: Map<true>, key: string | number): boolean {
3845+
key = String(key);
3846+
if (seen.has(key)) {
3847+
return false;
3848+
}
3849+
seen.set(key, true);
3850+
return true;
3851+
}
38423852
}
38433853

38443854
namespace ts {

src/services/utilities.ts

-10
Original file line numberDiff line numberDiff line change
@@ -1205,16 +1205,6 @@ namespace ts {
12051205
};
12061206
}
12071207

1208-
/** Add a value to a set, and return true if it wasn't already present. */
1209-
export function addToSeen(seen: Map<true>, key: string | number): boolean {
1210-
key = String(key);
1211-
if (seen.has(key)) {
1212-
return false;
1213-
}
1214-
seen.set(key, true);
1215-
return true;
1216-
}
1217-
12181208
export function getSnapshotText(snap: IScriptSnapshot): string {
12191209
return snap.getText(0, snap.getLength());
12201210
}

0 commit comments

Comments
 (0)