(moduleSymbol *ast.Symbol, node *ast.Node, dontResolveAlias bool)
| 14460 | } |
| 14461 | |
| 14462 | func (c *Checker) getTargetOfModuleDefault(moduleSymbol *ast.Symbol, node *ast.Node, dontResolveAlias bool) *ast.Symbol { |
| 14463 | file := core.Find(moduleSymbol.Declarations, ast.IsSourceFile) |
| 14464 | specifier := c.getModuleSpecifierForImportOrExport(node) |
| 14465 | var exportDefaultSymbol *ast.Symbol |
| 14466 | var exportModuleDotExportsSymbol *ast.Symbol |
| 14467 | if isShorthandAmbientModuleSymbol(moduleSymbol) { |
| 14468 | // !!! exportDefaultSymbol = moduleSymbol |
| 14469 | // Does nothing? |
| 14470 | } else if file != nil && specifier != nil && |
| 14471 | core.ModuleKindNode20 <= c.moduleKind && c.moduleKind <= core.ModuleKindNodeNext && |
| 14472 | c.getEmitSyntaxForModuleSpecifierExpression(specifier) == core.ModuleKindCommonJS && |
| 14473 | c.program.GetImpliedNodeFormatForEmit(file.AsSourceFile()) == core.ModuleKindESNext { |
| 14474 | exportModuleDotExportsSymbol = c.resolveExportByName(moduleSymbol, ast.InternalSymbolNameModuleExports, node, dontResolveAlias) |
| 14475 | } |
| 14476 | if exportModuleDotExportsSymbol != nil { |
| 14477 | // We have a transpiled default import where the `require` resolves to an ES module with a `module.exports` named |
| 14478 | // export. With `esModuleInterop` (always enabled), this will work: |
| 14479 | // |
| 14480 | // const dep_1 = __importDefault(require("./dep.mjs")); // wraps like { default: require("./dep.mjs") } |
| 14481 | // dep_1.default; // require("./dep.mjs") -> the `module.exports` export value |
| 14482 | c.markSymbolOfAliasDeclarationIfTypeOnly(node, nil) |
| 14483 | return exportModuleDotExportsSymbol |
| 14484 | } else { |
| 14485 | exportDefaultSymbol = c.resolveExportByName(moduleSymbol, ast.InternalSymbolNameDefault, node, dontResolveAlias) |
| 14486 | } |
| 14487 | if specifier == nil { |
| 14488 | return exportDefaultSymbol |
| 14489 | } |
| 14490 | hasDefaultOnly := c.isOnlyImportableAsDefault(specifier, moduleSymbol) |
| 14491 | hasSyntheticDefault := c.canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier) |
| 14492 | if exportDefaultSymbol == nil && !hasSyntheticDefault && !hasDefaultOnly { |
| 14493 | if ast.IsImportClause(node) { |
| 14494 | c.reportNonDefaultExport(moduleSymbol, node) |
| 14495 | } else { |
| 14496 | var name *ast.Node |
| 14497 | if ast.IsImportOrExportSpecifier(node) { |
| 14498 | name = node.PropertyNameOrName() |
| 14499 | } else { |
| 14500 | name = node.Name() |
| 14501 | } |
| 14502 | c.errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, name) |
| 14503 | } |
| 14504 | } else if hasSyntheticDefault || hasDefaultOnly { |
| 14505 | // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present |
| 14506 | resolved := c.resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) |
| 14507 | if resolved == nil { |
| 14508 | resolved = c.resolveSymbolEx(moduleSymbol, dontResolveAlias) |
| 14509 | } |
| 14510 | c.markSymbolOfAliasDeclarationIfTypeOnly(node, nil) |
| 14511 | return resolved |
| 14512 | } |
| 14513 | c.markSymbolOfAliasDeclarationIfTypeOnly(node, nil) |
| 14514 | return exportDefaultSymbol |
| 14515 | } |
| 14516 | |
| 14517 | func (c *Checker) reportNonDefaultExport(moduleSymbol *ast.Symbol, node *ast.Node) { |
| 14518 | if moduleSymbol.Exports != nil && moduleSymbol.Exports[node.Symbol().Name] != nil { |
no test coverage detected