Skip to content

Commit 500e4ad

Browse files
committed
Assert if a node has been bound more than once
1 parent 8a1b858 commit 500e4ad

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/compiler/binder.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ namespace ts {
227227
const reportedUnreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
228228
const bindBinaryExpressionFlow = createBindBinaryExpressionFlow();
229229

230+
let alreadyBound: Set<Node>;
231+
230232
/**
231233
* Inside the binder, we may create a diagnostic for an as-yet unbound node (with potentially no parent pointers, implying no accessible source file)
232234
* If so, the node _must_ be in the current file (as that's the only way anything could have traversed to it to yield it as the error node)
@@ -243,6 +245,7 @@ namespace ts {
243245
inStrictMode = bindInStrictMode(file, opts);
244246
classifiableNames = new Set();
245247
symbolCount = 0;
248+
alreadyBound = new Set();
246249

247250
Symbol = objectAllocator.getSymbolConstructor();
248251

@@ -280,6 +283,7 @@ namespace ts {
280283
hasExplicitReturn = false;
281284
inAssignmentPattern = false;
282285
emitFlags = NodeFlags.None;
286+
alreadyBound = undefined!;
283287
}
284288

285289
return bindSourceFile;
@@ -2396,6 +2400,10 @@ namespace ts {
23962400
if (!node) {
23972401
return;
23982402
}
2403+
2404+
Debug.assert(!alreadyBound.has(node), "This node has already been bound.");
2405+
alreadyBound.add(node);
2406+
23992407
setParent(node, parent);
24002408
if (tracing) (node as TracingNode).tracingPath = file.path;
24012409
const saveInStrictMode = inStrictMode;

0 commit comments

Comments
 (0)