Skip to content

Add specs for bare-bracket rejection in strict2 and self keyword - #124

Merged
aswamy merged 1 commit into
mainfrom
bare-bracket-self-keyword
May 19, 2026
Merged

Add specs for bare-bracket rejection in strict2 and self keyword#124
aswamy merged 1 commit into
mainfrom
bare-bracket-self-keyword

Conversation

@aswamy

@aswamy aswamy commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds conformance specs for the bare-bracket syntax changes in Shopify/liquid (28 specs total).

Bare-bracket rejection in strict2 (7 specs):

  • {{ ['product'] }}, {{ [key] }} are rejected with parse_error
  • Rejection applies in variables, for, if, case, assign

strict2 accepts qualified access (2 specs):

  • product['title'] and dot notation remain valid

self keyword (18 specs):

  • self['product'] resolves variables through the normal scope chain
  • self[key] performs dynamic variable lookups (key from environment OR local assign)
  • Works in all parsing modes (lax, strict, strict2)
  • Local assigns are visible via self['product']
  • self can be reassigned ({% assign self = 'value' %})
  • Returns empty string for unknown keys (lax and strict2)
  • Supports nested property access (self['product'].title)
  • Composes with other expressions: a[ self[ 'b' ] ], self[self['key1']]
  • Works inside for loop bodies and capture blocks
  • self keyword still resolves to SelfDrop even when environment defines a self key
  • QUIRK documented: self contains 'key' always returns false because contains calls include? and SelfDrop doesn't implement it — use self['key'] for definedness checks

Backwards compatibility (1 spec):

  • Lax mode still allows bare-bracket access

Depends on:

  • Shopify/liquid: #2060
  • Shopify/liquid-rewriter-private: #211

🤖 Generated with Claude Code

@karreiro karreiro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR, @aswamy!

Could we make sure we cover the scenarios outlined in this file (reference)?

Thanks again for the PR!

@aswamy
aswamy force-pushed the bare-bracket-self-keyword branch from 5a98157 to c841a82 Compare May 4, 2026 14:05
@aswamy
aswamy marked this pull request as ready for review May 4, 2026 14:05
- strict2 rejects bare-bracket access (['product'], [key], etc.)
- Qualified bracket access (product['title']) remains valid
- `self` keyword resolves variables through the scope chain
- `self` works in all parsing modes (lax, strict, strict2)
- Local assigns shadow the `self` keyword

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aswamy
aswamy force-pushed the bare-bracket-self-keyword branch from c841a82 to af487d9 Compare May 19, 2026 16:00
@aswamy
aswamy requested a review from EvilGenius13 May 19, 2026 16:03
@aswamy
aswamy merged commit a168e56 into main May 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants