Skip to content

Commit 909301f

Browse files
committed
remove old validation
1 parent 80557bb commit 909301f

File tree

11 files changed

+9
-365
lines changed

11 files changed

+9
-365
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
get_attribute_expression,
88
is_event_attribute
99
} from '../../../../utils/ast.js';
10-
import { dev, is_ignored, locate_node } from '../../../../state.js';
10+
import { dev, locate_node } from '../../../../state.js';
1111
import { should_proxy } from '../utils.js';
1212
import { visit_assignment_expression } from '../../shared/assignments.js';
1313

@@ -16,13 +16,9 @@ import { visit_assignment_expression } from '../../shared/assignments.js';
1616
* @param {Context} context
1717
*/
1818
export function AssignmentExpression(node, context) {
19-
const expression = /** @type {Expression} */ (
19+
return /** @type {Expression} */ (
2020
visit_assignment_expression(node, context, build_assignment) ?? context.next()
2121
);
22-
23-
return is_ignored(node, 'ownership_invalid_mutation')
24-
? b.call('$.skip_ownership_validation', b.thunk(expression))
25-
: expression;
2622
}
2723

2824
/**

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -161,33 +161,6 @@ export function ClassBody(node, context) {
161161
body.push(/** @type {MethodDefinition} **/ (context.visit(definition, child_state)));
162162
}
163163

164-
if (dev && public_state.size > 0) {
165-
// add an `[$.ADD_OWNER]` method so that a class with state fields can widen ownership
166-
body.push(
167-
b.method(
168-
'method',
169-
b.id('$.ADD_OWNER'),
170-
[b.id('owner')],
171-
[
172-
b.stmt(
173-
b.call(
174-
'$.add_owner_to_class',
175-
b.this,
176-
b.id('owner'),
177-
b.array(
178-
Array.from(public_state).map(([name]) =>
179-
b.thunk(b.call('$.get', b.member(b.this, b.private_id(name))))
180-
)
181-
),
182-
is_ignored(node, 'ownership_invalid_binding') && b.true
183-
)
184-
)
185-
],
186-
true
187-
)
188-
);
189-
}
190-
191164
return { ...node, body };
192165
}
193166

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/** @import { AssignmentExpression, Expression, UpdateExpression } from 'estree' */
22
/** @import { Context } from '../types' */
3-
import { is_ignored } from '../../../../state.js';
43
import { object } from '../../../../utils/ast.js';
54
import * as b from '../../../../utils/builders.js';
65

@@ -51,7 +50,5 @@ export function UpdateExpression(node, context) {
5150
);
5251
}
5352

