svelte 5.39.11 → 5.39.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "svelte",
3
3
  "description": "Cybernetically enhanced web apps",
4
4
  "license": "MIT",
5
- "version": "5.39.11",
5
+ "version": "5.39.12",
6
6
  "type": "module",
7
7
  "types": "./types/index.d.ts",
8
8
  "engines": {
@@ -192,17 +192,18 @@ function build_assignment(operator, left, right, context) {
192
192
  path.at(-1) === 'Component' ||
193
193
  path.at(-1) === 'SvelteComponent' ||
194
194
  (path.at(-1) === 'ArrowFunctionExpression' &&
195
- path.at(-2) === 'SequenceExpression' &&
196
- (path.at(-3) === 'Component' ||
197
- path.at(-3) === 'SvelteComponent' ||
198
- path.at(-3) === 'BindDirective'))
195
+ (path.at(-2) === 'BindDirective' ||
196
+ (path.at(-2) === 'Component' && path.at(-3) === 'Fragment') ||
197
+ (path.at(-2) === 'SequenceExpression' &&
198
+ (path.at(-3) === 'Component' ||
199
+ path.at(-3) === 'SvelteComponent' ||
200
+ path.at(-3) === 'BindDirective'))))
199
201
  ) {
200
202
  should_transform = false;
201
203
  }
202
204
 
