How to disable uglify-js for EM_JS and EM_ASM?

224 views
Skip to first unread message

Floh

unread,
Jul 19, 2018, 11:27:49 AM7/19/18
to emscripten-discuss
Hi,

I'm currently running into all sorts of annoying problems with EM_JS and EM_ASM, which mostly seem to be related to uglify-js not understanding proper JS (maybe it's not ES6 compatible)?

Once something goes wrong, the emscripten link step basically barfs a wall of text on the console, and the error messages are hard to decipher, eg...

=== START (lots of cryptic text before that ===
...
JS optimizer error:
Unexpected token: name (params) (line: 1596, col: 37, pos: 56504)

=== MORE TEXT...

function _args_emsc_parse_url(){ let params = new URLSearchParams(window.location.search); for (const p of params) { } }
                                     ^
================================


/Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:282
        throw new JS_Parse_Error(message, line, col, pos);
        ^
Error
    at new JS_Parse_Error (/Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:260:22)

=== END (lots of cryptic text following ===


Is there a way to disable uglify-js for EM_JS and EM_ASM? For the small JS snippets I'm having it's not really worth the trouble :)

Cheers!
-Floh.


Alon Zakai

unread,
Jul 19, 2018, 11:36:31 AM7/19/18
to emscripten-discuss
Yeah, we use Uglify1 currently, which does not support ES6. We have this issue open for fixing that: https://github.com/kripken/emscripten/issues/6000 - would be great if someone has time to look into that, it's very important.

To disable it, you can do  --js-opts 0  which will disable the JS optimizer. For small JS sizes that's probably ok (and you can run your own JS minifier later if you want).

Btw, we improved those error messages in https://github.com/kripken/emscripten/pull/6545 , is that not working for you?



--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Floh

unread,
Jul 19, 2018, 12:31:55 PM7/19/18
to emscripten-discuss
Cool, thanks :)

Hmm, regarding the error messages being improved, I think I'm seeing the new error message format, but the confusing thing is that the important information is at the top, and often scrolled out of the terminal window. Most of the text at the end where one scans for errors is a JS_Parse_Error exception callstack which is basically useless information.

I also had cases where the "error cursor" is far off (but I guess that's a problem with uglify-js).

For instance this is what I get (in this case the error cursor is right though):

cpc6128.dir/roms/cpc-roms.c.o  -o /Users/floh/projects/fips-deploy/chips-test/wasm-ninja-release/cpc6128.html  examples/libcommon.a && :

JS optimizer error:
Unexpected token name, expected punc (line: 1596, col: 110, pos: 56577)

================================

function __sapp_js_focus_textfield(){ document.getElementById("_sokol_app_input_element").focus(); }
function __sapp_js_unfocus_textfield(){ document.getElementById("_sokol_app_input_element").blur(); }
function __saudio_js_buffer_frames(){ if (Module._saudio_node) { return Module._saudio_node.bufferSize; } else { return 0; } }
function __saudio_js_init(sample_rate,buffer_size){ Module._saudio_context = null; Module._saudio_node = null; if (typeof AudioContext !== 'undefined') { Module._saudio_context = new AudioContext({ sampleRate: sample_rate, latencyHint: 'interactive', }); console.log('sokol_audio.h: created AudioContext'); } else if (typeof webkitAudioContext !== 'undefined') { Module._saudio_context = new webkitAudioContext({ sampleRate: sample_rate, latencyHint: 'interactive', }); console.log('sokol_audio.h: created webkitAudioContext'); } else { Module._saudio_context = null; console.log('sokol_audio.h: no WebAudio support'); } if (Module._saudio_context) { console.log('sokol_audio.h: sample rate ', Module._saudio_context.sampleRate); Module._saudio_node = Module._saudio_context.createScriptProcessor(buffer_size, 0, 1); Module._saudio_node.onaudioprocess = function pump_audio(event) { var buf_size = event.outputBuffer.length; var ptr = Module.ccall('_saudio_emsc_pull', 'number', ['number'], [buf_size]); if (ptr) { var chan = event.outputBuffer.getChannelData(0); for (var i = 0; i < buf_size; i++) { var heap_index = (ptr>>2) + i; chan[i] = HEAPF32[heap_index]; } } }; Module._saudio_node.connect(Module._saudio_context.destination); return 1; } else { return 0; } }
function __saudio_js_sample_rate(){ if (Module._saudio_context) { return Module._saudio_context.sampleRate; } else { return 0; } }
function _args_emsc_parse_url(){ var params = new URLSearchParams(window.location.search).entries(); for (let p of params) { var kvp = p.value[0] + '=' + p.value[1]; varres = Module.ccall('args_emsc_add', 'void', ['string'], [kvp]); } }
                                                                                                              ^
================================


/Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:282
        throw new JS_Parse_Error(message, line, col, pos);
        ^
Error
    at new JS_Parse_Error (/Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:260:22)
    at js_error (/Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:282:15)
    at croak (/Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:752:17)
    at token_error (/Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:760:17)
    at expect_token (/Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:773:17)
    at expect (/Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:776:40)
    at regular_for (/Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:950:17)
    at for_ (/Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:946:24)
    at /Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:862:40
    at block_ (/Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/eliminator/node_modules/uglify-js/lib/parse-js.js:1010:32)
ERROR:root:'/Users/floh/projects/fips-sdks/osx/emsdk-portable/node/8.9.1_64bit/bin/node /Users/floh/projects/fips-sdks/osx/emsdk-portable/emscripten/incoming/tools/js-optimizer.js /tmp/tmpwtTx0t/cpc6128.bc.o.js.mem.js noPrintMetadata AJSDCE minifyWhitespace' failed
ninja: build stopped: subcommand failed.

Floh

unread,
Jul 19, 2018, 12:34:11 PM7/19/18
to emscripten-discuss
Ha, no wait, the error cursor is totally off too here. This seems to depend on whether the text is wrapping around in the terminal or not. Once it's wrapping around, the error cursor seems to be quite useless)

Alon Zakai

unread,
Jul 19, 2018, 8:29:40 PM7/19/18
to emscripten-discuss
Is it just that wrapping makes it hard to see what's going on in a particular terminal? (But even if it is that, I'm not sure offhand what the right fix is...)

On Thu, Jul 19, 2018 at 9:34 AM, Floh <flo...@gmail.com> wrote:
Ha, no wait, the error cursor is totally off too here. This seems to depend on whether the text is wrapping around in the terminal or not. Once it's wrapping around, the error cursor seems to be quite useless)

--

Floh

unread,
Jul 20, 2018, 4:03:21 AM7/20/18
to emscripten-discuss
I think it's a couple small things:

(1) it looks like there is some important info lost in the uglify error message, for instance this is printed:

Unexpected token name, expected punc (line: 1596, col: 110, pos: 56577)

When googling for that message, it seems there is info missing for what the name and punc actually is, it should look something like this:

Unexpected token name «i», expected punc «;»... 


(2) the callstack dump below the error message from the JS_Parse_Error exception is confusing when eyeball-scanning what the actual error is (I'm wondering whether I switched this on accidently in the past in my build settings somehow, are you seeing this too?)

(3) the mis-positioned error-cursor when the terminal is wrapping adds to the confusion, but if the uglify error message would be complete (see point 1) it wouldn't be so bad (and I also don't know how to fix this ;)

Cheers!
-Floh.
Reply all
Reply to author
Forward
0 new messages