eslint-plugin-react-hooks 7.0.0-canary-f6a48828-20251019 → 7.0.0-canary-71b3a03c-20251021

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24145,7 +24145,7 @@ function lowerObjectMethod(builder, property) {
24145
24145
  };
24146
24146
  }
24147
24147
  function lowerObjectPropertyKey(builder, property) {
24148
- var _a, _b;
24148
+ var _a;
24149
24149
  const key = property.get('key');
24150
24150
  if (key.isStringLiteral()) {
24151
24151
  return {
@@ -24154,15 +24154,6 @@ function lowerObjectPropertyKey(builder, property) {
24154
24154
  };
24155
24155
  }
24156
24156
  else if (property.node.computed && key.isExpression()) {
24157
- if (!key.isIdentifier() && !key.isMemberExpression()) {
24158
- builder.errors.push({
24159
- reason: `(BuildHIR::lowerExpression) Expected Identifier, got ${key.type} key in ObjectExpression`,
24160
- category: ErrorCategory.Todo,
24161
- loc: (_a = key.node.loc) !== null && _a !== void 0 ? _a : null,
24162
- suggestions: null,
24163
- });
24164
- return null;
24165
- }
24166
24157
  const place = lowerExpressionToTemporary(builder, key);
24167
24158
  return {
24168
24159
  kind: 'computed',
@@ -24184,7 +24175,7 @@ function lowerObjectPropertyKey(builder, property) {
24184
24175
  builder.errors.push({
24185
24176
  reason: `(BuildHIR::lowerExpression) Expected Identifier, got ${key.type} key in ObjectExpression`,
24186
24177
  category: ErrorCategory.Todo,
24187
- loc: (_b = key.node.loc) !== null && _b !== void 0 ? _b : null,
24178
+ loc: (_a = key.node.loc) !== null && _a !== void 0 ? _a : null,
24188
24179
  suggestions: null,
24189
24180
  });
24190
24181
  return null;
@@ -50387,21 +50378,24 @@ function validateUseMemo(fn) {
50387
50378
  return errors.asResult();
50388
50379
  }
50389
50380
  function validateNoContextVariableAssignment(fn, errors) {
50381
+ const context = new Set(fn.context.map(place => place.identifier.id));
50390
50382
  for (const block of fn.body.blocks.values()) {
50391
50383
  for (const instr of block.instructions) {
50392
50384
  const value = instr.value;
50393
50385
  switch (value.kind) {
50394
50386
  case 'StoreContext': {
50395
- errors.pushDiagnostic(CompilerDiagnostic.create({
50396
- category: ErrorCategory.UseMemo,
50397
- reason: 'useMemo() callbacks may not reassign variables declared outside of the callback',
50398
- description: 'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
50399
- suggestions: null,
50400
- }).withDetails({
50401
- kind: 'error',
50402
- loc: value.lvalue.place.loc,
50403
- message: 'Cannot reassign variable',
50404
- }));
50387
+ if (context.has(value.lvalue.place.identifier.id)) {
50388
+ errors.pushDiagnostic(CompilerDiagnostic.create({
50389
+ category: ErrorCategory.UseMemo,
50390
+ reason: 'useMemo() callbacks may not reassign variables declared outside of the callback',
50391
+ description: 'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
50392
+ suggestions: null,
50393
+ }).withDetails({
50394
+ kind: 'error',
50395
+ loc: value.lvalue.place.loc,
50396
+ message: 'Cannot reassign variable',
50397
+ }));
50398
+ }
50405
50399
  break;
50406
50400
  }
50407
50401
  }
@@ -24136,7 +24136,7 @@ function lowerObjectMethod(builder, property) {
24136
24136
  };
24137
24137
  }
24138
24138
  function lowerObjectPropertyKey(builder, property) {
24139
- var _a, _b;
24139
+ var _a;
24140
24140
  const key = property.get('key');
24141
24141
  if (key.isStringLiteral()) {
24142
24142
  return {
@@ -24145,15 +24145,6 @@ function lowerObjectPropertyKey(builder, property) {
24145
24145
  };
24146
24146
  }
24147
24147
  else if (property.node.computed && key.isExpression()) {
24148
- if (!key.isIdentifier() && !key.isMemberExpression()) {
24149
- builder.errors.push({
24150
- reason: `(BuildHIR::lowerExpression) Expected Identifier, got ${key.type} key in ObjectExpression`,
24151
- category: ErrorCategory.Todo,
24152
- loc: (_a = key.node.loc) !== null && _a !== void 0 ? _a : null,
24153
- suggestions: null,
24154
- });
24155
- return null;
24156
- }
24157
24148
  const place = lowerExpressionToTemporary(builder, key);
24158
24149
  return {
24159
24150
  kind: 'computed',
@@ -24175,7 +24166,7 @@ function lowerObjectPropertyKey(builder, property) {
24175
24166
  builder.errors.push({
24176
24167
  reason: `(BuildHIR::lowerExpression) Expected Identifier, got ${key.type} key in ObjectExpression`,
24177
24168
  category: ErrorCategory.Todo,
24178
- loc: (_b = key.node.loc) !== null && _b !== void 0 ? _b : null,
24169
+ loc: (_a = key.node.loc) !== null && _a !== void 0 ? _a : null,
24179
24170
  suggestions: null,
24180
24171
  });
24181
24172
  return null;
@@ -50214,21 +50205,24 @@ function validateUseMemo(fn) {
50214
50205
  return errors.asResult();
50215
50206
  }
50216
50207
  function validateNoContextVariableAssignment(fn, errors) {
50208
+ const context = new Set(fn.context.map(place => place.identifier.id));
50217
50209
  for (const block of fn.body.blocks.values()) {
50218
50210
  for (const instr of block.instructions) {
50219
50211
  const value = instr.value;
50220
50212
  switch (value.kind) {
50221
50213
  case 'StoreContext': {
50222
- errors.pushDiagnostic(CompilerDiagnostic.create({
50223
- category: ErrorCategory.UseMemo,
50224
- reason: 'useMemo() callbacks may not reassign variables declared outside of the callback',
50225
- description: 'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
50226
- suggestions: null,
50227
- }).withDetails({
50228
- kind: 'error',
50229
- loc: value.lvalue.place.loc,
50230
- message: 'Cannot reassign variable',
50231
- }));
50214
+ if (context.has(value.lvalue.place.identifier.id)) {
50215
+ errors.pushDiagnostic(CompilerDiagnostic.create({
50216
+ category: ErrorCategory.UseMemo,
50217
+ reason: 'useMemo() callbacks may not reassign variables declared outside of the callback',
50218
+ description: 'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
50219
+ suggestions: null,
50220
+ }).withDetails({
50221
+ kind: 'error',
50222
+ loc: value.lvalue.place.loc,
50223
+ message: 'Cannot reassign variable',
50224
+ }));
50225
+ }
50232
50226
  break;
50233
50227
  }
50234
50228
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks",
3
3
  "description": "ESLint rules for React Hooks",
4
- "version": "7.0.0-canary-f6a48828-20251019",
4
+ "version": "7.0.0-canary-71b3a03c-20251021",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/facebook/react.git",