MCPcopy Create free account
hub / github.com/nodejs/node / updateImportsInOtherFiles

Function updateImportsInOtherFiles

test/fixtures/snapshot/typescript.js:162132–162166  ·  view source on GitHub ↗
(changes, program, oldFile, movedSymbols, newModuleName)

Source from the content-addressed store, hash-verified

162130 }
162131 }
162132 function updateImportsInOtherFiles(changes, program, oldFile, movedSymbols, newModuleName) {
162133 var checker = program.getTypeChecker();
162134 var _loop_19 = function (sourceFile) {
162135 if (sourceFile === oldFile)
162136 return "continue";
162137 var _loop_20 = function (statement) {
162138 forEachImportInStatement(statement, function (importNode) {
162139 if (checker.getSymbolAtLocation(moduleSpecifierFromImport(importNode)) !== oldFile.symbol)
162140 return;
162141 var shouldMove = function (name) {
162142 var symbol = ts.isBindingElement(name.parent)
162143 ? ts.getPropertySymbolFromBindingElement(checker, name.parent)
162144 : ts.skipAlias(checker.getSymbolAtLocation(name), checker); // TODO: GH#18217
162145 return !!symbol && movedSymbols.has(symbol);
162146 };
162147 deleteUnusedImports(sourceFile, importNode, changes, shouldMove); // These will be changed to imports from the new file
162148 var newModuleSpecifier = ts.combinePaths(ts.getDirectoryPath(moduleSpecifierFromImport(importNode).text), newModuleName);
162149 var newImportDeclaration = filterImport(importNode, ts.factory.createStringLiteral(newModuleSpecifier), shouldMove);
162150 if (newImportDeclaration)
162151 changes.insertNodeAfter(sourceFile, statement, newImportDeclaration);
162152 var ns = getNamespaceLikeImport(importNode);
162153 if (ns)
162154 updateNamespaceLikeImport(changes, sourceFile, checker, movedSymbols, newModuleName, newModuleSpecifier, ns, importNode);
162155 });
162156 };
162157 for (var _b = 0, _c = sourceFile.statements; _b < _c.length; _b++) {
162158 var statement = _c[_b];
162159 _loop_20(statement);
162160 }
162161 };
162162 for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
162163 var sourceFile = _a[_i];
162164 _loop_19(sourceFile);
162165 }
162166 }
162167 function getNamespaceLikeImport(node) {
162168 switch (node.kind) {
162169 case 266 /* SyntaxKind.ImportDeclaration */:

Callers 1

Calls 1

_loop_19Function · 0.85

Tested by

no test coverage detected