Skip to content

Commit 45bdd93

Browse files
committed
[compiler] source location validator (facebook#35109)
@josephsavona this was briefly discussed in an old thread, lmk your thoughts on the approach. I have some fixes ready as well but wanted to get this test case in first... there's some things I don't _love_ about this approach, but end of the day it's just a tool for the test suite rather than something for end user folks so even if it does a 70% good enough job that's fine. ### refresher on the problem when we generate coverage reports with jest (istanbul), our coverage ends up completely out of whack due to the AST missing a ton of (let's call them "important") source locations after the compiler pipeline has run. At the moment to get around this, we've been doing something a bit unorthodox and also running our test suite with istanbul running before the compiler -- which results in its own set of issues (for eg, things being memoized differently, or the compiler completely bailing out on the instrumented code, etc). before getting in fixes, I wanted to set up a test case to start chipping away on as you had recommended. ### how it works The validator basically: 1. Traverses the original AST and collects the source locations for some "important" node types - (excludes useMemo/useCallback calls, as those are stripped out by the compiler) 3. Traverses the generated AST and looks for nodes with matching source locations. 4. Generates errors for source locations missing nodes in the generated AST ### caveats/drawbacks There are some things that don't work super well with this approach. A more natural test fit I think would be just having some explicit assertions made against an AST in a test file, as you can just bake all of the assumptions/nuance in there that are difficult to handle in a generic manner. However, this is maybe "good enough" for now. 1. Have to be careful what you put into the test fixture. If you put in some code that the compiler just removes (for eg, a variable assignment that is unused), you're creating a failure case that's impossible to fix. I added a skip for useMemo/useCallback. 2. "Important" locations must exactly match for validation to pass. - Might get tricky making sure things are mapped correctly when a node type is completely changed, for eg, when a block statement arrow function body gets turned into an implicit return via the body just being an expression/identifier. - This can/could result in scenarios where more changes are needed to shuttle the locations through due to HIR not having a 1:1 mapping all the babel nuances, even if some combination of other data might be good enough even if not 10000% accurate. This might be the _right_ thing anyways so we don't end up with edge cases having incorrect source locations. DiffTrain build for [3a495ae](facebook@3a495ae)
1 parent 4417e23 commit 45bdd93

23 files changed

+302
-74
lines changed

compiled-rn/VERSION_NATIVE_FB

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19.3.0-native-fb-bbe3f4d3-20251112
1+
19.3.0-native-fb-3a495ae7-20251112

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-dev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<aa23f659f37c73b1c34cc3464d2eddd6>>
10+
* @generated SignedSource<<b1786409863e7fc8539d330abab84e87>>
1111
*/
1212

1313
"use strict";
@@ -404,5 +404,5 @@ __DEV__ &&
404404
exports.useFormStatus = function () {
405405
return resolveDispatcher().useHostTransitionStatus();
406406
};
407-
exports.version = "19.3.0-native-fb-bbe3f4d3-20251112";
407+
exports.version = "19.3.0-native-fb-3a495ae7-20251112";
408408
})();

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<b9eb4766d44eb1670c305bf7dcac506e>>
10+
* @generated SignedSource<<52e0eedd8f7e4a43a1d9a0f7a71006af>>
1111
*/
1212

