(sourceFile, statement, changes, checker, identifiers, target, quotePreference)
| 152210 | } |
| 152211 | } |
| 152212 | function convertVariableStatement(sourceFile, statement, changes, checker, identifiers, target, quotePreference) { |
| 152213 | var declarationList = statement.declarationList; |
| 152214 | var foundImport = false; |
| 152215 | var converted = ts.map(declarationList.declarations, function (decl) { |
| 152216 | var name = decl.name, initializer = decl.initializer; |
| 152217 | if (initializer) { |
| 152218 | if (ts.isExportsOrModuleExportsOrAlias(sourceFile, initializer)) { |
| 152219 | // `const alias = module.exports;` can be removed. |
| 152220 | foundImport = true; |
| 152221 | return convertedImports([]); |
| 152222 | } |
| 152223 | else if (ts.isRequireCall(initializer, /*checkArgumentIsStringLiteralLike*/ true)) { |
| 152224 | foundImport = true; |
| 152225 | return convertSingleImport(name, initializer.arguments[0], checker, identifiers, target, quotePreference); |
| 152226 | } |
| 152227 | else if (ts.isPropertyAccessExpression(initializer) && ts.isRequireCall(initializer.expression, /*checkArgumentIsStringLiteralLike*/ true)) { |
| 152228 | foundImport = true; |
| 152229 | return convertPropertyAccessImport(name, initializer.name.text, initializer.expression.arguments[0], identifiers, quotePreference); |
| 152230 | } |
| 152231 | } |
| 152232 | // Move it out to its own variable statement. (This will not be used if `!foundImport`) |
| 152233 | return convertedImports([ts.factory.createVariableStatement(/*modifiers*/ undefined, ts.factory.createVariableDeclarationList([decl], declarationList.flags))]); |
| 152234 | }); |
| 152235 | if (foundImport) { |
| 152236 | // useNonAdjustedEndPosition to ensure we don't eat the newline after the statement. |
| 152237 | changes.replaceNodeWithNodes(sourceFile, statement, ts.flatMap(converted, function (c) { return c.newImports; })); |
| 152238 | var combinedUseSites_1; |
| 152239 | ts.forEach(converted, function (c) { |
| 152240 | if (c.useSitesToUnqualify) { |
| 152241 | ts.copyEntries(c.useSitesToUnqualify, combinedUseSites_1 !== null && combinedUseSites_1 !== void 0 ? combinedUseSites_1 : (combinedUseSites_1 = new ts.Map())); |
| 152242 | } |
| 152243 | }); |
| 152244 | return combinedUseSites_1; |
| 152245 | } |
| 152246 | } |
| 152247 | /** Converts `const name = require("moduleSpecifier").propertyName` */ |
| 152248 | function convertPropertyAccessImport(name, propertyName, moduleSpecifier, identifiers, quotePreference) { |
| 152249 | switch (name.kind) { |
no test coverage detected