PHP Class MatthiasMullie\Minify\JS
This source file can be used to minify Javascript files.
The class is documented in the file itself. If you find any bugs help me out and report them. Reporting can be done by sending an email to
[email protected].
If you report a bug, make sure you give me enough information (include your code).
License
Copyright (c) 2012, Matthias Mullie. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
This software is provided by the author "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the author be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
Mostra file
Open project: matthiasmullie/minify
Class Usage Examples
Protected Properties
Property |
Type |
Description |
|
$keywordsAfter |
string[] |
..>
before them. Some end of lines are not the end of a statement, like when
continued by one of these keywords on the newline.
E.g.: we shouldn't insert a ; before this instanceof
variable
instanceof String
Will be loaded from /data/js/keywords_after.txt |
|
$keywordsBefore |
string[] |
..>
after them. Some end of lines are not the end of a statement, like with
these keywords.
E.g.: we shouldn't insert a ; after this else
else
console.log('this is quite fine')
Will be loaded from /data/js/keywords_before.txt |
|
$keywordsReserved |
string[] |
Will be loaded from /data/js/keywords_reserved.txt. |
|
$operators |
string[] |
Will be loaded from /data/js/operators.txt |
|
$operatorsAfter |
string[] |
..> before
them. Some end of lines are not the end of a statement, like when
continued by one of these operators on the newline.
Note: Most operators are fine, we've only removed ), ], ++ and --.
++ & -- have to be joined with the value they're in-/decrementing.
) & ] are "special" in that they have lots or usecases. () for example
is used for function calls, for grouping, in if () and for (), ...
Will be loaded from /data/js/operators_after.txt |
|
$operatorsBefore |
string[] |
..> after
them. Some end of lines are not the end of a statement, like with these
operators.
Note: Most operators are fine, we've only removed !, ++ and --.
There can't be a newline separating ! and whatever it is negating.
++ & -- have to be joined with the value they're in-/decrementing.
Will be loaded from /data/js/operators_before.txt |
|
Public Methods
Protected Methods
Method Details
__construct()
public method
Perform JS optimizations.
public execute ( string[optional] $path = null ) : string |
$path |
string[optional] |
|
return |
string |
The minified data |
getKeywordsForRegex()
protected method
This will prepare the given array by escaping all characters.
getOperatorsForRegex()
protected method
This will prepare the given array by escaping all characters.
propertyNotation()
protected method
Replaces all occurrences of array['key'] by array.key.
shortenBools()
protected method
Replaces true & false by !0 and !1.
stripWhitespace()
protected method
We won't strip *all* whitespace, but as much as possible. The thing that
we'll preserve are newlines we're unsure about.
JavaScript doesn't require statements to be terminated with a semicolon.
It will automatically fix missing semicolons with ASI (automatic semi-
colon insertion) at the end of line causing errors (without semicolon.)
Because it's sometimes hard to tell if a newline is part of a statement
that should be terminated or not, we'll just leave some of them alone.
Property Details
$keywordsAfter protected_oe property
..>
before them. Some end of lines are not the end of a statement, like when
continued by one of these keywords on the newline.
E.g.: we shouldn't insert a ; before this instanceof
variable
instanceof String
Will be loaded from /data/js/keywords_after.txt
protected string[] $keywordsAfter |
return |
string[] |
|
$keywordsBefore protected_oe property
..>
after them. Some end of lines are not the end of a statement, like with
these keywords.
E.g.: we shouldn't insert a ; after this else
else
console.log('this is quite fine')
Will be loaded from /data/js/keywords_before.txt
protected string[] $keywordsBefore |
return |
string[] |
|
$keywordsReserved protected_oe property
Will be loaded from /data/js/keywords_reserved.txt.
protected string[] $keywordsReserved |
return |
string[] |
|
$operators protected_oe property
Will be loaded from /data/js/operators.txt
protected string[] $operators |
return |
string[] |
|
$operatorsAfter protected_oe property
..> before
them. Some end of lines are not the end of a statement, like when
continued by one of these operators on the newline.
Note: Most operators are fine, we've only removed ), ], ++ and --.
++ & -- have to be joined with the value they're in-/decrementing.
) & ] are "special" in that they have lots or usecases. () for example
is used for function calls, for grouping, in if () and for (), ...
Will be loaded from /data/js/operators_after.txt
protected string[] $operatorsAfter |
return |
string[] |
|
$operatorsBefore protected_oe property
..> after
them. Some end of lines are not the end of a statement, like with these
operators.
Note: Most operators are fine, we've only removed !, ++ and --.
There can't be a newline separating ! and whatever it is negating.
++ & -- have to be joined with the value they're in-/decrementing.
Will be loaded from /data/js/operators_before.txt
protected string[] $operatorsBefore |
return |
string[] |
|