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

Function getExportEqualsImportKind

test/fixtures/snapshot/typescript.js:153642–153670  ·  view source on GitHub ↗
(importingFile, compilerOptions, forceImportKeyword)

Source from the content-addressed store, hash-verified

153640 return originalSymbolToExportInfos;
153641 }
153642 function getExportEqualsImportKind(importingFile, compilerOptions, forceImportKeyword) {
153643 var allowSyntheticDefaults = ts.getAllowSyntheticDefaultImports(compilerOptions);
153644 var isJS = ts.isInJSFile(importingFile);
153645 // 1. 'import =' will not work in es2015+ TS files, so the decision is between a default
153646 // and a namespace import, based on allowSyntheticDefaultImports/esModuleInterop.
153647 if (!isJS && ts.getEmitModuleKind(compilerOptions) >= ts.ModuleKind.ES2015) {
153648 return allowSyntheticDefaults ? 1 /* ImportKind.Default */ : 2 /* ImportKind.Namespace */;
153649 }
153650 // 2. 'import =' will not work in JavaScript, so the decision is between a default import,
153651 // a namespace import, and const/require.
153652 if (isJS) {
153653 return ts.isExternalModule(importingFile) || forceImportKeyword
153654 ? allowSyntheticDefaults ? 1 /* ImportKind.Default */ : 2 /* ImportKind.Namespace */
153655 : 3 /* ImportKind.CommonJS */;
153656 }
153657 // 3. At this point the most correct choice is probably 'import =', but people
153658 // really hate that, so look to see if the importing file has any precedent
153659 // on how to handle it.
153660 for (var _i = 0, _a = importingFile.statements; _i < _a.length; _i++) {
153661 var statement = _a[_i];
153662 // `import foo` parses as an ImportEqualsDeclaration even though it could be an ImportDeclaration
153663 if (ts.isImportEqualsDeclaration(statement) && !ts.nodeIsMissing(statement.moduleReference)) {
153664 return 3 /* ImportKind.CommonJS */;
153665 }
153666 }
153667 // 4. We have no precedent to go on, so just use a default import if
153668 // allowSyntheticDefaultImports/esModuleInterop is enabled.
153669 return allowSyntheticDefaults ? 1 /* ImportKind.Default */ : 3 /* ImportKind.CommonJS */;
153670 }
153671 function codeActionForFix(context, sourceFile, symbolName, fix, includeSymbolNameInDescription, quotePreference, compilerOptions) {
153672 var diag;
153673 var changes = ts.textChanges.ChangeTracker.with(context, function (tracker) {

Callers 1

getImportKindFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected