Commit graph

39 commits

Author SHA1 Message Date
Alangi Derick
b4ecf374fe Fix PHPDoc type for instance variables and methods
Should be "string" not "String" and "array" not "Array" in
@param, @return and @var use cases. Also, minor typo fixes.

Change-Id: I9d5ebc5b741c6560907b95f7c0c4039da2861f4a
2018-10-21 13:00:25 +01:00
Timo Tijhof
15110b1ca9 JavaScriptMinifier: Fix bad state after ternary in object literal
The following pattern of input (found in jquery.js) triggered
this bug:

    call( {
        key: 1 ? 0 : function () {
            return this;
        }
    } );

The open brace changes state to PROPERTY_ASSIGNMENT (for object literals).
The colon after 'key' sets state to PROPERTY_EXPRESSION.

Each individual parts of an expression (identifiers and literal values)
is recognised with state *_EXPRESSION_OP, such as PROPERTY_EXPRESSION_OP.

The '1' after 'key:' correctly sets the state to PROPERTY_EXPRESSION_OP.
Upto there it goes well, but after that it goes wrong.

The question mark (TYPE_HOOK) in this context was wrongly switching
back to PROPERTY_EXPRESSION. That is a problem because that does not
handle TYPE_COLON, which meant '0: function' was seen together as a
sequence of continuous PROPERTY_EXPRESSION_OP where TYPE_FUNC may
not be handled.

Fixed by changing handling of TYPE_HOOK in PROPERTY_EXPRESSION to
switch states to EXPRESSION_TERNARY, and also performing a push
so that ternary handling can pop back to the property expression.

This mirrors the handling that already exists for ternaries in
the regular handling of EXPRESSION/EXPRESSION_OP (as opposed to
the variant for object literal properties).

Bug: T201606
Change-Id: I6104c839cfc3416257543b54a91b74cb4aa4193b
2018-08-16 17:02:07 +00:00
Timo Tijhof
ff5b0acbc9 JavaScriptMinifier: Merge $push and $pop into $model
Bug: T201606
Change-Id: Ie28ccca2c44461e67964913cc76a414dce296dce
2018-08-13 18:12:43 +00:00
Timo Tijhof
48f64af342 JavaScriptMinifier: Turn $goto into a generic $model
In preparation for merging $push and $pop into it as well, so
that the state changes that happen for a particular state/type
are declared in the same place.

Bug: T201606
Change-Id: Idd12786d625621af949e7e6487e4c1655f61f295
2018-08-13 18:12:35 +00:00
Timo Tijhof
1f5f6fc204 JavaScriptMinifier: Fix bad state after '{}' in property value
Previously, $push contained:

	self::PROPERTY_EXPRESSION_OP => [
		self::TYPE_PAREN_OPEN => self::PROPERTY_EXPRESSION_OP
	],

But $pop contained:

	self::PROPERTY_EXPRESSION_OP => [ self::TYPE_BRACE_CLOSE => true ]

This meant that when a closing brace was found inside a property
expression, it would wrongly pop the stack, eventhough we are still
inside the property expression.

The impact is that everything after this is one level higher in
the stack than it should be, causing various other types to be
misinterpreted. Including in the following contrived example:

	call( function () {
		try {
		} catch (e) {
			obj = {
				key: 1 ? 0 : {} // A
			}; // B
		} // C
		return name === 'input';
	} );

In the above, the closing brace at A would close the 'obj.key' assignment
(PROPERTY_EXPRESSION_OP), instead of waiting for the closing brace at B to
decide that.

Then the closing brace at B would wrongly close the 'catch' block (instead of
the 'obj' assignment). And lastly, the closing brace at C would close the
function body (STATEMENT).

This resulted in keyword 'return' being interpreted while in state
PAREN_EXPRESSION_OP instead of STATEMENT, where PAREN_EXPRESSION_OP is the
arguments list to `call()`. In an argument list, TYPE_RETURN is not valid,
which means we stay in that state, instead of progressing to EXPRESSION_NO_NL,
which then wrongly allows for a line break to be inserted.

Bug: T201606
Change-Id: I07b809a7ca56e282ecb48b5c89c217b4b8da6856
2018-08-11 00:16:47 +01:00
Timo Tijhof
8cfe4abf8d JavaScriptMinifier: Add better line-breaker tests
Set maxLineLength to '1' instead of messing with filler content.
This makes it easy to see all potential line-breaks, instead of only
at the 999th offset.

Bug: T201606
Change-Id: I220b145c5bc8e7d1a41efacd2a6cea738545f006
2018-08-10 23:22:49 +01:00
Timo Tijhof
8f857f3621 JavaScriptMinifier: Document every operator and token type, with spec ref
* Group related operators and token types together.

* Document what each group's members have in common for the purposes of
  parsing and the state machine.

* Add spec reference.

Also confirmed that each group matches the spec (nothing missing,
nothing extra).

