From 01934b69601c23e8c2384d0ba9d2c6acd7cbaf39 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 10 Dec 2014 23:18:23 +1100 Subject: [PATCH] fix default import generation --- lib/6to5/generation/generators/modules.js | 13 +++++++++++-- .../expected.js | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) 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";