New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix parser to continue parsing key-value pairs after an If-Statement value in a HashExpression #7002
Merged
Merged
Fix parser to continue parsing key-value pairs after an If-Statement value in a HashExpression #7002
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,3 +212,22 @@ Describe "Members of System.Type" -Tags "CI" { | |
[MyType].ImplementedInterfaces | Should -Be System.Collections.IEnumerable | ||
} | ||
} | ||
|
||
Describe "Hash expression with if statement as value" -Tags "CI" { | ||
It "Key-value pairs after an if-statement-value in a HashExpression should continue to be parsed" { | ||
$result = @{ | ||
a = if (1) {'a'} | ||
b = 'b' | ||
c = if (0) {2} elseif (1) {'c'} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also test:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Thanks! |
||
d = 'd' | ||
e = if (0) {2} else {'e'} | ||
f = 'f' | ||
} | ||
$result['a'] | Should -BeExactly 'a' | ||
$result['b'] | Should -BeExactly 'b' | ||
$result['c'] | Should -BeExactly 'c' | ||
$result['d'] | Should -BeExactly 'd' | ||
$result['e'] | Should -BeExactly 'e' | ||
$result['f'] | Should -BeExactly 'f' | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use
PeekToken()
instead of_tokenizer.GetRestorePoint()
here because it's possible there is an unget token (_ungetToken != null
) at this point, and in that case,_tokenizer.GetRestorePoint()
will return the offset after the unget token, and we will lose the unget token when resyncing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decide to directly check
_ungotToken == null
. I think this way will deliver the intent more clearly. And also, in more common cases,_ungotToken
would be null when reaching here.