Skip to content

Commit dfb4e13

Browse files
committed
remove some unused stuff
1 parent de77e69 commit dfb4e13

File tree

7 files changed

+17
-26
lines changed

7 files changed

+17
-26
lines changed

packages/svelte/src/compiler/phases/3-transform/client/transform-client.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ export function client_component(analysis, options) {
163163
},
164164
events: new Set(),
165165
preserve_whitespace: options.preserveWhitespace,
166-
public_state: new Map(),
167-
private_state: new Map(),
166+
state_fields: {},
167+
backing_fields: {},
168168
transform: {},
169169
in_constructor: false,
170170
instance_level_snippets: [],
@@ -671,8 +671,8 @@ export function client_module(analysis, options) {
671671
options,
672672
scope: analysis.module.scope,
673673
scopes: analysis.module.scopes,
674-
public_state: new Map(),
675-
private_state: new Map(),
674+
state_fields: {},
675+
backing_fields: {},
676676
transform: {},
677677
in_constructor: false
678678
};

packages/svelte/src/compiler/phases/3-transform/client/types.d.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import type {
99
UpdateExpression,
1010
VariableDeclaration
1111
} from 'estree';
12-
import type { AST, Namespace, ValidatedCompileOptions } from '#compiler';
12+
import type { AST, Namespace, StateField, ValidatedCompileOptions } from '#compiler';
1313
import type { TransformState } from '../types.js';
1414
import type { ComponentAnalysis } from '../../types.js';
1515
import type { SourceLocation } from '#shared';
1616

1717
export interface ClientTransformState extends TransformState {
18-
readonly private_state: Map<string, StateField>;
19-
readonly public_state: Map<string, StateField>;
18+
readonly state_fields: Record<string, StateField>;
19+
readonly backing_fields: Record<string, PrivateIdentifier>;
2020

2121
/**
2222
* `true` if the current lexical scope belongs to a class constructor. this allows
@@ -94,10 +94,6 @@ export interface ComponentClientTransformState extends ClientTransformState {
9494
readonly module_level_snippets: VariableDeclaration[];
9595
}
9696

97-
export interface StateField {
98-
type: '$state' | '$state.raw' | '$derived' | '$derived.by';
99-
}
100-
10197
export type Context = import('zimmerframe').Context<AST.SvelteNode, ClientTransformState>;
10298
export type Visitors = import('zimmerframe').Visitors<AST.SvelteNode, any>;
10399

packages/svelte/src/compiler/phases/3-transform/client/visitors/AssignmentExpression.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ const callees = {
5353
*/
5454
function build_assignment(operator, left, right, context) {
5555
if (context.state.analysis.runes && left.type === 'MemberExpression') {
56+
const name = get_name(left.property);
57+
5658
// special case — state declaration in class constructor
5759
const ancestor = context.path.at(-4);
5860

5961
if (ancestor?.type === 'MethodDefinition' && ancestor.kind === 'constructor') {
6062
const rune = get_rune(right, context.state.scope);
6163

6264
if (rune) {
63-
const name = get_name(left.property);
64-
6565
const child_state = {
6666
...context.state,
6767
in_constructor: rune !== '$derived' && rune !== '$derived.by'
@@ -82,15 +82,15 @@ function build_assignment(operator, left, right, context) {
8282

8383
// special case — assignment to private state field
8484
if (left.property.type === 'PrivateIdentifier') {
85-
const private_state = context.state.private_state.get(left.property.name);
85+
const field = context.state.state_fields[name];
8686

87-
if (private_state !== undefined) {
87+
if (field) {
8888
let value = /** @type {Expression} */ (
8989
context.visit(build_assignment_value(operator, left, right))
9090
);
9191

9292
const needs_proxy =
93-
private_state.type === '$state' &&
93+
field.type === '$state' &&
9494
is_non_coercive_operator(operator) &&
9595
should_proxy(value, context.state.scope);
9696

packages/svelte/src/compiler/phases/3-transform/client/visitors/ClassBody.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ export function ClassBody(node, context) {
2929
}
3030
}
3131

32-
const private_state = new Map();
33-
3432
/**
3533
* each `foo = $state()` needs a backing `#foo` field
3634
* @type {Record<string, PrivateIdentifier>}
@@ -39,7 +37,6 @@ export function ClassBody(node, context) {
3937

4038
for (const name in state_fields) {
4139
if (name[0] === '#') {
42-
private_state.set(name.slice(1), state_fields[name]);
4340
continue;
4441
}
4542

@@ -55,7 +52,7 @@ export function ClassBody(node, context) {
5552
/** @type {Array<MethodDefinition | PropertyDefinition | StaticBlock>} */
5653
const body = [];
5754

58-
const child_state = { ...context.state, state_fields, backing_fields, private_state }; // TODO populate private_state
55+
const child_state = { ...context.state, state_fields, backing_fields };
5956

6057
for (const name in state_fields) {
6158
if (name[0] === '#') {

packages/svelte/src/compiler/phases/3-transform/client/visitors/MemberExpression.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import * as b from '#compiler/builders';
99
export function MemberExpression(node, context) {
1010
// rewrite `this.#foo` as `this.#foo.v` inside a constructor
1111
if (node.property.type === 'PrivateIdentifier') {
12-
const field = context.state.private_state.get(node.property.name);
12+
const field = context.state.state_fields['#' + node.property.name];
13+
1314
if (field) {
1415
return context.state.in_constructor &&
1516
(field.type === '$state.raw' || field.type === '$state')

packages/svelte/src/compiler/phases/3-transform/client/visitors/UpdateExpression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function UpdateExpression(node, context) {
1515
argument.type === 'MemberExpression' &&
1616
argument.object.type === 'ThisExpression' &&
1717
argument.property.type === 'PrivateIdentifier' &&
18-
context.state.private_state.has(argument.property.name)
18+
Object.hasOwn(context.state.state_fields, '#' + argument.property.name)
1919
) {
2020
let fn = '$.update';
2121
if (node.prefix) fn += '_pre';

packages/svelte/src/compiler/phases/3-transform/server/visitors/ClassBody.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ export function ClassBody(node, context) {
3232
}
3333
}
3434

35-
const private_state = new Map();
36-
3735
/**
3836
* each `foo = $state()` needs a backing `#foo` field
3937
* @type {Record<string, PrivateIdentifier>}
@@ -42,7 +40,6 @@ export function ClassBody(node, context) {
4240

4341
for (const name in state_fields) {
4442
if (name[0] === '#') {
45-
private_state.set(name.slice(1), state_fields[name]);
4643
continue;
4744
}
4845

@@ -58,7 +55,7 @@ export function ClassBody(node, context) {
5855
/** @type {Array<MethodDefinition | PropertyDefinition | StaticBlock>} */
5956
const body = [];
6057

61-
const child_state = { ...context.state, state_fields, backing_fields, private_state }; // TODO populate private_state
58+
const child_state = { ...context.state, state_fields, backing_fields };
6259

6360
for (const name in state_fields) {
6461
if (name[0] === '#') {

0 commit comments

Comments
 (0)