summaryrefslogtreecommitdiff
path: root/src/emscripten-optimizer
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2019-04-22 09:42:30 -0700
committerGitHub <noreply@github.com>2019-04-22 09:42:30 -0700
commitb2161e3148e40cec252abb0ef33538b797954579 (patch)
tree5455e5eae50f2360c63c20eba264cdd33b1e3440 /src/emscripten-optimizer
parentb8d93ea629f59f534093d20f37cb8baf9809062e (diff)
downloadbinaryen-b2161e3148e40cec252abb0ef33538b797954579.tar.gz
binaryen-b2161e3148e40cec252abb0ef33538b797954579.tar.bz2
binaryen-b2161e3148e40cec252abb0ef33538b797954579.zip
wasm2js: fix printing of negated negative constants (#2034)
It is invalid to print --5, we need to add a space - -5 so that it is valid JS to parse.
Diffstat (limited to 'src/emscripten-optimizer')
-rw-r--r--src/emscripten-optimizer/simple_ast.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/emscripten-optimizer/simple_ast.h b/src/emscripten-optimizer/simple_ast.h
index 969277466..ded8af5f4 100644
--- a/src/emscripten-optimizer/simple_ast.h
+++ b/src/emscripten-optimizer/simple_ast.h
@@ -986,6 +986,9 @@ struct JSPrinter {
}
void printNum(Ref node) {
+ if (node->getNumber() < 0 && buffer[used-1] == '-') {
+ emit(' '); // cannot join - and - to --, looks like the -- operator
+ }
emit(numToString(node->getNumber(), finalize));
}