fix: boolean values serialize as empty objects in JSON output#79
Merged
Conversation
…alization - Add to TrueExpr and to FalseExpr so boolean values are preserved in JSON output - Fix Node.to_json() filter: change to to preserve falsy values like False and 0 - Fix Node.to_json() crash when _tokens is missing (use hasattr guard) - Update test_to_pretty_json to match the corrected to_json() output format Fixes #76
Owner
Author
|
Please add an integration test |
Verify that TrueExpr and FalseExpr JSON output includes the value field, and that round-trip parsing preserves boolean values.
Owner
Author
|
Done — added
Full suite: 148/148 pass ✅ |
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.
What Problem This Solves
Boolean values (
true/false) in parsed Lua ASTs were serializing as empty objects{}in JSON output, making them indistinguishable from each other and from other node types. Additionally,Node.to_json()crashed when_tokenswas not set, and the value filter incorrectly dropped falsy values likeFalseand0.Why This Change Was Made
Three changes in
astnodes.py:TrueExprnow setsself.value = True,FalseExprsetsself.value = False— so the boolean value is preserved as a node attributeNode.to_json()filter changed fromand vtoand v is not None and v != []— preservesFalse,0, and other falsy-but-meaningful valuesNode.to_json()now useshasattr(self, "_tokens")guard instead of crashingUser Impact
Before:
{comments: [], wrapped: false} // is this true or false? Impossible to tell.After:
{True: {value: true, start_char: 10, stop_char: 13, ...}} {False: {value: false, start_char: 26, stop_char: 30, ...}}Evidence
test_to_pretty_jsonto match the corrected (and richer) output formatFixes #76