Skip to content

Commit f3edebc

Browse files
committed
[compiler] Add support for diagnostic hints (#34126)
Hints are meant as additional information to present to the developer about an error. The first use-case here is for the suggestion to name refs with "-Ref" if we encounter a mutation that looks like it might be a ref. The original error printing used a second error detail which printed the source code twice, a hint with just extra text is less noisy. DiffTrain build for [6ffcac8](6ffcac8)
1 parent 9718c76 commit f3edebc

35 files changed

+98
-93
lines changed

compiled/eslint-plugin-react-hooks/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17650,8 +17650,10 @@ class CompilerDiagnostic {
1765017650
return this;
1765117651
}
1765217652
primaryLocation() {
17653-
var _a, _b;
17654-
return (_b = (_a = this.options.details.filter(d => d.kind === 'error')[0]) === null || _a === void 0 ? void 0 : _a.loc) !== null && _b !== void 0 ? _b : null;
17653+
const firstErrorDetail = this.options.details.filter(d => d.kind === 'error')[0];
17654+
return firstErrorDetail != null && firstErrorDetail.kind === 'error'
17655+
? firstErrorDetail.loc
17656+
: null;
1765517657
}
1765617658
printErrorMessage(source, options) {
1765717659
const buffer = [
@@ -17684,8 +17686,13 @@ class CompilerDiagnostic {
1768417686
buffer.push(codeFrame);
1768517687
break;
1768617688
}
17689+
case 'hint': {
17690+
buffer.push('\n\n');
17691+
buffer.push(detail.message);
17692+
break;
17693+
}
1768717694
default: {
17688-
assertExhaustive$1(detail.kind, `Unexpected detail kind ${detail.kind}`);
17695+
assertExhaustive$1(detail, `Unexpected detail kind ${detail.kind}`);
1768917696
}
1769017697
}
1769117698
}
@@ -42154,8 +42161,7 @@ function applySignature(context, state, signature, instruction) {
4215442161
if (effect.kind === 'Mutate' &&
4215542162
((_b = effect.reason) === null || _b === void 0 ? void 0 : _b.kind) === 'AssignCurrentProperty') {
4215642163
diagnostic.withDetail({
42157-
kind: 'error',
42158-
loc: effect.value.loc,
42164+
kind: 'hint',
4215942165
message: `Hint: If this value is a Ref (value returned by \`useRef()\`), rename the variable to end in "Ref".`,
4216042166
});
4216142167
}
@@ -42583,8 +42589,7 @@ function applyEffect(context, state, _effect, initialized, effects) {
4258342589
if (effect.kind === 'Mutate' &&
4258442590
((_e = effect.reason) === null || _e === void 0 ? void 0 : _e.kind) === 'AssignCurrentProperty') {
4258542591
diagnostic.withDetail({
42586-
kind: 'error',
42587-
loc: effect.value.loc,
42592+
kind: 'hint',
4258842593
message: `Hint: If this value is a Ref (value returned by \`useRef()\`), rename the variable to end in "Ref".`,
4258942594
});
4259042595
}

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
724b324b966343f08ff0cb16ec9d8013e3891dfd
1+
6ffcac8558efbd204c7df5d52787a90e507dd8d7
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
724b324b966343f08ff0cb16ec9d8013e3891dfd
1+
6ffcac8558efbd204c7df5d52787a90e507dd8d7

compiled/facebook-www/React-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ __DEV__ &&
14091409
exports.useTransition = function () {
14101410
return resolveDispatcher().useTransition();
14111411
};
1412-
exports.version = "19.2.0-www-classic-724b324b-20250815";
1412+
exports.version = "19.2.0-www-classic-6ffcac85-20250815";
14131413
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14141414
"function" ===
14151415
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ __DEV__ &&
14091409
exports.useTransition = function () {
14101410
return resolveDispatcher().useTransition();
14111411
};
1412-
exports.version = "19.2.0-www-modern-724b324b-20250815";
1412+
exports.version = "19.2.0-www-modern-6ffcac85-20250815";
14131413
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14141414
"function" ===
14151415
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,4 +600,4 @@ exports.useSyncExternalStore = function (
600600
exports.useTransition = function () {
601601
return ReactSharedInternals.H.useTransition();
602602
};
603-
exports.version = "19.2.0-www-classic-724b324b-20250815";
603+
exports.version = "19.2.0-www-classic-6ffcac85-20250815";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,4 +600,4 @@ exports.useSyncExternalStore = function (
600600
exports.useTransition = function () {
601601
return ReactSharedInternals.H.useTransition();
602602
};
603-
exports.version = "19.2.0-www-modern-724b324b-20250815";
603+
exports.version = "19.2.0-www-modern-6ffcac85-20250815";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ exports.useSyncExternalStore = function (
604604
exports.useTransition = function () {
605605
return ReactSharedInternals.H.useTransition();
606606
};
607-
exports.version = "19.2.0-www-classic-724b324b-20250815";
607+
exports.version = "19.2.0-www-classic-6ffcac85-20250815";
608608
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
609609
"function" ===
610610
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ exports.useSyncExternalStore = function (
604604
exports.useTransition = function () {
605605
return ReactSharedInternals.H.useTransition();
606606
};
607-
exports.version = "19.2.0-www-modern-724b324b-20250815";
607+
exports.version = "19.2.0-www-modern-6ffcac85-20250815";
608608
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
609609
"function" ===
610610
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19588,10 +19588,10 @@ __DEV__ &&
1958819588
(function () {
1958919589
var internals = {
1959019590
bundleType: 1,
19591-
version: "19.2.0-www-classic-724b324b-20250815",
19591+
version: "19.2.0-www-classic-6ffcac85-20250815",
1959219592
rendererPackageName: "react-art",
1959319593
currentDispatcherRef: ReactSharedInternals,
19594-
reconcilerVersion: "19.2.0-www-classic-724b324b-20250815"
19594+
reconcilerVersion: "19.2.0-www-classic-6ffcac85-20250815"
1959519595
};
1959619596
internals.overrideHookState = overrideHookState;
1959719597
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -19625,7 +19625,7 @@ __DEV__ &&
1962519625
exports.Shape = Shape;
1962619626
exports.Surface = Surface;
1962719627
exports.Text = Text;
19628-
exports.version = "19.2.0-www-classic-724b324b-20250815";
19628+
exports.version = "19.2.0-www-classic-6ffcac85-20250815";
1962919629
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1963019630
"function" ===
1963119631
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)