Fix output for "use asm" code from SpiderMonkey AST

(will only work properly if the SM tree contains "raw" properties for
Literal number nodes)
This commit is contained in:
Mihai Bazon
2015-11-12 12:18:25 +02:00
parent c898a26117
commit 08623aa6a7
4 changed files with 18 additions and 8 deletions

View File

@@ -85,7 +85,7 @@ function DEFNODE(type, props, methods, base) {
return ctor;
};
var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos nlb comments_before file literal", {
var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos nlb comments_before file raw", {
}, null);
var AST_Node = DEFNODE("Node", "start end", {

View File

@@ -363,13 +363,15 @@
prefix: true,
argument: {
type: "Literal",
value: -value
value: -value,
raw: M.start.raw
}
};
}
return {
type: "Literal",
value: value
value: value,
raw: M.start.raw
};
});
@@ -389,6 +391,12 @@
/* -----[ tools ]----- */
function raw_token(moznode) {
if (moznode.type == "Literal") {
return moznode.raw != null ? moznode.raw : moznode.value + "";
}
}
function my_start_token(moznode) {
var loc = moznode.loc, start = loc && loc.start;
var range = moznode.range;
@@ -399,7 +407,8 @@
pos : range ? range[0] : moznode.start,
endline : start && start.line,
endcol : start && start.column,
endpos : range ? range[0] : moznode.start
endpos : range ? range[0] : moznode.start,
raw : raw_token(moznode),
});
};
@@ -413,7 +422,8 @@
pos : range ? range[1] : moznode.end,
endline : end && end.line,
endcol : end && end.column,
endpos : range ? range[1] : moznode.end
endpos : range ? range[1] : moznode.end,
raw : raw_token(moznode),
});
};

View File

@@ -1178,8 +1178,8 @@ function OutputStream(options) {
output.print_string(self.getValue(), self.quote);
});
DEFPRINT(AST_Number, function(self, output){
if (use_asm) {
output.print(self.start.literal);
if (use_asm && self.start.raw != null) {
output.print(self.start.raw);
} else {
output.print(make_num(self.getValue()));
}

View File

@@ -286,7 +286,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
file : filename
};
if (/^(?:num|string|regexp)$/i.test(type)) {
ret.literal = $TEXT.substring(ret.pos, ret.endpos);
ret.raw = $TEXT.substring(ret.pos, ret.endpos);
}
if (!is_comment) {
ret.comments_before = S.comments_before;