MCPcopy Index your code
hub / github.com/nodejs/node / convertFileToEsModule

Function convertFileToEsModule

test/fixtures/snapshot/typescript.js:152130–152155  ·  view source on GitHub ↗

@returns Whether we converted a `module.exports =` to a default export.

(sourceFile, checker, changes, target, quotePreference)

Source from the content-addressed store, hash-verified

152128 }
152129 /** @returns Whether we converted a `module.exports =` to a default export. */
152130 function convertFileToEsModule(sourceFile, checker, changes, target, quotePreference) {
152131 var identifiers = { original: collectFreeIdentifiers(sourceFile), additional: new ts.Set() };
152132 var exports = collectExportRenames(sourceFile, checker, identifiers);
152133 convertExportsAccesses(sourceFile, exports, changes);
152134 var moduleExportsChangedToDefault = false;
152135 var useSitesToUnqualify;
152136 // Process variable statements first to collect use sites that need to be updated inside other transformations
152137 for (var _i = 0, _a = ts.filter(sourceFile.statements, ts.isVariableStatement); _i < _a.length; _i++) {
152138 var statement = _a[_i];
152139 var newUseSites = convertVariableStatement(sourceFile, statement, changes, checker, identifiers, target, quotePreference);
152140 if (newUseSites) {
152141 ts.copyEntries(newUseSites, useSitesToUnqualify !== null && useSitesToUnqualify !== void 0 ? useSitesToUnqualify : (useSitesToUnqualify = new ts.Map()));
152142 }
152143 }
152144 // `convertStatement` will delete entries from `useSitesToUnqualify` when containing statements are replaced
152145 for (var _b = 0, _c = ts.filter(sourceFile.statements, function (s) { return !ts.isVariableStatement(s); }); _b < _c.length; _b++) {
152146 var statement = _c[_b];
152147 var moduleExportsChanged = convertStatement(sourceFile, statement, checker, changes, identifiers, target, exports, useSitesToUnqualify, quotePreference);
152148 moduleExportsChangedToDefault = moduleExportsChangedToDefault || moduleExportsChanged;
152149 }
152150 // Remaining use sites can be changed directly
152151 useSitesToUnqualify === null || useSitesToUnqualify === void 0 ? void 0 : useSitesToUnqualify.forEach(function (replacement, original) {
152152 changes.replaceNode(sourceFile, original, replacement);
152153 });
152154 return moduleExportsChangedToDefault;
152155 }
152156 function collectExportRenames(sourceFile, checker, identifiers) {
152157 var res = new ts.Map();
152158 forEachExportReference(sourceFile, function (node) {

Callers 1

typescript.jsFile · 0.85

Calls 7

collectFreeIdentifiersFunction · 0.85
collectExportRenamesFunction · 0.85
convertExportsAccessesFunction · 0.85
convertVariableStatementFunction · 0.85
convertStatementFunction · 0.85
filterMethod · 0.65
forEachMethod · 0.65

Tested by

no test coverage detected