Reject bare-bracket syntax in strict2 and introduce self keyword#2060
Open
Reject bare-bracket syntax in strict2 and introduce self keyword#2060
self keyword#2060Conversation
1 task
d77e5d3 to
f56eb10
Compare
Add bare-bracket rejection to Parser#expression in strict2 mode, so that
`['var']` is disallowed and `self['var']` is the required syntax.
- Add `Expression::SELF` constant ('self')
- Add `Parser#reject_bare_brackets` option, checked in `expression`
- Add `ParseContext#reject_bare_brackets?` and `force_reject_bare_brackets`
- Add `VariableLookupDrop` for `self['var']` scope-chain lookups
- Add `Variable#==` for rewriter state comparison
- Update `Context#find_variable` to return `VariableLookupDrop` for `self`
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
f56eb10 to
985943c
Compare
graygilmore
approved these changes
Mar 19, 2026
Contributor
graygilmore
left a comment
There was a problem hiding this comment.
The drop looks good to me but I'd prefer to have somebody with a little more Liquid context give another approval.
| end | ||
|
|
||
| def to_liquid | ||
| self |
Contributor
There was a problem hiding this comment.
Would love to see some additional tests for the new logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds bare-bracket rejection to the strict2 parser and introduces a
selfkeyword for explicit variable lookups.Parser changes:
Parser#expressionnow raises aSyntaxErrorwhen it encounters bare-bracket access (['product']) in strict2/rigid modeParseContext#new_parserpassesreject_bare_brackets: truewhenerror_modeis:strict2or:rigidselfkeyword:Expression::SELFconstant ('self')SelfDropclass — a drop that provides variable-only access to the context's scope chain (local > file > global), without exposing filters, interrupts, or other context internalsContext#find_variablereturns aSelfDropwhen the key isselfandselfhasn't been explicitly assigned as a local variableselfis explicitly assigned (e.g.{% assign self = 'value' %}), the local value takes precedenceContext#variable_defined?— new method that checks key existence across scopes/environments usingHash#key?, so nil-valued variables are correctly treated as defined (used bySelfDrop#key?)@liquid_public_docstags for public documentation generationVariable#==:nameandfilters, used by the rewriter to detect AST equivalence when deciding whether to flag nodes for rewriteTophat
Bare-bracket rejection in strict2:
selfresolves through the scope chain:Lax mode is unaffected:
🤖 Generated with Claude Code