Skip to content

Commit a788f15

Browse files
authored
Always preserve comments with --minify=0 is used (#20121)
This is useful for folks who want to run the closure compiler as an external step, after linking. Fixes google-internal issue: https://buganizer.corp.google.com/issues/287520718
1 parent e78076e commit a788f15

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ See docs/process.md for more on how version tagging works.
2121
3.1.46 (in development)
2222
-----------------------
2323
- libunwind updated to LLVM 16.0.6. (#20088)
24+
- The `--minify=0` commnad line flag will now preserve comments as well as
25+
whitespace. This means the resulting output can then be run though closure
26+
compiler or some other tool that gives comments semantic meaning. (#20121)
2427

2528
3.1.45 - 08/23/23
2629
-----------------

test/test_other.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13705,3 +13705,23 @@ def test_memory64_proxies(self):
1370513705
'-Wno-experimental',
1370613706
'--extern-post-js', test_file('other/test_memory64_proxies.js')])
1370713707
self.run_js('a.out.js')
13708+
13709+
def test_no_minify(self):
13710+
# Test that comments are preserved with `--minify=0` is used, even in `-Oz` builds.
13711+
# This allows the output of emscripten to be run through the closure compiler as
13712+
# as a seperate build step.
13713+
create_file('pre.js', '''
13714+
/**
13715+
* This comment should be preserved
13716+
*/
13717+
console.log('hello');
13718+
''')
13719+
comment = 'This comment should be preserved'
13720+
13721+
self.run_process([EMCC, test_file('hello_world.c'), '--pre-js=pre.js', '-Oz'])
13722+
content = read_file('a.out.js')
13723+
self.assertNotContained(comment, content)
13724+
13725+
self.run_process([EMCC, test_file('hello_world.c'), '--pre-js=pre.js', '-Oz', '--minify=0'])
13726+
content = read_file('a.out.js')
13727+
self.assertContained(comment, content)

tools/building.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def acorn_optimizer(filename, passes, extra_info=None, return_output=False):
336336
cmd = config.NODE_JS + [optimizer, filename] + passes
337337
# Keep JS code comments intact through the acorn optimization pass so that JSDoc comments
338338
# will be carried over to a later Closure run.
339-
if settings.USE_CLOSURE_COMPILER:
339+
if settings.USE_CLOSURE_COMPILER or not settings.MINIFY_WHITESPACE:
340340
cmd += ['--closureFriendly']
341341
if settings.EXPORT_ES6:
342342
cmd += ['--exportES6']

0 commit comments

Comments
 (0)