diff --git a/emcc.py b/emcc.py index 9187ae4a5db4d..37f4bb41ab2e7 100755 --- a/emcc.py +++ b/emcc.py @@ -2977,6 +2977,9 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam def minify_html(filename, options): + if shared.Settings.DEBUG_LEVEL >= 2: + return + opts = [] # -g1 and greater retain whitespace and comments in source if shared.Settings.DEBUG_LEVEL == 0: @@ -3006,13 +3009,10 @@ def minify_html(filename, options): # '--remove-empty-elements': removes all elements with empty contents. # (Breaks at least browser.test_asm_swapping) - if shared.Settings.DEBUG_LEVEL >= 2: - return - logger.debug('minifying HTML file ' + filename) size_before = os.path.getsize(filename) start_time = time.time() - run_process(shared.get_npm_cmd('html-minifier-terser') + [filename, '-o', filename] + opts, env=shared.env_with_node_in_path()) + shared.check_call(shared.get_npm_cmd('html-minifier-terser') + [filename, '-o', filename] + opts, env=shared.env_with_node_in_path()) elapsed_time = time.time() - start_time size_after = os.path.getsize(filename) diff --git a/tests/test_other.py b/tests/test_other.py index 617907d2c4da1..25d61c8f369d9 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -7721,18 +7721,25 @@ def build(): self.assertIdentical(normal, tiny) self.assertIdentical(normal, huge) - def test_EM_ASM_ES6(self): + @parameterized({ + '': ([],), # noqa + 'O3': (['-O3'],), # noqa + 'closure': (['--closure', '1'],), # noqa + 'closure_O3': (['--closure', '1', '-O3'],), # noqa + }) + def test_EM_ASM_ES6(self, args): create_test_file('src.cpp', r''' #include int main() { EM_ASM({ - var x = (a, b) => 5; // valid ES6 + let x = (a, b) => 5; // valid ES6 async function y() {} // valid ES2017 out('hello!'); + return x; }); } ''') - self.run_process([EMCC, 'src.cpp', '-O2']) + self.run_process([EMCC, 'src.cpp'] + args) self.assertContained('hello!', self.run_js('a.out.js')) def test_check_sourcemapurl(self): diff --git a/tools/acorn-optimizer.js b/tools/acorn-optimizer.js index 707ca869acbc8..c272aca3a5735 100644 --- a/tools/acorn-optimizer.js +++ b/tools/acorn-optimizer.js @@ -1301,6 +1301,7 @@ var sourceComments = []; var ast; try { ast = acorn.parse(input, { + // Keep in sync with --language_in that we pass to closure in building.py ecmaVersion: 2018, preserveParens: closureFriendly, onComment: closureFriendly ? sourceComments : undefined diff --git a/tools/building.py b/tools/building.py index 4c00a639f6785..21a49a03b06e3 100644 --- a/tools/building.py +++ b/tools/building.py @@ -1031,8 +1031,16 @@ def add_to_path(dirname): outfile = filename + '.cc.js' configuration.get_temp_files().note(outfile) - args = ['--compilation_level', 'ADVANCED_OPTIMIZATIONS' if advanced else 'SIMPLE_OPTIMIZATIONS', - '--language_in', 'ECMASCRIPT5'] + args = ['--compilation_level', 'ADVANCED_OPTIMIZATIONS' if advanced else 'SIMPLE_OPTIMIZATIONS'] + # Keep in sync with ecmaVersion in tools/acorn-optimizer.js + args += ['--language_in', 'ECMASCRIPT_2018'] + # Tell closure not to do any transpiling or inject any polyfills. + # At some point we may want to look into using this as way to convert to ES5 but + # babel is perhaps a better tool for that. + args += ['--language_out', 'NO_TRANSPILE'] + # Tell closure never to inject the 'use strict' directive. + args += ['--emit_use_strict=false'] + for e in CLOSURE_EXTERNS: args += ['--externs', e] args += ['--js_output_file', outfile]