svelte 5.57.2 → 5.58.0

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.
Files changed (66) hide show
  1. package/README.md +1 -1
  2. package/compiler/index.js +1 -1
  3. package/elements.d.ts +1 -2
  4. package/package.json +2 -2
  5. package/src/compiler/phases/1-parse/acorn.js +4 -14
  6. package/src/compiler/phases/1-parse/index.js +8 -1
  7. package/src/compiler/phases/1-parse/read/context.js +3 -2
  8. package/src/compiler/phases/1-parse/read/expression.js +2 -4
  9. package/src/compiler/phases/1-parse/utils/bracket.js +6 -0
  10. package/src/compiler/phases/2-analyze/css/css-prune.js +0 -8
  11. package/src/compiler/phases/2-analyze/index.js +2 -1
  12. package/src/compiler/phases/2-analyze/visitors/AwaitExpression.js +17 -15
  13. package/src/compiler/phases/2-analyze/visitors/shared/a11y/index.js +30 -5
  14. package/src/compiler/phases/3-transform/client/transform-template/index.js +27 -9
  15. package/src/compiler/phases/3-transform/client/visitors/EachBlock.js +1 -1
  16. package/src/compiler/phases/3-transform/client/visitors/Fragment.js +13 -1
  17. package/src/compiler/phases/3-transform/client/visitors/HtmlTag.js +10 -2
  18. package/src/compiler/phases/3-transform/client/visitors/RegularElement.js +11 -2
  19. package/src/compiler/phases/3-transform/client/visitors/RenderTag.js +15 -7
  20. package/src/compiler/phases/3-transform/client/visitors/SlotElement.js +19 -1
  21. package/src/compiler/phases/3-transform/client/visitors/SvelteComponent.js +0 -1
  22. package/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js +1 -1
  23. package/src/compiler/phases/3-transform/client/visitors/shared/element.js +1 -1
  24. package/src/compiler/phases/3-transform/client/visitors/shared/events.js +1 -1
  25. package/src/compiler/phases/3-transform/client/visitors/shared/utils.js +1 -1
  26. package/src/compiler/phases/3-transform/server/visitors/Fragment.js +6 -1
  27. package/src/compiler/phases/3-transform/server/visitors/TitleElement.js +1 -1
  28. package/src/compiler/phases/3-transform/server/visitors/shared/element.js +2 -1
  29. package/src/compiler/phases/3-transform/server/visitors/shared/utils.js +1 -1
  30. package/src/compiler/phases/patterns.js +0 -1
  31. package/src/compiler/print/index.js +4 -16
  32. package/src/compiler/state.js +1 -1
  33. package/src/compiler/utils/builders.js +0 -1
  34. package/src/compiler/utils/mapped_code.js +1 -12
  35. package/src/constants.js +0 -8
  36. package/src/internal/client/dev/debug.js +14 -0
  37. package/src/internal/client/dev/elements.js +25 -9
  38. package/src/internal/client/dom/blocks/await.js +1 -2
  39. package/src/internal/client/dom/blocks/boundary.js +4 -7
  40. package/src/internal/client/dom/blocks/branches.js +2 -1
  41. package/src/internal/client/dom/blocks/html.js +44 -10
  42. package/src/internal/client/dom/blocks/slot.js +19 -1
  43. package/src/internal/client/dom/blocks/snippet.js +13 -0
  44. package/src/internal/client/dom/blocks/svelte-component.js +1 -1
  45. package/src/internal/client/dom/blocks/svelte-element.js +2 -1
  46. package/src/internal/client/dom/elements/attributes.js +12 -4
  47. package/src/internal/client/dom/elements/bindings/select.js +2 -1
  48. package/src/internal/client/dom/hydration.js +4 -1
  49. package/src/internal/client/dom/template.js +0 -1
  50. package/src/internal/client/proxy.js +2 -1
  51. package/src/internal/client/reactivity/async.js +2 -1
  52. package/src/internal/client/reactivity/batch.js +84 -127
  53. package/src/internal/client/reactivity/deriveds.js +2 -1
  54. package/src/internal/client/reactivity/equality.js +0 -9
  55. package/src/internal/client/reactivity/props.js +0 -1
  56. package/src/internal/client/reactivity/sources.js +5 -3
  57. package/src/internal/client/reactivity/utils.js +5 -6
  58. package/src/internal/server/errors.js +2 -2
  59. package/src/internal/server/renderer.js +52 -118
  60. package/src/internal/shared/utils.js +12 -0
  61. package/src/motion/spring.js +1 -1
  62. package/src/motion/tweened.js +1 -1
  63. package/src/reactivity/create-subscriber.js +1 -1
  64. package/src/version.js +1 -1
  65. package/types/index.d.ts +2 -2
  66. package/types/index.d.ts.map +1 -1
