diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-10-02 12:22:39 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-10-02 12:22:39 +0300 |
commit | 347160c63138dcd7fbe107ae80309ad86d58a2e1 (patch) | |
tree | d80770283add5bb1a5ba712d4f8f4d793b35f285 /lib | |
parent | ff696cd7bc507ad0ffc5444bff39de9b6ad10a7e (diff) | |
download | tracifyjs-347160c63138dcd7fbe107ae80309ad86d58a2e1.tar.gz tracifyjs-347160c63138dcd7fbe107ae80309ad86d58a2e1.zip |
add AST_SymbolConst for names defined with `const`
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ast.js | 6 | ||||
-rw-r--r-- | lib/parse.js | 8 | ||||
-rw-r--r-- | lib/scope.js | 9 |
3 files changed, 15 insertions, 8 deletions
@@ -599,7 +599,11 @@ var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", { }, AST_Symbol); var AST_SymbolVar = DEFNODE("SymbolVar", null, { - $documentation: "Symbol defining a variable or constant", + $documentation: "Symbol defining a variable", +}, AST_SymbolDeclaration); + +var AST_SymbolConst = DEFNODE("SymbolConst", null, { + $documentation: "A constant declaration" }, AST_SymbolDeclaration); var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, { diff --git a/lib/parse.js b/lib/parse.js index 981c1294..b054c727 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1105,12 +1105,12 @@ function parse($TEXT, options) { }); }; - function vardefs(no_in) { + function vardefs(no_in, in_const) { var a = []; for (;;) { a.push(new AST_VarDef({ start : S.token, - name : as_symbol(AST_SymbolVar), + name : as_symbol(in_const ? AST_SymbolConst : AST_SymbolVar), value : is("operator", "=") ? (next(), expression(false, no_in)) : null, end : prev() })); @@ -1124,7 +1124,7 @@ function parse($TEXT, options) { var var_ = function(no_in) { return new AST_Var({ start : prev(), - definitions : vardefs(no_in), + definitions : vardefs(no_in, false), end : prev() }); }; @@ -1132,7 +1132,7 @@ function parse($TEXT, options) { var const_ = function() { return new AST_Const({ start : prev(), - definitions : vardefs(), + definitions : vardefs(false, true), end : prev() }); }; diff --git a/lib/scope.js b/lib/scope.js index 9f8981f9..71ed0667 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -49,6 +49,7 @@ function SymbolDef(scope, orig) { this.global = false; this.mangled_name = null; this.undeclared = false; + this.constant = false; }; SymbolDef.prototype = { @@ -144,9 +145,11 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){ (node.scope = scope.parent_scope).def_function(node); node.init.push(tw.parent()); } - else if (node instanceof AST_SymbolVar) { - scope.def_variable(node); - var def = tw.parent(); + else if (node instanceof AST_SymbolVar + || node instanceof AST_SymbolConst) { + var def = scope.def_variable(node); + def.constant = node instanceof AST_SymbolConst; + def = tw.parent(); if (def.value) node.init.push(def); } else if (node instanceof AST_SymbolCatch) { |