aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkzc <kzc@users.noreply.github.com>2017-09-20 12:52:48 -0400
committeralexlamsl <alexlamsl@gmail.com>2017-09-21 04:42:40 +0800
commit7e3e9da860d9da4fa3d5e37bea4d3bd399194c02 (patch)
tree942fd6473ff7792be4d07da7296c7cedb7244246
parent00f509405b44882bab5d63d97caacb21691cdad6 (diff)
downloadtracifyjs-7e3e9da860d9da4fa3d5e37bea4d3bd399194c02.tar.gz
tracifyjs-7e3e9da860d9da4fa3d5e37bea4d3bd399194c02.zip
fix "use asm" numeric output (#2328)
fixes #2324
-rw-r--r--lib/output.js16
-rw-r--r--test/compress/asm.js62
2 files changed, 72 insertions, 6 deletions
diff --git a/lib/output.js b/lib/output.js
index 315bfafd..1aa63450 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -482,13 +482,17 @@ function OutputStream(options) {
nodetype.DEFMETHOD("_codegen", generator);
};
- var use_asm = false;
var in_directive = false;
+ var active_scope = null;
+ var use_asm = null;
AST_Node.DEFMETHOD("print", function(stream, force_parens){
- var self = this, generator = self._codegen, prev_use_asm = use_asm;
- if (self instanceof AST_Directive && self.value == "use asm" && stream.parent() instanceof AST_Scope) {
- use_asm = true;
+ var self = this, generator = self._codegen;
+ if (self instanceof AST_Scope) {
+ active_scope = self;
+ }
+ else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") {
+ use_asm = active_scope;
}
function doit() {
self.add_comments(stream);
@@ -502,8 +506,8 @@ function OutputStream(options) {
doit();
}
stream.pop_node();
- if (self instanceof AST_Scope) {
- use_asm = prev_use_asm;
+ if (self === use_asm) {
+ use_asm = null;
}
});
AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);
diff --git a/test/compress/asm.js b/test/compress/asm.js
index 9b227326..527e6b43 100644
--- a/test/compress/asm.js
+++ b/test/compress/asm.js
@@ -104,3 +104,65 @@ asm_mixed: {
}
}
+asm_toplevel: {
+ options = {}
+ input: {
+ "use asm";
+ 0.0;
+ function f() {
+ 0.0;
+ (function(){
+ 0.0;
+ });
+ }
+ 0.0;
+ }
+ expect_exact: '"use asm";0.0;function f(){0.0;(function(){0.0})}0.0;'
+}
+
+asm_function_expression: {
+ options = {}
+ input: {
+ 0.0;
+ var a = function() {
+ "use asm";
+ 0.0;
+ }
+ function f() {
+ 0.0;
+ return function(){
+ "use asm";
+ 0.0;
+ }
+ 0.0;
+ }
+ 0.0;
+ }
+ expect_exact: '0;var a=function(){"use asm";0.0};function f(){0;return function(){"use asm";0.0};0}0;'
+}
+
+asm_nested_functions: {
+ options = {}
+ input: {
+ 0.0;
+ function a() {
+ "use asm";
+ 0.0;
+ }
+ 0.0;
+ function b() {
+ 0.0;
+ function c(){
+ "use asm";
+ 0.0;
+ }
+ 0.0;
+ function d(){
+ 0.0;
+ }
+ 0.0;
+ }
+ 0.0;
+ }
+ expect_exact: '0;function a(){"use asm";0.0}0;function b(){0;function c(){"use asm";0.0}0;function d(){0}0}0;'
+}