54-
return is_ignored(node, 'ownership_invalid_mutation')
55-
? b.call('$.skip_ownership_validation', b.thunk(update))
56-
: update;
53+
return update;
5754
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,22 +178,6 @@ export function build_component(node, component_name, context, anchor = context.
178178
}
179179
} else if (attribute.type === 'BindDirective') {
180180
const expression = /** @type {Expression} */ (context.visit(attribute.expression));
181-
182-
if (dev && attribute.name !== 'this') {
183-
binding_initializers.push(
184-
b.stmt(
185-
b.call(
186-
b.id('$.add_owner_effect'),
187-
expression.type === 'SequenceExpression'
188-
? expression.expressions[0]
189-
: b.thunk(expression),
190-
b.id(component_name),
191-
is_ignored(node, 'ownership_invalid_binding') && b.true
192-
)
193-
)
194-
);
195-
}
196-
197181
if (expression.type === 'SequenceExpression') {
198182
if (attribute.name === 'this') {
199183
bind_this = attribute.expression;

packages/svelte/src/internal/client/constants.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ export const EFFECT_HAS_DERIVED = 1 << 20;
2323
export const EFFECT_IS_UPDATING = 1 << 21;
2424

2525
export const STATE_SYMBOL = Symbol('$state');
26-
export const STATE_SYMBOL_METADATA = Symbol('$state metadata');
2726
export const LEGACY_PROPS = Symbol('legacy props');
2827
export const LOADING_ATTR_SYMBOL = Symbol('');

packages/svelte/src/internal/client/context.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/** @import { ComponentContext } from '#client' */
22

33
import { DEV } from 'esm-env';
4-
import { add_owner } from './dev/ownership.js';
54
import { lifecycle_outside_component } from '../shared/errors.js';
65
import { source } from './reactivity/sources.js';
76
import {
@@ -67,15 +66,6 @@ export function getContext(key) {
6766
*/
6867
export function setContext(key, context) {
6968
const context_map = get_or_init_context_map('setContext');
70-
71-
if (DEV) {
72-
// When state is put into context, we treat as if it's global from now on.
73-
// We do for performance reasons (it's for example very expensive to call
74-
// getContext on a big object many times when part of a list component)
75-
// and danger of false positives.
76-
untrack(() => add_owner(context, null, true));
77-
}
78-
7969
context_map.set(key, context);
8070
return context;
8171
}
Lines changed: 0 additions & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
/** @import { ProxyMetadata } from '#client' */
21
/** @typedef {{ file: string, line: number, column: number }} Location */
32

4-
import { STATE_SYMBOL_METADATA } from '../constants.js';
5-
import { render_effect, user_pre_effect } from '../reactivity/effects.js';
6-
import { dev_current_component_function } from '../context.js';
7-
import { get_prototype_of } from '../../shared/utils.js';
8-
import * as w from '../warnings.js';
9-
import { FILENAME, UNINITIALIZED } from '../../../constants.js';
10-
113
/** @type {Record<string, Array<{ start: Location, end: Location, component: Function }>>} */
124
const boundaries = {};
135

@@ -71,8 +63,6 @@ export function get_component() {
7163
return null;
7264
}
7365

74-
export const ADD_OWNER = Symbol('ADD_OWNER');
75-
7666
/**
7767
* Together with `mark_module_end`, this function establishes the boundaries of a `.svelte` file,
7868
* such that subsequent calls to `get_component` can tell us which component is responsible
@@ -106,199 +96,3 @@ export function mark_module_end(component) {
10696
boundary.component = component;
10797
}
10898
}
109-
110-
/**
111-
* @param {any} object
112-
* @param {any | null} owner
113-
* @param {boolean} [global]
114-
* @param {boolean} [skip_warning]
115-
*/
116-
export function add_owner(object, owner, global = false, skip_warning = false) {
117-
if (object && !global) {
118-
const component = dev_current_component_function;
119-
const metadata = object[STATE_SYMBOL_METADATA];
120-
if (metadata && !has_owner(metadata, component)) {
121-
let original = get_owner(metadata);
122-
123-
if (owner && owner[FILENAME] !== component[FILENAME] && !skip_warning) {
124-
w.ownership_invalid_binding(component[FILENAME], owner[FILENAME], original[FILENAME]);
125-
}
126-
}
127-
}
128-
129-
add_owner_to_object(object, owner, new Set());
130-
}
131-
132-
/**
133-
* @param {() => unknown} get_object
134-
* @param {any} Component
135-
* @param {boolean} [skip_warning]
136-
*/
137-
export function add_owner_effect(get_object, Component, skip_warning = false) {
138-
user_pre_effect(() => {
139-
add_owner(get_object(), Component, false, skip_warning);
140-
});
141-
}
142-
143-
/**
144-
* @param {any} _this
145-
* @param {Function} owner
146-
* @param {Array<() => any>} getters
147-
* @param {boolean} skip_warning
148-
*/
149-
export function add_owner_to_class(_this, owner, getters, skip_warning) {
150-
_this[ADD_OWNER].current ||= getters.map(() => UNINITIALIZED);
151-
152-
for (let i = 0; i < getters.length; i += 1) {
153-
const current = getters[i]();
154-
// For performance reasons we only re-add the owner if the state has changed
155-
if (current !== _this[ADD_OWNER][i]) {
156-
_this[ADD_OWNER].current[i] = current;
157-
add_owner(current, owner, false, skip_warning);
158-
}
159-
}
160-
}
161-
162-
/**
163-
* @param {ProxyMetadata | null} from
164-
* @param {ProxyMetadata} to
165-
*/
166-
export function widen_ownership(from, to) {
167-
if (to.owners === null) {
168-
return;
169-
}
170-
171-
while (from) {
172-
if (from.owners === null) {
173-
to.owners = null;
174-
break;
175-
}
176-
177-
for (const owner of from.owners) {
178-
to.owners.add(owner);
179-
}
180-
181-
from = from.parent;
182-
}
183-
}
184-
185-
/**
186-
* @param {any} object
187-
* @param {Function | null} owner If `null`, then the object is globally owned and will not be checked
188-
* @param {Set<any>} seen
189-
*/
190-
function add_owner_to_object(object, owner, seen) {
191-
const metadata = /** @type {ProxyMetadata} */ (object?.[STATE_SYMBOL_METADATA]);
192-
193-
if (metadata) {
194-
// this is a state proxy, add owner directly, if not globally shared
195-
if ('owners' in metadata && metadata.owners != null) {
196-
if (owner) {
197-
metadata.owners.add(owner);
198-
} else {
199-
metadata.owners = null;
200-
}
201-
}
202-
} else if (object && typeof object === 'object') {
203-
if (seen.has(object)) return;
204-
seen.add(object);
205-
if (ADD_OWNER in object && object[ADD_OWNER]) {
206-
// this is a class with state fields. we put this in a render effect
207-
// so that if state is replaced (e.g. `instance.name = { first, last }`)
208-
// the new state is also co-owned by the caller of `getContext`
209-
render_effect(() => {
210-
object[ADD_OWNER](owner);
211-
});
212-
} else {
213-
var proto = get_prototype_of(object);
214-
215-
if (proto === Object.prototype) {
216-
// recurse until we find a state proxy
217-
for (const key in object) {
218-
if (Object.getOwnPropertyDescriptor(object, key)?.get) {
219-
// Similar to the class case; the getter could update with a new state
220-
let current = UNINITIALIZED;
221-
render_effect(() => {
222-
const next = object[key];
223-
if (current !== next) {
224-
current = next;
225-
add_owner_to_object(next, owner, seen);
226-
}
227-
});
228-
} else {
229-
add_owner_to_object(object[key], owner, seen);
230-
}
231-
}
232-
} else if (proto === Array.prototype) {
233-
// recurse until we find a state proxy
234-
for (let i = 0; i < object.length; i += 1) {
235-
add_owner_to_object(object[i], owner, seen);
236-
}
237-
}
238-
}
239-
}
240-
}
241-
242-
/**
243-
* @param {ProxyMetadata} metadata
244-
* @param {Function} component
245-
* @returns {boolean}
246-
*/
247-
function has_owner(metadata, component) {
248-
if (metadata.owners === null) {
249-
return true;
250-
}
251-
252-
return (
253-
metadata.owners.has(component) ||
254-
// This helps avoid false positives when using HMR, where the component function is replaced
255-
(FILENAME in component &&
256-
[...metadata.owners].some(
257-
(owner) => /** @type {any} */ (owner)[FILENAME] === component[FILENAME]
258-
)) ||
259-
(metadata.parent !== null && has_owner(metadata.parent, component))
260-
);
261-
}
262-
263-
/**
264-
* @param {ProxyMetadata} metadata
265-
* @returns {any}
266-
*/
267-
function get_owner(metadata) {
268-
return (
269-
metadata?.owners?.values().next().value ??
270-
get_owner(/** @type {ProxyMetadata} */ (metadata.parent))
271-
);
272-
}
273-
274-
let skip = false;
275-
276-
/**
277-
* @param {() => any} fn
278-
*/
279-
export function skip_ownership_validation(fn) {
280-
skip = true;
281-
fn();
282-
skip = false;
283-
}
284-
285-
/**
286-
* @param {ProxyMetadata} metadata
287-
*/
288-
export function check_ownership(metadata) {
289-
if (skip) return;
290-
291-
const component = get_component();
292-
293-
if (component && !has_owner(metadata, component)) {
294-
let original = get_owner(metadata);
295-
296-
// @ts-expect-error
297-
if (original[FILENAME] !== component[FILENAME]) {
298-
// @ts-expect-error
299-
w.ownership_invalid_mutation(component[FILENAME], original[FILENAME]);
300-
} else {
301-
w.ownership_invalid_mutation();
302-
}
303-
}
304-
}

packages/svelte/src/internal/client/index.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ export { assign, assign_and, assign_or, assign_nullish } from './dev/assign.js';
44
export { cleanup_styles } from './dev/css.js';
55
export { add_locations } from './dev/elements.js';
66
export { hmr } from './dev/hmr.js';
7-
export {
8-
ADD_OWNER,
9-
add_owner,
10-
mark_module_start,
11-
mark_module_end,
12-
add_owner_effect,
13-
add_owner_to_class,
14-
skip_ownership_validation
15-
} from './dev/ownership.js';
7+
export { mark_module_start, mark_module_end } from './dev/ownership.js';
168
export { check_target, legacy_api } from './dev/legacy.js';
179
export { trace } from './dev/tracing.js';
1810
export { inspect } from './dev/inspect.js';

0 commit comments

Comments
 (0)