[rust-compiler] Preserve explicit predicate: null in function-like nodes#36517
Open
poteto wants to merge 1 commit into
Open
[rust-compiler] Preserve explicit predicate: null in function-like nodes#36517poteto wants to merge 1 commit into
predicate: null in function-like nodes#36517poteto wants to merge 1 commit into
Conversation
…nodes
The Babel parser emits `"predicate": null` on every function-like
node (FunctionDeclaration, ArrowFunctionExpression, ObjectMethod,
...) to signal "no Flow `%checks` predicate". Babel JSON contains
the field explicitly even when no predicate is set, and the test
suite at scripts/test-babel-ast.sh diffs original-vs-round-tripped
JSON byte-equivalently.
`FunctionDeclaration` and `ArrowFunctionExpression` already had a
`predicate: Option<Box<Value>>` field, but plain `Option`
deserialization collapses both "absent" and "explicit null" into
`None`, and then `skip_serializing_if = "Option::is_none"` drops
the field on the way back out. `ObjectMethod` was missing the
field entirely.
Apply the existing `crate::common::nullable_value` deserializer
(already used for the same pattern elsewhere) to the two existing
fields, and add the same field shape to `ObjectMethod`. The helper
distinguishes:
- absent -> None (skip on serialize)
- null -> Some(Value::Null) (round-trips as `"predicate": null`)
- object -> Some(Value::Object(_)) (round-trips a populated predicate)
`FunctionExpression` is not touched here because no failing
fixture uses a function expression with `predicate: null`; can be
extended later if/when one shows up. `DeclareFunction.predicate`
in declarations.rs has the same shape but is also not exercised
by current fixtures.
Fixes 4 round-trip parity failures:
- error.todo-hoist-type-alias-before-declaration.js
- error.todo-round2_severity_diff.js
- component-in-object-method-body.flow.js
- (one additional fixture that was truncated in CI output)
Test plan:
- bash compiler/scripts/test-babel-ast.sh:
Before: 1774/1780 round-trip (6 failures)
After: 1778/1780 round-trip (2 failures, 4 fixed)
Remaining 2 failures are unrelated: TypeCastExpression missing
from PatternLike (next commit) and a lone-surrogate JSON parse
failure (skip-list commit after that).
- cargo test --workspace: not re-run; this change is data-only.
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.
The Babel parser emits
"predicate": nullon every function-likenode (FunctionDeclaration, ArrowFunctionExpression, ObjectMethod,
...) to signal "no Flow
%checkspredicate". Babel JSON containsthe field explicitly even when no predicate is set, and the test
suite at scripts/test-babel-ast.sh diffs original-vs-round-tripped
JSON byte-equivalently.
FunctionDeclarationandArrowFunctionExpressionalready had apredicate: Option<Box<Value>>field, but plainOptiondeserialization collapses both "absent" and "explicit null" into
None, and thenskip_serializing_if = "Option::is_none"dropsthe field on the way back out.
ObjectMethodwas missing thefield entirely.
Apply the existing
crate::common::nullable_valuedeserializer(already used for the same pattern elsewhere) to the two existing
fields, and add the same field shape to
ObjectMethod. The helperdistinguishes:
"predicate": null)FunctionExpressionis not touched here because no failingfixture uses a function expression with
predicate: null; can beextended later if/when one shows up.
DeclareFunction.predicatein declarations.rs has the same shape but is also not exercised
by current fixtures.
Fixes 4 round-trip parity failures:
Test plan:
Before: 1774/1780 round-trip (6 failures)
After: 1778/1780 round-trip (2 failures, 4 fixed)
Remaining 2 failures are unrelated: TypeCastExpression missing
from PatternLike (next commit) and a lone-surrogate JSON parse
failure (skip-list commit after that).