diff --git a/lib/6to5/generation/generators/modules.js b/lib/6to5/generation/generators/modules.js index 871afe085f..16f6a01d83 100644 --- a/lib/6to5/generation/generators/modules.js +++ b/lib/6to5/generation/generators/modules.js @@ -1,7 +1,14 @@ var t = require("../../types"); var _ = require("lodash"); -exports.ImportSpecifier = +exports.ImportSpecifier = function (node, print) { + if (node.id && node.id.name === "default") { + print(node.name); + } else { + return exports.ExportSpecifier.apply(this, arguments); + } +}; + exports.ExportSpecifier = function (node, print) { print(node.id); if (node.name) { @@ -62,7 +69,9 @@ exports.ImportDeclaration = function (node, print) { self.push(", "); } - if (!spec.default && spec.type !== "ImportBatchSpecifier" && !foundImportSpecifier) { + var isDefault = spec.id && spec.id.name === "default"; + + if (!isDefault && spec.type !== "ImportBatchSpecifier" && !foundImportSpecifier) { foundImportSpecifier = true; self.push("{ "); } diff --git a/test/fixtures/generation/types/ImportDeclaration-ImportSpecifier-ImportBatchSpecifier/expected.js b/test/fixtures/generation/types/ImportDeclaration-ImportSpecifier-ImportBatchSpecifier/expected.js index b7a4a4b9fd..ed9cfef590 100644 --- a/test/fixtures/generation/types/ImportDeclaration-ImportSpecifier-ImportBatchSpecifier/expected.js +++ b/test/fixtures/generation/types/ImportDeclaration-ImportSpecifier-ImportBatchSpecifier/expected.js @@ -1,6 +1,6 @@ import "foo"; import foo from "foo"; -import { default as foo } from "foo"; +import foo from "foo"; import * as foo from "foo"; import foo, { baz as xyz } from "foo"; import { bar } from "foo";