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

Function replaceImportUseSites

test/fixtures/snapshot/typescript.js:152397–152413  ·  view source on GitHub ↗
(nodeOrNodes, useSitesToUnqualify)

Source from the content-addressed store, hash-verified

152395 }
152396 }
152397 function replaceImportUseSites(nodeOrNodes, useSitesToUnqualify) {
152398 if (!useSitesToUnqualify || !ts.some(ts.arrayFrom(useSitesToUnqualify.keys()), function (original) { return ts.rangeContainsRange(nodeOrNodes, original); })) {
152399 return nodeOrNodes;
152400 }
152401 return ts.isArray(nodeOrNodes)
152402 ? ts.getSynthesizedDeepClonesWithReplacements(nodeOrNodes, /*includeTrivia*/ true, replaceNode)
152403 : ts.getSynthesizedDeepCloneWithReplacements(nodeOrNodes, /*includeTrivia*/ true, replaceNode);
152404 function replaceNode(original) {
152405 // We are replacing `mod.SomeExport` wih `SomeExport`, so we only need to look at PropertyAccessExpressions
152406 if (original.kind === 206 /* SyntaxKind.PropertyAccessExpression */) {
152407 var replacement = useSitesToUnqualify.get(original);
152408 // Remove entry from `useSitesToUnqualify` so the refactor knows it's taken care of by the parent statement we're replacing
152409 useSitesToUnqualify.delete(original);
152410 return replacement;
152411 }
152412 }
152413 }
152414 /**
152415 * Converts `const <<name>> = require("x");`.
152416 * Returns nodes that will replace the variable declaration for the commonjs import.

Callers 3

exportConstFunction · 0.85

Calls 2

someMethod · 0.80
keysMethod · 0.65

Tested by

no test coverage detected