@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

T15774: Celerity: javascript minification issue with template literals (backticked strings)

Test Plan:
This archive contains a small demo: {F2142567}
When installed, an application named D25571 appears under "More Applications".
When you start it, you will see 2 messageboxes: one should be a single lined text, the other a multilined text.

Steps:
1) unpack archive in some directory
2) add ext-D25571/src/ path to load-libraries in local.json
3) bin/arc liberate
4) bin/cache purge --all
5) bin/celerity map
6) restart httpd
7) start D25571 application from More Applications

Also:

arc unit ./src/applications/celerity/__tests__/CelerityResourceTransformerTestCase.php

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: avivey, aklapper, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15774

Differential Revision: https://we.phorge.it/D25571

+7 -4
+7 -4
externals/JsShrink/jsShrink.php
··· 11 11 function jsShrink($input) { 12 12 return preg_replace_callback('( 13 13 (?: 14 - (^|[-+\([{}=,:;!%^&*|?~]|/(?![/*])|return|throw) # context before regexp 14 + (`(?:\\\\.|[^`\\\\])*`) # template literal 15 + |(^|[-+\([{}=,:;!%^&*|?~]|/(?![/*])|return|throw) # context before regexp 15 16 (?:\s|//[^\n]*+\n|/\*(?:[^*]|\*(?!/))*+\*/)* # optional space 16 17 (/(?![/*])(?: 17 18 \\\\[^\n] ··· 31 32 32 33 function jsShrinkCallback($match) { 33 34 static $last = ''; 34 - $match += array_fill(1, 5, null); // avoid E_NOTICE 35 - list(, $context, $regexp, $result, $word, $operator) = $match; 36 - if ($word != '') { 35 + $match += array_fill(1, 7, null); // avoid E_NOTICE 36 + list(, $template, $context, $regexp, $result, $word, $operator) = $match; 37 + if ($template) { 38 + $result = $template; 39 + } elseif ($word != '') { 37 40 $result = ($last == 'word' ? "\n" : ($last == 'return' ? " " : "")) . $result; 38 41 $last = ($word == 'return' || $word == 'throw' || $word == 'break' || $word == 'async' ? 'return' : 'word'); 39 42 } elseif ($operator) {