Skip to content

Commit 728a92e

Browse files
author
Kanchalai Tanglertsampan
committed
Handle when namespace improt is malform and external module is undefined
1 parent e5a0f60 commit 728a92e

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

src/compiler/transformers/module/module.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,20 @@ namespace ts {
359359

360360
// Find the name of the module alias, if there is one
361361
const importAliasName = getLocalNameForExternalImport(importNode, currentSourceFile);
362-
if (includeNonAmdDependencies && importAliasName) {
363-
// Set emitFlags on the name of the classDeclaration
364-
// This is so that when printer will not substitute the identifier
365-
setEmitFlags(importAliasName, EmitFlags.NoSubstitution);
366-
aliasedModuleNames.push(externalModuleName);
367-
importAliasNames.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, importAliasName));
368-
}
369-
else {
370-
unaliasedModuleNames.push(externalModuleName);
362+
// It is possible that externalModuleName is undefined if it is not string literal.
363+
// This can happen in the invalid import syntax.
364+
// E.g : "import * from alias from 'someLib';"
365+
if (externalModuleName) {
366+
if (includeNonAmdDependencies && importAliasName) {
367+
// Set emitFlags on the name of the classDeclaration
368+
// This is so that when printer will not substitute the identifier
369+
setEmitFlags(importAliasName, EmitFlags.NoSubstitution);
370+
aliasedModuleNames.push(externalModuleName);
371+
importAliasNames.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, importAliasName));
372+
}
373+
else {
374+
unaliasedModuleNames.push(externalModuleName);
375+
}
371376
}
372377
}
373378

src/compiler/transformers/module/system.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,20 @@ namespace ts {
151151
for (let i = 0; i < externalImports.length; i++) {
152152
const externalImport = externalImports[i];
153153
const externalModuleName = getExternalModuleNameLiteral(externalImport, currentSourceFile, host, resolver, compilerOptions);
154-
const text = externalModuleName.text;
155-
const groupIndex = groupIndices.get(text);
156-
if (groupIndex !== undefined) {
157-
// deduplicate/group entries in dependency list by the dependency name
158-
dependencyGroups[groupIndex].externalImports.push(externalImport);
159-
}
160-
else {
161-
groupIndices.set(text, dependencyGroups.length);
162-
dependencyGroups.push({
163-
name: externalModuleName,
164-
externalImports: [externalImport]
165-
});
154+
if (externalModuleName) {
155+
const text = externalModuleName.text;
156+
const groupIndex = groupIndices.get(text);
157+
if (groupIndex !== undefined) {
158+
// deduplicate/group entries in dependency list by the dependency name
159+
dependencyGroups[groupIndex].externalImports.push(externalImport);
160+
}
161+
else {
162+
groupIndices.set(text, dependencyGroups.length);
163+
dependencyGroups.push({
164+
name: externalModuleName,
165+
externalImports: [externalImport]
166+
});
167+
}
166168
}
167169
}
168170

0 commit comments

Comments
 (0)