Skip to content

Commit a47fecb

Browse files
committed
Allow all kinds of object keys
1 parent cb867a2 commit a47fecb

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

examples/object.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{color: 'red', 'font-size': '12px', 'tab-size': 12, content: ">"}

examples/object.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
array( 'color' => 'red', 'font-size' => '12px', 'tab-size' => 12, 'content' => ">" );

src/JsPhpize/Nodes/BracketsArray.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function __toString()
1313
{
1414
$items = array();
1515
foreach ($this->data as $key => $value) {
16-
$items[] = var_export($key, true) . ' => ' . $value;
16+
$items[] = $key . ' => ' . $value;
1717
}
1818

1919
return $this->export($items);

src/JsPhpize/Parser/ExpressionParser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function getBracketsArray()
3030
while ($token = $this->next()) {
3131
if ($token->type === '}') {
3232
if (!empty($value)) {
33-
$array->addItem($key, $value);
33+
$array->addItem(strval($key), $value);
3434
}
3535

3636
return $array;
@@ -39,11 +39,11 @@ protected function getBracketsArray()
3939
if (!$isValue) {
4040
switch ($token->type) {
4141
case 'string':
42-
$key = json_decode($token->value);
42+
$key = $token->value;
4343
break;
4444
case 'variable':
4545
case 'constant':
46-
$key = $token->value;
46+
$key = var_export($token->value, true);
4747
break;
4848
}
4949
if ($key === null) {
@@ -54,7 +54,7 @@ protected function getBracketsArray()
5454
continue;
5555
}
5656
if ($token->type === ',') {
57-
$array->addItem(in_array($key->type, array('constant', 'variable')) ? var_export($key->value, true) : strval($key), $value);
57+
$array->addItem(strval($key), $value);
5858
$isValue = false;
5959
$key = null;
6060
$value = null;

0 commit comments

Comments
 (0)