-
Notifications
You must be signed in to change notification settings - Fork 38
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
[LiquidDoc] Parsing support for optional parameters and default values #753
Conversation
0a52108
to
49fdddd
Compare
@@ -0,0 +1,6 @@ | |||
--- | |||
'@shopify/liquid-html-parser': minor | |||
'theme-check-vscode': minor |
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.
not sure why this is being included - is anything going to break if I remove this? 🤔
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.
@@ -1011,30 +1011,352 @@ describe('Unit: Stage 1 (CST)', () => { | |||
expectPath(cst, '0.children.0.value').to.equal('@param'); | |||
}); | |||
|
|||
it('should parse @param with name', () => { | |||
const testStr = `{% doc %} @param paramWithNoDescription {% enddoc %}`; | |||
it('should parse required @param', () => { |
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.
In these tests, I typically test permutations, and include location
assertions for the first permutation only (aside from the whitespace case).
To avoid being overly verbose / repetitive, I'm just checking the value of the description
/ type
to ensure that nothing has completely broken in the matching logic.
paramDescription: ConcreteTextNode | null; | ||
paramType: ConcreteTextNode | null; | ||
} | ||
|
||
export interface ConcreteLiquidDocParamNameNode |
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 syntax for default value and required properties are related to how the ParamName
is defined, so I'm choosing to include that information in this ConcreteLiquidDocParamNameNode
This makes it a bit funky to access, but this aligns with how the parsing logic works, and allows us to leverage the Mappings
mechanism. We map this to a more sensible location in stage-2
(node.paramName.required
-> node.required
)
---- - Added a parameter `required` to the LiquidDocParamNode - By default, parameters are required unless they have `[]` around the name - Parameters with incomplete delimiters `e.g. ([missingTail)` will map to a `TextNode` - Default values are supported for optional parameters - `[param=default]` - Default values will match anything between `=` and `]`. Leading and Trailing spaces are trimmed. I originally tried accessing everything from the top level in the param node. This is still the goal, but I think this should be done at stage 2 so that we can leverage the recursive nature of how to-AST works. My original approach attempted to Write everything to the top level in stage 1, but we should be doing this in stage 2.
49fdddd
to
463c120
Compare
position: position(node.paramName), | ||
source: node.paramName.source, | ||
}, | ||
paramName: toTextNode(node.paramName.paramNameContent), |
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.
@param {String} [param_name=123]
This allows us to refer to the node.paramName
, which will be the node referring to param_name
with the associated location info
export interface ConcreteLiquidDocParamNameNode | ||
extends ConcreteBasicNode<ConcreteNodeTypes.LiquidDocParamNameNode> { | ||
required: boolean; | ||
defaultValue: ConcreteTextNode | null; |
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 not sure we should support default value as it would do nothing unless you also add the {% assign x | x | default %}
?
We've decided to go in a different direction at this time. |
What are you adding in this PR?
Closes 533
Closes 534
Adds
LiquidDoc
parsing support to allow users to define optional parameters and default values.Optional Parameters
[]
around the namee.g. ([missingTail)
will map to aTextNode
Default Values
[param=default]
=
and]
. Leading and Trailing spaces are trimmed.What's next? Any followup issues?
#734
Before you deploy
changeset