Skip to content

Commit f987e3b

Browse files
authored
Ensure we minify whitespace, even when transpiling using babel (#21882)
We could instead rely try to configure babel do this, but it seems more consistent to simply run our existing minifier again. Fixes: #21881
1 parent 9d954ba commit f987e3b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

test/test_other.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13365,7 +13365,7 @@ def test_hello_function(self):
1336513365

1336613366
@parameterized({
1336713367
'': ([],),
13368-
'O2': (['-O2'],),
13368+
'O3': (['-O3'],),
1336913369
})
1337013370
@crossplatform
1337113371
def test_es5_transpile(self, args):
@@ -13478,6 +13478,9 @@ def check_for_es6(filename, expect):
1347813478
self.set_setting('LEGACY_VM_SUPPORT')
1347913479
self.do_runf('test.c', expected, output_basename='test_old')
1348013480
check_for_es6('test_old.js', False)
13481+
if '-O3' in args:
13482+
# Verify that output is minified
13483+
self.assertEqual(len(read_file('test_old.js').splitlines()), 1)
1348113484

1348213485
# If we add `-sPOLYFILL=0` that transpiler is not run at all
1348313486
print('with old browser + -sPOLYFILL=0')

tools/link.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,11 +2228,15 @@ def phase_binaryen(target, options, wasm_target):
22282228
if options.use_closure_compiler:
22292229
with ToolchainProfiler.profile_block('closure_compile'):
22302230
final_js = building.closure_compiler(final_js, extra_closure_args=options.closure_args)
2231-
save_intermediate_with_wasm('closure', wasm_target)
2231+
save_intermediate('closure')
2232+
22322233
if settings.TRANSPILE:
22332234
with ToolchainProfiler.profile_block('transpile'):
22342235
final_js = building.transpile(final_js)
2235-
save_intermediate_with_wasm('traspile', wasm_target)
2236+
save_intermediate('transpile')
2237+
# Run acorn one more time to minify whitespace after babel runs
2238+
if settings.MINIFY_WHITESPACE:
2239+
final_js = building.acorn_optimizer(final_js, ['--minify-whitespace'])
22362240

22372241
if settings.ASYNCIFY_LAZY_LOAD_CODE:
22382242
with ToolchainProfiler.profile_block('asyncify_lazy_load_code'):

0 commit comments

Comments
 (0)