move some visitors out of deoptimising enter method

This commit is contained in:
Sebastian McKenzie 2015-05-31 23:40:42 +01:00
parent beb5ee1333
commit bfd307cd57
6 changed files with 27 additions and 27 deletions

View File

@ -6,10 +6,10 @@ var visitor = {
state.found = true;
this.stop();
}
},
if (this.isFunction()) {
this.skip();
}
Function() {
this.skip();
}
};

View File

@ -3,10 +3,9 @@ import * as util from "../../util";
import * as t from "../../types";
var visitor = {
enter(node, parent, scope, state) {
// check if this node is a referenced identifier that matches the same as our
// function id
if (!this.isReferencedIdentifier({ name: state.name })) return;
ReferencedIdentifier(node, parent, scope, state) {
// check if this node matches our function id
if (node.name !== state.name) return;
// check that we don't have a local variable declared as that removes the need
// for the wrapper

View File

@ -1,25 +1,25 @@
import * as t from "../../types";
var awaitVisitor = {
enter(node) {
if (t.isFunction(node)) this.skip();
Function() {
this.skip();
},
if (t.isAwaitExpression(node)) {
node.type = "YieldExpression";
AwaitExpression(node) {
node.type = "YieldExpression";
if (node.all) {
// await* foo; -> yield Promise.all(foo);
node.all = false;
node.argument = t.callExpression(t.memberExpression(t.identifier("Promise"), t.identifier("all")), [node.argument]);
}
if (node.all) {
// await* foo; -> yield Promise.all(foo);
node.all = false;
node.argument = t.callExpression(t.memberExpression(t.identifier("Promise"), t.identifier("all")), [node.argument]);
}
}
};
var referenceVisitor = {
enter(node, parent, scope, state) {
ReferencedIdentifier(node, parent, scope, state) {
var name = state.id.name;
if (this.isReferencedIdentifier({ name: name }) && scope.bindingIdentifierEquals(name, state.id)) {
if (node.name === name && scope.bindingIdentifierEquals(name, state.id)) {
return state.ref = state.ref || scope.generateUidIdentifier(name);
}
}

View File

@ -44,9 +44,11 @@ var hoistVariablesVisitor = {
};
var hoistFunctionsVisitor = {
enter(node, parent, scope, state) {
if (t.isFunction(node)) this.skip();
Function() {
this.skip();
},
enter(node, parent, scope, state) {
if (t.isFunctionDeclaration(node) || state.formatter._canHoist(node)) {
state.handlerBody.push(node);
this.dangerouslyRemove();

View File

@ -103,11 +103,9 @@ var renameVisitor = {
}
},
Scopable(node, parent, scope, state) {
if (this.isScope()) {
if (!scope.bindingIdentifierEquals(state.oldName, state.binding)) {
this.skip();
}
Scope(node, parent, scope, state) {
if (!scope.bindingIdentifierEquals(state.oldName, state.binding)) {
this.skip();
}
}
};
@ -599,7 +597,7 @@ export default class Scope {
if (path.isFunctionExpression() && path.has("id")) {
if (!t.isProperty(path.parent, { method: true })) {
this.registerBinding("var", path.get("id"));
this.registerBinding("var", path);
}
}
@ -626,7 +624,7 @@ export default class Scope {
// CatchClause - param
if (path.isCatchClause()) {
this.registerBinding("let", path.get("param"));
this.registerBinding("let", path);
}
// ComprehensionExpression - blocks

View File

@ -32,6 +32,7 @@ export function getBindingIdentifiers(node: Object): Object {
}
getBindingIdentifiers.keys = {
CatchClause: ["param"],
UnaryExpression: ["argument"],
AssignmentExpression: ["left"],
ImportSpecifier: ["local"],