package/elements.d.ts CHANGED
@@ -752,6 +752,7 @@ export interface HTMLAttributes<T extends EventTarget> extends AriaAttributes, D
752
752
  // Standard HTML Attributes
753
753
  accesskey?: string | undefined | null;
754
754
  autocapitalize?: 'characters' | 'off' | 'on' | 'none' | 'sentences' | 'words' | undefined | null;
755
+ autocorrect?: 'on' | 'off' | '' | undefined | null;
755
756
  autofocus?: boolean | undefined | null;
756
757
  class?: ClassValue | undefined | null;
757
758
  contenteditable?: Booleanish | 'inherit' | 'plaintext-only' | undefined | null;
@@ -1077,8 +1078,6 @@ export interface HTMLInputAttributes extends HTMLAttributes<HTMLInputElement> {
1077
1078
  accept?: string | undefined | null;
1078
1079
  alt?: string | undefined | null;
1079
1080
  autocomplete?: FullAutoFill | undefined | null;
1080
- // Safari only https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocorrect
1081
- autocorrect?: 'on' | 'off' | '' | undefined | null;
1082
1081
  capture?: boolean | 'user' | 'environment' | undefined | null; // https://www.w3.org/TR/html-media-capture/#the-capture-attribute
1083
1082
  checked?: boolean | undefined | null;
1084
1083
  dirname?: string | undefined | null;
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.57.2",
5
+ "version": "5.58.0",
6
6
  "type": "module",
7
7
  "types": "./types/index.d.ts",
8
8
  "engines": {
@@ -168,7 +168,7 @@
168
168
  "clsx": "^2.1.1",
169
169
  "devalue": "^5.9.2",
170
170
  "esm-env": "^1.2.1",
171
- "esrap": "^2.3.6",
171
+ "esrap": "^2.4.2",
172
172
  "is-reference": "^3.0.3",
173
173
  "locate-character": "^3.0.0",
174
174
  "magic-string": "^0.30.11",
@@ -138,28 +138,21 @@ export function parse_statement_at(parser, source, index) {
138
138
 
139
139
  const regex_non_lf_line_break = /\r(?!\n)|[\u2028\u2029]/;
140
140
 
141
- let last_template = '';
142
- let lf_only = true;
143
-
144
141
  /**
145
142
  * Without `startLocation`, acorn counts the lines before `index` on every call
146
143
  * @param {Parser} parser
147
144
  * @param {number} index
148
145
  */
149
146
  function start_location(parser, index) {
150
- return has_lf_line_breaks_only(parser) ? locator(index) : undefined;
147
+ return parser.lf_only ? locator(index) : undefined;
151
148
  }
152
149
 
153
150
  /**
154
151
  * acorn breaks lines on bare `\r`, `\u2028` and `\u2029`, which the locator doesn't
155
- * @param {Parser} parser
152
+ * @param {string} template
156
153
  */
157
- export function has_lf_line_breaks_only(parser) {
158
- if (parser.template !== last_template) {
159
- last_template = parser.template;
160
- lf_only = !regex_non_lf_line_break.test(last_template);
161
- }
162
- return lf_only;
154
+ export function has_lf_line_breaks_only(template) {
155
+ return !regex_non_lf_line_break.test(template);
163
156
  }
164
157
 
165
158
  const regex_position_indicator = / \(\d+:\d+\)$/;
@@ -261,15 +254,12 @@ function get_comment_handlers(source, comments, index = 0) {
261
254
  if (is_last_in_body) {
262
255
  // Special case: There can be multiple trailing comments after the last node in a block,
263
256
  // and they can be separated by newlines
264
- let end = node.end;
265
-
266
257
  while (comments.length) {
267
258
  const comment = comments[0];
268
259
  if (parent && comment.start >= parent.end) break;
269
260
 
270
261
  (node.trailingComments ||= []).push(comment);
271
262
  comments.shift();
272
- end = comment.end;
273
263
  }
274
264
  } else if (node.end <= comments[0].start && /^[,) \t]*$/.test(slice)) {
275
265
  node.trailingComments = [/** @type {CommentWithLocation} */ (comments.shift())];
@@ -10,6 +10,7 @@ import read_options from './read/options.js';
10
10
  import { is_reserved } from '../../../utils.js';
11
11
  import * as state from '../../state.js';
12
12
  import { is_whitespace } from './utils/whitespace.js';
13
+ import { has_lf_line_breaks_only } from './acorn.js';
13
14
 
14
15
  const regex_lang_attribute =
15
16
  /<!--[^]*?-->|<script\s+(?:[^>]*|(?:[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)\s+)*)lang=(["'])?([^"' >]+)\1[^>]*>/g;
@@ -31,6 +32,12 @@ export class Parser {
31
32
  /** */
32
33
  index = 0;
33
34
 
35
+ /**
36
+ * @readonly
37
+ * @type {boolean}
38
+ */
39
+ lf_only;
40
+
34
41
  /** @type {AST.CSS.CSSComment[]} */
35
42
  css_comments = [];
36
43
 
@@ -78,6 +85,7 @@ export class Parser {
78
85
 
79
86
  this.loose = loose;
80
87
  this.template = template.trimEnd();
88
+ this.lf_only = has_lf_line_breaks_only(this.template);
81
89
 
82
90
  let match_lang;
83
91
 
@@ -229,7 +237,6 @@ export class Parser {
229
237
  const code = /** @type {number} */ (this.template.codePointAt(this.index));
230
238
 
231
239
  if (isIdentifierStart(code, true)) {
232
- let i = this.index;
233
240
  end += code <= 0xffff ? 1 : 2;
234
241
 
235
242
  while (end < this.template.length) {
@@ -69,8 +69,9 @@ function read_type_annotation(parser) {
69
69
  insert +
70
70
  // If this is a type annotation for a function parameter, Acorn-TS will treat subsequent
71
71
  // parameters as part of a sequence expression instead, and will then error on optional
72
- // parameters (`?:`). Therefore replace that sequence with something that will not error.
73
- parser.template.slice(parser.index).replace(/\?\s*:/g, ':');
72
+ // parameters (`?:`). Therefore replace that sequence with something that will not error,
73
+ // keeping the length so that positions still line up with the template.
74
+ parser.template.slice(parser.index).replace(/\?(?=\s*:)/g, ' ');
74
75
  let expression = remove_parens(parse_expression_at(parser, template, a));
75
76
 
76
77
  // `foo: bar = baz` gets mangled — fix it
@@ -2,9 +2,7 @@
2
2
  /** @import { Parser } from '../index.js' */
3
3
  // @ts-expect-error acorn type definitions are borked in the release we use
4
4
  import { isIdentifierStart, isIdentifierChar } from 'acorn';
5
- import { has_lf_line_breaks_only, parse_expression_at, remove_parens } from '../acorn.js';
6
- import { regex_whitespace } from '../../patterns.js';
7
- import * as e from '../../../errors.js';
5
+ import { parse_expression_at, remove_parens } from '../acorn.js';
8
6
  import { find_matching_bracket } from '../utils/bracket.js';
9
7
  import { is_reserved } from '../../../../utils.js';
10
8
  import { locator } from '../../../state.js';
@@ -72,7 +70,7 @@ export default function read_expression(parser, opening_token, disallow_loose) {
72
70
  * @returns {Expression | null}
73
71
  */
74
72
  function read_simple_expression(parser) {
75
- if (!has_lf_line_breaks_only(parser)) return null;
73
+ if (!parser.lf_only) return null;
76
74
 
77
75
  const template = parser.template;
78
76
  const index = parser.index;
@@ -173,6 +173,12 @@ export function match_bracket(parser, start, brackets = default_brackets) {
173
173
  continue;
174
174
  }
175
175
 
176
+ // the `>` in an arrow function type (e.g. `T extends () => void`) doesn't close
177
+ // the type parameter list
178
+ if (char === '>' && close.has('>') && parser.template[i - 2] === '=') {
179
+ continue;
180
+ }
181
+
176
182
  if (char in brackets) {
177
183
  bracket_stack.push(char);
178
184
  } else if (close.has(char)) {
@@ -116,12 +116,6 @@ const any_selector = {
116
116
  }
117
117
  };
118
118
 
119
- /**
120
- * Snippets encountered already (avoids infinite loops)
121
- * @type {Set<Compiler.AST.SnippetBlock>}
122
- */
123
- const seen = new Set();
124
-
125
119
  /**
126
120
  * @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.RenderTag | Compiler.AST.Component | Compiler.AST.SvelteComponent | Compiler.AST.SvelteSelf} node
127
121
  */
@@ -153,8 +147,6 @@ export function prune(stylesheet, elements) {
153
147
  }
154
148
 
155
149
  for (const element of elements) {
156
- seen.clear();
157
-
158
150
  if (
159
151
  // Elements rendered through <svelte:head> are not style-scopable.
160
152
  // Prevent css hash injection (class="s-...") on tags like <meta>, <link>, <script>.
@@ -2,6 +2,7 @@
2
2
  /** @import { Binding, AST, ValidatedCompileOptions, ValidatedModuleCompileOptions } from '#compiler' */
3
3
  /** @import { AnalysisState, Visitors } from './types' */
4
4
  /** @import { Analysis, ComponentAnalysis, Js, ReactiveStatement, Template } from '../types' */
5
+ /** @import { Scope } from '../scope.js' */
5
6
  import { walk } from 'zimmerframe';
6
7
  import { parse } from '../1-parse/acorn.js';
7
8
  import * as e from '../../errors.js';
@@ -13,7 +14,7 @@ import {
13
14
  unwrap_pattern
14
15
  } from '../../utils/ast.js';
15
16
  import * as b from '#compiler/builders';
16
- import { Scope, ScopeRoot, create_scopes, get_rune, set_scope } from '../scope.js';
17
+ import { ScopeRoot, create_scopes, get_rune, set_scope } from '../scope.js';
17
18
  import check_graph_for_cycles from '../../utils/check_graph_for_cycles.js';
18
19
  import { create_attribute, is_custom_element_node } from '../nodes.js';
19
20
  import { analyze_css } from './css/css-analyze.js';
@@ -11,21 +11,15 @@ import * as e from '../../../errors.js';
11
11
  export function AwaitExpression(node, context) {
12
12
  const tla = context.state.ast_type === 'instance' && context.state.function_depth === 1;
13
13
 
14
- if (
15
- is_reactive_expression(
16
- context.path,
17
- context.state.derived_function_depth === context.state.function_depth
18
- )
19
- ) {
20
- const expression = /** @type {ExpressionMetadata} */ (context.state.expression);
21
-
22
- // preserve context for awaits that precede other expressions in template or `$derived(...)`,
23
- // and for any await that follows one, so the restored context ends at the next suspension
24
- if (expression.has_pickled_await || !is_last_evaluated_expression(context.path, node)) {
25
- context.state.analysis.pickled_awaits.add(node);
26
- expression.has_pickled_await = true;
27
- }
28
- }
14
+ /** @type {ExpressionMetadata | null} */
15
+ var reactive = is_reactive_expression(
16
+ context.path,
17
+ context.state.derived_function_depth === context.state.function_depth
18
+ )
19
+ ? /** @type {ExpressionMetadata} */ (context.state.expression)
20
+ : null;
21
+
22
+ var last = reactive !== null && is_last_evaluated_expression(context.path, node);
29
23
 
30
24
  let suspend = tla;
31
25
 
@@ -48,6 +42,14 @@ export function AwaitExpression(node, context) {
48
42
  }
49
43
 
50
44
  context.next();
45
+
46
+ // Preserve context for awaits that precede other expressions in template or `$derived(...)`, and for any await
47
+ // that follows one, so the restored context ends at the next suspension. (Decided after visiting the argument:
48
+ // an await inside it, as in `await f(await g())`, suspends before this one does)
49
+ if (reactive !== null && (reactive.has_pickled_await || !last)) {
50
+ context.state.analysis.pickled_awaits.add(node);
51
+ reactive.has_pickled_await = true;
52
+ }
51
53
  }
52
54
 
53
55
  /**
@@ -40,7 +40,8 @@ import {
40
40
  regex_not_whitespace,
41
41
  regex_redundant_img_alt,
42
42
  regex_starts_with_vowel,
43
- regex_whitespaces
43
+ regex_whitespaces,
44
+ regex_whitespaces_strict
44
45
  } from '../../../../patterns.js';
45
46
  import { is_event_attribute, is_text_attribute } from '../../../../../utils/ast.js';
46
47
  import { list } from '../../../../../utils/string.js';
@@ -158,9 +159,7 @@ export function check_element(node, context) {
158
159
  if (typeof value !== 'string') {
159
160
  break;
160
161
  }
161
- for (const c_r of value.split(regex_whitespaces)) {
162
- const current_role = /** @type {ARIARoleDefinitionKey} current_role */ (c_r);
163
-
162
+ for (const current_role of get_role_tokens(value)) {
164
163
  if (current_role && is_abstract_role(current_role)) {
165
164
  w.a11y_no_abstract_role(attribute, current_role);
166
165
  } else if (current_role && !aria_roles.includes(current_role)) {
@@ -286,7 +285,9 @@ export function check_element(node, context) {
286
285
  }
287
286
 
288
287
  const role = attribute_map.get('role');
289
- const role_static_value = /** @type {ARIARoleDefinitionKey} */ (get_static_text_value(role));
288
+ const role_static_value = /** @type {ARIARoleDefinitionKey} */ (
289
+ get_effective_role(get_static_text_value(role))
290
+ );
290
291
 
291
292
  // click-events-have-key-events
292
293
  if (handlers.has('click')) {
@@ -778,6 +779,30 @@ function is_abstract_role(role) {
778
779
  return abstract_roles.includes(role);
779
780
  }
780
781
 
782
+ /**
783
+ * Role tokens use ASCII whitespace and ASCII case-insensitive matching.
784
+ * @param {string} value
785
+ */
786
+ function get_role_tokens(value) {
787
+ return /** @type {ARIARoleDefinitionKey[]} */ (
788
+ // we use this instead of value.toLowerCase() to avoid lowercasing non-ASCII characters
789
+ value.replace(/[A-Z]/g, (char) => char.toLowerCase()).split(regex_whitespaces_strict)
790
+ );
791
+ }
792
+
793
+ /**
794
+ * The `role` attribute can list fallback roles, in which case the element
795
+ * gets the first one that is a known, non-abstract role. Preserve the original
796
+ * value if none match, so invalid roles retain their existing diagnostics.
797
+ * @param {string | null} value
798
+ */
799
+ function get_effective_role(value) {
800
+ if (value === null) return null;
801
+ const roles = get_role_tokens(value);
802
+ // we return the whole value here in case there's no known, non-abstract role in the list
803
+ return roles.find((role) => aria_roles.includes(role) && !is_abstract_role(role)) ?? value;
804
+ }
805
+
781
806
  /**
782
807
  * @param {AST.Attribute | undefined} attribute
783
808
  */
@@ -1,4 +1,4 @@
1
- /** @import { TemplateLiteral } from 'estree' */
1
+ /** @import { Expression, Statement, TemplateLiteral } from 'estree' */
2
2
  /** @import { Namespace } from '#compiler' */
3
3
  /** @import { ComponentClientTransformState } from '../types.js' */
4
4
  /** @import { Node } from './types.js' */
@@ -30,6 +30,21 @@ function build_locations(nodes) {
30
30
  return array;
31
31
  }
32
32
 
33
+ /**
34
+ * In dev, returns a statement that assigns source locations after the template's content has been
35
+ * hydrated. Child components, snippets and `{@html ...}` tags then have their own locations, so we
36
+ * can skip their elements.
37
+ * @param {ComponentClientTransformState} state
38
+ * @param {Expression} template_name
39
+ * @param {Expression} node
40
+ * @returns {Statement | undefined}
41
+ */
42
+ export function build_hydration_locations_statement(state, template_name, node) {
43
+ if (dev && state.template.nodes.some((node) => node.type === 'element')) {
44
+ return b.stmt(b.call(b.member(template_name, 'hydrate_assign_locations'), node));
45
+ }
46
+ }
47
+
33
48
  /**
34
49
  * @param {ComponentClientTransformState} state
35
50
  * @param {string} name
@@ -77,12 +92,16 @@ export function transform_template(state, name, flags = 0) {
77
92
  }
78
93
 
79
94
  if (dev) {
80
- call = b.call(
81
- '$.add_locations',
82
- call,
83
- b.member(b.id(state.analysis.name), '$.FILENAME', true),
84
- build_locations(state.template.nodes)
85
- );
95
+ const locations = build_locations(nodes);
96
+
97
+ if (locations.elements.length > 0) {
98
+ call = b.call(
99
+ '$.add_locations',
100
+ call,
101
+ b.member(b.id(state.analysis.name), '$.FILENAME', true),
102
+ locations
103
+ );
104
+ }
86
105
  }
87
106
 
88
107
  const id = state.scope.root.unique(name);
@@ -98,8 +117,7 @@ export function transform_template(state, name, flags = 0) {
98
117
  /**
99
118
  * Returns a stable key for templates that are safe to deduplicate - plain
100
119
  * `$.from_html`/`from_svg`/`from_mathml` factories with literal arguments - or `null`
101
- * for anything else. Dev-mode templates are wrapped in `$.add_locations(...)`, which
102
- * embeds per-call-site locations, so they never produce a key and are never shared.
120
+ * for anything else.
103
121
  * @param {TemplateLiteral} template
104
122
  * @param {Namespace} namespace
105
123
  * @param {number} flags
@@ -10,7 +10,7 @@ import {
10
10
  EACH_ITEM_REACTIVE
11
11
  } from '../../../../../constants.js';
12
12
  import { dev } from '../../../../state.js';
13
- import { extract_paths, object } from '../../../../utils/ast.js';
13
+ import { extract_paths } from '../../../../utils/ast.js';
14
14
  import * as b from '#compiler/builders';
15
15
  import { async_thunk } from '../utils.js';
16
16
  import { get_value } from './shared/declarations.js';
@@ -4,7 +4,10 @@
4
4
  import * as b from '#compiler/builders';
5
5
  import { TEMPLATE_FRAGMENT, TEMPLATE_USE_IMPORT_NODE } from '../../../../../constants.js';
6
6
  import { clean_nodes, infer_namespace } from '../../utils.js';
7
- import { transform_template } from '../transform-template/index.js';
7
+ import {
8
+ build_hydration_locations_statement,
9
+ transform_template
10
+ } from '../transform-template/index.js';
8
11
  import { Template } from '../transform-template/template.js';
9
12
  import { process_children } from './shared/fragment.js';
10
13
  import { build_render_statement, Memoizer } from './shared/utils.js';
@@ -59,6 +62,9 @@ export function Fragment(node, context) {
59
62
  /** @type {Statement | undefined} */
60
63
  let close = undefined;
61
64
 
65
+ /** @type {Statement | undefined} */
66
+ let hydrate_locations = undefined;
67
+
62
68
  /** @type {ComponentClientTransformState} */
63
69
  const state = {
64
70
  ...context.state,
@@ -97,6 +103,7 @@ export function Fragment(node, context) {
97
103
 
98
104
  const template_name = transform_template(state, 'root', flags);
99
105
 
106
+ hydrate_locations = build_hydration_locations_statement(state, template_name, id);
100
107
  state.init.unshift(b.var(id, b.call(template_name)));
101
108
  close = b.stmt(b.call('$.append', b.id('$$anchor'), id));
102
109
  } else if (is_single_child_not_needing_template) {
@@ -143,6 +150,7 @@ export function Fragment(node, context) {
143
150
 
144
151
  const template_name = transform_template(state, 'root', flags);
145
152
 
153
+ hydrate_locations = build_hydration_locations_statement(state, template_name, id);
146
154
  state.init.unshift(b.var(id, b.call(template_name)));
147
155
 
148
156
  close = b.stmt(b.call('$.append', b.id('$$anchor'), id));
@@ -168,6 +176,10 @@ export function Fragment(node, context) {
168
176
 
169
177
  body.push(...state.after_update);
170
178
 
179
+ if (hydrate_locations !== undefined) {
180
+ body.push(hydrate_locations);
181
+ }
182
+
171
183
  if (close !== undefined) {
172
184
  // It's important that close is the last statement in the block, as any previous statements
173
185
  // could contain element insertions into the template, which the close statement needs to
@@ -1,6 +1,6 @@
1
1
  /** @import { AST } from '#compiler' */
2
2
  /** @import { ComponentContext } from '../types' */
3
- import { is_ignored } from '../../../../state.js';
3
+ import { dev, is_ignored, locator } from '../../../../state.js';
4
4
  import * as b from '#compiler/builders';
5
5
  import { async_thunk } from '../utils.js';
6
6
  import { build_expression } from './shared/utils.js';
@@ -27,6 +27,8 @@ export function HtmlTag(node, context) {
27
27
  const is_svg = !is_controlled && context.state.metadata.namespace === 'svg';
28
28
  const is_mathml = !is_controlled && context.state.metadata.namespace === 'mathml';
29
29
 
30
+ const location = dev && locator(node.start);
31
+
30
32
  const statement = b.stmt(
31
33
  b.call(
32
34
  '$.html',
@@ -35,7 +37,13 @@ export function HtmlTag(node, context) {
35
37
  is_controlled && b.true,
36
38
  is_svg && b.true,
37
39
  is_mathml && b.true,
38
- is_ignored(node, 'hydration_html_changed') && b.true
40
+ is_ignored(node, 'hydration_html_changed') && b.true,
41
+ location &&
42
+ b.array([
43
+ b.member(b.id(context.state.analysis.name), '$.FILENAME', true),
44
+ b.literal(location.line),
45
+ b.literal(location.column)
46
+ ])
39
47
  )
40
48
  );
41
49
 
@@ -28,7 +28,10 @@ import { process_children, is_static_element } from './shared/fragment.js';
28
28
  import { build_render_statement, build_template_chunk, Memoizer } from './shared/utils.js';
29
29
  import { visit_event_attribute } from './shared/events.js';
30
30
  import { Template } from '../transform-template/template.js';
31
- import { transform_template } from '../transform-template/index.js';
31
+ import {
32
+ build_hydration_locations_statement,
33
+ transform_template
34
+ } from '../transform-template/index.js';
32
35
  import { TEMPLATE_FRAGMENT } from '../../../../../constants.js';
33
36
 
34
37
  /**
@@ -402,8 +405,13 @@ export function RegularElement(node, context) {
402
405
  }
403
406
  );
404
407
 
405
- // Transform the template to $.from_html(...) and hoist it (deduplicating identical templates)
408
+ // Transform the template to $.from_html(...) and hoist it (deduplicating in production)
406
409
  const template_name = transform_template(select_state, `${name}_content`, TEMPLATE_FRAGMENT);
410
+ const hydrate_locations = build_hydration_locations_statement(
411
+ select_state,
412
+ template_name,
413
+ fragment_id
414
+ );
407
415
 
408
416
  // Build the rich content function body
409
417
  // The anchor is the child of the element (a hydration marker during hydration)
@@ -413,6 +421,7 @@ export function RegularElement(node, context) {
413
421
  ...select_state.init,
414
422
  ...(select_state.update.length > 0 ? [build_render_statement(select_state)] : []),
415
423
  ...select_state.after_update,
424
+ ...(hydrate_locations ? [hydrate_locations] : []),
416
425
  b.stmt(b.call('$.append', anchor_id, fragment_id))
417
426
  ]);
418
427
 
@@ -4,6 +4,7 @@
4
4
  import { unwrap_optional } from '../../../../utils/ast.js';
5
5
  import * as b from '#compiler/builders';
6
6
  import { add_svelte_meta, build_expression, Memoizer } from './shared/utils.js';
7
+ import { source } from '../../../../state.js';
7
8
 
8
9
  /**
9
10
  * @param {AST.RenderTag} node
@@ -37,11 +38,16 @@ export function RenderTag(node, context) {
37
38
  /** @type {Statement[]} */
38
39
  const statements = memoizer.deriveds(context.state.analysis.runes);
39
40
 
40
- let snippet_function = build_expression(
41
- context,
42
- /** @type {Expression} */ (call.callee),
43
- node.metadata.expression
44
- );
41
+ const callee = /** @type {Expression} */ (call.callee);
42
+
43
+ let snippet_function = build_expression(context, callee, node.metadata.expression);
44
+
45
+ const meta = {
46
+ snippetName: source.slice(
47
+ /** @type {number} */ (callee.start),
48
+ /** @type {number} */ (callee.end)
49
+ )
50
+ };
45
51
 
46
52
  if (node.metadata.dynamic) {
47
53
  // If we have a chain expression then ensure a nullish snippet function gets turned into an empty one
@@ -53,7 +59,8 @@ export function RenderTag(node, context) {
53
59
  add_svelte_meta(
54
60
  b.call('$.snippet', context.state.node, b.thunk(snippet_function), ...args),
55
61
  node,
56
- 'render'
62
+ 'render',
63
+ meta
57
64
  )
58
65
  );
59
66
  } else {
@@ -65,7 +72,8 @@ export function RenderTag(node, context) {
65
72
  ...args
66
73
  ),
67
74
  node,
68
- 'render'
75
+ 'render',
76
+ meta
69
77
  )
70
78
  );
71
79
  }
@@ -1,6 +1,7 @@
1
1
  /** @import { BlockStatement, Expression, ExpressionStatement, Literal, Property, Statement } from 'estree' */
2
2
  /** @import { AST } from '#compiler' */
3
3
  /** @import { ComponentContext } from '../types' */
4
+ import { dev, locator } from '../../../../state.js';
4
5
  import * as b from '#compiler/builders';
5
6
  import { build_attribute_value } from './shared/element.js';
6
7
  import { Memoizer } from './shared/utils.js';
@@ -69,8 +70,25 @@ export function SlotElement(node, context) {
69
70
  ? b.null
70
71
  : b.arrow([b.id('$$anchor')], /** @type {BlockStatement} */ (context.visit(node.fragment)));
71
72
 
73
+ const location = dev && locator(node.start);
74
+
72
75
  statements.push(
73
- b.stmt(b.call('$.slot', context.state.node, b.id('$$props'), name, props_expression, fallback))
76
+ b.stmt(
77
+ b.call(
78
+ '$.slot',
79
+ context.state.node,
80
+ b.id('$$props'),
81
+ name,
82
+ props_expression,
83
+ fallback,
84
+ location &&
85
+ b.array([
86
+ b.member(b.id(context.state.analysis.name), '$.FILENAME', true),
87
+ b.literal(location.line),
88
+ b.literal(location.column)
89
+ ])
90
+ )
91
+ )
74
92
  );
75
93
 
76
94
  const async_values = memoizer.async_values();
@@ -1,7 +1,6 @@
1
1
  /** @import { AST } from '#compiler' */
2
2
  /** @import { ComponentContext } from '../types' */
3
3
  import { build_component } from './shared/component.js';
4
- import * as b from '#compiler/builders';
5
4
 
6
5
  /**
7
6
  * @param {AST.SvelteComponent} node
@@ -2,7 +2,7 @@
2
2
  /** @import { Binding } from '#compiler' */
3
3
  /** @import { ComponentContext } from '../types' */
4
4
  import { dev, is_ignored, locate_node } from '../../../../state.js';
5
- import { extract_paths, save } from '../../../../utils/ast.js';
5
+ import { extract_paths } from '../../../../utils/ast.js';
6
6
  import * as b from '#compiler/builders';
7
7
  import * as assert from '../../../../utils/assert.js';
8
8
  import { get_rune, should_proxy } from '../../../scope.js';
@@ -1,6 +1,7 @@
1
1
  /** @import { Expression, Identifier, ObjectExpression } from 'estree' */
2
2
  /** @import { AST } from '#compiler' */
3
3
  /** @import { ComponentContext } from '../../types' */
4
+ /** @import { ExpressionMetadata } from '../../../../nodes.js' */
4
5
  import { escape_html } from '../../../../../../escaping.js';
5
6
  import { normalize_attribute } from '../../../../../../utils.js';
6
7
  import { is_ignored } from '../../../../../state.js';
@@ -8,7 +9,6 @@ import { is_event_attribute } from '../../../../../utils/ast.js';
8
9
  import * as b from '#compiler/builders';
9
10
  import { build_class_directives_object, build_style_directives_object } from '../RegularElement.js';
10
11
  import { build_expression, build_template_chunk, Memoizer } from './utils.js';
11
- import { ExpressionMetadata } from '../../../../nodes.js';
12
12
 
13
13
  /**
14
14
  * @param {Array<AST.Attribute | AST.SpreadAttribute>} attributes
@@ -1,10 +1,10 @@
1
1
  /** @import { Expression } from 'estree' */
2
2
  /** @import { AST } from '#compiler' */
3
3
  /** @import { ComponentContext } from '../../types' */
4
+ /** @import { ExpressionMetadata } from '../../../../nodes.js' */
4
5
  import { is_capture_event, is_passive_event } from '../../../../../../utils.js';
5
6
  import { dev, locator } from '../../../../../state.js';
6
7
  import * as b from '#compiler/builders';
7
- import { ExpressionMetadata } from '../../../../nodes.js';
8
8
 
9
9
  /**
10
10
  * @param {AST.Attribute} node
@@ -1,6 +1,7 @@
1
1
  /** @import { AssignmentExpression, Expression, Identifier, MemberExpression, SequenceExpression, Literal, Super, UpdateExpression, ExpressionStatement } from 'estree' */
2
2
  /** @import { AST } from '#compiler' */
3
3
  /** @import { ComponentClientTransformState, ComponentContext, Context } from '../../types' */
4
+ /** @import { ExpressionMetadata } from '../../../../nodes.js' */
4
5
  import { walk } from 'zimmerframe';
5
6
  import { object } from '../../../../../utils/ast.js';
6
7
  import * as b from '#compiler/builders';
@@ -9,7 +10,6 @@ import { regex_is_valid_identifier } from '../../../../patterns.js';
9
10
  import is_reference from 'is-reference';
10
11
  import { dev, is_ignored, locator, component_name } from '../../../../../state.js';
11
12
  import { async_thunk, build_getter, is_state_source } from '../../utils.js';
12
- import { ExpressionMetadata } from '../../../../nodes.js';
13
13
 
14
14
  /**
15
15
  * A utility for extracting complex expressions (such as call expressions)