add kinds to binding registration and rename declaration scope methods to bindings
This commit is contained in:
parent
a2cc384172
commit
8e2df3f1f9
@ -460,7 +460,7 @@ File.prototype.generateUid = function (name, scope) {
|
||||
File.prototype.generateUidIdentifier = function (name, scope) {
|
||||
scope = scope || this.scope;
|
||||
var id = t.identifier(this.generateUid(name, scope));
|
||||
scope.addDeclarationToFunctionScope("var", id);
|
||||
scope.addBindingToFunctionScope("var", id);
|
||||
return id;
|
||||
};
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ var visitor = {
|
||||
|
||||
exports.Scope = function (node, parent, scope, file) {
|
||||
scope.traverse(node, visitor, {
|
||||
constants: scope.getAllDeclarationsOfKind("const"),
|
||||
constants: scope.getAllBindingsOfKind("const"),
|
||||
file: file
|
||||
});
|
||||
};
|
||||
|
||||
@ -250,7 +250,7 @@ var programReferenceVisitor = {
|
||||
var blockVariableVisitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
if (t.isBlockScoped(node)) {
|
||||
state.register(node);
|
||||
state.register(node, null, "let");
|
||||
} else if (t.isScope(node)) {
|
||||
this.skip();
|
||||
}
|
||||
@ -298,7 +298,7 @@ Scope.prototype.crawl = function () {
|
||||
if (t.isLoop(block)) {
|
||||
for (i = 0; i < t.FOR_INIT_KEYS.length; i++) {
|
||||
var node = block[t.FOR_INIT_KEYS[i]];
|
||||
if (t.isBlockScoped(node)) this.register(node, false, true);
|
||||
if (t.isBlockScoped(node)) this.register(node, false, "let");
|
||||
}
|
||||
|
||||
if (t.isBlockStatement(block.body)) {
|
||||
@ -310,7 +310,7 @@ Scope.prototype.crawl = function () {
|
||||
|
||||
if (t.isFunctionExpression(block) && block.id) {
|
||||
if (!t.isProperty(this.parentBlock, { method: true })) {
|
||||
this.register(block.id);
|
||||
this.register(block.id, null, "var");
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ Scope.prototype.crawl = function () {
|
||||
|
||||
if (t.isFunction(block)) {
|
||||
for (i = 0; i < block.params.length; i++) {
|
||||
this.register(block.params[i]);
|
||||
this.register(block.params[i], null, "var");
|
||||
}
|
||||
this.traverse(block.body, blockVariableVisitor, this);
|
||||
}
|
||||
@ -332,13 +332,13 @@ Scope.prototype.crawl = function () {
|
||||
// CatchClause - param
|
||||
|
||||
if (t.isCatchClause(block)) {
|
||||
this.register(block.param);
|
||||
this.register(block.param, null, "let");
|
||||
}
|
||||
|
||||
// ComprehensionExpression - blocks
|
||||
|
||||
if (t.isComprehensionExpression(block)) {
|
||||
this.register(block);
|
||||
this.register(block, null, "let");
|
||||
}
|
||||
|
||||
// Program, Function - var variables
|
||||
@ -391,7 +391,7 @@ Scope.prototype.push = function (opts) {
|
||||
* @param {Object} node
|
||||
*/
|
||||
|
||||
Scope.prototype.addDeclarationToFunctionScope = function (kind, node) {
|
||||
Scope.prototype.addBindingToFunctionScope = function (kind, node) {
|
||||
var scope = this.getFunctionParent();
|
||||
var ids = t.getBindingIdentifiers(node);
|
||||
|
||||
@ -441,7 +441,7 @@ Scope.prototype.getAllBindings = function () {
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Scope.prototype.getAllDeclarationsOfKind = function (kind) {
|
||||
Scope.prototype.getAllBindingsOfKind = function (kind) {
|
||||
var ids = object();
|
||||
|
||||
var scope = this;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user