Repository navigation
Remove 3 sketchy-null suppressions (constant-folding-plugin, getRamBundleInfo, symbolicate) - #2090
Merged
Merged
Conversation
…ndleInfo, symbolicate)
Summary:
Replaces three sketchy-null suppressions in Metro with explicit checks that keep the exact runtime behavior.
- `metro-transform-plugins/src/constant-folding-plugin.js`: removes `$FlowFixMe[sketchy-null-mixed]` on `path.replaceWith(result.value ? node.consequent : node.alternate)`. `result.value` is `unknown`, so the test becomes `Boolean(result.value)`. That is the same truthiness test the ternary did implicitly, for every value. It is read into `const valueIsTruthy` first because Metro's ESLint `no-extra-boolean-cast` flags `Boolean()` directly in a ternary test. The existing `$FlowFixMe[incompatible-type]` on the call is unchanged.
- `metro/src/DeltaBundler/Serializers/getRamBundleInfo.js`: removes `$FlowFixMe[sketchy-null-bool]` on `preloadedModules || {}`. `preloadedModules` is typed `?Readonly<{[path: string]: true}> | false`. An object is always truthy, so `||` falls back exactly for `null`, `undefined` and `false`; the new check is `preloadedModules != null && preloadedModules !== false ? preloadedModules : {}`.
- `metro-symbolicate/src/symbolicate.js` (`readAll`): removes `// flowlint-next-line sketchy-null-string:off` on `while ((chunk = stream.read()))`. `read()` returns `?(string | Buffer)`; a `Buffer` is always truthy, so the loop stopped exactly on `null`, `undefined` or `''`. The loop now reads before the check and again at the end of the body, with `while (chunk != null && chunk !== '')`. `read()` is still called once per iteration and the loop stops on the same values. The read is split out because Flow does not refine a value assigned inside a loop condition.
No `||` was rewritten to `??`. No new suppressions, casts, `any`, comments, or tests. `metro-symbolicate` has no checked-in `symbolicate.js.flow`; the `.js.flow` copies only exist under `node_modules` and are generated by the build.
Changelog: [Internal]
Differential Revision: D127164728
Contributor
|
@jcperez-ch has exported this pull request. If you are a Meta employee, you can view the originating Diff in D127164728. |
robhogan
approved these changes
Oct 23, 2026
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:
Replaces three sketchy-null suppressions in Metro with explicit checks that keep the exact runtime behavior.
metro-transform-plugins/src/constant-folding-plugin.js: removes$FlowFixMe[sketchy-null-mixed]onpath.replaceWith(result.value ? node.consequent : node.alternate).result.valueisunknown, so the test becomesBoolean(result.value). That is the same truthiness test the ternary did implicitly, for every value. It is read intoconst valueIsTruthyfirst because Metro's ESLintno-extra-boolean-castflagsBoolean()directly in a ternary test. The existing$FlowFixMe[incompatible-type]on the call is unchanged.metro/src/DeltaBundler/Serializers/getRamBundleInfo.js: removes$FlowFixMe[sketchy-null-bool]onpreloadedModules || {}.preloadedModulesis typed?Readonly<{[path: string]: true}> | false. An object is always truthy, so||falls back exactly fornull,undefinedandfalse; the new check ispreloadedModules != null && preloadedModules !== false ? preloadedModules : {}.metro-symbolicate/src/symbolicate.js(readAll): removes// flowlint-next-line sketchy-null-string:offonwhile ((chunk = stream.read())).read()returns?(string | Buffer); aBufferis always truthy, so the loop stopped exactly onnull,undefinedor''. The loop now reads before the check and again at the end of the body, withwhile (chunk != null && chunk !== '').read()is still called once per iteration and the loop stops on the same values. The read is split out because Flow does not refine a value assigned inside a loop condition.No
||was rewritten to??. No new suppressions, casts,any, comments, or tests.metro-symbolicatehas no checked-insymbolicate.js.flow; the.js.flowcopies only exist undernode_modulesand are generated by the build.Changelog: [Internal]
Differential Revision: D127164728