add optional scope parameter to TraversalPath#hoist

This commit is contained in:
Sebastian McKenzie 2015-03-30 16:41:29 +11:00
parent bc155f956c
commit 46462e3e69
3 changed files with 15 additions and 3 deletions

View File

@ -12,6 +12,10 @@ var referenceVisitor = {
if (this.isReferenced()) {
var bindingInfo = scope.getBinding(node.name);
// this binding isn't accessible from the parent scope so we can safely ignore it
// eg. it's in a closure etc
if (bindingInfo !== state.scope.getBinding(node.name)) return;
if (bindingInfo && bindingInfo.constant) {
state.bindings[node.name] = bindingInfo;
} else {
@ -25,9 +29,10 @@ var referenceVisitor = {
};
export default class PathHoister {
constructor(path) {
constructor(path, scope) {
this.foundIncompatible = false;
this.bindings = {};
this.scope = scope;
this.scopes = [];
this.path = path;
}

View File

@ -644,8 +644,8 @@ export default class TraversalPath {
* Description
*/
hoist() {
var hoister = new PathHoister(this);
hoist(scope = this.scope) {
var hoister = new PathHoister(this, scope);
return hoister.run();
}

View File

@ -75,6 +75,13 @@ export default class Scope {
return parent;
}
var cached = path.getData("scope");
if (cached && cached.parent === parent) {
return cached;
} else {
path.setData("scope", this);
}
this.parent = parent;
this.file = parent ? parent.file : file;