aboutsummaryrefslogtreecommitdiff
path: root/lib/scope.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-09-18 13:21:09 +0300
committerMihai Bazon <mihai@bazon.net>2012-09-18 13:21:09 +0300
commit3da0ac4897e1b12adbdedbfa1c3a145931f0af56 (patch)
tree155d17888ea85824a6aef7e81d176cb51a43cf7b /lib/scope.js
parent21968285e8fad1cfe775b389c6bcd16e14b62c6c (diff)
downloadtracifyjs-3da0ac4897e1b12adbdedbfa1c3a145931f0af56.tar.gz
tracifyjs-3da0ac4897e1b12adbdedbfa1c3a145931f0af56.zip
support for directives
Diffstat (limited to 'lib/scope.js')
-rw-r--r--lib/scope.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/scope.js b/lib/scope.js
index 79d6e91d..dfbff4b8 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -82,6 +82,11 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
scope = save_scope;
return true; // don't descend again in TreeWalker
}
+ if (node instanceof AST_Directive) {
+ node.scope = scope;
+ push_uniq(scope.directives, node.value);
+ return true;
+ }
if (node instanceof AST_With) {
for (var s = scope; s; s = s.parent_scope)
s.uses_with = true;
@@ -193,6 +198,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
});
AST_Scope.DEFMETHOD("init_scope_vars", function(){
+ this.directives = []; // contains the directives defined in this scope, i.e. "use strict"
this.variables = {}; // map name to AST_SymbolVar (variables defined in this scope; includes functions)
this.functions = {}; // map name to AST_SymbolDefun (functions defined in this scope)
this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement
@@ -233,6 +239,11 @@ AST_Scope.DEFMETHOD("find_variable", function(name){
: (this.parent_scope && this.parent_scope.find_variable(name));
});
+AST_Scope.DEFMETHOD("has_directive", function(value){
+ return this.parent_scope && this.parent_scope.has_directive(value)
+ || (this.directives.indexOf(value) >= 0 ? this : null);
+});
+
AST_Scope.DEFMETHOD("def_function", function(symbol){
this.functions[symbol.name] = this.def_variable(symbol);
});