From 5534f99a9605e8b6b931b1cd2925de545d674ad2 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 10 Oct 2014 16:05:41 +1100 Subject: [PATCH] add comments to display what module syntax each part handles --- lib/6to5/transformers/modules.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/6to5/transformers/modules.js b/lib/6to5/transformers/modules.js index fe1d37e70a..4aa89a3c70 100644 --- a/lib/6to5/transformers/modules.js +++ b/lib/6to5/transformers/modules.js @@ -8,7 +8,7 @@ exports.ImportDeclaration = function (node) { if (node.specifiers.length) { _.each(node.specifiers, function (specifier) { - var variableName = specifier.name || specifier.id; + var variableName = getSpecifierName(specifier.name); var key = specifier.id.name; // import foo from "foo"; @@ -28,6 +28,7 @@ exports.ImportDeclaration = function (node) { })); }); } else { + // import "foo"; nodes.push(util.template("require", { MODULE_NAME: node.source.raw }, true)); @@ -38,14 +39,16 @@ exports.ImportDeclaration = function (node) { var pushExportSpecifiers = function (node, nodes) { _.each(node.specifiers, function (specifier) { - var variableName = specifier.name || specifier.id; + var variableName = getSpecifierName(specifier); if (node.source) { if (specifier.type === "ExportBatchSpecifier") { + // export * from "foo"; nodes.push(util.template("exports-wildcard", { MODULE_NAME: node.source.raw }, true)); } else { + // export { foo } from "test"; nodes.push(util.template("exports-require-assign-key", { VARIABLE_NAME: variableName.name, MODULE_NAME: node.source.raw, @@ -53,6 +56,7 @@ var pushExportSpecifiers = function (node, nodes) { }, true)); } } else { + // export { foo }; nodes.push(util.template("exports-assign", { VALUE: specifier.id, KEY: variableName @@ -61,6 +65,10 @@ var pushExportSpecifiers = function (node, nodes) { }); }; +var getSpecifierName = function (specifier) { + return specifier.name || specifier.id; +}; + var pushExportDeclaration = function (node, parent, nodes) { var declar = node.declaration;