Handle when namespace improt is malform and external module is undefined

This commit is contained in:
Kanchalai Tanglertsampan 2017-03-29 13:08:13 -07:00
parent e5a0f60d4c
commit 728a92ec1a
2 changed files with 28 additions and 21 deletions

View file

@ -359,6 +359,10 @@ namespace ts {
// Find the name of the module alias, if there is one
const importAliasName = getLocalNameForExternalImport(importNode, currentSourceFile);
// 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
@ -370,6 +374,7 @@ namespace ts {
unaliasedModuleNames.push(externalModuleName);
}
}
}
return { aliasedModuleNames, unaliasedModuleNames, importAliasNames };
}

View file

@ -151,6 +151,7 @@ namespace ts {
for (let i = 0; i < externalImports.length; i++) {
const externalImport = externalImports[i];
const externalModuleName = getExternalModuleNameLiteral(externalImport, currentSourceFile, host, resolver, compilerOptions);
if (externalModuleName) {
const text = externalModuleName.text;
const groupIndex = groupIndices.get(text);
if (groupIndex !== undefined) {
@ -165,6 +166,7 @@ namespace ts {
});
}
}
}
return dependencyGroups;
}