Merge branch 'master' of github.com:babel/babel

This commit is contained in:
Sebastian McKenzie
2015-07-05 21:41:58 +01:00
9 changed files with 110 additions and 5 deletions

View File

@@ -78,6 +78,7 @@ export default class SystemFormatter extends AMDFormatter {
constructor(file) {
super(file);
this._setters = null;
this.exportIdentifier = file.scope.generateUidIdentifier("export");
this.noInteropRequireExport = true;
this.noInteropRequireImport = true;
@@ -178,11 +179,14 @@ export default class SystemFormatter extends AMDFormatter {
var block = t.blockStatement(program.body);
var setterListNode = this._buildRunnerSetters(block, hoistDeclarators);
this._setters = setterListNode;
var runner = util.template("system", {
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
EXPORT_IDENTIFIER: this.exportIdentifier,
MODULE_NAME: moduleNameLiteral,
SETTERS: this._buildRunnerSetters(block, hoistDeclarators),
SETTERS: setterListNode,
EXECUTE: t.functionExpression(null, [], block)
}, true);

View File

@@ -316,9 +316,12 @@ class DestructuringTransformer {
var left = pattern.left;
if (t.isPattern(left)) {
this.nodes.push(t.expressionStatement(
var tempValueDefault = t.expressionStatement(
t.assignmentExpression("=", tempValueRef, tempConditional)
));
);
tempValueDefault._blockHoist = this.blockHoist;
this.nodes.push(tempValueDefault);
this.push(left, tempValueRef);
} else {
this.nodes.push(this.buildVariableAssignment(left, tempConditional));

View File

@@ -84,4 +84,5 @@ export default {
_blockHoist: require("./internal/block-hoist"),
jscript: require("babel-plugin-jscript"),
flow: require("./other/flow"),
"optimisation.modules.system": require("./optimisation/modules.system"),
};

View File

@@ -0,0 +1,50 @@
import * as t from "../../../types";
export var metadata = {
optional: true,
group: "builtin-trailing"
};
export var visitor = {
Program(node, parent, scope, file){
if (file.moduleFormatter._setters){
scope.traverse(file.moduleFormatter._setters, optimizeSettersVisitor, {
exportFunctionIdentifier: file.moduleFormatter.exportIdentifier
});
}
}
};
/**
* Setters are optimized to avoid slow export behavior in modules that rely on deep hierarchies
* of export-from declarations.
* More info in https://github.com/babel/babel/pull/1722 and
* https://github.com/ModuleLoader/es6-module-loader/issues/386.
*
* TODO: Ideally this would be optimized during construction of the setters, but the current
* architecture of the module formatters make that difficult.
*/
var optimizeSettersVisitor = {
FunctionExpression: {
enter: (node, parent, scope, state) => {
state.hasExports = false;
state.exportObjectIdentifier = scope.generateUidIdentifier("exportObj");
},
exit: (node, parent, scope, state) => {
if (!state.hasExports) return;
node.body.body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(t.cloneDeep(state.exportObjectIdentifier), t.objectExpression([]))
]));
node.body.body.push(t.expressionStatement(t.callExpression(
t.cloneDeep(state.exportFunctionIdentifier), [t.cloneDeep(state.exportObjectIdentifier)])));
}
},
CallExpression: (node, parent, scope, state) => {
if (!t.isIdentifier(node.callee, {name: state.exportFunctionIdentifier.name})) return;
state.hasExports = true;
var memberNode = t.memberExpression(t.cloneDeep(state.exportObjectIdentifier), node.arguments[0], true);
return t.assignmentExpression("=", memberNode, node.arguments[1]);
}
};