Skip to content

Commit 2de585d

Browse files
committed
merge main
2 parents 642db07 + 2cefd78 commit 2de585d

File tree

49 files changed

+452
-262
lines changed

Some content is hidden

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

49 files changed

+452
-262
lines changed

.changeset/afraid-kids-hide.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: throw error when auto-subscribed store variable shadow by local variable

.changeset/calm-pandas-vanish.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: make ownership validation work correctly with HMR

.changeset/cool-comics-marry.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 missing classes after dynamic expressions in class attribute

.changeset/few-teachers-know.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: revert ownership widening change

.changeset/fresh-dots-destroy.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: add validation around disallowed sequence expressions to element attributes

.changeset/pre.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"cold-birds-own",
5454
"cold-masks-learn",
5555
"cool-ants-leave",
56+
"cool-comics-marry",
5657
"cool-peas-lick",
5758
"cool-rabbits-tickle",
5859
"cool-roses-trade",
@@ -89,6 +90,7 @@
8990
"empty-bulldogs-exercise",
9091
"empty-crabs-think",
9192
"empty-tools-share",
93+
"fair-bags-smoke",
9294
"fair-crabs-check",
9395
"fair-pianos-talk",
9496
"fair-spies-repeat",
@@ -111,6 +113,7 @@
111113
"forty-suns-smile",
112114
"four-flies-hammer",
113115
"four-mice-hammer",
116+
"fresh-dots-destroy",
114117
"fresh-impalas-bow",
115118
"fresh-weeks-trade",
116119
"friendly-candles-relate",
@@ -316,6 +319,7 @@
316319
"small-sheep-type",
317320
"small-spiders-fail",
318321
"smart-cherries-leave",
322+
"smart-grapes-mate",
319323
"smart-parents-swim",
320324
"smart-turkeys-tell",
321325
"smart-zebras-pay",

.changeset/shy-fishes-drive.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: fix string name of reactive map and set iterator

.changeset/smart-grapes-mate.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: generate correct types for reactive Map/Set/Date

.changeset/wicked-wasps-allow.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+
feat: update error message for snippet binding and assignments

packages/svelte/CHANGELOG.md

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

