enable prefer const (#5113)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
export default function ({ types: t, template }) {
|
||||
let buildMutatorMapAssign = template(`
|
||||
const buildMutatorMapAssign = template(`
|
||||
MUTATOR_MAP_REF[KEY] = MUTATOR_MAP_REF[KEY] || {};
|
||||
MUTATOR_MAP_REF[KEY].KIND = VALUE;
|
||||
`);
|
||||
@@ -29,7 +29,7 @@ export default function ({ types: t, template }) {
|
||||
function pushMutatorDefine({ objId, body, getMutatorId, scope }, prop) {
|
||||
let key = !prop.computed && t.isIdentifier(prop.key) ? t.stringLiteral(prop.key.name) : prop.key;
|
||||
|
||||
let maybeMemoise = scope.maybeGenerateMemoised(key);
|
||||
const maybeMemoise = scope.maybeGenerateMemoised(key);
|
||||
if (maybeMemoise) {
|
||||
body.push(t.expressionStatement(t.assignmentExpression("=", maybeMemoise, key)));
|
||||
key = maybeMemoise;
|
||||
@@ -44,7 +44,7 @@ export default function ({ types: t, template }) {
|
||||
}
|
||||
|
||||
function loose(info) {
|
||||
for (let prop of info.computedProps) {
|
||||
for (const prop of info.computedProps) {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
pushMutatorDefine(info, prop);
|
||||
} else {
|
||||
@@ -54,10 +54,10 @@ export default function ({ types: t, template }) {
|
||||
}
|
||||
|
||||
function spec(info) {
|
||||
let { objId, body, computedProps, state } = info;
|
||||
const { objId, body, computedProps, state } = info;
|
||||
|
||||
for (let prop of computedProps) {
|
||||
let key = t.toComputedKey(prop);
|
||||
for (const prop of computedProps) {
|
||||
const key = t.toComputedKey(prop);
|
||||
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
pushMutatorDefine(info, prop);
|
||||
@@ -87,9 +87,9 @@ export default function ({ types: t, template }) {
|
||||
visitor: {
|
||||
ObjectExpression: {
|
||||
exit(path, state) {
|
||||
let { node, parent, scope } = path;
|
||||
const { node, parent, scope } = path;
|
||||
let hasComputed = false;
|
||||
for (let prop of (node.properties: Array<Object>)) {
|
||||
for (const prop of (node.properties: Array<Object>)) {
|
||||
hasComputed = prop.computed === true;
|
||||
if (hasComputed) break;
|
||||
}
|
||||
@@ -98,11 +98,11 @@ export default function ({ types: t, template }) {
|
||||
// put all getters/setters into the first object expression as well as all initialisers up
|
||||
// to the first computed property
|
||||
|
||||
let initProps = [];
|
||||
let computedProps = [];
|
||||
const initProps = [];
|
||||
const computedProps = [];
|
||||
let foundComputed = false;
|
||||
|
||||
for (let prop of node.properties) {
|
||||
for (const prop of node.properties) {
|
||||
if (prop.computed) {
|
||||
foundComputed = true;
|
||||
}
|
||||
@@ -114,9 +114,9 @@ export default function ({ types: t, template }) {
|
||||
}
|
||||
}
|
||||
|
||||
let objId = scope.generateUidIdentifierBasedOnNode(parent);
|
||||
let initPropExpression = t.objectExpression(initProps);
|
||||
let body = [];
|
||||
const objId = scope.generateUidIdentifierBasedOnNode(parent);
|
||||
const initPropExpression = t.objectExpression(initProps);
|
||||
const body = [];
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(objId, initPropExpression)
|
||||
@@ -127,7 +127,7 @@ export default function ({ types: t, template }) {
|
||||
|
||||
let mutatorRef;
|
||||
|
||||
let getMutatorId = function () {
|
||||
const getMutatorId = function () {
|
||||
if (!mutatorRef) {
|
||||
mutatorRef = scope.generateUidIdentifier("mutatorMap");
|
||||
|
||||
@@ -139,7 +139,7 @@ export default function ({ types: t, template }) {
|
||||
return mutatorRef;
|
||||
};
|
||||
|
||||
let single = callback({
|
||||
const single = callback({
|
||||
scope,
|
||||
objId,
|
||||
body,
|
||||
|
||||
Reference in New Issue
Block a user