Index: trunk/phase3/includes/libs/jsminplus.php |
— | — | @@ -15,6 +15,7 @@ |
16 | 16 | * Usage: $minified = JSMinPlus::minify($script [, $filename]) |
17 | 17 | * |
18 | 18 | * Versionlog (see also changelog.txt): |
| 19 | + * 19-07-2011 - expanded operator and keyword defines. Fixes the notices when creating several JSTokenizer |
19 | 20 | * 17-05-2009 - fixed hook:colon precedence, fixed empty body in loop and if-constructs |
20 | 21 | * 18-04-2009 - fixed crashbug in PHP 5.2.9 and several other bugfixes |
21 | 22 | * 12-04-2009 - some small bugfixes and performance improvements |
— | — | @@ -89,6 +90,83 @@ |
90 | 91 | define('EXPRESSED_FORM', 1); |
91 | 92 | define('STATEMENT_FORM', 2); |
92 | 93 | |
| 94 | +/* Operators */ |
| 95 | +define('OP_SEMICOLON', ';'); |
| 96 | +define('OP_COMMA', ','); |
| 97 | +define('OP_HOOK', '?'); |
| 98 | +define('OP_COLON', ':'); |
| 99 | +define('OP_OR', '||'); |
| 100 | +define('OP_AND', '&&'); |
| 101 | +define('OP_BITWISE_OR', '|'); |
| 102 | +define('OP_BITWISE_XOR', '^'); |
| 103 | +define('OP_BITWISE_AND', '&'); |
| 104 | +define('OP_STRICT_EQ', '==='); |
| 105 | +define('OP_EQ', '=='); |
| 106 | +define('OP_ASSIGN', '='); |
| 107 | +define('OP_STRICT_NE', '!=='); |
| 108 | +define('OP_NE', '!='); |
| 109 | +define('OP_LSH', '<<'); |
| 110 | +define('OP_LE', '<='); |
| 111 | +define('OP_LT', '<'); |
| 112 | +define('OP_URSH', '>>>'); |
| 113 | +define('OP_RSH', '>>'); |
| 114 | +define('OP_GE', '>='); |
| 115 | +define('OP_GT', '>'); |
| 116 | +define('OP_INCREMENT', '++'); |
| 117 | +define('OP_DECREMENT', '--'); |
| 118 | +define('OP_PLUS', '+'); |
| 119 | +define('OP_MINUS', '-'); |
| 120 | +define('OP_MUL', '*'); |
| 121 | +define('OP_DIV', '/'); |
| 122 | +define('OP_MOD', '%'); |
| 123 | +define('OP_NOT', '!'); |
| 124 | +define('OP_BITWISE_NOT', '~'); |
| 125 | +define('OP_DOT', '.'); |
| 126 | +define('OP_LEFT_BRACKET', '['); |
| 127 | +define('OP_RIGHT_BRACKET', ']'); |
| 128 | +define('OP_LEFT_CURLY', '{'); |
| 129 | +define('OP_RIGHT_CURLY', '}'); |
| 130 | +define('OP_LEFT_PAREN', '('); |
| 131 | +define('OP_RIGHT_PAREN', ')'); |
| 132 | +define('OP_CONDCOMMENT_END', '@*/'); |
| 133 | + |
| 134 | +define('OP_UNARY_PLUS', 'U+'); |
| 135 | +define('OP_UNARY_MINUS', 'U-'); |
| 136 | + |
| 137 | +/* Keywords */ |
| 138 | +define('KEYWORD_BREAK', 'break'); |
| 139 | +define('KEYWORD_CASE', 'case'); |
| 140 | +define('KEYWORD_CATCH', 'catch'); |
| 141 | +define('KEYWORD_CONST', 'const'); |
| 142 | +define('KEYWORD_CONTINUE', 'continue'); |
| 143 | +define('KEYWORD_DEBUGGER', 'debugger'); |
| 144 | +define('KEYWORD_DEFAULT', 'default'); |
| 145 | +define('KEYWORD_DELETE', 'delete'); |
| 146 | +define('KEYWORD_DO', 'do'); |
| 147 | +define('KEYWORD_ELSE', 'else'); |
| 148 | +define('KEYWORD_ENUM', 'enum'); |
| 149 | +define('KEYWORD_FALSE', 'false'); |
| 150 | +define('KEYWORD_FINALLY', 'finally'); |
| 151 | +define('KEYWORD_FOR', 'for'); |
| 152 | +define('KEYWORD_FUNCTION', 'function'); |
| 153 | +define('KEYWORD_IF', 'if'); |
| 154 | +define('KEYWORD_IN', 'in'); |
| 155 | +define('KEYWORD_INSTANCEOF', 'instanceof'); |
| 156 | +define('KEYWORD_NEW', 'new'); |
| 157 | +define('KEYWORD_NULL', 'null'); |
| 158 | +define('KEYWORD_RETURN', 'return'); |
| 159 | +define('KEYWORD_SWITCH', 'switch'); |
| 160 | +define('KEYWORD_THIS', 'this'); |
| 161 | +define('KEYWORD_THROW', 'throw'); |
| 162 | +define('KEYWORD_TRUE', 'true'); |
| 163 | +define('KEYWORD_TRY', 'try'); |
| 164 | +define('KEYWORD_TYPEOF', 'typeof'); |
| 165 | +define('KEYWORD_VAR', 'var'); |
| 166 | +define('KEYWORD_VOID', 'void'); |
| 167 | +define('KEYWORD_WHILE', 'while'); |
| 168 | +define('KEYWORD_WITH', 'with'); |
| 169 | + |
| 170 | + |
93 | 171 | class JSMinPlus |
94 | 172 | { |
95 | 173 | private $parser; |
— | — | @@ -1646,16 +1724,6 @@ |
1647 | 1725 | public function __construct() |
1648 | 1726 | { |
1649 | 1727 | $this->opRegExp = '#^(' . implode('|', array_map('preg_quote', array_keys($this->opTypeNames))) . ')#'; |
1650 | | - |
1651 | | - // this is quite a hidden yet convenient place to create the defines for operators and keywords |
1652 | | - foreach ($this->opTypeNames as $operand => $name) |
1653 | | - define('OP_' . $name, $operand); |
1654 | | - |
1655 | | - define('OP_UNARY_PLUS', 'U+'); |
1656 | | - define('OP_UNARY_MINUS', 'U-'); |
1657 | | - |
1658 | | - foreach ($this->keywords as $keyword) |
1659 | | - define('KEYWORD_' . strtoupper($keyword), $keyword); |
1660 | 1728 | } |
1661 | 1729 | |
1662 | 1730 | public function init($source, $filename = '', $lineno = 1) |
— | — | @@ -1977,4 +2045,3 @@ |
1978 | 2046 | public $assignOp; |
1979 | 2047 | } |
1980 | 2048 | |
1981 | | -?> |