Bug: T201606
Change-Id: I9128beed9ab5dcf831d4655854565f826f81c602
2018-08-10 21:04:58 +01:00
Timo Tijhof
d45f943427 JavaScriptMinifier: Disambiguate token constants from state constants
Makes debugging a bit easier.

Bug: T201606
Change-Id: Icc660bc2dfa6af823722dd6567fb185308ac74e7
2018-08-10 21:04:58 +01:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Kunal Mehta
e0193327bd Fix MediaWiki.Commenting.LicenseComment.InvalidLicenseTag errors
Change-Id: I936c3f5fca1a0061f215e80469f5d882cb32ee29
2018-05-23 16:23:42 -07:00
Timo Tijhof
3316a00c26 JavaScriptMinifier: Fix "Uninitialized offset" in regexp char class parsing
Bug: T75556
Change-Id: I0bb63212dd44aec3c6b40477553dbf6a471bc7b3
2018-01-30 19:55:15 -08:00
Timo Tijhof
da786f6ae5 JavaScriptMinifier: Remove support for unused $maxLineLength param
Follows-up 93b8023946.

The $wgResourceLoaderMinifierMaxLineLength config var was deprecated
in MediaWiki 1.27. The parameter of minify() was not used by other
code, and no new usage has been introduced since then, either.

Remove the feature from JavaScriptMinifier, and add a release note.
The 1.31 release notes already contain a note about the removal
of the configuration variables.

The feature was not covered by unit tests.

Change-Id: I38eb4187e3a8e2d882f317481b43f0bf6ac3bada
2018-01-11 22:59:47 +00:00
Timo Tijhof
d43cbc7ca9 JavaScriptMinifier: Enable phpcs and fix violations
Found 90 violations. 88 fixed by phpxbf. 2 remaining violations
were Generic.Files.LineLength.TooLong (fixed manually).

Change-Id: I760acc5b249fe6f4863652de7b563eaa5f13f05f
2018-01-11 22:21:53 +00:00
Timo Tijhof
f2ef535e39 JavaScriptMinifier: Fix "Uninitialized offset" in string and regexp parsing
When parsing an incomplete string literal or regex literal at the end of a file,
$end would be set to an offset higher than $length, because the code
speculatively increases $end without correcting for this scenario.

This is due to the assumption that the strcspn() search will end because
an end character was seen, instead of simply ending because the string
doesn't have any further characters.

Bug: T75556
Change-Id: I2325c9aff33293c13ff414699c2d47306182aaa6
2018-01-11 17:47:59 +00:00
Timo Tijhof
bd8f8ca29d JavaScriptMinifier: Improve docs for parsing of string literals
Also update docs for parsing of regexp literals to match.

Bug: T75556
Change-Id: I86c79b1b1866339d65d1c69e56d457c62544aaac
2018-01-11 17:46:31 +00:00
Umherirrender
255d76f2a1 build: Updating mediawiki/mediawiki-codesniffer to 15.0.0
Clean up use of @codingStandardsIgnore
- @codingStandardsIgnoreFile -> phpcs:ignoreFile
- @codingStandardsIgnoreLine -> phpcs:ignore
- @codingStandardsIgnoreStart -> phpcs:disable
- @codingStandardsIgnoreEnd -> phpcs:enable

For phpcs:disable always the necessary sniffs are provided.
Some start/end pairs are changed to line ignore

Change-Id: I92ef235849bcc349c69e53504e664a155dd162c8
2018-01-01 14:10:16 +01:00
Thiemo Mättig
544122a6c2 Remove self-explaining "section heading" comments from classes
I can see that "parent::__construct" literally calls the parent
constructor. I can see that stuff preceeded by the keyword "protected"
is protected. I really (really) don't need comments explaining such.

Change-Id: I7458e714976a6acd3ba6a7c93fdc27d03903df83
2017-12-28 16:12:08 +01:00
Timo Tijhof
37de322d73 JavaScriptMinifier: Improve docs around parsing of regexp literals
Bug: T75556
Change-Id: Ifcb6bc21418dfc2e1d3e44dbd2497a0f5f691bf3
2017-12-24 21:48:34 +00:00
Timo Tijhof
93b8023946 JavaScriptMinifier: Remove support for unused $statementsOnOwnLine flag
The $wgResourceLoaderMinifierStatementsOnOwnLine config var was deprecated
in MediaWiki 1.27. The parameter of minify() was not used by other code, and
no new usage has been introduced since then, either.

Remove the feature from JavaScriptMinifier, and add a release note for that.
The same 1.31 release notes also contain a note already about the removal
of the configuration variable.

The feature was not covered by unit tests.

The following private variables have been removed, that are no longer used
due to this change: $newlineBefore, $newlineAfter, $newlineAdded.

