add optional scope parameter to TraversalPath#hoist
This commit is contained in:
parent
bc155f956c
commit
46462e3e69
@ -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;
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user