fix(lib): ForExpression missing iteratorContext and OperatorExpression drops falsy right operands#112
Open
X-Guardian wants to merge 2 commits intoopen-constructs:mainfrom
Open
fix(lib): ForExpression missing iteratorContext and OperatorExpression drops falsy right operands#112X-Guardian wants to merge 2 commits intoopen-constructs:mainfrom
X-Guardian wants to merge 2 commits intoopen-constructs:mainfrom
Conversation
added 2 commits
April 21, 2026 12:42
…s falsy right operands
jsteinich
reviewed
Apr 23, 2026
| public resolve(context: IResolveContext): string { | ||
| const suppressBraces = context.suppressBraces; | ||
| context.suppressBraces = true; | ||
| context.iteratorContext = "FOR_EXPRESSION"; |
Collaborator
There was a problem hiding this comment.
I don't believe this is the correct solution. It does work for your example and test case, but I believe it will fail if the input expression actually references a map.
I wonder if DynamicListTerraformIterator should resolve the for each expression with a value set at creation time rather than relying on the current context. Or perhaps the ForExpression needs more information at creation time about the input expression.
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.
Related issue
Fixes #111
Description
Bug 1:
ForExpression.resolve()does not setiteratorContextDynamicListTerraformIterator._getForEachExpression()returns aLazythat checkscontext.iteratorContext— returning the raw list for"FOR_EXPRESSION"and the map conversion for the default case.TerraformDynamicExpression.resolve()correctly setscontext.iteratorContext = "FOR_EXPRESSION"before resolving, butForExpression.resolve()does not.Fix: Add
context.iteratorContext = "FOR_EXPRESSION"inForExpression.resolve():Bug 2:
OperatorExpression.resolve()uses truthiness check instead of undefined checkLine 325 uses
this.right ? ... : undefinedwhich treats all falsy values (0,false,"") as missing. The-operator branch (line 337) has the same bug.Fix:
case "-": { - if (right) { + if (right !== undefined) { // subtraction expr = `(${left} - ${right})`; } else {Checklist