From bfd307cd571330af663058ab27a0bc42bb8d3c57 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 31 May 2015 23:40:42 +0100 Subject: [PATCH] move some visitors out of deoptimising enter method --- .../transformation/helpers/call-delegate.js | 6 ++--- .../transformation/helpers/name-method.js | 7 +++--- .../helpers/remap-async-to-generator.js | 22 +++++++++---------- src/babel/transformation/modules/system.js | 6 +++-- src/babel/traversal/scope/index.js | 12 +++++----- src/babel/types/retrievers.js | 1 + 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/babel/transformation/helpers/call-delegate.js b/src/babel/transformation/helpers/call-delegate.js index ba899aac84..1de7f5a956 100644 --- a/src/babel/transformation/helpers/call-delegate.js +++ b/src/babel/transformation/helpers/call-delegate.js @@ -6,10 +6,10 @@ var visitor = { state.found = true; this.stop(); } + }, - if (this.isFunction()) { - this.skip(); - } + Function() { + this.skip(); } }; diff --git a/src/babel/transformation/helpers/name-method.js b/src/babel/transformation/helpers/name-method.js index 97af78f66b..331a7edd32 100644 --- a/src/babel/transformation/helpers/name-method.js +++ b/src/babel/transformation/helpers/name-method.js @@ -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 diff --git a/src/babel/transformation/helpers/remap-async-to-generator.js b/src/babel/transformation/helpers/remap-async-to-generator.js index 64cfb2f551..dc22c076fd 100644 --- a/src/babel/transformation/helpers/remap-async-to-generator.js +++ b/src/babel/transformation/helpers/remap-async-to-generator.js @@ -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); } } diff --git a/src/babel/transformation/modules/system.js b/src/babel/transformation/modules/system.js index 866fc168f1..afcb86a003 100644 --- a/src/babel/transformation/modules/system.js +++ b/src/babel/transformation/modules/system.js @@ -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(); diff --git a/src/babel/traversal/scope/index.js b/src/babel/traversal/scope/index.js index 59a9d0ba92..11247ede23 100644 --- a/src/babel/traversal/scope/index.js +++ b/src/babel/traversal/scope/index.js @@ -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 diff --git a/src/babel/types/retrievers.js b/src/babel/types/retrievers.js index 494656234b..d72cfc2d53 100644 --- a/src/babel/types/retrievers.js +++ b/src/babel/types/retrievers.js @@ -32,6 +32,7 @@ export function getBindingIdentifiers(node: Object): Object { } getBindingIdentifiers.keys = { + CatchClause: ["param"], UnaryExpression: ["argument"], AssignmentExpression: ["left"], ImportSpecifier: ["local"],