Change-Id: I2cbf271156c1954abb982531d0125b4b9573b12c
2017-12-22 18:38:04 +00:00
Ori Livneh
3ecec5434e Only convert boolean true/false to !0/!1
Fix-up for I5ab29b686b8. If we encounter stupid code like
`a.true = 1;` or `a = { true: 1 }`, we should not convert that to !0/!1.
Because JSMin barfs on such input, it is necessary to add another parameter to
the test method which specifies whether or not the minified JavaScript is
supposed to be valid JavaScript by the standards of JSMin.

Change-Id: Ib78c628147fdb95982d6e33e0ab298584fb63d0b
2015-08-15 14:13:59 -07:00
Ori Livneh
a44fe77c62 JavaScriptMinifier: minify booleans
Minify true to !0 and false to !1, like Google Closure Compiler and UglifyJS2.

Change-Id: I5ab29b686b812d64a2913611be091084c06d630b
2015-08-14 17:51:59 +00:00
Siebrand Mazeland
c0c39640e4 Make phpcs-strict pass on includes/ (5/~10)
Change-Id: I259f3f11cfc22f3ed1693f9ebd5bd80491b8a6e8
2014-05-11 19:35:32 +00:00
Tyler Anthony Romeo
4dcc7961df Fixed @param tags to conform with Doxygen format.
Doxygen expects parameter types to come before the
parameter name in @param tags. Used a quick regex
to switch everything around where possible. This
only fixes cases where a primitve variable (or a
primitive followed by other types) is the variable
type. Other cases will need to be fixed manually.

Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
2013-03-11 13:15:01 -04:00
umherirrender
c157f4d424 Remove a bunch of trailing spaces and unneeded newlines
Change-Id: I52ae3c55044bc8c53698e356bad74969406670bf
2012-10-20 13:32:35 +02:00
Alexandre Emsenhuber
63176b99b7 Added missing GPLv2 headers in some places.
Also made file/class documentation more consistent.

Change-Id: I1deb70318d01a257b51948ba806d80cd1a239f4f
2012-05-04 08:47:07 +02:00
Brion Vibber
e97346ec18 Revert r103978, r103979 -- screwed something up, breaks jQuery minification.
Incremented ResourceLoader::filterCacheVersion rather than decrementing to avoid potential confusion, especially since we already needed the incr.
2011-11-23 00:22:46 +00:00
Brion Vibber
956de0db3f Functional part of r103978 (d'oh!) plus an update to the ResourceLoader filter cache key, so broken entries stuck in cache will be reloaded. 2011-11-22 23:20:50 +00:00
Platonides
a82a7940f6 Final fixup to r103910 and follow-ups.
Reverts r103931 test change.
2011-11-22 18:56:55 +00:00
Platonides
6cac97e88c Two decimal points may be valid, as 5..toString() == (5.).toString()
Added some tests
2011-11-22 18:42:21 +00:00
Platonides
b23dc2f758 Follow-up r103915: We need to increment $end before the strcspn.
Adjusting the tests, since it is now adding the newline after the number.
2011-11-22 18:10:25 +00:00
Platonides
7b9e098668 Follow-up r103915. The @fixme of r103865 was wrong.
It is apparently legal to have a decimal point without after it, 
eg. var a = 5.
Not for hexadecimal numbers.
2011-11-22 17:48:32 +00:00
Platonides
4417d4cfbe Fix r103865 fixmes about case where there a parse error should be raised.
Also detect as an error 1..0 or 1eeeeee5
2011-11-22 16:21:18 +00:00
Platonides
f0e8973335 Follow-up r103865. Accept lowercase hex and remove empty statement. 2011-11-22 16:04:39 +00:00
Brion Vibber
3e415f816f * (bug 32548) fix minification bug when numeric literal with exponent was split over lines
This broke the OpenLayers support in the Maps extension, as used for example on TranslateWiki.net.
The original JavaScriptMinifier's tokenizer (r83885) explicitly didn't bother looking for the exponent part because it "didn't matter" to its internal state machine; however since r83891 added a max line length that definitely is not true.

I've split out handling of hex and decimal numerals, and let the decimal numeral handling check for exponents.

PHPUnit test cases were added in r103846.
2011-11-21 23:16:36 +00:00
Neil Kandalgaonkar
388d13ce42 removing another use of the vertical tab & form feed escapes, which are not available in production php5.2.4 2011-03-15 04:41:15 +00:00
Neil Kandalgaonkar
50a412b7d3 the vertical tab \v and form feed \f escapes are not available in php5.2.4 which is what we run in production. Using equivalent hexadecimal 2011-03-15 04:37:06 +00:00
Roan Kattouw
27508f06af Followup r83891: don't insert a newline before ++ or -- . Patch by Paul Copperman 2011-03-14 18:04:39 +00:00
Roan Kattouw
47d5ad564b Followup r83885: implement maximum line length and statement termination (each statement on its own line) in JavaScriptMinifier. Also add globals for these things and update minify.php for these new config vars. 2011-03-14 13:24:30 +00:00
Roan Kattouw
867fc1cba8 (bug 27528) Incorporate Paul Copperman's minifier 2011-03-14 11:44:33 +00:00