Skip to content

Commit ef0bc44

Browse files
Apply suggestions from code review
Co-authored-by: Rich Harris <[email protected]>
1 parent 7992ef8 commit ef0bc44

File tree

6 files changed

+18
-20
lines changed

6 files changed

+18
-20
lines changed

packages/svelte/src/compiler/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ const runes = {
182182
`$props() assignment must not contain nested properties or computed keys`,
183183
'invalid-props-location': () =>
184184
`$props() can only be used at the top level of components as a variable declaration initializer`,
185-
'invalid-bindable-location': () => `$bindable() can only be used as part of the $props() rune`,
185+
'invalid-bindable-location': () => `$bindable() can only be used inside a $props() declaration`,
186186
/** @param {string} rune */
187187
'invalid-state-location': (rune) =>
188188
`${rune}(...) can only be used as a variable declaration initializer or a class field`,

packages/svelte/src/compiler/phases/2-analyze/validation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ export const validation_runes = merge(validation, a11y_validators, {
10731073
} else if (rune === '$state' && args.length > 1) {
10741074
error(node, 'invalid-rune-args-length', rune, [0, 1]);
10751075
} else if (rune === '$props') {
1076-
if (rune === '$props' && state.has_props_rune) {
1076+
if (state.has_props_rune) {
10771077
error(node, 'duplicate-props-rune');
10781078
}
10791079

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,6 @@ export function client_component(source, analysis, options) {
270270
if (analysis.accessors) {
271271
for (const [name, binding] of properties) {
272272
const key = binding.prop_alias ?? name;
273-
if (
274-
binding.kind === 'prop' &&
275-
[...analysis.instance.scope.declarations].some(
276-
([name, d]) => d.kind === 'bindable_prop' && (d.prop_alias ?? name) === key
277-
)
278-
) {
279-
// bindable prop takes precedence
280-
continue;
281-
}
282273

283274
component_returned_object.push(
284275
b.get(key, [b.return(b.call(b.id(name)))]),

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,25 @@ export const javascript_visitors_runes = {
211211
property.value.type === 'AssignmentPattern' ? property.value.left : property.value;
212212
assert.equal(id.type, 'Identifier');
213213
const binding = /** @type {import('#compiler').Binding} */ (state.scope.get(id.name));
214-
let initial = /** @type {import('estree').Expression | null} */ (binding.initial);
215-
if (initial) {
216-
initial = /** @type {import('estree').Expression} */ (visit(initial));
217-
}
214+
const initial =
215+
binding.initial &&
216+
/** @type {import('estree').Expression} */ (visit(binding.initial));
218217

219218
if (binding.reassigned || state.analysis.accessors || initial) {
220219
declarations.push(b.declarator(id, get_prop_source(binding, state, name, initial)));
221220
}
222221
} else {
223222
// RestElement
224-
/** @type {import('estree').Expression[]} */
225-
const args = [b.id('$$props'), b.array(seen.map((name) => b.literal(name)))];
226-
declarations.push(b.declarator(property.argument, b.call('$.rest_props', ...args)));
223+
declarations.push(
224+
b.declarator(
225+
property.argument,
226+
b.call(
227+
'$.rest_props',
228+
b.id('$$props'),
229+
b.array(seen.map((name) => b.literal(name)))
230+
)
231+
)
232+
);
227233
}
228234
}
229235

packages/svelte/src/compiler/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export interface Binding {
241241
node: Identifier;
242242
/**
243243
* - `normal`: A variable that is not in any way special
244-
* - `prop`: A normal prop (possibly reassigned)
244+
* - `prop`: A normal prop (possibly reassigned or mutated)
245245
* - `bindable_prop`: A prop one can `bind:` to (possibly reassigned or mutated)
246246
* - `rest_prop`: A rest prop
247247
* - `state`: A state variable

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,8 @@ if (DEV) {
12791279
throw_rune_error('$effect', ['pre', 'root', 'active']);
12801280
throw_rune_error('$derived', ['by']);
12811281
throw_rune_error('$inspect');
1282-
throw_rune_error('$props', ['bindable']);
1282+
throw_rune_error('$props');
1283+
throw_rune_error('$bindable');
12831284
}
12841285

12851286
/**

0 commit comments

Comments
 (0)