Run prettier

This commit is contained in:
Brian Ng
2017-06-27 12:15:00 -05:00
parent 93cc22dae1
commit e4b35f680d
307 changed files with 6742 additions and 4080 deletions

View File

@@ -5,23 +5,28 @@ import * as destructuring from "./destructuring";
import * as def from "./default";
import * as rest from "./rest";
export default function () {
export default function() {
return {
visitor: visitors.merge([{
ArrowFunctionExpression(path) {
// In some conversion cases, it may have already been converted to a function while this callback
// was queued up.
if (!path.isArrowFunctionExpression()) return;
visitor: visitors.merge([
{
ArrowFunctionExpression(path) {
// In some conversion cases, it may have already been converted to a function while this callback
// was queued up.
if (!path.isArrowFunctionExpression()) return;
// default/rest visitors require access to `arguments`
const params: Array<NodePath> = path.get("params");
for (const param of params) {
if (param.isRestElement() || param.isAssignmentPattern()) {
path.arrowFunctionToExpression();
break;
// default/rest visitors require access to `arguments`
const params: Array<NodePath> = path.get("params");
for (const param of params) {
if (param.isRestElement() || param.isAssignmentPattern()) {
path.arrowFunctionToExpression();
break;
}
}
}
},
},
}, destructuring.visitor, rest.visitor, def.visitor]),
destructuring.visitor,
rest.visitor,
def.visitor,
]),
};
}

View File

@@ -47,7 +47,7 @@ const memberExpressionOptimisationVisitor = {
path.skip();
},
"Function|ClassProperty": function (path, state) {
"Function|ClassProperty": function(path, state) {
// Detect whether any reference to rest is contained in nested functions to
// determine if deopt is necessary.
const oldNoOptimise = state.noOptimise;
@@ -86,38 +86,29 @@ const memberExpressionOptimisationVisitor = {
if (parentPath.isMemberExpression({ object: node })) {
const grandparentPath = parentPath.parentPath;
const argsOptEligible = !state.deopted && !(
// ex: `args[0] = "whatever"`
const argsOptEligible =
!state.deopted &&
!// ex: `args[0] = "whatever"`
(
grandparentPath.isAssignmentExpression() &&
parentPath.node === grandparentPath.node.left
) ||
// ex: `[args[0]] = ["whatever"]`
grandparentPath.isLVal() ||
// ex: `for (rest[0] in this)`
// ex: `for (rest[0] of this)`
grandparentPath.isForXStatement() ||
// ex: `++args[0]`
// ex: `args[0]--`
grandparentPath.isUpdateExpression() ||
// ex: `delete args[0]`
grandparentPath.isUnaryExpression({ operator: "delete" }) ||
// ex: `args[0]()`
// ex: `new args[0]()`
// ex: `new args[0]`
(
(
grandparentPath.isCallExpression() ||
grandparentPath.isNewExpression()
) &&
parentPath.node === grandparentPath.node.callee
)
);
(grandparentPath.isAssignmentExpression() &&
parentPath.node === grandparentPath.node.left) ||
// ex: `[args[0]] = ["whatever"]`
grandparentPath.isLVal() ||
// ex: `for (rest[0] in this)`
// ex: `for (rest[0] of this)`
grandparentPath.isForXStatement() ||
// ex: `++args[0]`
// ex: `args[0]--`
grandparentPath.isUpdateExpression() ||
// ex: `delete args[0]`
grandparentPath.isUnaryExpression({ operator: "delete" }) ||
// ex: `args[0]()`
// ex: `new args[0]()`
// ex: `new args[0]`
((grandparentPath.isCallExpression() ||
grandparentPath.isNewExpression()) &&
parentPath.node === grandparentPath.node.callee)
);
if (argsOptEligible) {
if (parentPath.node.computed) {
@@ -127,9 +118,8 @@ const memberExpressionOptimisationVisitor = {
state.candidates.push({ cause: "indexGetter", path });
return;
}
}
// args.length
else if (parentPath.node.property.name === "length") {
} else if (parentPath.node.property.name === "length") {
// args.length
state.candidates.push({ cause: "lengthGetter", path });
return;
}
@@ -177,32 +167,42 @@ function optimiseIndexGetter(path, argsId, offset) {
// Avoid unnecessary '+ 0'
index = path.parent.property;
} else {
index = t.binaryExpression("+", path.parent.property, t.numericLiteral(offset));
index = t.binaryExpression(
"+",
path.parent.property,
t.numericLiteral(offset),
);
}
const { scope } = path;
if (!scope.isPure(index)) {
const temp = scope.generateUidIdentifierBasedOnNode(index);
scope.push({ id: temp, kind: "var" });
path.parentPath.replaceWith(restIndexImpure({
ARGUMENTS: argsId,
INDEX: index,
REF: temp,
}));
path.parentPath.replaceWith(
restIndexImpure({
ARGUMENTS: argsId,
INDEX: index,
REF: temp,
}),
);
} else {
path.parentPath.replaceWith(restIndex({
ARGUMENTS: argsId,
INDEX: index,
}));
path.parentPath.replaceWith(
restIndex({
ARGUMENTS: argsId,
INDEX: index,
}),
);
}
}
function optimiseLengthGetter(path, argsId, offset) {
if (offset) {
path.parentPath.replaceWith(restLength({
ARGUMENTS: argsId,
OFFSET: t.numericLiteral(offset),
}));
path.parentPath.replaceWith(
restLength({
ARGUMENTS: argsId,
OFFSET: t.numericLiteral(offset),
}),
);
} else {
path.replaceWith(argsId);
}
@@ -266,7 +266,7 @@ export const visitor = {
}
state.references = state.references.concat(
state.candidates.map(({ path }) => path)
state.candidates.map(({ path }) => path),
);
const start = t.numericLiteral(node.params.length);
@@ -290,7 +290,7 @@ export const visitor = {
arrLen = t.conditionalExpression(
t.binaryExpression(">", len, start),
t.binaryExpression("-", len, start),
t.numericLiteral(0)
t.numericLiteral(0),
);
}
@@ -311,10 +311,12 @@ export const visitor = {
// perform allocation at the lowest common ancestor of all references
loop._blockHoist = 1;
let target = path.getEarliestCommonAncestorFrom(state.references).getStatementParent();
let target = path
.getEarliestCommonAncestorFrom(state.references)
.getStatementParent();
// don't perform the allocation inside a loop
target.findParent((path) => {
target.findParent(path => {
if (path.isLoop()) {
target = path;
} else {