svelte-effect-runtime 4.0.0 → 4.0.1

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 (146) hide show
  1. package/.dist/chunks/client-BrZka6DW.js +530 -0
  2. package/.dist/chunks/client-BrZka6DW.js.map +1 -0
  3. package/.dist/chunks/compiler-COVzgLYo.js +412 -0
  4. package/.dist/chunks/compiler-COVzgLYo.js.map +1 -0
  5. package/.dist/chunks/descriptors-B4otDlm1.js +216 -0
  6. package/.dist/chunks/descriptors-B4otDlm1.js.map +1 -0
  7. package/.dist/chunks/diagnostics-BDrky-Di.js +359 -0
  8. package/.dist/chunks/diagnostics-BDrky-Di.js.map +1 -0
  9. package/.dist/chunks/dispatcher-BA0PLQhA.js +16 -0
  10. package/.dist/chunks/dispatcher-BA0PLQhA.js.map +1 -0
  11. package/.dist/chunks/{dispatcher-DOx8iC6r.js → dispatcher-_x0MQZBS.js} +84 -258
  12. package/.dist/chunks/dispatcher-_x0MQZBS.js.map +1 -0
  13. package/.dist/chunks/{errors-IJjsUwrE.js → errors-CLsbGjIa.js} +39 -44
  14. package/.dist/chunks/errors-CLsbGjIa.js.map +1 -0
  15. package/.dist/chunks/live-BundLSoY.js +146 -0
  16. package/.dist/chunks/live-BundLSoY.js.map +1 -0
  17. package/.dist/chunks/live-CHK0RrZu.js +10 -0
  18. package/.dist/chunks/live-CHK0RrZu.js.map +1 -0
  19. package/.dist/chunks/{remote-client-CVI4t66c.js → remote-client-mkQAfP1G.js} +29 -23
  20. package/.dist/chunks/remote-client-mkQAfP1G.js.map +1 -0
  21. package/.dist/chunks/{runtime-GBQz32DZ.js → runtime-HDTlEnzp.js} +3 -27
  22. package/.dist/chunks/runtime-HDTlEnzp.js.map +1 -0
  23. package/.dist/chunks/{server-D1LcDnZE.js → server-BNrA1I-u.js} +15 -84
  24. package/.dist/chunks/server-BNrA1I-u.js.map +1 -0
  25. package/.dist/chunks/source-scan-9pZxnfct.js +1059 -0
  26. package/.dist/chunks/source-scan-9pZxnfct.js.map +1 -0
  27. package/.dist/chunks/{transform-jNUr65K9.js → transform-BXyYUAez.js} +184 -358
  28. package/.dist/chunks/transform-BXyYUAez.js.map +1 -0
  29. package/.dist/compiler/markup-identifiers.d.ts +2 -0
  30. package/.dist/compiler/remote-client.d.ts +1 -19
  31. package/.dist/compiler/source-scan.d.ts +11 -108
  32. package/.dist/compiler/sveltekit-remote-bridge.d.ts +3 -0
  33. package/.dist/compiler.d.ts +6 -0
  34. package/.dist/compiler.js +1 -1
  35. package/.dist/detect.d.ts +0 -31
  36. package/.dist/detect.js +0 -39
  37. package/.dist/detect.js.map +1 -1
  38. package/.dist/diagnostics.d.ts +0 -16
  39. package/.dist/dispatcher/deps.d.ts +3 -14
  40. package/.dist/dispatcher/fibers.d.ts +5 -46
  41. package/.dist/dispatcher/index.d.ts +1 -143
  42. package/.dist/dispatcher/types.d.ts +0 -151
  43. package/.dist/dispatcher.js +1 -1
  44. package/.dist/errors.d.ts +30 -42
  45. package/.dist/generated/dispatcher.d.ts +0 -50
  46. package/.dist/generators.d.ts +1 -12
  47. package/.dist/internal/descriptors.d.ts +0 -16
  48. package/.dist/internal/generators.js +13 -8
  49. package/.dist/internal/generators.js.map +1 -1
  50. package/.dist/internal/live.d.ts +9 -0
  51. package/.dist/internal/remote-client.js +2 -2
  52. package/.dist/internal/remote-server.js +2 -2
  53. package/.dist/internal/schema.d.ts +0 -54
  54. package/.dist/live.d.ts +9 -26
  55. package/.dist/markup/event-attributes.d.ts +0 -32
  56. package/.dist/markup/promise.d.ts +1 -23
  57. package/.dist/markup/promise.js +2 -18
  58. package/.dist/markup/promise.js.map +1 -1
  59. package/.dist/markup/run.d.ts +1 -10
  60. package/.dist/markup/run.js +2 -11
  61. package/.dist/markup/run.js.map +1 -1
  62. package/.dist/markup/transform/apply.d.ts +4 -4
  63. package/.dist/markup/transform/classify.d.ts +2 -11
  64. package/.dist/markup/transform/constants.d.ts +1 -1
  65. package/.dist/markup/transform/effect-bindings.d.ts +2 -26
  66. package/.dist/markup/transform/effect-callbacks.d.ts +0 -20
  67. package/.dist/markup/transform/emit.d.ts +2 -11
  68. package/.dist/markup/transform/expressions.d.ts +0 -35
  69. package/.dist/markup/transform/scan.d.ts +3 -22
  70. package/.dist/markup/transform/types.d.ts +1 -129
  71. package/.dist/markup/transform.js +1 -1
  72. package/.dist/markup/value.d.ts +1 -18
  73. package/.dist/markup/value.js +2 -19
  74. package/.dist/markup/value.js.map +1 -1
  75. package/.dist/mod.d.ts +3 -8
  76. package/.dist/mod.js +5 -5
  77. package/.dist/mod.js.map +1 -1
  78. package/.dist/remote/cause-codec.d.ts +3 -37
  79. package/.dist/remote/client/command.d.ts +3 -17
  80. package/.dist/remote/client/form-data.d.ts +0 -7
  81. package/.dist/remote/client/form-enhance.d.ts +0 -7
  82. package/.dist/remote/client/form-transport.d.ts +14 -20
  83. package/.dist/remote/client/form.d.ts +4 -24
  84. package/.dist/remote/client/index.d.ts +2 -1
  85. package/.dist/remote/client/prerender.d.ts +6 -0
  86. package/.dist/remote/client/query-result.d.ts +2 -14
  87. package/.dist/remote/client/query.d.ts +8 -48
  88. package/.dist/remote/client/responses.d.ts +3 -27
  89. package/.dist/remote/client/types.d.ts +16 -110
  90. package/.dist/remote/client/utils.d.ts +0 -8
  91. package/.dist/remote/client.d.ts +2 -2
  92. package/.dist/remote/client.js +2 -2
  93. package/.dist/remote/effect.d.ts +6 -0
  94. package/.dist/remote/failures.d.ts +4 -0
  95. package/.dist/remote/query-update.d.ts +2 -0
  96. package/.dist/remote/resource.d.ts +25 -0
  97. package/.dist/remote/server.d.ts +5 -50
  98. package/.dist/remote/server.js +2 -2
  99. package/.dist/remote/shared.d.ts +6 -145
  100. package/.dist/remote/shared.js +6 -127
  101. package/.dist/remote/shared.js.map +1 -1
  102. package/.dist/runtime/transform.js +5 -22
  103. package/.dist/runtime/transform.js.map +1 -1
  104. package/.dist/script-transform/ast.d.ts +0 -46
  105. package/.dist/script-transform/imports.d.ts +0 -38
  106. package/.dist/script-transform/lower.d.ts +0 -9
  107. package/.dist/script-transform/runes.d.ts +0 -10
  108. package/.dist/script-transform/runtime-block.d.ts +0 -17
  109. package/.dist/script-transform/source.d.ts +0 -24
  110. package/.dist/script-transform/types.d.ts +1 -126
  111. package/.dist/server/effects.d.ts +4 -53
  112. package/.dist/server/factories.d.ts +7 -7
  113. package/.dist/server/index.d.ts +1 -1
  114. package/.dist/server/invalid.d.ts +0 -7
  115. package/.dist/server/live-snapshot.d.ts +5 -0
  116. package/.dist/server/remote-handler-context.d.ts +5 -0
  117. package/.dist/server/runtime.d.ts +6 -24
  118. package/.dist/server/schema.d.ts +0 -14
  119. package/.dist/server/transport.d.ts +2 -0
  120. package/.dist/server/types.d.ts +49 -26
  121. package/.dist/server/wrappers.d.ts +3 -40
  122. package/.dist/server.d.ts +1 -1
  123. package/.dist/server.js +200 -215
  124. package/.dist/server.js.map +1 -1
  125. package/.dist/yieldable.d.ts +1 -35
  126. package/package.json +2 -2
  127. package/.dist/chunks/client-DcZUV4rR.js +0 -653
  128. package/.dist/chunks/client-DcZUV4rR.js.map +0 -1
  129. package/.dist/chunks/compiler-BBPNyXmQ.js +0 -460
  130. package/.dist/chunks/compiler-BBPNyXmQ.js.map +0 -1
  131. package/.dist/chunks/dispatcher-DOx8iC6r.js.map +0 -1
  132. package/.dist/chunks/dispatcher-H-Ia0Os4.js +0 -47
  133. package/.dist/chunks/dispatcher-H-Ia0Os4.js.map +0 -1
  134. package/.dist/chunks/errors-IJjsUwrE.js.map +0 -1
  135. package/.dist/chunks/live-BXAKre_4.js +0 -104
  136. package/.dist/chunks/live-BXAKre_4.js.map +0 -1
  137. package/.dist/chunks/remote-client-CVI4t66c.js.map +0 -1
  138. package/.dist/chunks/runtime-GBQz32DZ.js.map +0 -1
  139. package/.dist/chunks/schema-D9pct6Y5.js +0 -89
  140. package/.dist/chunks/schema-D9pct6Y5.js.map +0 -1
  141. package/.dist/chunks/server-D1LcDnZE.js.map +0 -1
  142. package/.dist/chunks/source-scan-C4PsggID.js +0 -341
  143. package/.dist/chunks/source-scan-C4PsggID.js.map +0 -1
  144. package/.dist/chunks/transform-jNUr65K9.js.map +0 -1
  145. package/.dist/remote/client/effect.d.ts +0 -29
  146. package/.dist/remote/client/failures.d.ts +0 -42
