From 728a92ec1ab26a96175ccf5e2c8926101b624b8a Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 29 Mar 2017 13:08:13 -0700 Subject: [PATCH] Handle when namespace improt is malform and external module is undefined --- src/compiler/transformers/module/module.ts | 23 +++++++++++-------- src/compiler/transformers/module/system.ts | 26 ++++++++++++---------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 4ef9c674ad..81ed20bd4e 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -359,15 +359,20 @@ namespace ts { // Find the name of the module alias, if there is one const importAliasName = getLocalNameForExternalImport(importNode, currentSourceFile); - if (includeNonAmdDependencies && importAliasName) { - // Set emitFlags on the name of the classDeclaration - // This is so that when printer will not substitute the identifier - setEmitFlags(importAliasName, EmitFlags.NoSubstitution); - aliasedModuleNames.push(externalModuleName); - importAliasNames.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, importAliasName)); - } - else { - unaliasedModuleNames.push(externalModuleName); + // It is possible that externalModuleName is undefined if it is not string literal. + // This can happen in the invalid import syntax. + // E.g : "import * from alias from 'someLib';" + if (externalModuleName) { + if (includeNonAmdDependencies && importAliasName) { + // Set emitFlags on the name of the classDeclaration + // This is so that when printer will not substitute the identifier + setEmitFlags(importAliasName, EmitFlags.NoSubstitution); + aliasedModuleNames.push(externalModuleName); + importAliasNames.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, importAliasName)); + } + else { + unaliasedModuleNames.push(externalModuleName); + } } } diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 3daeee1e6d..56341f482f 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -151,18 +151,20 @@ namespace ts { for (let i = 0; i < externalImports.length; i++) { const externalImport = externalImports[i]; const externalModuleName = getExternalModuleNameLiteral(externalImport, currentSourceFile, host, resolver, compilerOptions); - const text = externalModuleName.text; - const groupIndex = groupIndices.get(text); - if (groupIndex !== undefined) { - // deduplicate/group entries in dependency list by the dependency name - dependencyGroups[groupIndex].externalImports.push(externalImport); - } - else { - groupIndices.set(text, dependencyGroups.length); - dependencyGroups.push({ - name: externalModuleName, - externalImports: [externalImport] - }); + if (externalModuleName) { + const text = externalModuleName.text; + const groupIndex = groupIndices.get(text); + if (groupIndex !== undefined) { + // deduplicate/group entries in dependency list by the dependency name + dependencyGroups[groupIndex].externalImports.push(externalImport); + } + else { + groupIndices.set(text, dependencyGroups.length); + dependencyGroups.push({ + name: externalModuleName, + externalImports: [externalImport] + }); + } } }