aboutsummaryrefslogtreecommitdiff
path: root/lib/output.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai.bazon@gmail.com>2015-11-11 22:15:25 +0200
committerMihai Bazon <mihai.bazon@gmail.com>2015-11-11 22:15:25 +0200
commit7691bebea525e96cb74d52e0bb8f294cf778c966 (patch)
treed2485ce55b215edb1846cbbe9cc3e4e3ad28725d /lib/output.js
parent3c4346728e5067608b6393ba98e24849ac22adea (diff)
downloadtracifyjs-7691bebea525e96cb74d52e0bb8f294cf778c966.tar.gz
tracifyjs-7691bebea525e96cb74d52e0bb8f294cf778c966.zip
Rework has_directive
It's now available during tree walking, i.e. walker.has_directive("use asm"), rather than as part of the scope. It's thus no longer necessary to call `figure_out_scope` before codegen. Added special bits in the code generator to overcome the fact that it doesn't inherit from TreeWalker. Fix #861
Diffstat (limited to 'lib/output.js')
-rw-r--r--lib/output.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/output.js b/lib/output.js
index b7f69717..9dadf0e5 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -382,8 +382,13 @@ function OutputStream(options) {
nodetype.DEFMETHOD("_codegen", generator);
};
+ var use_asm = false;
+
AST_Node.DEFMETHOD("print", function(stream, force_parens){
- var self = this, generator = self._codegen;
+ var self = this, generator = self._codegen, prev_use_asm = use_asm;
+ if (self instanceof AST_Directive && self.value == "use asm") {
+ use_asm = true;
+ }
function doit() {
self.add_comments(stream);
self.add_source_map(stream);
@@ -396,6 +401,9 @@ function OutputStream(options) {
doit();
}
stream.pop_node();
+ if (self instanceof AST_Lambda) {
+ use_asm = prev_use_asm;
+ }
});
AST_Node.DEFMETHOD("print_to_string", function(options){
@@ -1170,10 +1178,8 @@ function OutputStream(options) {
output.print_string(self.getValue(), self.quote);
});
DEFPRINT(AST_Number, function(self, output){
- if (self.literal !== undefined
- && +self.literal === self.value /* paranoid check */
- && self.scope && self.scope.has_directive('use asm')) {
- output.print(self.literal);
+ if (use_asm) {
+ output.print(self.start.literal);
} else {
output.print(make_num(self.getValue()));
}