r92563 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92562‎ | r92563 | r92564 >
Date:20:03, 19 July 2011
Author:platonides
Status:resolved (Comments)
Tags:
Comment:
Expand the defines from JSTokenizer::__construct() placing them at the top of the file.
This fixes the Notices that would be produced if several JSTokenizer were instantiated.
jsminplus was added in r91591.

Defines code was generated with:
$js = new JSTokenizer();
foreach ($js->opTypeNames as $operand => $name) echo "define('OP_$name', '$operand');\n";
foreach ($js->keywords as $keyword) echo "define('KEYWORD_" . strtoupper($keyword) . "', '$keyword');\n";
Modified paths:
  • /trunk/phase3/includes/libs/jsminplus.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/libs/jsminplus.php
@@ -15,6 +15,7 @@
1616 * Usage: $minified = JSMinPlus::minify($script [, $filename])
1717 *
1818 * Versionlog (see also changelog.txt):
 19+ * 19-07-2011 - expanded operator and keyword defines. Fixes the notices when creating several JSTokenizer
1920 * 17-05-2009 - fixed hook:colon precedence, fixed empty body in loop and if-constructs
2021 * 18-04-2009 - fixed crashbug in PHP 5.2.9 and several other bugfixes
2122 * 12-04-2009 - some small bugfixes and performance improvements
@@ -89,6 +90,83 @@
9091 define('EXPRESSED_FORM', 1);
9192 define('STATEMENT_FORM', 2);
9293
 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+
93171 class JSMinPlus
94172 {
95173 private $parser;
@@ -1646,16 +1724,6 @@
16471725 public function __construct()
16481726 {
16491727 $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);
16601728 }
16611729
16621730 public function init($source, $filename = '', $lineno = 1)
@@ -1977,4 +2045,3 @@
19782046 public $assignOp;
19792047 }
19802048
1981 -?>

Follow-up revisions

RevisionCommit summaryAuthorDate
r92586Merge code cleanup revisions so that code analysis can also be performed in t...platonides21:29, 19 July 2011
r93020Update JSMin+ to the newly released 1.4...platonides21:46, 24 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91591Followup r83885: add JSMin+ 1.3 to use its parser to verify output of JavaScr...brion20:02, 6 July 2011

Comments

#Comment by Reedy (talk | contribs)   20:18, 19 July 2011

Can we get this pushed upstream?

Though, I'm not sure where that is.. [1] is 1.1...

http://code.google.com/p/minify/

#Comment by Platonides (talk | contribs)   21:26, 19 July 2011

I sent an email to Tino Zijdel.

Upstream is http://crisp.tweakblogs.net/blog/cat/716 That project seem to have an old version imported.

#Comment by Nikerabbit (talk | contribs)   08:50, 20 July 2011

Can we somehow indicate that the latest changes are our own and departs from "upstream" (for now at least)?

#Comment by Brion VIBBER (talk | contribs)   17:48, 20 July 2011

Please VERY CLEARLY mark anything that diverges from upstream -- when we next update this, we don't want to lose it! Preferably don't diverge at all, and get it pushed upstream.

#Comment by Platonides (talk | contribs)   21:47, 24 July 2011

This has been included into JSMin+ 1.4 http://crisp.tweakblogs.net/blog/6861/jsmin+-version-14.html

#Comment by 😂 (talk | contribs)   23:22, 2 August 2011

With r93020, this is resolved.

Status & tagging log