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,15 +359,20 @@ namespace ts {
// Find the name of the module alias, if there is one // Find the name of the module alias, if there is one
const importAliasName = getLocalNameForExternalImport(importNode, currentSourceFile); const importAliasName = getLocalNameForExternalImport(importNode, currentSourceFile);
if (includeNonAmdDependencies && importAliasName) { // It is possible that externalModuleName is undefined if it is not string literal.
// Set emitFlags on the name of the classDeclaration // This can happen in the invalid import syntax.
// This is so that when printer will not substitute the identifier // E.g : "import * from alias from 'someLib';"
setEmitFlags(importAliasName, EmitFlags.NoSubstitution); if (externalModuleName) {
aliasedModuleNames.push(externalModuleName); if (includeNonAmdDependencies && importAliasName) {
importAliasNames.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, importAliasName)); // Set emitFlags on the name of the classDeclaration
} // This is so that when printer will not substitute the identifier
else { setEmitFlags(importAliasName, EmitFlags.NoSubstitution);
unaliasedModuleNames.push(externalModuleName); aliasedModuleNames.push(externalModuleName);
importAliasNames.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, importAliasName));
}
else {
unaliasedModuleNames.push(externalModuleName);
}
} }
} }

View file

@ -151,18 +151,20 @@ namespace ts {
for (let i = 0; i < externalImports.length; i++) { for (let i = 0; i < externalImports.length; i++) {
const externalImport = externalImports[i]; const externalImport = externalImports[i];
const externalModuleName = getExternalModuleNameLiteral(externalImport, currentSourceFile, host, resolver, compilerOptions); const externalModuleName = getExternalModuleNameLiteral(externalImport, currentSourceFile, host, resolver, compilerOptions);
const text = externalModuleName.text; if (externalModuleName) {
const groupIndex = groupIndices.get(text); const text = externalModuleName.text;
if (groupIndex !== undefined) { const groupIndex = groupIndices.get(text);
// deduplicate/group entries in dependency list by the dependency name if (groupIndex !== undefined) {
dependencyGroups[groupIndex].externalImports.push(externalImport); // deduplicate/group entries in dependency list by the dependency name
} dependencyGroups[groupIndex].externalImports.push(externalImport);
else { }
groupIndices.set(text, dependencyGroups.length); else {
dependencyGroups.push({ groupIndices.set(text, dependencyGroups.length);
name: externalModuleName, dependencyGroups.push({
externalImports: [externalImport] name: externalModuleName,
}); externalImports: [externalImport]
});
}
} }
} }