pull/12808/head
Rich Harris 2 years ago
parent 7a25e04832
commit 92e6cbef7f

@ -34,7 +34,7 @@ export function BindDirective(node, context) {
node.name !== 'this' && // bind:this also works for regular variables
(!binding ||
(binding.kind !== 'state' &&
binding.kind !== 'frozen_state' &&
binding.kind !== 'raw_state' &&
binding.kind !== 'prop' &&
binding.kind !== 'bindable_prop' &&
binding.kind !== 'each' &&

@ -32,7 +32,7 @@ export function ExportNamedDeclaration(node, context) {
e.derived_invalid_export(node);
}
if ((binding.kind === 'state' || binding.kind === 'frozen_state') && binding.reassigned) {
if ((binding.kind === 'state' || binding.kind === 'raw_state') && binding.reassigned) {
e.state_invalid_export(node);
}
}

@ -26,7 +26,7 @@ export function ExportSpecifier(node, context) {
if (
binding !== null &&
(binding.kind === 'state' ||
binding.kind === 'frozen_state' ||
binding.kind === 'raw_state' ||
(binding.kind === 'normal' &&
(binding.declaration_kind === 'let' || binding.declaration_kind === 'var')))
) {
@ -60,7 +60,7 @@ function validate_export(node, scope, name) {
e.derived_invalid_export(node);
}
if ((binding.kind === 'state' || binding.kind === 'frozen_state') && binding.reassigned) {
if ((binding.kind === 'state' || binding.kind === 'raw_state') && binding.reassigned) {
e.state_invalid_export(node);
}
}

@ -133,7 +133,7 @@ export function Identifier(node, context) {
binding.initial.arguments.length === 1 &&
binding.initial.arguments[0].type !== 'SpreadElement' &&
!should_proxy_or_freeze(binding.initial.arguments[0], context.state.scope)))) ||
binding.kind === 'frozen_state' ||
binding.kind === 'raw_state' ||
binding.kind === 'derived') &&
// We're only concerned with reads here
(parent.type !== 'AssignmentExpression' || parent.left !== node) &&

@ -33,7 +33,7 @@ export function VariableDeclarator(node, context) {
rune === '$state'
? 'state'
: rune === '$state.raw'
? 'frozen_state'
? 'raw_state'
: rune === '$derived' || rune === '$derived.by'
? 'derived'
: path.is_rest

@ -78,7 +78,7 @@ export function validate_no_const_assignment(node, argument, scope, is_binding)
// // This takes advantage of the fact that we don't assign initial for let directives and then/catch variables.
// // If we start doing that, we need another property on the binding to differentiate, or give up on the more precise error message.
// binding.kind !== 'state' &&
// binding.kind !== 'frozen_state' &&
// binding.kind !== 'raw_state' &&
// (binding.kind !== 'normal' || !binding.initial)
// );

@ -271,7 +271,7 @@ export function client_component(analysis, options) {
}
}
if (binding?.kind === 'state' || binding?.kind === 'frozen_state') {
if (binding?.kind === 'state' || binding?.kind === 'raw_state') {
const value = binding.kind === 'state' ? b.call('$.proxy', b.id('$$value')) : b.id('$$value');
return [getter, b.set(alias ?? name, [b.stmt(b.call('$.set', b.id(name), value))])];
}

@ -88,7 +88,7 @@ export interface ComponentClientTransformState extends ClientTransformState {
}
export interface StateField {
kind: 'state' | 'frozen_state' | 'derived' | 'derived_by';
kind: 'state' | 'raw_state' | 'derived' | 'derived_by';
id: PrivateIdentifier;
}

@ -20,7 +20,7 @@ import { get_value } from './visitors/shared/declarations.js';
*/
export function is_state_source(binding, state) {
return (
(binding.kind === 'state' || binding.kind === 'frozen_state') &&
(binding.kind === 'state' || binding.kind === 'raw_state') &&
(!state.analysis.immutable || binding.reassigned || state.analysis.accessors)
);
}

@ -40,7 +40,7 @@ export function build_assignment(operator, left, right, context) {
if (should_proxy_or_freeze(value, context.state.scope)) {
transformed = true;
value =
private_state.kind === 'frozen_state'
private_state.kind === 'raw_state'
? value
: build_proxy_reassignment(value, private_state.id);
}
@ -60,7 +60,7 @@ export function build_assignment(operator, left, right, context) {
return b.assignment(
operator,
/** @type {Pattern} */ (context.visit(left)),
public_state.kind === 'frozen_state'
public_state.kind === 'raw_state'
? value
: build_proxy_reassignment(value, public_state.id)
);
@ -102,8 +102,7 @@ export function build_assignment(operator, left, right, context) {
context.state.analysis.runes &&
should_proxy_or_freeze(value, context.state.scope)
) {
value =
binding.kind === 'frozen_state' ? value : build_proxy_reassignment(value, object.name);
value = binding.kind === 'raw_state' ? value : build_proxy_reassignment(value, object.name);
}
return transform.assign(object, value);

@ -54,7 +54,7 @@ export function ClassBody(node, context) {
rune === '$state'
? 'state'
: rune === '$state.raw'
? 'frozen_state'
? 'raw_state'
: rune === '$derived.by'
? 'derived_by'
: 'derived',
@ -116,7 +116,7 @@ export function ClassBody(node, context) {
'$.source',
should_proxy_or_freeze(init, context.state.scope) ? b.call('$.proxy', init) : init
)
: field.kind === 'frozen_state'
: field.kind === 'raw_state'
? b.call('$.source', init)
: field.kind === 'derived_by'
? b.call('$.derived', init)
@ -149,7 +149,7 @@ export function ClassBody(node, context) {
);
}
if (field.kind === 'frozen_state') {
if (field.kind === 'raw_state') {
// set foo(value) { this.#foo = value; }
const value = b.id('value');
body.push(

@ -151,7 +151,7 @@ export function VariableDeclaration(node, context) {
const binding = context.state.scope.get(/** @type {Identifier} */ (path.node).name);
return b.declarator(
path.node,
binding?.kind === 'state' || binding?.kind === 'frozen_state'
binding?.kind === 'state' || binding?.kind === 'raw_state'
? create_state_declarator(binding.node, value)
: value
);

@ -278,7 +278,7 @@ export interface Binding {
| 'bindable_prop'
| 'rest_prop'
| 'state'
| 'frozen_state'
| 'raw_state'
| 'derived'
| 'each'
| 'snippet'

Loading…
Cancel
Save