Skip to content

Commit ca13132

Browse files
Remove getOriginalNodeId.
1 parent e64dbab commit ca13132

File tree

5 files changed

+49
-66
lines changed

5 files changed

+49
-66
lines changed

src/compiler/transformers/declarations.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace ts {
6060
let enclosingDeclaration: Node;
6161
let necessaryTypeReferences: Set<string> | undefined;
6262
let lateMarkedStatements: LateVisibilityPaintedStatement[] | undefined;
63-
let lateStatementReplacementMap: ESMap<NodeId, VisitResult<LateVisibilityPaintedStatement | ExportAssignment>>;
63+
let lateStatementReplacementMap: ESMap<Node, VisitResult<LateVisibilityPaintedStatement | ExportAssignment>>;
6464
let suppressNewDiagnosticContexts: boolean;
6565
let exportedModulesFromDeclarationEmit: Symbol[] | undefined;
6666

@@ -84,7 +84,7 @@ namespace ts {
8484
let errorFallbackNode: Declaration | undefined;
8585

8686
let currentSourceFile: SourceFile;
87-
let refs: ESMap<NodeId, SourceFile>;
87+
let refs: ESMap<Node, SourceFile>;
8888
let libs: ESMap<string, boolean>;
8989
let emittedImports: readonly AnyImportSyntax[] | undefined; // must be declared in container so it can be `undefined` while transformer's first pass
9090
const resolver = context.getEmitResolver();
@@ -110,7 +110,7 @@ namespace ts {
110110
}
111111
// Otherwise we should emit a path-based reference
112112
const container = getSourceFileOfNode(node);
113-
refs.set(getOriginalNodeId(container), container);
113+
refs.set(getOriginalNode(container), container);
114114
}
115115

116116
function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) {
@@ -426,12 +426,12 @@ namespace ts {
426426
}
427427
}
428428