@@ -0,0 +1,1059 @@
1
+ import ts from "typescript";
2
+ import { parse } from "svelte/compiler";
3
+ //#region src/compiler/source-scan.ts
4
+ let latest_scan;
5
+ function parse_svelte_source(source) {
6
+ let parse_source = source;
7
+ const max_attempts = (source.match(/\byield\s*\*/g)?.length ?? 0) + 1;
8
+ for (let attempt = 0; attempt < max_attempts; attempt += 1) try {
9
+ return parse(parse_source, {
10
+ modern: true,
11
+ loose: true
12
+ });
13
+ } catch (error) {
14
+ const normalized = normalize_parser_error(parse_source, error);
15
+ if (!normalized || normalized === parse_source) return;
16
+ parse_source = normalized;
17
+ }
18
+ }
19
+ function normalize_parser_error(source, error) {
20
+ if (!is_parser_diagnostic(error) || !is_parser_position(error.position)) return;
21
+ const [start, end] = error.position;
22
+ if (error.code === "js_parse_error") {
23
+ const match = source.slice(start).match(/^yield\s*\*/);
24
+ if (!match) return;
25
+ return replace_range(source, start, start + match[0].length, blank_source(match[0]));
26
+ }
27
+ if (error.code !== "render_tag_invalid_expression") return;
28
+ if (source.slice(start, end).search(/\byield\s*\*/) === -1) return;
29
+ return normalize_render_yield_expressions(source);
30
+ }
31
+ function normalize_render_yield_expressions(source) {
32
+ const replacements = [];
33
+ let cursor = 0;
34
+ while (cursor < source.length) {
35
+ const open = source.indexOf("{@render", cursor);
36
+ if (open === -1) break;
37
+ const close = find_closing_brace(source, open);
38
+ if (close === -1) {
39
+ cursor = open + 1;
40
+ continue;
41
+ }
42
+ const prefix = source.slice(open + 1, close).match(/^@render\b\s*/)?.[0];
43
+ const expression_start = prefix ? open + 1 + prefix.length : -1;
44
+ const expression = expression_start === -1 ? "" : source.slice(expression_start, close);
45
+ if (/\byield\s*\*/.test(expression)) {
46
+ const blanked = blank_source(expression);
47
+ replacements.push({
48
+ start: expression_start,
49
+ end: close,
50
+ text: "x()" + blanked.slice(3)
51
+ });
52
+ }
53
+ cursor = close + 1;
54
+ }
55
+ if (replacements.length === 0) return source;
56
+ const parts = [];
57
+ let source_cursor = 0;
58
+ for (const replacement of replacements) {
59
+ parts.push(source.slice(source_cursor, replacement.start), replacement.text);
60
+ source_cursor = replacement.end;
61
+ }
62
+ parts.push(source.slice(source_cursor));
63
+ return parts.join("");
64
+ }
65
+ function is_parser_diagnostic(error) {
66
+ return typeof error === "object" && error !== null;
67
+ }
68
+ function is_parser_position(position) {
69
+ return Array.isArray(position) && position.length === 2 && position.every((offset) => typeof offset === "number");
70
+ }
71
+ function replace_range(source, start, end, replacement) {
72
+ return source.slice(0, start) + replacement + source.slice(end);
73
+ }
74
+ function blank_source(source) {
75
+ return source.replace(/[^\r\n]/g, " ");
76
+ }
77
+ function scan_svelte_effect_source(source, filename = "unknown.svelte") {
78
+ if (latest_scan?.source === source && latest_scan.filename === filename) return latest_scan;
79
+ const scan = scan_svelte_effect_source_uncached(source, filename);
80
+ latest_scan = scan;
81
+ return scan;
82
+ }
83
+ function scan_svelte_effect_source_uncached(source, filename) {
84
+ const fast_regions = collect_fast_source_regions(source);
85
+ if (fast_regions) return make_source_scan(source, filename, fast_regions);
86
+ const ast = parse_svelte_source(make_svelte_parse_shadow(source));
87
+ if (!ast) return make_opaque_scan(source, filename);
88
+ return make_source_scan(source, filename, collect_source_regions(source, ast));
89
+ }
90
+ function make_source_scan(source, filename, regions) {
91
+ const scripts = regions.scripts;
92
+ const styles = regions.styles;
93
+ const comments = regions.comments;
94
+ const excluded_ranges = merge_ranges([...comments, ...regions.opaque_ranges]);
95
+ const markup_expressions = collect_scanned_markup_expressions(source, excluded_ranges, regions.attribute_names);
96
+ const bare_const_tags = markup_expressions.flatMap((expression) => make_bare_const_tag(expression));
97
+ const instance_script = scripts.find((script) => !script.is_module);
98
+ const effect_script = scripts.find((script) => !script.is_module && script.has_effect);
99
+ return {
100
+ filename,
101
+ source,
102
+ scripts,
103
+ styles,
104
+ comments,
105
+ excluded_ranges,
106
+ markup_expressions,
107
+ markup_binding_names: [...regions.markup_binding_names],
108
+ bare_const_tags,
109
+ instance_script,
110
+ effect_script
111
+ };
112
+ }
113
+ function make_opaque_scan(source, filename) {
114
+ return {
115
+ filename,
116
+ source,
117
+ scripts: [],
118
+ styles: [],
119
+ comments: [],
120
+ excluded_ranges: source.length === 0 ? [] : [{
121
+ start: 0,
122
+ end: source.length
123
+ }],
124
+ markup_expressions: [],
125
+ markup_binding_names: [],
126
+ bare_const_tags: [],
127
+ instance_script: void 0,
128
+ effect_script: void 0
129
+ };
130
+ }
131
+ function collect_fast_source_regions(source) {
132
+ const element_stack = [];
133
+ const scripts = [];
134
+ const styles = [];
135
+ const comments = [];
136
+ const opaque_ranges = [];
137
+ let optional_element_count = 0;
138
+ let cursor = 0;
139
+ while (cursor < source.length) {
140
+ if (source.startsWith("<!--", cursor)) {
141
+ const close = source.indexOf("-->", cursor + 4);
142
+ if (close === -1) return;
143
+ const comment = {
144
+ start: cursor,
145
+ end: close + 3
146
+ };
147
+ comments.push(comment);
148
+ cursor = comment.end;
149
+ continue;
150
+ }
151
+ const char = source[cursor];
152
+ if (char === "&") return;
153
+ if (char === "{") {
154
+ const close = find_fast_closing_brace(source, cursor);
155
+ if (close === -1 || /^\s*[#/:@]/.test(source.slice(cursor + 1, close))) return;
156
+ cursor = close + 1;
157
+ continue;
158
+ }
159
+ if (char !== "<") {
160
+ cursor += 1;
161
+ continue;
162
+ }
163
+ const raw_name = read_raw_opening_name(source, cursor);
164
+ if (raw_name) {
165
+ if (element_stack.length > 0) return;
166
+ const raw_tag = locate_raw_tag(source, cursor, raw_name);
167
+ if (!raw_tag || !is_fast_raw_opening(source, raw_tag)) return;
168
+ if (raw_name === "script") {
169
+ if (scripts.length > 0) return;
170
+ scripts.push(make_fast_script_region(source, raw_tag));
171
+ } else {
172
+ if (styles.length > 0) return;
173
+ styles.push({
174
+ start: raw_tag.start,
175
+ end: raw_tag.end
176
+ });
177
+ }
178
+ opaque_ranges.push({
179
+ start: raw_tag.start,
180
+ end: raw_tag.end
181
+ });
182
+ cursor = raw_tag.end;
183
+ continue;
184
+ }
185
+ const tag = read_fast_ordinary_tag(source, cursor);
186
+ if (!tag) return;
187
+ if (tag.is_closing) {
188
+ if (fast_void_tag_names.has(tag.name) || element_stack.at(-1) !== tag.name) return;
189
+ element_stack.pop();
190
+ if (fast_optional_end_tag_names.has(tag.name)) optional_element_count -= 1;
191
+ } else if (!tag.is_self_closing && !fast_void_tag_names.has(tag.name)) {
192
+ if (optional_element_count > 0) return;
193
+ element_stack.push(tag.name);
194
+ if (fast_optional_end_tag_names.has(tag.name)) optional_element_count += 1;
195
+ }
196
+ cursor = tag.end;
197
+ }
198
+ if (element_stack.length > 0) return;
199
+ return {
200
+ scripts,
201
+ styles,
202
+ comments,
203
+ opaque_ranges,
204
+ attribute_names: /* @__PURE__ */ new Map(),
205
+ markup_binding_names: /* @__PURE__ */ new Set()
206
+ };
207
+ }
208
+ const fast_void_tag_names = /* @__PURE__ */ new Set([
209
+ "area",
210
+ "base",
211
+ "br",
212
+ "col",
213
+ "embed",
214
+ "hr",
215
+ "img",
216
+ "input",
217
+ "link",
218
+ "meta",
219
+ "param",
220
+ "source",
221
+ "track",
222
+ "wbr"
223
+ ]);
224
+ const fast_optional_end_tag_names = /* @__PURE__ */ new Set([
225
+ "colgroup",
226
+ "dd",
227
+ "dt",
228
+ "li",
229
+ "optgroup",
230
+ "option",
231
+ "p",
232
+ "rp",
233
+ "rt",
234
+ "tbody",
235
+ "td",
236
+ "tfoot",
237
+ "th",
238
+ "thead",
239
+ "tr"
240
+ ]);
241
+ function read_fast_ordinary_tag(source, start) {
242
+ let cursor = start + 1;
243
+ const is_closing = source[cursor] === "/";
244
+ if (is_closing) cursor += 1;
245
+ const name_start = cursor;
246
+ if (!/[a-z]/.test(source[cursor] ?? "")) return;
247
+ while (/[a-z0-9-]/.test(source[cursor] ?? "")) cursor += 1;
248
+ const name = source.slice(name_start, cursor);
249
+ while (/\s/.test(source[cursor] ?? "")) cursor += 1;
250
+ const is_self_closing = !is_closing && source[cursor] === "/";
251
+ if (is_self_closing) cursor += 1;
252
+ if (source[cursor] !== ">") return;
253
+ return {
254
+ name,
255
+ end: cursor + 1,
256
+ is_closing,
257
+ is_self_closing
258
+ };
259
+ }
260
+ function find_fast_closing_brace(source, open) {
261
+ let depth = 1;
262
+ let cursor = open + 1;
263
+ while (cursor < source.length) {
264
+ const char = source[cursor];
265
+ if (char === "'" || char === "\"") {
266
+ const close = skip_quoted_string(source, cursor, char);
267
+ if (close === -1) return -1;
268
+ cursor = close + 1;
269
+ continue;
270
+ }
271
+ if (char === "`" || char === "/") return -1;
272
+ if (char === "{") depth += 1;
273
+ else if (char === "}") {
274
+ depth -= 1;
275
+ if (depth === 0) return cursor;
276
+ }
277
+ cursor += 1;
278
+ }
279
+ return -1;
280
+ }
281
+ function read_raw_opening_name(source, start) {
282
+ for (const name of ["script", "style"]) {
283
+ const name_end = start + name.length + 1;
284
+ if (source.startsWith(`<${name}`, start) && (source[name_end] === ">" || /\s/.test(source[name_end] ?? ""))) return name;
285
+ }
286
+ }
287
+ function locate_raw_tag(source, start, name) {
288
+ const content_start = find_static_opening_tag_end(source, start, name);
289
+ if (content_start === -1) return;
290
+ const opening_tag = source.slice(start, content_start);
291
+ const is_preprocessor_style = name === "style" && has_style_lang_attribute(opening_tag);
292
+ const parsed_style_end = name === "style" ? find_style_closing_tag(source, content_start, is_preprocessor_style) : void 0;
293
+ const content_end = name === "script" ? find_raw_closing_tag(source, content_start, name) : parsed_style_end ?? (is_preprocessor_style ? find_raw_closing_tag(source, content_start, name) : void 0);
294
+ if (!content_end) return;
295
+ return {
296
+ name,
297
+ start,
298
+ end: content_end.end,
299
+ content_start,
300
+ content_end: content_end.start
301
+ };
302
+ }
303
+ function has_style_lang_attribute(opening_tag) {
304
+ try {
305
+ return parse(`${opening_tag}</style>`, {
306
+ modern: true,
307
+ loose: true
308
+ }).css?.attributes.some((attribute) => attribute.name.toLowerCase() === "lang") ?? false;
309
+ } catch {
310
+ return false;
311
+ }
312
+ }
313
+ function find_raw_closing_tag(source, start, name) {
314
+ let cursor = start;
315
+ while (cursor < source.length) {
316
+ const closing_start = source.indexOf(`</${name}`, cursor);
317
+ if (closing_start === -1) return;
318
+ const closing_end = find_closing_tag_end_at(source, closing_start, name, false);
319
+ if (closing_end !== void 0) return {
320
+ start: closing_start,
321
+ end: closing_end
322
+ };
323
+ cursor = closing_start + name.length + 2;
324
+ }
325
+ }
326
+ function find_static_opening_tag_end(source, start, name) {
327
+ let cursor = start + name.length + 1;
328
+ let quote;
329
+ while (cursor < source.length) {
330
+ const char = source[cursor];
331
+ if (quote) {
332
+ if (char === quote) quote = void 0;
333
+ cursor += 1;
334
+ continue;
335
+ }
336
+ if (char === "\"" || char === "'") {
337
+ quote = char;
338
+ cursor += 1;
339
+ continue;
340
+ }
341
+ if (char === "{" || char === "}" || char === "<" || source.startsWith("/*", cursor) || source.startsWith("//", cursor)) return -1;
342
+ if (char === ">") return source.slice(start, cursor).trimEnd().endsWith("/") ? -1 : cursor + 1;
343
+ cursor += 1;
344
+ }
345
+ return -1;
346
+ }
347
+ function find_style_closing_tag(source, start, skip_line_comments) {
348
+ let cursor = start;
349
+ while (cursor < source.length) {
350
+ const char = source[cursor];
351
+ const identifier_end = skip_line_comments ? find_css_identifier_end(source, cursor) : void 0;
352
+ if (identifier_end !== void 0) {
353
+ const url_end = skip_css_url(source, cursor, identifier_end);
354
+ if (url_end === -1) return;
355
+ cursor = url_end === void 0 ? identifier_end : url_end + 1;
356
+ continue;
357
+ }
358
+ if (char === "\"" || char === "'") {
359
+ const close = skip_quoted_string(source, cursor, char);
360
+ if (close === -1) return;
361
+ cursor = close + 1;
362
+ continue;
363
+ }
364
+ if (source.startsWith("/*", cursor)) {
365
+ const close = skip_block_comment(source, cursor);
366
+ if (close === -1) return;
367
+ cursor = close + 1;
368
+ continue;
369
+ }
370
+ if (skip_line_comments && source.startsWith("//", cursor)) {
371
+ cursor = skip_line_comment(source, cursor) + 1;
372
+ continue;
373
+ }
374
+ const closing_end = find_closing_tag_end_at(source, cursor, "style", false);
375
+ if (closing_end !== void 0) return {
376
+ start: cursor,
377
+ end: closing_end
378
+ };
379
+ cursor += 1;
380
+ }
381
+ }
382
+ function find_css_identifier_end(source, start) {
383
+ const first = source[start];
384
+ if (!is_css_identifier_start(first)) return;
385
+ let cursor = start;
386
+ while (cursor < source.length) {
387
+ const char = source[cursor];
388
+ if (is_css_identifier_character(char)) {
389
+ cursor += 1;
390
+ continue;
391
+ }
392
+ if (char === "\\") {
393
+ cursor = skip_css_escape(source, cursor);
394
+ continue;
395
+ }
396
+ break;
397
+ }
398
+ return cursor;
399
+ }
400
+ function skip_css_url(source, start, identifier_end) {
401
+ if (source.slice(start, identifier_end).toLowerCase() !== "url") return;
402
+ let cursor = skip_css_whitespace(source, identifier_end);
403
+ if (source[cursor] !== "(") return;
404
+ cursor = skip_css_whitespace(source, cursor + 1);
405
+ const quote = source[cursor];
406
+ if (quote === "\"" || quote === "'") {
407
+ const close = skip_quoted_string(source, cursor, quote);
408
+ if (close === -1) return -1;
409
+ cursor = skip_css_url_trivia(source, close + 1);
410
+ if (cursor === -1) return -1;
411
+ return source[cursor] === ")" ? cursor : -1;
412
+ }
413
+ while (cursor < source.length) {
414
+ const char = source[cursor];
415
+ if (char === "\\") {
416
+ cursor = skip_css_escape(source, cursor);
417
+ continue;
418
+ }
419
+ if (char === ")") return cursor;
420
+ cursor += 1;
421
+ }
422
+ return -1;
423
+ }
424
+ function skip_css_whitespace(source, start) {
425
+ let cursor = start;
426
+ while (cursor < source.length && /[\t\n\f\r ]/.test(source[cursor] ?? "")) cursor += 1;
427
+ return cursor;
428
+ }
429
+ function skip_css_url_trivia(source, start) {
430
+ let cursor = start;
431
+ while (cursor < source.length) {
432
+ cursor = skip_css_whitespace(source, cursor);
433
+ if (!source.startsWith("/*", cursor)) return cursor;
434
+ const close = skip_block_comment(source, cursor);
435
+ if (close === -1) return -1;
436
+ cursor = close + 1;
437
+ }
438
+ return cursor;
439
+ }
440
+ function skip_css_escape(source, start) {
441
+ return Math.min(start + 2, source.length);
442
+ }
443
+ function is_css_identifier_start(char) {
444
+ return char !== void 0 && (/[A-Za-z_-]/.test(char) || char === "\\" || char.charCodeAt(0) >= 128);
445
+ }
446
+ function is_css_identifier_character(char) {
447
+ return char !== void 0 && (/[A-Za-z0-9_-]/.test(char) || char.charCodeAt(0) >= 128);
448
+ }
449
+ function is_fast_raw_opening(source, raw_tag) {
450
+ const opening = source.slice(raw_tag.start, raw_tag.content_start);
451
+ if (raw_tag.name === "script") return opening === "<script>";
452
+ return /^<style(?:\s+lang=(?:"[A-Za-z0-9_-]+"|'[A-Za-z0-9_-]+'|[A-Za-z0-9_-]+))?\s*>$/.test(opening);
453
+ }
454
+ function make_fast_script_region(source, raw_tag) {
455
+ return {
456
+ start: raw_tag.start,
457
+ end: raw_tag.end,
458
+ opening_tag_start: raw_tag.start,
459
+ opening_tag_end: raw_tag.content_start,
460
+ tag_name_end: raw_tag.start + 7,
461
+ content_start: raw_tag.content_start,
462
+ content_end: raw_tag.content_end,
463
+ closing_tag_start: raw_tag.content_end,
464
+ closing_tag_end: raw_tag.end,
465
+ attributes_text: "",
466
+ attributes: [],
467
+ text: source.slice(raw_tag.content_start, raw_tag.content_end),
468
+ is_module: false,
469
+ has_lang: false,
470
+ lang: void 0,
471
+ is_typescript: false,
472
+ has_effect: false,
473
+ effect_attribute: void 0
474
+ };
475
+ }
476
+ function make_svelte_parse_shadow(source) {
477
+ const raw_tags = collect_shadow_raw_tags(source);
478
+ if (!raw_tags) return source;
479
+ const parts = [];
480
+ let cursor = 0;
481
+ for (const raw_tag of raw_tags) {
482
+ parts.push(source.slice(cursor, raw_tag.content_start));
483
+ parts.push(blank_source(source.slice(raw_tag.content_start, raw_tag.content_end)));
484
+ cursor = raw_tag.content_end;
485
+ }
486
+ parts.push(source.slice(cursor));
487
+ return normalize_markup_yield_operators(parts.join(""));
488
+ }
489
+ function normalize_markup_yield_operators(source) {
490
+ const replacements = [];
491
+ let cursor = 0;
492
+ while (cursor < source.length) {
493
+ const open = source.indexOf("{", cursor);
494
+ if (open === -1) break;
495
+ const close = find_closing_brace(source, open);
496
+ if (close === -1) {
497
+ cursor = open + 1;
498
+ continue;
499
+ }
500
+ const inner = source.slice(open + 1, close);
501
+ const trimmed = inner.trimStart();
502
+ if (!/\byield\s*\*/.test(inner) || /^@debug\b/.test(trimmed)) {
503
+ cursor = close + 1;
504
+ continue;
505
+ }
506
+ const render_prefix = inner.match(/^(\s*@render\b\s*)/)?.[0];
507
+ const text = render_prefix ? render_prefix + "x()" + blank_source(inner.slice(render_prefix.length)).slice(3) : inner.replace(/\byield\s*\*/g, blank_source);
508
+ replacements.push({
509
+ start: open + 1,
510
+ end: close,
511
+ text
512
+ });
513
+ cursor = close + 1;
514
+ }
515
+ if (replacements.length === 0) return source;
516
+ const parts = [];
517
+ let source_cursor = 0;
518
+ for (const replacement of replacements) {
519
+ parts.push(source.slice(source_cursor, replacement.start), replacement.text);
520
+ source_cursor = replacement.end;
521
+ }
522
+ parts.push(source.slice(source_cursor));
523
+ return parts.join("");
524
+ }
525
+ function collect_shadow_raw_tags(source) {
526
+ const raw_tags = [];
527
+ let cursor = 0;
528
+ while (cursor < source.length) {
529
+ if (source.startsWith("<!--", cursor)) {
530
+ const close = source.indexOf("-->", cursor + 4);
531
+ if (close === -1) return;
532
+ cursor = close + 3;
533
+ continue;
534
+ }
535
+ const char = source[cursor];
536
+ if (char === "{") {
537
+ const close = find_closing_brace(source, cursor);
538
+ if (close === -1) return;
539
+ cursor = close + 1;
540
+ continue;
541
+ }
542
+ if (char !== "<") {
543
+ cursor += 1;
544
+ continue;
545
+ }
546
+ const rcdata_name = read_rcdata_opening_name(source, cursor);
547
+ if (rcdata_name) {
548
+ const content_start = find_markup_tag_end(source, cursor);
549
+ const closing_tag = content_start === -1 ? void 0 : find_rcdata_closing_tag(source, content_start, rcdata_name);
550
+ if (!closing_tag) return;
551
+ cursor = closing_tag.end;
552
+ continue;
553
+ }
554
+ const raw_name = read_raw_opening_name(source, cursor);
555
+ if (raw_name) {
556
+ const raw_tag = locate_raw_tag(source, cursor, raw_name);
557
+ if (!raw_tag) return;
558
+ raw_tags.push(raw_tag);
559
+ cursor = raw_tag.end;
560
+ continue;
561
+ }
562
+ const tag_end = find_markup_tag_end(source, cursor);
563
+ if (tag_end === -1) return;
564
+ cursor = tag_end;
565
+ }
566
+ return raw_tags;
567
+ }
568
+ function read_rcdata_opening_name(source, start) {
569
+ for (const name of ["textarea", "title"]) {
570
+ const name_end = start + name.length + 1;
571
+ if (source.slice(start, name_end).toLowerCase() === `<${name}` && (source[name_end] === ">" || /\s/.test(source[name_end] ?? ""))) return name;
572
+ }
573
+ }
574
+ function find_rcdata_closing_tag(source, start, name) {
575
+ let cursor = start;
576
+ while (cursor < source.length) {
577
+ if (source[cursor] === "{") {
578
+ const close = find_closing_brace(source, cursor);
579
+ if (close === -1) return;
580
+ cursor = close + 1;
581
+ continue;
582
+ }
583
+ const closing_end = find_closing_tag_end_at(source, cursor, name, true);
584
+ if (closing_end !== void 0) return {
585
+ start: cursor,
586
+ end: closing_end
587
+ };
588
+ cursor += 1;
589
+ }
590
+ }
591
+ function find_closing_tag_end_at(source, start, name, case_insensitive) {
592
+ if (source[start] !== "<") return;
593
+ const prefix = source.slice(start, start + name.length + 2);
594
+ const expected = `</${name}`;
595
+ if (!(case_insensitive ? prefix.toLowerCase() === expected : prefix === expected)) return;
596
+ let cursor = start + expected.length;
597
+ while (/\s/.test(source[cursor] ?? "")) cursor += 1;
598
+ return source[cursor] === ">" ? cursor + 1 : void 0;
599
+ }
600
+ function find_markup_tag_end(source, start) {
601
+ let cursor = start + 1;
602
+ let quote;
603
+ while (cursor < source.length) {
604
+ const char = source[cursor];
605
+ if (quote) {
606
+ if (char === quote) quote = void 0;
607
+ cursor += 1;
608
+ continue;
609
+ }
610
+ if (char === "\"" || char === "'") {
611
+ quote = char;
612
+ cursor += 1;
613
+ continue;
614
+ }
615
+ if (char === "{") {
616
+ const close = find_closing_brace(source, cursor);
617
+ if (close === -1) return -1;
618
+ cursor = close + 1;
619
+ continue;
620
+ }
621
+ if (source.startsWith("/*", cursor)) {
622
+ const close = skip_block_comment(source, cursor);
623
+ if (close === -1) return -1;
624
+ cursor = close + 1;
625
+ continue;
626
+ }
627
+ if (source.startsWith("//", cursor)) {
628
+ cursor = skip_line_comment(source, cursor) + 1;
629
+ continue;
630
+ }
631
+ if (char === ">") return cursor + 1;
632
+ if (char === "<") return -1;
633
+ cursor += 1;
634
+ }
635
+ return -1;
636
+ }
637
+ function collect_source_regions(source, ast) {
638
+ const scripts = [ast.module, ast.instance].filter((script) => script != null).map((script) => make_ast_script_region(source, script)).sort((left, right) => left.start - right.start);
639
+ const styles = ast.css ? [{
640
+ start: ast.css.start,
641
+ end: ast.css.end
642
+ }] : [];
643
+ const comments = [];
644
+ const opaque_ranges = [
645
+ ...scripts.map(({ start, end }) => ({
646
+ start,
647
+ end
648
+ })),
649
+ ...styles,
650
+ ...ast.comments.map(({ start, end }) => ({
651
+ start,
652
+ end
653
+ }))
654
+ ];
655
+ const attribute_names = /* @__PURE__ */ new Map();
656
+ const markup_binding_names = /* @__PURE__ */ new Set();
657
+ collect_fragment_regions(source, ast.fragment, comments, opaque_ranges, attribute_names, markup_binding_names);
658
+ return {
659
+ scripts,
660
+ styles,
661
+ comments,
662
+ opaque_ranges,
663
+ attribute_names,
664
+ markup_binding_names
665
+ };
666
+ }
667
+ function collect_fragment_regions(source, fragment, comments, opaque_ranges, attribute_names, markup_binding_names) {
668
+ for (const node of fragment.nodes) {
669
+ if (node.type === "Comment") {
670
+ comments.push({
671
+ start: node.start,
672
+ end: node.end
673
+ });
674
+ continue;
675
+ }
676
+ if (node.type === "RegularElement" && (node.name === "script" || node.name === "style")) {
677
+ opaque_ranges.push({
678
+ start: node.start,
679
+ end: node.end
680
+ });
681
+ continue;
682
+ }
683
+ collect_node_markup_binding_names(node, markup_binding_names);
684
+ collect_node_attribute_names(source, node, attribute_names, markup_binding_names);
685
+ collect_node_fragments(source, node, comments, opaque_ranges, attribute_names, markup_binding_names);
686
+ }
687
+ }
688
+ function collect_node_markup_binding_names(node, markup_binding_names) {
689
+ switch (node.type) {
690
+ case "EachBlock":
691
+ if (node.context) collect_markup_binding_pattern_names(node.context, markup_binding_names);
692
+ if (node.index) markup_binding_names.add(node.index);
693
+ return;
694
+ case "AwaitBlock":
695
+ for (const pattern of [node.value, node.error]) if (pattern) collect_markup_binding_pattern_names(pattern, markup_binding_names);
696
+ return;
697
+ case "SnippetBlock":
698
+ markup_binding_names.add(node.expression.name);
699
+ for (const parameter of node.parameters) collect_markup_binding_pattern_names(parameter, markup_binding_names);
700
+ return;
701
+ case "ConstTag":
702
+ case "DeclarationTag":
703
+ for (const declaration of node.declaration.declarations) collect_markup_binding_pattern_names(declaration.id, markup_binding_names);
704
+ return;
705
+ default: return;
706
+ }
707
+ }
708
+ function collect_markup_binding_pattern_names(pattern, markup_binding_names) {
709
+ switch (pattern.type) {
710
+ case "Identifier":
711
+ markup_binding_names.add(pattern.name);
712
+ return;
713
+ case "ArrayPattern":
714
+ for (const element of pattern.elements) if (element) collect_markup_binding_pattern_names(element, markup_binding_names);
715
+ return;
716
+ case "ObjectPattern":
717
+ for (const property of pattern.properties) collect_markup_binding_pattern_names(property.type === "RestElement" ? property.argument : property.value, markup_binding_names);
718
+ return;
719
+ case "RestElement":
720
+ collect_markup_binding_pattern_names(pattern.argument, markup_binding_names);
721
+ return;
722
+ case "AssignmentPattern":
723
+ collect_markup_binding_pattern_names(pattern.left, markup_binding_names);
724
+ return;
725
+ case "MemberExpression": return;
726
+ }
727
+ }
728
+ function collect_node_fragments(source, node, comments, opaque_ranges, attribute_names, markup_binding_names) {
729
+ if ("fragment" in node) collect_fragment_regions(source, node.fragment, comments, opaque_ranges, attribute_names, markup_binding_names);
730
+ switch (node.type) {
731
+ case "IfBlock":
732
+ collect_fragment_regions(source, node.consequent, comments, opaque_ranges, attribute_names, markup_binding_names);
733
+ if (node.alternate) collect_fragment_regions(source, node.alternate, comments, opaque_ranges, attribute_names, markup_binding_names);
734
+ return;
735
+ case "EachBlock":
736
+ collect_fragment_regions(source, node.body, comments, opaque_ranges, attribute_names, markup_binding_names);
737
+ if (node.fallback) collect_fragment_regions(source, node.fallback, comments, opaque_ranges, attribute_names, markup_binding_names);
738
+ return;
739
+ case "AwaitBlock":
740
+ for (const branch of [
741
+ node.pending,
742
+ node.then,
743
+ node.catch
744
+ ]) if (branch) collect_fragment_regions(source, branch, comments, opaque_ranges, attribute_names, markup_binding_names);
745
+ return;
746
+ case "SnippetBlock":
747
+ collect_fragment_regions(source, node.body, comments, opaque_ranges, attribute_names, markup_binding_names);
748
+ return;
749
+ default: return;
750
+ }
751
+ }
752
+ function collect_node_attribute_names(source, node, attribute_names, markup_binding_names) {
753
+ if (!("attributes" in node)) return;
754
+ for (const attribute of node.attributes) {
755
+ if (attribute.type === "LetDirective" && attribute.expression === null) {
756
+ markup_binding_names.add(attribute.name);
757
+ continue;
758
+ }
759
+ if (attribute.type === "Attribute") {
760
+ collect_attribute_value_names(attribute.value, attribute.name, attribute_names);
761
+ continue;
762
+ }
763
+ if (attribute.type === "StyleDirective") {
764
+ const source_name = read_source_attribute_name(source, attribute.start, attribute.end);
765
+ if (source_name) collect_attribute_value_names(attribute.value, source_name, attribute_names);
766
+ continue;
767
+ }
768
+ if (!("expression" in attribute) || !attribute.expression) continue;
769
+ const open = source.indexOf("{", attribute.start);
770
+ if (open < attribute.start || open >= attribute.end) continue;
771
+ const source_name = read_source_attribute_name(source, attribute.start, attribute.end);
772
+ if (source_name && source.slice(attribute.start, open).includes("=")) attribute_names.set(open, source_name);
773
+ }
774
+ }
775
+ function collect_attribute_value_names(value, attribute_name, attribute_names) {
776
+ if (value === true) return;
777
+ const parts = Array.isArray(value) ? value : [value];
778
+ const expression = parts.length === 1 ? parts[0] : void 0;
779
+ if (expression?.type !== "ExpressionTag") return;
780
+ attribute_names.set(expression.start, attribute_name);
781
+ }
782
+ function read_source_attribute_name(source, start, end) {
783
+ return source.slice(start, end).match(/^[^\s=]+/)?.[0];
784
+ }
785
+ function make_ast_script_region(source, script) {
786
+ const tag_name_end = script.start + 7;
787
+ const attributes = collect_ast_script_attributes(source, script, tag_name_end);
788
+ const content_start = get_program_offset(script.content, "start");
789
+ const content_end = get_program_offset(script.content, "end");
790
+ const lang = get_attribute(attributes, "lang")?.value?.toLowerCase();
791
+ const effect_attribute = get_attribute(attributes, "effect");
792
+ return {
793
+ start: script.start,
794
+ end: script.end,
795
+ opening_tag_start: script.start,
796
+ opening_tag_end: content_start,
797
+ tag_name_end,
798
+ content_start,
799
+ content_end,
800
+ closing_tag_start: content_end,
801
+ closing_tag_end: script.end,
802
+ attributes_text: source.slice(tag_name_end, content_start - 1),
803
+ attributes,
804
+ text: source.slice(content_start, content_end),
805
+ is_module: script.context === "module",
806
+ has_lang: get_attribute(attributes, "lang") !== void 0,
807
+ lang,
808
+ is_typescript: lang === "ts" || lang === "typescript",
809
+ has_effect: effect_attribute !== void 0,
810
+ effect_attribute: effect_attribute ? {
811
+ start: effect_attribute.start,
812
+ end: effect_attribute.end
813
+ } : void 0
814
+ };
815
+ }
816
+ function get_program_offset(program, key) {
817
+ if (key === "start" && "start" in program && typeof program.start === "number") return program.start;
818
+ if (key === "end" && "end" in program && typeof program.end === "number") return program.end;
819
+ throw new Error(`Svelte script content has no ${key} offset`);
820
+ }
821
+ function collect_ast_script_attributes(source, script, tag_name_end) {
822
+ let previous_end = tag_name_end;
823
+ return script.attributes.map((attribute) => {
824
+ const name_start = attribute.start;
825
+ const source_name = read_source_attribute_name(source, attribute.start, attribute.end);
826
+ const name_end = name_start + (source_name?.length ?? attribute.name.length);
827
+ let start = attribute.start;
828
+ while (start > previous_end && /\s/.test(source[start - 1] ?? "")) start -= 1;
829
+ previous_end = attribute.end;
830
+ return {
831
+ name: source_name ?? attribute.name,
832
+ start,
833
+ end: attribute.end,
834
+ name_start,
835
+ name_end,
836
+ value: get_static_attribute_value(attribute.value)
837
+ };
838
+ });
839
+ }
840
+ function get_static_attribute_value(value) {
841
+ if (value === true) return;
842
+ const parts = Array.isArray(value) ? value : [value];
843
+ if (!parts.every((part) => part.type === "Text")) return;
844
+ return parts.map((part) => part.data).join("");
845
+ }
846
+ function collect_scanned_markup_expressions(source, excluded_ranges, attribute_names) {
847
+ const expressions = [];
848
+ let cursor = 0;
849
+ while (cursor < source.length) {
850
+ const open = source.indexOf("{", cursor);
851
+ if (open === -1) break;
852
+ const excluded_range = find_range_containing(excluded_ranges, open);
853
+ if (excluded_range) {
854
+ cursor = excluded_range.end;
855
+ continue;
856
+ }
857
+ const close = find_closing_brace(source, open);
858
+ if (close === -1) {
859
+ cursor = open + 1;
860
+ continue;
861
+ }
862
+ const inner_start = open + 1;
863
+ const inner_end = close;
864
+ const inner = source.slice(inner_start, inner_end);
865
+ expressions.push({
866
+ open,
867
+ close,
868
+ inner_start,
869
+ inner_end,
870
+ inner,
871
+ expression_text: inner.trim(),
872
+ attribute_name: attribute_names.get(open)
873
+ });
874
+ cursor = close + 1;
875
+ }
876
+ return expressions;
877
+ }
878
+ function find_range_containing(ranges, position) {
879
+ let low = 0;
880
+ let high = ranges.length - 1;
881
+ while (low <= high) {
882
+ const mid = Math.floor((low + high) / 2);
883
+ const range = ranges[mid];
884
+ if (position < range.start) {
885
+ high = mid - 1;
886
+ continue;
887
+ }
888
+ if (position >= range.end) {
889
+ low = mid + 1;
890
+ continue;
891
+ }
892
+ return range;
893
+ }
894
+ }
895
+ function make_bare_const_tag(expression) {
896
+ if (!/^(\s*)const\s/.test(expression.inner)) return [];
897
+ return [{
898
+ open: expression.open,
899
+ insert_position: expression.open + 1,
900
+ expression
901
+ }];
902
+ }
903
+ function merge_ranges(ranges) {
904
+ const sorted = [...ranges].sort((a, b) => a.start - b.start);
905
+ const merged = [];
906
+ for (const range of sorted) {
907
+ const previous = merged.at(-1);
908
+ if (!previous || range.start > previous.end) {
909
+ merged.push({ ...range });
910
+ continue;
911
+ }
912
+ previous.end = Math.max(previous.end, range.end);
913
+ }
914
+ return merged;
915
+ }
916
+ function get_attribute(attributes, name) {
917
+ const normalized_name = name.toLowerCase();
918
+ return attributes.find((attribute) => attribute.name.toLowerCase() === normalized_name);
919
+ }
920
+ function find_closing_brace(source, open) {
921
+ const closing_directive = source.slice(open + 1).match(/^\s*\/(?:if|each|await|key|snippet)\s*}/);
922
+ if (closing_directive) return open + 1 + closing_directive[0].lastIndexOf("}");
923
+ let depth = 1;
924
+ let cursor = open + 1;
925
+ while (cursor < source.length) {
926
+ const char = source[cursor];
927
+ if (char === "'" || char === "\"") {
928
+ const close = skip_quoted_string(source, cursor, char);
929
+ if (close === -1) return -1;
930
+ cursor = close + 1;
931
+ continue;
932
+ }
933
+ if (char === "`") {
934
+ const close = skip_template_literal(source, cursor);
935
+ if (close === -1) return -1;
936
+ cursor = close + 1;
937
+ continue;
938
+ }
939
+ if (char === "/" && source[cursor + 1] === "/") {
940
+ cursor = skip_line_comment(source, cursor) + 1;
941
+ continue;
942
+ }
943
+ if (char === "/" && source[cursor + 1] === "*") {
944
+ const close = skip_block_comment(source, cursor);
945
+ if (close === -1) return -1;
946
+ cursor = close + 1;
947
+ continue;
948
+ }
949
+ if (char === "/") return find_closing_brace_with_typescript(source, open, cursor);
950
+ if (char === "{") depth += 1;
951
+ else if (char === "}") {
952
+ depth -= 1;
953
+ if (depth === 0) return cursor;
954
+ }
955
+ cursor += 1;
956
+ }
957
+ return -1;
958
+ }
959
+ function find_closing_brace_with_typescript(source, open, slash) {
960
+ let candidate = source.indexOf("}", slash + 1);
961
+ let candidate_index = 0;
962
+ let next_probe_index = 0;
963
+ let last_candidate = -1;
964
+ let last_probed_candidate = -1;
965
+ while (candidate !== -1) {
966
+ last_candidate = candidate;
967
+ if (candidate_index === next_probe_index) {
968
+ const resolved = resolve_closing_brace_probe(source, open, slash, candidate);
969
+ if (resolved !== -1) return resolved;
970
+ last_probed_candidate = candidate;
971
+ next_probe_index = next_probe_index * 2 + 1;
972
+ }
973
+ candidate_index += 1;
974
+ candidate = source.indexOf("}", candidate + 1);
975
+ }
976
+ if (last_candidate !== last_probed_candidate) return resolve_closing_brace_probe(source, open, slash, last_candidate);
977
+ return -1;
978
+ }
979
+ function resolve_closing_brace_probe(source, open, slash, candidate) {
980
+ if (candidate === -1) return -1;
981
+ const probe = parse_closing_brace_probe(source, open, candidate);
982
+ if (probe.is_exact) return candidate;
983
+ if (probe.close < slash || probe.close >= candidate || source[probe.close] !== "}") return -1;
984
+ return parse_closing_brace_probe(source, open, probe.close).is_exact ? probe.close : -1;
985
+ }
986
+ function parse_closing_brace_probe(source, open, candidate) {
987
+ const generator_prefix = "function* __SER__(){";
988
+ const boundary_name = "__SER___expression_boundary";
989
+ const boundary_statement = `\nconst ${boundary_name} = 0;`;
990
+ const tail = adapt_svelte_directive_tail(source.slice(open + 1, candidate + 1));
991
+ const source_file = ts.createSourceFile("svelte-expression.ts", generator_prefix + tail + boundary_statement, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
992
+ const declaration = source_file.statements[0];
993
+ const boundary = source_file.statements[1];
994
+ const boundary_declaration = boundary && ts.isVariableStatement(boundary) ? boundary.declarationList.declarations[0] : void 0;
995
+ const has_boundary = boundary_declaration?.name !== void 0 && ts.isIdentifier(boundary_declaration.name) && boundary_declaration.name.text === boundary_name;
996
+ const has_unterminated_regex = source_file.parseDiagnostics?.some((diagnostic) => diagnostic.code === 1161);
997
+ if (!declaration || !ts.isFunctionDeclaration(declaration) || !declaration.body) return {
998
+ close: -1,
999
+ is_exact: false
1000
+ };
1001
+ const close = open + declaration.body.end - 20;
1002
+ return {
1003
+ close,
1004
+ is_exact: close === candidate && has_boundary && !has_unterminated_regex
1005
+ };
1006
+ }
1007
+ function adapt_svelte_directive_tail(tail) {
1008
+ const const_directive = tail.match(/^(\s*)@(?=const\b)/);
1009
+ if (const_directive) {
1010
+ const at = const_directive[1].length;
1011
+ return tail.slice(0, at) + " " + tail.slice(at + 1);
1012
+ }
1013
+ const prefix = tail.match(/^\s*(?:(?:#(?:if|each|await|key|snippet)|@(?:render|html|debug|attach)|:(?:else\s+if|else|then|catch))\b\s*|\.\.\.\s*)/)?.[0];
1014
+ if (!prefix) return tail;
1015
+ return blank_source(prefix) + tail.slice(prefix.length);
1016
+ }
1017
+ function skip_quoted_string(source, start, quote) {
1018
+ for (let cursor = start + 1; cursor < source.length; cursor += 1) {
1019
+ if (source[cursor] === "\\") {
1020
+ cursor += 1;
1021
+ continue;
1022
+ }
1023
+ if (source[cursor] === quote) return cursor;
1024
+ }
1025
+ return -1;
1026
+ }
1027
+ function skip_template_literal(source, start) {
1028
+ let cursor = start + 1;
1029
+ while (cursor < source.length) {
1030
+ if (source[cursor] === "\\") {
1031
+ cursor += 2;
1032
+ continue;
1033
+ }
1034
+ if (source[cursor] === "`") return cursor;
1035
+ if (source[cursor] === "$" && source[cursor + 1] === "{") {
1036
+ const close = find_closing_brace(source, cursor + 1);
1037
+ if (close === -1) return -1;
1038
+ cursor = close + 1;
1039
+ continue;
1040
+ }
1041
+ cursor += 1;
1042
+ }
1043
+ return -1;
1044
+ }
1045
+ function skip_line_comment(source, start) {
1046
+ for (let cursor = start + 2; cursor < source.length; cursor += 1) {
1047
+ const char = source[cursor];
1048
+ if (char === "\n" || char === "\r" || char === "\u2028" || char === "\u2029") return cursor;
1049
+ }
1050
+ return source.length;
1051
+ }
1052
+ function skip_block_comment(source, start) {
1053
+ const close = source.indexOf("*/", start + 2);
1054
+ return close === -1 ? -1 : close + 1;
1055
+ }
1056
+ //#endregion
1057
+ export { scan_svelte_effect_source as t };
1058
+
1059
+ //# sourceMappingURL=source-scan-9pZxnfct.js.map