Skip to content

Commit dcd1d6d

Browse files
committed
Fix concatenation #1
1 parent dd94d91 commit dcd1d6d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/JsPhpize/Parser/ExpressionParser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ protected function getBracketsArray()
3838

3939
if (!$isValue) {
4040
switch ($token->type) {
41+
case 'newline':
42+
continue 2;
4143
case 'string':
4244
$key = $token->value;
4345
break;
@@ -140,6 +142,12 @@ protected function handlePlus(&$expression, $token, $handlePlus)
140142
}
141143
$token = $this->helperWrap('plus', $before . ' ' . implode(' ', $after));
142144
}
145+
} else {
146+
while (strval(end($expression)) === '+') {
147+
array_pop($expression);
148+
$before = array_pop($expression);
149+
$token = $this->helperWrap('plus', $before, $token);
150+
}
143151
}
144152

145153
$expression[] = $token;

tests/mainMethods.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ public function testCompileFileMissing()
115115
}
116116
}
117117

118+
/**
119+
* @group group
120+
*/
121+
public function testCompileConcat()
122+
{
123+
$jsPhpize = new JsPhpize();
124+
$actual = $jsPhpize->render('return "group[" + group.id + "]"', array(
125+
'group' => (object) array(
126+
'id' => 4,
127+
),
128+
));
129+
$expected = 'group[4]';
130+
131+
$this->assertSame($expected, $actual);
132+
}
133+
118134
public function testCompileSource()
119135
{
120136
$jsPhpize = new JsPhpize();

0 commit comments

Comments
 (0)