@@ -325,21 +325,61 @@ protected function parseTernary(Node $condition)
325325
326326 protected function parseValue ($ token )
327327 {
328- $ value = $ token ->is ('variable ' )
328+ return $ token ->is ('variable ' )
329329 ? $ this ->parseVariable ($ token ->value )
330330 : new Constant ($ token ->type , $ token ->value );
331+ }
332+
333+ protected function getInitialValue ($ token )
334+ {
335+ if ($ token ->is ('function ' )) {
336+ $ function = new Block ('function ' );
337+ $ token = $ this ->get (0 );
338+ if ($ token ->is ('variable ' )) {
339+ $ this ->skip ();
340+ $ token = $ this ->get (0 );
341+ }
342+ if (!$ token ->is ('( ' )) {
343+ $ this ->unexpected ($ token );
344+ }
345+ $ this ->skip ();
346+ $ function ->setValue ($ this ->parseParentheses ());
347+ $ token = $ this ->get (0 );
348+ if (!$ token ->is ('{ ' )) {
349+ $ this ->unexpected ($ token );
350+ }
351+ $ this ->skip ();
352+ $ this ->parseBlock ($ function );
353+ $ this ->skip ();
354+
355+ return $ function ;
356+ }
357+ if ($ token ->is ('( ' )) {
358+ return $ this ->parseParentheses ();
359+ }
360+ if ($ token ->is ('[ ' )) {
361+ return $ this ->parseHooksArray ();
362+ }
363+ if ($ token ->is ('{ ' )) {
364+ return $ this ->parseBracketsArray ();
365+ }
366+ if ($ token ->isOperator () && $ token ->isIn ('~ ' , '! ' , '-- ' , '++ ' , '- ' , '+ ' , 'delete ' , 'typeof ' , 'void ' )) {
367+ $ value = $ this ->expectValue ($ this ->next (), $ token );
368+ $ value ->prepend ($ token ->type );
331369
370+ return $ value ;
371+ }
372+ if ($ token ->isValue ()) {
373+ return $ this ->parseValue ($ token );
374+ }
375+ }
376+
377+ protected function appendFunctionsCalls (&$ value )
378+ {
332379 while ($ token = $ this ->get (0 )) {
333380 if ($ token ->isValue ()) {
334381 $ this ->unexpected ($ this ->next ());
335382 }
336- if ($ token ->is ('( ' )) {
337- $ this ->skip ();
338- $ arguments = array ();
339- $ value = new FunctionCall ($ value , $ this ->parseParentheses ()->nodes );
340-
341- continue ;
342- }
343383 if ($ token ->is ('{ ' ) || $ token ->expectNoLeftMember ()) {
344384 $ this ->unexpected ($ this ->next ());
345385 }
@@ -349,6 +389,13 @@ protected function parseValue($token)
349389
350390 continue ;
351391 }
392+ if ($ token ->is ('( ' )) {
393+ $ this ->skip ();
394+ $ arguments = array ();
395+ $ value = new FunctionCall ($ value , $ this ->parseParentheses ()->nodes );
396+
397+ continue ;
398+ }
352399 if ($ token ->isOperator ()) {
353400 if ($ token ->isIn ('++ ' , '-- ' )) {
354401 $ value ->append ($ this ->next ()->type );
@@ -374,52 +421,16 @@ protected function parseValue($token)
374421
375422 break ;
376423 }
377-
378- return $ value ;
379424 }
380425
381426 protected function getValueFromToken ($ token )
382427 {
383- if ($ token ->is ('function ' )) {
384- $ function = new Block ('function ' );
385- $ token = $ this ->get (0 );
386- if ($ token ->is ('variable ' )) {
387- $ this ->skip ();
388- $ token = $ this ->get (0 );
389- }
390- if (!$ token ->is ('( ' )) {
391- $ this ->unexpected ($ token );
392- }
393- $ this ->skip ();
394- $ function ->setValue ($ this ->parseParentheses ());
395- $ token = $ this ->get (0 );
396- if (!$ token ->is ('{ ' )) {
397- $ this ->unexpected ($ token );
398- }
399- $ this ->skip ();
400- $ this ->parseBlock ($ function );
401- $ this ->skip ();
402-
403- return $ function ;
404- }
405- if ($ token ->is ('( ' )) {
406- return $ this ->parseParentheses ();
407- }
408- if ($ token ->is ('[ ' )) {
409- return $ this ->parseHooksArray ();
428+ $ value = $ this ->getInitialValue ($ token );
429+ if ($ value ) {
430+ $ this ->appendFunctionsCalls ($ value );
410431 }
411- if ($ token ->is ('{ ' )) {
412- return $ this ->parseBracketsArray ();
413- }
414- if ($ token ->isOperator () && $ token ->isIn ('~ ' , '! ' , '-- ' , '++ ' , '- ' , '+ ' , 'delete ' , 'typeof ' , 'void ' )) {
415- $ value = $ this ->expectValue ($ this ->next (), $ token );
416- $ value ->prepend ($ token ->type );
417432
418- return $ value ;
419- }
420- if ($ token ->isValue ()) {
421- return $ this ->parseValue ($ token );
422- }
433+ return $ value ;
423434 }
424435
425436 public function parseBlock ($ block )
@@ -458,7 +469,7 @@ public function parseBlock($block)
458469 case 'continue ' :
459470 case 'break ' :
460471 $ afterKeyword = $ this ->get (0 );
461- if ($ afterKeyword && $ afterKeyword -> isValue ( )) {
472+ if (! $ afterKeyword-> is ( ' ; ' )) {
462473 $ value = $ this ->expectValue ($ this ->next ());
463474 $ keyword ->setValue ($ value );
464475 }
0 commit comments