diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index b620be2ed5e..e35c5a08297 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1708,6 +1708,9 @@ namespace ts { return nodes; } + /** + * Get the name of that target module from an import or export declaration + */ export function getLocalNameForExternalImport(node: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration, sourceFile: SourceFile): Identifier { const namespaceDeclaration = getNamespaceDeclarationNode(node); if (namespaceDeclaration && !isDefaultImport(node)) { @@ -1719,8 +1722,17 @@ namespace ts { if (node.kind === SyntaxKind.ExportDeclaration && (node).moduleSpecifier) { return getGeneratedNameForNode(node); } + return undefined; } + /** + * Get the name of a target module from an import/export declaration as should be written in the emitted output. + * The emitted output name can be different from the input if: + * 1. The module has a /// + * 2. --out or --outFile is used, making the name relative to the rootDir + * 3- The containing SourceFile has an entry in renamedDependencies for the import as requested by some module loaders (e.g. System). + * Otherwise, a new StringLiteral node representing the module name will be returned. + */ export function getExternalModuleNameLiteral(importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration, sourceFile: SourceFile, host: EmitHost, resolver: EmitResolver, compilerOptions: CompilerOptions) { const moduleName = getExternalModuleName(importNode); if (moduleName.kind === SyntaxKind.StringLiteral) { @@ -1743,6 +1755,13 @@ namespace ts { return undefined; } + /** + * Get the name of a module as should be written in the emitted output. + * The emitted output name can be different from the input if: + * 1. The module has a /// + * 2. --out or --outFile is used, making the name relative to the rootDir + * Otherwise, a new StringLiteral node representing the module name will be returned. + */ export function tryGetModuleNameFromFile(file: SourceFile, host: EmitHost, options: CompilerOptions): StringLiteral { if (!file) { return undefined;