enable prefer const (#5113)

This commit is contained in:
Henry Zhu
2017-01-14 09:48:52 -05:00
committed by GitHub
parent 982850731e
commit 672adba9a1
177 changed files with 1862 additions and 1863 deletions

View File

@@ -5,7 +5,7 @@ export default function (opts: {
build: Function;
operator: string;
}): Object {
let visitor = {};
const visitor = {};
function isAssignment(node) {
return node && node.operator === opts.operator + "=";
@@ -19,11 +19,11 @@ export default function (opts: {
// hit the `AssignmentExpression` one below
if (path.isCompletionRecord()) return;
let expr = path.node.expression;
const expr = path.node.expression;
if (!isAssignment(expr)) return;
let nodes = [];
let exploded = explode(expr.left, nodes, file, path.scope, true);
const nodes = [];
const exploded = explode(expr.left, nodes, file, path.scope, true);
nodes.push(t.expressionStatement(
buildAssignment(exploded.ref, opts.build(exploded.uid, expr.right))
@@ -33,17 +33,17 @@ export default function (opts: {
};
visitor.AssignmentExpression = function (path, file) {
let { node, scope } = path;
const { node, scope } = path;
if (!isAssignment(node)) return;
let nodes = [];
let exploded = explode(node.left, nodes, file, scope);
const nodes = [];
const 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;
const { node } = path;
if (node.operator === opts.operator) {
path.replaceWith(opts.build(node.left, node.right));
}