Sebastian McKenzie ae7d5367f1 6.0.0
I'm extremely stupid and didn't commit as I go. To anyone reading this
I'm extremely sorry. A lot of these changes are very broad and I plan on
releasing Babel 6.0.0 today live on stage at Ember Camp London so I'm
afraid I couldn't wait. If you're ever in London I'll buy you a beer
(or assorted beverage!) to make up for it, also I'll kiss your feet and
give you a back massage, maybe.
2015-10-29 17:51:24 +00:00

55 lines
1.2 KiB
JavaScript

/* @flow */
import explode from "babel-helper-explode-assignable-expression";
import * as t from "babel-types";
export default function (
exports: Object,
opts: {
build: Function;
is: Function;
},
) {
let buildAssignment = function (left, right) {
return t.assignmentExpression("=", left, right);
};
exports.ExpressionStatement = function (path, file) {
// hit the `AssignmentExpression` one below
if (path.isCompletionRecord()) return;
let expr = path.node.expression;
if (!opts.is(expr, file)) return;
let nodes = [];
let exploded = explode(expr.left, nodes, file, path.scope);
nodes.push(t.ifStatement(
opts.build(exploded.uid, file),
t.expressionStatement(buildAssignment(exploded.ref, expr.right))
));
return nodes;
};
exports.AssignmentExpression = function (path, file) {
let node = path.node;
if (!opts.is(node, file)) return;
let nodes = [];
let exploded = explode(node.left, nodes, file, path.scope);
nodes.push(t.logicalExpression(
"&&",
opts.build(exploded.uid, file),
buildAssignment(exploded.ref, node.right)
));
// todo: duplicate expression node
nodes.push(exploded.ref);
return nodes;
};
}