File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 44
55use JsPhpize \JsPhpize ;
66use JsPhpize \Lexer \Lexer ;
7+ use JsPhpize \Nodes \Assignation ;
78use JsPhpize \Nodes \Block ;
89use JsPhpize \Nodes \BracketsArray ;
910use JsPhpize \Nodes \Constant ;
@@ -358,30 +359,40 @@ protected function parseLet()
358359
359360 protected function parseInstructions ($ block )
360361 {
362+ $ initNext = false ;
363+
361364 while ($ token = $ this ->next ()) {
362365 if ($ token ->is ($ block ->multipleInstructions ? '} ' : '; ' )) {
363366 break ;
364367 }
365368
366369 if ($ token ->type === 'keyword ' ) {
367370 if ($ token ->isIn ('var ' , 'const ' )) {
371+ $ initNext = true ;
372+
368373 continue ;
369374 }
370375
371376 if ($ token ->value === 'let ' ) {
377+ $ initNext = true ;
372378 $ block ->let ($ this ->parseLet ($ token ));
373379
374380 continue ;
375381 }
376382 }
377383
378384 if ($ instruction = $ this ->getInstructionFromToken ($ token )) {
385+ if ($ initNext && $ instruction instanceof Variable) {
386+ $ instruction = new Assignation ('= ' , $ instruction , new Constant ('constant ' , 'null ' ));
387+ }
388+ $ initNext = false ;
379389 $ block ->addInstruction ($ instruction );
380390
381391 continue ;
382392 }
383393
384394 if ($ token ->is ('; ' ) || !$ this ->engine ->getOption ('strict ' )) {
395+ $ initNext = false ;
385396 $ block ->endInstruction ();
386397
387398 continue ;
You can’t perform that action at this time.
0 commit comments