feat: add getAssignVarNames API to complement getOutVarNames (#464) - #466
Open
chenjunwenhao wants to merge 1 commit into
Open
feat: add getAssignVarNames API to complement getOutVarNames (#464)#466chenjunwenhao wants to merge 1 commit into
chenjunwenhao wants to merge 1 commit into
Conversation
…#464) Add Express4Runner.getAssignVarNames() which returns the set of context variables that are assigned (created or updated) by a script, excluding locally-scoped variables such as typed declarations and for-each loop variables. This complements the existing getOutVarNames() method which returns external input variables. The implementation introduces AssignVarNamesVisitor, following the same AST-walking pattern as OutVarNamesVisitor and OutVarAttrsVisitor. Co-Authored-By: Qoder <noreply@qoder.com>
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
Add
Express4Runner.getAssignVarNames(String script)— a new introspection API that returns the set of context variables assigned (created or updated) by a script. This is the natural counterpart to the existinggetOutVarNames(): whilegetOutVarNamesidentifies external inputs,getAssignVarNamesidentifies outputs/side-effects.Behavior
getAssignVarNamesgetOutVarNamesa = b{a}{b}object a = b{}(typed decl = local){b}a = 1; b += 1{a, b}{}a = 1; b = a + 1{a, b}{}Key design decisions:
int a = 10,String name = "hello") are excluded — they create locally-scoped variables, not assignments to the execution context.for(i : list)) are excluded — also locally-scoped.a++,--b) are included — they modify the variable.obj.field = value) do not include the base variable — only the field is modified.Implementation
Introduces
AssignVarNamesVisitorextendingScopeStackVisitor, following the same AST-walking pattern as the existingOutVarNamesVisitorandOutVarAttrsVisitor. The visitor collects LHS variable names from assignment expressions and handles suffix/prefix++/--operators.Test plan
a = b→{a})object a = b→{})b += 1→{b})a = 1; a = a + 1→{a})getOutVarNameson same scriptobj.field = 10→{})${0} = ${1})b = a++ + 1→{a, b})a + b,hello()→{})Closes #464