Skip to content
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

Calling macro with a parameter invoking a filter crashes #76

Closed
gushromp opened this issue Feb 7, 2018 · 4 comments
Closed

Calling macro with a parameter invoking a filter crashes #76

gushromp opened this issue Feb 7, 2018 · 4 comments
Milestone

Comments

@gushromp
Copy link

gushromp commented Feb 7, 2018

So I have a macro
{% macro someMacro someParameter %}

And when I attempt to invoke it like this:
{% call someMacro myType.storedVariables|annotated:"someAnnotation" %}

I get this fatal exception:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SourceryRuntime.Struct 0x7f94a2e1a5a0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key storedVariables|annotated:"json".'

Calling the macro without the filter on storedVariables works just fine:
{% call someMacro myType.storedVariables %}

@Liquidsoul
Copy link
Member

Hi @gushromp,

Depending on what your macro does, maybe you could use the map tag to work around this issue?

@gushromp
Copy link
Author

gushromp commented Feb 9, 2018

Hi @Liquidsoul
Thanks for the help, but unfortunately that doesn't seem to work, either, for my use case - since it seems that the map tag does not keep the original type of what it's mapping over.

So for example, if I write:
{% map myType.storedVariables into myArray %}{{ maploop.item }}{% endmap %}

Originally, the type of item is a Sourcery Variable type, but after being mapped it gets transformed into some other type and some functions no longer work, such as isArray.

Perhaps I'm just doing the mapping wrong? I tried using just maploop.item instead of {{ maploop.item }} but it gets parsed as a string literal.

@djbe
Copy link
Member

djbe commented Feb 9, 2018

You can always use the set tag inside before your call tag, or inside your macro block to apply filters I think.

I'm curious though, how does Stencil do this? (ping @kylef) Is it this line?

VariableNode(variable: resolvable).render(context)

https://github.com/kylef/Stencil/blob/master/Sources/FilterTag.swift#L31

@ilyapuchka
Copy link
Collaborator

@djbe wrapping in variable node will stringify the result but current tests expect the type of arguments to be preserved. So just compiling arguments as filter expressions should be sufficient.

@djbe djbe added this to the 2.6.0 milestone Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants