Skip to content

Commit 580bb83

Browse files
committed
Fix issue with AMD emit for 'import d, * as x from "foo"'
1 parent 6074b3e commit 580bb83

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/compiler/emitter.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5004,6 +5004,10 @@ module ts {
50045004
}
50055005
}
50065006

5007+
function isDefaultImport(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration) {
5008+
return node.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node).importClause && !!(<ImportDeclaration>node).importClause.name;
5009+
}
5010+
50075011
function emitExportImportAssignments(node: Node) {
50085012
if (isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) {
50095013
emitExportMemberAssignments(<Identifier>(<Declaration>node).name);
@@ -5018,8 +5022,7 @@ module ts {
50185022
if (compilerOptions.module !== ModuleKind.AMD) {
50195023
emitLeadingComments(node);
50205024
emitStart(node);
5021-
let isDefaultImport = node.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node).importClause && !!(<ImportDeclaration>node).importClause.name;
5022-
if (namespaceDeclaration && !isDefaultImport) {
5025+
if (namespaceDeclaration && !isDefaultImport(node)) {
50235026
// import x = require("foo")
50245027
// import * as x from "foo"
50255028
if (!isExportedImport) write("var ");
@@ -5040,7 +5043,7 @@ module ts {
50405043
}
50415044
}
50425045
emitRequire(getExternalModuleName(node));
5043-
if (namespaceDeclaration && isDefaultImport) {
5046+
if (namespaceDeclaration && isDefaultImport(node)) {
50445047
// import d, * as x from "foo"
50455048
write(", ");
50465049
emitModuleMemberName(namespaceDeclaration);
@@ -5059,6 +5062,14 @@ module ts {
50595062
emit(namespaceDeclaration.name);
50605063
write(";");
50615064
}
5065+
else if (namespaceDeclaration && isDefaultImport(node)) {
5066+
// import d, * as x from "foo"
5067+
write("var ");
5068+
emitModuleMemberName(namespaceDeclaration);
5069+
write(" = ");
5070+
write(resolver.getGeneratedNameForNode(<ImportDeclaration>node));
5071+
write(";");
5072+
}
50625073
emitExportImportAssignments(node);
50635074
}
50645075
}
@@ -5249,7 +5260,7 @@ module ts {
52495260
for (let importNode of externalImports) {
52505261
write(", ");
52515262
let namespaceDeclaration = getNamespaceDeclarationNode(importNode);
5252-
if (namespaceDeclaration) {
5263+
if (namespaceDeclaration && !isDefaultImport(importNode)) {
52535264
emit(namespaceDeclaration.name);
52545265
}
52555266
else {

0 commit comments

Comments
 (0)