6 * jsParser will take javascript source code and minify it.
8 * Note: There is a lot of redundant code since both passes
9 * operate similarly but with slight differences. It will probably
10 * be a good idea to refactor the code at a later point when it is stable.
12 * JSParser will perform 3 passes on the code. Pass 1 takes care of single
13 * line and mult-line comments. Pass 2 performs some sanitation on each of the lines
14 * and pass 3 works on stripping out unnecessary spaces.
17 * @param string $currentOptions
20 private function __construct($text, $compression) {
21 $this->text = trim($text)."\n";
22 $this->compression = $compression;
26 * Entry point function to minify javascript.
28 * @param string $js Javascript source code as a string.
29 * @param string $compression Compression option. {light, deep}.
30 * @return string $output Output javascript code as a string.
32 static public function minify($js, $compression = 'light') {
34 $me = new SugarMin($js, $compression);
35 $output = $me->jsParser();
38 } catch (Exception $e) {
39 // Exception handling is left up to the implementer.
44 protected function jsParser() {
45 require_once('jssource/Minifier.php');
46 return Minifier::minify($this->text);