-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetAttrCompiler produces redundant macros arguments during macros call compilation #67
Conversation
Thank you to solve this problem because I also |
Hi, I have the same problem. I have a macro that call another macro, but it doesn't work because the generate file contains wrong array. Thanks
give the output result :
|
@phoenix741 Does your macros work with version of twig.js containing my changes proposed to fix this issue? |
I'm finding the Template{% macro show(value) %}
The value is {{ value }}
{% endmacro %}
{{ _self.show("Hello World!") }} Expected Output
Actual Output
|
Rerunning the test case with the code change from the proposed fix, it works as expected.
I'll make some time to look at this in more depth and do some regression testing. It'd be nice if we could fit this into the automated test suite somehow so that it can never break again without us noticing as well. Thanks for the patch btw :) |
@h2s, yeah, your are right, some regression testing is very appreciated there. Unfortunately we have not enough test fixtures to cover the most cases.. Anyway we can add your example as a fixture to the current pull-request. |
Macro parameters aren't getting passed into the macros properly.
I've ported Twig's integration testing system to Twig.js to help with this issue. It's awesome, now we can write full integration test cases to reproduce bugs like these in a way that we can incorporate into the test suite. Here's the test case for this one.
I'm confident enough now to merge your fix too. Thanks for being so patient with this issue. It took me a while to set aside some time to work on Twig.js again :) |
Hmmm, GitHub isn't clever enough to detect that I've rebased your pull request before merging it. Rest assured, your fix is now merged into schmittjoh/twig.js as commit 6775ffa. Looks like I'll have to close the PR manually though. Thanks again! |
Ok, thank you) |
Hello @schmittjoh!
Probably there is an issue with compiling twig macros calls with parameters.
That's my case below.
I am using two twig templates in symfony 2 application.
The first one contains show macro definition and looks like this:
The second one includes show macro and invokes it with 2 parameters:
After compilation i am trying to call the second template from javascript like this:
The expected result is:
But actual result looks like this:
Attempting to understand the problem i've analyzed compiled representation of my both original twig templates. The second one has redundant argument 0 in show parameter list, therefore original macro did not work as expected:
The cause of this is clear to me: twig parser fills macro parameters into Twig_Node_Expression_Array object using its addElement method that prepends each element with new constant node that contains index of element (excluding associative arrays case with it predefined keys).
And then twig-js's GetAttrCompiler compiles all the parameters (including generated index-elements) provided by parser into js function arguments here: https://github.com/schmittjoh/twig.js/blob/master/src/TwigJs/Compiler/Expression/GetAttrCompiler.php#L60-L74 and it causes extra parameters appearance.
What if we'll use ArrayCompiler to compile getattr arguments? In this case we would manage flexibly argument sets as key-values and get only needed values in getattr arguments lists.