-
-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add keyword arguments for Liquid shortcodes #3444
base: main
Are you sure you want to change the base?
Conversation
Hmm, I’m seeing some test suite failures here from some missing variables in Liquid.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great but has a few small issues!
I think the big question I have is in the test suite tests—I would imagine these tests would need to be gated behind eleventyConfig.setLiquidParameterParsing("builtin");
similar to what shipped in #2679 (comment)
src/Engines/Liquid.js
Outdated
let value = tokenizer.readHash() ?? tokenizer.readValue(); | ||
// readHash() treats unmarked identifiers as hash keys with undefined | ||
// values, but we want to parse them as positional arguments instead. | ||
return value?.kind === 64 && value.value === undefined ? value.name : value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m seeing some errors here, from LiquidJS’s types: value
and name
do not exist on type HashToken | ValueToken | RangeToken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's weird, I would expect Liquid to be typed so that the value.kind
check type-infers value
to be a HashToken
. I've made that explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests keep timing out locally, so I'm not 100% confident they're passing now. But I did fix all the known issues!
src/Engines/Liquid.js
Outdated
let value = tokenizer.readHash() ?? tokenizer.readValue(); | ||
// readHash() treats unmarked identifiers as hash keys with undefined | ||
// values, but we want to parse them as positional arguments instead. | ||
return value?.kind === 64 && value.value === undefined ? value.name : value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's weird, I would expect Liquid to be typed so that the value.kind
check type-infers value
to be a HashToken
. I've made that explicit.
I'm clearly missing something about how to correctly set the parameter parsing... |
This is an adaptation of #1733 to use the built-in Liquid argument parser that was added in #2679. Keyword arguments are passed as an object after all the positional arguments.