diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 299ac0a2b6c..d4271c23830 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5004,6 +5004,10 @@ module ts { } } + function isDefaultImport(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration) { + return node.kind === SyntaxKind.ImportDeclaration && (node).importClause && !!(node).importClause.name; + } + function emitExportImportAssignments(node: Node) { if (isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { emitExportMemberAssignments((node).name); @@ -5018,8 +5022,7 @@ module ts { if (compilerOptions.module !== ModuleKind.AMD) { emitLeadingComments(node); emitStart(node); - let isDefaultImport = node.kind === SyntaxKind.ImportDeclaration && (node).importClause && !!(node).importClause.name; - if (namespaceDeclaration && !isDefaultImport) { + if (namespaceDeclaration && !isDefaultImport(node)) { // import x = require("foo") // import * as x from "foo" if (!isExportedImport) write("var "); @@ -5040,7 +5043,7 @@ module ts { } } emitRequire(getExternalModuleName(node)); - if (namespaceDeclaration && isDefaultImport) { + if (namespaceDeclaration && isDefaultImport(node)) { // import d, * as x from "foo" write(", "); emitModuleMemberName(namespaceDeclaration); @@ -5059,6 +5062,14 @@ module ts { emit(namespaceDeclaration.name); write(";"); } + else if (namespaceDeclaration && isDefaultImport(node)) { + // import d, * as x from "foo" + write("var "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + write(resolver.getGeneratedNameForNode(node)); + write(";"); + } emitExportImportAssignments(node); } } @@ -5249,7 +5260,7 @@ module ts { for (let importNode of externalImports) { write(", "); let namespaceDeclaration = getNamespaceDeclarationNode(importNode); - if (namespaceDeclaration) { + if (namespaceDeclaration && !isDefaultImport(importNode)) { emit(namespaceDeclaration.name); } else {