Open uncenter opened 4 days ago
Thanks for submitting an issue and for including a reduced test case! I took a look at your reproduction and noticed that you didn't declare myShortcode
in the Eleventy config file, like so:
export default function defineConfig(eleventyConfig) {
eleventyConfig.addShortcode('myShortcode', (...args) => `Provided args were ${args.join(', ')}`)
}
Like other template languages, Vento is pretty strict about tags being used without being defined. Once registered as above, this template:
{{ myShortcode 'arg1', 'arg2' }}
Compiles to:
Provided args were arg1, arg2
If you don't mind, I'm interested to hear a solution you'd like to see to handle this case, since this is more of a user error than a bug in this plugin or Vento. I'm happy to dig into my source to see if I can catch any errors from Vento during the compile step, or either one of us can open an issue upstream to get support for unknown tag handling by Vento itself. Let me know if you have any thoughts otherwise I'll close this as the behavior you've experienced is what's expected.
Why does not declaring it cause a syntax/parsing error? That should be a runtime error I would think if the function isn't defined.
(Specifically my issue was adding the Vento plugin before another plugin that added the shortcode I was using, fwiw.)
Glad you solved it!
I'm not completely sure, but my best guess is that when Vento transforms template functions via meriyah there's a breakdown in parsing because the parser expects arguments to be wrapped in ()
. The transform step is necessary because Vento tries to avoid using with
and transforms references in the compliled template function from varname
to it.varname
.
Again this is only my best guess. You can see the change that introduced this functionality as well as the discussion around it here: https://github.com/ventojs/vento/pull/43
Lastly, I did look into my code in the past hour and the problem is that the error is reported on the code of the compiled template function (this syntax), so trying to trace that back to the offending line in the .vto
file is beyond the scope of this plugin and should be handled in Vento itself.
Reopening to track implemeting of ventojs/vento#85
Steps to reproduce
Add the example
{{ myShortcode 'arg1', 'arg2' }}
from the README to a Vento template.Expected behavior
Successful build.
Actual behavior
Plugin version
4.0.1
Eleventy version
3.0.0
Reduced Test Case URL
https://github.com/uncenter/vento-11ty-repro
Additional information
No response