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