@@ -45843,19 +45843,42 @@ const EMPTY = new Empty();
4584345843function pruneHoistedContexts(fn) {
4584445844 visitReactiveFunction(fn, new Visitor$8(), {
4584545845 activeScopes: empty(),
45846+ uninitialized: new Map(),
4584645847 });
4584745848}
4584845849let Visitor$8 = class Visitor extends ReactiveFunctionTransform {
4584945850 visitScope(scope, state) {
4585045851 state.activeScopes = state.activeScopes.push(new Set(scope.scope.declarations.keys()));
45852+ for (const decl of scope.scope.declarations.values()) {
45853+ state.uninitialized.set(decl.identifier.id, { kind: 'unknown-kind' });
45854+ }
4585145855 this.traverseScope(scope, state);
4585245856 state.activeScopes.pop();
45857+ for (const decl of scope.scope.declarations.values()) {
45858+ state.uninitialized.delete(decl.identifier.id);
45859+ }
45860+ }
45861+ visitPlace(_id, place, state) {
45862+ const maybeHoistedFn = state.uninitialized.get(place.identifier.id);
45863+ if ((maybeHoistedFn === null || maybeHoistedFn === void 0 ? void 0 : maybeHoistedFn.kind) === 'func' &&
45864+ maybeHoistedFn.definition !== place) {
45865+ CompilerError.throwTodo({
45866+ reason: '[PruneHoistedContexts] Rewrite hoisted function references',
45867+ loc: place.loc,
45868+ });
45869+ }
4585345870 }
4585445871 transformInstruction(instruction, state) {
45855- this.visitInstruction(instruction, state);
4585645872 if (instruction.value.kind === 'DeclareContext') {
4585745873 const maybeNonHoisted = convertHoistedLValueKind(instruction.value.lvalue.kind);
4585845874 if (maybeNonHoisted != null) {
45875+ if (maybeNonHoisted === InstructionKind.Function &&
45876+ state.uninitialized.has(instruction.value.lvalue.place.identifier.id)) {
45877+ state.uninitialized.set(instruction.value.lvalue.place.identifier.id, {
45878+ kind: 'func',
45879+ definition: null,
45880+ });
45881+ }
4585945882 return { kind: 'remove' };
4586045883 }
4586145884 }
@@ -45864,9 +45887,31 @@ let Visitor$8 = class Visitor extends ReactiveFunctionTransform {
4586445887 const lvalueId = instruction.value.lvalue.place.identifier.id;
4586545888 const isDeclaredByScope = state.activeScopes.find(scope => scope.has(lvalueId));
4586645889 if (isDeclaredByScope) {
45867- instruction.value.lvalue.kind = InstructionKind.Reassign;
45890+ if (instruction.value.lvalue.kind === InstructionKind.Let ||
45891+ instruction.value.lvalue.kind === InstructionKind.Const) {
45892+ instruction.value.lvalue.kind = InstructionKind.Reassign;
45893+ }
45894+ else if (instruction.value.lvalue.kind === InstructionKind.Function) {
45895+ const maybeHoistedFn = state.uninitialized.get(lvalueId);
45896+ if (maybeHoistedFn != null) {
45897+ CompilerError.invariant(maybeHoistedFn.kind === 'func', {
45898+ reason: '[PruneHoistedContexts] Unexpected hoisted function',
45899+ loc: instruction.loc,
45900+ });
45901+ maybeHoistedFn.definition = instruction.value.lvalue.place;
45902+ state.uninitialized.delete(lvalueId);
45903+ }
45904+ }
45905+ else {
45906+ CompilerError.throwTodo({
45907+ reason: '[PruneHoistedContexts] Unexpected kind',
45908+ description: `(${instruction.value.lvalue.kind})`,
45909+ loc: instruction.loc,
45910+ });
45911+ }
4586845912 }
4586945913 }
45914+ this.visitInstruction(instruction, state);
4587045915 return { kind: 'keep' };
4587145916 }
4587245917};
@@ -60153,7 +60198,7 @@ const rule = {
6015360198 docs: {
6015460199 description: 'enforces the Rules of Hooks',
6015560200 recommended: true,
60156- url: 'https://reactjs.org/docs/hooks- rules.html ',
60201+ url: 'https://react.dev/reference/ rules/rules-of-hooks ',
6015760202 },
6015860203 },
6015960204 create(context) {
0 commit comments