Remove getOriginalNodeId.
This commit is contained in:
parent
e64dbabab8
commit
ca13132e84
|
@ -60,7 +60,7 @@ namespace ts {
|
|||
let enclosingDeclaration: Node;
|
||||
let necessaryTypeReferences: Set<string> | undefined;
|
||||
let lateMarkedStatements: LateVisibilityPaintedStatement[] | undefined;
|
||||
let lateStatementReplacementMap: ESMap<NodeId, VisitResult<LateVisibilityPaintedStatement | ExportAssignment>>;
|
||||
let lateStatementReplacementMap: ESMap<Node, VisitResult<LateVisibilityPaintedStatement | ExportAssignment>>;
|
||||
let suppressNewDiagnosticContexts: boolean;
|
||||
let exportedModulesFromDeclarationEmit: Symbol[] | undefined;
|
||||
|
||||
|
@ -84,7 +84,7 @@ namespace ts {
|
|||
let errorFallbackNode: Declaration | undefined;
|
||||
|
||||
let currentSourceFile: SourceFile;
|
||||
let refs: ESMap<NodeId, SourceFile>;
|
||||
let refs: ESMap<Node, SourceFile>;
|
||||
let libs: ESMap<string, boolean>;
|
||||
let emittedImports: readonly AnyImportSyntax[] | undefined; // must be declared in container so it can be `undefined` while transformer's first pass
|
||||
const resolver = context.getEmitResolver();
|
||||
|
@ -110,7 +110,7 @@ namespace ts {
|
|||
}
|
||||
// Otherwise we should emit a path-based reference
|
||||
const container = getSourceFileOfNode(node);
|
||||
refs.set(getOriginalNodeId(container), container);
|
||||
refs.set(getOriginalNode(container), container);
|
||||
}
|
||||
|
||||
function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) {
|
||||
|
@ -426,12 +426,12 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
|
||||
function collectReferences(sourceFile: SourceFile | UnparsedSource, ret: ESMap<NodeId, SourceFile>) {
|
||||
function collectReferences(sourceFile: SourceFile | UnparsedSource, ret: ESMap<Node, SourceFile>) {
|
||||
if (noResolve || (!isUnparsedSource(sourceFile) && isSourceFileJS(sourceFile))) return ret;
|
||||
forEach(sourceFile.referencedFiles, f => {
|
||||
const elem = host.getSourceFileFromReference(sourceFile, f);
|
||||
if (elem) {
|
||||
ret.set(getOriginalNodeId(elem), elem);
|
||||
ret.set(getOriginalNode(elem), elem);
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
|
@ -812,7 +812,7 @@ namespace ts {
|
|||
needsDeclare = i.parent && isSourceFile(i.parent) && !(isExternalModule(i.parent) && isBundledEmit);
|
||||
const result = transformTopLevelDeclaration(i);
|
||||
needsDeclare = priorNeedsDeclare;
|
||||
lateStatementReplacementMap.set(getOriginalNodeId(i), result);
|
||||
lateStatementReplacementMap.set(getOriginalNode(i), result);
|
||||
}
|
||||
|
||||
// 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 {
|
|||
|
||||
function visitLateVisibilityMarkedStatements(statement: Statement) {
|
||||
if (isLateVisibilityPaintedStatement(statement)) {
|
||||
const key = getOriginalNodeId(statement);
|
||||
if (lateStatementReplacementMap.has(key)) {
|
||||
const result = lateStatementReplacementMap.get(key);
|
||||
lateStatementReplacementMap.delete(key);
|
||||
const originalNode = getOriginalNode(statement);
|
||||
if (lateStatementReplacementMap.has(originalNode)) {
|
||||
const result = lateStatementReplacementMap.get(originalNode);
|
||||
lateStatementReplacementMap.delete(originalNode);
|
||||
if (result) {
|
||||
if (isArray(result) ? some(result, needsScopeMarker) : needsScopeMarker(result)) {
|
||||
// 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 {
|
|||
|
||||
const result = transformTopLevelDeclaration(input);
|
||||
// Don't actually transform yet; just leave as original node - will be elided/swapped by late pass
|
||||
lateStatementReplacementMap.set(getOriginalNodeId(input), result);
|
||||
lateStatementReplacementMap.set(getOriginalNode(input), result);
|
||||
return input;
|
||||
}
|
||||
|
||||
|
@ -1348,9 +1348,9 @@ namespace ts {
|
|||
needsDeclare = false;
|
||||
visitNode(inner, visitDeclarationStatements);
|
||||
// eagerly transform nested namespaces (the nesting doesn't need any elision or painting done)
|
||||
const id = getOriginalNodeId(inner!); // TODO: GH#18217
|
||||
const body = lateStatementReplacementMap.get(id);
|
||||
lateStatementReplacementMap.delete(id);
|
||||
const originalNode = getOriginalNode(inner!); // TODO: GH#18217
|
||||
const body = lateStatementReplacementMap.get(originalNode);
|
||||
lateStatementReplacementMap.delete(originalNode);
|
||||
return cleanup(factory.updateModuleDeclaration(
|
||||
input,
|
||||
/*decorators*/ undefined,
|
||||
|
|
|
@ -245,7 +245,7 @@ namespace ts {
|
|||
context.onSubstituteNode = onSubstituteNode;
|
||||
|
||||
let renamedCatchVariables: ESMap<string, boolean>;
|
||||
let renamedCatchVariableDeclarations: Identifier[];
|
||||
let renamedCatchVariableDeclarations: ESMap<Node, Identifier>;
|
||||
|
||||
let inGeneratorFunctionBody: boolean;
|
||||
let inStatementContainingYield: boolean;
|
||||
|
@ -1969,7 +1969,7 @@ namespace ts {
|
|||
if (isIdentifier(original) && original.parent) {
|
||||
const declaration = resolver.getReferencedValueDeclaration(original);
|
||||
if (declaration) {
|
||||
const name = renamedCatchVariableDeclarations[getOriginalNodeId(declaration)];
|
||||
const name = renamedCatchVariableDeclarations.get(getOriginalNode(declaration));
|
||||
if (name) {
|
||||
// TODO(rbuckton): Does this need to be parented?
|
||||
const clone = setParent(setTextRange(factory.cloneNode(name), name), name.parent);
|
||||
|
@ -2137,12 +2137,12 @@ namespace ts {
|
|||
name = declareLocal(text);
|
||||
if (!renamedCatchVariables) {
|
||||
renamedCatchVariables = new Map<string, boolean>();
|
||||
renamedCatchVariableDeclarations = [];
|
||||
renamedCatchVariableDeclarations = new Map<Node, Identifier>();
|
||||
context.enableSubstitution(SyntaxKind.Identifier);
|
||||
}
|
||||
|
||||
renamedCatchVariables.set(text, true);
|
||||
renamedCatchVariableDeclarations[getOriginalNodeId(variable)] = name;
|
||||
renamedCatchVariableDeclarations.set(getOriginalNode(variable), name);
|
||||
}
|
||||
|
||||
const exception = peekBlock() as ExceptionBlock;
|
||||
|
|
|
@ -40,8 +40,8 @@ namespace ts {
|
|||
context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); // Substitutes shorthand property assignments for imported/exported symbols.
|
||||
context.enableEmitNotification(SyntaxKind.SourceFile); // Restore state when substituting nodes in a file.
|
||||
|
||||
const moduleInfoMap: ExternalModuleInfo[] = []; // The ExternalModuleInfo for each file.
|
||||
const deferredExports: (Statement[] | undefined)[] = []; // Exports to defer until an EndOfDeclarationMarker is found.
|
||||
const moduleInfoMap = new Map<Node, ExternalModuleInfo>(); // The ExternalModuleInfo for each file.
|
||||
const deferredExports = new Map<Node, Statement[] | undefined>();; // Exports to defer until an EndOfDeclarationMarker is found.
|
||||
|
||||
let currentSourceFile: SourceFile; // The current file.
|
||||
let currentModuleInfo: ExternalModuleInfo; // The ExternalModuleInfo for the current file.
|
||||
|
@ -65,7 +65,7 @@ namespace ts {
|
|||
|
||||
currentSourceFile = node;
|
||||
currentModuleInfo = collectExternalModuleInfo(context, node, resolver, compilerOptions);
|
||||
moduleInfoMap[getOriginalNodeId(node)] = currentModuleInfo;
|
||||
moduleInfoMap.set(getOriginalNode(node), currentModuleInfo);
|
||||
|
||||
// Perform the transformation.
|
||||
const transformModule = getTransformModuleDelegate(moduleKind);
|
||||
|
@ -981,8 +981,8 @@ namespace ts {
|
|||
|
||||
if (hasAssociatedEndOfDeclarationMarker(node)) {
|
||||
// Defer exports until we encounter an EndOfDeclarationMarker node
|
||||
const id = getOriginalNodeId(node);
|
||||
deferredExports[id] = appendExportsOfImportDeclaration(deferredExports[id], node);
|
||||
const originalNode = getOriginalNode(node);
|
||||
deferredExports.set(node, appendExportsOfImportDeclaration(deferredExports.get(originalNode), node));
|
||||
}
|
||||
else {
|
||||
statements = appendExportsOfImportDeclaration(statements, node);
|
||||
|
@ -1072,8 +1072,8 @@ namespace ts {
|
|||
|
||||
if (hasAssociatedEndOfDeclarationMarker(node)) {
|
||||
// Defer exports until we encounter an EndOfDeclarationMarker node
|
||||
const id = getOriginalNodeId(node);
|
||||
deferredExports[id] = appendExportsOfImportEqualsDeclaration(deferredExports[id], node);
|
||||
const originalNode = getOriginalNode(node);
|
||||
deferredExports.set(node, appendExportsOfImportEqualsDeclaration(deferredExports.get(originalNode), node));
|
||||
}
|
||||
else {
|
||||
statements = appendExportsOfImportEqualsDeclaration(statements, node);
|
||||
|
@ -1206,8 +1206,8 @@ namespace ts {
|
|||
const original = node.original;
|
||||
if (original && hasAssociatedEndOfDeclarationMarker(original)) {
|
||||
// Defer exports until we encounter an EndOfDeclarationMarker node
|
||||
const id = getOriginalNodeId(node);
|
||||
deferredExports[id] = appendExportStatement(deferredExports[id], factory.createIdentifier("default"), visitNode(node.expression, visitor), /*location*/ node, /*allowComments*/ true);
|
||||
const originalNode = getOriginalNode(node);
|
||||
deferredExports.set(node, appendExportStatement(deferredExports.get(originalNode), factory.createIdentifier("default"), visitNode(node.expression, visitor), /*location*/ node, /*allowComments*/ true));
|
||||
}
|
||||
else {
|
||||
statements = appendExportStatement(statements, factory.createIdentifier("default"), visitNode(node.expression, visitor), /*location*/ node, /*allowComments*/ true);
|
||||
|
@ -1249,8 +1249,8 @@ namespace ts {
|
|||
|
||||
if (hasAssociatedEndOfDeclarationMarker(node)) {
|
||||
// Defer exports until we encounter an EndOfDeclarationMarker node
|
||||
const id = getOriginalNodeId(node);
|
||||
deferredExports[id] = appendExportsOfHoistedDeclaration(deferredExports[id], node);
|
||||
const originalNode = getOriginalNode(node);
|
||||
deferredExports.set(node, appendExportsOfHoistedDeclaration(deferredExports.get(originalNode), node));
|
||||
}
|
||||
else {
|
||||
statements = appendExportsOfHoistedDeclaration(statements, node);
|
||||
|
@ -1290,8 +1290,8 @@ namespace ts {
|
|||
|
||||
if (hasAssociatedEndOfDeclarationMarker(node)) {
|
||||
// Defer exports until we encounter an EndOfDeclarationMarker node
|
||||
const id = getOriginalNodeId(node);
|
||||
deferredExports[id] = appendExportsOfHoistedDeclaration(deferredExports[id], node);
|
||||
const originalNode = getOriginalNode(node);
|
||||
deferredExports.set(node, appendExportsOfHoistedDeclaration(deferredExports.get(originalNode), node));
|
||||
}
|
||||
else {
|
||||
statements = appendExportsOfHoistedDeclaration(statements, node);
|
||||
|
@ -1370,8 +1370,8 @@ namespace ts {
|
|||
|
||||
if (hasAssociatedEndOfDeclarationMarker(node)) {
|
||||
// Defer exports until we encounter an EndOfDeclarationMarker node
|
||||
const id = getOriginalNodeId(node);
|
||||
deferredExports[id] = appendExportsOfVariableStatement(deferredExports[id], node);
|
||||
const originalNode = getOriginalNode(node);
|
||||
deferredExports.set(node, appendExportsOfVariableStatement(deferredExports.get(originalNode), node));
|
||||
}
|
||||
else {
|
||||
statements = appendExportsOfVariableStatement(statements, node);
|
||||
|
@ -1441,8 +1441,8 @@ namespace ts {
|
|||
// To balance the declaration, add the exports of the elided variable
|
||||
// statement.
|
||||
if (hasAssociatedEndOfDeclarationMarker(node) && node.original!.kind === SyntaxKind.VariableStatement) {
|
||||
const id = getOriginalNodeId(node);
|
||||
deferredExports[id] = appendExportsOfVariableStatement(deferredExports[id], node.original as VariableStatement);
|
||||
const originalNode = getOriginalNode(node);
|
||||
deferredExports.set(node, appendExportsOfVariableStatement(deferredExports.get(originalNode), node.original as VariableStatement));
|
||||
}
|
||||
|
||||
return node;
|
||||
|
@ -1467,10 +1467,10 @@ namespace ts {
|
|||
// For some transformations we emit an `EndOfDeclarationMarker` to mark the actual
|
||||
// end of the transformed declaration. We use this marker to emit any deferred exports
|
||||
// of the declaration.
|
||||
const id = getOriginalNodeId(node);
|
||||
const statements = deferredExports[id];
|
||||
const originalNode = getOriginalNode(node);
|
||||
const statements = deferredExports.get(originalNode);
|
||||
if (statements) {
|
||||
delete deferredExports[id];
|
||||
deferredExports.delete(node);
|
||||
return append(statements, node);
|
||||
}
|
||||
|
||||
|
@ -1770,7 +1770,7 @@ namespace ts {
|
|||
function onEmitNode(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void {
|
||||
if (node.kind === SyntaxKind.SourceFile) {
|
||||
currentSourceFile = node as SourceFile;
|
||||
currentModuleInfo = moduleInfoMap[getOriginalNodeId(currentSourceFile)];
|
||||
currentModuleInfo = moduleInfoMap.get(getOriginalNode(currentSourceFile))!;
|
||||
|
||||
previousOnEmitNode(hint, node, emitCallback);
|
||||
|
||||
|
@ -1984,7 +1984,7 @@ namespace ts {
|
|||
|| resolver.getReferencedValueDeclaration(name);
|
||||
if (valueDeclaration) {
|
||||
return currentModuleInfo
|
||||
&& currentModuleInfo.exportedBindings[getOriginalNodeId(valueDeclaration)];
|
||||
&& currentModuleInfo.exportedBindings.get(getOriginalNode(valueDeclaration));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1901,7 +1901,7 @@ namespace ts {
|
|||
exportedNames = append(exportedNames, factory.getDeclarationName(valueDeclaration));
|
||||
}
|
||||
|
||||
exportedNames = addRange(exportedNames, moduleInfo && moduleInfo.exportedBindings[getOriginalNodeId(valueDeclaration)]);
|
||||
exportedNames = addRange(exportedNames, moduleInfo && moduleInfo.exportedBindings.get(getOriginalNode(valueDeclaration)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
/* @internal */
|
||||
namespace ts {
|
||||
export function getOriginalNodeId(node: Node) {
|
||||
node = getOriginalNode(node);
|
||||
return node ? getNodeId(node) : 0;
|
||||
}
|
||||
|
||||
export interface ExternalModuleInfo {
|
||||
externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; // imports of other external modules
|
||||
externalHelpersImportDeclaration: ImportDeclaration | undefined; // import of external helpers
|
||||
exportSpecifiers: ESMap<string, ExportSpecifier[]>; // file-local export specifiers by name (no reexports)
|
||||
exportedBindings: Identifier[][]; // exported names of local declarations
|
||||
exportedBindings: MultiMap<Node, Identifier>; // exported names of local declarations
|
||||
exportedNames: Identifier[] | undefined; // all exported names in the module, both local and reexported
|
||||
exportEquals: ExportAssignment | undefined; // an export= declaration if one was present
|
||||
hasExportStarsToExportValues: boolean; // whether this module contains export*
|
||||
|
@ -68,7 +63,7 @@ namespace ts {
|
|||
export function collectExternalModuleInfo(context: TransformationContext, sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo {
|
||||
const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = [];
|
||||
const exportSpecifiers = createMultiMap<ExportSpecifier>();
|
||||
const exportedBindings: Identifier[][] = [];
|
||||
const exportedBindings = createMultiMap<Node, Identifier>();
|
||||
const uniqueExports = new Map<string, boolean>();
|
||||
let exportedNames: Identifier[] | undefined;
|
||||
let hasExportDefault = false;
|
||||
|
@ -118,7 +113,7 @@ namespace ts {
|
|||
else {
|
||||
const name = ((node as ExportDeclaration).exportClause as NamespaceExport).name;
|
||||
if (!uniqueExports.get(idText(name))) {
|
||||
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name);
|
||||
exportedBindings.add(getOriginalNode(node), name);
|
||||
uniqueExports.set(idText(name), true);
|
||||
exportedNames = append(exportedNames, name);
|
||||
}
|
||||
|
@ -153,7 +148,7 @@ namespace ts {
|
|||
if (hasSyntacticModifier(node, ModifierFlags.Default)) {
|
||||
// export default function() { }
|
||||
if (!hasExportDefault) {
|
||||
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), context.factory.getDeclarationName(node as FunctionDeclaration));
|
||||
exportedBindings.add(getOriginalNode(node), context.factory.getDeclarationName(node as FunctionDeclaration));
|
||||
hasExportDefault = true;
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +156,7 @@ namespace ts {
|
|||
// export function x() { }
|
||||
const name = (node as FunctionDeclaration).name!;
|
||||
if (!uniqueExports.get(idText(name))) {
|
||||
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name);
|
||||
exportedBindings.add(getOriginalNode(node), name);
|
||||
uniqueExports.set(idText(name), true);
|
||||
exportedNames = append(exportedNames, name);
|
||||
}
|
||||
|
@ -174,7 +169,7 @@ namespace ts {
|
|||
if (hasSyntacticModifier(node, ModifierFlags.Default)) {
|
||||
// export default class { }
|
||||
if (!hasExportDefault) {
|
||||
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), context.factory.getDeclarationName(node as ClassDeclaration));
|
||||
exportedBindings.add(getOriginalNode(node), context.factory.getDeclarationName(node as ClassDeclaration));
|
||||
hasExportDefault = true;
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +177,7 @@ namespace ts {
|
|||
// export class x { }
|
||||
const name = (node as ClassDeclaration).name;
|
||||
if (name && !uniqueExports.get(idText(name))) {
|
||||
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name);
|
||||
exportedBindings.add(getOriginalNode(node), name);
|
||||
uniqueExports.set(idText(name), true);
|
||||
exportedNames = append(exportedNames, name);
|
||||
}
|
||||
|
@ -211,7 +206,7 @@ namespace ts {
|
|||
|| resolver.getReferencedValueDeclaration(name);
|
||||
|
||||
if (decl) {
|
||||
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(decl), specifier.name);
|
||||
exportedBindings.add(getOriginalNode(decl), specifier.name);
|
||||
}
|
||||
|
||||
uniqueExports.set(idText(specifier.name), true);
|
||||
|
@ -239,18 +234,6 @@ namespace ts {
|
|||
return exportedNames;
|
||||
}
|
||||
|
||||
/** Use a sparse array as a multi-map. */
|
||||
function multiMapSparseArrayAdd<V>(map: V[][], key: number, value: V): V[] {
|
||||
let values = map[key];
|
||||
if (values) {
|
||||
values.push(value);
|
||||
}
|
||||
else {
|
||||
map[key] = values = [value];
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in the module transformer to check if an expression is reasonably without sideeffect,
|
||||
* and thus better to copy into multiple places rather than to cache in a temporary variable
|
||||
|
|
Loading…
Reference in a new issue