3+
## 5.0.0-next.102
4+
5+
### Patch Changes
6+
7+
- fix: generate correct types for reactive Map/Set/Date ([#11153](https://github.com/sveltejs/svelte/pull/11153))
8+
9+
## 5.0.0-next.101
10+
11+
### Patch Changes
12+
13+
- fix missing classes after dynamic expressions in class attribute ([#11134](https://github.com/sveltejs/svelte/pull/11134))
14+
15+
- feat: simplify HMR implementation ([#11132](https://github.com/sveltejs/svelte/pull/11132))
16+
17+
- fix: add validation around disallowed sequence expressions to element attributes ([#11149](https://github.com/sveltejs/svelte/pull/11149))
18+
319
## 5.0.0-next.100
420

521
### Patch Changes

packages/svelte/package.json

Lines changed: 3 additions & 3 deletions
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.100",
5+
"version": "5.0.0-next.102",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {
@@ -104,7 +104,7 @@
104104
"check": "tsc && cd ./tests/types && tsc",
105105
"check:watch": "tsc --watch",
106106
"generate:version": "node ./scripts/generate-version.js",
107-
"generate:types": "node ./scripts/generate-types.js",
107+
"generate:types": "node ./scripts/generate-types.js && tsc -p tsconfig.generated.json",
108108
"prepublishOnly": "pnpm build",
109109
"knip": "knip"
110110
},
@@ -116,7 +116,7 @@
116116
"@rollup/plugin-terser": "^0.4.4",
117117
"@rollup/plugin-virtual": "^3.0.2",
118118
"@types/aria-query": "^5.0.4",
119-
"dts-buddy": "^0.4.6",
119+
"dts-buddy": "^0.4.7",
120120
"esbuild": "^0.19.11",
121121
"knip": "^4.2.1",
122122
"rollup": "^4.9.5",

packages/svelte/src/compiler/errors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ const runes = {
214214
'duplicate-props-rune': () => `Cannot use $props() more than once`,
215215
'invalid-each-assignment': () =>
216216
`Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. 'array[i] = value' instead of 'entry = value')`,
217+
'invalid-snippet-assignment': () => `Cannot reassign or bind to snippet parameter`,
217218
'invalid-derived-call': () => `$derived.call(...) has been replaced with $derived.by(...)`,
218219
'conflicting-property-name': () =>
219220
`Cannot have a property and a component export with the same name`

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,23 +302,26 @@ export function analyze_component(root, source, options) {
302302
declaration.initial.source.value === 'svelte/store'
303303
))
304304
) {
305-
let is_nested_store_subscription = false;
306-
for (const reference of references) {
305+
let is_nested_store_subscription_node = undefined;
306+
search: for (const reference of references) {
307307
for (let i = reference.path.length - 1; i >= 0; i--) {
308308
const scope =
309309
scopes.get(reference.path[i]) ||
310310
module.scopes.get(reference.path[i]) ||
311311
instance.scopes.get(reference.path[i]);
312312
if (scope) {
313313
const owner = scope?.owner(store_name);
314-
is_nested_store_subscription =
315-
!!owner && owner !== module.scope && owner !== instance.scope;
314+
if (!!owner && owner !== module.scope && owner !== instance.scope) {
315+
is_nested_store_subscription_node = reference.node;
316+
break search;
317+
}
316318
break;
317319
}
318320
}
319321
}
320-
if (is_nested_store_subscription) {
321-
error(references[0].node, 'illegal-store-subscription');
322+
323+
if (is_nested_store_subscription_node) {
324+
error(is_nested_store_subscription_node, 'illegal-store-subscription');
322325
}
323326

324327
if (options.runes !== false) {

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ function validate_element(node, context) {
9898
if (context.state.analysis.runes && is_expression) {
9999
const expression = attribute.value[0].expression;
100100
if (expression.type === 'SequenceExpression') {
101-
error(expression, 'invalid-sequence-expression');
101+
let i = /** @type {number} */ (expression.start);
102+
while (--i > 0) {
103+
const char = context.state.analysis.source[i];
104+
if (char === '(') break; // parenthesized sequence expressions are ok
105+
if (char === '{') error(expression, 'invalid-sequence-expression');
106+
}
102107
}
103108
}
104109

@@ -348,7 +353,9 @@ const validation = {
348353
error(node, 'invalid-each-assignment');
349354
}
350355

351-
// TODO handle mutations of non-state/props in runes mode
356+
if (binding.kind === 'snippet') {
357+
error(node, 'invalid-snippet-assignment');
358+
}
352359
}
353360

354361
if (node.name === 'group') {
@@ -1008,14 +1015,21 @@ function validate_no_const_assignment(node, argument, scope, is_binding) {
10081015
function validate_assignment(node, argument, state) {
10091016
validate_no_const_assignment(node, argument, state.scope, false);
10101017

1011-
if (state.analysis.runes && argument.type === 'Identifier') {
1018+
if (argument.type === 'Identifier') {
10121019
const binding = state.scope.get(argument.name);
1013-
if (binding?.kind === 'derived') {
1014-
error(node, 'invalid-derived-assignment');
1020+
1021+
if (state.analysis.runes) {
1022+
if (binding?.kind === 'derived') {
1023+
error(node, 'invalid-derived-assignment');
1024+
}
1025+
1026+
if (binding?.kind === 'each') {
1027+
error(node, 'invalid-each-assignment');
1028+
}
10151029
}
10161030

1017-
if (binding?.kind === 'each') {
1018-
error(node, 'invalid-each-assignment');
1031+
if (binding?.kind === 'snippet') {
1032+
error(node, 'invalid-snippet-assignment');
10191033
}
10201034
}
10211035

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ export function client_component(source, analysis, options) {
464464
);
465465
}
466466

467-
body.unshift(b.stmt(b.call(b.id('$.mark_module_start'), b.id(analysis.name))));
468-
body.push(b.stmt(b.call(b.id('$.mark_module_end'))));
467+
body.unshift(b.stmt(b.call(b.id('$.mark_module_start'))));
468+
body.push(b.stmt(b.call(b.id('$.mark_module_end'), b.id(analysis.name))));
469469
}
470470

471471
if (options.discloseVersion) {

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,7 @@ function serialize_attribute_value(
853853
/** @type {import('estree').Expression[]} */
854854
const expressions = [];
855855

856-
if (attribute_value[0].type !== 'Text') {
857-
quasis.push(b.quasi('', false));
858-
}
856+
quasis.push(b.quasi('', false));
859857

860858
let i = 0;
861859
for (const node of attribute_value) {
@@ -866,17 +864,16 @@ function serialize_attribute_value(
866864
// don't trim, space could be important to separate from expression tag
867865
data = data.replace(regex_whitespaces_strict, ' ');
868866
}
869-
quasis.push(b.quasi(data, i === attribute_value.length));
867+
const last = /** @type {import('estree').TemplateElement} */ (quasis.at(-1));
868+
last.value.raw += data;
870869
} else {
871870
expressions.push(
872871
b.call(
873872
'$.stringify',
874873
/** @type {import('estree').Expression} */ (context.visit(node.expression))
875874
)
876875
);
877-
if (i === attribute_value.length || attribute_value[i]?.type !== 'Text') {
878-
quasis.push(b.quasi('', true));
879-
}
876+
quasis.push(b.quasi('', i + 1 === attribute_value.length));
880877
}
881878
}
882879

packages/svelte/src/compiler/phases/scope.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
649649

650650
for (const param of node.parameters) {
651651
for (const id of extract_identifiers(param)) {
652-
child_scope.declare(id, 'each', 'let');
652+
child_scope.declare(id, 'snippet', 'let');
653653
}
654654
}
655655

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ export interface Binding {
253253
* - `rest_prop`: A rest prop
254254
* - `state`: A state variable
255255
* - `derived`: A derived variable
256-
* - `each`: An each block context variable
256+
* - `each`: An each block parameter
257+
* - `snippet`: A snippet parameter
257258
* - `store_sub`: A $store value
258259
* - `legacy_reactive`: A `$:` declaration
259260
* - `legacy_reactive_import`: An imported binding that is mutated inside the component
@@ -267,6 +268,7 @@ export interface Binding {
267268
| 'frozen_state'
268269
| 'derived'
269270
| 'each'
271+
| 'snippet'
270272
| 'store_sub'
271273
| 'legacy_reactive'
272274
| 'legacy_reactive_import';

0 commit comments

Comments
 (0)