aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-10-04 17:28:35 +0300
committerMihai Bazon <mihai@bazon.net>2012-10-04 17:28:35 +0300
commita9b6f9909a331740cae4a37f1fc6bb40801674fe (patch)
tree446d75f848eef6978d0b5bb51926470a007df79c /lib
parent708ec0467cc584a1cbc377f9d724084357ca5d1a (diff)
downloadtracifyjs-a9b6f9909a331740cae4a37f1fc6bb40801674fe.tar.gz
tracifyjs-a9b6f9909a331740cae4a37f1fc6bb40801674fe.zip
use the appropriate constructor for symbols
Diffstat (limited to 'lib')
-rw-r--r--lib/mozilla-ast.js38
1 files changed, 33 insertions, 5 deletions
diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js
index 6bc33953..41cf13ce 100644
--- a/lib/mozilla-ast.js
+++ b/lib/mozilla-ast.js
@@ -69,18 +69,21 @@
end : my_end_token(M),
properties : M.properties.map(function(prop){
var key = prop.key;
+ var name = key.type == "Identifier" ? key.name : key.value;
var args = {
start : my_start_token(key),
end : my_end_token(prop.value),
- key : key.type == "Identifier" ? key.name : key.value,
+ key : name,
value : from_moz(prop.value)
};
switch (prop.kind) {
case "init":
return new AST_ObjectKeyVal(args);
case "set":
+ args.value.name = from_moz(key);
return new AST_ObjectSetter(args);
case "get":
+ args.value.name = from_moz(key);
return new AST_ObjectGetter(args);
}
})
@@ -129,7 +132,22 @@
}
},
UnaryExpression: From_Moz_Unary,
- UpdateExpression: From_Moz_Unary
+ UpdateExpression: From_Moz_Unary,
+ Identifier: function(M) {
+ var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
+ return new (M.name == "this" ? AST_This
+ : p.type == "LabeledStatement" ? AST_Label
+ : p.type == "VariableDeclarator" && p.id === M ? (p.kind == "const" ? AST_SymbolConst : AST_SymbolVar)
+ : p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
+ : p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
+ : p.type == "CatchClause" ? AST_SymbolCatch
+ : p.type == "BreakStatement" || p.type == "ContinueStatement" ? AST_LabelRef
+ : AST_SymbolRef)({
+ start : my_start_token(M),
+ end : my_end_token(M),
+ name : M.name
+ });
+ }
};
function From_Moz_Unary(M) {
@@ -175,7 +193,6 @@
map("ConditionalExpression", AST_Conditional, "test>condition, consequent>consequent, alternate>alternative");
map("NewExpression", AST_New, "callee>expression, arguments@args");
map("CallExpression", AST_Call, "callee>expression, arguments@args");
- map("Identifier", AST_Symbol, "name=name");
/* -----[ tools ]----- */
@@ -233,10 +250,21 @@
return MOZ_TO_ME[moztype] = moz_to_me;
};
+ var FROM_MOZ_STACK = null;
+
function from_moz(node) {
- return node != null ? MOZ_TO_ME[node.type](node) : null;
+ FROM_MOZ_STACK.push(node);
+ var ret = node != null ? MOZ_TO_ME[node.type](node) : null;
+ FROM_MOZ_STACK.pop();
+ return ret;
};
- AST_Node.from_mozilla_ast = from_moz;
+ AST_Node.from_mozilla_ast = function(node){
+ var save_stack = FROM_MOZ_STACK;
+ FROM_MOZ_STACK = [];
+ var ast = from_moz(node);
+ FROM_MOZ_STACK = save_stack;
+ return ast;
+ };
})();