Calling macro with a parameter invoking a filter crashes
Closed this issue · 4 comments
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 %}
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.
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
@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.