Skip to content

Commit

Permalink
fix "use asm" numeric output (#2328)
Browse files Browse the repository at this point in the history
fixes #2324
  • Loading branch information
kzc authored and alexlamsl committed Sep 20, 2017
1 parent 00f5094 commit 3f5a7b7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/output.js
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
62 changes: 62 additions & 0 deletions test/compress/asm.js
Expand Up @@ -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;'
}

0 comments on commit 3f5a7b7

Please sign in to comment.