Skip to content

Commit 26d9ae0

Browse files
authored
Merge branch 'props-bindable-2' into props-bindable-2-error-message
2 parents 6a39559 + adc3f7a commit 26d9ae0

File tree

78 files changed

+1962
-2561
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1962
-2561
lines changed

.changeset/pre.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"afraid-moose-matter",
1414
"angry-books-jam",
1515
"angry-plums-punch",
16+
"beige-cobras-smoke",
1617
"beige-flies-wash",
1718
"beige-mirrors-listen",
1819
"beige-rabbits-shave",
@@ -63,6 +64,7 @@
6364
"dry-eggs-retire",
6465
"dull-coins-vanish",
6566
"dull-mangos-wave",
67+
"dull-pots-add",
6668
"dull-roses-relate",
6769
"early-ads-tie",
6870
"eight-steaks-shout",
@@ -166,6 +168,7 @@
166168
"lucky-schools-hang",
167169
"lucky-toes-begin",
168170
"many-trees-fix",
171+
"mighty-cooks-scream",
169172
"mighty-files-hammer",
170173
"moody-carrots-lay",
171174
"moody-frogs-exist",
@@ -192,6 +195,7 @@
192195
"old-mails-sneeze",
193196
"old-oranges-compete",
194197
"olive-kangaroos-brake",
198+
"olive-mice-fix",
195199
"olive-seals-sell",
196200
"olive-shirts-complain",
197201
"olive-socks-kick",
@@ -233,6 +237,7 @@
233237
"rotten-rules-invite",
234238
"rude-ghosts-tickle",
235239
"selfish-dragons-knock",
240+
"selfish-spies-help",
236241
"selfish-tools-hide",
237242
"serious-kids-deliver",
238243
"serious-needles-joke",
@@ -265,6 +270,7 @@
265270
"small-papayas-laugh",
266271
"small-sheep-type",
267272
"smart-parents-swim",
273+
"smart-turkeys-tell",
268274
"smart-zebras-pay",
269275
"smooth-rings-rush",
270276
"soft-clocks-remember",
@@ -306,6 +312,7 @@
306312
"tasty-cheetahs-appear",
307313
"tasty-numbers-perform",
308314
"tasty-steaks-smile",
315+
"ten-eels-move",
309316
"ten-foxes-repeat",
310317
"ten-jokes-divide",
311318
"ten-peaches-sleep",

.changeset/selfish-spies-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: improve element class attribute behaviour

.changeset/small-spiders-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
breaking: apply fallback value every time in runes mode

packages/svelte/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
/motion.d.ts
1212
/store.d.ts
1313
/transition.d.ts
14+
15+
/scripts/_bundle.js

packages/svelte/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# svelte
22

