pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
387 stars 42 forks source link

uppercase var name causes error #137

Closed sandrodz closed 7 years ago

sandrodz commented 7 years ago
screen shot 2017-05-24 at 3 31 00 pm
Fatal error: Uncaught JsPhpize\Parser\Exception: Unexpected . in on line 1 near from T. in /www/lithuanianbakery.dev/vendor/js-phpize/js-phpize/src/JsPhpize/Parser/TokenCrawler.php:40 Stack trace: #0 /www/lithuanianbakery.dev/vendor/js-phpize/js-phpize/src/JsPhpize/Parser/Parser.php(324): JsPhpize\Parser\TokenCrawler->unexpected(Object(JsPhpize\Lexer\Token)) #1 /www/lithuanianbakery.dev/vendor/js-phpize/js-phpize/src/JsPhpize/Parser/Parser.php(345): JsPhpize\Parser\Parser->parseInstructions(Object(JsPhpize\Nodes\Main)) #2 /www/lithuanianbakery.dev/vendor/js-phpize/js-phpize/src/JsPhpize/Parser/Parser.php(353): JsPhpize\Parser\Parser->parseBlock(Object(JsPhpize\Nodes\Main)) #3 /www/lithuanianbakery.dev/vendor/js-phpize/js-phpize/src/JsPhpize/JsPhpize.php(52): JsPhpize\Parser\Parser->parse() #4 /www/lithuanianbakery.dev/vendor/js-phpize/js-phpize/src/JsPhpize/JsPhpize.php(86): JsPhpize\JsPhpize->compile('T.curr', 'source.js') #5 [internal function]: JsPhpize\JsPhpize->compileCode('T.curr') #6 /www/lithuanianbakery.dev/vend in /www/lithuanianbakery.dev/vendor/pug-php/pug/src/Jade/Compiler/Visitor.php on line 52
screen shot 2017-05-24 at 3 31 42 pm screen shot 2017-05-24 at 3 31 39 pm
kylekatarnls commented 7 years ago

Indeed, it's a convention on purpose. Uppercase are considered as global constants. It means foobar become $foobar and FOOBAR just remains FOOBAR in the compiled code.

You have several solutions:

1/ My recommendation is: follow one of the wide-followed convention for variable names: snake case (foo_bar) or camel case (fooBar) and use uppercase for constants (define('FOO_BAR', 'value')). One uppercase char for a variable name is a bad idea: other developers that would maintain this code will never know what L is about and they will not even expect this could be a variable. (In the same way, prefer current over curr).

2/ Use the mode 'auto' or 'php' ('expressionLanguage' => 'auto') that can handle this syntax smoothly.

3/ Use the native pugjs engine ('pugjs' => true)

sandrodz commented 7 years ago

1 option sounds good. thanks!