How to use the tsickle/src/annotator_host.moduleNameAsIdentifier function in tsickle

To help you get started, we’ve selected a few tsickle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github theseanl / tscc / packages / tscc / src / transformer / externalModuleTransformer.ts View on Github external
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;
}