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

@@ -3,22 +3,22 @@ import * as parens from "./parentheses";
import * as t from "babel-types";
function expandAliases(obj) {
let newObj = {};
const newObj = {};
function add(type, func) {
let fn = newObj[type];
const fn = newObj[type];
newObj[type] = fn ? function(node, parent, stack) {
let result = fn(node, parent, stack);
const result = fn(node, parent, stack);
return result == null ? func(node, parent, stack) : result;
} : func;
}
for (let type of Object.keys(obj)) {
for (const type of Object.keys(obj)) {
let aliases = t.FLIPPED_ALIAS_KEYS[type];
const aliases = t.FLIPPED_ALIAS_KEYS[type];
if (aliases) {
for (let alias of aliases) {
for (const alias of aliases) {
add(alias, obj[type]);
}
} else {
@@ -31,12 +31,12 @@ function expandAliases(obj) {
// Rather than using `t.is` on each object property, we pre-expand any type aliases
// into concrete types so that the 'find' call below can be as fast as possible.
let expandedParens = expandAliases(parens);
let expandedWhitespaceNodes = expandAliases(whitespace.nodes);
let expandedWhitespaceList = expandAliases(whitespace.list);
const expandedParens = expandAliases(parens);
const expandedWhitespaceNodes = expandAliases(whitespace.nodes);
const expandedWhitespaceList = expandAliases(whitespace.list);
function find(obj, node, parent, printStack) {
let fn = obj[node.type];
const fn = obj[node.type];
return fn ? fn(node, parent, printStack) : null;
}
@@ -63,7 +63,7 @@ export function needsWhitespace(node, parent, type) {
let linesInfo = find(expandedWhitespaceNodes, node, parent);
if (!linesInfo) {
let items = find(expandedWhitespaceList, node, parent);
const items = find(expandedWhitespaceList, node, parent);
if (items) {
for (let i = 0; i < items.length; i++) {
linesInfo = needsWhitespace(items[i], node, type);

View File

@@ -60,11 +60,11 @@ export function Binary(node: Object, parent: Object): boolean {
}
if (t.isBinary(parent)) {
let parentOp = parent.operator;
let parentPos = PRECEDENCE[parentOp];
const parentOp = parent.operator;
const parentPos = PRECEDENCE[parentOp];
let nodeOp = node.operator;
let nodePos = PRECEDENCE[nodeOp];
const nodeOp = node.operator;
const nodePos = PRECEDENCE[nodeOp];
if (parentPos > nodePos) {
return true;

View File

@@ -69,7 +69,7 @@ exports.nodes = {
*/
AssignmentExpression(node: Object): ?WhitespaceObject {
let state = crawl(node.right);
const state = crawl(node.right);
if ((state.hasCall && state.hasHelper) || state.hasFunction) {
return {
before: state.hasFunction,
@@ -131,11 +131,11 @@ exports.nodes = {
VariableDeclaration(node: Object): ?WhitespaceObject {
for (let i = 0; i < node.declarations.length; i++) {
let declar = node.declarations[i];
const declar = node.declarations[i];
let enabled = isHelper(declar.id) && !isType(declar.init);
if (!enabled) {
let state = crawl(declar.init);
const state = crawl(declar.init);
enabled = (isHelper(declar.init) && state.hasCall) || state.hasFunction;
}