@@ -14978,14 +14978,14 @@ func (c *Checker) resolveESModuleSymbol(moduleSymbol *ast.Symbol, referencingLoc
14978
14978
return exportModuleDotExportsSymbol
14979
14979
}
14980
14980
14981
- isEsmCjsRef := targetFile != nil && usageMode == core.ModuleKindESNext && c.program.GetImpliedNodeFormatForEmit(targetFile.AsSourceFile()) == core.ModuleKindCommonJS
14981
+ isEsmCjsRef := targetFile != nil && isESMFormatImportImportingCommonjsFormatFile( usageMode, c.program.GetImpliedNodeFormatForEmit(targetFile.AsSourceFile()))
14982
14982
if c.compilerOptions.GetESModuleInterop() || isEsmCjsRef {
14983
14983
if c.hasSignatures(typ) || c.getPropertyOfTypeEx(typ, ast.InternalSymbolNameDefault, true /*skipObjectFunctionPropertyAugment*/, false /*includeTypeOnlyMembers*/) != nil || isEsmCjsRef {
14984
14984
var moduleType *Type
14985
14985
if typ.Flags()&TypeFlagsStructuredType != 0 {
14986
14986
moduleType = c.getTypeWithSyntheticDefaultImportType(typ, symbol, moduleSymbol, reference)
14987
14987
} else {
14988
- moduleType = c.createDefaultPropertyWrapperForModule(symbol, moduleSymbol , nil)
14988
+ moduleType = c.createDefaultPropertyWrapperForModule(symbol, symbol.Parent , nil)
14989
14989
}
14990
14990
return c.cloneTypeAsModuleType(symbol, moduleType, referenceParent)
14991
14991
}
@@ -14999,6 +14999,10 @@ func (c *Checker) hasSignatures(t *Type) bool {
14999
14999
return len(c.getSignaturesOfStructuredType(t, SignatureKindCall)) > 0 || len(c.getSignaturesOfStructuredType(t, SignatureKindConstruct)) > 0
15000
15000
}
15001
15001
15002
+ func isESMFormatImportImportingCommonjsFormatFile(usageMode core.ResolutionMode, targetMode core.ResolutionMode) bool {
15003
+ return usageMode == core.ModuleKindESNext && targetMode == core.ModuleKindCommonJS
15004
+ }
15005
+
15002
15006
func (c *Checker) getTypeWithSyntheticDefaultOnly(t *Type, symbol *ast.Symbol, originalSymbol *ast.Symbol, moduleSpecifier *ast.Node) *Type {
15003
15007
hasDefaultOnly := c.isOnlyImportableAsDefault(moduleSpecifier, nil)
15004
15008
if hasDefaultOnly && t != nil && !c.isErrorType(t) {
0 commit comments