MCPcopy Index your code
hub / github.com/nodejs/node / resolveESModuleSymbol

Function resolveESModuleSymbol

test/fixtures/snapshot/typescript.js:51347–51384  ·  view source on GitHub ↗
(moduleSymbol, referencingLocation, dontResolveAlias, suppressInteropError)

Source from the content-addressed store, hash-verified

51345 // references a symbol that is at least declared as a module or a variable. The target of the 'export =' may
51346 // combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable).
51347 function resolveESModuleSymbol(moduleSymbol, referencingLocation, dontResolveAlias, suppressInteropError) {
51348 var _a;
51349 var symbol = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias);
51350 if (!dontResolveAlias && symbol) {
51351 if (!suppressInteropError && !(symbol.flags & (1536 /* SymbolFlags.Module */ | 3 /* SymbolFlags.Variable */)) && !ts.getDeclarationOfKind(symbol, 305 /* SyntaxKind.SourceFile */)) {
51352 var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015
51353 ? "allowSyntheticDefaultImports"
51354 : "esModuleInterop";
51355 error(referencingLocation, ts.Diagnostics.This_module_can_only_be_referenced_with_ECMAScript_imports_Slashexports_by_turning_on_the_0_flag_and_referencing_its_default_export, compilerOptionName);
51356 return symbol;
51357 }
51358 var referenceParent = referencingLocation.parent;
51359 if ((ts.isImportDeclaration(referenceParent) && ts.getNamespaceDeclarationNode(referenceParent)) ||
51360 ts.isImportCall(referenceParent)) {
51361 var reference = ts.isImportCall(referenceParent) ? referenceParent.arguments[0] : referenceParent.moduleSpecifier;
51362 var type = getTypeOfSymbol(symbol);
51363 var defaultOnlyType = getTypeWithSyntheticDefaultOnly(type, symbol, moduleSymbol, reference);
51364 if (defaultOnlyType) {
51365 return cloneTypeAsModuleType(symbol, defaultOnlyType, referenceParent);
51366 }
51367 var targetFile = (_a = moduleSymbol === null || moduleSymbol === void 0 ? void 0 : moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
51368 var isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getUsageModeForExpression(reference), targetFile.impliedNodeFormat);
51369 if (ts.getESModuleInterop(compilerOptions) || isEsmCjsRef) {
51370 var sigs = getSignaturesOfStructuredType(type, 0 /* SignatureKind.Call */);
51371 if (!sigs || !sigs.length) {
51372 sigs = getSignaturesOfStructuredType(type, 1 /* SignatureKind.Construct */);
51373 }
51374 if ((sigs && sigs.length) ||
51375 getPropertyOfType(type, "default" /* InternalSymbolName.Default */, /*skipObjectFunctionPropertyAugment*/ true) ||
51376 isEsmCjsRef) {
51377 var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, reference);
51378 return cloneTypeAsModuleType(symbol, moduleType, referenceParent);
51379 }
51380 }
51381 }
51382 }
51383 return symbol;
51384 }
51385 /**
51386 * Create a new symbol which has the module's type less the call and construct signatures
51387 */

Callers 4

getExternalModuleMemberFunction · 0.85

Calls 11

getTypeOfSymbolFunction · 0.85
cloneTypeAsModuleTypeFunction · 0.85
getPropertyOfTypeFunction · 0.85
errorFunction · 0.70
findMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…