JavaScriptMinifier: Fix bad state after ternary in object literal
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 13 Aug 2018 17:38:14 +0000 (18:38 +0100)
committerKrinkle <krinklemail@gmail.com>
Thu, 16 Aug 2018 17:02:07 +0000 (17:02 +0000)
commit15110b1ca9bdc6be69ab3fb47a8dc7e34ebc22d2
tree983c06a14a11bbdba99df50b25b1fc4ef2d433fe
parent7f843b0c0472b9da909d7abf7c2829eec17a5b3e
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
includes/libs/JavaScriptMinifier.php
tests/phpunit/includes/libs/JavaScriptMinifierTest.php