Skip to content

Commit 0569218

Browse files
author
epriestley
committedMay 19, 2013
Use JsShrink if jsxmin is not available
Summary: If `jsxmin` is not available, use a pure PHP implementation instead (JsShrink). Test Plan: - Ran `arc lint --lintall` on all JS and fixed every relevant warning. - Forced minification on and browsed around the site using JS behaviors. Didn't hit anything problematic. Reviewers: vrana, btrahan Reviewed By: vrana CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D5670
1 parent b09dc9c commit 0569218

File tree

94 files changed

+598
-501
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+598
-501
lines changed
 

‎.arcconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"phutil_libraries" : {
77
"phabricator" : "src/"
88
},
9-
"lint.xhpast.naminghook" : "PhabricatorSymbolNameLinter"
9+
"lint.xhpast.naminghook" : "PhabricatorSymbolNameLinter",
10+
"lint.jshint.config" : "support/jshint/jshintconfig"
1011
}

‎externals/JsShrink/jsShrink.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/** Remove spaces and comments from JavaScript code
3+
* @param string code with commands terminated by semicolon
4+
* @return string shrinked code
5+
* @link http://vrana.github.com/JsShrink/
6+
* @author Jakub Vrana, http://www.vrana.cz/
7+
* @copyright 2007 Jakub Vrana
8+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
9+
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
10+
*/
11+
function jsShrink($input) {
12+
return preg_replace_callback('(
13+
(?:
14+
(^|[-+\([{}=,:;!%^&*|?~]|/(?![/*])|return|throw) # context before regexp
15+
(?:\s|//[^\n]*+\n|/\*(?:[^*]|\*(?!/))*+\*/)* # optional space
16+
(/(?![/*])(?:\\\\[^\n]|[^[\n/\\\\]|\[(?:\\\\[^\n]|[^]])++)+/) # regexp
17+
|(^
18+
|\'(?:\\\\.|[^\n\'\\\\])*\'
19+
|"(?:\\\\.|[^\n"\\\\])*"
20+
|([0-9A-Za-z_$]+)
21+
|([-+]+)
22+
|.
23+
)
24+
)(?:\s|//[^\n]*+\n|/\*(?:[^*]|\*(?!/))*+\*/)* # optional space
25+
)sx', 'jsShrinkCallback', "$input\n");
26+
}
27+
28+
function jsShrinkCallback($match) {
29+
static $last = '';
30+
$match += array_fill(1, 5, null); // avoid E_NOTICE
31+
list(, $context, $regexp, $result, $word, $operator) = $match;
32+
if ($word != '') {
33+
$result = ($last == 'word' ? "\n" : ($last == 'return' ? " " : "")) . $result;
34+
$last = ($word == 'return' || $word == 'throw' || $word == 'break' ? 'return' : 'word');
35+
} elseif ($operator) {
36+
$result = ($last == $operator[0] ? "\n" : "") . $result;
37+
$last = $operator[0];
38+
} else {
39+
if ($regexp) {
40+
$result = $context . ($context == '/' ? "\n" : "") . $regexp;
41+
}
42+
$last = '';
43+
}
44+
return $result;
45+
}

0 commit comments

Comments
 (0)
Failed to load comments.