203
205
  if (left.type === 'MemberExpression' && should_transform) {
204
206
  const callee = callees[operator];
205
-
206
207
  return /** @type {Expression} */ (
207
208
  context.visit(
208
209
  b.call(
@@ -209,10 +209,8 @@ export function parse_directive_name(name) {
209
209
  * @param {import('zimmerframe').Context<AST.SvelteNode, ComponentClientTransformState>} context
210
210
  */
211
211
  export function build_bind_this(expression, value, { state, visit }) {
212
- if (expression.type === 'SequenceExpression') {
213
- const [get, set] = /** @type {SequenceExpression} */ (visit(expression)).expressions;
214
- return b.call('$.bind_this', value, set, get);
215
- }
212
+ const [getter, setter] =
213
+ expression.type === 'SequenceExpression' ? expression.expressions : [null, null];
216
214
 
217
215
  /** @type {Identifier[]} */
218
216
  const ids = [];
@@ -229,7 +227,7 @@ export function build_bind_this(expression, value, { state, visit }) {
229
227
  // Note that we only do this for each context variables, the consequence is that the value might be stale in
230
228
  // some scenarios where the value is a member expression with changing computed parts or using a combination of multiple
231
229
  // variables, but that was the same case in Svelte 4, too. Once legacy mode is gone completely, we can revisit this.
232
- walk(expression, null, {
230
+ walk(getter ?? expression, null, {
233
231
  Identifier(node, { path }) {
234
232
  if (seen.includes(node.name)) return;
235
233
  seen.push(node.name);
@@ -260,9 +258,17 @@ export function build_bind_this(expression, value, { state, visit }) {
260
258
 
261
259
  const child_state = { ...state, transform };
262
260
 
263
- const get = /** @type {Expression} */ (visit(expression, child_state));
264
- const set = /** @type {Expression} */ (
265
- visit(b.assignment('=', expression, b.id('$$value')), child_state)
261
+ let get = /** @type {Expression} */ (visit(getter ?? expression, child_state));
262
+ let set = /** @type {Expression} */ (
263
+ visit(
264
+ setter ??
265
+ b.assignment(
266
+ '=',
267
+ /** @type {Identifier | MemberExpression} */ (expression),
268
+ b.id('$$value')
269
+ ),
270
+ child_state
271
+ )
266
272
  );
267
273
 
268
274
  // If we're mutating a property, then it might already be non-existent.
@@ -275,13 +281,25 @@ export function build_bind_this(expression, value, { state, visit }) {
275
281
  node = node.object;
276
282
  }
277
283
 
278
- return b.call(
279
- '$.bind_this',
280
- value,
281
- b.arrow([b.id('$$value'), ...ids], set),
282
- b.arrow([...ids], get),
283
- values.length > 0 && b.thunk(b.array(values))
284
- );
284
+ get =
285
+ get.type === 'ArrowFunctionExpression'
286
+ ? b.arrow([...ids], get.body)
287
+ : get.type === 'FunctionExpression'
288
+ ? b.function(null, [...ids], get.body)
289
+ : getter
290
+ ? get
291
+ : b.arrow([...ids], get);
292
+
293
+ set =
294
+ set.type === 'ArrowFunctionExpression'
295
+ ? b.arrow([set.params[0] ?? b.id('_'), ...ids], set.body)
296
+ : set.type === 'FunctionExpression'
297
+ ? b.function(null, [set.params[0] ?? b.id('_'), ...ids], set.body)
298
+ : setter
299
+ ? set
300
+ : b.arrow([b.id('$$value'), ...ids], set);
301
+
302
+ return b.call('$.bind_this', value, set, get, values.length > 0 && b.thunk(b.array(values)));
285
303
  }
286
304
 
287
305
  /**
@@ -32,7 +32,9 @@ export function EachBlock(node, context) {
32
32
  each.push(b.let(node.index, index));
33
33
  }
34
34
 
35
- each.push(.../** @type {BlockStatement} */ (context.visit(node.body)).body);
35
+ const new_body = /** @type {BlockStatement} */ (context.visit(node.body)).body;
36
+
37
+ each.push(...(node.body.metadata.has_await ? [create_async_block(b.block(new_body))] : new_body));
36
38
 
37
39
  const for_loop = b.for(
38
40
  b.declaration('let', [
@@ -55,7 +57,7 @@ export function EachBlock(node, context) {
55
57
  b.if(
56
58
  b.binary('!==', b.member(array_id, 'length'), b.literal(0)),
57
59
  b.block([open, for_loop]),
58
- fallback
60
+ node.fallback.metadata.has_await ? create_async_block(fallback) : fallback
59
61
  )
60
62
  );
61
63
  } else {
@@ -43,11 +43,14 @@ export function SvelteBoundary(node, context) {
43
43
  );
44
44
  const pending = b.call(callee, b.id('$$renderer'));
45
45
  const block = /** @type {BlockStatement} */ (context.visit(node.fragment));
46
+ const statement = node.fragment.metadata.has_await
47
+ ? create_async_block(b.block([block]))
48
+ : block;
46
49
  context.state.template.push(
47
50
  b.if(
48
51
  callee,
49
- b.block(build_template([block_open_else, pending, block_close])),
50
- b.block(build_template([block_open, block, block_close]))
52
+ b.block([b.stmt(pending)]),
53
+ b.block(build_template([block_open, statement, block_close]))
51
54
  )
52
55
  );
53
56
  } else {
@@ -43,14 +43,22 @@ export function bind_value(input, get, set = get) {
43
43
  if (value !== (value = get())) {
44
44
  var start = input.selectionStart;
45
45
  var end = input.selectionEnd;
46
+ var length = input.value.length;
46
47
 
47
48
  // the value is coerced on assignment
48
49
  input.value = value ?? '';
49
50
 
50
51
  // Restore selection
51
52
  if (end !== null) {
52
- input.selectionStart = start;
53
- input.selectionEnd = Math.min(end, input.value.length);
53
+ var new_length = input.value.length;
54
+ // If cursor was at end and new input is longer, move cursor to new end
55
+ if (start === end && end === length && new_length > length) {
56
+ input.selectionStart = new_length;
57
+ input.selectionEnd = new_length;
58
+ } else {
59
+ input.selectionStart = start;
60
+ input.selectionEnd = Math.min(end, new_length);
61
+ }
54
62
  }
55
63
  }
56
64
  });
package/src/version.js CHANGED
@@ -4,5 +4,5 @@
4
4
  * The current version, as set in package.json.
5
5
  * @type {string}
6
6
  */
7
- export const VERSION = '5.39.11';
7
+ export const VERSION = '5.39.12';
8
8
  export const PUBLIC_VERSION = '5';