3+
## 5.0.0-next.81
4+
5+
### Patch Changes
6+
7+
- feat: add support for webkitdirectory DOM boolean attribute ([#10847](https://github.com/sveltejs/svelte/pull/10847))
8+
9+
- fix: don't override instance methods during legacy class creation ([#10834](https://github.com/sveltejs/svelte/pull/10834))
10+
11+
- fix: adjust scope parent for named slots ([#10843](https://github.com/sveltejs/svelte/pull/10843))
12+
13+
- fix: improve handling of unowned derived signals ([#10842](https://github.com/sveltejs/svelte/pull/10842))
14+
15+
- fix: improve element class attribute behaviour ([#10856](https://github.com/sveltejs/svelte/pull/10856))
16+
17+
- fix: ensure select value is updated upon select option removal ([#10846](https://github.com/sveltejs/svelte/pull/10846))
18+
19+
- fix: ensure capture events don't call delegated events ([#10831](https://github.com/sveltejs/svelte/pull/10831))
20+
321
## 5.0.0-next.80
422

523
### Patch Changes

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "svelte",
33
"description": "Cybernetically enhanced web apps",
44
"license": "MIT",
5-
"version": "5.0.0-next.80",
5+
"version": "5.0.0-next.81",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {

packages/svelte/scripts/check-treeshakeability.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ async function bundle_code(entry) {
1212
virtual({
1313
__entry__: entry
1414
}),
15+
{
16+
name: 'resolve-svelte',
17+
resolveId(importee) {
18+
if (importee.startsWith('svelte')) {
19+
const entry = pkg.exports[importee.replace('svelte', '.')];
20+
return path.resolve(entry.browser ?? entry.default);
21+
}
22+
}
23+
},
1524
nodeResolve({
1625
exportConditions: ['production', 'import', 'browser', 'default']
1726
})
@@ -65,7 +74,7 @@ for (const key in pkg.exports) {
6574
}
6675

6776
const client_main = path.resolve(pkg.exports['.'].browser);
68-
const without_hydration = await bundle_code(
77+
const bundle = await bundle_code(
6978
// Use all features which contain hydration code to ensure it's treeshakeable
7079
compile(
7180
`
@@ -99,15 +108,18 @@ const without_hydration = await bundle_code(
99108
{ filename: 'App.svelte' }
100109
).js.code
101110
);
102-
if (!without_hydration.includes('current_hydration_fragment')) {
111+
112+
if (!bundle.includes('current_hydration_fragment')) {
103113
// eslint-disable-next-line no-console
104114
console.error(`✅ Hydration code treeshakeable`);
105115
} else {
106116
// eslint-disable-next-line no-console
107-
console.error(without_hydration);
117+
console.error(bundle);
108118
// eslint-disable-next-line no-console
109119
console.error(`❌ Hydration code not treeshakeable`);
110120
failed = true;
121+
122+
fs.writeFileSync('scripts/_bundle.js', bundle);
111123
}
112124

113125
// eslint-disable-next-line no-console

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/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,7 @@ const common_visitors = {
10881088
}
10891089

10901090
if (
1091+
context.state.analysis.runes &&
10911092
node !== binding.node &&
10921093
// If we have $state that can be proxied or frozen and isn't re-assigned, then that means
10931094
// it's likely not using a primitive value and thus this warning isn't that helpful.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,8 @@ export const validation_runes_js = {
891891
error(node, 'invalid-rune-args-length', rune, [0, 1]);
892892
} else if (rune === '$props') {
893893
error(node, 'invalid-props-location');
894+
} else if (rune === '$bindable') {
895+
error(node, 'invalid-bindable-location');
894896
}
895897
},
896898
AssignmentExpression(node, { state }) {
@@ -1070,10 +1072,10 @@ export const validation_runes = merge(validation, a11y_validators, {
10701072
// TODO some of this is duplicated with above, seems off
10711073
if ((rune === '$derived' || rune === '$derived.by') && args.length !== 1) {
10721074
error(node, 'invalid-rune-args-length', rune, [1]);
1073-
} else if (rune === '$state' && args.length > 1) {
1075+
} else if ((rune === '$state' || rune === '$bindable') && args.length > 1) {
10741076
error(node, 'invalid-rune-args-length', rune, [0, 1]);
10751077
} else if (rune === '$props') {
1076-
if (rune === '$props' && state.has_props_rune) {
1078+
if (state.has_props_rune) {
10771079
error(node, 'duplicate-props-rune');
10781080
}
10791081

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,24 @@ 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;
273+
274+
const getter = b.get(key, [b.return(b.call(b.id(name)))]);
275+
276+
const setter = b.set(key, [
277+
b.stmt(b.call(b.id(name), b.id('$$value'))),
278+
b.stmt(b.call('$.flushSync'))
279+
]);
280+
281+
if (analysis.runes && binding.initial) {
282+
// turn `set foo($$value)` into `set foo($$value = expression)`
283+
setter.value.params[0] = {
284+
type: 'AssignmentPattern',
285+
left: b.id('$$value'),
286+
right: /** @type {import('estree').Expression} */ (binding.initial)
287+
};
281288
}
282289

283-
component_returned_object.push(
284-
b.get(key, [b.return(b.call(b.id(name)))]),
285-
b.set(key, [b.stmt(b.call(b.id(name), b.id('$$value'))), b.stmt(b.call('$.flushSync'))])
286-
);
290+
component_returned_object.push(getter, setter);
287291
}
288292
}
289293

0 commit comments

Comments
 (0)