Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getExternsForExternalModules(tsccSpec: ITsccSpecWithTS, tsickleHost: TsickleHost): string {
const moduleNames = tsccSpec.getExternalModuleNames();
const toGlobalName = tsccSpec.getExternalModuleNamesToGlobalsMap();
const header = `\n/** Generated by TSCC */`
let out = '';
for (let moduleName of moduleNames) {
// If a module's type definition is from node_modules, its path is used as a namespace.
// otherwise, it comes from declare module '...' in user-provided files, in which the module name string
// is used as a namespace.
let typeRefFile = tsccSpec.resolveExternalModuleTypeReference(moduleName) || moduleName;
out += `
/**
* @type{${moduleNameAsIdentifier(tsickleHost, typeRefFile)}}
* @const
*/
${tsickleHost.es5Mode ? 'var' : 'const'} ${toGlobalName[moduleName]} = {};\n`;
}
if (out.length) out = header + out;
return out;
}