svelte-effect-runtime 3.4.7 → 3.4.8
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/.dist/chunks/{client-CsVu54pU.js → client-D_DE2cFa.js} +11 -42
- package/.dist/chunks/{client-CsVu54pU.js.map → client-D_DE2cFa.js.map} +1 -1
- package/.dist/chunks/{dispatcher-pHH4JcFR.js → dispatcher-BdvO4AAS.js} +2 -2
- package/.dist/chunks/{dispatcher-pHH4JcFR.js.map → dispatcher-BdvO4AAS.js.map} +1 -1
- package/.dist/chunks/{dispatcher-LtvFKYUp.js → dispatcher-NpL5xhWF.js} +3 -3
- package/.dist/chunks/{dispatcher-LtvFKYUp.js.map → dispatcher-NpL5xhWF.js.map} +1 -1
- package/.dist/chunks/{errors-Dcf0MVbq.js → errors-Bl3NVEez.js} +21 -3
- package/.dist/chunks/{errors-Dcf0MVbq.js.map → errors-Bl3NVEez.js.map} +1 -1
- package/.dist/chunks/live-DEmS7qpO.js +103 -0
- package/.dist/chunks/live-DEmS7qpO.js.map +1 -0
- package/.dist/chunks/{runtime-ekkMQ-wL.js → runtime-BNNW2GDT.js} +3 -3
- package/.dist/chunks/{runtime-ekkMQ-wL.js.map → runtime-BNNW2GDT.js.map} +1 -1
- package/.dist/chunks/{transform-CEK6Ccll.js → transform-C2fCVPL_.js} +172 -105
- package/.dist/chunks/transform-C2fCVPL_.js.map +1 -0
- package/.dist/dispatcher.js +1 -1
- package/.dist/errors.d.ts +15 -0
- package/.dist/generators.d.ts +3 -1
- package/.dist/internal/generators.js +20 -3
- package/.dist/internal/generators.js.map +1 -0
- package/.dist/internal/remote-client.js +1 -1
- package/.dist/live.d.ts +100 -0
- package/.dist/markup/promise.js +1 -1
- package/.dist/markup/run.js +1 -1
- package/.dist/markup/transform/constants.d.ts +1 -0
- package/.dist/markup/transform/types.d.ts +1 -0
- package/.dist/markup/transform.js +1 -1
- package/.dist/markup/value.js +1 -1
- package/.dist/mod.d.ts +5 -2
- package/.dist/mod.js +4 -3
- package/.dist/mod.js.map +1 -1
- package/.dist/remote/client/query.d.ts +6 -16
- package/.dist/remote/client/types.d.ts +2 -11
- package/.dist/remote/client.js +1 -1
- package/.dist/remote/server.js +1 -1
- package/.dist/runtime/transform.js +57 -26
- package/.dist/runtime/transform.js.map +1 -1
- package/.dist/script-transform/imports.d.ts +2 -0
- package/.dist/script-transform/types.d.ts +8 -0
- package/.dist/server/effects.d.ts +7 -7
- package/.dist/server/index.d.ts +3 -1
- package/.dist/server/types.d.ts +25 -50
- package/.dist/server/wrappers.d.ts +2 -2
- package/.dist/server.d.ts +2 -2
- package/.dist/server.js +40 -65
- package/.dist/server.js.map +1 -1
- package/.dist/yieldable.d.ts +41 -0
- package/package.json +1 -1
- package/.dist/chunks/transform-CEK6Ccll.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { O as UnsupportedMarkupEffectPositionError, j as YieldStarInEventCallbackError, n as AsyncEffectInSyncRuneError, t as AsyncEffectInEventCallbackError } from "./errors-Bl3NVEez.js";
|
|
2
2
|
import { contains_top_level_yield_star } from "../detect.js";
|
|
3
3
|
import ts from "typescript";
|
|
4
4
|
import { parse } from "svelte/compiler";
|
|
@@ -22,20 +22,37 @@ function make_imports(has_effect_import, has_dispatcher_import, has_untrack_impo
|
|
|
22
22
|
dispatcher_value: "__SER___dispatcher",
|
|
23
23
|
effect: "Effect",
|
|
24
24
|
program: "__SER___program",
|
|
25
|
-
untrack: "untrack"
|
|
25
|
+
untrack: "untrack",
|
|
26
|
+
yield_success: "YieldSuccess",
|
|
27
|
+
yieldable: "ToEffect"
|
|
26
28
|
}, options = {}) {
|
|
27
29
|
const needs_dispatcher = options.needs_dispatcher ?? true;
|
|
28
30
|
const needs_effect = options.needs_effect ?? true;
|
|
29
31
|
const needs_untrack = options.needs_untrack ?? true;
|
|
30
|
-
const
|
|
32
|
+
const needs_yield_success = options.needs_yield_success ?? false;
|
|
33
|
+
const needs_yieldable = options.needs_yieldable ?? false;
|
|
34
|
+
const generator_import = make_generator_import(bindings, needs_dispatcher && !has_dispatcher_import, needs_yieldable, needs_yield_success);
|
|
31
35
|
const untrack_import = bindings.untrack === "untrack" ? `import { untrack } from "svelte";` : `import { untrack as ${bindings.untrack} } from "svelte";`;
|
|
32
36
|
const effect_import = has_effect_import ? false : bindings.effect === "Effect" ? `import { Effect } from "effect";` : `import { Effect as ${bindings.effect} } from "effect";`;
|
|
33
37
|
return [
|
|
34
|
-
|
|
38
|
+
generator_import,
|
|
35
39
|
needs_untrack && !has_untrack_import && untrack_import,
|
|
36
40
|
needs_effect && effect_import
|
|
37
41
|
].filter(Boolean).join("\n");
|
|
38
42
|
}
|
|
43
|
+
function make_generator_import(bindings, needs_dispatcher, needs_yieldable, needs_yield_success) {
|
|
44
|
+
const specifiers = [
|
|
45
|
+
needs_dispatcher && make_named_import("get_dispatcher", bindings.dispatcher),
|
|
46
|
+
needs_yieldable && make_named_import("ToEffect", bindings.yieldable),
|
|
47
|
+
needs_yield_success && make_named_import("YieldSuccess", bindings.yield_success, true)
|
|
48
|
+
].filter((specifier) => specifier !== false);
|
|
49
|
+
if (specifiers.length === 0) return false;
|
|
50
|
+
return `import { ${specifiers.join(", ")} } from "svelte-effect-runtime/internal/generators";`;
|
|
51
|
+
}
|
|
52
|
+
function make_named_import(imported_name, local_name, type_only = false) {
|
|
53
|
+
const prefix = type_only ? "type " : "";
|
|
54
|
+
return imported_name === local_name ? `${prefix}${imported_name}` : `${prefix}${imported_name} as ${local_name}`;
|
|
55
|
+
}
|
|
39
56
|
/**
|
|
40
57
|
* Checks whether a source file imports a local binding from a module.
|
|
41
58
|
*
|
|
@@ -93,7 +110,8 @@ function collect_binding_name_text(name) {
|
|
|
93
110
|
//#region src/markup/transform/constants.ts
|
|
94
111
|
const HELPERS = {
|
|
95
112
|
codes: "Code",
|
|
96
|
-
dispatcher: "Dispatcher"
|
|
113
|
+
dispatcher: "Dispatcher",
|
|
114
|
+
yieldable: "ToEffect"
|
|
97
115
|
};
|
|
98
116
|
//#endregion
|
|
99
117
|
//#region src/markup/transform/apply.ts
|
|
@@ -144,7 +162,8 @@ function make_markup_helper_bindings(content) {
|
|
|
144
162
|
return {
|
|
145
163
|
bindings: {
|
|
146
164
|
codes: name_allocator.reserve(HELPERS.codes),
|
|
147
|
-
dispatcher: name_allocator.reserve(HELPERS.dispatcher)
|
|
165
|
+
dispatcher: name_allocator.reserve(HELPERS.dispatcher),
|
|
166
|
+
yieldable: name_allocator.reserve(HELPERS.yieldable)
|
|
148
167
|
},
|
|
149
168
|
name_allocator
|
|
150
169
|
};
|
|
@@ -183,7 +202,7 @@ function make_import_helper(content, import_text) {
|
|
|
183
202
|
return import_text;
|
|
184
203
|
}
|
|
185
204
|
function make_dispatcher_import(bindings) {
|
|
186
|
-
return `import { ${make_import_specifier(HELPERS.dispatcher, bindings.dispatcher)}, ${make_import_specifier(HELPERS.codes, bindings.codes)} } from "svelte-effect-runtime/internal/generators";`;
|
|
205
|
+
return `import { ${make_import_specifier(HELPERS.dispatcher, bindings.dispatcher)}, ${make_import_specifier(HELPERS.codes, bindings.codes)}, ${make_import_specifier(HELPERS.yieldable, bindings.yieldable)} } from "svelte-effect-runtime/internal/generators";`;
|
|
187
206
|
}
|
|
188
207
|
function make_import_specifier(imported_name, local_name) {
|
|
189
208
|
if (imported_name === local_name) return imported_name;
|
|
@@ -529,6 +548,75 @@ function is_record(value) {
|
|
|
529
548
|
return typeof value === "object" && value !== null;
|
|
530
549
|
}
|
|
531
550
|
//#endregion
|
|
551
|
+
//#region src/script-transform/ast.ts
|
|
552
|
+
/**
|
|
553
|
+
* Checks whether a node is a `yield*` binary expression.
|
|
554
|
+
*
|
|
555
|
+
* @since 2.0.0
|
|
556
|
+
* @param node - TypeScript AST node to check.
|
|
557
|
+
* @returns Whether the node represents `yield * operand`.
|
|
558
|
+
*/
|
|
559
|
+
function is_yield_star_expression$1(node) {
|
|
560
|
+
return ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AsteriskToken && ts.isIdentifier(node.left) && node.left.text === "yield";
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Checks whether a node owns its own yield semantics.
|
|
564
|
+
*
|
|
565
|
+
* @since 2.0.0
|
|
566
|
+
* @param node - TypeScript AST node to check.
|
|
567
|
+
* @returns Whether traversal should stop at this function boundary.
|
|
568
|
+
*/
|
|
569
|
+
function is_function_boundary_node(node) {
|
|
570
|
+
return ts.isArrowFunction(node) || ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isMethodDeclaration(node) || ts.isGetAccessorDeclaration(node) || ts.isSetAccessorDeclaration(node);
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Returns `true` if the node tree contains a top-level `await`.
|
|
574
|
+
*
|
|
575
|
+
* @since 2.0.0
|
|
576
|
+
* @param node - Root node to search.
|
|
577
|
+
* @returns Whether a top-level await expression was found.
|
|
578
|
+
*/
|
|
579
|
+
function contains_top_level_await(node) {
|
|
580
|
+
if (ts.isAwaitExpression(node)) return true;
|
|
581
|
+
return node.getChildren().some((child) => !is_function_boundary_node(child) && contains_top_level_await(child));
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Collects top-level `yield*` nodes under an expression.
|
|
585
|
+
*
|
|
586
|
+
* @since 2.0.0
|
|
587
|
+
* @param node - Root node to search.
|
|
588
|
+
* @param on_found - Callback invoked for each matching yield node.
|
|
589
|
+
* @returns Nothing.
|
|
590
|
+
*/
|
|
591
|
+
function collect_yield_star_nodes(node, on_found) {
|
|
592
|
+
if (is_function_boundary_node(node)) return;
|
|
593
|
+
if (is_yield_star_expression$1(node)) {
|
|
594
|
+
on_found(node);
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
node.forEachChild((child) => {
|
|
598
|
+
collect_yield_star_nodes(child, on_found);
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Finds the first top-level `yield*` expression below a node.
|
|
603
|
+
*
|
|
604
|
+
* @since 2.0.0
|
|
605
|
+
* @param node - Root node to search.
|
|
606
|
+
* @param on_found - Callback invoked with the first matching node.
|
|
607
|
+
* @returns Nothing.
|
|
608
|
+
*/
|
|
609
|
+
function find_yield_star_node(node, on_found) {
|
|
610
|
+
if (is_function_boundary_node(node)) return;
|
|
611
|
+
if (is_yield_star_expression$1(node)) {
|
|
612
|
+
on_found(node);
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
node.forEachChild((child) => {
|
|
616
|
+
find_yield_star_node(child, on_found);
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
//#endregion
|
|
532
620
|
//#region src/markup/transform/expressions.ts
|
|
533
621
|
/**
|
|
534
622
|
* Strips an event handler arrow function down to its executable body.
|
|
@@ -673,7 +761,7 @@ function add_binding_names(name, locals) {
|
|
|
673
761
|
}
|
|
674
762
|
}
|
|
675
763
|
function visit_event_body(node, context, result) {
|
|
676
|
-
if (is_yield_star_expression
|
|
764
|
+
if (is_yield_star_expression(node)) {
|
|
677
765
|
if (context === "top_level") result.has_top_level_yield_star = true;
|
|
678
766
|
else if (context === "nested_invalid") result.has_nested_invalid_yield_star = true;
|
|
679
767
|
node.forEachChild((child) => visit_event_body(child, context, result));
|
|
@@ -692,7 +780,7 @@ function is_nested_function_boundary(node) {
|
|
|
692
780
|
function is_generator_function_boundary(node) {
|
|
693
781
|
return (ts.isFunctionExpression(node) || ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node)) && node.asteriskToken !== void 0;
|
|
694
782
|
}
|
|
695
|
-
function is_yield_star_expression
|
|
783
|
+
function is_yield_star_expression(node) {
|
|
696
784
|
if (ts.isYieldExpression(node)) return node.asteriskToken !== void 0;
|
|
697
785
|
return ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AsteriskToken && ts.isIdentifier(node.left) && node.left.text === "yield";
|
|
698
786
|
}
|
|
@@ -953,32 +1041,28 @@ function emit_replacement(candidate, kind, effect_context, helper_bindings, name
|
|
|
953
1041
|
let helpers;
|
|
954
1042
|
let relocation;
|
|
955
1043
|
if (kind === "await") {
|
|
956
|
-
const effect = make_effect_helper(normalized_candidate, helper_name);
|
|
1044
|
+
const effect = make_effect_helper(normalized_candidate, helper_name, helper_bindings);
|
|
957
1045
|
replacement_text = emit_promise_expression(id_text, effect, helper_bindings, "undefined", `{ ssr: "pending" }`);
|
|
958
1046
|
helpers = [...normalized.helpers, effect.helper];
|
|
959
1047
|
} else if (kind === "render") {
|
|
960
|
-
const effect = make_effect_helper(normalized_candidate, helper_name);
|
|
1048
|
+
const effect = make_effect_helper(normalized_candidate, helper_name, helper_bindings);
|
|
961
1049
|
replacement_text = emit_render_expression(id_text, effect, candidate, helper_bindings, is_server_target);
|
|
962
1050
|
helpers = [...normalized.helpers, effect.helper];
|
|
963
1051
|
} else if (kind === "render_argument") {
|
|
964
|
-
const effect = make_effect_helper(normalized_candidate, helper_name);
|
|
1052
|
+
const effect = make_effect_helper(normalized_candidate, helper_name, helper_bindings);
|
|
965
1053
|
replacement_text = emit_await_expression(id_text, effect, helper_bindings, server_fallback(is_server_target, "undefined"));
|
|
966
1054
|
helpers = [...normalized.helpers, effect.helper];
|
|
967
1055
|
} else if (kind === "each") {
|
|
968
|
-
const effect = make_effect_helper(normalized_candidate, helper_name);
|
|
1056
|
+
const effect = make_effect_helper(normalized_candidate, helper_name, helper_bindings);
|
|
969
1057
|
replacement_text = emit_await_expression(id_text, effect, helper_bindings, server_fallback(is_server_target, "[]"));
|
|
970
1058
|
helpers = [...normalized.helpers, effect.helper];
|
|
971
1059
|
} else if (kind === "event") {
|
|
972
1060
|
const event = make_event_handler(normalized_candidate, helper_bindings);
|
|
973
1061
|
replacement_text = event.text;
|
|
974
1062
|
helpers = normalized.helpers;
|
|
975
|
-
relocation =
|
|
976
|
-
originalStart: 0,
|
|
977
|
-
originalEnd: candidate.expr_text.length,
|
|
978
|
-
generatedText: event.expr_text
|
|
979
|
-
});
|
|
1063
|
+
relocation = make_pending_relocation(candidate, replacement_text, event.expr_text, event.relocation);
|
|
980
1064
|
} else {
|
|
981
|
-
const effect = make_effect_helper(normalized_candidate, helper_name);
|
|
1065
|
+
const effect = make_effect_helper(normalized_candidate, helper_name, helper_bindings);
|
|
982
1066
|
replacement_text = emit_await_expression(id_text, effect, helper_bindings, server_fallback(is_server_target, "undefined"));
|
|
983
1067
|
helpers = [...normalized.helpers, effect.helper];
|
|
984
1068
|
}
|
|
@@ -994,9 +1078,11 @@ function make_event_handler(candidate, helper_bindings) {
|
|
|
994
1078
|
const expr_text = candidate.expr_text;
|
|
995
1079
|
if (is_callback_function_expression(expr_text)) throw new YieldStarInEventCallbackError(candidate.filename, expr_text);
|
|
996
1080
|
if (analyze_event_body_yield_star(expr_text).has_nested_invalid_yield_star) throw new AsyncEffectInEventCallbackError(candidate.filename, expr_text);
|
|
1081
|
+
const wrapped_expr_text = wrap_yield_stars(expr_text, helper_bindings);
|
|
997
1082
|
return {
|
|
998
|
-
expr_text,
|
|
999
|
-
|
|
1083
|
+
expr_text: wrapped_expr_text,
|
|
1084
|
+
relocation: make_yield_operand_relocation(expr_text, wrapped_expr_text, helper_bindings),
|
|
1085
|
+
text: `(event) => { ${helper_bindings.dispatcher}.emit({ type: ${helper_bindings.codes}.Markup.Run, fn: function* () { ${wrapped_expr_text}; } }); }`
|
|
1000
1086
|
};
|
|
1001
1087
|
}
|
|
1002
1088
|
function emit_promise_expression(id_text, effect, helper_bindings, ssr_fallback, options) {
|
|
@@ -1021,41 +1107,91 @@ function emit_await_expression(id_text, effect, helper_bindings, ssr_fallback) {
|
|
|
1021
1107
|
function server_fallback(is_server_target, fallback) {
|
|
1022
1108
|
return is_server_target ? fallback : void 0;
|
|
1023
1109
|
}
|
|
1024
|
-
function make_effect_helper(candidate, helper_name) {
|
|
1110
|
+
function make_effect_helper(candidate, helper_name, helper_bindings) {
|
|
1025
1111
|
const deps = collect_free_identifiers(candidate.expr_text);
|
|
1026
1112
|
const args_text = deps.join(", ");
|
|
1027
1113
|
const deps_text = deps.length === 0 ? "[]" : `[${args_text}]`;
|
|
1028
1114
|
const call = `${helper_name}()`;
|
|
1029
|
-
const
|
|
1030
|
-
const
|
|
1115
|
+
const effect_text = wrap_yield_stars(candidate.expr_text, helper_bindings);
|
|
1116
|
+
const text = `function* ${helper_name}() { return (${effect_text}); }`;
|
|
1117
|
+
const generated_start = text.indexOf(effect_text);
|
|
1118
|
+
const relocation = make_yield_operand_relocation(candidate.expr_text, effect_text, helper_bindings) ?? {
|
|
1119
|
+
originalStart: 0,
|
|
1120
|
+
originalEnd: candidate.expr_text.length,
|
|
1121
|
+
generatedStart: 0,
|
|
1122
|
+
generatedEnd: effect_text.length
|
|
1123
|
+
};
|
|
1031
1124
|
return {
|
|
1032
1125
|
call,
|
|
1033
1126
|
deps_text,
|
|
1034
1127
|
helper: {
|
|
1035
1128
|
text,
|
|
1036
1129
|
relocation: {
|
|
1037
|
-
originalStart: candidate.start,
|
|
1038
|
-
originalEnd: candidate.
|
|
1039
|
-
generatedStartInReplacement: generated_start,
|
|
1040
|
-
generatedEndInReplacement: generated_start +
|
|
1130
|
+
originalStart: candidate.start + relocation.originalStart,
|
|
1131
|
+
originalEnd: candidate.start + relocation.originalEnd,
|
|
1132
|
+
generatedStartInReplacement: generated_start + relocation.generatedStart,
|
|
1133
|
+
generatedEndInReplacement: generated_start + relocation.generatedEnd
|
|
1041
1134
|
}
|
|
1042
1135
|
}
|
|
1043
1136
|
};
|
|
1044
1137
|
}
|
|
1138
|
+
function wrap_yield_stars(text, helper_bindings) {
|
|
1139
|
+
const source_file = ts.createSourceFile("markup-yield.ts", text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
1140
|
+
const replacements = [];
|
|
1141
|
+
collect_yield_star_nodes(source_file, (node) => {
|
|
1142
|
+
const yield_text = text.slice(node.getStart(source_file), node.end).trim();
|
|
1143
|
+
replacements.push({
|
|
1144
|
+
start: node.getStart(source_file),
|
|
1145
|
+
end: node.end,
|
|
1146
|
+
text: `yield* ${helper_bindings.yieldable}(${strip_yield_star(yield_text)})`
|
|
1147
|
+
});
|
|
1148
|
+
});
|
|
1149
|
+
if (replacements.length === 0) return text;
|
|
1150
|
+
replacements.sort((a, b) => b.start - a.start);
|
|
1151
|
+
let output = text;
|
|
1152
|
+
for (const replacement of replacements) output = output.slice(0, replacement.start) + replacement.text + output.slice(replacement.end);
|
|
1153
|
+
return output;
|
|
1154
|
+
}
|
|
1155
|
+
function strip_yield_star(yield_text) {
|
|
1156
|
+
return yield_text.replace(/^yield\s*\*\s*/, "");
|
|
1157
|
+
}
|
|
1158
|
+
function make_yield_operand_relocation(original_text, generated_text, helper_bindings) {
|
|
1159
|
+
const source_file = ts.createSourceFile("markup-yield-relocation.ts", original_text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
1160
|
+
let yield_node;
|
|
1161
|
+
collect_yield_star_nodes(source_file, (node) => {
|
|
1162
|
+
yield_node ??= node;
|
|
1163
|
+
});
|
|
1164
|
+
if (!yield_node || !ts.isBinaryExpression(yield_node)) return;
|
|
1165
|
+
const operand = yield_node.right;
|
|
1166
|
+
const original_start = operand.getStart(source_file);
|
|
1167
|
+
const original_end = operand.end;
|
|
1168
|
+
const operand_text = original_text.slice(original_start, original_end).trim();
|
|
1169
|
+
const wrapper_text = `${helper_bindings.yieldable}(${operand_text})`;
|
|
1170
|
+
const wrapper_start = generated_text.indexOf(wrapper_text);
|
|
1171
|
+
if (wrapper_start === -1) return;
|
|
1172
|
+
const generated_start = wrapper_start + wrapper_text.indexOf(operand_text);
|
|
1173
|
+
return {
|
|
1174
|
+
originalStart: original_start,
|
|
1175
|
+
originalEnd: original_end,
|
|
1176
|
+
generatedStart: generated_start,
|
|
1177
|
+
generatedEnd: generated_start + operand_text.length
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1045
1180
|
function make_cache_id(candidate) {
|
|
1046
1181
|
return `${candidate.filename.replace(/[?#].*$/, "")}:${candidate.start}:${candidate.end}`;
|
|
1047
1182
|
}
|
|
1048
1183
|
function make_helper_name(candidate, name_allocator) {
|
|
1049
1184
|
return name_allocator.reserve(`__SER___markup_effect_${candidate.start}_${candidate.end}`);
|
|
1050
1185
|
}
|
|
1051
|
-
function
|
|
1052
|
-
|
|
1186
|
+
function make_pending_relocation(candidate, replacement_text, expression_text, relocation) {
|
|
1187
|
+
if (!relocation) return;
|
|
1188
|
+
const generated_start = replacement_text.indexOf(expression_text);
|
|
1053
1189
|
if (generated_start === -1) return;
|
|
1054
1190
|
return {
|
|
1055
|
-
originalStart: candidate.start +
|
|
1056
|
-
originalEnd: candidate.start +
|
|
1057
|
-
generatedStartInReplacement: generated_start,
|
|
1058
|
-
generatedEndInReplacement: generated_start +
|
|
1191
|
+
originalStart: candidate.start + relocation.originalStart,
|
|
1192
|
+
originalEnd: candidate.start + relocation.originalEnd,
|
|
1193
|
+
generatedStartInReplacement: generated_start + relocation.generatedStart,
|
|
1194
|
+
generatedEndInReplacement: generated_start + relocation.generatedEnd
|
|
1059
1195
|
};
|
|
1060
1196
|
}
|
|
1061
1197
|
//#endregion
|
|
@@ -1155,75 +1291,6 @@ function is_rune_root(name) {
|
|
|
1155
1291
|
return name === "$bindable" || name === "$derived" || name === "$effect" || name === "$host" || name === "$inspect" || name === "$props" || name === "$state";
|
|
1156
1292
|
}
|
|
1157
1293
|
//#endregion
|
|
1158
|
-
//#region src/script-transform/ast.ts
|
|
1159
|
-
/**
|
|
1160
|
-
* Checks whether a node is a `yield*` binary expression.
|
|
1161
|
-
*
|
|
1162
|
-
* @since 2.0.0
|
|
1163
|
-
* @param node - TypeScript AST node to check.
|
|
1164
|
-
* @returns Whether the node represents `yield * operand`.
|
|
1165
|
-
*/
|
|
1166
|
-
function is_yield_star_expression(node) {
|
|
1167
|
-
return ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AsteriskToken && ts.isIdentifier(node.left) && node.left.text === "yield";
|
|
1168
|
-
}
|
|
1169
|
-
/**
|
|
1170
|
-
* Checks whether a node owns its own yield semantics.
|
|
1171
|
-
*
|
|
1172
|
-
* @since 2.0.0
|
|
1173
|
-
* @param node - TypeScript AST node to check.
|
|
1174
|
-
* @returns Whether traversal should stop at this function boundary.
|
|
1175
|
-
*/
|
|
1176
|
-
function is_function_boundary_node(node) {
|
|
1177
|
-
return ts.isArrowFunction(node) || ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isMethodDeclaration(node) || ts.isGetAccessorDeclaration(node) || ts.isSetAccessorDeclaration(node);
|
|
1178
|
-
}
|
|
1179
|
-
/**
|
|
1180
|
-
* Returns `true` if the node tree contains a top-level `await`.
|
|
1181
|
-
*
|
|
1182
|
-
* @since 2.0.0
|
|
1183
|
-
* @param node - Root node to search.
|
|
1184
|
-
* @returns Whether a top-level await expression was found.
|
|
1185
|
-
*/
|
|
1186
|
-
function contains_top_level_await(node) {
|
|
1187
|
-
if (ts.isAwaitExpression(node)) return true;
|
|
1188
|
-
return node.getChildren().some((child) => !is_function_boundary_node(child) && contains_top_level_await(child));
|
|
1189
|
-
}
|
|
1190
|
-
/**
|
|
1191
|
-
* Collects top-level `yield*` nodes under an expression.
|
|
1192
|
-
*
|
|
1193
|
-
* @since 2.0.0
|
|
1194
|
-
* @param node - Root node to search.
|
|
1195
|
-
* @param on_found - Callback invoked for each matching yield node.
|
|
1196
|
-
* @returns Nothing.
|
|
1197
|
-
*/
|
|
1198
|
-
function collect_yield_star_nodes(node, on_found) {
|
|
1199
|
-
if (is_function_boundary_node(node)) return;
|
|
1200
|
-
if (is_yield_star_expression(node)) {
|
|
1201
|
-
on_found(node);
|
|
1202
|
-
return;
|
|
1203
|
-
}
|
|
1204
|
-
node.forEachChild((child) => {
|
|
1205
|
-
collect_yield_star_nodes(child, on_found);
|
|
1206
|
-
});
|
|
1207
|
-
}
|
|
1208
|
-
/**
|
|
1209
|
-
* Finds the first top-level `yield*` expression below a node.
|
|
1210
|
-
*
|
|
1211
|
-
* @since 2.0.0
|
|
1212
|
-
* @param node - Root node to search.
|
|
1213
|
-
* @param on_found - Callback invoked with the first matching node.
|
|
1214
|
-
* @returns Nothing.
|
|
1215
|
-
*/
|
|
1216
|
-
function find_yield_star_node(node, on_found) {
|
|
1217
|
-
if (is_function_boundary_node(node)) return;
|
|
1218
|
-
if (is_yield_star_expression(node)) {
|
|
1219
|
-
on_found(node);
|
|
1220
|
-
return;
|
|
1221
|
-
}
|
|
1222
|
-
node.forEachChild((child) => {
|
|
1223
|
-
find_yield_star_node(child, on_found);
|
|
1224
|
-
});
|
|
1225
|
-
}
|
|
1226
|
-
//#endregion
|
|
1227
1294
|
//#region src/markup/transform/scan.ts
|
|
1228
1295
|
/**
|
|
1229
1296
|
* Replaces markup `yield*` expressions with placeholders before Svelte parses
|
|
@@ -1644,6 +1711,6 @@ function transform_markup_effect(content, filename, options = {}) {
|
|
|
1644
1711
|
};
|
|
1645
1712
|
}
|
|
1646
1713
|
//#endregion
|
|
1647
|
-
export {
|
|
1714
|
+
export { slice_start as a, contains_top_level_await as c, collect_top_level_binding_names as d, has_local_import_binding as f, slice as i, find_yield_star_node as l, validate_rune_yield_usage as n, collect_free_identifiers as o, make_imports as p, create_source_map as r, collect_yield_star_nodes as s, transform_markup_effect as t, is_yield_star_expression$1 as u };
|
|
1648
1715
|
|
|
1649
|
-
//# sourceMappingURL=transform-
|
|
1716
|
+
//# sourceMappingURL=transform-C2fCVPL_.js.map
|