85define(
'JSMIN_VERSION',
'0.2');
99define(
'ORD_NL', ord(
"\n"));
100define(
'ORD_space', ord(
' '));
101define(
'ORD_cA', ord(
'A'));
102define(
'ORD_cZ', ord(
'Z'));
103define(
'ORD_a', ord(
'a'));
104define(
'ORD_z', ord(
'z'));
105define(
'ORD_0', ord(
'0'));
106define(
'ORD_9', ord(
'9'));
155define(
'JSMIN_ACT_FULL', 1);
161define(
'JSMIN_ACT_BUF', 2);
167define(
'JSMIN_ACT_IMM', 3);
234 $c ===
'_' ||
$c ===
'$' ||
$c ===
'\\' ||
$a > 126
247 public function get()
252 if ($this->isString) {
253 if ($this->inPos < $this->inLength) {
260 $c = $this->in->fgetc();
292 if ($this->isString) {
293 if ($this->inPos < $this->inLength) {
301 $c = $this->in->fgetc();
305 $this->in->fseek(-1, SEEK_CUR);
319 if ($this->isString) {
322 $this->out->fwrite(
$c);
348 switch ($this->
peek()) {
379 if ($this->
peek() ==
'/') {
386 } elseif (
$c ===
EOF) {
391 trigger_error(
'UnterminatedComment', E_USER_ERROR);
435 $this->
put($this->theA);
447 if ($tmpA ==
'\'' || $tmpA ==
'"') {
458 $tmpA = $this->theA = $this->
get();
460 if ($tmpA == $this->theB) {
469 if (ord($tmpA) <=
ORD_NL) {
474 trigger_error(
'UnterminatedStringLiteral', E_USER_ERROR);
484 $tmpA = $this->theA = $this->
get();
494 $this->theB = $this->
next();
501 if ($this->theB ==
'/' && ($tmpA ==
'(' || $tmpA ==
',' || $tmpA ==
'=')) {
506 $this->
put($this->theB);
512 $tmpA = $this->theA = $this->
get();
528 $tmpA = $this->theA = $this->
get();
529 } elseif (ord($tmpA) <=
ORD_NL) {
534 trigger_error(
'UnterminatedRegExpLiteral', E_USER_ERROR);
544 $this->theB = $this->
next();
550 trigger_error(
'Expected a JSMin::ACT_* constant in action()', E_USER_ERROR);
579 while ($this->theA !==
EOF) {
580 switch ($this->theA) {
593 switch ($this->theB) {
595 case '{':
case '[':
case '(':
620 switch ($this->theB) {
636 switch ($this->theA) {
638 case '}':
case ']':
case ')':
case '+':
639 case '-':
case '"':
case '\'':
667 if ($this->isString) {
682 public function __construct($inFileName =
'-', $outFileName =
'-', $comments =
null)
684 if ($outFileName ===
false) {
687 $this->
JSMin_File($inFileName, $outFileName, $comments);
691 public function JSMin_File($inFileName =
'-', $outFileName =
'-', $comments =
null)
697 if ($inFileName ==
'-') {
698 $inFileName =
'php://stdin';
700 if ($outFileName ==
'-') {
701 $outFileName =
'php://stdout';
726 $this->in = fopen($inFileName,
'rb');
728 trigger_error(
'Failed to open "' . $inFileName, E_USER_ERROR);
730 $this->out = fopen($outFileName,
'wb');
732 trigger_error(
'Failed to open "' . $outFileName, E_USER_ERROR);
737 if ($comments !==
null) {
738 foreach ($comments as $comm) {
739 $this->out->fwrite(
'// ' . str_replace(
"\n",
" ", $comm) .
"\n");
746 $this->in = $inString;
748 $this->inLength = strlen($inString);
750 $this->isString =
true;
752 if ($comments !==
null) {
753 foreach ($comments as $comm) {
754 $this->out .=
'// ' . str_replace(
"\n",
" ", $comm) .
"\n";
const ORD_NL
Some ASCII character ordinals.
const JSMIN_ACT_BUF
Constant describing an action() : Copy B to A.
const EOF
How fgetc() reports an End Of File.
const JSMIN_ACT_IMM
Constant describing an action() : Get the next B.
const JSMIN_ACT_FULL
Constant describing an action() : Output A.
An exception for terminatinating execution or to throw for unit testing.
A JSMin exception indicating that a file provided for input or output could not be properly opened.
Generic exception class related to JSMin.
Main JSMin application class.
JSMin_File($inFileName='-', $outFileName='-', $comments=null)
$inLength
variables used for string-based parsing
next()
Get the next character from the input stream, excluding comments.
put($c)
Adds a char to the output steram / string.
peek()
Get the next character from the input stream, without gettng it.
minify()
Run the JSMin application : minify some JS code.
action($action)
Do something !
JSMin_String($inString, $comments=null)
__construct($inFileName='-', $outFileName='-', $comments=null)
Prepare a new JSMin application.
isAlphaNum($c)
Indicates whether a character is alphanumeric or _, $, \ or non-ASCII.
A JSMin exception indicatig that an unterminated regular expression lieteral was encountered in input...
A JSMin exception indicatig that an unterminated string literal was encountered in input.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples