@@ -42,18 +42,25 @@ public function __construct(JsPhpize $engine, $input, $filename)
4242 $ this ->lexer = new Lexer ($ engine , $ input , $ filename );
4343 }
4444
45+ public function rest ()
46+ {
47+ return $ this ->lexer ->rest ();
48+ }
49+
4550 protected function parseLambda (Value $ parameters )
4651 {
4752 $ lambda = new Block ('function ' );
4853 $ lambda ->setValue ($ parameters );
4954 $ next = $ this ->next ();
55+
5056 if ($ next ) {
5157 if ($ next ->is ('{ ' )) {
5258 $ this ->parseBlock ($ lambda );
5359 $ this ->skip ();
5460
5561 return $ lambda ;
5662 }
63+
5764 $ return = new Block ('return ' );
5865 $ return ->setValue ($ this ->expectValue ($ next ));
5966 $ lambda ->addInstruction ($ return );
@@ -71,6 +78,7 @@ protected function parseParentheses($allowedSeparators = [',', ';'])
7178 while ($ token = $ this ->next ()) {
7279 if ($ token ->is (') ' )) {
7380 $ next = $ this ->get (0 );
81+
7482 if ($ next && $ next ->type === 'lambda ' ) {
7583 $ this ->skip ();
7684
@@ -204,6 +212,7 @@ protected function parseFunctionCallChildren($function, $applicant = null)
204212 $ children [] = $ value ;
205213
206214 $ next = $ this ->get (0 );
215+
207216 if ($ next && $ next ->is ('( ' )) {
208217 $ this ->skip ();
209218
@@ -225,6 +234,7 @@ protected function parseVariable($name)
225234 {
226235 $ children = [];
227236 $ variable = null ;
237+
228238 while ($ next = $ this ->get (0 )) {
229239 if ($ next ->type === 'lambda ' ) {
230240 $ this ->skip ();
@@ -238,6 +248,7 @@ protected function parseVariable($name)
238248 $ children [] = $ value ;
239249
240250 $ next = $ this ->get (0 );
251+
241252 if ($ next && $ next ->is ('( ' )) {
242253 $ this ->skip ();
243254
@@ -257,6 +268,7 @@ protected function parseVariable($name)
257268
258269 for ($ i = count ($ this ->stack ) - 1 ; $ i >= 0 ; $ i --) {
259270 $ block = $ this ->stack [$ i ];
271+
260272 if ($ block ->isLet ($ name )) {
261273 $ variable ->setScope ($ block );
262274
@@ -272,6 +284,7 @@ protected function parseTernary(Value $condition)
272284 {
273285 $ trueValue = $ this ->expectValue ($ this ->next ());
274286 $ next = $ this ->next ();
287+
275288 if (!$ next ) {
276289 throw new Exception ("Ternary expression not properly closed after '?' " . $ this ->exceptionInfos (), 14 );
277290 }
@@ -281,6 +294,7 @@ protected function parseTernary(Value $condition)
281294 }
282295
283296 $ next = $ this ->next ();
297+
284298 if (!$ next ) {
285299 throw new Exception ("Ternary expression not properly closed after ':' " . $ this ->exceptionInfos (), 16 );
286300 }
@@ -294,6 +308,7 @@ protected function parseTernary(Value $condition)
294308 protected function jsonMethodToPhpFunction ($ method )
295309 {
296310 $ function = null ;
311+
297312 switch ($ method ) {
298313 case 'stringify ' :
299314 $ function = 'json_encode ' ;
@@ -345,6 +360,7 @@ protected function parseFunction()
345360 $ function = new Block ('function ' );
346361 $ function ->enableMultipleInstructions ();
347362 $ token = $ this ->get (0 );
363+
348364 if ($ token && $ token ->type === 'variable ' ) {
349365 $ this ->skip ();
350366 $ token = $ this ->get (0 );
@@ -357,6 +373,7 @@ protected function parseFunction()
357373 $ this ->skip ();
358374 $ function ->setValue ($ this ->parseParentheses ());
359375 $ token = $ this ->get (0 );
376+
360377 if ($ token && !$ token ->is ('{ ' )) {
361378 throw $ this ->unexpected ($ token );
362379 }
@@ -374,7 +391,9 @@ protected function parseKeywordStatement($token)
374391
375392 switch ($ name ) {
376393 case 'typeof ' :
394+ // @codeCoverageIgnoreStart
377395 throw new Exception ('typeof keyword not supported ' , 26 );
396+ // @codeCoverageIgnoreEnd
378397 break ;
379398 case 'new ' :
380399 case 'clone ' :
@@ -451,6 +470,7 @@ protected function parseInstruction($block, $token, &$initNext)
451470 if ($ initNext && $ instruction instanceof Variable) {
452471 $ instruction = new Assignation ('= ' , $ instruction , new Constant ('constant ' , 'null ' ));
453472 }
473+
454474 $ initNext = false ;
455475 $ block ->addInstruction ($ instruction );
456476
0 commit comments