Skip to content

Commit dde22e0

Browse files
committed
Handle lonely expressions
1 parent 0d90f46 commit dde22e0

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-1
lines changed

examples/solo-ternary.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(1) ? 1 : 0

examples/solo-ternary.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(1) ? 1 : 0;

src/JsPhpize/JsPhpize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class JsPhpize extends JsPhpizeOptions
1616
protected $stream = 'jsphpize.stream';
1717

1818
/**
19-
* @var bool
19+
* @var array
2020
*/
2121
protected $streamsRegistered = array();
2222

src/JsPhpize/Parser/Parser.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ protected function parseLambda(Value $parameters)
6262
return $lambda;
6363
}
6464

65+
protected function parseValueCompletion(&$base, $token)
66+
{
67+
if ($token && $token->is('?')) {
68+
$base = $this->parseTernary($base);
69+
}
70+
71+
$this->appendFunctionsCalls($base);
72+
}
73+
6574
protected function parseParentheses()
6675
{
6776
$parentheses = new Parenthesis();
@@ -381,6 +390,14 @@ protected function parseInstructions($block)
381390
continue;
382391
}
383392

393+
if ($token->isIn('?', '(', '[') || $token->isOperator()) {
394+
$value = $block->value;
395+
$this->parseValueCompletion($value, $token);
396+
$block->addInstruction($value);
397+
398+
continue;
399+
}
400+
384401
if ($token->is(';') || !$this->engine->getOption('strict')) {
385402
$block->endInstruction();
386403

tests/compile.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function caseProvider()
1919
}
2020

2121
/**
22+
* @group examples
2223
* @dataProvider caseProvider
2324
*/
2425
public function testJsPhpizeGeneration($phpFile, $jsFile)

tests/render.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function caseProvider()
1919
}
2020

2121
/**
22+
* @group examples
2223
* @dataProvider caseProvider
2324
*/
2425
public function testJsPhpizeGeneration($returnFile, $jsFile)

0 commit comments

Comments
 (0)