Skip to content

Commit bc4628d

Browse files
committed
Add disableConstants option
1 parent 0e13b05 commit bc4628d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/JsPhpize/JsPhpizeOptions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public function __construct($options = array())
5757
new Pattern(100, 'operator', '[\\|\\^&%\\/\\*\\+\\-]='),
5858
new Pattern(110, 'operator', '[\\[\\]\\{\\}\\(\\)\\:\\.\\/\\*~\\!\\^\\|&%\\?,;\\+\\-]'),
5959
new Pattern(120, 'keyword', array('as', 'async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'do', 'else', 'enum', 'export', 'extends', 'finally', 'for', 'from', 'function', 'get', 'if', 'implements', 'import', 'in', 'instanceof', 'interface', 'let', 'new', 'of', 'package', 'private', 'protected', 'public', 'return', 'set', 'static', 'super', 'switch', 'throw', 'try', 'var', 'while', 'with', 'yield', 'yield*'), true),
60-
new Pattern(130, 'constant', 'null|undefined|Infinity|NaN|true|false|Math\.[A-Z][A-Z0-9_]*|[A-Z][A-Z0-9\\\\_\\x7f-\\xff]*|[\\\\\\x7f-\\xff_][A-Z0-9\\\\_\\x7f-\\xff]*[A-Z][A-Z0-9\\\\_\\x7f-\\xff]*', true),
60+
new Pattern(130, 'constant', 'null|undefined|Infinity|NaN|true|false|Math\.[A-Z][A-Z0-9_]*' . (isset($this->options['disableConstants']) && $this->options['disableConstants']
61+
? ''
62+
: '|[A-Z][A-Z0-9\\\\_\\x7f-\\xff]*|[\\\\\\x7f-\\xff_][A-Z0-9\\\\_\\x7f-\\xff]*[A-Z][A-Z0-9\\\\_\\x7f-\\xff]*'), true),
6163
new Pattern(135, 'variable', '[a-zA-Z\\\\\\x7f-\\xff\\$_][a-zA-Z0-9\\\\_\\x7f-\\xff\\$]*', '$'),
6264
new Pattern(140, 'operator', '[\\s\\S]'),
6365
);

tests/options.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,14 @@ public function testPatternsException()
137137
});
138138
$jsPhpize->compile('1 + 1');
139139
}
140+
141+
public function testDisableConstants()
142+
{
143+
$jsPhpize = new JsPhpize();
144+
self::assertSame('FOO', trim($jsPhpize->compile('FOO'), " \n;"));
145+
$jsPhpize = new JsPhpize(array(
146+
'disableConstants' => true,
147+
));
148+
self::assertSame('$FOO', trim($jsPhpize->compile('FOO'), " \n;"));
149+
}
140150
}

0 commit comments

Comments
 (0)