429-
function collectReferences(sourceFile: SourceFile | UnparsedSource, ret: ESMap<NodeId, SourceFile>) {
429+
function collectReferences(sourceFile: SourceFile | UnparsedSource, ret: ESMap<Node, SourceFile>) {
430430
if (noResolve || (!isUnparsedSource(sourceFile) && isSourceFileJS(sourceFile))) return ret;
431431
forEach(sourceFile.referencedFiles, f => {
432432
const elem = host.getSourceFileFromReference(sourceFile, f);
433433
if (elem) {
434-
ret.set(getOriginalNodeId(elem), elem);
434+
ret.set(getOriginalNode(elem), elem);
435435
}
436436
});
437437
return ret;
@@ -812,7 +812,7 @@ namespace ts {
812812
needsDeclare = i.parent && isSourceFile(i.parent) && !(isExternalModule(i.parent) && isBundledEmit);
813813
const result = transformTopLevelDeclaration(i);
814814
needsDeclare = priorNeedsDeclare;
815-
lateStatementReplacementMap.set(getOriginalNodeId(i), result);
815+
lateStatementReplacementMap.set(getOriginalNode(i), result);
816816
}
817817

818818
// And lastly, we need to get the final form of all those indetermine import declarations from before and add them to the output list
@@ -821,10 +821,10 @@ namespace ts {
821821

822822
function visitLateVisibilityMarkedStatements(statement: Statement) {
823823
if (isLateVisibilityPaintedStatement(statement)) {
824-
const key = getOriginalNodeId(statement);
825-
if (lateStatementReplacementMap.has(key)) {
826-
const result = lateStatementReplacementMap.get(key);
827-
lateStatementReplacementMap.delete(key);
824+
const originalNode = getOriginalNode(statement);
825+
if (lateStatementReplacementMap.has(originalNode)) {
826+
const result = lateStatementReplacementMap.get(originalNode);
827+
lateStatementReplacementMap.delete(originalNode);
828828
if (result) {
829829
if (isArray(result) ? some(result, needsScopeMarker) : needsScopeMarker(result)) {
830830
// Top-level declarations in .d.ts files are always considered exported even without a modifier unless there's an export assignment or specifier
@@ -1146,7 +1146,7 @@ namespace ts {
11461146

11471147
const result = transformTopLevelDeclaration(input);
11481148
// Don't actually transform yet; just leave as original node - will be elided/swapped by late pass
1149-
lateStatementReplacementMap.set(getOriginalNodeId(input), result);
1149+
lateStatementReplacementMap.set(getOriginalNode(input), result);
11501150
return input;
11511151
}
11521152

@@ -1348,9 +1348,9 @@ namespace ts {
13481348
needsDeclare = false;
13491349
visitNode(inner, visitDeclarationStatements);
13501350
// eagerly transform nested namespaces (the nesting doesn't need any elision or painting done)
1351-
const id = getOriginalNodeId(inner!); // TODO: GH#18217
1352-
const body = lateStatementReplacementMap.get(id);
1353-
lateStatementReplacementMap.delete(id);
1351+
const originalNode = getOriginalNode(inner!); // TODO: GH#18217
1352+
const body = lateStatementReplacementMap.get(originalNode);
1353+
lateStatementReplacementMap.delete(originalNode);
13541354
return cleanup(factory.updateModuleDeclaration(
13551355
input,
13561356
/*decorators*/ undefined,

src/compiler/transformers/generators.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ namespace ts {
245245
context.onSubstituteNode = onSubstituteNode;
246246

247247
let renamedCatchVariables: ESMap<string, boolean>;
248-
let renamedCatchVariableDeclarations: Identifier[];
248+
let renamedCatchVariableDeclarations: ESMap<Node, Identifier>;
249249

250250
let inGeneratorFunctionBody: boolean;
251251
let inStatementContainingYield: boolean;
@@ -1969,7 +1969,7 @@ namespace ts {
19691969
if (isIdentifier(original) && original.parent) {
19701970
const declaration = resolver.getReferencedValueDeclaration(original);
19711971
if (declaration) {
1972-
const name = renamedCatchVariableDeclarations[getOriginalNodeId(declaration)];
1972+
const name = renamedCatchVariableDeclarations.get(getOriginalNode(declaration));
19731973
if (name) {
19741974
// TODO(rbuckton): Does this need to be parented?
19751975
const clone = setParent(setTextRange(factory.cloneNode(name), name), name.parent);
@@ -2137,12 +2137,12 @@ namespace ts {
21372137
name = declareLocal(text);
21382138
if (!renamedCatchVariables) {
21392139
renamedCatchVariables = new Map<string, boolean>();
2140-
renamedCatchVariableDeclarations = [];
2140+
renamedCatchVariableDeclarations = new Map<Node, Identifier>();
21412141
context.enableSubstitution(SyntaxKind.Identifier);
21422142
}
21432143

21442144
renamedCatchVariables.set(text, true);
2145-
renamedCatchVariableDeclarations[getOriginalNodeId(variable)] = name;
2145+
renamedCatchVariableDeclarations.set(getOriginalNode(variable), name);
21462146
}
21472147

21482148
const exception = peekBlock() as ExceptionBlock;

src/compiler/transformers/module/module.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ namespace ts {
4040
context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); // Substitutes shorthand property assignments for imported/exported symbols.
4141
context.enableEmitNotification(SyntaxKind.SourceFile); // Restore state when substituting nodes in a file.
4242

43-
const moduleInfoMap: ExternalModuleInfo[] = []; // The ExternalModuleInfo for each file.
44-
const deferredExports: (Statement[] | undefined)[] = []; // Exports to defer until an EndOfDeclarationMarker is found.
43+
const moduleInfoMap = new Map<Node, ExternalModuleInfo>(); // The ExternalModuleInfo for each file.
44+
const deferredExports = new Map<Node, Statement[] | undefined>();; // Exports to defer until an EndOfDeclarationMarker is found.
4545

4646
let currentSourceFile: SourceFile; // The current file.
4747
let currentModuleInfo: ExternalModuleInfo; // The ExternalModuleInfo for the current file.
@@ -65,7 +65,7 @@ namespace ts {
6565

6666
currentSourceFile = node;
6767
currentModuleInfo = collectExternalModuleInfo(context, node, resolver, compilerOptions);
68-
moduleInfoMap[getOriginalNodeId(node)] = currentModuleInfo;
68+
moduleInfoMap.set(getOriginalNode(node), currentModuleInfo);
6969

7070
// Perform the transformation.
7171
const transformModule = getTransformModuleDelegate(moduleKind);
@@ -981,8 +981,8 @@ namespace ts {
981981

982982
if (hasAssociatedEndOfDeclarationMarker(node)) {
983983
// Defer exports until we encounter an EndOfDeclarationMarker node
984-
const id = getOriginalNodeId(node);
985-
deferredExports[id] = appendExportsOfImportDeclaration(deferredExports[id], node);
984+
const originalNode = getOriginalNode(node);
985+
deferredExports.set(node, appendExportsOfImportDeclaration(deferredExports.get(originalNode), node));
986986
}
987987
else {
988988
statements = appendExportsOfImportDeclaration(statements, node);
@@ -1072,8 +1072,8 @@ namespace ts {
10721072

10731073
if (hasAssociatedEndOfDeclarationMarker(node)) {
10741074
// Defer exports until we encounter an EndOfDeclarationMarker node
1075-
const id = getOriginalNodeId(node);
1076-
deferredExports[id] = appendExportsOfImportEqualsDeclaration(deferredExports[id], node);
1075+
const originalNode = getOriginalNode(node);
1076+
deferredExports.set(node, appendExportsOfImportEqualsDeclaration(deferredExports.get(originalNode), node));
10771077
}
10781078
else {
10791079
statements = appendExportsOfImportEqualsDeclaration(statements, node);
@@ -1206,8 +1206,8 @@ namespace ts {
12061206
const original = node.original;
12071207
if (original && hasAssociatedEndOfDeclarationMarker(original)) {
12081208
// Defer exports until we encounter an EndOfDeclarationMarker node
1209-
const id = getOriginalNodeId(node);
1210-
deferredExports[id] = appendExportStatement(deferredExports[id], factory.createIdentifier("default"), visitNode(node.expression, visitor), /*location*/ node, /*allowComments*/ true);
1209+
const originalNode = getOriginalNode(node);
1210+
deferredExports.set(node, appendExportStatement(deferredExports.get(originalNode), factory.createIdentifier("default"), visitNode(node.expression, visitor), /*location*/ node, /*allowComments*/ true));
12111211
}
12121212
else {
12131213
statements = appendExportStatement(statements, factory.createIdentifier("default"), visitNode(node.expression, visitor), /*location*/ node, /*allowComments*/ true);
@@ -1249,8 +1249,8 @@ namespace ts {
12491249

12501250
if (hasAssociatedEndOfDeclarationMarker(node)) {
12511251
// Defer exports until we encounter an EndOfDeclarationMarker node
1252-
const id = getOriginalNodeId(node);
1253-
deferredExports[id] = appendExportsOfHoistedDeclaration(deferredExports[id], node);
1252+
const originalNode = getOriginalNode(node);
1253+
deferredExports.set(node, appendExportsOfHoistedDeclaration(deferredExports.get(originalNode), node));
12541254
}
12551255
else {
12561256
statements = appendExportsOfHoistedDeclaration(statements, node);
@@ -1290,8 +1290,8 @@ namespace ts {
12901290

12911291
if (hasAssociatedEndOfDeclarationMarker(node)) {
12921292
// Defer exports until we encounter an EndOfDeclarationMarker node
1293-
const id = getOriginalNodeId(node);
1294-
deferredExports[id] = appendExportsOfHoistedDeclaration(deferredExports[id], node);
1293+
const originalNode = getOriginalNode(node);
1294+
deferredExports.set(node, appendExportsOfHoistedDeclaration(deferredExports.get(originalNode), node));
12951295
}
12961296
else {
12971297
statements = appendExportsOfHoistedDeclaration(statements, node);
@@ -1370,8 +1370,8 @@ namespace ts {
13701370

13711371
if (hasAssociatedEndOfDeclarationMarker(node)) {
13721372
// Defer exports until we encounter an EndOfDeclarationMarker node
1373-
const id = getOriginalNodeId(node);
1374-
deferredExports[id] = appendExportsOfVariableStatement(deferredExports[id], node);
1373+
const originalNode = getOriginalNode(node);
1374+
deferredExports.set(node, appendExportsOfVariableStatement(deferredExports.get(originalNode), node));
13751375
}
13761376
else {
13771377
statements = appendExportsOfVariableStatement(statements, node);
@@ -1441,8 +1441,8 @@ namespace ts {
14411441
// To balance the declaration, add the exports of the elided variable
14421442
// statement.
14431443
if (hasAssociatedEndOfDeclarationMarker(node) && node.original!.kind === SyntaxKind.VariableStatement) {
1444-
const id = getOriginalNodeId(node);
1445-
deferredExports[id] = appendExportsOfVariableStatement(deferredExports[id], node.original as VariableStatement);
1444+
const originalNode = getOriginalNode(node);
1445+
deferredExports.set(node, appendExportsOfVariableStatement(deferredExports.get(originalNode), node.original as VariableStatement));
14461446
}
14471447

14481448
return node;
@@ -1467,10 +1467,10 @@ namespace ts {
14671467
// For some transformations we emit an `EndOfDeclarationMarker` to mark the actual
14681468
// end of the transformed declaration. We use this marker to emit any deferred exports
14691469
// of the declaration.
1470-
const id = getOriginalNodeId(node);
1471-
const statements = deferredExports[id];
1470+
const originalNode = getOriginalNode(node);
1471+
const statements = deferredExports.get(originalNode);
14721472
if (statements) {
1473-
delete deferredExports[id];
1473+
deferredExports.delete(node);
14741474
return append(statements, node);
14751475
}
14761476

@@ -1770,7 +1770,7 @@ namespace ts {
17701770
function onEmitNode(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void {
17711771
if (node.kind === SyntaxKind.SourceFile) {
17721772
currentSourceFile = node as SourceFile;
1773-
currentModuleInfo = moduleInfoMap[getOriginalNodeId(currentSourceFile)];
1773+
currentModuleInfo = moduleInfoMap.get(getOriginalNode(currentSourceFile))!;
17741774

17751775
previousOnEmitNode(hint, node, emitCallback);
17761776

@@ -1984,7 +1984,7 @@ namespace ts {
19841984
|| resolver.getReferencedValueDeclaration(name);
19851985
if (valueDeclaration) {
19861986
return currentModuleInfo
1987-
&& currentModuleInfo.exportedBindings[getOriginalNodeId(valueDeclaration)];
1987+
&& currentModuleInfo.exportedBindings.get(getOriginalNode(valueDeclaration));
19881988
}
19891989
}
19901990
}

src/compiler/transformers/module/system.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,7 @@ namespace ts {
19011901
exportedNames = append(exportedNames, factory.getDeclarationName(valueDeclaration));
19021902
}
19031903

1904-
exportedNames = addRange(exportedNames, moduleInfo && moduleInfo.exportedBindings[getOriginalNodeId(valueDeclaration)]);
1904+
exportedNames = addRange(exportedNames, moduleInfo && moduleInfo.exportedBindings.get(getOriginalNode(valueDeclaration)));
19051905
}
19061906
}
19071907

0 commit comments

Comments
 (0)