Closed J5lx closed 7 years ago
For reference, this is the relevant PHP that JsPhpize trips over (in my actual, non-MWE project) (if that helps at all):
array_merge(\Jade\Compiler::withMixinAttributes(array (
'name' => 'site',
'required' => true,
), array (
0 =>
array (
'name' => 'name',
'value' => 'site',
'escaped' => true,
),
1 =>
array (
'name' => 'required',
'value' => true,
'escaped' => true,
),
)), (isset($attributes)) ? $attributes : array())
I tried your code on https://pug-demo.herokuapp.com/ and get your expected result.
What is you version of PHP and of Pug?
Ah, that's because I forgot a pair of parentheses. I'm sorry for that! The actual code should be:
mixin test
div&attributes(attributes)
body
+test()(class='test')
After all, the empty pair of parens is recommended in the documentation:
The syntax
+link(class="btn")
is also valid and equivalent to+link()(class="btn")
since Pug try to detect if parentheses contents are attributes or arguments but we encourage you to use the second syntax as you pass explicitly no arguments and you ensure the first parenthesis is the arguments list.
Haha, trapped by my own words!
I will try to fix it.
Please try to update to 2.5.4, it's fixed. Feel free to re-open if anything goes wrong.
Works fine now. Thanks for fixing!
MWE:
Expected result:
Actual result:
Apparent cause:
Jade\Compiler\MixinVisitor::visitMixinCall() first passes the attributes to Jade\Compiler\MixinVisitor::parseMixinAttributes() to generate PHP code from them. This PHP code is then later merged with $arguments and passed to Jade\Compiler::createStatements(), where it is further passed down to Jade\Compiler\ExpressionCompiler::getArgumentExpression(). This function then checks for the value of the expressionLanguage option, and since it is set to JS, it tries to convert all arguments, including the generated PHP code, from JavaScript to PHP. And there you have it: The converter trips over PHP’s Paamayim Nekudotayim.
To solve the issue, there would obviously need to be a way to prevent the compiler from trying to convert the PHP code to PHP. It seems to me that ExpressionCompiler::getPhpCodeFromJs() already does this for some array and isset calls, but I'm not quite sure I understand the logic behind those regexes correctly.