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.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# babel-helper-builder-binary-assignment-operator-visitor
|
||||
|
||||
## Usage
|
||||
|
||||
TODO
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "babel-helper-builder-binary-assignment-operator-visitor",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"repository": "babel/babel",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-helper-explode-assignable-expression": "^5.8.20",
|
||||
"babel-runtime": "^5.8.20",
|
||||
"babel-types": "^5.8.20"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/* @flow */
|
||||
|
||||
import explode from "babel-helper-explode-assignable-expression";
|
||||
import * as t from "babel-types";
|
||||
|
||||
export default function (opts: {
|
||||
build: Function;
|
||||
operator: string;
|
||||
}): Object {
|
||||
let visitor = {};
|
||||
|
||||
function isAssignment(node) {
|
||||
return node.operator === opts.operator + "=";
|
||||
}
|
||||
|
||||
function buildAssignment(left, right) {
|
||||
return t.assignmentExpression("=", left, right);
|
||||
}
|
||||
|
||||
visitor.ExpressionStatement = function (path, file) {
|
||||
// hit the `AssignmentExpression` one below
|
||||
if (path.isCompletionRecord()) return;
|
||||
|
||||
let expr = path.node.expression;
|
||||
if (!isAssignment(expr)) return;
|
||||
|
||||
let nodes = [];
|
||||
let exploded = explode(expr.left, nodes, file, path.scope, true);
|
||||
|
||||
nodes.push(t.expressionStatement(
|
||||
buildAssignment(exploded.ref, opts.build(exploded.uid, expr.right))
|
||||
));
|
||||
|
||||
path.replaceWithMultiple(nodes);
|
||||
};
|
||||
|
||||
visitor.AssignmentExpression = function (path, file) {
|
||||
let { node, scope } = path;
|
||||
if (!isAssignment(node)) return;
|
||||
|
||||
let nodes = [];
|
||||
let exploded = explode(node.left, nodes, file, scope);
|
||||
nodes.push(buildAssignment(exploded.ref, opts.build(exploded.uid, node.right)));
|
||||
path.replaceWithMultiple(nodes);
|
||||
};
|
||||
|
||||
visitor.BinaryExpression = function (path) {
|
||||
let { node } = path;
|
||||
if (node.operator === opts.operator) {
|
||||
path.replaceWith(opts.build(node.left, node.right));
|
||||
}
|
||||
};
|
||||
|
||||
return visitor;
|
||||
}
|
||||
Reference in New Issue
Block a user