aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-10-02 12:22:39 +0300
committerMihai Bazon <mihai@bazon.net>2012-10-02 12:22:39 +0300
commit347160c63138dcd7fbe107ae80309ad86d58a2e1 (patch)
treed80770283add5bb1a5ba712d4f8f4d793b35f285 /lib
parentff696cd7bc507ad0ffc5444bff39de9b6ad10a7e (diff)
downloadtracifyjs-347160c63138dcd7fbe107ae80309ad86d58a2e1.tar.gz
tracifyjs-347160c63138dcd7fbe107ae80309ad86d58a2e1.zip
add AST_SymbolConst for names defined with `const`
Diffstat (limited to 'lib')
-rw-r--r--lib/ast.js6
-rw-r--r--lib/parse.js8
-rw-r--r--lib/scope.js9
3 files changed, 15 insertions, 8 deletions
diff --git a/lib/ast.js b/lib/ast.js
index 0b0273c8..c62e1429 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -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) {