remove some unused stuff

pull/15820/head
Rich Harris 4 months ago
parent de77e69628
commit dfb4e13cdd

@ -163,8 +163,8 @@ export function client_component(analysis, options) {
},
events: new Set(),
preserve_whitespace: options.preserveWhitespace,
public_state: new Map(),
private_state: new Map(),
state_fields: {},
backing_fields: {},
transform: {},
in_constructor: false,
instance_level_snippets: [],
@ -671,8 +671,8 @@ export function client_module(analysis, options) {
options,
scope: analysis.module.scope,
scopes: analysis.module.scopes,
public_state: new Map(),
private_state: new Map(),
state_fields: {},
backing_fields: {},
transform: {},
in_constructor: false
};

@ -9,14 +9,14 @@ import type {
UpdateExpression,
VariableDeclaration
} from 'estree';
import type { AST, Namespace, ValidatedCompileOptions } from '#compiler';
import type { AST, Namespace, StateField, ValidatedCompileOptions } from '#compiler';
import type { TransformState } from '../types.js';
import type { ComponentAnalysis } from '../../types.js';
import type { SourceLocation } from '#shared';
export interface ClientTransformState extends TransformState {
readonly private_state: Map<string, StateField>;
readonly public_state: Map<string, StateField>;
readonly state_fields: Record<string, StateField>;
readonly backing_fields: Record<string, PrivateIdentifier>;
/**
* `true` if the current lexical scope belongs to a class constructor. this allows
@ -94,10 +94,6 @@ export interface ComponentClientTransformState extends ClientTransformState {
readonly module_level_snippets: VariableDeclaration[];
}
export interface StateField {
type: '$state' | '$state.raw' | '$derived' | '$derived.by';
}
export type Context = import('zimmerframe').Context<AST.SvelteNode, ClientTransformState>;
export type Visitors = import('zimmerframe').Visitors<AST.SvelteNode, any>;

@ -53,6 +53,8 @@ const callees = {
*/
function build_assignment(operator, left, right, context) {
if (context.state.analysis.runes && left.type === 'MemberExpression') {
const name = get_name(left.property);
// special case — state declaration in class constructor
const ancestor = context.path.at(-4);
@ -60,8 +62,6 @@ function build_assignment(operator, left, right, context) {
const rune = get_rune(right, context.state.scope);
if (rune) {
const name = get_name(left.property);
const child_state = {
...context.state,
in_constructor: rune !== '$derived' && rune !== '$derived.by'
@ -82,15 +82,15 @@ function build_assignment(operator, left, right, context) {
// special case — assignment to private state field
if (left.property.type === 'PrivateIdentifier') {
const private_state = context.state.private_state.get(left.property.name);
const field = context.state.state_fields[name];
if (private_state !== undefined) {
if (field) {
let value = /** @type {Expression} */ (
context.visit(build_assignment_value(operator, left, right))
);
const needs_proxy =
private_state.type === '$state' &&
field.type === '$state' &&
is_non_coercive_operator(operator) &&
should_proxy(value, context.state.scope);

@ -29,8 +29,6 @@ export function ClassBody(node, context) {
}
}
const private_state = new Map();
/**
* each `foo = $state()` needs a backing `#foo` field
* @type {Record<string, PrivateIdentifier>}
@ -39,7 +37,6 @@ export function ClassBody(node, context) {
for (const name in state_fields) {
if (name[0] === '#') {
private_state.set(name.slice(1), state_fields[name]);
continue;
}
@ -55,7 +52,7 @@ export function ClassBody(node, context) {
/** @type {Array<MethodDefinition | PropertyDefinition | StaticBlock>} */
const body = [];
const child_state = { ...context.state, state_fields, backing_fields, private_state }; // TODO populate private_state
const child_state = { ...context.state, state_fields, backing_fields };
for (const name in state_fields) {
if (name[0] === '#') {

@ -9,7 +9,8 @@ import * as b from '#compiler/builders';
export function MemberExpression(node, context) {
// rewrite `this.#foo` as `this.#foo.v` inside a constructor
if (node.property.type === 'PrivateIdentifier') {
const field = context.state.private_state.get(node.property.name);
const field = context.state.state_fields['#' + node.property.name];
if (field) {
return context.state.in_constructor &&
(field.type === '$state.raw' || field.type === '$state')

@ -15,7 +15,7 @@ export function UpdateExpression(node, context) {
argument.type === 'MemberExpression' &&
argument.object.type === 'ThisExpression' &&
argument.property.type === 'PrivateIdentifier' &&
context.state.private_state.has(argument.property.name)
Object.hasOwn(context.state.state_fields, '#' + argument.property.name)
) {
let fn = '$.update';
if (node.prefix) fn += '_pre';

@ -32,8 +32,6 @@ export function ClassBody(node, context) {
}
}
const private_state = new Map();
/**
* each `foo = $state()` needs a backing `#foo` field
* @type {Record<string, PrivateIdentifier>}
@ -42,7 +40,6 @@ export function ClassBody(node, context) {
for (const name in state_fields) {
if (name[0] === '#') {
private_state.set(name.slice(1), state_fields[name]);
continue;
}
@ -58,7 +55,7 @@ export function ClassBody(node, context) {
/** @type {Array<MethodDefinition | PropertyDefinition | StaticBlock>} */
const body = [];
const child_state = { ...context.state, state_fields, backing_fields, private_state }; // TODO populate private_state
const child_state = { ...context.state, state_fields, backing_fields };
for (const name in state_fields) {
if (name[0] === '#') {

Loading…
Cancel
Save