Repository navigation
Add JEP-18 lexical scoping with let expressions - #138
Merged
Merged
Conversation
GrahamCampbell
force-pushed
the
jep-18-lexical-scope
branch
from
November 17, 2026 13:00
cbcbaf0 to
b147b8d
Compare
Co-authored-by: Harry Vennik <h.vennik@topgeschenken.nl>
GrahamCampbell
force-pushed
the
jep-18-lexical-scope
branch
from
November 17, 2026 13:58
b147b8d to
a5966aa
Compare
GrahamCampbell
marked this pull request as ready for review
November 17, 2026 14:49
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.
JEP-18 adds lexical scoping to JMESPath, so that an expression can refer to values outside its current element by binding them to variables with
let $name = expression in expression. This implements it in both runtimes.letandinare contextual keywords and stay usable as identifiers, bindings are evaluated before the body and are not visible to each other, inner bindings shadow outer ones, and referencing an undefined variable is an error when it is evaluated rather than when the expression is parsed.The interpreter evaluates the body of a let expression on a copy of itself that holds the bindings, so evaluating expressions that do not use variables costs nothing extra and expression references keep the variables they were created with. The compiler resolves each variable to a PHP local when it generates code, and passes the visible ones to the interpreter for expression references.
This supersedes #80 and builds on its lexer and parser work. The compliance cases are the ones from the JEP plus further cases for pipes, expression references, a null current node and invalid syntax, all of which run against both runtimes.