more intelligent scope tracking and insertion

This commit is contained in:
Sebastian McKenzie
2015-01-22 01:40:26 +11:00
parent 878a7ada06
commit c2d61ad660

View File

@@ -45,7 +45,7 @@ Scope.prototype._add = function (node, references, throwOnDuplicate) {
var id = ids[key];
if (throwOnDuplicate && references[key]) {
throw this.file.errorWithNode(id, "Duplicate declaration");
throw this.file.errorWithNode(id, "Duplicate declaration", TypeError);
}
references[key] = id;
@@ -169,12 +169,11 @@ var functionVariableVisitor = {
var blockVariableVisitor = {
enter: function (node, parent, scope, context, add) {
if (t.isScope(node)) {
return context.skip();
}
if (t.isBlockScoped(node)) {
add(node, false, true);
context.stop();
} else if (t.isScope(node)) {
context.skip();
}
}
};
@@ -277,13 +276,18 @@ Scope.prototype.push = function (opts) {
};
/**
* Description
* Walk up the scope tree until we hit a `Function` and then
* push our `node` to it's references.
*
* @param {Object} node
*/
Scope.prototype.add = function (node) {
this._add(node, this.references);
var scope = this;
while (scope.parent && !t.isFunction(scope.block)) {
scope = scope.parent;
}
scope._add(node, scope.references);
};
/**