(file, moduleSymbol, dontResolveAlias, usage)
| 50444 | return usageMode === ts.ModuleKind.ESNext && ts.endsWith(usage.text, ".json" /* Extension.Json */); |
| 50445 | } |
| 50446 | function canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, usage) { |
| 50447 | var usageMode = file && getUsageModeForExpression(usage); |
| 50448 | if (file && usageMode !== undefined) { |
| 50449 | var result = isESMFormatImportImportingCommonjsFormatFile(usageMode, file.impliedNodeFormat); |
| 50450 | if (usageMode === ts.ModuleKind.ESNext || result) { |
| 50451 | return result; |
| 50452 | } |
| 50453 | // fallthrough on cjs usages so we imply defaults for interop'd imports, too |
| 50454 | } |
| 50455 | if (!allowSyntheticDefaultImports) { |
| 50456 | return false; |
| 50457 | } |
| 50458 | // Declaration files (and ambient modules) |
| 50459 | if (!file || file.isDeclarationFile) { |
| 50460 | // Definitely cannot have a synthetic default if they have a syntactic default member specified |
| 50461 | var defaultExportSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, /*sourceNode*/ undefined, /*dontResolveAlias*/ true); // Dont resolve alias because we want the immediately exported symbol's declaration |
| 50462 | if (defaultExportSymbol && ts.some(defaultExportSymbol.declarations, isSyntacticDefault)) { |
| 50463 | return false; |
| 50464 | } |
| 50465 | // It _might_ still be incorrect to assume there is no __esModule marker on the import at runtime, even if there is no `default` member |
| 50466 | // So we check a bit more, |
| 50467 | if (resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias)) { |
| 50468 | // If there is an `__esModule` specified in the declaration (meaning someone explicitly added it or wrote it in their code), |
| 50469 | // it definitely is a module and does not have a synthetic default |
| 50470 | return false; |
| 50471 | } |
| 50472 | // There are _many_ declaration files not written with esmodules in mind that still get compiled into a format with __esModule set |
| 50473 | // Meaning there may be no default at runtime - however to be on the permissive side, we allow access to a synthetic default member |
| 50474 | // as there is no marker to indicate if the accompanying JS has `__esModule` or not, or is even native esm |
| 50475 | return true; |
| 50476 | } |
| 50477 | // TypeScript files never have a synthetic default (as they are always emitted with an __esModule marker) _unless_ they contain an export= statement |
| 50478 | if (!ts.isSourceFileJS(file)) { |
| 50479 | return hasExportAssignmentSymbol(moduleSymbol); |
| 50480 | } |
| 50481 | // JS files have a synthetic default if they do not contain ES2015+ module syntax (export = is not valid in js) _and_ do not have an __esModule marker |
| 50482 | return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); |
| 50483 | } |
| 50484 | function getTargetOfImportClause(node, dontResolveAlias) { |
| 50485 | var _a; |
| 50486 | var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); |
no test coverage detected