Skip to content

Commit 11a4e79

Browse files
committed
Refactor: wrap states in an object
1 parent 99e8a2a commit 11a4e79

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

src/analysis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export function analyzeClass(
118118

119119
const render = analyzeRender(renderPath, locals);
120120

121-
for (const [name, stateAnalysis] of states.entries()) {
121+
for (const [name, stateAnalysis] of states.states.entries()) {
122122
const bindingPaths = stateAnalysis.sites.map((site) => site.path);
123123
stateAnalysis.localName = locals.newLocal(name, bindingPaths);
124124
stateAnalysis.localSetterName = locals.newLocal(`set${name.replace(/^[a-z]/, (s) => s.toUpperCase())}`, bindingPaths);

src/analysis/state.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import type { LocalManager } from "./local.js";
77
import type { ClassFieldAnalysis } from "./class_fields.js";
88
import { trackMember } from "./track_member.js";
99

10-
export type StateObjAnalysis = Map<string, StateAnalysis>;
10+
export type StateObjAnalysis = {
11+
states: Map<string, StateAnalysis>;
12+
};
1113

1214
export type StateAnalysis = {
1315
localName?: string | undefined;
@@ -183,5 +185,5 @@ export function analyzeState(
183185
}
184186
state.init = state.sites.find((site): site is StateInitSite => site.type === "state_init");
185187
}
186-
return states;
188+
return { states };
187189
}

src/analysis/user_defined.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ export function postAnalyzeCallbackDependencies(
347347
type: "dep_props_obj",
348348
});
349349
}
350-
for (const [name, state] of states) {
350+
for (const [name, state] of states.states) {
351351
for (const site of state.sites) {
352352
if (site.type !== "expr") {
353353
continue;

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function transformClass(analysis: AnalysisResult, options: { ts: boolean }, babe
142142
}
143143
}
144144
}
145-
for (const [name, stateAnalysis] of analysis.state) {
145+
for (const [name, stateAnalysis] of analysis.state.states) {
146146
for (const site of stateAnalysis.sites) {
147147
if (site.type === "expr") {
148148
// this.state.foo -> foo
@@ -212,7 +212,7 @@ function transformClass(analysis: AnalysisResult, options: { ts: boolean }, babe
212212
),
213213
]));
214214
}
215-
for (const field of analysis.state.values()) {
215+
for (const field of analysis.state.states.values()) {
216216
// State declarations
217217
const call = t.callExpression(
218218
getReactImport("useState", babel, analysis.superClassRef),
@@ -265,7 +265,7 @@ function transformClass(analysis: AnalysisResult, options: { ts: boolean }, babe
265265
break;
266266
}
267267
case "dep_state": {
268-
const state = analysis.state.get(dep.name)!;
268+
const state = analysis.state.states.get(dep.name)!;
269269
depVars.add(state.localName!);
270270
break;
271271
}

0 commit comments

Comments
 (0)