68
import {getWriteErrorReason} from './InferFunctionEffects';
69
import prettyFormat from 'pretty-format';
70
import {createTemporaryPlace} from '../HIR/HIRBuilder';
71
-import {AliasingEffect, AliasingSignature, hashEffect} from './AliasingEffects';
71
+import {
72
+ AliasingEffect,
73
+ AliasingSignature,
74
+ hashEffect,
75
+ MutationReason,
76
+} from './AliasingEffects';
77
78
const DEBUG = false;
79
457
effect.value.identifier.name.kind === 'named'
458
? `\`${effect.value.identifier.name.value}\``
459
: 'value';
460
+ const diagnostic = CompilerDiagnostic.create({
461
+ severity: ErrorSeverity.InvalidReact,
462
+ category: 'This value cannot be modified',
463
+ description: `${reason}.`,
464
+ }).withDetail({
465
+ kind: 'error',
466
+ loc: effect.value.loc,
467
+ message: `${variable} cannot be modified`,
468
+ });
469
+ if (
470
+ effect.kind === 'Mutate' &&
471
+ effect.reason?.kind === 'AssignCurrentProperty'
472
+ ) {
473
+ diagnostic.withDetail({
474
+ kind: 'error',
475
+ loc: effect.value.loc,
476
+ message: `Hint: If this value is a Ref (value returned by \`useRef()\`), rename the variable to end in "Ref".`,
477
+ });
478
+ }
479
effects.push({
480
kind: 'MutateFrozen',
481
place: effect.value,
458
- error: CompilerDiagnostic.create({
459
- severity: ErrorSeverity.InvalidReact,
460
- category: 'This value cannot be modified',
461
- description: `${reason}.`,
462
- }).withDetail({
463
- kind: 'error',
464
- loc: effect.value.loc,
465
- message: `${variable} cannot be modified`,
466
- }),
482
+ error: diagnostic,
483
});
484
}
485
}
1082
effect.value.identifier.name.kind === 'named'
1083
? `\`${effect.value.identifier.name.value}\``
1084
: 'value';
1085
+ const diagnostic = CompilerDiagnostic.create({
1086
+ severity: ErrorSeverity.InvalidReact,
1087
+ category: 'This value cannot be modified',
1088
+ description: `${reason}.`,
1089
+ }).withDetail({
1090
+ kind: 'error',
1091
+ loc: effect.value.loc,
1092
+ message: `${variable} cannot be modified`,
1093
+ });
1094
+ if (
1095
+ effect.kind === 'Mutate' &&
1096
+ effect.reason?.kind === 'AssignCurrentProperty'
1097
+ ) {
1098
+ diagnostic.withDetail({
1099
+ kind: 'error',
1100
+ loc: effect.value.loc,
1101
+ message: `Hint: If this value is a Ref (value returned by \`useRef()\`), rename the variable to end in "Ref".`,
1102
+ });
1103
+ }
1104
applyEffect(
1105
context,
1106
state,
1110
? 'MutateFrozen'
1111
: 'MutateGlobal',
1112
place: effect.value,
1078
- error: CompilerDiagnostic.create({
1079
- severity: ErrorSeverity.InvalidReact,
1080
- category: 'This value cannot be modified',
1081
- description: `${reason}.`,
1082
- }).withDetail({
1083
- kind: 'error',
1084
- loc: effect.value.loc,
1085
- message: `${variable} cannot be modified`,
1086
- }),
1113
+ error: diagnostic,
1114
},
1115
initialized,
1116
effects,
1707
}
1708
case 'PropertyStore':
1709
case 'ComputedStore': {
1683
- effects.push({kind: 'Mutate', value: value.object});
1710
+ const mutationReason: MutationReason | null =
1711
+ value.kind === 'PropertyStore' && value.property === 'current'
1712
+ ? {kind: 'AssignCurrentProperty'}
1713
+ : null;
1714
+ effects.push({
1715
+ kind: 'Mutate',
1716
+ value: value.object,
1717
+ reason: mutationReason,
1718
+ });
1719
effects.push({
1720
kind: 'Capture',
1721
from: value.value,