|
37 | 37 | import_sig = re.compile(r'(var|const) ([_\w$]+ *=[^;]+);')
|
38 | 38 |
|
39 | 39 |
|
| 40 | +def get_acorn_cmd(): |
| 41 | + node = config.NODE_JS |
| 42 | + if not any('--stack-size' in arg for arg in node): |
| 43 | + # Use an 8Mb stack (rather than the ~1Mb default) when running the |
| 44 | + # js optimizer since larger inputs can cause terser to use a lot of stack. |
| 45 | + node.append('--stack-size=8192') |
| 46 | + return node + [ACORN_OPTIMIZER] |
| 47 | + |
| 48 | + |
40 | 49 | def split_funcs(js):
|
41 | 50 | # split properly even if there are no newlines,
|
42 | 51 | # which is important for deterministic builds (as which functions
|
@@ -88,7 +97,7 @@ def minify_shell(self, shell, minify_whitespace):
|
88 | 97 | f.write('\n')
|
89 | 98 | f.write('// EXTRA_INFO:' + json.dumps(self.serialize()))
|
90 | 99 |
|
91 |
| - cmd = config.NODE_JS + [ACORN_OPTIMIZER, temp_file, 'minifyGlobals'] |
| 100 | + cmd = get_acorn_cmd() + [temp_file, 'minifyGlobals'] |
92 | 101 | if minify_whitespace:
|
93 | 102 | cmd.append('minifyWhitespace')
|
94 | 103 | output = shared.run_process(cmd, stdout=subprocess.PIPE).stdout
|
@@ -139,8 +148,8 @@ def chunkify(funcs, chunk_size):
|
139 | 148 | return [''.join(func[1] for func in chunk) for chunk in chunks] # remove function names
|
140 | 149 |
|
141 | 150 |
|
142 |
| -@ToolchainProfiler.profile_block('js_optimizer.run_on_js') |
143 |
| -def run_on_js(filename, passes, extra_info=None): |
| 151 | +@ToolchainProfiler.profile_block('js_optimizer.run_on_file') |
| 152 | +def run_on_file(filename, passes, extra_info=None): |
144 | 153 | with ToolchainProfiler.profile_block('js_optimizer.split_markers'):
|
145 | 154 | if not isinstance(passes, list):
|
146 | 155 | passes = [passes]
|
@@ -261,7 +270,7 @@ def write_chunk(chunk, i):
|
261 | 270 | filenames = [write_chunk(chunk, i) for i, chunk in enumerate(chunks)]
|
262 | 271 |
|
263 | 272 | with ToolchainProfiler.profile_block('run_optimizer'):
|
264 |
| - commands = [config.NODE_JS + [ACORN_OPTIMIZER, f] + passes for f in filenames] |
| 273 | + commands = [get_acorn_cmd() + [f] + passes for f in filenames] |
265 | 274 | filenames = shared.run_multiple_processes(commands, route_stdout_to_temp_files_suffix='js_opt.jo.js')
|
266 | 275 |
|
267 | 276 | with ToolchainProfiler.profile_block('split_closure_cleanup'):
|
@@ -348,7 +357,7 @@ def main():
|
348 | 357 | sys.argv = sys.argv[:-1]
|
349 | 358 | else:
|
350 | 359 | extra_info = None
|
351 |
| - out = run_on_js(sys.argv[1], sys.argv[2:], extra_info=extra_info) |
| 360 | + out = run_on_file(sys.argv[1], sys.argv[2:], extra_info=extra_info) |
352 | 361 | shutil.copyfile(out, sys.argv[1] + '.jsopt.js')
|
353 | 362 | return 0
|
354 | 363 |
|
|
0 commit comments