2013-05-19 02:04:22 +02:00
|
|
|
<?php
|
|
|
|
/** Remove spaces and comments from JavaScript code
|
|
|
|
* @param string code with commands terminated by semicolon
|
|
|
|
* @return string shrinked code
|
|
|
|
* @link http://vrana.github.com/JsShrink/
|
|
|
|
* @author Jakub Vrana, http://www.vrana.cz/
|
|
|
|
* @copyright 2007 Jakub Vrana
|
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
|
|
|
*/
|
|
|
|
function jsShrink($input) {
|
|
|
|
return preg_replace_callback('(
|
|
|
|
(?:
|
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
2024-04-14 07:36:06 +02:00
|
|
|
(`(?:\\\\.|[^`\\\\])*`) # template literal
|
|
|
|
|(^|[-+\([{}=,:;!%^&*|?~]|/(?![/*])|return|throw) # context before regexp
|
2013-05-19 02:04:22 +02:00
|
|
|
(?:\s|//[^\n]*+\n|/\*(?:[^*]|\*(?!/))*+\*/)* # optional space
|
2014-06-07 20:26:20 +02:00
|
|
|
(/(?![/*])(?:
|
|
|
|
\\\\[^\n]
|
|
|
|
|[^[\n/\\\\]++
|
|
|
|
|\[(?:\\\\[^\n]|[^]])++
|
|
|
|
)+/) # regexp
|
2013-05-19 02:04:22 +02:00
|
|
|
|(^
|
|
|
|
|\'(?:\\\\.|[^\n\'\\\\])*\'
|
|
|
|
|"(?:\\\\.|[^\n"\\\\])*"
|
|
|
|
|([0-9A-Za-z_$]+)
|
|
|
|
|([-+]+)
|
|
|
|
|.
|
|
|
|
)
|
|
|
|
)(?:\s|//[^\n]*+\n|/\*(?:[^*]|\*(?!/))*+\*/)* # optional space
|
|
|
|
)sx', 'jsShrinkCallback', "$input\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
function jsShrinkCallback($match) {
|
|
|
|
static $last = '';
|
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
2024-04-14 07:36:06 +02:00
|
|
|
$match += array_fill(1, 7, null); // avoid E_NOTICE
|
|
|
|
list(, $template, $context, $regexp, $result, $word, $operator) = $match;
|
|
|
|
if ($template) {
|
|
|
|
$result = $template;
|
|
|
|
} elseif ($word != '') {
|
2013-05-19 02:04:22 +02:00
|
|
|
$result = ($last == 'word' ? "\n" : ($last == 'return' ? " " : "")) . $result;
|
Implements copy button in clone repo modal
Summary:
This diff adds a copy button to every repo uri in the clone repo modal. I have made the button to select the text to a merely structural span before the input - it just shows the type of the repository uri. When you click inside the input, the entire uri will be selected. Also I have uncluttered the HTML structure. A table is not needed here, nothing a flex block can't handle.
| Before | After |
|-----------|-----------|
| {F1360344} | {F1368592} |
While at it, I have extended the used javascript copy behavior. First of all: `document.execCommand('copy')` [[ https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand | could stop working every moment in every browser ]]. The [[ https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard | new clipboard API ]] is the way to go, so I have implemented it as the preferred method. The old method is kept as a fallback. And I have added a very nice feature: If defined, the behavior will now issue success or error notifications. See the changed UIExamples for that.
To support the shrinking of JS code with async functions I have patched the JsShrink source.
Test Plan: Go to a repository, hit the clone button and use the new copy button. You will see a shiny notification as a reward.
Reviewers: O1 Blessed Committers, avivey, valerio.bozzolan
Reviewed By: O1 Blessed Committers, avivey, valerio.bozzolan
Subscribers: avivey, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno
Differential Revision: https://we.phorge.it/D25536
2024-02-15 19:30:57 +01:00
|
|
|
$last = ($word == 'return' || $word == 'throw' || $word == 'break' || $word == 'async' ? 'return' : 'word');
|
2013-05-19 02:04:22 +02:00
|
|
|
} elseif ($operator) {
|
|
|
|
$result = ($last == $operator[0] ? "\n" : "") . $result;
|
|
|
|
$last = $operator[0];
|
|
|
|
} else {
|
|
|
|
if ($regexp) {
|
|
|
|
$result = $context . ($context == '/' ? "\n" : "") . $regexp;
|
|
|
|
}
|
|
|
|
$last = '';
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|