Add custom export declaration fn for AMD modules
This commit is contained in:
parent
61c3e0a3de
commit
7ac98c1532
@ -96,6 +96,39 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
]));
|
||||
};
|
||||
|
||||
AMDFormatter.prototype.exportDeclaration = function (node, nodes) {
|
||||
if (node.default) {
|
||||
var declar = node.declaration;
|
||||
var assign;
|
||||
|
||||
// exports = VALUE;
|
||||
var templateName = "exports-default";
|
||||
|
||||
if (t.isFunction(declar) || !this.hasNonDefaultExports) {
|
||||
assign = util.template(templateName, {
|
||||
VALUE: this._pushStatement(declar, nodes)
|
||||
}, true);
|
||||
|
||||
// hoist to the top if this default is a function
|
||||
nodes.push(this._hoistExport(declar, assign, 3));
|
||||
return;
|
||||
} else {
|
||||
// this export isn't a function so we can't hoist it to the top so we need to set it
|
||||
// at the very end of the file with something like:
|
||||
//
|
||||
// module.exports = Object.assign(exports["default"], exports)
|
||||
//
|
||||
|
||||
assign = util.template("amd-export-default-assign", true);
|
||||
assign._blockHoist = 0;
|
||||
|
||||
nodes.push(assign);
|
||||
}
|
||||
}
|
||||
|
||||
DefaultFormatter.prototype.exportDeclaration.apply(this, arguments);
|
||||
};
|
||||
|
||||
AMDFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
||||
var self = this;
|
||||
return this._exportSpecifier(function () {
|
||||
|
||||
@ -0,0 +1 @@
|
||||
exports = Object.assign(exports["default"], exports);
|
||||
1
lib/6to5/transformation/templates/exports-default.js
Normal file
1
lib/6to5/transformation/templates/exports-default.js
Normal file
@ -0,0 +1 @@
|
||||
exports = VALUE;
|
||||
Loading…
x
Reference in New Issue
Block a user