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

@@ -1,20 +1,20 @@
import * as t from "babel-types";
export let visitor = {
export const visitor = {
Function(path) {
let params: Array = path.get("params");
const params: Array = path.get("params");
// If there's a rest param, no need to loop through it. Also, we need to
// hoist one more level to get `declar` at the right spot.
let hoistTweak = t.isRestElement(params[params.length - 1]) ? 1 : 0;
let outputParamsLength = params.length - hoistTweak;
const hoistTweak = t.isRestElement(params[params.length - 1]) ? 1 : 0;
const outputParamsLength = params.length - hoistTweak;
for (let i = 0; i < outputParamsLength; i++) {
let param = params[i];
const param = params[i];
if (param.isArrayPattern() || param.isObjectPattern()) {
let uid = path.scope.generateUidIdentifier("ref");
const uid = path.scope.generateUidIdentifier("ref");
let declar = t.variableDeclaration("let", [
const declar = t.variableDeclaration("let", [
t.variableDeclarator(param.node, uid)
]);
declar._blockHoist = outputParamsLength - i;