add comments to display what module syntax each part handles

This commit is contained in:
Sebastian McKenzie
2014-10-10 16:05:41 +11:00
parent 2403e8bec2
commit 5534f99a96

View File

@@ -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;