1313
"use strict";
@@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) {
203203
exports.useFormStatus = function () {
204204
return ReactSharedInternals.H.useHostTransitionStatus();
205205
};
206-
exports.version = "19.3.0-native-fb-bbe3f4d3-20251112";
206+
exports.version = "19.3.0-native-fb-3a495ae7-20251112";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-profiling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<b9eb4766d44eb1670c305bf7dcac506e>>
10+
* @generated SignedSource<<52e0eedd8f7e4a43a1d9a0f7a71006af>>
1111
*/
1212

1313
"use strict";
@@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) {
203203
exports.useFormStatus = function () {
204204
return ReactSharedInternals.H.useHostTransitionStatus();
205205
};
206-
exports.version = "19.3.0-native-fb-bbe3f4d3-20251112";
206+
exports.version = "19.3.0-native-fb-3a495ae7-20251112";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-dev.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<d7841432f5ff7c956ccf024141c3844a>>
10+
* @generated SignedSource<<5ff4a3e5d7af2cebc02272b3e8b9a60e>>
1111
*/
1212

1313
/*
@@ -30242,11 +30242,11 @@ __DEV__ &&
3024230242
};
3024330243
(function () {
3024430244
var isomorphicReactPackageVersion = React.version;
30245-
if ("19.3.0-native-fb-bbe3f4d3-20251112" !== isomorphicReactPackageVersion)
30245+
if ("19.3.0-native-fb-3a495ae7-20251112" !== isomorphicReactPackageVersion)
3024630246
throw Error(
3024730247
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
3024830248
(isomorphicReactPackageVersion +
30249-
"\n - react-dom: 19.3.0-native-fb-bbe3f4d3-20251112\nLearn more: https://react.dev/warnings/version-mismatch")
30249+
"\n - react-dom: 19.3.0-native-fb-3a495ae7-20251112\nLearn more: https://react.dev/warnings/version-mismatch")
3025030250
);
3025130251
})();
3025230252
("function" === typeof Map &&
@@ -30283,10 +30283,10 @@ __DEV__ &&
3028330283
!(function () {
3028430284
var internals = {
3028530285
bundleType: 1,
30286-
version: "19.3.0-native-fb-bbe3f4d3-20251112",
30286+
version: "19.3.0-native-fb-3a495ae7-20251112",
3028730287
rendererPackageName: "react-dom",
3028830288
currentDispatcherRef: ReactSharedInternals,
30289-
reconcilerVersion: "19.3.0-native-fb-bbe3f4d3-20251112"
30289+
reconcilerVersion: "19.3.0-native-fb-3a495ae7-20251112"
3029030290
};
3029130291
internals.overrideHookState = overrideHookState;
3029230292
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -30436,5 +30436,5 @@ __DEV__ &&
3043630436
listenToAllSupportedEvents(container);
3043730437
return new ReactDOMHydrationRoot(initialChildren);
3043830438
};
30439-
exports.version = "19.3.0-native-fb-bbe3f4d3-20251112";
30439+
exports.version = "19.3.0-native-fb-3a495ae7-20251112";
3044030440
})();

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-prod.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<143bc06d61da1835169773e09e4e84e0>>
10+
* @generated SignedSource<<196ad08e86238826c7669ff2a722b053>>
1111
*/
1212

1313
/*
@@ -17702,14 +17702,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1770217702
};
1770317703
var isomorphicReactPackageVersion$jscomp$inline_2054 = React.version;
1770417704
if (
17705-
"19.3.0-native-fb-bbe3f4d3-20251112" !==
17705+
"19.3.0-native-fb-3a495ae7-20251112" !==
1770617706
isomorphicReactPackageVersion$jscomp$inline_2054
1770717707
)
1770817708
throw Error(
1770917709
formatProdErrorMessage(
1771017710
527,
1771117711
isomorphicReactPackageVersion$jscomp$inline_2054,
17712-
"19.3.0-native-fb-bbe3f4d3-20251112"
17712+
"19.3.0-native-fb-3a495ae7-20251112"
1771317713
)
1771417714
);
1771517715
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -17731,10 +17731,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1773117731
};
1773217732
var internals$jscomp$inline_2636 = {
1773317733
bundleType: 0,
17734-
version: "19.3.0-native-fb-bbe3f4d3-20251112",
17734+
version: "19.3.0-native-fb-3a495ae7-20251112",
1773517735
rendererPackageName: "react-dom",
1773617736
currentDispatcherRef: ReactSharedInternals,
17737-
reconcilerVersion: "19.3.0-native-fb-bbe3f4d3-20251112"
17737+
reconcilerVersion: "19.3.0-native-fb-3a495ae7-20251112"
1773817738
};
1773917739
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1774017740
var hook$jscomp$inline_2637 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17841,4 +17841,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
1784117841
listenToAllSupportedEvents(container);
1784217842
return new ReactDOMHydrationRoot(initialChildren);
1784317843
};
17844-
exports.version = "19.3.0-native-fb-bbe3f4d3-20251112";
17844+
exports.version = "19.3.0-native-fb-3a495ae7-20251112";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-profiling.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<67dc76a36aaa0538d5411f92e3991c33>>
10+
* @generated SignedSource<<49ead18ef025070263b5cea2610003c8>>
1111
*/
1212

1313
/*
@@ -19828,14 +19828,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1982819828
};
1982919829
var isomorphicReactPackageVersion$jscomp$inline_2369 = React.version;
1983019830
if (
19831-
"19.3.0-native-fb-bbe3f4d3-20251112" !==
19831+
"19.3.0-native-fb-3a495ae7-20251112" !==
1983219832
isomorphicReactPackageVersion$jscomp$inline_2369
1983319833
)
1983419834
throw Error(
1983519835
formatProdErrorMessage(
1983619836
527,
1983719837
isomorphicReactPackageVersion$jscomp$inline_2369,
19838-
"19.3.0-native-fb-bbe3f4d3-20251112"
19838+
"19.3.0-native-fb-3a495ae7-20251112"
1983919839
)
1984019840
);
1984119841
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -19857,10 +19857,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1985719857
};
1985819858
var internals$jscomp$inline_2376 = {
1985919859
bundleType: 0,
19860-
version: "19.3.0-native-fb-bbe3f4d3-20251112",
19860+
version: "19.3.0-native-fb-3a495ae7-20251112",
1986119861
rendererPackageName: "react-dom",
1986219862
currentDispatcherRef: ReactSharedInternals,
19863-
reconcilerVersion: "19.3.0-native-fb-bbe3f4d3-20251112",
19863+
reconcilerVersion: "19.3.0-native-fb-3a495ae7-20251112",
1986419864
getLaneLabelMap: function () {
1986519865
for (
1986619866
var map = new Map(), lane = 1, index$336 = 0;
@@ -19983,4 +19983,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
1998319983
listenToAllSupportedEvents(container);
1998419984
return new ReactDOMHydrationRoot(initialChildren);
1998519985
};
19986-
exports.version = "19.3.0-native-fb-bbe3f4d3-20251112";
19986+
exports.version = "19.3.0-native-fb-3a495ae7-20251112";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-dev.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<8a50274047709632dea944e9a92fe66f>>
10+
* @generated SignedSource<<4baf05fbbb71d442ad008317e8f760f2>>
1111
*/
1212

1313
/*
@@ -30298,11 +30298,11 @@ __DEV__ &&
3029830298
};
3029930299
(function () {
3030030300
var isomorphicReactPackageVersion = React.version;
30301-
if ("19.3.0-native-fb-bbe3f4d3-20251112" !== isomorphicReactPackageVersion)
30301+
if ("19.3.0-native-fb-3a495ae7-20251112" !== isomorphicReactPackageVersion)
3030230302
throw Error(
3030330303
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
3030430304
(isomorphicReactPackageVersion +
30305-
"\n - react-dom: 19.3.0-native-fb-bbe3f4d3-20251112\nLearn more: https://react.dev/warnings/version-mismatch")
30305+
"\n - react-dom: 19.3.0-native-fb-3a495ae7-20251112\nLearn more: https://react.dev/warnings/version-mismatch")
3030630306
);
3030730307
})();
3030830308
("function" === typeof Map &&
@@ -30339,10 +30339,10 @@ __DEV__ &&
3033930339
!(function () {
3034030340
var internals = {
3034130341
bundleType: 1,
30342-
version: "19.3.0-native-fb-bbe3f4d3-20251112",
30342+
version: "19.3.0-native-fb-3a495ae7-20251112",
3034330343
rendererPackageName: "react-dom",
3034430344
currentDispatcherRef: ReactSharedInternals,
30345-
reconcilerVersion: "19.3.0-native-fb-bbe3f4d3-20251112"
30345+
reconcilerVersion: "19.3.0-native-fb-3a495ae7-20251112"
3034630346
};
3034730347
internals.overrideHookState = overrideHookState;
3034830348
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -30808,7 +30808,7 @@ __DEV__ &&
3080830808
exports.useFormStatus = function () {
3080930809
return resolveDispatcher().useHostTransitionStatus();
3081030810
};
30811-
exports.version = "19.3.0-native-fb-bbe3f4d3-20251112";
30811+
exports.version = "19.3.0-native-fb-3a495ae7-20251112";
3081230812
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
3081330813
"function" ===
3081430814
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-prod.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<9bf461dd720b720cad340330f8139786>>
10+
* @generated SignedSource<<6620aba321bdee49a85a58f8fb300cef>>
1111
*/
1212

1313
/*
@@ -17713,14 +17713,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1771317713
};
1771417714
var isomorphicReactPackageVersion$jscomp$inline_2055 = React.version;
1771517715
if (
17716-
"19.3.0-native-fb-bbe3f4d3-20251112" !==
17716+
"19.3.0-native-fb-3a495ae7-20251112" !==
1771717717
isomorphicReactPackageVersion$jscomp$inline_2055
1771817718
)
1771917719
throw Error(
1772017720
formatProdErrorMessage(
1772117721
527,
1772217722
isomorphicReactPackageVersion$jscomp$inline_2055,
17723-
"19.3.0-native-fb-bbe3f4d3-20251112"
17723+
"19.3.0-native-fb-3a495ae7-20251112"
1772417724
)
1772517725
);
1772617726
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -17742,10 +17742,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1774217742
};
1774317743
var internals$jscomp$inline_2639 = {
1774417744
bundleType: 0,
17745-
version: "19.3.0-native-fb-bbe3f4d3-20251112",
17745+
version: "19.3.0-native-fb-3a495ae7-20251112",
1774617746
rendererPackageName: "react-dom",
1774717747
currentDispatcherRef: ReactSharedInternals,
17748-
reconcilerVersion: "19.3.0-native-fb-bbe3f4d3-20251112"
17748+
reconcilerVersion: "19.3.0-native-fb-3a495ae7-20251112"
1774917749
};
1775017750
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1775117751
var hook$jscomp$inline_2640 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -18005,4 +18005,4 @@ exports.useFormState = function (action, initialState, permalink) {
1800518005
exports.useFormStatus = function () {
1800618006
return ReactSharedInternals.H.useHostTransitionStatus();
1800718007
};
18008-
exports.version = "19.3.0-native-fb-bbe3f4d3-20251112";
18008+
exports.version = "19.3.0-native-fb-3a495ae7-20251112";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-profiling.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<927b7aec7c9202b9f9143c74d7f3a37b>>
10+
* @generated SignedSource<<fa8ccfbb5a43845baa0e77e4fe3ac882>>
1111
*/
1212

1313
/*
@@ -19843,14 +19843,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1984319843
};
1984419844
var isomorphicReactPackageVersion$jscomp$inline_2370 = React.version;
1984519845
if (
19846-
"19.3.0-native-fb-bbe3f4d3-20251112" !==
19846+
"19.3.0-native-fb-3a495ae7-20251112" !==
1984719847
isomorphicReactPackageVersion$jscomp$inline_2370
1984819848
)
1984919849
throw Error(
1985019850
formatProdErrorMessage(
1985119851
527,
1985219852
isomorphicReactPackageVersion$jscomp$inline_2370,
19853-
"19.3.0-native-fb-bbe3f4d3-20251112"
19853+
"19.3.0-native-fb-3a495ae7-20251112"
1985419854
)
1985519855
);
1985619856
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -19872,10 +19872,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1987219872
};
1987319873
var internals$jscomp$inline_2377 = {
1987419874
bundleType: 0,
19875-
version: "19.3.0-native-fb-bbe3f4d3-20251112",
19875+
version: "19.3.0-native-fb-3a495ae7-20251112",
1987619876
rendererPackageName: "react-dom",
1987719877
currentDispatcherRef: ReactSharedInternals,
19878-
reconcilerVersion: "19.3.0-native-fb-bbe3f4d3-20251112",
19878+
reconcilerVersion: "19.3.0-native-fb-3a495ae7-20251112",
1987919879
getLaneLabelMap: function () {
1988019880
for (
1988119881
var map = new Map(), lane = 1, index$336 = 0;
@@ -20151,7 +20151,7 @@ exports.useFormState = function (action, initialState, permalink) {
2015120151
exports.useFormStatus = function () {
2015220152
return ReactSharedInternals.H.useHostTransitionStatus();
2015320153
};
20154-
exports.version = "19.3.0-native-fb-bbe3f4d3-20251112";
20154+
exports.version = "19.3.0-native-fb-3a495ae7-20251112";
2015520155
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
2015620156
"function" ===
2015720157
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)